2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVCODEC_CBS_MPEG2_H
20 #define AVCODEC_CBS_MPEG2_H
27 MPEG2_START_PICTURE = 0x00,
28 MPEG2_START_SLICE_MIN = 0x01,
29 MPEG2_START_SLICE_MAX = 0xaf,
30 MPEG2_START_USER_DATA = 0xb2,
31 MPEG2_START_SEQUENCE_HEADER = 0xb3,
32 MPEG2_START_SEQUENCE_ERROR = 0xb4,
33 MPEG2_START_EXTENSION = 0xb5,
34 MPEG2_START_SEQUENCE_END = 0xb7,
35 MPEG2_START_GROUP = 0xb8,
38 #define MPEG2_START_IS_SLICE(type) \
39 ((type) >= MPEG2_START_SLICE_MIN && \
40 (type) <= MPEG2_START_SLICE_MAX)
43 MPEG2_EXTENSION_SEQUENCE = 0x1,
44 MPEG2_EXTENSION_SEQUENCE_DISPLAY = 0x2,
45 MPEG2_EXTENSION_QUANT_MATRIX = 0x3,
46 MPEG2_EXTENSION_COPYRIGHT = 0x4,
47 MPEG2_EXTENSION_SEQUENCE_SCALABLE = 0x5,
48 MPEG2_EXTENSION_PICTURE_DISPLAY = 0x7,
49 MPEG2_EXTENSION_PICTURE_CODING = 0x8,
50 MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE = 0x9,
51 MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0xa,
52 MPEG2_EXTENSION_CAMAERA_PARAMETERS = 0xb,
53 MPEG2_EXTENSION_ITU_T = 0xc,
57 typedef struct MPEG2RawSequenceHeader {
58 uint8_t sequence_header_code;
60 uint16_t horizontal_size_value;
61 uint16_t vertical_size_value;
62 uint8_t aspect_ratio_information;
63 uint8_t frame_rate_code;
64 uint32_t bit_rate_value;
65 uint16_t vbv_buffer_size_value;
66 uint8_t constrained_parameters_flag;
68 uint8_t load_intra_quantiser_matrix;
69 uint8_t intra_quantiser_matrix[64];
70 uint8_t load_non_intra_quantiser_matrix;
71 uint8_t non_intra_quantiser_matrix[64];
72 } MPEG2RawSequenceHeader;
74 typedef struct MPEG2RawUserData {
75 uint8_t user_data_start_code;
78 size_t user_data_length;
81 typedef struct MPEG2RawSequenceExtension {
82 uint8_t profile_and_level_indication;
83 uint8_t progressive_sequence;
84 uint8_t chroma_format;
85 uint8_t horizontal_size_extension;
86 uint8_t vertical_size_extension;
87 uint16_t bit_rate_extension;
88 uint8_t vbv_buffer_size_extension;
90 uint8_t frame_rate_extension_n;
91 uint8_t frame_rate_extension_d;
92 } MPEG2RawSequenceExtension;
94 typedef struct MPEG2RawSequenceDisplayExtension {
97 uint8_t colour_description;
98 uint8_t colour_primaries;
99 uint8_t transfer_characteristics;
100 uint8_t matrix_coefficients;
102 uint16_t display_horizontal_size;
103 uint16_t display_vertical_size;
104 } MPEG2RawSequenceDisplayExtension;
106 typedef struct MPEG2RawGroupOfPicturesHeader {
107 uint8_t group_start_code;
112 } MPEG2RawGroupOfPicturesHeader;
114 typedef struct MPEG2RawPictureHeader {
115 uint8_t picture_start_code;
117 uint16_t temporal_reference;
118 uint8_t picture_coding_type;
121 uint8_t full_pel_forward_vector;
122 uint8_t forward_f_code;
123 uint8_t full_pel_backward_vector;
124 uint8_t backward_f_code;
126 uint8_t extra_bit_picture;
127 } MPEG2RawPictureHeader;
129 typedef struct MPEG2RawPictureCodingExtension {
130 uint8_t f_code[2][2];
132 uint8_t intra_dc_precision;
133 uint8_t picture_structure;
134 uint8_t top_field_first;
135 uint8_t frame_pred_frame_dct;
136 uint8_t concealment_motion_vectors;
137 uint8_t q_scale_type;
138 uint8_t intra_vlc_format;
139 uint8_t alternate_scan;
140 uint8_t repeat_first_field;
141 uint8_t chroma_420_type;
142 uint8_t progressive_frame;
144 uint8_t composite_display_flag;
146 uint8_t field_sequence;
148 uint8_t burst_amplitude;
149 uint8_t sub_carrier_phase;
150 } MPEG2RawPictureCodingExtension;
152 typedef struct MPEG2RawQuantMatrixExtension {
153 uint8_t load_intra_quantiser_matrix;
154 uint8_t intra_quantiser_matrix[64];
155 uint8_t load_non_intra_quantiser_matrix;
156 uint8_t non_intra_quantiser_matrix[64];
157 uint8_t load_chroma_intra_quantiser_matrix;
158 uint8_t chroma_intra_quantiser_matrix[64];
159 uint8_t load_chroma_non_intra_quantiser_matrix;
160 uint8_t chroma_non_intra_quantiser_matrix[64];
161 } MPEG2RawQuantMatrixExtension;
163 typedef struct MPEG2RawPictureDisplayExtension {
164 uint16_t frame_centre_horizontal_offset[3];
165 uint16_t frame_centre_vertical_offset[3];
166 } MPEG2RawPictureDisplayExtension;
168 typedef struct MPEG2RawExtensionData {
169 uint8_t extension_start_code;
170 uint8_t extension_start_code_identifier;
173 MPEG2RawSequenceExtension sequence;
174 MPEG2RawSequenceDisplayExtension sequence_display;
175 MPEG2RawQuantMatrixExtension quant_matrix;
176 MPEG2RawPictureCodingExtension picture_coding;
177 MPEG2RawPictureDisplayExtension picture_display;
179 } MPEG2RawExtensionData;
181 typedef struct MPEG2RawSliceHeader {
182 uint8_t slice_vertical_position;
184 uint8_t slice_vertical_position_extension;
185 uint8_t priority_breakpoint;
187 uint8_t quantiser_scale_code;
189 uint8_t slice_extension_flag;
191 uint8_t slice_picture_id_enable;
192 uint8_t slice_picture_id;
194 uint8_t extra_bit_slice;
196 size_t extra_information_length;
197 uint8_t *extra_information;
198 } MPEG2RawSliceHeader;
200 typedef struct MPEG2RawSlice {
201 MPEG2RawSliceHeader header;
209 typedef struct CodedBitstreamMPEG2Context {
210 // Elements stored in headers which are required for other decoding.
211 uint16_t horizontal_size;
212 uint16_t vertical_size;
214 uint8_t scalable_mode;
215 uint8_t progressive_sequence;
216 uint8_t number_of_frame_centre_offsets;
219 uint8_t *write_buffer;
220 size_t write_buffer_size;
221 } CodedBitstreamMPEG2Context;
224 #endif /* AVCODEC_CBS_MPEG2_H */