Skip to content

Commit

Permalink
input/thread: use pass std::span<std::byte> to ThreadRead()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 29, 2024
1 parent dbaa72c commit 2e78bd4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/input/ThreadInputStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ThreadInputStream::ThreadFunc() noexcept

try {
const ScopeUnlock unlock(mutex);
nbytes = ThreadRead(w.data(), w.size());
nbytes = ThreadRead(w);
} catch (...) {
postponed_exception = std::current_exception();
InvokeOnAvailable();
Expand Down
2 changes: 1 addition & 1 deletion src/input/ThreadInputStream.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected:
*
* @return 0 on end-of-file
*/
virtual size_t ThreadRead(void *ptr, size_t size) = 0;
virtual std::size_t ThreadRead(std::span<std::byte> dest) = 0;

/**
* Optional deinitialization before leaving the thread.
Expand Down
12 changes: 6 additions & 6 deletions src/input/plugins/MmsInputPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MmsInputStream final : public ThreadInputStream {

protected:
void Open() override;
size_t ThreadRead(void *ptr, size_t size) override;
std::size_t ThreadRead(std::span<std::byte> dest) override;

void Close() noexcept override {
mmsx_close(mms);
Expand Down Expand Up @@ -62,17 +62,17 @@ input_mms_open(const char *url,
return m;
}

size_t
MmsInputStream::ThreadRead(void *ptr, size_t read_size)
std::size_t
MmsInputStream::ThreadRead(std::span<std::byte> dest)
{
/* unfortunately, mmsx_read() blocks until the whole buffer
has been filled; to avoid big latencies, limit the size of
each chunk we read to a reasonable size */
constexpr size_t MAX_CHUNK = 16384;
if (read_size > MAX_CHUNK)
read_size = MAX_CHUNK;
if (dest.size() > MAX_CHUNK)
dest = dest.first(MAX_CHUNK);

int nbytes = mmsx_read(nullptr, mms, (char *)ptr, read_size);
int nbytes = mmsx_read(nullptr, mms, reinterpret_cast<char *>(dest.data()), dest.size());
if (nbytes <= 0) {
if (nbytes < 0)
throw MakeErrno("mmsx_read() failed");
Expand Down

0 comments on commit 2e78bd4

Please sign in to comment.