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

📄 asf.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * asf.c : ASF demux module ***************************************************************************** * Copyright (C) 2002-2003 the VideoLAN team * $Id$ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_demux.h>#include <vlc_interface.h>#include <vlc_meta.h>#include <vlc_access.h>                /* GET_PRIVATE_ID_STATE */#include <vlc_codecs.h>                /* BITMAPINFOHEADER, WAVEFORMATEX */#include "libasf.h"/* TODO *  - add support for the newly added object: language, bitrate, *                                            extended stream properties. *//***************************************************************************** * Module descriptor *****************************************************************************/static int  Open  ( vlc_object_t * );static void Close ( vlc_object_t * );vlc_module_begin();    set_category( CAT_INPUT );    set_subcategory( SUBCAT_INPUT_DEMUX );    set_description( N_("ASF v1.0 demuxer") );    set_capability( "demux", 200 );    set_callbacks( Open, Close );    add_shortcut( "asf" );vlc_module_end();/***************************************************************************** * Local prototypes *****************************************************************************/static int Demux  ( demux_t * );static int Control( demux_t *, int i_query, va_list args );typedef struct{    int i_cat;    es_out_id_t     *p_es;    asf_object_stream_properties_t *p_sp;    mtime_t i_time;    block_t         *p_frame; /* use to gather complete frame */} asf_track_t;struct demux_sys_t{    mtime_t             i_time;     /* s */    mtime_t             i_length;   /* length of file file */    int64_t             i_bitrate;  /* global file bitrate */    asf_object_root_t            *p_root;    asf_object_file_properties_t *p_fp;    unsigned int        i_track;    asf_track_t         *track[128]; /* track number is stored on 7 bits */    int64_t             i_data_begin;    int64_t             i_data_end;    bool          b_index;    vlc_meta_t          *meta;};static mtime_t  GetMoviePTS( demux_sys_t * );static int      DemuxInit( demux_t * );static void     DemuxEnd( demux_t * );static int      DemuxPacket( demux_t * );/***************************************************************************** * Open: check file and initializes ASF structures *****************************************************************************/static int Open( vlc_object_t * p_this ){    demux_t     *p_demux = (demux_t *)p_this;    demux_sys_t *p_sys;    guid_t      guid;    const uint8_t     *p_peek;    /* A little test to see if it could be a asf stream */    if( stream_Peek( p_demux->s, &p_peek, 16 ) < 16 ) return VLC_EGENERIC;    ASF_GetGUID( &guid, p_peek );    if( !ASF_CmpGUID( &guid, &asf_object_header_guid ) ) return VLC_EGENERIC;    /* Set p_demux fields */    p_demux->pf_demux = Demux;    p_demux->pf_control = Control;    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );    memset( p_sys, 0, sizeof( demux_sys_t ) );    /* Load the headers */    if( DemuxInit( p_demux ) )    {        free( p_sys );        return VLC_EGENERIC;    }    return VLC_SUCCESS;}/***************************************************************************** * Demux: read packet and send them to decoders *****************************************************************************/static int Demux( demux_t *p_demux ){    demux_sys_t *p_sys = p_demux->p_sys;    for( ;; )    {        const uint8_t *p_peek;        mtime_t i_length;        mtime_t i_time_begin = GetMoviePTS( p_sys );        int i_result;        if( !vlc_object_alive (p_demux) )            break;#if 0        /* FIXME: returns EOF too early for some mms streams */        if( p_sys->i_data_end >= 0 &&                stream_Tell( p_demux->s ) >= p_sys->i_data_end )            return 0; /* EOF */#endif        /* Check if we have concatenated files */        if( stream_Peek( p_demux->s, &p_peek, 16 ) == 16 )        {            guid_t guid;            ASF_GetGUID( &guid, p_peek );            if( ASF_CmpGUID( &guid, &asf_object_header_guid ) )            {                msg_Warn( p_demux, "found a new ASF header" );                /* We end this stream */                DemuxEnd( p_demux );                /* And we prepare to read the next one */                if( DemuxInit( p_demux ) )                {                    msg_Err( p_demux, "failed to load the new header" );                    intf_UserFatal( p_demux, false, _("Could not demux ASF stream"),                                    _("VLC failed to load the ASF header.") );                    return 0;                }                continue;            }        }        /* Read and demux a packet */        if( ( i_result = DemuxPacket( p_demux ) ) <= 0 )        {            return i_result;        }        if( i_time_begin == -1 )        {            i_time_begin = GetMoviePTS( p_sys );        }        else        {            i_length = GetMoviePTS( p_sys ) - i_time_begin;            if( i_length < 0 || i_length >= 40 * 1000 ) break;        }    }    /* Set the PCR */    p_sys->i_time = GetMoviePTS( p_sys );    if( p_sys->i_time >= 0 )    {        es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_time );    }    return 1;}/***************************************************************************** * Close: frees unused data *****************************************************************************/static void Close( vlc_object_t * p_this ){    demux_t     *p_demux = (demux_t *)p_this;    DemuxEnd( p_demux );    free( p_demux->p_sys );}/***************************************************************************** * SeekIndex: goto to i_date or i_percent *****************************************************************************/static int SeekIndex( demux_t *p_demux, mtime_t i_date, float f_pos ){    demux_sys_t *p_sys = p_demux->p_sys;    asf_object_index_t *p_index;    int64_t i_pos;    msg_Dbg( p_demux, "seek with index: %i seconds, position %f",             (int)(i_date/1000000), f_pos );    p_index = ASF_FindObject( p_sys->p_root, &asf_object_index_guid, 0 );    if( i_date < 0 ) i_date = p_sys->i_length * f_pos;    i_pos = i_date * 10 / p_index->i_index_entry_time_interval;    i_pos = p_index->index_entry[i_pos].i_packet_number *        p_sys->p_fp->i_min_data_packet_size;    return stream_Seek( p_demux->s, p_sys->i_data_begin + i_pos );}/***************************************************************************** * Control: *****************************************************************************/static int Control( demux_t *p_demux, int i_query, va_list args ){    demux_sys_t *p_sys = p_demux->p_sys;    vlc_meta_t  *p_meta;    int64_t     i64, *pi64;    double      f, *pf;    int         i;    switch( i_query )    {    case DEMUX_GET_LENGTH:        pi64 = (int64_t*)va_arg( args, int64_t * );        *pi64 = p_sys->i_length;        return VLC_SUCCESS;    case DEMUX_GET_TIME:        pi64 = (int64_t*)va_arg( args, int64_t * );        if( p_sys->i_time < 0 ) return VLC_EGENERIC;        *pi64 = p_sys->i_time;        return VLC_SUCCESS;    case DEMUX_SET_TIME:        p_sys->i_time = -1;        for( i = 0; i < 128 ; i++ )            if( p_sys->track[i] ) p_sys->track[i]->i_time = -1;        if( p_sys->b_index && p_sys->i_length > 0 )        {            i64 = (int64_t)va_arg( args, int64_t );            return SeekIndex( p_demux, i64, -1 );        }        else        {            return demux_vaControlHelper( p_demux->s, p_sys->i_data_begin,                                           p_sys->i_data_end, p_sys->i_bitrate,                                           p_sys->p_fp->i_min_data_packet_size,                                           i_query, args );        }    case DEMUX_GET_POSITION:        if( p_sys->i_time < 0 ) return VLC_EGENERIC;        if( p_sys->i_length > 0 )        {            pf = (double*)va_arg( args, double * );            *pf = p_sys->i_time / (double)p_sys->i_length;            return VLC_SUCCESS;        }        return demux_vaControlHelper( p_demux->s, p_sys->i_data_begin,                                       p_sys->i_data_end, p_sys->i_bitrate,                                       p_sys->p_fp->i_min_data_packet_size,                                       i_query, args );    case DEMUX_SET_POSITION:        p_sys->i_time = -1;        for( i = 0; i < 128 ; i++ )            if( p_sys->track[i] ) p_sys->track[i]->i_time = -1;        if( p_sys->b_index && p_sys->i_length > 0 )        {            f = (double)va_arg( args, double );            return SeekIndex( p_demux, -1, f );        }        else        {            return demux_vaControlHelper( p_demux->s, p_sys->i_data_begin,                                           p_sys->i_data_end, p_sys->i_bitrate,                                           p_sys->p_fp->i_min_data_packet_size,                                           i_query, args );        }    case DEMUX_GET_META:        p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );        vlc_meta_Merge( p_meta, p_sys->meta );        return VLC_SUCCESS;    default:        return demux_vaControlHelper( p_demux->s, p_sys->i_data_begin,                                       p_sys->i_data_end, p_sys->i_bitrate,                                       p_sys->p_fp->i_min_data_packet_size,                                       i_query, args );    }}/***************************************************************************** * *****************************************************************************/static mtime_t GetMoviePTS( demux_sys_t *p_sys ){    mtime_t i_time = -1;    int     i;    for( i = 0; i < 128 ; i++ )    {        asf_track_t *tk = p_sys->track[i];        if( tk && tk->p_es && tk->i_time > 0)        {            if( i_time < 0 ) i_time = tk->i_time;            else i_time = __MIN( i_time, tk->i_time );        }    }    return i_time;}#define GETVALUE2b( bits, var, def ) \

⌨️ 快捷键说明

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