[vlc-devel] commit: Refactor DecoderDecode(). (Jean-Paul Saman )
git version control
git at videolan.org
Mon Nov 24 15:06:37 CET 2008
vlc | branch: 0.8.6-bugfix | Jean-Paul Saman <jpsaman at videolan.org> | Thu Nov 13 19:02:37 2008 +0100| [8d04fd2cd71d5f07e6a65a83b990a8f1db9f27be] | committer: Jean-Paul Saman
Refactor DecoderDecode().
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d04fd2cd71d5f07e6a65a83b990a8f1db9f27be
---
src/input/decoder.c | 157 ++++++++++++++++++++++++++++-----------------------
1 files changed, 87 insertions(+), 70 deletions(-)
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 53e90e3..d185e47 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -2,7 +2,7 @@
* decoder.c: Functions for the management of decoders
*****************************************************************************
* Copyright (C) 1999-2004 the VideoLAN team
- * $Id$
+ * $Id: 53e90e362d4150b89e6de62b683454e6118f4dc2 $
*
* Authors: Christophe Massiot <massiot at via.ecp.fr>
* Gildas Bazin <gbazin at videolan.org>
@@ -42,6 +42,9 @@ static void DeleteDecoder( decoder_t * );
static int DecoderThread( decoder_t * );
static int DecoderDecode( decoder_t * p_dec, block_t *p_block );
+static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block );
+static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block );
+
/* Buffers allocation callbacks for the decoders */
static aout_buffer_t *aout_new_buffer( decoder_t *, int );
static void aout_del_buffer( decoder_t *, aout_buffer_t * );
@@ -511,6 +514,79 @@ static int DecoderThread( decoder_t * p_dec )
return 0;
}
+static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p_block )
+{
+ if( p_block->i_flags & (BLOCK_FLAG_PREROLL|BLOCK_FLAG_DISCONTINUITY) )
+ *pi_preroll = INT64_MAX;
+ else if( p_block->i_pts > 0 )
+ *pi_preroll = __MIN( *pi_preroll, p_block->i_pts );
+ else if( p_block->i_dts > 0 )
+ *pi_preroll = __MIN( *pi_preroll, p_block->i_dts );
+}
+
+static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
+{
+ aout_buffer_t *p_aout_buf;
+
+ while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
+ {
+ aout_instance_t *p_aout = p_dec->p_owner->p_aout;
+ aout_input_t *p_aout_input = p_dec->p_owner->p_aout_input;
+
+ if( p_dec->b_die )
+ {
+ aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
+ if( p_block )
+ block_Release( p_block );
+ break;
+ }
+
+ stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_AUDIO, 1, NULL );
+
+ /* FIXME the best would be to handle the case start_date < preroll < end_date
+ * but that's not easy with non raw audio stream */
+ if( p_dec->p_owner->i_preroll_end > 0 &&
+ p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
+ {
+ aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
+ continue;
+ }
+ p_dec->p_owner->i_preroll_end = -1;
+ aout_DecPlay( p_aout, p_aout_input, p_aout_buf );
+ }
+}
+
+static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
+{
+ picture_t *p_pic;
+
+ while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
+ {
+ vout_thread_t *p_vout = p_dec->p_owner->p_vout;
+ if( p_dec->b_die )
+ {
+ vout_DestroyPicture( p_vout, p_pic );
+ if( p_block )
+ block_Release( p_block );
+ break;
+ }
+
+ stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO, 1, NULL );
+
+ if( p_dec->p_owner->i_preroll_end > 0 &&
+ p_pic->date < p_dec->p_owner->i_preroll_end )
+ {
+ vout_DestroyPicture( p_vout, p_pic );
+ continue;
+ }
+
+ p_dec->p_owner->i_preroll_end = -1;
+
+ vout_DatePicture( p_vout, p_pic, p_pic->date );
+ vout_DisplayPicture( p_vout, p_pic );
+ }
+}
+
/**
* Decode a block
*
@@ -599,7 +675,8 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
}
else if( p_dec->fmt_in.i_cat == AUDIO_ES )
{
- aout_buffer_t *p_aout_buf;
+ if( p_block )
+ DecoderUpdatePreroll( &p_dec->p_owner->i_preroll_end, p_block );
if( p_dec->p_owner->p_packetizer )
{
@@ -621,53 +698,21 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
p_packetized_block->p_next = NULL;
p_packetized_block->i_rate = i_rate;
- while( (p_aout_buf = p_dec->pf_decode_audio( p_dec,
- &p_packetized_block )) )
- {
- stats_UpdateInteger( p_dec->p_parent,
- STATS_DECODED_AUDIO, 1, NULL );
- /* FIXME the best would be to handle the case start_date < preroll < end_date
- * but that's not easy with non raw audio stream */
- if( p_dec->p_owner->i_preroll_end > 0 &&
- p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
- {
- aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
- p_dec->p_owner->p_aout_input, p_aout_buf );
- }
- else
- {
- p_dec->p_owner->i_preroll_end = -1;
- aout_DecPlay( p_dec->p_owner->p_aout,
- p_dec->p_owner->p_aout_input,
- p_aout_buf );
- }
- }
+ DecoderDecodeAudio( p_dec, p_packetized_block);
p_packetized_block = p_next;
}
}
}
- else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
+ else if( p_block )
{
- stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_AUDIO, 1, NULL );
- if( p_dec->p_owner->i_preroll_end > 0 &&
- p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
- {
- aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
- p_dec->p_owner->p_aout_input, p_aout_buf );
- }
- else
- {
- p_dec->p_owner->i_preroll_end = -1;
- aout_DecPlay( p_dec->p_owner->p_aout,
- p_dec->p_owner->p_aout_input,
- p_aout_buf );
- }
+ DecoderDecodeAudio( p_dec, p_block );
}
}
else if( p_dec->fmt_in.i_cat == VIDEO_ES )
{
- picture_t *p_pic;
+ if( p_block )
+ DecoderUpdatePreroll( &p_dec->p_owner->i_preroll_end, p_block );
if( p_dec->p_owner->p_packetizer )
{
@@ -689,43 +734,15 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
p_packetized_block->p_next = NULL;
p_packetized_block->i_rate = i_rate;
- while( (p_pic = p_dec->pf_decode_video( p_dec,
- &p_packetized_block )) )
- {
- stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO,
- 1, NULL );
- if( p_dec->p_owner->i_preroll_end > 0 &&
- p_pic->date < p_dec->p_owner->i_preroll_end )
- {
- vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
- }
- else
- {
- p_dec->p_owner->i_preroll_end = -1;
- vout_DatePicture( p_dec->p_owner->p_vout, p_pic,
- p_pic->date );
- vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
- }
- }
+ DecoderDecodeVideo( p_dec, p_packetized_block );
p_packetized_block = p_next;
}
}
}
- else while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
+ else if( p_block )
{
- stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO, 1 , NULL);
- if( p_dec->p_owner->i_preroll_end > 0 &&
- p_pic->date < p_dec->p_owner->i_preroll_end )
- {
- vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
- }
- else
- {
- p_dec->p_owner->i_preroll_end = -1;
- vout_DatePicture( p_dec->p_owner->p_vout, p_pic, p_pic->date );
- vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
- }
+ DecoderDecodeVideo( p_dec, p_block );
}
}
else if( p_dec->fmt_in.i_cat == SPU_ES )
More information about the vlc-devel
mailing list