libasf.h
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:13k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * libasf.h :
  3.  *****************************************************************************
  4.  * Copyright (C) 2001-2003 the VideoLAN team
  5.  * $Id: ebd16604913c109438204c9be174201a805b8fba $
  6.  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  21.  *****************************************************************************/
  22. /*****************************************************************************
  23.  * Structure needed for decoder
  24.  *****************************************************************************/
  25. typedef struct guid_s
  26. {
  27.     uint32_t v1; /* le */
  28.     uint16_t v2; /* le */
  29.     uint16_t v3; /* le */
  30.     uint8_t  v4[8];
  31. } guid_t;
  32. enum
  33. {
  34.     ASF_OBJECT_NULL = 0,
  35.     ASF_OBJECT_ROOT,
  36.     ASF_OBJECT_HEADER,
  37.     ASF_OBJECT_DATA,
  38.     ASF_OBJECT_INDEX,
  39.     ASF_OBJECT_FILE_PROPERTIES,
  40.     ASF_OBJECT_STREAM_PROPERTIES,
  41.     ASF_OBJECT_HEADER_EXTENSION,
  42.     ASF_OBJECT_CODEC_LIST,
  43.     ASF_OBJECT_MARKER,
  44.     ASF_OBJECT_CONTENT_DESCRIPTION,
  45.     ASF_OBJECT_METADATA,
  46.     ASF_OBJECT_PADDING,
  47.     ASF_OBJECT_OTHER,
  48. };
  49. static const guid_t asf_object_null_guid =
  50. {
  51.     0x00000000,
  52.     0x0000,
  53.     0x0000,
  54.     { 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00 }
  55. };
  56. static const guid_t asf_object_header_guid =
  57. {0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
  58. static const guid_t asf_object_data_guid =
  59. {0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
  60. static const guid_t asf_object_index_guid =
  61. {0x33000890, 0xE5B1, 0x11CF, {0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}};
  62. static const guid_t asf_object_file_properties_guid =
  63. {0x8cabdca1, 0xa947, 0x11cf, {0x8e, 0xe4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
  64. static const guid_t asf_object_stream_properties_guid =
  65. {0xB7DC0791, 0xA9B7, 0x11CF, {0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
  66. static const guid_t asf_object_content_description_guid =
  67. {0x75B22633, 0x668E, 0x11CF, {0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}};
  68. static const guid_t asf_object_header_extension_guid =
  69. {0x5FBF03B5, 0xA92E, 0x11CF, {0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
  70. static const guid_t asf_object_metadata_guid =
  71. {0xC5F8CBEA, 0x5BAF, 0x4877, {0x84, 0x67, 0xAA, 0x8C, 0x44, 0xFA, 0x4C, 0xCA}};
  72. static const guid_t asf_object_codec_list_guid =
  73. {0x86D15240, 0x311D, 0x11D0, {0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
  74. static const guid_t asf_object_marker_guid =
  75. {0xF487CD01, 0xA951, 0x11CF, {0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
  76. static const guid_t asf_object_stream_type_audio =
  77. {0xF8699E40, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
  78. static const guid_t asf_object_stream_type_video =
  79. {0xbc19efc0, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
  80. static const guid_t asf_object_stream_type_command =
  81. {0x59DACFC0, 0x59E6, 0x11D0, {0xA3, 0xAC, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
  82. /* TODO */
  83. static const guid_t asf_object_stream_bitrate_properties =
  84. {0x7BF875CE, 0x468D, 0x11D1, {0x8D, 0x82, 0x00, 0x60, 0x97, 0xC9, 0xA2, 0xB2}};
  85. static const guid_t asf_object_language_list =
  86. {0x7C4346A9, 0xEFE0, 0x4BFC, {0xB2, 0x29, 0x39, 0x3E, 0xDE, 0x41, 0x5C, 0x85}};
  87. static const guid_t asf_object_extended_stream_properties =
  88. {0x14E6A5CB, 0xC672, 0x4332, {0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A}};
  89. static const guid_t asf_object_advanced_mutual_exclusion =
  90. {0xA08649CF, 0x4775, 0x4670, {0x8A, 0x16, 0x6E, 0x35, 0x35, 0x75, 0x66, 0xCD}};
  91. static const guid_t asf_object_padding =
  92. {0x1806D474, 0xCADF, 0x4509, {0xA4, 0xBA, 0x9A, 0xAB, 0xCB, 0x96, 0xAA, 0xE8}};
  93. static const guid_t asf_object_stream_prioritization =
  94. {0xD4FED15B, 0x88D3, 0x454F, {0x81, 0xF0, 0xED, 0x5C, 0x45, 0x99, 0x9E, 0x24}};
  95. static const guid_t asf_object_extended_content_description =
  96. {0xD2D0A440, 0xE307, 0x11D2, {0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50}};
  97. static const guid_t asf_object_extended_stream_header =
  98. {0x3afb65e2, 0x47ef, 0x40f2, { 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43}};
  99. static const guid_t asf_object_extended_stream_type_audio =
  100. {0x31178c9d, 0x03e1, 0x4528, { 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03}};
  101. #define ASF_OBJECT_COMMON          
  102.     int          i_type;           
  103.     guid_t       i_object_id;      
  104.     uint64_t     i_object_size;    
  105.     uint64_t     i_object_pos;     
  106.     union asf_object_u *p_father;  
  107.     union asf_object_u *p_first;   
  108.     union asf_object_u *p_last;    
  109.     union asf_object_u *p_next;
  110. typedef struct
  111. {
  112.     ASF_OBJECT_COMMON
  113. } asf_object_common_t;
  114. typedef struct
  115. {
  116.     uint32_t i_packet_number;
  117.     uint16_t i_packet_count;
  118. } asf_index_entry_t;
  119. /****************************************************************************
  120.  * High level asf object
  121.  ****************************************************************************/
  122. /* This is the first header found in an asf file
  123.  * It's the only object that has subobjects */
  124. typedef struct
  125. {
  126.     ASF_OBJECT_COMMON
  127.     uint32_t i_sub_object_count;
  128.     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
  129.     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
  130. } asf_object_header_t;
  131. typedef struct
  132. {
  133.     ASF_OBJECT_COMMON
  134.     guid_t      i_file_id;
  135.     uint64_t    i_total_data_packets;
  136.     uint16_t    i_reserved;
  137. } asf_object_data_t;
  138. typedef struct
  139. {
  140.     ASF_OBJECT_COMMON
  141.     guid_t      i_file_id;
  142.     uint64_t    i_index_entry_time_interval;
  143.     uint32_t    i_max_packet_count;
  144.     uint32_t    i_index_entry_count;
  145.     asf_index_entry_t *index_entry;
  146. } asf_object_index_t;
  147. /****************************************************************************
  148.  * Sub level asf object
  149.  ****************************************************************************/
  150. #define ASF_FILE_PROPERTIES_BROADCAST   0x01
  151. #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
  152. typedef struct
  153. {
  154.     ASF_OBJECT_COMMON
  155.     guid_t  i_file_id;
  156.     uint64_t     i_file_size;
  157.     uint64_t     i_creation_date;
  158.     uint64_t     i_data_packets_count;
  159.     uint64_t     i_play_duration;
  160.     uint64_t     i_send_duration;
  161.     uint64_t     i_preroll;
  162.     uint32_t     i_flags;
  163.     uint32_t     i_min_data_packet_size;
  164.     uint32_t     i_max_data_packet_size;
  165.     uint32_t     i_max_bitrate;
  166. } asf_object_file_properties_t;
  167. #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
  168. typedef struct
  169. {
  170.     ASF_OBJECT_COMMON
  171.     guid_t  i_stream_type;
  172.     guid_t  i_error_correction_type;
  173.     uint64_t     i_time_offset;
  174.     uint32_t     i_type_specific_data_length;
  175.     uint32_t     i_error_correction_data_length;
  176.     uint16_t     i_flags;
  177.         /* extrated from flags */
  178.         uint8_t i_stream_number;
  179.     uint32_t    i_reserved;
  180.     uint8_t     *p_type_specific_data;
  181.     uint8_t     *p_error_correction_data;
  182. } asf_object_stream_properties_t;
  183. typedef struct
  184. {
  185.     ASF_OBJECT_COMMON
  186.     guid_t      i_reserved1;
  187.     uint16_t    i_reserved2;
  188.     uint32_t    i_header_extension_size;
  189.     uint8_t     *p_header_extension_data;
  190. } asf_object_header_extension_t;
  191. #define ASF_METADATA_TYPE_STRING 0x0000
  192. #define ASF_METADATA_TYPE_BYTE   0x0001
  193. #define ASF_METADATA_TYPE_BOOL   0x0002
  194. #define ASF_METADATA_TYPE_DWORD  0x0003
  195. #define ASF_METADATA_TYPE_QWORD  0x0004
  196. #define ASF_METADATA_TYPE_WORD   0x0005
  197. typedef struct
  198. {
  199.     uint16_t    i_stream;
  200.     uint16_t    i_type;
  201.     char        *psz_name;
  202.     int64_t i_val;
  203.     int i_data;
  204.     uint8_t *p_data;
  205. } asf_metadata_record_t;
  206. typedef struct
  207. {
  208.     ASF_OBJECT_COMMON
  209.     uint32_t i_record_entries_count;
  210.     asf_metadata_record_t *record;
  211. } asf_object_metadata_t;
  212. typedef struct
  213. {
  214.     ASF_OBJECT_COMMON
  215.     char *psz_title;
  216.     char *psz_artist;
  217.     char *psz_copyright;
  218.     char *psz_description;
  219.     char *psz_rating;
  220. } asf_object_content_description_t;
  221. typedef struct
  222. {
  223.     uint16_t i_length;
  224.     uint16_t *i_char;
  225. } string16_t;
  226. #define ASF_CODEC_TYPE_VIDEO    0x0001
  227. #define ASF_CODEC_TYPE_AUDIO    0x0002
  228. #define ASF_CODEC_TYPE_UNKNOW   0xffff
  229. typedef struct
  230. {
  231.     uint16_t    i_type;
  232.     char        *psz_name;
  233.     char        *psz_description;
  234.     uint16_t    i_information_length;
  235.     uint8_t     *p_information;
  236. } asf_codec_entry_t;
  237. typedef struct
  238. {
  239.     ASF_OBJECT_COMMON
  240.     guid_t      i_reserved;
  241.     uint32_t    i_codec_entries_count;
  242.     asf_codec_entry_t *codec;
  243. } asf_object_codec_list_t;
  244. typedef struct
  245. {
  246.     uint64_t     i_offset;
  247.     uint64_t     i_presentation_time;
  248.     uint16_t     i_entry_length;
  249.     uint32_t     i_send_time;
  250.     uint32_t     i_flags;
  251.     uint32_t     i_marker_description_length;
  252.     uint8_t      *i_marker_description;
  253. } asf_marker_t;
  254. typedef struct
  255. {
  256.     ASF_OBJECT_COMMON
  257.     guid_t      i_reserved1;
  258.     uint32_t    i_count;
  259.     uint16_t    i_reserved2;
  260.     string16_t name;
  261.     asf_marker_t *marker;
  262. } asf_object_marker_t;
  263. typedef struct
  264. {
  265.     ASF_OBJECT_COMMON
  266.     int  i_language;
  267.     char **ppsz_language;
  268. } asf_object_language_list_t;
  269. typedef struct
  270. {
  271.     ASF_OBJECT_COMMON
  272.     int i_bitrate;
  273.     struct
  274.     {
  275.         int      i_stream_number;
  276.         uint32_t i_avg_bitrate;
  277.     } bitrate[128];
  278. } asf_object_stream_bitrate_properties_t;
  279. typedef struct
  280. {
  281.     ASF_OBJECT_COMMON
  282.     int64_t i_start_time;
  283.     int64_t i_end_time;
  284.     int32_t i_data_bitrate;
  285.     int32_t i_buffer_size;
  286.     int32_t i_initial_buffer_fullness;
  287.     int32_t i_alternate_data_bitrate;
  288.     int32_t i_alternate_buffer_size;
  289.     int32_t i_alternate_initial_buffer_fullness;
  290.     int32_t i_maximum_object_size;
  291.     int32_t i_flags;
  292.     int16_t i_stream_number;
  293.     int16_t i_language_index;
  294.     int64_t i_average_time_per_frame;
  295.     int     i_stream_name_count;
  296.     int     i_payload_extension_system_count;
  297.     int     *pi_stream_name_language;
  298.     char    **ppsz_stream_name;
  299.     asf_object_stream_properties_t *p_sp;
  300. } asf_object_extended_stream_properties_t;
  301. typedef struct
  302. {
  303.     ASF_OBJECT_COMMON
  304.     guid_t  type;
  305.     int16_t i_stream_number_count;
  306.     int16_t *pi_stream_number;
  307. } asf_object_advanced_mutual_exclusion_t;
  308. typedef struct
  309. {
  310.     ASF_OBJECT_COMMON
  311.     int i_priority_count;
  312.     int *pi_priority_flag;
  313.     int *pi_priority_stream_number;
  314. } asf_object_stream_prioritization_t;
  315. typedef struct
  316. {
  317.     ASF_OBJECT_COMMON
  318.     int i_count;
  319.     char **ppsz_name;
  320.     char **ppsz_value;
  321. } asf_object_extended_content_description_t;
  322. /****************************************************************************
  323.  * Special Root Object
  324.  ****************************************************************************/
  325. typedef struct
  326. {
  327.     ASF_OBJECT_COMMON
  328.     asf_object_header_t *p_hdr;
  329.     asf_object_data_t   *p_data;
  330.     /* could be NULL if !b_seekable or not-present */
  331.     asf_object_index_t  *p_index;
  332.     /* from asf_object_header_t */
  333.     asf_object_file_properties_t *p_fp;
  334.     /* from asf_object_header_extension_t */
  335.     asf_object_metadata_t *p_metadata;
  336. } asf_object_root_t;
  337. /****************************************************************************
  338.  * asf_object_t: union of all objects.
  339.  ****************************************************************************/
  340. typedef union asf_object_u
  341. {
  342.     asf_object_common_t common;
  343.     asf_object_header_t header;
  344.     asf_object_data_t   data;
  345.     asf_object_index_t  index;
  346.     asf_object_root_t   root;
  347.     asf_object_file_properties_t    file_properties;
  348.     asf_object_stream_properties_t  stream_properties;
  349.     asf_object_header_extension_t   header_extension;
  350.     asf_object_metadata_t           metadata;
  351.     asf_object_codec_list_t         codec_list;
  352.     asf_object_marker_t             marker;
  353.     asf_object_language_list_t      language_list;
  354.     asf_object_stream_bitrate_properties_t stream_bitrate;
  355.     asf_object_extended_stream_properties_t ext_stream;
  356.     asf_object_content_description_t content_description;
  357.     asf_object_advanced_mutual_exclusion_t advanced_mutual_exclusion;
  358.     asf_object_stream_prioritization_t stream_prioritization;
  359.     asf_object_extended_content_description_t extended_content_description;
  360. } asf_object_t;
  361. void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data );
  362. bool ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 );
  363. asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
  364. void               ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root );
  365. #define ASF_CountObject( a, b ) __ASF_CountObject( (asf_object_t*)(a), b )
  366. int  __ASF_CountObject ( asf_object_t *p_obj, const guid_t *p_guid );
  367. #define ASF_FindObject( a, b, c )  __ASF_FindObject( (asf_object_t*)(a), b, c )
  368. void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number );