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

📄 ogg.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
                    p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )                {                    if( ogg_stream_packetout( &p_stream->os, &oggpacket ) > 0 )                    {                        Ogg_DecodePacket( p_demux, p_stream, &oggpacket );                    }                    else                    {                        es_out_Control( p_demux->out, ES_OUT_SET_PCR,                                        p_stream->i_pcr );                    }                    continue;                }            }            Ogg_DecodePacket( p_demux, p_stream, &oggpacket );        }        break;    }    i_stream = 0; p_sys->i_pcr = -1;    for( ; i_stream < p_sys->i_streams; i_stream++ )    {        logical_stream_t *p_stream = p_sys->pp_stream[i_stream];        if( p_stream->fmt.i_cat == SPU_ES )            continue;        if( p_stream->i_interpolated_pcr < 0 )            continue;        if( p_sys->i_pcr < 0 || p_stream->i_interpolated_pcr < p_sys->i_pcr )            p_sys->i_pcr = p_stream->i_interpolated_pcr;    }    if( p_sys->i_pcr >= 0 )    {        es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );    }    return 1;}/***************************************************************************** * Control: *****************************************************************************/static int Control( demux_t *p_demux, int i_query, va_list args ){    demux_sys_t *p_sys  = p_demux->p_sys;    int64_t *pi64;    bool *pb_bool;    int i;    switch( i_query )    {        case DEMUX_HAS_UNSUPPORTED_META:            pb_bool = (bool*)va_arg( args, bool* );            *pb_bool = true;            return VLC_SUCCESS;        case DEMUX_GET_TIME:            pi64 = (int64_t*)va_arg( args, int64_t * );            *pi64 = p_sys->i_pcr;            return VLC_SUCCESS;        case DEMUX_SET_TIME:            return VLC_EGENERIC;        case DEMUX_SET_POSITION:            for( i = 0; i < p_sys->i_streams; i++ )            {                logical_stream_t *p_stream = p_sys->pp_stream[i];                /* we'll trash all the data until we find the next pcr */                p_stream->b_reinit = 1;                p_stream->i_pcr = -1;                p_stream->i_interpolated_pcr = -1;                ogg_stream_reset( &p_stream->os );            }            ogg_sync_reset( &p_sys->oy );        default:            return demux_vaControlHelper( p_demux->s, 0, -1, p_sys->i_bitrate,                                           1, i_query, args );    }}/**************************************************************************** * Ogg_ReadPage: Read a full Ogg page from the physical bitstream. **************************************************************************** * Returns VLC_SUCCESS if a page has been read. An error might happen if we * are at the end of stream. ****************************************************************************/static int Ogg_ReadPage( demux_t *p_demux, ogg_page *p_oggpage ){    demux_sys_t *p_ogg = p_demux->p_sys  ;    int i_read = 0;    char *p_buffer;    while( ogg_sync_pageout( &p_ogg->oy, p_oggpage ) != 1 )    {        p_buffer = ogg_sync_buffer( &p_ogg->oy, OGG_BLOCK_SIZE );        i_read = stream_Read( p_demux->s, p_buffer, OGG_BLOCK_SIZE );        if( i_read <= 0 )            return VLC_EGENERIC;        ogg_sync_wrote( &p_ogg->oy, i_read );    }    return VLC_SUCCESS;}/**************************************************************************** * Ogg_UpdatePCR: update the PCR (90kHz program clock reference) for the *                current stream. ****************************************************************************/static void Ogg_UpdatePCR( logical_stream_t *p_stream,                           ogg_packet *p_oggpacket ){    /* Convert the granulepos into a pcr */    if( p_oggpacket->granulepos >= 0 )    {        if( p_stream->fmt.i_codec == VLC_FOURCC( 't','h','e','o' ) ||            p_stream->fmt.i_codec == VLC_FOURCC( 'k','a','t','e' ) )        {            ogg_int64_t iframe = p_oggpacket->granulepos >>              p_stream->i_granule_shift;            ogg_int64_t pframe = p_oggpacket->granulepos -              ( iframe << p_stream->i_granule_shift );            p_stream->i_pcr = ( iframe + pframe ) * INT64_C(1000000)                              / p_stream->f_rate;        }        else if( p_stream->fmt.i_codec == VLC_FOURCC( 'd','r','a','c' ) )        {            ogg_int64_t i_dts = p_oggpacket->granulepos >> 31;            /* NB, OggDirac granulepos values are in units of 2*picturerate */            p_stream->i_pcr = (i_dts/2) * INT64_C(1000000) / p_stream->f_rate;        }        else        {            p_stream->i_pcr = p_oggpacket->granulepos * INT64_C(1000000)                              / p_stream->f_rate;        }        p_stream->i_interpolated_pcr = p_stream->i_pcr;    }    else    {        p_stream->i_pcr = -1;        /* no granulepos available, try to interpolate the pcr.         * If we can't then don't touch the old value. */        if( p_stream->fmt.i_cat == VIDEO_ES )            /* 1 frame per packet */            p_stream->i_interpolated_pcr += (INT64_C(1000000) / p_stream->f_rate);        else if( p_stream->fmt.i_bitrate )            p_stream->i_interpolated_pcr +=                ( p_oggpacket->bytes * INT64_C(1000000) /                  p_stream->fmt.i_bitrate / 8 );    }}/**************************************************************************** * Ogg_DecodePacket: Decode an Ogg packet. ****************************************************************************/static void Ogg_DecodePacket( demux_t *p_demux,                              logical_stream_t *p_stream,                              ogg_packet *p_oggpacket ){    block_t *p_block;    bool b_selected;    int i_header_len = 0;    mtime_t i_pts = -1, i_interpolated_pts;    /* Sanity check */    if( !p_oggpacket->bytes )    {        msg_Dbg( p_demux, "discarding 0 sized packet" );        return;    }    if( p_oggpacket->bytes >= 7 &&        ! memcmp ( p_oggpacket->packet, "Annodex", 7 ) )    {        /* it's an Annodex packet -- skip it (do nothing) */        return;    }    else if( p_oggpacket->bytes >= 7 &&        ! memcmp ( p_oggpacket->packet, "AnxData", 7 ) )    {        /* it's an AnxData packet -- skip it (do nothing) */        return;    }    if( p_stream->fmt.i_codec == VLC_FOURCC( 's','u','b','t' ) &&        p_oggpacket->packet[0] & PACKET_TYPE_BITS ) return;    /* Check the ES is selected */    es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,                    p_stream->p_es, &b_selected );    if( p_stream->b_force_backup )    {        uint8_t *p_sav;        bool b_store_size = true;        bool b_store_num_headers = false;        p_stream->i_packets_backup++;        switch( p_stream->fmt.i_codec )        {        case VLC_FOURCC( 'v','o','r','b' ):        case VLC_FOURCC( 's','p','x',' ' ):        case VLC_FOURCC( 't','h','e','o' ):            if( p_stream->i_packets_backup == 3 ) p_stream->b_force_backup = 0;            break;        case VLC_FOURCC( 'f','l','a','c' ):            if( !p_stream->fmt.audio.i_rate && p_stream->i_packets_backup == 2 )            {                Ogg_ReadFlacHeader( p_demux, p_stream, p_oggpacket );                p_stream->b_force_backup = 0;            }            else if( p_stream->fmt.audio.i_rate )            {                p_stream->b_force_backup = 0;                if( p_oggpacket->bytes >= 9 )                {                    p_oggpacket->packet += 9;                    p_oggpacket->bytes -= 9;                }            }            b_store_size = false;            break;        case VLC_FOURCC( 'k','a','t','e' ):            if( p_stream->i_packets_backup == 1)                b_store_num_headers = true;            if( p_stream->i_packets_backup == p_stream->i_kate_num_headers ) p_stream->b_force_backup = 0;            break;        default:            p_stream->b_force_backup = 0;            break;        }        /* Backup the ogg packet (likely an header packet) */        p_stream->p_headers =            realloc( p_sav = p_stream->p_headers, p_stream->i_headers +                     p_oggpacket->bytes + (b_store_size ? 2 : 0) + (b_store_num_headers ? 1 : 0) );        if( p_stream->p_headers )        {            uint8_t *p_extra = p_stream->p_headers + p_stream->i_headers;            if( b_store_num_headers )            {                /* Kate streams store the number of headers in the first header,                   so we can't just test for 3 as Vorbis/Theora */                *(p_extra++) = p_stream->i_kate_num_headers;            }            if( b_store_size )            {                *(p_extra++) = p_oggpacket->bytes >> 8;                *(p_extra++) = p_oggpacket->bytes & 0xFF;            }            memcpy( p_extra, p_oggpacket->packet, p_oggpacket->bytes );            p_stream->i_headers += p_oggpacket->bytes + (b_store_size ? 2 : 0) + (b_store_num_headers ? 1 : 0);            if( !p_stream->b_force_backup )            {                /* Last header received, commit changes */                free( p_stream->fmt.p_extra );                p_stream->fmt.i_extra = p_stream->i_headers;                p_stream->fmt.p_extra =                    realloc( p_stream->fmt.p_extra, p_stream->i_headers );                if( p_stream->fmt.p_extra )                    memcpy( p_stream->fmt.p_extra, p_stream->p_headers,                            p_stream->i_headers );                else                    p_stream->fmt.i_extra = 0;                if( Ogg_LogicalStreamResetEsFormat( p_demux, p_stream ) )                    es_out_Control( p_demux->out, ES_OUT_SET_FMT,                                    p_stream->p_es, &p_stream->fmt );            }        }        else        {                p_stream->p_headers = p_sav;        }        b_selected = false; /* Discard the header packet */    }    /* Convert the pcr into a pts */    if( p_stream->fmt.i_codec == VLC_FOURCC( 'v','o','r','b' ) ||        p_stream->fmt.i_codec == VLC_FOURCC( 's','p','x',' ' ) ||        p_stream->fmt.i_codec == VLC_FOURCC( 'f','l','a','c' ) )    {        if( p_stream->i_pcr >= 0 )        {            /* This is for streams where the granulepos of the header packets             * doesn't match these of the data packets (eg. ogg web radios). */            if( p_stream->i_previous_pcr == 0 &&                p_stream->i_pcr  > 3 * DEFAULT_PTS_DELAY )            {                es_out_Control( p_demux->out, ES_OUT_RESET_PCR );                /* Call the pace control */                es_out_Control( p_demux->out, ES_OUT_SET_PCR,                                p_stream->i_pcr );            }            p_stream->i_previous_pcr = p_stream->i_pcr;            /* The granulepos is the end date of the sample */            i_pts =  p_stream->i_pcr;        }    }    /* Convert the granulepos into the next pcr */    i_interpolated_pts = p_stream->i_interpolated_pcr;    Ogg_UpdatePCR( p_stream, p_oggpacket );    if( p_stream->i_pcr >= 0 )    {        /* This is for streams where the granulepos of the header packets         * doesn't match these of the data packets (eg. ogg web radios). */        if( p_stream->i_previous_pcr == 0 &&            p_stream->i_pcr  > 3 * DEFAULT_PTS_DELAY )        {            es_out_Control( p_demux->out, ES_OUT_RESET_PCR );            /* Call the pace control */            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_stream->i_pcr );        }    }    if( p_stream->fmt.i_codec != VLC_FOURCC( 'v','o','r','b' ) &&        p_stream->fmt.i_codec != VLC_FOURCC( 's','p','x',' ' ) &&        p_stream->fmt.i_codec != VLC_FOURCC( 'f','l','a','c' ) &&        p_stream->i_pcr >= 0 )    {        p_stream->i_previous_pcr = p_stream->i_pcr;        /* The granulepos is the start date of the sample */        i_pts = p_stream->i_pcr;    }

⌨️ 快捷键说明

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