1 /***************************************************************************** 2 * vc1.h 3 ***************************************************************************** 4 * Copyright (C) 2012-2017 L-SMASH project 5 * 6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com> 7 * 8 * Permission to use, copy, modify, and/or distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 *****************************************************************************/ 20 21 /* This file is available under an ISC license. */ 22 23 #define VC1_DEFAULT_BUFFER_SIZE (1<<16) 24 #define VC1_START_CODE_PREFIX_LENGTH 3 /* 0x000001 */ 25 #define VC1_START_CODE_SUFFIX_LENGTH 1 /* BDU type */ 26 #define VC1_START_CODE_LENGTH (VC1_START_CODE_PREFIX_LENGTH + VC1_START_CODE_SUFFIX_LENGTH) /* = 4 */ 27 28 typedef struct 29 { 30 uint8_t hrd_num_leaky_buckets; 31 } vc1_hrd_param_t; 32 33 typedef struct 34 { 35 uint8_t present; 36 uint8_t profile; 37 uint8_t level; 38 uint8_t colordiff_format; /* currently 4:2:0 only */ 39 uint8_t interlace; 40 uint8_t color_prim; 41 uint8_t transfer_char; 42 uint8_t matrix_coef; 43 uint8_t hrd_param_flag; 44 uint8_t aspect_width; 45 uint8_t aspect_height; 46 uint8_t framerate_flag; 47 uint32_t framerate_numerator; 48 uint32_t framerate_denominator; 49 uint16_t max_coded_width; 50 uint16_t max_coded_height; 51 uint16_t disp_horiz_size; 52 uint16_t disp_vert_size; 53 vc1_hrd_param_t hrd_param; 54 } vc1_sequence_header_t; 55 56 typedef struct 57 { 58 uint8_t present; 59 uint8_t closed_entry_point; 60 } vc1_entry_point_t; 61 62 typedef struct 63 { 64 uint8_t present; 65 uint8_t frame_coding_mode; 66 uint8_t type; 67 uint8_t closed_gop; 68 uint8_t start_of_sequence; 69 uint8_t random_accessible; 70 } vc1_picture_info_t; 71 72 typedef struct 73 { 74 uint8_t random_accessible; 75 uint8_t closed_gop; 76 uint8_t independent; 77 uint8_t non_bipredictive; 78 uint8_t disposable; 79 uint8_t *data; 80 uint32_t data_length; 81 uint8_t *incomplete_data; 82 uint32_t incomplete_data_length; 83 uint32_t number; 84 } vc1_access_unit_t; 85 86 typedef struct vc1_info_tag vc1_info_t; 87 88 typedef struct 89 { 90 lsmash_multiple_buffers_t *bank; 91 uint8_t *rbdu; 92 } vc1_stream_buffer_t; 93 94 struct vc1_info_tag 95 { 96 lsmash_vc1_specific_parameters_t dvc1_param; 97 vc1_sequence_header_t sequence; 98 vc1_entry_point_t entry_point; 99 vc1_picture_info_t picture; 100 vc1_access_unit_t access_unit; 101 uint8_t prev_bdu_type; 102 uint64_t ebdu_head_pos; 103 lsmash_bits_t *bits; 104 vc1_stream_buffer_t buffer; 105 }; 106 107 int vc1_setup_parser 108 ( 109 vc1_info_t *info, 110 int parse_only 111 ); 112 113 uint64_t vc1_find_next_start_code_prefix 114 ( 115 lsmash_bs_t *bs, 116 uint8_t *bdu_type, 117 uint64_t *trailing_zero_bytes 118 ); 119 120 int vc1_check_next_start_code_suffix 121 ( 122 lsmash_bs_t *bs, 123 uint8_t *p_bdu_type 124 ); 125 126 void vc1_cleanup_parser( vc1_info_t *info ); 127 int vc1_parse_sequence_header( vc1_info_t *info, uint8_t *ebdu, uint64_t ebdu_size, int probe ); 128 int vc1_parse_entry_point_header( vc1_info_t *info, uint8_t *ebdu, uint64_t ebdu_size, int probe ); 129 int vc1_parse_advanced_picture( lsmash_bits_t *bits, 130 vc1_sequence_header_t *sequence, vc1_picture_info_t *picture, 131 uint8_t *rbdu_buffer, uint8_t *ebdu, uint64_t ebdu_size ); 132 void vc1_update_au_property( vc1_access_unit_t *access_unit, vc1_picture_info_t *picture ); 133 int vc1_find_au_delimit_by_bdu_type( uint8_t bdu_type, uint8_t prev_bdu_type ); 134 int vc1_supplement_buffer( vc1_stream_buffer_t *buffer, vc1_access_unit_t *access_unit, uint32_t size ); 135