2 * Copyright (C) 2003-2009 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "decoder_internal.h"
21 #include "decoder_control.h"
22 #include "player_control.h"
24 #include "input_stream.h"
31 * This is a wrapper for input_stream_buffer(). It assumes that the
32 * decoder is currently locked, and temporarily unlocks it while
33 * calling input_stream_buffer(). We shouldn't hold the lock during a
34 * potentially blocking operation.
37 decoder_input_buffer(struct input_stream
*is
)
42 ret
= input_stream_buffer(is
) > 0;
49 * All chunks are full of decoded data; wait for the player to free
52 static enum decoder_command
53 need_chunks(struct input_stream
*is
, bool do_wait
)
55 if (dc
.command
== DECODE_COMMAND_STOP
||
56 dc
.command
== DECODE_COMMAND_SEEK
)
59 if ((is
== NULL
|| decoder_input_buffer(is
) <= 0) && do_wait
) {
63 notify_signal(&pc
.notify
);
69 return DECODE_COMMAND_NONE
;
73 decoder_get_chunk(struct decoder
*decoder
, struct input_stream
*is
)
75 enum decoder_command cmd
;
77 assert(decoder
!= NULL
);
79 if (decoder
->chunk
!= NULL
)
80 return decoder
->chunk
;
83 decoder
->chunk
= music_buffer_allocate(dc
.buffer
);
84 if (decoder
->chunk
!= NULL
)
85 return decoder
->chunk
;
88 cmd
= need_chunks(is
, true);
90 } while (cmd
== DECODE_COMMAND_NONE
);
96 decoder_flush_chunk(struct decoder
*decoder
)
98 assert(decoder
!= NULL
);
99 assert(decoder
->chunk
!= NULL
);
101 if (music_chunk_is_empty(decoder
->chunk
))
102 music_buffer_return(dc
.buffer
, decoder
->chunk
);
104 music_pipe_push(dc
.pipe
, decoder
->chunk
);
106 decoder
->chunk
= NULL
;