libasf.c
来自「VLC媒体播放程序」· C语言 代码 · 共 852 行 · 第 1/2 页
C
852 行
/***************************************************************************** * libasf.c : ***************************************************************************** * Copyright (C) 2001-2003 VideoLAN * $Id: libasf.c,v 1.19 2004/01/25 20:05:28 hartman Exp $ * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <vlc/vlc.h>#include <vlc/input.h>#include "codecs.h" /* BITMAPINFOHEADER, WAVEFORMATEX */#include "libasf.h"#define ASF_DEBUG 1#define FREE( p ) \ if( p ) {free( p ); p = NULL; }#define GUID_FMT "0x%x-0x%x-0x%x-0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x"#define GUID_PRINT( guid ) \ (guid).v1, \ (guid).v2, \ (guid).v3, \ (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \ (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]/**************************************************************************** * ****************************************************************************/static int ASF_ReadObject( stream_t *, asf_object_t *p_obj, asf_object_t *p_father );/**************************************************************************** * GUID functions ****************************************************************************/void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data ){ p_guid->v1 = GetDWLE( p_data ); p_guid->v2 = GetWLE( p_data + 4); p_guid->v3 = GetWLE( p_data + 6); memcpy( p_guid->v4, p_data + 8, 8 );}int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 ){ if( (p_guid1->v1 != p_guid2->v1 )|| (p_guid1->v2 != p_guid2->v2 )|| (p_guid1->v3 != p_guid2->v3 )|| ( memcmp( p_guid1->v4, p_guid2->v4,8 )) ) { return( 0 ); } return( 1 ); /* match */}/**************************************************************************** * ****************************************************************************/static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj ){ asf_object_common_t *p_common = (asf_object_common_t*)p_obj; uint8_t *p_peek; if( stream_Peek( s, &p_peek, 24 ) < 24 ) { return( VLC_EGENERIC ); } ASF_GetGUID( &p_common->i_object_id, p_peek ); p_common->i_object_size = GetQWLE( p_peek + 16 ); p_common->i_object_pos = stream_Tell( s ); p_common->p_next = NULL;#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "found object guid: " GUID_FMT " size:"I64Fd, GUID_PRINT( p_common->i_object_id ), p_common->i_object_size );#endif return( VLC_SUCCESS );}static int ASF_NextObject( stream_t *s, asf_object_t *p_obj ){ asf_object_t obj; if( p_obj == NULL ) { if( ASF_ReadObjectCommon( s, &obj ) ) { return( VLC_EGENERIC ); } p_obj = &obj; } if( p_obj->common.i_object_size <= 0 ) { return( VLC_EGENERIC ); } if( p_obj->common.p_father && p_obj->common.p_father->common.i_object_size != 0 ) { if( p_obj->common.p_father->common.i_object_pos + p_obj->common.p_father->common.i_object_size < p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 ) /* 24 is min size of an object */ { return( VLC_EGENERIC ); } } return stream_Seek( s, p_obj->common.i_object_pos + p_obj->common.i_object_size );}static void ASF_FreeObject_Null( asf_object_t *pp_obj ){ return;}static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj ){ asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj; asf_object_t *p_subobj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 ) { return( VLC_EGENERIC ); } p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 ); p_hdr->i_reserved1 = p_peek[28]; p_hdr->i_reserved2 = p_peek[29]; p_hdr->p_first = NULL; p_hdr->p_last = NULL;#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d", p_hdr->i_sub_object_count, p_hdr->i_reserved1, p_hdr->i_reserved2 );#endif /* Cannot failed as peek succeed */ stream_Read( s, NULL, 30 ); /* Now load sub object */ for( ; ; ) { p_subobj = malloc( sizeof( asf_object_t ) ); if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) ) { break; } if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */ { break; } } return VLC_SUCCESS;}static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj ){ asf_object_data_t *p_data = (asf_object_data_t*)p_obj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 ) { return VLC_EGENERIC; } ASF_GetGUID( &p_data->i_file_id, p_peek + 24 ); p_data->i_total_data_packets = GetQWLE( p_peek + 40 ); p_data->i_reserved = GetWLE( p_peek + 48 );#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"data object\" file_id:" GUID_FMT " total data packet:" I64Fd" reserved:%d", GUID_PRINT( p_data->i_file_id ), p_data->i_total_data_packets, p_data->i_reserved );#endif return VLC_SUCCESS;}static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj ){ asf_object_index_t *p_index = (asf_object_index_t*)p_obj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, 56 ) ) < 56 ) { return VLC_EGENERIC; } ASF_GetGUID( &p_index->i_file_id, p_peek + 24 ); p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 ); p_index->i_max_packet_count = GetDWLE( p_peek + 48 ); p_index->i_index_entry_count = GetDWLE( p_peek + 52 ); p_index->index_entry = NULL; /* FIXME */#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"index object\" file_id:" GUID_FMT " index_entry_time_interval:"I64Fd" max_packet_count:%d " "index_entry_count:%ld", GUID_PRINT( p_index->i_file_id ), p_index->i_index_entry_time_interval, p_index->i_max_packet_count, (long int)p_index->i_index_entry_count );#endif return VLC_SUCCESS;}static void ASF_FreeObject_Index( asf_object_t *p_obj ){ asf_object_index_t *p_index = (asf_object_index_t*)p_obj; FREE( p_index->index_entry );}static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj ){ asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, 92) ) < 92 ) { return VLC_EGENERIC; } ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 ); p_fp->i_file_size = GetQWLE( p_peek + 40 ); p_fp->i_creation_date = GetQWLE( p_peek + 48 ); p_fp->i_data_packets_count = GetQWLE( p_peek + 56 ); p_fp->i_play_duration = GetQWLE( p_peek + 64 ); p_fp->i_send_duration = GetQWLE( p_peek + 72 ); p_fp->i_preroll = GetQWLE( p_peek + 80 ); p_fp->i_flags = GetDWLE( p_peek + 88 ); p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 ); p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 ); p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"file properties object\" file_id:" GUID_FMT " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:" I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:" I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d " "max_bitrate:%d", GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size, p_fp->i_creation_date, p_fp->i_data_packets_count, p_fp->i_play_duration, p_fp->i_send_duration, p_fp->i_preroll, p_fp->i_flags, p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size, p_fp->i_max_bitrate );#endif return VLC_SUCCESS;}static int ASF_ReadObject_header_extention( stream_t *s, asf_object_t *p_obj ){ asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46) { return VLC_EGENERIC; } ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 ); p_he->i_reserved2 = GetWLE( p_peek + 40 ); p_he->i_header_extention_size = GetDWLE( p_peek + 42 ); if( p_he->i_header_extention_size ) { p_he->p_header_extention_data = malloc( p_he->i_header_extention_size ); memcpy( p_he->p_header_extention_data, p_peek + 46, p_he->i_header_extention_size ); } else { p_he->p_header_extention_data = NULL; }#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"header extention object\" reserved1:" GUID_FMT " reserved2:%d header_extention_size:%d", GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2, p_he->i_header_extention_size );#endif return VLC_SUCCESS;}static void ASF_FreeObject_header_extention( asf_object_t *p_obj ){ asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj; FREE( p_he->p_header_extention_data );}static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj ){ asf_object_stream_properties_t *p_sp = (asf_object_stream_properties_t*)p_obj; int i_peek; uint8_t *p_peek; if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 74 ) { return VLC_EGENERIC; } ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 ); ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 ); p_sp->i_time_offset = GetQWLE( p_peek + 56 ); p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 ); p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 ); p_sp->i_flags = GetWLE( p_peek + 72 ); p_sp->i_stream_number = p_sp->i_flags&0x07f; p_sp->i_reserved = GetDWLE( p_peek + 74 ); if( p_sp->i_type_specific_data_length ) { p_sp->p_type_specific_data = malloc( p_sp->i_type_specific_data_length ); memcpy( p_sp->p_type_specific_data, p_peek + 78, p_sp->i_type_specific_data_length ); } else { p_sp->p_type_specific_data = NULL; } if( p_sp->i_error_correction_data_length ) { p_sp->p_error_correction_data = malloc( p_sp->i_error_correction_data_length ); memcpy( p_sp->p_error_correction_data, p_peek + 78 + p_sp->i_type_specific_data_length, p_sp->i_error_correction_data_length ); } else { p_sp->p_error_correction_data = NULL; }#ifdef ASF_DEBUG msg_Dbg( (vlc_object_t*)s, "read \"stream Properties object\" stream_type:" GUID_FMT " error_correction_type:" GUID_FMT " time_offset:"I64Fd " type_specific_data_length:%d error_correction_data_length:%d" " flags:0x%x stream_number:%d", GUID_PRINT( p_sp->i_stream_type ), GUID_PRINT( p_sp->i_error_correction_type ), p_sp->i_time_offset, p_sp->i_type_specific_data_length, p_sp->i_error_correction_data_length, p_sp->i_flags, p_sp->i_stream_number );#endif return VLC_SUCCESS;}static void ASF_FreeObject_stream_properties( asf_object_t *p_obj ){ asf_object_stream_properties_t *p_sp = (asf_object_stream_properties_t*)p_obj; FREE( p_sp->p_type_specific_data ); FREE( p_sp->p_error_correction_data );}static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj ){ asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj; int i_peek; uint8_t *p_peek, *p_data; unsigned int i_codec; if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 ) { return VLC_EGENERIC; } ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 ); p_cl->i_codec_entries_count = GetWLE( p_peek + 40 ); if( p_cl->i_codec_entries_count > 0 ) { p_cl->codec = calloc( p_cl->i_codec_entries_count, sizeof( asf_codec_entry_t ) ); memset( p_cl->codec, 0, p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) ); p_data = p_peek + 44; for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) {#define codec p_cl->codec[i_codec] int i_len, i; codec.i_type = GetWLE( p_data ); p_data += 2; /* codec name */ i_len = GetWLE( p_data ); p_data += 2; codec.psz_name = calloc( sizeof( char ), i_len + 1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?