⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpeg4video.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
            /* When starting the stream we can have the first frame with             * a null DTS (i_interpolated_pts is initialized to 0) */            if( !p_pic->i_dts ) p_pic->i_dts = p_pic->i_pts;            /* So p_block doesn't get re-added several times */            *pp_block = block_BytestreamPop( &p_sys->bytestream );            p_sys->i_state = STATE_NOSYNC;            return p_pic;        }    }}/***************************************************************************** * ParseMPEGBlock: Re-assemble fragments into a block containing a picture *****************************************************************************/static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ){    decoder_sys_t *p_sys = p_dec->p_sys;    block_t *p_pic = NULL;    if( p_frag->p_buffer[3] == 0xB0 || p_frag->p_buffer[3] == 0xB1 )    {#if 0        /* Remove VOS start/end code from the original stream */        block_Release( p_frag );#else        /* Append the block for now since ts/ps muxers rely on VOL         * being present in the stream */        block_ChainLastAppend( &p_sys->pp_last, p_frag );#endif        return NULL;    }    if( p_frag->p_buffer[3] >= 0x20 && p_frag->p_buffer[3] <= 0x2f )    {        /* Copy the complete VOL */        if( p_dec->fmt_out.i_extra != p_frag->i_buffer )        {            p_dec->fmt_out.p_extra =                realloc( p_dec->fmt_out.p_extra, p_frag->i_buffer );            p_dec->fmt_out.i_extra = p_frag->i_buffer;        }        memcpy( p_dec->fmt_out.p_extra, p_frag->p_buffer, p_frag->i_buffer );        ParseVOL( p_dec, &p_dec->fmt_out,                  p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );#if 0        /* Remove from the original stream */        block_Release( p_frag );#else        /* Append the block for now since ts/ps muxers rely on VOL         * being present in the stream */        block_ChainLastAppend( &p_sys->pp_last, p_frag );#endif        return NULL;    }    else    {        if( !p_dec->fmt_out.i_extra )        {            msg_Warn( p_dec, "waiting for VOL" );            block_Release( p_frag );            return NULL;        }        /* Append the block */        block_ChainLastAppend( &p_sys->pp_last, p_frag );    }    if( p_frag->p_buffer[3] == 0xb6 &&        ParseVOP( p_dec, p_frag ) == VLC_SUCCESS )    {        /* We are dealing with a VOP */        p_pic = block_ChainGather( p_sys->p_frame );        p_pic->i_pts = p_sys->i_interpolated_pts;        p_pic->i_dts = p_sys->i_interpolated_dts;        /* Reset context */        p_sys->p_frame = NULL;        p_sys->pp_last = &p_sys->p_frame;    }    return p_pic;}/* ParseVOL: *  TODO: *      - support aspect ratio */static int ParseVOL( decoder_t *p_dec, es_format_t *fmt,                     uint8_t *p_vol, int i_vol ){    decoder_sys_t *p_sys = p_dec->p_sys;    int i_vo_type, i_vo_ver_id, i_ar, i_shape;    bs_t s;    for( ;; )    {        if( p_vol[0] == 0x00 && p_vol[1] == 0x00 && p_vol[2] == 0x01 &&            p_vol[3] >= 0x20 && p_vol[3] <= 0x2f ) break;        p_vol++; i_vol--;        if( i_vol <= 4 ) return VLC_EGENERIC;    }    bs_init( &s, &p_vol[4], i_vol - 4 );    bs_skip( &s, 1 );   /* random access */    i_vo_type = bs_read( &s, 8 );    if( bs_read1( &s ) )    {        i_vo_ver_id = bs_read( &s, 4 );        bs_skip( &s, 3 );    }    else    {        i_vo_ver_id = 1;    }    i_ar = bs_read( &s, 4 );    if( i_ar == 0xf )    {        int i_ar_width, i_ar_height;        i_ar_width = bs_read( &s, 8 );        i_ar_height= bs_read( &s, 8 );    }    if( bs_read1( &s ) )    {        int i_chroma_format;        int i_low_delay;        /* vol control parameter */        i_chroma_format = bs_read( &s, 2 );        i_low_delay = bs_read1( &s );        if( bs_read1( &s ) )        {            bs_skip( &s, 16 );            bs_skip( &s, 16 );            bs_skip( &s, 16 );            bs_skip( &s, 3 );            bs_skip( &s, 11 );            bs_skip( &s, 1 );            bs_skip( &s, 16 );        }    }    /* shape 0->RECT, 1->BIN, 2->BIN_ONLY, 3->GRAY */    i_shape = bs_read( &s, 2 );    if( i_shape == 3 && i_vo_ver_id != 1 )    {        bs_skip( &s, 4 );    }    if( !bs_read1( &s ) ) return VLC_EGENERIC; /* Marker */    p_sys->i_fps_num = bs_read( &s, 16 ); /* Time increment resolution*/    if( !p_sys->i_fps_num ) p_sys->i_fps_num = 1;    if( !bs_read1( &s ) ) return VLC_EGENERIC; /* Marker */    if( bs_read1( &s ) )    {        int i_time_increment_bits = vlc_log2( p_sys->i_fps_num - 1 ) + 1;        if( i_time_increment_bits < 1 ) i_time_increment_bits = 1;        p_sys->i_fps_den = bs_read( &s, i_time_increment_bits );    }    if( i_shape == 0 )    {        bs_skip( &s, 1 );        fmt->video.i_width = bs_read( &s, 13 );        bs_skip( &s, 1 );        fmt->video.i_height= bs_read( &s, 13 );        bs_skip( &s, 1 );    }    return VLC_SUCCESS;}static int ParseVOP( decoder_t *p_dec, block_t *p_vop ){    decoder_sys_t *p_sys = p_dec->p_sys;    int64_t i_time_increment, i_time_ref;    int i_modulo_time_base = 0, i_time_increment_bits;    bs_t s;    bs_init( &s, &p_vop->p_buffer[4], p_vop->i_buffer - 4 );    switch( bs_read( &s, 2 ) )    {    case 0:        p_sys->i_flags = BLOCK_FLAG_TYPE_I;        break;    case 1:        p_sys->i_flags = BLOCK_FLAG_TYPE_P;        break;    case 2:        p_sys->i_flags = BLOCK_FLAG_TYPE_B;        p_sys->b_frame = VLC_TRUE;        break;    case 3: /* gni ? */        p_sys->i_flags = BLOCK_FLAG_TYPE_PB;        break;    }    while( bs_read( &s, 1 ) ) i_modulo_time_base++;    if( !bs_read1( &s ) ) return VLC_EGENERIC; /* Marker */    /* VOP time increment */    i_time_increment_bits = vlc_log2(p_dec->p_sys->i_fps_num - 1) + 1;    if( i_time_increment_bits < 1 ) i_time_increment_bits = 1;    i_time_increment = bs_read( &s, i_time_increment_bits );    /* Interpolate PTS/DTS */    if( !(p_sys->i_flags & BLOCK_FLAG_TYPE_B) )    {        p_sys->i_last_time_ref = p_sys->i_time_ref;        p_sys->i_time_ref +=            (i_modulo_time_base * p_dec->p_sys->i_fps_num);        i_time_ref = p_sys->i_time_ref;    }    else    {        i_time_ref = p_sys->i_last_time_ref +            (i_modulo_time_base * p_dec->p_sys->i_fps_num);    }#if 0    msg_Err( p_dec, "interp pts/dts (%lli,%lli), pts/dts (%lli,%lli)",             p_sys->i_interpolated_pts, p_sys->i_interpolated_dts,             p_vop->i_pts, p_vop->i_dts );#endif    if( p_dec->p_sys->i_fps_num < 5 && /* Work-around buggy streams */        p_dec->fmt_in.video.i_frame_rate > 0 &&        p_dec->fmt_in.video.i_frame_rate_base > 0 )    {        p_sys->i_interpolated_pts += I64C(1000000) *        p_dec->fmt_in.video.i_frame_rate_base *        p_vop->i_rate / INPUT_RATE_DEFAULT /        p_dec->fmt_in.video.i_frame_rate;    }    else if( p_dec->p_sys->i_fps_num )        p_sys->i_interpolated_pts +=            ( I64C(1000000) * (i_time_ref + i_time_increment -              p_sys->i_last_time - p_sys->i_last_timeincr) *              p_vop->i_rate / INPUT_RATE_DEFAULT /              p_dec->p_sys->i_fps_num );    p_sys->i_last_time = i_time_ref;    p_sys->i_last_timeincr = i_time_increment;    /* Correct interpolated dts when we receive a new pts/dts */    if( p_vop->i_pts > 0 )        p_sys->i_interpolated_pts = p_vop->i_pts;    if( p_vop->i_dts > 0 )        p_sys->i_interpolated_dts = p_vop->i_dts;    if( (p_sys->i_flags & BLOCK_FLAG_TYPE_B) || !p_sys->b_frame )    {        /* Trivial case (DTS == PTS) */        p_sys->i_interpolated_dts = p_sys->i_interpolated_pts;        if( p_vop->i_pts > 0 )            p_sys->i_interpolated_dts = p_vop->i_pts;        if( p_vop->i_dts > 0 )            p_sys->i_interpolated_dts = p_vop->i_dts;        p_sys->i_interpolated_pts = p_sys->i_interpolated_dts;    }    else    {        if( p_sys->i_last_ref_pts > 0 )            p_sys->i_interpolated_dts = p_sys->i_last_ref_pts;        p_sys->i_last_ref_pts = p_sys->i_interpolated_pts;    }    return VLC_SUCCESS;}/* look at ffmpeg av_log2 ;) */static int vlc_log2( unsigned int v ){    int n = 0;    static const int vlc_log2_table[16] =    {        0,0,1,1,2,2,2,2, 3,3,3,3,3,3,3,3    };    if( v&0xffff0000 )    {        v >>= 16;        n += 16;    }    if( v&0xff00 )    {        v >>= 8;        n += 8;    }    if( v&0xf0 )    {        v >>= 4;        n += 4;    }    n += vlc_log2_table[v];    return n;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -