protocol: add command "binarylimit"

Increasing the protocol version to 0.22.4 to allow clients to detect
this feature.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1038
This commit is contained in:
Max Kellermann
2021-01-21 16:27:52 +01:00
parent 6e33566cee
commit 995aafe9cc
10 changed files with 66 additions and 25 deletions

View File

@@ -43,6 +43,7 @@
#include "thread/Mutex.hxx"
#include "Log.hxx"
#include <algorithm>
#include <cassert>
#include <cinttypes> /* for PRIu64 */
@@ -205,28 +206,26 @@ read_stream_art(Response &r, const char *uri, size_t offset)
const offset_type art_file_size = is->GetSize();
if (offset >= art_file_size) {
if (offset > art_file_size) {
r.Error(ACK_ERROR_ARG, "Offset too large");
return CommandResult::ERROR;
} else {
r.Format("size: %" PRIoffset "\n", art_file_size);
r.WriteBinary(nullptr);
return CommandResult::OK;
}
if (offset > art_file_size) {
r.Error(ACK_ERROR_ARG, "Offset too large");
return CommandResult::ERROR;
}
uint8_t buffer[Response::MAX_BINARY_SIZE];
size_t read_size;
std::size_t buffer_size =
std::min<offset_type>(art_file_size - offset,
r.GetClient().binary_limit);
{
std::unique_ptr<std::byte[]> buffer(new std::byte[buffer_size]);
std::size_t read_size = 0;
if (buffer_size > 0) {
std::unique_lock<Mutex> lock(mutex);
is->Seek(lock, offset);
read_size = is->Read(lock, &buffer, sizeof(buffer));
read_size = is->Read(lock, buffer.get(), buffer_size);
}
r.Format("size: %" PRIoffset "\n", art_file_size);
r.WriteBinary({buffer, read_size});
r.WriteBinary({buffer.get(), read_size});
return CommandResult::OK;
}
@@ -313,8 +312,10 @@ public:
response.Format("type: %s\n", mime_type);
buffer.size -= offset;
if (buffer.size > Response::MAX_BINARY_SIZE)
buffer.size = Response::MAX_BINARY_SIZE;
const std::size_t binary_limit = response.GetClient().binary_limit;
if (buffer.size > binary_limit)
buffer.size = binary_limit;
buffer.data = OffsetPointer(buffer.data, offset);
response.WriteBinary(buffer);