DecoderInternal: move functions into the class
This commit is contained in:
parent
44ac84767e
commit
a80b5cf19b
@ -312,12 +312,12 @@ do_send_tag(Decoder &decoder, const Tag &tag)
|
|||||||
if (decoder.chunk != nullptr) {
|
if (decoder.chunk != nullptr) {
|
||||||
/* there is a partial chunk - flush it, we want the
|
/* there is a partial chunk - flush it, we want the
|
||||||
tag in a new chunk */
|
tag in a new chunk */
|
||||||
decoder_flush_chunk(decoder);
|
decoder.FlushChunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(decoder.chunk == nullptr);
|
assert(decoder.chunk == nullptr);
|
||||||
|
|
||||||
chunk = decoder_get_chunk(decoder);
|
chunk = decoder.GetChunk();
|
||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
assert(decoder.dc.command != DecoderCommand::NONE);
|
assert(decoder.dc.command != DecoderCommand::NONE);
|
||||||
return decoder.dc.command;
|
return decoder.dc.command;
|
||||||
@ -408,7 +408,7 @@ decoder_data(Decoder &decoder,
|
|||||||
struct music_chunk *chunk;
|
struct music_chunk *chunk;
|
||||||
bool full;
|
bool full;
|
||||||
|
|
||||||
chunk = decoder_get_chunk(decoder);
|
chunk = decoder.GetChunk();
|
||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
assert(dc.command != DecoderCommand::NONE);
|
assert(dc.command != DecoderCommand::NONE);
|
||||||
return dc.command;
|
return dc.command;
|
||||||
@ -421,7 +421,7 @@ decoder_data(Decoder &decoder,
|
|||||||
kbit_rate);
|
kbit_rate);
|
||||||
if (dest.IsNull()) {
|
if (dest.IsNull()) {
|
||||||
/* the chunk is full, flush it */
|
/* the chunk is full, flush it */
|
||||||
decoder_flush_chunk(decoder);
|
decoder.FlushChunk();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +440,7 @@ decoder_data(Decoder &decoder,
|
|||||||
full = chunk->Expand(dc.out_audio_format, nbytes);
|
full = chunk->Expand(dc.out_audio_format, nbytes);
|
||||||
if (full) {
|
if (full) {
|
||||||
/* the chunk is full, flush it */
|
/* the chunk is full, flush it */
|
||||||
decoder_flush_chunk(decoder);
|
decoder.FlushChunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (const uint8_t *)data + nbytes;
|
data = (const uint8_t *)data + nbytes;
|
||||||
@ -532,7 +532,7 @@ decoder_replay_gain(Decoder &decoder,
|
|||||||
/* flush the current chunk because the new
|
/* flush the current chunk because the new
|
||||||
replay gain values affect the following
|
replay gain values affect the following
|
||||||
samples */
|
samples */
|
||||||
decoder_flush_chunk(decoder);
|
decoder.FlushChunk();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
decoder.replay_gain_serial = 0;
|
decoder.replay_gain_serial = 0;
|
||||||
|
@ -51,24 +51,21 @@ need_chunks(DecoderControl &dc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct music_chunk *
|
struct music_chunk *
|
||||||
decoder_get_chunk(Decoder &decoder)
|
Decoder::GetChunk()
|
||||||
{
|
{
|
||||||
DecoderControl &dc = decoder.dc;
|
|
||||||
DecoderCommand cmd;
|
DecoderCommand cmd;
|
||||||
|
|
||||||
if (decoder.chunk != nullptr)
|
if (chunk != nullptr)
|
||||||
return decoder.chunk;
|
return chunk;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
decoder.chunk = dc.buffer->Allocate();
|
chunk = dc.buffer->Allocate();
|
||||||
if (decoder.chunk != nullptr) {
|
if (chunk != nullptr) {
|
||||||
decoder.chunk->replay_gain_serial =
|
chunk->replay_gain_serial = replay_gain_serial;
|
||||||
decoder.replay_gain_serial;
|
if (replay_gain_serial != 0)
|
||||||
if (decoder.replay_gain_serial != 0)
|
chunk->replay_gain_info = replay_gain_info;
|
||||||
decoder.chunk->replay_gain_info =
|
|
||||||
decoder.replay_gain_info;
|
|
||||||
|
|
||||||
return decoder.chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.Lock();
|
dc.Lock();
|
||||||
@ -80,18 +77,16 @@ decoder_get_chunk(Decoder &decoder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_flush_chunk(Decoder &decoder)
|
Decoder::FlushChunk()
|
||||||
{
|
{
|
||||||
DecoderControl &dc = decoder.dc;
|
assert(chunk != nullptr);
|
||||||
|
|
||||||
assert(decoder.chunk != nullptr);
|
if (chunk->IsEmpty())
|
||||||
|
dc.buffer->Return(chunk);
|
||||||
if (decoder.chunk->IsEmpty())
|
|
||||||
dc.buffer->Return(decoder.chunk);
|
|
||||||
else
|
else
|
||||||
dc.pipe->Push(decoder.chunk);
|
dc.pipe->Push(chunk);
|
||||||
|
|
||||||
decoder.chunk = nullptr;
|
chunk = nullptr;
|
||||||
|
|
||||||
dc.Lock();
|
dc.Lock();
|
||||||
if (dc.client_is_waiting)
|
if (dc.client_is_waiting)
|
||||||
|
@ -95,23 +95,21 @@ struct Decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
~Decoder();
|
~Decoder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current chunk the decoder writes to, or allocates a new
|
||||||
|
* chunk if there is none.
|
||||||
|
*
|
||||||
|
* @return the chunk, or NULL if we have received a decoder command
|
||||||
|
*/
|
||||||
|
music_chunk *GetChunk();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes the current chunk.
|
||||||
|
*
|
||||||
|
* Caller must not lock the #DecoderControl object.
|
||||||
|
*/
|
||||||
|
void FlushChunk();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current chunk the decoder writes to, or allocates a new
|
|
||||||
* chunk if there is none.
|
|
||||||
*
|
|
||||||
* @return the chunk, or NULL if we have received a decoder command
|
|
||||||
*/
|
|
||||||
struct music_chunk *
|
|
||||||
decoder_get_chunk(Decoder &decoder);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flushes the current chunk.
|
|
||||||
*
|
|
||||||
* Caller must not lock the #DecoderControl object.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
decoder_flush_chunk(Decoder &decoder);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -356,7 +356,7 @@ decoder_run_song(DecoderControl &dc,
|
|||||||
/* flush the last chunk */
|
/* flush the last chunk */
|
||||||
|
|
||||||
if (decoder.chunk != nullptr)
|
if (decoder.chunk != nullptr)
|
||||||
decoder_flush_chunk(decoder);
|
decoder.FlushChunk();
|
||||||
|
|
||||||
dc.Lock();
|
dc.Lock();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user