encoder/Interface: move instance methods to abstract class
Rename struct Encoder to PreparedEncoder, and add a new (abstract) class Encoder which represents one encoder instance.
This commit is contained in:
@@ -63,8 +63,8 @@ HttpdOutput::~HttpdOutput()
|
||||
if (metadata != nullptr)
|
||||
metadata->Unref();
|
||||
|
||||
if (encoder != nullptr)
|
||||
encoder->Dispose();
|
||||
if (prepared_encoder != nullptr)
|
||||
prepared_encoder->Dispose();
|
||||
|
||||
}
|
||||
|
||||
@@ -123,12 +123,12 @@ HttpdOutput::Configure(const ConfigBlock &block, Error &error)
|
||||
|
||||
/* initialize encoder */
|
||||
|
||||
encoder = encoder_init(*encoder_plugin, block, error);
|
||||
if (encoder == nullptr)
|
||||
prepared_encoder = encoder_init(*encoder_plugin, block, error);
|
||||
if (prepared_encoder == nullptr)
|
||||
return false;
|
||||
|
||||
/* determine content type */
|
||||
content_type = encoder_get_mime_type(encoder);
|
||||
content_type = encoder_get_mime_type(prepared_encoder);
|
||||
if (content_type == nullptr)
|
||||
content_type = "application/octet-stream";
|
||||
|
||||
@@ -169,7 +169,7 @@ inline void
|
||||
HttpdOutput::AddClient(int fd)
|
||||
{
|
||||
auto *client = new HttpdClient(*this, fd, GetEventLoop(),
|
||||
encoder->plugin.tag == nullptr);
|
||||
!encoder->ImplementsTag());
|
||||
clients.push_front(*client);
|
||||
|
||||
/* pass metadata to client */
|
||||
@@ -250,15 +250,14 @@ HttpdOutput::ReadPage()
|
||||
/* we have fed a lot of input into the encoder, but it
|
||||
didn't give anything back yet - flush now to avoid
|
||||
buffer underruns */
|
||||
encoder_flush(encoder, IgnoreError());
|
||||
encoder->Flush(IgnoreError());
|
||||
unflushed_input = 0;
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
do {
|
||||
size_t nbytes = encoder_read(encoder,
|
||||
buffer + size,
|
||||
sizeof(buffer) - size);
|
||||
size_t nbytes = encoder->Read(buffer + size,
|
||||
sizeof(buffer) - size);
|
||||
if (nbytes == 0)
|
||||
break;
|
||||
|
||||
@@ -292,7 +291,8 @@ httpd_output_disable(AudioOutput *ao)
|
||||
inline bool
|
||||
HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
|
||||
{
|
||||
if (!encoder->Open(audio_format, error))
|
||||
encoder = prepared_encoder->Open(audio_format, error);
|
||||
if (encoder == nullptr)
|
||||
return false;
|
||||
|
||||
/* we have to remember the encoder header, i.e. the first
|
||||
@@ -351,7 +351,7 @@ HttpdOutput::Close()
|
||||
if (header != nullptr)
|
||||
header->Unref();
|
||||
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -441,7 +441,7 @@ HttpdOutput::BroadcastFromEncoder()
|
||||
inline bool
|
||||
HttpdOutput::EncodeAndPlay(const void *chunk, size_t size, Error &error)
|
||||
{
|
||||
if (!encoder_write(encoder, chunk, size, error))
|
||||
if (!encoder->Write(chunk, size, error))
|
||||
return false;
|
||||
|
||||
unflushed_input += size;
|
||||
@@ -491,18 +491,18 @@ httpd_output_pause(AudioOutput *ao)
|
||||
inline void
|
||||
HttpdOutput::SendTag(const Tag &tag)
|
||||
{
|
||||
if (encoder->plugin.tag != nullptr) {
|
||||
if (encoder->ImplementsTag()) {
|
||||
/* embed encoder tags */
|
||||
|
||||
/* flush the current stream, and end it */
|
||||
|
||||
encoder_pre_tag(encoder, IgnoreError());
|
||||
encoder->PreTag(IgnoreError());
|
||||
BroadcastFromEncoder();
|
||||
|
||||
/* send the tag to the encoder - which starts a new
|
||||
stream now */
|
||||
|
||||
encoder_tag(encoder, tag, IgnoreError());
|
||||
encoder->SendTag(tag, IgnoreError());
|
||||
|
||||
/* the first page generated by the encoder will now be
|
||||
used as the new "header" page, which is sent to all
|
||||
|
||||
Reference in New Issue
Block a user