1 /* 2 * GPAC - Multimedia Framework C SDK 3 * 4 * Authors: Jean Le Feuvre 5 * Copyright (c) Telecom ParisTech 2000-2012 6 * All rights reserved 7 * 8 * This file is part of GPAC / Media Tools sub-project 9 * 10 * GPAC is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2, or (at your option) 13 * any later version. 14 * 15 * GPAC is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; see the file COPYING. If not, write to 22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 */ 25 26 27 #ifndef _GF_MEDIA_DEV_H_ 28 #define _GF_MEDIA_DEV_H_ 29 30 #include <gpac/media_tools.h> 31 #include <gpac/mpeg4_odf.h> 32 33 #ifndef GPAC_DISABLE_STREAMING 34 #include <gpac/ietf.h> 35 #endif 36 37 #ifndef GPAC_DISABLE_ISOM 38 void gf_media_get_sample_average_infos(GF_ISOFile *file, u32 Track, u32 *avgSize, u32 *MaxSize, u32 *TimeDelta, u32 *maxCTSDelta, u32 *const_duration, u32 *bandwidth); 39 #endif 40 41 42 #ifndef GPAC_DISABLE_MEDIA_IMPORT 43 GF_Err gf_import_message(GF_MediaImporter *import, GF_Err e, char *format, ...); 44 #endif /*GPAC_DISABLE_MEDIA_IMPORT*/ 45 46 #ifndef GPAC_DISABLE_AV_PARSERS 47 48 u32 gf_latm_get_value(GF_BitStream *bs); 49 50 #define GF_SVC_SSPS_ID_SHIFT 16 51 52 /*returns 0 if not a start code, or size of start code (3 or 4 bytes). If start code, bitstream 53 is positionned AFTER start code*/ 54 u32 gf_media_nalu_is_start_code(GF_BitStream *bs); 55 56 /*returns size of chunk between current and next startcode (excluding startcode sizes), 0 if no more startcodes (eos)*/ 57 u32 gf_media_nalu_next_start_code_bs(GF_BitStream *bs); 58 59 /*return nb bytes from current data until the next start code and set the size of the next start code (3 or 4 bytes) 60 returns data_len if no startcode found and sets sc_size to 0 (last nal in payload)*/ 61 u32 gf_media_nalu_next_start_code(const u8 *data, u32 data_len, u32 *sc_size); 62 63 u32 gf_media_nalu_emulation_bytes_remove_count(const u8 *buffer, u32 nal_size); 64 u32 gf_media_nalu_remove_emulation_bytes(const u8 *buffer_src, u8 *buffer_dst, u32 nal_size); 65 66 u32 gf_bs_get_ue(GF_BitStream *bs); 67 s32 gf_bs_get_se(GF_BitStream *bs); 68 void gf_bs_set_ue(GF_BitStream *bs, u32 num); 69 void gf_bs_set_se(GF_BitStream *bs, s32 num); 70 71 enum 72 { 73 /*SPS has been parsed*/ 74 AVC_SPS_PARSED = 1, 75 /*SPS has been declared to the upper layer*/ 76 AVC_SPS_DECLARED = 1<<1, 77 /*SUB-SPS has been parsed*/ 78 AVC_SUBSPS_PARSED = 1<<2, 79 /*SUB-SPS has been declared to the upper layer*/ 80 AVC_SUBSPS_DECLARED = 1<<3, 81 /*SPS extension has been parsed*/ 82 AVC_SPS_EXT_DECLARED = 1<<4, 83 }; 84 85 typedef struct 86 { 87 u8 cpb_removal_delay_length_minus1; 88 u8 dpb_output_delay_length_minus1; 89 u8 time_offset_length; 90 /*to be eventually completed by other hrd members*/ 91 } AVC_HRD; 92 93 typedef struct 94 { 95 s32 timing_info_present_flag; 96 u32 num_units_in_tick; 97 u32 time_scale; 98 s32 fixed_frame_rate_flag; 99 100 Bool aspect_ratio_info_present_flag; 101 u32 par_num, par_den; 102 103 Bool overscan_info_present_flag; 104 Bool video_signal_type_present_flag; 105 u8 video_format; 106 Bool video_full_range_flag; 107 108 Bool colour_description_present_flag; 109 u8 colour_primaries; 110 u8 transfer_characteristics; 111 u8 matrix_coefficients; 112 113 Bool nal_hrd_parameters_present_flag; 114 Bool vcl_hrd_parameters_present_flag; 115 Bool low_delay_hrd_flag; 116 AVC_HRD hrd; 117 118 Bool pic_struct_present_flag; 119 120 /*to be eventually completed by other vui members*/ 121 } AVC_VUI; 122 123 typedef struct 124 { 125 u32 left; 126 u32 right; 127 u32 top; 128 u32 bottom; 129 130 } AVC_CROP; 131 132 133 typedef struct 134 { 135 s32 profile_idc; 136 s32 level_idc; 137 s32 prof_compat; 138 s32 log2_max_frame_num; 139 u32 poc_type, poc_cycle_length; 140 s32 log2_max_poc_lsb; 141 s32 delta_pic_order_always_zero_flag; 142 s32 offset_for_non_ref_pic, offset_for_top_to_bottom_field; 143 Bool frame_mbs_only_flag; 144 Bool mb_adaptive_frame_field_flag; 145 u32 max_num_ref_frames; 146 Bool gaps_in_frame_num_value_allowed_flag; 147 u8 chroma_format; 148 u8 luma_bit_depth_m8; 149 u8 chroma_bit_depth_m8; 150 u32 ChromaArrayType; 151 152 s16 offset_for_ref_frame[256]; 153 154 u32 width, height; 155 156 Bool vui_parameters_present_flag; 157 AVC_VUI vui; 158 AVC_CROP crop; 159 160 /*used to discard repeated SPSs - 0: not parsed, 1 parsed, 2 sent*/ 161 u32 state; 162 163 u32 sbusps_crc; 164 165 /*for SVC stats during import*/ 166 u32 nb_ei, nb_ep, nb_eb; 167 } AVC_SPS; 168 169 typedef struct 170 { 171 s32 id; /* used to compare pps when storing SVC PSS */ 172 s32 sps_id; 173 Bool entropy_coding_mode_flag; 174 s32 pic_order_present; /* pic_order_present_flag*/ 175 s32 redundant_pic_cnt_present; /* redundant_pic_cnt_present_flag */ 176 u32 slice_group_count; /* num_slice_groups_minus1 + 1*/ 177 u32 mb_slice_group_map_type; 178 u32 pic_size_in_map_units_minus1; 179 u32 slice_group_change_rate_minus1; 180 /*used to discard repeated SPSs - 0: not parsed, 1 parsed, 2 sent*/ 181 u32 status; 182 Bool weighted_pred_flag; 183 u8 weighted_bipred_idc; 184 Bool deblocking_filter_control_present_flag; 185 u32 num_ref_idx_l0_default_active_minus1, num_ref_idx_l1_default_active_minus1; 186 } AVC_PPS; 187 188 typedef struct 189 { 190 s32 idr_pic_flag; 191 u8 temporal_id, priority_id, dependency_id, quality_id; 192 } SVC_NALUHeader; 193 194 typedef struct 195 { 196 u8 nal_ref_idc, nal_unit_type, field_pic_flag, bottom_field_flag; 197 u32 frame_num, idr_pic_id, poc_lsb, slice_type; 198 s32 delta_poc_bottom; 199 s32 delta_poc[2]; 200 s32 redundant_pic_cnt; 201 202 s32 poc; 203 u32 poc_msb, poc_msb_prev, poc_lsb_prev, frame_num_prev; 204 s32 frame_num_offset, frame_num_offset_prev; 205 206 AVC_SPS *sps; 207 AVC_PPS *pps; 208 SVC_NALUHeader NalHeader; 209 } AVCSliceInfo; 210 211 212 typedef struct 213 { 214 u32 frame_cnt; 215 u8 exact_match_flag; 216 u8 broken_link_flag; 217 u8 changing_slice_group_idc; 218 u8 valid; 219 } AVCSeiRecoveryPoint; 220 221 typedef struct 222 { 223 u8 pic_struct; 224 /*to be eventually completed by other pic_timing members*/ 225 } AVCSeiPicTiming; 226 227 typedef struct 228 { 229 Bool rpu_flag; 230 } AVCSeiItuTT35DolbyVision; 231 232 typedef struct 233 { 234 AVCSeiRecoveryPoint recovery_point; 235 AVCSeiPicTiming pic_timing; 236 AVCSeiItuTT35DolbyVision dovi; 237 /*to be eventually completed by other sei*/ 238 } AVCSei; 239 240 typedef struct 241 { 242 AVC_SPS sps[32]; /* range allowed in the spec is 0..31 */ 243 s8 sps_active_idx, pps_active_idx; /*currently active sps; must be initalized to -1 in order to discard not yet decodable SEIs*/ 244 245 AVC_PPS pps[255]; 246 247 AVCSliceInfo s_info; 248 AVCSei sei; 249 250 Bool is_svc; 251 u8 last_nal_type_parsed; 252 s8 last_ps_idx; 253 } AVCState; 254 255 typedef struct 256 { 257 u32 NALUnitHeader; 258 u8 track_ref_index; 259 s8 sample_offset; 260 u32 data_offset; 261 u32 data_length; 262 } SVC_Extractor; 263 264 265 /*return sps ID or -1 if error*/ 266 s32 gf_media_avc_read_sps(const u8 *sps_data, u32 sps_size, AVCState *avc, u32 subseq_sps, u32 *vui_flag_pos); 267 s32 gf_media_avc_read_sps_bs(GF_BitStream *bs, AVCState *avc, u32 subseq_sps, u32 *vui_flag_pos); 268 /*return pps ID or -1 if error*/ 269 s32 gf_media_avc_read_pps(const u8 *pps_data, u32 pps_size, AVCState *avc); 270 s32 gf_media_avc_read_pps_bs(GF_BitStream *bs, AVCState *avc); 271 272 /*is slice containing intra MB only*/ 273 Bool gf_media_avc_slice_is_intra(AVCState *avc); 274 /*parses NALU, updates avc state and returns: 275 1 if NALU part of new frame 276 0 if NALU part of prev frame 277 -1 if bitstream error 278 */ 279 s32 gf_media_avc_parse_nalu(GF_BitStream *bs, AVCState *avc); 280 /*remove SEI messages not allowed in MP4*/ 281 /*nota: 'buffer' remains unmodified but cannot be set const*/ 282 u32 gf_media_avc_reformat_sei(u8 *buffer, u32 nal_size, Bool isobmf_rewrite, AVCState *avc); 283 284 #ifndef GPAC_DISABLE_ISOM 285 GF_Err gf_media_avc_change_par(GF_AVCConfig *avcc, s32 ar_n, s32 ar_d); 286 GF_Err gf_media_hevc_change_par(GF_HEVCConfig *hvcc, s32 ar_n, s32 ar_d); 287 #endif 288 289 290 291 typedef struct 292 { 293 Bool profile_present_flag, level_present_flag, tier_flag; 294 u8 profile_space; 295 u8 profile_idc; 296 u32 profile_compatibility_flag; 297 u8 level_idc; 298 } HEVC_SublayerPTL; 299 300 typedef struct 301 { 302 u8 profile_space, tier_flag, profile_idc, level_idc; 303 u32 profile_compatibility_flag; 304 Bool general_progressive_source_flag; 305 Bool general_interlaced_source_flag; 306 Bool general_non_packed_constraint_flag; 307 Bool general_frame_only_constraint_flag; 308 u64 general_reserved_44bits; 309 310 HEVC_SublayerPTL sub_ptl[8]; 311 } HEVC_ProfileTierLevel; 312 313 typedef struct 314 { 315 u32 num_negative_pics; 316 u32 num_positive_pics; 317 s32 delta_poc[16]; 318 } HEVC_ReferencePictureSets; 319 320 typedef struct 321 { 322 s32 id, vps_id; 323 /*used to discard repeated SPSs - 0: not parsed, 1 parsed, 2 stored*/ 324 u32 state; 325 u32 crc; 326 u32 width, height; 327 328 HEVC_ProfileTierLevel ptl; 329 330 u8 chroma_format_idc; 331 Bool cw_flag ; 332 u32 cw_left, cw_right, cw_top, cw_bottom; 333 u8 bit_depth_luma; 334 u8 bit_depth_chroma; 335 u8 log2_max_pic_order_cnt_lsb; 336 Bool separate_colour_plane_flag; 337 338 u32 max_CU_width, max_CU_height, max_CU_depth; 339 u32 bitsSliceSegmentAddress; 340 341 u32 num_short_term_ref_pic_sets, num_long_term_ref_pic_sps; 342 HEVC_ReferencePictureSets rps[64]; 343 344 345 Bool aspect_ratio_info_present_flag, long_term_ref_pics_present_flag, temporal_mvp_enable_flag, sample_adaptive_offset_enabled_flag; 346 u8 sar_idc; 347 u16 sar_width, sar_height; 348 Bool has_timing_info; 349 u32 num_units_in_tick, time_scale; 350 Bool poc_proportional_to_timing_flag; 351 u32 num_ticks_poc_diff_one_minus1; 352 353 Bool video_full_range_flag; 354 Bool colour_description_present_flag; 355 u8 colour_primaries, transfer_characteristic, matrix_coeffs; 356 u32 rep_format_idx; 357 358 u8 sps_ext_or_max_sub_layers_minus1, max_sub_layers_minus1, update_rep_format_flag, sub_layer_ordering_info_present_flag, scaling_list_enable_flag, infer_scaling_list_flag, scaling_list_ref_layer_id, scaling_list_data_present_flag, asymmetric_motion_partitions_enabled_flag, pcm_enabled_flag, strong_intra_smoothing_enable_flag, vui_parameters_present_flag; 359 u32 log2_diff_max_min_luma_coding_block_size; 360 u32 log2_min_transform_block_size, log2_min_luma_coding_block_size, log2_max_transform_block_size; 361 u32 max_transform_hierarchy_depth_inter, max_transform_hierarchy_depth_intra; 362 363 u8 pcm_sample_bit_depth_luma_minus1, pcm_sample_bit_depth_chroma_minus1, pcm_loop_filter_disable_flag; 364 u32 log2_min_pcm_luma_coding_block_size_minus3, log2_diff_max_min_pcm_luma_coding_block_size; 365 u8 overscan_info_present, overscan_appropriate, video_signal_type_present_flag, video_format; 366 367 u8 chroma_loc_info_present_flag; 368 u32 chroma_sample_loc_type_top_field, chroma_sample_loc_type_bottom_field; 369 370 u8 neutra_chroma_indication_flag, field_seq_flag, frame_field_info_present_flag; 371 u8 default_display_window_flag; 372 u32 left_offset, right_offset, top_offset, bottom_offset; 373 u8 hrd_parameters_present_flag; 374 } HEVC_SPS; 375 376 typedef struct 377 { 378 s32 id; 379 u32 sps_id; 380 /*used to discard repeated SPSs - 0: not parsed, 1 parsed, 2 stored*/ 381 u32 state; 382 u32 crc; 383 384 Bool dependent_slice_segments_enabled_flag, tiles_enabled_flag, uniform_spacing_flag; 385 u32 num_extra_slice_header_bits, num_ref_idx_l0_default_active, num_ref_idx_l1_default_active; 386 Bool slice_segment_header_extension_present_flag, output_flag_present_flag, lists_modification_present_flag, cabac_init_present_flag; 387 Bool weighted_pred_flag, weighted_bipred_flag, slice_chroma_qp_offsets_present_flag, deblocking_filter_override_enabled_flag, loop_filter_across_slices_enabled_flag, entropy_coding_sync_enabled_flag; 388 Bool loop_filter_across_tiles_enabled_flag; 389 s32 pic_init_qp_minus26; 390 u32 num_tile_columns, num_tile_rows; 391 u32 column_width[22], row_height[20]; 392 393 Bool sign_data_hiding_flag, constrained_intra_pred_flag, transform_skip_enabled_flag, cu_qp_delta_enabled_flag, transquant_bypass_enable_flag; 394 u32 diff_cu_qp_delta_depth, pic_cb_qp_offset, pic_cr_qp_offset; 395 396 Bool deblocking_filter_control_present_flag, pic_disable_deblocking_filter_flag, pic_scaling_list_data_present_flag; 397 u32 beta_offset_div2, tc_offset_div2, log2_parallel_merge_level_minus2; 398 399 } HEVC_PPS; 400 401 typedef struct RepFormat 402 { 403 u32 chroma_format_idc; 404 u32 pic_width_luma_samples; 405 u32 pic_height_luma_samples; 406 u32 bit_depth_luma; 407 u32 bit_depth_chroma; 408 u8 separate_colour_plane_flag; 409 } HEVC_RepFormat; 410 411 typedef struct 412 { 413 u16 avg_bit_rate, max_bit_rate, avg_pic_rate; 414 u8 constand_pic_rate_idc; 415 } HEVC_RateInfo; 416 417 418 #define MAX_LHVC_LAYERS 4 419 #define MAX_NUM_LAYER_SETS 1024 420 typedef struct 421 { 422 s32 id; 423 /*used to discard repeated SPSs - 0: not parsed, 1 parsed, 2 stored*/ 424 u32 state; 425 s32 bit_pos_vps_extensions; 426 u32 crc; 427 Bool vps_extension_found; 428 u32 max_layers, max_sub_layers, max_layer_id, num_layer_sets; 429 Bool temporal_id_nesting; 430 HEVC_ProfileTierLevel ptl; 431 432 HEVC_SublayerPTL sub_ptl[8]; 433 HEVC_RateInfo rates[8]; 434 435 436 u32 scalability_mask[16]; 437 u32 dimension_id[MAX_LHVC_LAYERS][16]; 438 u32 layer_id_in_nuh[MAX_LHVC_LAYERS]; 439 u32 layer_id_in_vps[MAX_LHVC_LAYERS]; 440 441 u8 num_profile_tier_level, num_output_layer_sets; 442 u32 profile_level_tier_idx[MAX_LHVC_LAYERS]; 443 HEVC_ProfileTierLevel ext_ptl[MAX_LHVC_LAYERS]; 444 445 u32 num_rep_formats; 446 HEVC_RepFormat rep_formats[16]; 447 u32 rep_format_idx[16]; 448 Bool base_layer_internal_flag, base_layer_available_flag; 449 u8 num_layers_in_id_list[MAX_NUM_LAYER_SETS]; 450 u8 direct_dependency_flag[MAX_LHVC_LAYERS][MAX_LHVC_LAYERS]; 451 Bool output_layer_flag[MAX_LHVC_LAYERS][MAX_LHVC_LAYERS]; 452 u8 profile_tier_level_idx[MAX_LHVC_LAYERS][MAX_LHVC_LAYERS]; 453 Bool alt_output_layer_flag[MAX_LHVC_LAYERS]; 454 u8 num_necessary_layers[MAX_LHVC_LAYERS]; 455 Bool necessary_layers_flag[MAX_LHVC_LAYERS][MAX_LHVC_LAYERS]; 456 u8 LayerSetLayerIdList[MAX_LHVC_LAYERS][MAX_LHVC_LAYERS]; 457 u8 LayerSetLayerIdListMax[MAX_LHVC_LAYERS]; //the highest value in LayerSetLayerIdList[i] 458 } HEVC_VPS; 459 460 typedef struct 461 { 462 AVCSeiRecoveryPoint recovery_point; 463 AVCSeiPicTiming pic_timing; 464 AVCSeiItuTT35DolbyVision dovi; 465 } HEVC_SEI; 466 467 typedef struct 468 { 469 u8 nal_unit_type; 470 u32 frame_num, poc_lsb, slice_type, header_size_with_emulation; 471 472 s32 redundant_pic_cnt; 473 474 s32 poc; 475 u32 poc_msb, poc_msb_prev, poc_lsb_prev, frame_num_prev; 476 s32 frame_num_offset, frame_num_offset_prev; 477 478 Bool dependent_slice_segment_flag; 479 Bool first_slice_segment_in_pic_flag; 480 u32 slice_segment_address; 481 u8 prev_layer_id_plus1; 482 483 //bit offset of the num_entry_point (if present) field 484 s32 entry_point_start_bits; 485 u64 header_size_bits; 486 //byte offset of the payload start (after byte alignment) 487 s32 payload_start_offset; 488 489 s32 slice_qp_delta_start_bits; 490 s32 slice_qp_delta; 491 492 HEVC_SPS *sps; 493 HEVC_PPS *pps; 494 } HEVCSliceInfo; 495 496 typedef struct _hevc_state 497 { 498 //set by user 499 Bool full_slice_header_parse; 500 501 //all other vars set by parser 502 503 HEVC_SPS sps[16]; /* range allowed in the spec is 0..15 */ 504 s8 sps_active_idx; /*currently active sps; must be initalized to -1 in order to discard not yet decodable SEIs*/ 505 506 HEVC_PPS pps[64]; 507 508 HEVC_VPS vps[16]; 509 510 HEVCSliceInfo s_info; 511 HEVC_SEI sei; 512 513 //-1 or the value of the vps/sps/pps ID of the nal just parsed 514 s32 last_parsed_vps_id; 515 s32 last_parsed_sps_id; 516 s32 last_parsed_pps_id; 517 518 // Dolby Vision 519 Bool dv_rpu; 520 Bool dv_el; 521 } HEVCState; 522 523 typedef struct hevc_combine{ 524 Bool is_hevccombine, first_slice_segment; 525 s32 buffer_header_src_alloc; // because payload_start_offset is s32, otherwhise it's an u32 526 u8 *buffer_header_src; 527 }Combine; 528 529 enum 530 { 531 GF_HEVC_SLICE_TYPE_B = 0, 532 GF_HEVC_SLICE_TYPE_P = 1, 533 GF_HEVC_SLICE_TYPE_I = 2, 534 }; 535 s32 gf_media_hevc_read_vps(u8 *data, u32 size, HEVCState *hevc); 536 s32 gf_media_hevc_read_vps_bs(GF_BitStream *bs, HEVCState *hevc); 537 s32 gf_media_hevc_read_sps(u8 *data, u32 size, HEVCState *hevc); 538 s32 gf_media_hevc_read_sps_bs(GF_BitStream *bs, HEVCState *hevc); 539 s32 gf_media_hevc_read_pps(u8 *data, u32 size, HEVCState *hevc); 540 s32 gf_media_hevc_read_pps_bs(GF_BitStream *bs, HEVCState *hevc); 541 s32 gf_media_hevc_parse_nalu(u8 *data, u32 size, HEVCState *hevc, u8 *nal_unit_type, u8 *temporal_id, u8 *layer_id); 542 Bool gf_media_hevc_slice_is_intra(HEVCState *hevc); 543 Bool gf_media_hevc_slice_is_IDR(HEVCState *hevc); 544 //parses VPS and rewrites data buffer after removing VPS extension 545 s32 gf_media_hevc_read_vps_ex(u8 *data, u32 *size, HEVCState *hevc, Bool remove_extensions); 546 547 void gf_media_hevc_parse_ps(GF_HEVCConfig* hevccfg, HEVCState* hevc, u32 nal_type); 548 s32 gf_media_hevc_parse_nalu_bs(GF_BitStream *bs, HEVCState *hevc, u8 *nal_unit_type, u8 *temporal_id, u8 *layer_id); 549 550 GF_Err gf_hevc_get_sps_info_with_state(HEVCState *hevc_state, u8 *sps_data, u32 sps_size, u32 *sps_id, u32 *width, u32 *height, s32 *par_n, s32 *par_d); 551 552 /*parses HEVC SEI and fill state accordingly*/ 553 void gf_media_hevc_parse_sei(char* buffer, u32 nal_size, HEVCState *hevc); 554 555 556 GF_Err gf_media_parse_ivf_file_header(GF_BitStream *bs, u32 *width, u32*height, u32 *codec_fourcc, u32 *frame_rate, u32 *time_scale, u32 *num_frames); 557 558 559 560 #define VP9_MAX_FRAMES_IN_SUPERFRAME 16 561 562 GF_Err gf_media_vp9_parse_sample(GF_BitStream *bs, GF_VPConfig *vp9_cfg, Bool *key_frame, u32 *FrameWidth, u32 *FrameHeight, u32 *renderWidth, u32 *renderHeight); 563 GF_Err gf_media_vp9_parse_superframe(GF_BitStream *bs, u64 ivf_frame_size, u32 *num_frames_in_superframe, u32 frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME], u32 *superframe_index_size); 564 565 566 567 #define AV1_MAX_TILE_ROWS 64 568 #define AV1_MAX_TILE_COLS 64 569 570 typedef enum { 571 AV1_KEY_FRAME = 0, 572 AV1_INTER_FRAME = 1, 573 AV1_INTRA_ONLY_FRAME = 2, 574 AV1_SWITCH_FRAME = 3, 575 } AV1FrameType; 576 577 typedef struct 578 { 579 //offset in bytes after first byte of obu, including its header 580 u32 obu_start_offset; 581 u32 size; 582 } AV1Tile; 583 584 typedef struct 585 { 586 Bool is_first_frame; 587 Bool seen_frame_header, seen_seq_header; 588 Bool key_frame, show_frame; 589 AV1FrameType frame_type; 590 GF_List *header_obus, *frame_obus; /*GF_AV1_OBUArrayEntry*/ 591 AV1Tile tiles[AV1_MAX_TILE_ROWS * AV1_MAX_TILE_COLS]; 592 u32 nb_tiles_in_obu; 593 u8 refresh_frame_flags; 594 u8 order_hint; 595 u8 allow_high_precision_mv; 596 u8 show_existing_frame, frame_to_show_map_idx; 597 //indicates the size of the uncompressed_header syntax element. This is set back to 0 at the next OBU parsing 598 u16 uncompressed_header_bytes; 599 } AV1StateFrame; 600 601 #define AV1_NUM_REF_FRAMES 8 602 603 typedef struct 604 { 605 s32 coefs[AV1_NUM_REF_FRAMES][6]; 606 } AV1GMParams; 607 608 typedef struct 609 { 610 /*importing options*/ 611 Bool keep_temporal_delim; 612 /*parser config*/ 613 //if set only header frames are stored 614 Bool skip_frames; 615 //if set, frame OBUs are not pushed to the frame_obus OBU list but are written in the below bitstream 616 Bool mem_mode; 617 /*bitstream object for mem mode - this bitstream is NOT destroyed by gf_av1_reset_state(state, GF_TRUE) */ 618 GF_BitStream *bs; 619 Bool bs_overread, unframed; 620 u8 *frame_obus; 621 u32 frame_obus_alloc; 622 623 /*general sequence information*/ 624 Bool frame_id_numbers_present_flag; 625 Bool reduced_still_picture_header; 626 Bool decoder_model_info_present_flag; 627 u16 OperatingPointIdc; 628 u32 width, height, UpscaledWidth; 629 u32 tb_num, tb_den; 630 631 Bool use_128x128_superblock; 632 u8 frame_width_bits_minus_1, frame_height_bits_minus_1; 633 u8 equal_picture_interval; 634 u8 delta_frame_id_length_minus_2; 635 u8 additional_frame_id_length_minus_1; 636 u8 seq_force_integer_mv; 637 u8 seq_force_screen_content_tools; 638 Bool enable_superres; 639 Bool enable_order_hint; 640 Bool enable_cdef; 641 Bool enable_restoration; 642 Bool enable_warped_motion; 643 u8 OrderHintBits; 644 Bool enable_ref_frame_mvs; 645 Bool film_grain_params_present; 646 u8 buffer_delay_length; 647 u8 frame_presentation_time_length; 648 u32 buffer_removal_time_length; 649 u8 operating_points_count; 650 u8 decoder_model_present_for_this_op[32]; 651 u8 operating_point_idc[32]; 652 653 u32 tileRows, tileCols, tileRowsLog2, tileColsLog2; 654 u8 tile_size_bytes; /*coding tile header size*/ 655 Bool separate_uv_delta_q; 656 657 /*Needed for RFC6381*/ 658 Bool still_picture; 659 u8 bit_depth; 660 Bool color_description_present_flag; 661 u8 color_primaries, transfer_characteristics, matrix_coefficients; 662 Bool color_range; 663 664 /*AV1 config record - shall not be null when parsing - this is NOT destroyed by gf_av1_reset_state(state, GF_TRUE) */ 665 GF_AV1Config *config; 666 667 /*OBU parsing state, reset at each obu*/ 668 Bool obu_has_size_field, obu_extension_flag; 669 u8 temporal_id, spatial_id; 670 ObuType obu_type; 671 672 /*inter-frames state */ 673 u8 RefOrderHint[AV1_NUM_REF_FRAMES]; 674 u8 RefValid[AV1_NUM_REF_FRAMES]; 675 u8 OrderHints[AV1_NUM_REF_FRAMES]; 676 677 AV1GMParams GmParams; 678 AV1GMParams PrevGmParams; 679 AV1GMParams SavedGmParams[AV1_NUM_REF_FRAMES]; 680 u8 RefFrameType[AV1_NUM_REF_FRAMES]; 681 682 /*frame parsing state*/ 683 AV1StateFrame frame_state; 684 } AV1State; 685 686 GF_Err aom_av1_parse_temporal_unit_from_section5(GF_BitStream *bs, AV1State *state); 687 GF_Err aom_av1_parse_temporal_unit_from_annexb(GF_BitStream *bs, AV1State *state); 688 GF_Err aom_av1_parse_temporal_unit_from_ivf(GF_BitStream *bs, AV1State *state); 689 690 GF_Err gf_media_parse_ivf_frame_header(GF_BitStream *bs, u64 *frame_size, u64 *pts); 691 692 Bool gf_media_probe_ivf(GF_BitStream *bs); 693 Bool gf_media_aom_probe_annexb(GF_BitStream *bs); 694 695 /*parses one OBU*/ 696 GF_Err gf_media_aom_av1_parse_obu(GF_BitStream *bs, ObuType *obu_type, u64 *obu_size, u32 *obu_hdr_size, AV1State *state); 697 698 Bool av1_is_obu_header(ObuType obu_type); 699 700 /*! init av1 frame parsing state 701 \param state the frame parser 702 */ 703 void gf_av1_init_state(AV1State *state); 704 705 /*! reset av1 frame parsing state - this does not destroy the structure. 706 \param state the frame parser 707 \param is_destroy if TRUE, destroy internal reference picture lists 708 */ 709 void gf_av1_reset_state(AV1State *state, Bool is_destroy); 710 711 u64 gf_av1_leb128_read(GF_BitStream *bs, u8 *opt_Leb128Bytes); 712 u32 gf_av1_leb128_size(u64 value); 713 u64 gf_av1_leb128_write(GF_BitStream *bs, u64 value); 714 GF_Err gf_av1_parse_obu_header(GF_BitStream *bs, ObuType *obu_type, Bool *obu_extension_flag, Bool *obu_has_size_field, u8 *temporal_id, u8 *spatial_id); 715 716 typedef struct 717 { 718 u32 picture_size; 719 u16 deprecated_number_of_slices; 720 u8 log2_desired_slice_size_in_mb; 721 } GF_ProResPictureInfo; 722 723 typedef struct 724 { 725 u32 frame_size; 726 u32 frame_identifier; 727 u16 frame_hdr_size; 728 u8 version; 729 u32 encoder_id; 730 u16 width; 731 u16 height; 732 u8 chroma_format; 733 u8 interlaced_mode; 734 u8 aspect_ratio_information; 735 u8 framerate_code; 736 u8 color_primaries; 737 u8 transfer_characteristics; 738 u8 matrix_coefficients; 739 u8 alpha_channel_type; 740 u8 load_luma_quant_matrix, load_chroma_quant_matrix; 741 u8 luma_quant_matrix[8][8]; 742 u8 chroma_quant_matrix[8][8]; 743 744 u8 nb_pic; //1 or 2 745 //for now we don't parse this 746 // GF_ProResPictureInfo pictures[2]; 747 } GF_ProResFrameInfo; 748 749 GF_Err gf_media_prores_parse_bs(GF_BitStream *bs, GF_ProResFrameInfo *prores_frame); 750 751 #endif /*GPAC_DISABLE_AV_PARSERS*/ 752 753 typedef struct 754 { 755 u8 rate_idx; 756 u8 pck_size; 757 } QCPRateTable; 758 759 760 #if !defined(GPAC_DISABLE_ISOM) && !defined(GPAC_DISABLE_STREAMING) 761 762 GP_RTPPacketizer *gf_rtp_packetizer_create_and_init_from_file(GF_ISOFile *file, 763 u32 TrackNum, 764 void *cbk_obj, 765 void (*OnNewPacket)(void *cbk, GF_RTPHeader *header), 766 void (*OnPacketDone)(void *cbk, GF_RTPHeader *header), 767 void (*OnDataReference)(void *cbk, u32 payload_size, u32 offset_from_orig), 768 void (*OnData)(void *cbk, u8 *data, u32 data_size, Bool is_head), 769 u32 Path_MTU, 770 u32 max_ptime, 771 u32 default_rtp_rate, 772 u32 flags, 773 u8 PayloadID, 774 Bool copy_media, 775 u32 InterleaveGroupID, 776 u8 InterleaveGroupPriority); 777 778 void gf_media_format_ttxt_sdp(GP_RTPPacketizer *builder, char *payload_name, char *sdpLine, u32 w, u32 h, s32 tx, s32 ty, s16 l, u32 max_w, u32 max_h, char *tx3g_base64); 779 780 #endif 781 782 783 #ifndef GPAC_DISABLE_VTT 784 785 typedef struct _webvtt_parser GF_WebVTTParser; 786 typedef struct _webvtt_sample GF_WebVTTSample; 787 788 GF_WebVTTParser *gf_webvtt_parser_new(); 789 GF_Err gf_webvtt_parser_init(GF_WebVTTParser *parser, FILE *vtt_file, s32 unicode_type, Bool is_srt, 790 void *user, GF_Err (*report_message)(void *, GF_Err, char *, const char *), 791 void (*on_sample_parsed)(void *, GF_WebVTTSample *), 792 void (*on_header_parsed)(void *, const char *)); 793 GF_Err gf_webvtt_parser_parse(GF_WebVTTParser *parser); 794 void gf_webvtt_parser_del(GF_WebVTTParser *parser); 795 void gf_webvtt_parser_suspend(GF_WebVTTParser *vttparser); 796 void gf_webvtt_parser_restart(GF_WebVTTParser *parser); 797 798 #include <gpac/webvtt.h> 799 void gf_webvtt_parser_cue_callback(GF_WebVTTParser *parser, void (*on_cue_read)(void *, GF_WebVTTCue *), void *udta); 800 GF_Err gf_webvtt_merge_cues(GF_WebVTTParser *parser, u64 start, GF_List *cues); 801 GF_Err gf_webvtt_parser_finalize(GF_WebVTTParser *parser, u64 duration); 802 803 void gf_webvtt_sample_del(GF_WebVTTSample * samp); 804 u64 gf_webvtt_sample_get_start(GF_WebVTTSample * samp); 805 u64 gf_webvtt_sample_get_end(GF_WebVTTSample * samp); 806 807 808 809 #ifndef GPAC_DISABLE_ISOM 810 GF_Err gf_webvtt_dump_header(FILE *dump, GF_ISOFile *file, u32 track, Bool box_mode, u32 index); 811 GF_Err gf_webvtt_parser_dump_done(GF_WebVTTParser *parser, u32 duration); 812 #endif /* GPAC_DISABLE_ISOM */ 813 814 #endif /* GPAC_DISABLE_VTT */ 815 816 817 #define M4V_VO_START_CODE 0x00 818 #define M4V_VOL_START_CODE 0x20 819 #define M4V_VOP_START_CODE 0xB6 820 #define M4V_VISOBJ_START_CODE 0xB5 821 #define M4V_VOS_START_CODE 0xB0 822 #define M4V_GOV_START_CODE 0xB3 823 #define M4V_UDTA_START_CODE 0xB2 824 825 826 #define M2V_PIC_START_CODE 0x00 827 #define M2V_SEQ_START_CODE 0xB3 828 #define M2V_EXT_START_CODE 0xB5 829 #define M2V_GOP_START_CODE 0xB8 830 831 832 #endif /*_GF_MEDIA_DEV_H_*/ 833 834