avcodec/idctdsp: Transmit studio_profile to init instead of using AVCodecContext...
[ffmpeg.git] / 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 #include "libavutil/buffer.h"
26
27
28 enum {
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
44 enum {
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,
56 };
57
58
59 typedef 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
76 typedef struct MPEG2RawUserData {
77     uint8_t user_data_start_code;
78
79     uint8_t *user_data;
80     size_t user_data_length;
81     AVBufferRef *user_data_ref;
82 } MPEG2RawUserData;
83
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;
92     uint8_t low_delay;
93     uint8_t frame_rate_extension_n;
94     uint8_t frame_rate_extension_d;
95 } MPEG2RawSequenceExtension;
96
97 typedef 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
109 typedef 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
117 typedef struct MPEG2RawPictureHeader {
118     uint8_t picture_start_code;
119
120     uint16_t temporal_reference;
121     uint8_t picture_coding_type;
122     uint16_t vbv_delay;
123
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;
128
129     uint8_t extra_bit_picture;
130 } MPEG2RawPictureHeader;
131
132 typedef struct MPEG2RawPictureCodingExtension {
133     uint8_t f_code[2][2];
134
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;
146
147     uint8_t composite_display_flag;
148     uint8_t v_axis;
149     uint8_t field_sequence;
150     uint8_t sub_carrier;
151     uint8_t burst_amplitude;
152     uint8_t sub_carrier_phase;
153 } MPEG2RawPictureCodingExtension;
154
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;
165
166 typedef struct MPEG2RawPictureDisplayExtension {
167     uint16_t frame_centre_horizontal_offset[3];
168     uint16_t frame_centre_vertical_offset[3];
169 } MPEG2RawPictureDisplayExtension;
170
171 typedef struct MPEG2RawExtensionData {
172     uint8_t extension_start_code;
173     uint8_t extension_start_code_identifier;
174
175     union {
176         MPEG2RawSequenceExtension sequence;
177         MPEG2RawSequenceDisplayExtension sequence_display;
178         MPEG2RawQuantMatrixExtension quant_matrix;
179         MPEG2RawPictureCodingExtension picture_coding;
180         MPEG2RawPictureDisplayExtension picture_display;
181     } data;
182 } MPEG2RawExtensionData;
183
184 typedef struct MPEG2RawSliceHeader {
185     uint8_t slice_vertical_position;
186
187     uint8_t slice_vertical_position_extension;
188     uint8_t priority_breakpoint;
189
190     uint8_t quantiser_scale_code;
191
192     uint8_t slice_extension_flag;
193     uint8_t intra_slice;
194     uint8_t slice_picture_id_enable;
195     uint8_t slice_picture_id;
196
197     uint8_t extra_bit_slice;
198
199     size_t extra_information_length;
200     uint8_t *extra_information;
201     AVBufferRef *extra_information_ref;
202 } MPEG2RawSliceHeader;
203
204 typedef struct MPEG2RawSlice {
205     MPEG2RawSliceHeader header;
206
207     uint8_t *data;
208     size_t   data_size;
209     int      data_bit_start;
210     AVBufferRef *data_ref;
211 } MPEG2RawSlice;
212
213
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;
218     uint8_t scalable;
219     uint8_t scalable_mode;
220     uint8_t progressive_sequence;
221     uint8_t number_of_frame_centre_offsets;
222
223     // Write buffer.
224     uint8_t *write_buffer;
225     size_t write_buffer_size;
226 } CodedBitstreamMPEG2Context;
227
228
229 #endif /* AVCODEC_CBS_MPEG2_H */