]> git.sesse.net Git - ffmpeg/blob - libavcodec/cbs_mpeg2.h
Merge commit '92f0aceb36c6e4412d4cf346e70dc74b5a4069e9'
[ffmpeg] / libavcodec / cbs_mpeg2.h
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #ifndef AVCODEC_CBS_MPEG2_H
20 #define AVCODEC_CBS_MPEG2_H
21
22 #include <stddef.h>
23 #include <stdint.h>
24
25
26 enum {
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,
36 };
37
38 #define MPEG2_START_IS_SLICE(type) \
39     ((type) >= MPEG2_START_SLICE_MIN && \
40      (type) <= MPEG2_START_SLICE_MAX)
41
42 enum {
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,
54 };
55
56
57 typedef struct MPEG2RawSequenceHeader {
58     uint8_t sequence_header_code;
59
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;
67
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;
73
74 typedef struct MPEG2RawUserData {
75     uint8_t user_data_start_code;
76
77     uint8_t *user_data;
78     size_t user_data_length;
79 } MPEG2RawUserData;
80
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;
89     uint8_t low_delay;
90     uint8_t frame_rate_extension_n;
91     uint8_t frame_rate_extension_d;
92 } MPEG2RawSequenceExtension;
93
94 typedef struct MPEG2RawSequenceDisplayExtension {
95     uint8_t video_format;
96
97     uint8_t colour_description;
98     uint8_t colour_primaries;
99     uint8_t transfer_characteristics;
100     uint8_t matrix_coefficients;
101
102     uint16_t display_horizontal_size;
103     uint16_t display_vertical_size;
104 } MPEG2RawSequenceDisplayExtension;
105
106 typedef struct MPEG2RawGroupOfPicturesHeader {
107     uint8_t group_start_code;
108
109     uint32_t time_code;
110     uint8_t closed_gop;
111     uint8_t broken_link;
112 } MPEG2RawGroupOfPicturesHeader;
113
114 typedef struct MPEG2RawPictureHeader {
115     uint8_t picture_start_code;
116
117     uint16_t temporal_reference;
118     uint8_t picture_coding_type;
119     uint16_t vbv_delay;
120
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;
125
126     uint8_t extra_bit_picture;
127 } MPEG2RawPictureHeader;
128
129 typedef struct MPEG2RawPictureCodingExtension {
130     uint8_t f_code[2][2];
131
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;
143
144     uint8_t composite_display_flag;
145     uint8_t v_axis;
146     uint8_t field_sequence;
147     uint8_t sub_carrier;
148     uint8_t burst_amplitude;
149     uint8_t sub_carrier_phase;
150 } MPEG2RawPictureCodingExtension;
151
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;
162
163 typedef struct MPEG2RawPictureDisplayExtension {
164     uint16_t frame_centre_horizontal_offset[3];
165     uint16_t frame_centre_vertical_offset[3];
166 } MPEG2RawPictureDisplayExtension;
167
168 typedef struct MPEG2RawExtensionData {
169     uint8_t extension_start_code;
170     uint8_t extension_start_code_identifier;
171
172     union {
173         MPEG2RawSequenceExtension sequence;
174         MPEG2RawSequenceDisplayExtension sequence_display;
175         MPEG2RawQuantMatrixExtension quant_matrix;
176         MPEG2RawPictureCodingExtension picture_coding;
177         MPEG2RawPictureDisplayExtension picture_display;
178     } data;
179 } MPEG2RawExtensionData;
180
181 typedef struct MPEG2RawSliceHeader {
182     uint8_t slice_vertical_position;
183
184     uint8_t slice_vertical_position_extension;
185     uint8_t priority_breakpoint;
186
187     uint8_t quantiser_scale_code;
188
189     uint8_t slice_extension_flag;
190     uint8_t intra_slice;
191     uint8_t slice_picture_id_enable;
192     uint8_t slice_picture_id;
193
194     uint8_t extra_bit_slice;
195
196     size_t extra_information_length;
197     uint8_t *extra_information;
198 } MPEG2RawSliceHeader;
199
200 typedef struct MPEG2RawSlice {
201     MPEG2RawSliceHeader header;
202
203     uint8_t *data;
204     size_t   data_size;
205     int      data_bit_start;
206 } MPEG2RawSlice;
207
208
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;
213     uint8_t scalable;
214     uint8_t scalable_mode;
215     uint8_t progressive_sequence;
216     uint8_t number_of_frame_centre_offsets;
217
218     // Write buffer.
219     uint8_t *write_buffer;
220     size_t write_buffer_size;
221 } CodedBitstreamMPEG2Context;
222
223
224 #endif /* AVCODEC_CBS_MPEG2_H */