encoder/Interface: pass std::span to Write() and Read()
This commit is contained in:
@@ -333,7 +333,7 @@ RecorderOutput::Play(const void *chunk, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
encoder->Write(chunk, size);
|
||||
encoder->Write({(const std::byte *)chunk, size});
|
||||
|
||||
EncoderToFile();
|
||||
|
||||
|
||||
@@ -326,12 +326,14 @@ static void
|
||||
EncoderToShout(shout_t *shout_conn, Encoder &encoder)
|
||||
{
|
||||
while (true) {
|
||||
uint8_t buffer[32768];
|
||||
size_t nbytes = encoder.Read(buffer, sizeof(buffer));
|
||||
if (nbytes == 0)
|
||||
std::byte buffer[32768];
|
||||
const auto e = encoder.Read(std::span{buffer});
|
||||
if (e.empty() == 0)
|
||||
return;
|
||||
|
||||
int err = shout_send(shout_conn, buffer, nbytes);
|
||||
int err = shout_send(shout_conn,
|
||||
(const unsigned char *)e.data(),
|
||||
e.size());
|
||||
HandleShoutError(shout_conn, err);
|
||||
}
|
||||
}
|
||||
@@ -414,7 +416,7 @@ ShoutOutput::Delay() const noexcept
|
||||
size_t
|
||||
ShoutOutput::Play(const void *chunk, size_t size)
|
||||
{
|
||||
encoder->Write(chunk, size);
|
||||
encoder->Write({(const std::byte *)chunk, size});
|
||||
WritePage();
|
||||
return size;
|
||||
}
|
||||
@@ -422,9 +424,9 @@ ShoutOutput::Play(const void *chunk, size_t size)
|
||||
bool
|
||||
ShoutOutput::Pause()
|
||||
{
|
||||
static char silence[1020];
|
||||
static std::byte silence[1020];
|
||||
|
||||
encoder->Write(silence, sizeof(silence));
|
||||
encoder->Write(std::span{silence});
|
||||
WritePage();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
|
||||
struct ConfigBlock;
|
||||
class EventLoop;
|
||||
@@ -249,7 +250,7 @@ public:
|
||||
*
|
||||
* Throws on error.
|
||||
*/
|
||||
void EncodeAndPlay(const void *chunk, size_t size);
|
||||
void EncodeAndPlay(std::span<const std::byte> src);
|
||||
|
||||
void SendTag(const Tag &tag) override;
|
||||
|
||||
|
||||
@@ -161,14 +161,13 @@ HttpdOutput::ReadPage() noexcept
|
||||
|
||||
size_t size = 0;
|
||||
do {
|
||||
size_t nbytes = encoder->Read(buffer + size,
|
||||
sizeof(buffer) - size);
|
||||
if (nbytes == 0)
|
||||
const auto r = encoder->Read(std::span{buffer}.subspan(size));
|
||||
if (r.empty())
|
||||
break;
|
||||
|
||||
unflushed_input = 0;
|
||||
|
||||
size += nbytes;
|
||||
size += r.size();
|
||||
} while (size < sizeof(buffer));
|
||||
|
||||
if (size == 0)
|
||||
@@ -301,11 +300,11 @@ HttpdOutput::BroadcastFromEncoder() noexcept
|
||||
}
|
||||
|
||||
inline void
|
||||
HttpdOutput::EncodeAndPlay(const void *chunk, size_t size)
|
||||
HttpdOutput::EncodeAndPlay(std::span<const std::byte> src)
|
||||
{
|
||||
encoder->Write(chunk, size);
|
||||
encoder->Write(src);
|
||||
|
||||
unflushed_input += size;
|
||||
unflushed_input += src.size();
|
||||
|
||||
BroadcastFromEncoder();
|
||||
}
|
||||
@@ -316,7 +315,7 @@ HttpdOutput::Play(const void *chunk, size_t size)
|
||||
pause = false;
|
||||
|
||||
if (LockHasClients())
|
||||
EncodeAndPlay(chunk, size);
|
||||
EncodeAndPlay({(const std::byte *)chunk, size});
|
||||
|
||||
if (!timer->IsStarted())
|
||||
timer->Start();
|
||||
|
||||
@@ -128,9 +128,7 @@ ReadEncoder(Encoder &encoder) noexcept
|
||||
{
|
||||
std::byte buffer[4096];
|
||||
|
||||
size_t nbytes = encoder.Read(buffer, sizeof(buffer));
|
||||
const std::span<const std::byte> src{buffer, nbytes};
|
||||
return AllocatedArray<std::byte>{src};
|
||||
return AllocatedArray<std::byte>{encoder.Read(std::span{buffer})};
|
||||
}
|
||||
|
||||
inline void
|
||||
@@ -313,7 +311,7 @@ SnapcastOutput::Play(const void *chunk, size_t size)
|
||||
if (!LockHasClients())
|
||||
return size;
|
||||
|
||||
encoder->Write(chunk, size);
|
||||
encoder->Write({(const std::byte *)chunk, size});
|
||||
unflushed_input += size;
|
||||
|
||||
if (unflushed_input >= 65536) {
|
||||
@@ -332,8 +330,8 @@ SnapcastOutput::Play(const void *chunk, size_t size)
|
||||
while (true) {
|
||||
std::byte buffer[32768];
|
||||
|
||||
size_t nbytes = encoder->Read(buffer, sizeof(buffer));
|
||||
if (nbytes == 0)
|
||||
const auto payload = encoder->Read(std::span{buffer});
|
||||
if (payload.empty())
|
||||
break;
|
||||
|
||||
unflushed_input = 0;
|
||||
@@ -342,7 +340,6 @@ SnapcastOutput::Play(const void *chunk, size_t size)
|
||||
if (chunks.empty())
|
||||
inject_event.Schedule();
|
||||
|
||||
const std::span<const std::byte> payload{buffer, nbytes};
|
||||
chunks.push(std::make_shared<SnapcastChunk>(now, AllocatedArray{payload}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user