[vlc-devel] [PATCH 1/3] mpeg/es demuxer : get last block out of the packetizer
Laurent Aimar
fenrir at elivagar.org
Tue Sep 13 23:04:55 CEST 2011
Hi,
On Fri, Sep 09, 2011 at 03:02:39PM +0200, Rafaël Carré wrote:
> diff --git a/modules/demux/mpeg/es.c b/modules/demux/mpeg/es.c
> index a66f9f6..ff1fd94 100644
> --- a/modules/demux/mpeg/es.c
> +++ b/modules/demux/mpeg/es.c
> @@ -208,7 +208,7 @@ static int OpenCommon( demux_t *p_demux,
>
> while( vlc_object_alive( p_demux ) )
> {
> - if( Parse( p_demux, &p_sys->p_packetized_data ) )
> + if( Parse( p_demux, &p_sys->p_packetized_data ) != 1 )
> break;
> if( p_sys->p_packetized_data )
> break;
> @@ -256,13 +256,14 @@ static int OpenVideo( vlc_object_t *p_this )
> *****************************************************************************/
> static int Demux( demux_t *p_demux )
> {
> + int ret = 1;
> demux_sys_t *p_sys = p_demux->p_sys;
>
> block_t *p_block_out = p_sys->p_packetized_data;
> if( p_block_out )
> p_sys->p_packetized_data = NULL;
> - else if( Parse( p_demux, &p_block_out ) )
> - return 0;
> + else
> + ret = Parse( p_demux, &p_block_out );
>
> while( p_block_out )
> {
> @@ -302,7 +303,7 @@ static int Demux( demux_t *p_demux )
>
> p_block_out = p_next;
> }
> - return 1;
> + return ret;
> }
>
> /*****************************************************************************
> @@ -393,7 +394,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
> }
>
> /*****************************************************************************
> - * Returned a link list of buffer of parsed data
> + * Makes a link list of buffer of parsed data
> + * Returns 0 in case of EOF, 1 otherwise
I am not sure it makes the code more readable, but it won't prevent
the patch from being commited.
> *****************************************************************************/
> static int Parse( demux_t *p_demux, block_t **pp_output )
> {
> @@ -410,9 +412,10 @@ static int Parse( demux_t *p_demux, block_t **pp_output )
> stream_Read( p_demux->s, NULL, 1 );
> }
>
> - if( ( p_block_in = stream_Block( p_demux->s, p_sys->i_packet_size ) ) == NULL )
> - return VLC_EGENERIC;
> + p_block_in = stream_Block( p_demux->s, p_sys->i_packet_size );
>
> + if( p_block_in )
> + {
> if( p_sys->codec.b_use_word && !p_sys->b_big_endian && p_block_in->i_buffer > 0 )
> {
> /* Convert to big endian */
> @@ -420,9 +423,9 @@ static int Parse( demux_t *p_demux, block_t **pp_output )
> }
>
> p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start || p_sys->b_initial_sync_failed ? VLC_TS_0 : VLC_TS_INVALID;
> + }
> p_sys->b_initial_sync_failed = p_sys->b_start; /* Only try to resync once */
> -
> - while( ( p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in ) ) )
> + while( ( p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, p_block_in ? &p_block_in : NULL ) ) )
> {
> p_sys->b_initial_sync_failed = false;
> while( p_block_out )
> @@ -459,10 +462,13 @@ static int Parse( demux_t *p_demux, block_t **pp_output )
> }
> }
>
> + if( !p_block_in )
> + return 0; // EOF
You cannot test p_block_in once you call p_packetizer->pf_packetize() on it
as the packetizer could set it to whatever it wants. You probably need to
save the result of the test just after the stream_Block() call.
Regards,
--
fenrir
More information about the vlc-devel
mailing list