xref: /third_party/ffmpeg/libavcodec/cbs_mpeg2.h (revision cabdff1a)
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#include "libavutil/buffer.h"
26
27
28enum {
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,
38};
39
40#define MPEG2_START_IS_SLICE(type) \
41    ((type) >= MPEG2_START_SLICE_MIN && \
42     (type) <= MPEG2_START_SLICE_MAX)
43
44enum {
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_CAMERA_PARAMETERS         = 0xb,
55    MPEG2_EXTENSION_ITU_T                     = 0xc,
56};
57
58
59typedef struct MPEG2RawSequenceHeader {
60    uint8_t sequence_header_code;
61
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;
69
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;
75
76typedef struct MPEG2RawUserData {
77    uint8_t user_data_start_code;
78
79    uint8_t     *user_data;
80    AVBufferRef *user_data_ref;
81    size_t       user_data_length;
82} MPEG2RawUserData;
83
84typedef 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;
92    uint8_t low_delay;
93    uint8_t frame_rate_extension_n;
94    uint8_t frame_rate_extension_d;
95} MPEG2RawSequenceExtension;
96
97typedef struct MPEG2RawSequenceDisplayExtension {
98    uint8_t video_format;
99
100    uint8_t colour_description;
101    uint8_t colour_primaries;
102    uint8_t transfer_characteristics;
103    uint8_t matrix_coefficients;
104
105    uint16_t display_horizontal_size;
106    uint16_t display_vertical_size;
107} MPEG2RawSequenceDisplayExtension;
108
109typedef struct MPEG2RawGroupOfPicturesHeader {
110    uint8_t group_start_code;
111
112    uint32_t time_code;
113    uint8_t closed_gop;
114    uint8_t broken_link;
115} MPEG2RawGroupOfPicturesHeader;
116
117typedef struct MPEG2RawExtraInformation {
118    uint8_t     *extra_information;
119    AVBufferRef *extra_information_ref;
120    size_t       extra_information_length;
121} MPEG2RawExtraInformation;
122
123typedef struct MPEG2RawPictureHeader {
124    uint8_t picture_start_code;
125
126    uint16_t temporal_reference;
127    uint8_t picture_coding_type;
128    uint16_t vbv_delay;
129
130    uint8_t full_pel_forward_vector;
131    uint8_t forward_f_code;
132    uint8_t full_pel_backward_vector;
133    uint8_t backward_f_code;
134
135    MPEG2RawExtraInformation extra_information_picture;
136} MPEG2RawPictureHeader;
137
138typedef struct MPEG2RawPictureCodingExtension {
139    uint8_t f_code[2][2];
140
141    uint8_t intra_dc_precision;
142    uint8_t picture_structure;
143    uint8_t top_field_first;
144    uint8_t frame_pred_frame_dct;
145    uint8_t concealment_motion_vectors;
146    uint8_t q_scale_type;
147    uint8_t intra_vlc_format;
148    uint8_t alternate_scan;
149    uint8_t repeat_first_field;
150    uint8_t chroma_420_type;
151    uint8_t progressive_frame;
152
153    uint8_t composite_display_flag;
154    uint8_t v_axis;
155    uint8_t field_sequence;
156    uint8_t sub_carrier;
157    uint8_t burst_amplitude;
158    uint8_t sub_carrier_phase;
159} MPEG2RawPictureCodingExtension;
160
161typedef struct MPEG2RawQuantMatrixExtension {
162    uint8_t load_intra_quantiser_matrix;
163    uint8_t intra_quantiser_matrix[64];
164    uint8_t load_non_intra_quantiser_matrix;
165    uint8_t non_intra_quantiser_matrix[64];
166    uint8_t load_chroma_intra_quantiser_matrix;
167    uint8_t chroma_intra_quantiser_matrix[64];
168    uint8_t load_chroma_non_intra_quantiser_matrix;
169    uint8_t chroma_non_intra_quantiser_matrix[64];
170} MPEG2RawQuantMatrixExtension;
171
172typedef struct MPEG2RawPictureDisplayExtension {
173    int16_t frame_centre_horizontal_offset[3];
174    int16_t frame_centre_vertical_offset[3];
175} MPEG2RawPictureDisplayExtension;
176
177typedef struct MPEG2RawExtensionData {
178    uint8_t extension_start_code;
179    uint8_t extension_start_code_identifier;
180
181    union {
182        MPEG2RawSequenceExtension sequence;
183        MPEG2RawSequenceDisplayExtension sequence_display;
184        MPEG2RawQuantMatrixExtension quant_matrix;
185        MPEG2RawPictureCodingExtension picture_coding;
186        MPEG2RawPictureDisplayExtension picture_display;
187    } data;
188} MPEG2RawExtensionData;
189
190typedef struct MPEG2RawSliceHeader {
191    uint8_t slice_vertical_position;
192
193    uint8_t slice_vertical_position_extension;
194    uint8_t priority_breakpoint;
195
196    uint8_t quantiser_scale_code;
197
198    uint8_t slice_extension_flag;
199    uint8_t intra_slice;
200    uint8_t slice_picture_id_enable;
201    uint8_t slice_picture_id;
202
203    MPEG2RawExtraInformation extra_information_slice;
204} MPEG2RawSliceHeader;
205
206typedef struct MPEG2RawSlice {
207    MPEG2RawSliceHeader header;
208
209    uint8_t     *data;
210    AVBufferRef *data_ref;
211    size_t       data_size;
212    int          data_bit_start;
213} MPEG2RawSlice;
214
215typedef struct MPEG2RawSequenceEnd {
216    uint8_t sequence_end_code;
217} MPEG2RawSequenceEnd;
218
219
220typedef struct CodedBitstreamMPEG2Context {
221    // Elements stored in headers which are required for other decoding.
222    uint16_t horizontal_size;
223    uint16_t vertical_size;
224    uint8_t scalable;
225    uint8_t scalable_mode;
226    uint8_t progressive_sequence;
227    uint8_t number_of_frame_centre_offsets;
228} CodedBitstreamMPEG2Context;
229
230
231#endif /* AVCODEC_CBS_MPEG2_H */
232