encoder/Interface: pass std::span to Write() and Read()
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user