📄 libasf.c
字号:
(asf_object_XXX_t *)p_obj;}#endif/* */static const struct{ const guid_t *p_id; int i_type; int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj ); void (*ASF_FreeObject_function)( asf_object_t *p_obj );} ASF_Object_Function [] ={ { &asf_object_header_guid, ASF_OBJECT_HEADER, ASF_ReadObject_Header, ASF_FreeObject_Null }, { &asf_object_data_guid, ASF_OBJECT_DATA, ASF_ReadObject_Data, ASF_FreeObject_Null }, { &asf_object_index_guid, ASF_OBJECT_INDEX, ASF_ReadObject_Index, ASF_FreeObject_Index }, { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES, ASF_ReadObject_file_properties, ASF_FreeObject_Null }, { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES, ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties }, { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION, ASF_ReadObject_header_extension, ASF_FreeObject_header_extension}, { &asf_object_metadata_guid, ASF_OBJECT_METADATA, ASF_ReadObject_metadata, ASF_FreeObject_metadata}, { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST, ASF_ReadObject_codec_list, ASF_FreeObject_codec_list }, { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL }, { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL }, { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION, ASF_ReadObject_content_description, ASF_FreeObject_content_description }, { &asf_object_language_list, ASF_OBJECT_OTHER, ASF_ReadObject_language_list, ASF_FreeObject_language_list }, { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER, ASF_ReadObject_stream_bitrate_properties, ASF_FreeObject_stream_bitrate_properties }, { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER, ASF_ReadObject_extended_stream_properties, ASF_FreeObject_extended_stream_properties }, { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER, ASF_ReadObject_advanced_mutual_exclusion, ASF_FreeObject_advanced_mutual_exclusion }, { &asf_object_stream_prioritization, ASF_OBJECT_OTHER, ASF_ReadObject_stream_prioritization, ASF_FreeObject_stream_prioritization }, { &asf_object_extended_content_description, ASF_OBJECT_OTHER, ASF_ReadObject_extended_content_description, ASF_FreeObject_extended_content_description }, { &asf_object_null_guid, 0, NULL, NULL }};static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj, asf_object_t *p_father ){ int i_result; int i_index; if( !p_obj ) return 0; memset( p_obj, 0, sizeof( *p_obj ) ); if( ASF_ReadObjectCommon( s, p_obj ) ) { msg_Warn( s, "cannot read one asf object" ); return VLC_EGENERIC; } p_obj->common.p_father = p_father; p_obj->common.p_first = NULL; p_obj->common.p_next = NULL; p_obj->common.p_last = NULL; if( p_obj->common.i_object_size < 24 ) { msg_Warn( s, "found a corrupted asf object (size<24)" ); return VLC_EGENERIC; } /* find this object */ for( i_index = 0; ; i_index++ ) { if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id, &p_obj->common.i_object_id ) || ASF_CmpGUID( ASF_Object_Function[i_index].p_id, &asf_object_null_guid ) ) { break; } } p_obj->common.i_type = ASF_Object_Function[i_index].i_type; /* Now load this object */ if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL ) { msg_Warn( s, "unknown asf object (not loaded)" ); i_result = VLC_SUCCESS; } else { /* XXX ASF_ReadObject_function realloc *pp_obj XXX */ i_result = (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj ); } /* link this object with father */ if( p_father && ! i_result ) { if( p_father->common.p_first ) { p_father->common.p_last->common.p_next = p_obj; } else { p_father->common.p_first = p_obj; } p_father->common.p_last = p_obj; } return i_result;}static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj ){ int i_index; asf_object_t *p_child; if( !p_obj ) return; /* Free all child object */ p_child = p_obj->common.p_first; while( p_child ) { asf_object_t *p_next; p_next = p_child->common.p_next; ASF_FreeObject( s, p_child ); p_child = p_next; } /* find this object */ for( i_index = 0; ; i_index++ ) { if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id, &p_obj->common.i_object_id )|| ASF_CmpGUID( ASF_Object_Function[i_index].p_id, &asf_object_null_guid ) ) { break; } } /* Now free this object */ if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL ) { msg_Warn( s, "unknown asf object " GUID_FMT, GUID_PRINT( p_obj->common.i_object_id ) ); } else {#ifdef ASF_DEBUG msg_Dbg( s, "free asf object " GUID_FMT, GUID_PRINT( p_obj->common.i_object_id ) );#endif (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj ); } free( p_obj );}/***************************************************************************** * ASF_ObjectDumpDebug: *****************************************************************************/static const struct{ const guid_t *p_id; const char *psz_name;} ASF_ObjectDumpDebugInfo[] ={ { &asf_object_header_guid, "Header" }, { &asf_object_data_guid, "Data" }, { &asf_object_index_guid, "Index" }, { &asf_object_file_properties_guid, "File Properties" }, { &asf_object_stream_properties_guid, "Stream Properties" }, { &asf_object_content_description_guid, "Content Description" }, { &asf_object_header_extension_guid, "Header Extension" }, { &asf_object_metadata_guid, "Metadata" }, { &asf_object_codec_list_guid, "Codec List" }, { &asf_object_marker_guid, "Marker" }, { &asf_object_stream_type_audio, "Stream Type Audio" }, { &asf_object_stream_type_video, "Stream Type Video" }, { &asf_object_stream_type_command, "Stream Type Command" }, { &asf_object_language_list, "Language List" }, { &asf_object_stream_bitrate_properties, "Stream Bitrate Properties" }, { &asf_object_padding, "Padding" }, { &asf_object_extended_stream_properties, "Extended Stream Properties" }, { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" }, { &asf_object_stream_prioritization, "Stream Prioritization" }, { &asf_object_extended_content_description, "Extended content description"}, { NULL, "Unknown" },};static void ASF_ObjectDumpDebug( vlc_object_t *p_obj, asf_object_common_t *p_node, int i_level ){ char str[1024]; int i; union asf_object_u *p_child; const char *psz_name; /* Find the name */ for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ ) { if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id, &p_node->i_object_id ) ) break; } psz_name = ASF_ObjectDumpDebugInfo[i].psz_name; memset( str, ' ', sizeof( str ) ); for( i = 1; i < i_level; i++ ) { str[i * 5] = '|'; } snprintf( str + 5*i_level, 1024, "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64, psz_name, GUID_PRINT( p_node->i_object_id ), p_node->i_object_size, p_node->i_object_pos ); msg_Dbg( p_obj, "%s", str ); for( p_child = p_node->p_first; p_child != NULL; p_child = p_child->common.p_next ) { ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 ); }}/***************************************************************************** * ASF_ReadObjetRoot : parse the entire stream/file *****************************************************************************/asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable ){ asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) ); asf_object_t *p_obj; if( !p_root ) return NULL; p_root->i_type = ASF_OBJECT_ROOT; memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) ); p_root->i_object_pos = stream_Tell( s ); p_root->i_object_size = 0; p_root->p_first = NULL; p_root->p_last = NULL; p_root->p_next = NULL; p_root->p_hdr = NULL; p_root->p_data = NULL; p_root->p_fp = NULL; p_root->p_index = NULL; p_root->p_metadata = NULL; for( ; ; ) { p_obj = malloc( sizeof( asf_object_t ) ); if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) ) { free( p_obj ); break; } switch( p_obj->common.i_type ) { case( ASF_OBJECT_HEADER ): p_root->p_hdr = (asf_object_header_t*)p_obj; break; case( ASF_OBJECT_DATA ): p_root->p_data = (asf_object_data_t*)p_obj; break; case( ASF_OBJECT_INDEX ): p_root->p_index = (asf_object_index_t*)p_obj; break; default: msg_Warn( s, "unknow object found" ); break; } if( p_obj->common.i_type == ASF_OBJECT_DATA && p_obj->common.i_object_size <= 50 ) { /* probably a dump of broadcasted asf */ break; } if( !b_seekable && p_root->p_hdr && p_root->p_data ) { /* For unseekable stream it's enough to play */ break; } if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */ break; } if( p_root->p_hdr != NULL && p_root->p_data != NULL ) { p_root->p_fp = ASF_FindObject( p_root->p_hdr, &asf_object_file_properties_guid, 0 ); if( p_root->p_fp ) { asf_object_t *p_hdr_ext = ASF_FindObject( p_root->p_hdr, &asf_object_header_extension_guid, 0 ); if( p_hdr_ext ) { int i_ext_stream; int i; p_root->p_metadata = ASF_FindObject( p_hdr_ext, &asf_object_metadata_guid, 0 ); /* Special case for broken designed file format :( */ i_ext_stream = ASF_CountObject( p_hdr_ext, &asf_object_extended_stream_properties ); for( i = 0; i < i_ext_stream; i++ ) { asf_object_t *p_esp = ASF_FindObject( p_hdr_ext, &asf_object_extended_stream_properties, i ); if( p_esp->ext_stream.p_sp ) { asf_object_t *p_sp = (asf_object_t*)p_esp->ext_stream.p_sp; /* Insert this p_sp */ p_root->p_hdr->p_last->common.p_next = p_sp; p_root->p_hdr->p_last = p_sp; p_sp->common.p_father = (asf_object_t*)p_root->p_hdr; } } } ASF_ObjectDumpDebug( VLC_OBJECT(s), (asf_object_common_t*)p_root, 0 ); return p_root; } msg_Warn( s, "cannot find file properties object" ); } /* Invalid file */ ASF_FreeObjectRoot( s, p_root ); return NULL;}void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root ){ asf_object_t *p_obj; p_obj = p_root->p_first; while( p_obj ) { asf_object_t *p_next; p_next = p_obj->common.p_next; ASF_FreeObject( s, p_obj ); p_obj = p_next; } free( p_root );}int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid ){ int i_count; asf_object_t *p_child; if( !p_obj ) return 0; i_count = 0; p_child = p_obj->common.p_first; while( p_child ) { if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) ) i_count++; p_child = p_child->common.p_next; } return i_count;}void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number ){ asf_object_t *p_child; p_child = p_obj->common.p_first; while( p_child ) { if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) ) { if( i_number == 0 ) return p_child; i_number--; } p_child = p_child->common.p_next; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -