diff options
Diffstat (limited to 'src/decoder_internal.c')
-rw-r--r-- | src/decoder_internal.c | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/decoder_internal.c b/src/decoder_internal.c index bc349f2f..30089d17 100644 --- a/src/decoder_internal.c +++ b/src/decoder_internal.c @@ -48,49 +48,31 @@ need_chunks(struct decoder_control *dc, bool do_wait) return DECODE_COMMAND_NONE; } -struct music_chunk * -decoder_get_chunk(struct decoder *decoder) +struct music_chunk *decoder_get_chunk(struct decoder *decoder) { - struct decoder_control *dc = decoder->dc; - enum decoder_command cmd; + struct decoder_control *dc = decoder->dc; + struct music_chunk *chunk; + enum decoder_command cmd; - assert(decoder != NULL); + assert(decoder != NULL); - if (decoder->chunk != NULL) - return decoder->chunk; + do { + if (music_pipe_size(dc->pipe) >= dc->buffer_samples) { + chunk = music_chunk_alloc(); + if (!chunk) + return NULL; - do { - decoder->chunk = music_buffer_allocate(dc->buffer); - if (decoder->chunk != NULL) { - decoder->chunk->replay_gain_serial = - decoder->replay_gain_serial; - if (decoder->replay_gain_serial != 0) - decoder->chunk->replay_gain_info = - decoder->replay_gain_info; + chunk->replay_gain_serial = decoder->replay_gain_serial; + if (decoder->replay_gain_serial != 0) + chunk->replay_gain_info = decoder->replay_gain_info; - return decoder->chunk; - } + return chunk; + } - decoder_lock(dc); - cmd = need_chunks(dc, true); - decoder_unlock(dc); - } while (cmd == DECODE_COMMAND_NONE); + decoder_lock(dc); + cmd = need_chunks(dc, true); + decoder_unlock(dc); + } while (cmd == DECODE_COMMAND_NONE); - return NULL; -} - -void -decoder_flush_chunk(struct decoder *decoder) -{ - struct decoder_control *dc = decoder->dc; - - assert(decoder != NULL); - assert(decoder->chunk != NULL); - - if (music_chunk_is_empty(decoder->chunk)) - music_buffer_return(dc->buffer, decoder->chunk); - else - music_pipe_push(dc->pipe, decoder->chunk); - - decoder->chunk = NULL; + return NULL; } |