output/Shout: move write_page() into the struct
This commit is contained in:
@@ -69,6 +69,9 @@ struct ShoutOutput final {
|
|||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
bool Pause();
|
bool Pause();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void WritePage();
|
||||||
};
|
};
|
||||||
|
|
||||||
static int shout_init_count;
|
static int shout_init_count;
|
||||||
@@ -278,22 +281,26 @@ HandleShoutError(shout_t *shout_conn, int err)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
write_page(ShoutOutput *sd)
|
EncoderToShout(shout_t *shout_conn, Encoder &encoder,
|
||||||
|
unsigned char *buffer, size_t buffer_size)
|
||||||
{
|
{
|
||||||
assert(sd->encoder != nullptr);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
size_t nbytes = sd->encoder->Read(sd->buffer,
|
size_t nbytes = encoder.Read(buffer, buffer_size);
|
||||||
sizeof(sd->buffer));
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
int err = shout_send(sd->shout_conn, sd->buffer, nbytes);
|
int err = shout_send(shout_conn, buffer, nbytes);
|
||||||
HandleShoutError(sd->shout_conn, err);
|
HandleShoutError(shout_conn, err);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
void
|
||||||
|
ShoutOutput::WritePage()
|
||||||
|
{
|
||||||
|
assert(encoder != nullptr);
|
||||||
|
|
||||||
|
EncoderToShout(shout_conn, *encoder, buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -301,7 +308,7 @@ ShoutOutput::Close()
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
encoder->End();
|
encoder->End();
|
||||||
write_page(this);
|
WritePage();
|
||||||
} catch (const std::runtime_error &) {
|
} catch (const std::runtime_error &) {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
@@ -347,7 +354,7 @@ ShoutOutput::Open(AudioFormat &audio_format)
|
|||||||
encoder = prepared_encoder->Open(audio_format);
|
encoder = prepared_encoder->Open(audio_format);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
write_page(this);
|
WritePage();
|
||||||
} catch (const std::runtime_error &) {
|
} catch (const std::runtime_error &) {
|
||||||
delete encoder;
|
delete encoder;
|
||||||
throw;
|
throw;
|
||||||
@@ -372,7 +379,7 @@ size_t
|
|||||||
ShoutOutput::Play(const void *chunk, size_t size)
|
ShoutOutput::Play(const void *chunk, size_t size)
|
||||||
{
|
{
|
||||||
encoder->Write(chunk, size);
|
encoder->Write(chunk, size);
|
||||||
write_page(this);
|
WritePage();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +390,7 @@ ShoutOutput::Pause()
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
encoder->Write(silence, sizeof(silence));
|
encoder->Write(silence, sizeof(silence));
|
||||||
write_page(this);
|
WritePage();
|
||||||
} catch (const std::runtime_error &) {
|
} catch (const std::runtime_error &) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -424,7 +431,7 @@ ShoutOutput::SendTag(const Tag &tag)
|
|||||||
/* encoder plugin supports stream tags */
|
/* encoder plugin supports stream tags */
|
||||||
|
|
||||||
encoder->PreTag();
|
encoder->PreTag();
|
||||||
write_page(this);
|
WritePage();
|
||||||
encoder->SendTag(tag);
|
encoder->SendTag(tag);
|
||||||
} else {
|
} else {
|
||||||
/* no stream tag support: fall back to icy-metadata */
|
/* no stream tag support: fall back to icy-metadata */
|
||||||
@@ -439,7 +446,7 @@ ShoutOutput::SendTag(const Tag &tag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write_page(this);
|
WritePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef AudioOutputWrapper<ShoutOutput> Wrapper;
|
typedef AudioOutputWrapper<ShoutOutput> Wrapper;
|
||||||
|
Reference in New Issue
Block a user