2 * This file is part of Libav.
4 * Libav 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 * Libav 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 Libav; 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
25 #include "libavutil/buffer.h"
29 MPEG2_START_PICTURE
= 0x00,
30 MPEG2_START_SLICE_MIN
= 0x01,
31 MPEG2_START_SLICE_MAX
= 0xaf,
32 MPEG2_START_USER_DATA
= 0xb2,
33 MPEG2_START_SEQUENCE_HEADER
= 0xb3,
34 MPEG2_START_SEQUENCE_ERROR
= 0xb4,
35 MPEG2_START_EXTENSION
= 0xb5,
36 MPEG2_START_SEQUENCE_END
= 0xb7,
37 MPEG2_START_GROUP
= 0xb8,
40 #define MPEG2_START_IS_SLICE(type) \
41 ((type) >= MPEG2_START_SLICE_MIN && \
42 (type) <= MPEG2_START_SLICE_MAX)
45 MPEG2_EXTENSION_SEQUENCE
= 0x1,
46 MPEG2_EXTENSION_SEQUENCE_DISPLAY
= 0x2,
47 MPEG2_EXTENSION_QUANT_MATRIX
= 0x3,
48 MPEG2_EXTENSION_COPYRIGHT
= 0x4,
49 MPEG2_EXTENSION_SEQUENCE_SCALABLE
= 0x5,
50 MPEG2_EXTENSION_PICTURE_DISPLAY
= 0x7,
51 MPEG2_EXTENSION_PICTURE_CODING
= 0x8,
52 MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE
= 0x9,
53 MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE
= 0xa,
54 MPEG2_EXTENSION_CAMAERA_PARAMETERS
= 0xb,
55 MPEG2_EXTENSION_ITU_T
= 0xc,
59 typedef struct MPEG2RawSequenceHeader
{
60 uint8_t sequence_header_code
;
62 uint16_t horizontal_size_value
;
63 uint16_t vertical_size_value
;
64 uint8_t aspect_ratio_information
;
65 uint8_t frame_rate_code
;
66 uint32_t bit_rate_value
;
67 uint16_t vbv_buffer_size_value
;
68 uint8_t constrained_parameters_flag
;
70 uint8_t load_intra_quantiser_matrix
;
71 uint8_t intra_quantiser_matrix
[64];
72 uint8_t load_non_intra_quantiser_matrix
;
73 uint8_t non_intra_quantiser_matrix
[64];
74 } MPEG2RawSequenceHeader
;
76 typedef struct MPEG2RawUserData
{
77 uint8_t user_data_start_code
;
80 size_t user_data_length
;
81 AVBufferRef
*user_data_ref
;
84 typedef struct MPEG2RawSequenceExtension
{
85 uint8_t profile_and_level_indication
;
86 uint8_t progressive_sequence
;
87 uint8_t chroma_format
;
88 uint8_t horizontal_size_extension
;
89 uint8_t vertical_size_extension
;
90 uint16_t bit_rate_extension
;
91 uint8_t vbv_buffer_size_extension
;
93 uint8_t frame_rate_extension_n
;
94 uint8_t frame_rate_extension_d
;
95 } MPEG2RawSequenceExtension
;
97 typedef struct MPEG2RawSequenceDisplayExtension
{
100 uint8_t colour_description
;
101 uint8_t colour_primaries
;
102 uint8_t transfer_characteristics
;
103 uint8_t matrix_coefficients
;
105 uint16_t display_horizontal_size
;
106 uint16_t display_vertical_size
;
107 } MPEG2RawSequenceDisplayExtension
;
109 typedef struct MPEG2RawGroupOfPicturesHeader
{
110 uint8_t group_start_code
;
115 } MPEG2RawGroupOfPicturesHeader
;
117 typedef struct MPEG2RawPictureHeader
{
118 uint8_t picture_start_code
;
120 uint16_t temporal_reference
;
121 uint8_t picture_coding_type
;
124 uint8_t full_pel_forward_vector
;
125 uint8_t forward_f_code
;
126 uint8_t full_pel_backward_vector
;
127 uint8_t backward_f_code
;
129 uint8_t extra_bit_picture
;
130 } MPEG2RawPictureHeader
;
132 typedef struct MPEG2RawPictureCodingExtension
{
133 uint8_t f_code
[2][2];
135 uint8_t intra_dc_precision
;
136 uint8_t picture_structure
;
137 uint8_t top_field_first
;
138 uint8_t frame_pred_frame_dct
;
139 uint8_t concealment_motion_vectors
;
140 uint8_t q_scale_type
;
141 uint8_t intra_vlc_format
;
142 uint8_t alternate_scan
;
143 uint8_t repeat_first_field
;
144 uint8_t chroma_420_type
;
145 uint8_t progressive_frame
;
147 uint8_t composite_display_flag
;
149 uint8_t field_sequence
;
151 uint8_t burst_amplitude
;
152 uint8_t sub_carrier_phase
;
153 } MPEG2RawPictureCodingExtension
;
155 typedef struct MPEG2RawQuantMatrixExtension
{
156 uint8_t load_intra_quantiser_matrix
;
157 uint8_t intra_quantiser_matrix
[64];
158 uint8_t load_non_intra_quantiser_matrix
;
159 uint8_t non_intra_quantiser_matrix
[64];
160 uint8_t load_chroma_intra_quantiser_matrix
;
161 uint8_t chroma_intra_quantiser_matrix
[64];
162 uint8_t load_chroma_non_intra_quantiser_matrix
;
163 uint8_t chroma_non_intra_quantiser_matrix
[64];
164 } MPEG2RawQuantMatrixExtension
;
166 typedef struct MPEG2RawPictureDisplayExtension
{
167 uint16_t frame_centre_horizontal_offset
[3];
168 uint16_t frame_centre_vertical_offset
[3];
169 } MPEG2RawPictureDisplayExtension
;
171 typedef struct MPEG2RawExtensionData
{
172 uint8_t extension_start_code
;
173 uint8_t extension_start_code_identifier
;
176 MPEG2RawSequenceExtension sequence
;
177 MPEG2RawSequenceDisplayExtension sequence_display
;
178 MPEG2RawQuantMatrixExtension quant_matrix
;
179 MPEG2RawPictureCodingExtension picture_coding
;
180 MPEG2RawPictureDisplayExtension picture_display
;
182 } MPEG2RawExtensionData
;
184 typedef struct MPEG2RawSliceHeader
{
185 uint8_t slice_vertical_position
;
187 uint8_t slice_vertical_position_extension
;
188 uint8_t priority_breakpoint
;
190 uint8_t quantiser_scale_code
;
192 uint8_t slice_extension_flag
;
194 uint8_t slice_picture_id_enable
;
195 uint8_t slice_picture_id
;
197 uint8_t extra_bit_slice
;
199 size_t extra_information_length
;
200 uint8_t *extra_information
;
201 AVBufferRef
*extra_information_ref
;
202 } MPEG2RawSliceHeader
;
204 typedef struct MPEG2RawSlice
{
205 MPEG2RawSliceHeader header
;
210 AVBufferRef
*data_ref
;
214 typedef struct CodedBitstreamMPEG2Context
{
215 // Elements stored in headers which are required for other decoding.
216 uint16_t horizontal_size
;
217 uint16_t vertical_size
;
219 uint8_t scalable_mode
;
220 uint8_t progressive_sequence
;
221 uint8_t number_of_frame_centre_offsets
;
224 uint8_t *write_buffer
;
225 size_t write_buffer_size
;
226 } CodedBitstreamMPEG2Context
;
229 #endif /* AVCODEC_CBS_MPEG2_H */