[vlc-devel] [PATCH 2/4] decoder: add decoder_QueueAudio
Thomas Guillem
thomas at gllm.fr
Thu Dec 3 10:51:24 CET 2015
This function allow asynchronous decoders to queue an audio block to the audio
output. Decoders that use this function should return NULL in pf_decode_audio
callback.
---
include/vlc_codec.h | 18 ++++++++++++
src/input/decoder.c | 83 +++++++++++++++++++++++++++++++++++++----------------
2 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index b5170f7..96fd1e9 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -123,6 +123,8 @@ struct decoder_t
/* XXX use decoder_QueueVideo */
int (*pf_queue_video)( decoder_t *, picture_t * );
+ /* XXX use decoder_QueueAudio */
+ int (*pf_queue_audio)( decoder_t *, block_t * );
/* Private structure for the owner of the decoder */
decoder_owner_sys_t *p_owner;
@@ -259,6 +261,22 @@ static inline int decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
}
/**
+ * This function queues an audio block to the audio output.
+ *
+ * \note
+ * The caller doesn't own the audio block anymore after this call (even in case
+ * of error).
+ *
+ * \return 0 if the block is queued, -1 on error
+ */
+static inline int decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
+{
+ if( !dec->pf_queue_audio )
+ return -1;
+ return dec->pf_queue_audio( dec, p_aout_buf );
+}
+
+/**
* This function notifies the audio output pipeline of a new audio output
* format (fmt_out.audio). If there is currently no audio output or if the
* audio output format has changed, a new audio output will be set up.
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 9b04df3..ec4fefe 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1069,40 +1069,36 @@ static void DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
*pi_lost_sum += aout_DecGetResetLost( p_aout );
}
-static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
+static int DecoderPreparePlayAudio( decoder_t *p_dec, block_t *p_aout_buf )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
- block_t *p_aout_buf;
- int i_decoded = 0;
- int i_lost = 0;
- int i_played = 0;
- while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
+ if( p_owner->i_preroll_end > VLC_TS_INVALID &&
+ p_aout_buf->i_pts < p_owner->i_preroll_end )
{
- i_decoded++;
+ block_Release( p_aout_buf );
+ return -1;
+ }
- if( p_owner->i_preroll_end > VLC_TS_INVALID &&
- p_aout_buf->i_pts < p_owner->i_preroll_end )
- {
- block_Release( p_aout_buf );
- continue;
- }
+ if( p_owner->i_preroll_end > VLC_TS_INVALID )
+ {
+ msg_Dbg( p_dec, "End of audio preroll" );
+ if( p_owner->p_aout )
+ aout_DecFlush( p_owner->p_aout, false );
+ /* */
+ p_owner->i_preroll_end = VLC_TS_INVALID;
+ }
- if( p_owner->i_preroll_end > VLC_TS_INVALID )
- {
- msg_Dbg( p_dec, "End of audio preroll" );
- if( p_owner->p_aout )
- aout_DecFlush( p_owner->p_aout, false );
- /* */
- p_owner->i_preroll_end = VLC_TS_INVALID;
- }
+ return 0;
+}
- DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
- }
+static void DecoderUpdateStatAudio( decoder_t *p_dec, int i_decoded,
+ int i_lost, int i_played )
+{
+ decoder_owner_sys_t *p_owner = p_dec->p_owner;
+ input_thread_t *p_input = p_owner->p_input;
/* Update ugly stat */
- input_thread_t *p_input = p_owner->p_input;
-
if( p_input != NULL && (i_decoded > 0 || i_lost > 0 || i_played > 0) )
{
vlc_mutex_lock( &p_input->p->counters.counters_lock);
@@ -1113,6 +1109,42 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
}
}
+static int DecoderQueueAudio( decoder_t *p_dec, block_t *p_aout_buf )
+{
+ assert( p_aout_buf );
+ int i_lost = 0;
+ int i_played = 0;
+
+ if( DecoderPreparePlayAudio( p_dec, p_aout_buf ) != 0 )
+ return -1;
+
+ DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
+
+ DecoderUpdateStatAudio( p_dec, 1, i_lost, i_played );
+
+ return 0;
+}
+
+static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
+{
+ block_t *p_aout_buf;
+ int i_decoded = 0;
+ int i_lost = 0;
+ int i_played = 0;
+
+ while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
+ {
+ i_decoded++;
+
+ if( DecoderPreparePlayAudio( p_dec, p_aout_buf ) != 0 )
+ continue;
+
+ DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
+ }
+
+ DecoderUpdateStatAudio( p_dec, i_decoded, i_lost, i_played );
+}
+
/* This function process a audio block
*/
static void DecoderProcessAudio( decoder_t *p_dec, block_t *p_block )
@@ -1541,6 +1573,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
p_dec->pf_get_display_date = DecoderGetDisplayDate;
p_dec->pf_get_display_rate = DecoderGetDisplayRate;
p_dec->pf_queue_video = DecoderQueueVideo;
+ p_dec->pf_queue_audio = DecoderQueueAudio;
/* Load a packetizer module if the input is not already packetized */
if( p_sout == NULL && !fmt->b_packetized )
--
2.1.4
More information about the vlc-devel
mailing list