1 /***************************************************************************** 2 * libasf.h : 3 ***************************************************************************** 4 * Copyright © 2001-2004, 2011 VLC authors and VideoLAN 5 * 6 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 21 *****************************************************************************/ 22 #ifndef VLC_ASF_LIBASF_H_ 23 #define VLC_ASF_LIBASF_H_ 24 25 #define ASF_MAX_STREAMNUMBER 127 26 #define ASF_OBJECT_COMMON_SIZE 24 27 28 /***************************************************************************** 29 * Structure needed for decoder 30 *****************************************************************************/ 31 32 #include "libasf_guid.h" 33 34 #define ASF_OBJECT_COMMON \ 35 int i_type; \ 36 guid_t i_object_id; \ 37 uint64_t i_object_size; \ 38 uint64_t i_object_pos; \ 39 union asf_object_u *p_father; \ 40 union asf_object_u *p_first; \ 41 union asf_object_u *p_last; \ 42 union asf_object_u *p_next; 43 44 typedef struct 45 { 46 ASF_OBJECT_COMMON 47 48 } asf_object_common_t; 49 50 typedef struct 51 { 52 uint32_t i_packet_number; 53 uint16_t i_packet_count; 54 55 } asf_index_entry_t; 56 57 /**************************************************************************** 58 * High level asf object 59 ****************************************************************************/ 60 /* This is the first header found in an asf file 61 * It's the only object that has subobjects */ 62 typedef struct 63 { 64 ASF_OBJECT_COMMON 65 uint32_t i_sub_object_count; 66 uint8_t i_reserved1; /* 0x01, but could be safely ignored */ 67 uint8_t i_reserved2; /* 0x02, if not must failed to source the contain */ 68 69 } asf_object_header_t; 70 71 typedef struct 72 { 73 ASF_OBJECT_COMMON 74 guid_t i_file_id; 75 uint64_t i_total_data_packets; 76 uint16_t i_reserved; 77 78 } asf_object_data_t; 79 80 81 typedef struct 82 { 83 ASF_OBJECT_COMMON 84 guid_t i_file_id; 85 uint64_t i_index_entry_time_interval; 86 uint32_t i_max_packet_count; 87 uint32_t i_index_entry_count; 88 89 asf_index_entry_t *index_entry; 90 91 } asf_object_index_t; 92 93 /**************************************************************************** 94 * Sub level asf object 95 ****************************************************************************/ 96 #define ASF_FILE_PROPERTIES_BROADCAST 0x01 97 #define ASF_FILE_PROPERTIES_SEEKABLE 0x02 98 99 typedef struct 100 { 101 ASF_OBJECT_COMMON 102 103 guid_t i_file_id; 104 uint64_t i_file_size; 105 uint64_t i_creation_date; 106 uint64_t i_data_packets_count; 107 uint64_t i_play_duration; 108 uint64_t i_send_duration; 109 uint64_t i_preroll; 110 uint32_t i_flags; 111 uint32_t i_min_data_packet_size; 112 uint32_t i_max_data_packet_size; 113 uint32_t i_max_bitrate; 114 115 } asf_object_file_properties_t; 116 117 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000 118 typedef struct 119 { 120 ASF_OBJECT_COMMON 121 122 guid_t i_stream_type; 123 guid_t i_error_correction_type; 124 uint64_t i_time_offset; 125 uint32_t i_type_specific_data_length; 126 uint32_t i_error_correction_data_length; 127 uint16_t i_flags; 128 /* extrated from flags */ 129 uint8_t i_stream_number; 130 uint32_t i_reserved; 131 uint8_t *p_type_specific_data; 132 uint8_t *p_error_correction_data; 133 } asf_object_stream_properties_t; 134 135 typedef struct 136 { 137 ASF_OBJECT_COMMON 138 139 guid_t i_reserved1; 140 uint16_t i_reserved2; 141 uint32_t i_header_extension_size; 142 uint8_t *p_header_extension_data; 143 144 } asf_object_header_extension_t; 145 146 enum { 147 ASF_METADATA_TYPE_STRING, 148 ASF_METADATA_TYPE_BYTE, 149 ASF_METADATA_TYPE_BOOL, 150 ASF_METADATA_TYPE_DWORD, 151 ASF_METADATA_TYPE_QWORD, 152 ASF_METADATA_TYPE_WORD, 153 }; 154 155 typedef struct 156 { 157 uint16_t i_stream; 158 uint16_t i_type; 159 char *psz_name; 160 161 uint64_t i_val; 162 uint16_t i_data; 163 uint8_t *p_data; 164 165 } asf_metadata_record_t; 166 167 typedef struct 168 { 169 ASF_OBJECT_COMMON 170 171 uint32_t i_record_entries_count; 172 asf_metadata_record_t *record; 173 174 } asf_object_metadata_t; 175 176 typedef struct 177 { 178 ASF_OBJECT_COMMON 179 180 char *psz_title; 181 char *psz_artist; 182 char *psz_copyright; 183 char *psz_description; 184 char *psz_rating; 185 186 } asf_object_content_description_t; 187 188 #define ASF_CODEC_TYPE_VIDEO 0x0001 189 #define ASF_CODEC_TYPE_AUDIO 0x0002 190 #define ASF_CODEC_TYPE_UNKNOWN 0xffff 191 192 typedef struct asf_codec_entry 193 { 194 uint16_t i_type; 195 char *psz_name; 196 char *psz_description; 197 198 uint16_t i_information_length; 199 uint8_t *p_information; 200 201 struct asf_codec_entry *p_next; 202 } asf_codec_entry_t; 203 204 typedef struct 205 { 206 ASF_OBJECT_COMMON 207 guid_t i_reserved; 208 asf_codec_entry_t *codecs; 209 210 } asf_object_codec_list_t; 211 212 typedef struct 213 { 214 uint64_t i_offset; 215 uint64_t i_presentation_time; 216 uint16_t i_entry_length; 217 uint32_t i_send_time; 218 uint32_t i_flags; 219 uint32_t i_marker_description_length; 220 char *p_marker_description; 221 222 } asf_marker_t; 223 224 typedef struct 225 { 226 ASF_OBJECT_COMMON 227 guid_t i_reserved1; 228 uint32_t i_count; 229 uint16_t i_reserved2; 230 char *name; 231 asf_marker_t *marker; 232 233 } asf_object_marker_t; 234 235 typedef struct 236 { 237 ASF_OBJECT_COMMON 238 uint16_t i_language; 239 char **ppsz_language; 240 241 } asf_object_language_list_t; 242 243 typedef struct 244 { 245 ASF_OBJECT_COMMON 246 247 uint16_t i_bitrate; 248 struct 249 { 250 uint8_t i_stream_number; 251 uint32_t i_avg_bitrate; 252 } bitrate[ASF_MAX_STREAMNUMBER + 1]; 253 } asf_object_stream_bitrate_properties_t; 254 255 256 typedef struct 257 { 258 guid_t i_extension_id; 259 uint16_t i_data_size; 260 uint32_t i_info_length; 261 char *pi_info; 262 } asf_payload_extension_system_t; 263 #define ASF_EXTENSION_VIDEOFRAME_NEWFRAME 0x08 264 #define ASF_EXTENSION_VIDEOFRAME_IFRAME 0x01 265 #define ASF_EXTENSION_VIDEOFRAME_TYPE_MASK 0x07 266 267 typedef struct 268 { 269 ASF_OBJECT_COMMON 270 271 uint64_t i_start_time; 272 uint64_t i_end_time; 273 uint32_t i_data_bitrate; 274 uint32_t i_buffer_size; 275 uint32_t i_initial_buffer_fullness; 276 uint32_t i_alternate_data_bitrate; 277 uint32_t i_alternate_buffer_size; 278 uint32_t i_alternate_initial_buffer_fullness; 279 uint32_t i_maximum_object_size; 280 281 uint32_t i_flags; 282 uint16_t i_stream_number; 283 uint16_t i_language_index; 284 uint64_t i_average_time_per_frame; 285 286 uint16_t i_stream_name_count; 287 288 uint16_t i_payload_extension_system_count; 289 asf_payload_extension_system_t *p_ext; 290 291 uint16_t *pi_stream_name_language; 292 char **ppsz_stream_name; 293 294 asf_object_stream_properties_t *p_sp; 295 } asf_object_extended_stream_properties_t; 296 297 #define ASF_MAX_EXCLUSION_TYPE 2 298 typedef enum 299 { 300 LANGUAGE = ASF_MAX_EXCLUSION_TYPE, 301 BITRATE = 1, 302 UNKNOWN = 0 303 } asf_exclusion_type_t; 304 305 typedef struct 306 { 307 ASF_OBJECT_COMMON 308 309 asf_exclusion_type_t exclusion_type; 310 uint16_t i_stream_number_count; 311 uint16_t *pi_stream_number; 312 313 } asf_object_advanced_mutual_exclusion_t; 314 315 typedef struct 316 { 317 ASF_OBJECT_COMMON 318 319 uint16_t i_priority_count; 320 uint16_t *pi_priority_flag; 321 uint16_t *pi_priority_stream_number; 322 } asf_object_stream_prioritization_t; 323 324 typedef struct 325 { 326 ASF_OBJECT_COMMON 327 328 asf_exclusion_type_t exclusion_type; 329 uint16_t i_stream_number_count; 330 uint16_t *pi_stream_numbers; 331 } asf_object_bitrate_mutual_exclusion_t; 332 333 typedef struct 334 { 335 ASF_OBJECT_COMMON 336 337 uint16_t i_count; 338 char **ppsz_name; 339 char **ppsz_value; 340 } asf_object_extended_content_description_t; 341 342 /**************************************************************************** 343 * Special Root Object 344 ****************************************************************************/ 345 typedef struct 346 { 347 ASF_OBJECT_COMMON 348 349 asf_object_header_t *p_hdr; 350 asf_object_data_t *p_data; 351 /* could be NULL if !b_seekable or not-present */ 352 asf_object_index_t *p_index; 353 354 /* from asf_object_header_t */ 355 asf_object_file_properties_t *p_fp; 356 357 /* from asf_object_header_extension_t */ 358 asf_object_metadata_t *p_metadata; 359 360 } asf_object_root_t; 361 362 /**************************************************************************** 363 * asf_object_t: union of all objects. 364 ****************************************************************************/ 365 typedef union asf_object_u 366 { 367 asf_object_common_t common; 368 asf_object_header_t header; 369 asf_object_data_t data; 370 asf_object_index_t index; 371 asf_object_root_t root; 372 asf_object_file_properties_t file_properties; 373 asf_object_stream_properties_t stream_properties; 374 asf_object_header_extension_t header_extension; 375 asf_object_metadata_t metadata; 376 asf_object_codec_list_t codec_list; 377 asf_object_marker_t marker; 378 asf_object_language_list_t language_list; 379 asf_object_stream_bitrate_properties_t stream_bitrate; 380 asf_object_extended_stream_properties_t ext_stream; 381 asf_object_content_description_t content_description; 382 asf_object_advanced_mutual_exclusion_t advanced_mutual_exclusion; 383 asf_object_stream_prioritization_t stream_prioritization; 384 asf_object_bitrate_mutual_exclusion_t bitrate_mutual_exclusion; 385 asf_object_extended_content_description_t extended_content_description; 386 387 } asf_object_t; 388 389 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable ); 390 void ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root ); 391 392 int ASF_CountObject ( void *p_obj, const guid_t *p_guid ); 393 394 void *ASF_FindObject( void *p_obj, const guid_t *p_guid, int i_number ); 395 #endif 396