[vlc-devel] How to set PTS

Sheldon quyadong at hotmail.com
Tue Dec 13 01:23:41 CET 2011


Rafaël Carré <funman <at> videolan.org> writes:

> 
> Le Mon, 12 Dec 2011 15:10:02 +0800,
> 曲亚东 <quyadong <at> hotmail.com> a écrit :
> 
> > 
> > hi all,
> >  
> > Recently I try to write an access-demux module to parse h264 stream from a 
local camera. However,
> Runthread function can't get frame. I stepped into function decodeVideo in
> modules/codec/avcodec/video.c and found that picture have been dropped 
because p_sys->i_pts is 0. So I
> set 400000 to the first frame,  800000 to the second frame, ... and so on, 
but vlc just display the first frame
> and don't enter function demux and decodevideo again. I had read ts.c and 
found PCRHandle function to deal
> with the similar thing, but I can't understand how to transfer pts into 
decode or display. Would you like to
> give me some hint to deal with this issue? 
> 
> try --demux avformat
> 
In my case, if set p_block->i_pts in function Demux, vlc can display an frame 
correctly, Later RunThread always have picture, don't enter function 
DecodeVideo. If don't set this values, can enter DecodeVideo but drop all 
frames. Demux codes just like this:

static int Demux( demux_t *p_demux )
{
    demux_sys_t  *p_sys = p_demux->p_sys;
    block_t      *p_block;
    ssize_t       i_read = 0;

    p_block = block_New( p_demux, MAX_FRAME_BYTES );
    if( p_block == NULL )
        return 0;
    p_block->i_flags = BLOCK_FLAG_TYPE_P;

    // if no data, just wait.
    while( gi_framelength == 0 )
    {
        usleep( 5* 1000 );
    }

    /* copy data from an buffer. */
    if( pthread_mutex_lock( &g_mutex ) != 0 )
        return 0;
    memcpy( p_block->p_buffer, g_framebuffer, gi_framelength );
    p_block->i_buffer = i_read = gi_framelength;
    memset( g_framebuffer, 0, gi_framelength );
    gi_framelength = 0;
    pthread_mutex_unlock( &g_mutex );

   
#if 1
    if (p_sys->i_pts <= 0)
    {
        p_sys->i_pts = 400000;
    }
    else
    {
        p_sys->i_pts += 400000;
    }
    p_block->i_pts = p_sys->i_pts;
#endif
    msg_Err( p_demux, "%s read %d bytes pts %lld", __func__, i_read, p_block-
>i_pts );
    es_out_Send( p_demux->out, p_sys->p_es, p_block );
    if( i_read <= 0 )
    {
        block_Release( p_block );
        return 0;
    }
    return 1;
}







More information about the vlc-devel mailing list