[vlc-devel] h264 packetizer patch (v2)

Rafaël Carré funman at videolan.org
Sun Oct 21 22:50:04 CEST 2012


Hello,

Le 2012-09-28 17:45, Sergio M. Ammirata, Ph.D. a écrit :
> After using the previous patch for a while, I realized that the code in the
> validate function is not required and it actually causes some streams not to
> work. Here is a revised patch without that section.
>
> Also, there is a similar thread from July that died out and which is fixed
> by this patch as well:
> http://mailman.videolan.org/pipermail/vlc-devel/2012-June/088783.html
>
> Comments?
>
> Sergio
>
>
>
>
> h264_packetizer.patch
>
>
>   modules/packetizer/h264.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
>   1 files changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
> index d8072a7..a1cddf7 100644
> --- a/modules/packetizer/h264.c
> +++ b/modules/packetizer/h264.c
> @@ -137,6 +137,11 @@ struct decoder_sys_t
>       cc_data_t cc;
>
>       cc_data_t cc_next;
> +
> +    mtime_t i_last_pts;
> +    mtime_t i_last_dts;
> +    mtime_t i_pts_interval;
> +    mtime_t i_dts_interval;
>   };
>
>   enum nal_unit_type_e
> @@ -213,6 +218,10 @@ static int Open( vlc_object_t *p_this )
>                        p_h264_startcode, 1, 5,
>                        PacketizeReset, PacketizeParse, PacketizeValidate, p_dec );
>
> +    p_sys->i_last_pts = VLC_TS_INVALID;
> +    p_sys->i_last_dts = VLC_TS_INVALID;
> +    p_sys->i_dts_interval = 1;
> +    p_sys->i_pts_interval = 1;
>       p_sys->b_slice = false;
>       p_sys->p_frame = NULL;
>       p_sys->b_frame_sps = false;
> @@ -524,6 +533,11 @@ static void PacketizeReset( void *p_private, bool b_broken )
>       }
>       p_sys->i_frame_pts = VLC_TS_INVALID;
>       p_sys->i_frame_dts = VLC_TS_INVALID;
> +    p_sys->i_last_pts = VLC_TS_INVALID;
> +    p_sys->i_last_dts = VLC_TS_INVALID;
> +    p_sys->i_dts_interval = 1;
> +    p_sys->i_pts_interval = 1;
> +
>   }
>   static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t *p_block )
>   {
> @@ -536,7 +550,7 @@ static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t *p_bl
>       return ParseNALBlock( p_dec, pb_ts_used, p_block );
>   }
>   static int PacketizeValidate( void *p_private, block_t *p_au )
> -{
> +{

Unrelated cosmetics, please remove them (there is another one at the end).

>       VLC_UNUSED(p_private);
>       VLC_UNUSED(p_au);
>       return VLC_SUCCESS;
> @@ -704,10 +718,36 @@ static block_t *ParseNALBlock( decoder_t *p_dec, bool *pb_used_ts, block_t *p_fr
>           }
>       }
>
> +    if( p_frag && i_nal_type == NAL_AU_DELIMITER )
> +    {
> +        /* Correct interpolated dts when we receive a new pts/dts */
> +        if( p_frag->i_pts > VLC_TS_INVALID )
> +        {
> +            if (p_sys->i_last_pts != 0)

Why do you compare to 0 ?

> +                p_sys->i_pts_interval = (p_frag->i_pts - p_sys->i_last_pts)/2;
> +            p_sys->i_last_pts = p_frag->i_pts;
> +        }
> +        if( p_frag->i_dts > VLC_TS_INVALID )
> +        {
> +            if (p_sys->i_last_dts != 0)
> +                p_sys->i_dts_interval = (p_frag->i_dts - p_sys->i_last_dts)/2;
> +            p_sys->i_last_dts = p_frag->i_dts;
> +        }
> +        // Now fix the timestamps if they are broken
> +        if ( p_frag->i_pts <= VLC_TS_INVALID )
> +            p_frag->i_pts = p_sys->i_last_pts + p_sys->i_pts_interval;
> +        if ( p_frag->i_dts <= VLC_TS_INVALID )
> +            p_frag->i_dts = p_sys->i_last_dts + p_sys->i_dts_interval;
> +    }
> +
>       /* Append the block */
>       if( p_frag )
> +    {
> +        if ( p_frag->i_dts == 0 && p_frag->i_pts == 0 && p_frag->i_flags != 0 )

Same question about 0.

> +            msg_Err( p_dec, "h264 packetizer error: dts %llu, pts %llu, p_frag->i_flags %i, i_nal_type %i", p_frag->i_dts, p_frag->i_pts, p_frag->i_flags, i_nal_type );
>           block_ChainAppend( &p_sys->p_frame, p_frag );
> -
> +    }
> +
>       *pb_used_ts = false;
>       if( p_sys->i_frame_dts <= VLC_TS_INVALID &&
>           p_sys->i_frame_pts <= VLC_TS_INVALID )



More information about the vlc-devel mailing list