• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \file va_enc_mpeg2.h
27  * \brief The MPEG-2 encoding API
28  *
29  * This file contains the \ref api_enc_mpeg2 "MPEG-2 encoding API".
30  */
31 
32 #ifndef _VA_ENC_MPEG2_H_
33 #define _VA_ENC_MPEG2_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <va/va_enc.h>
40 
41 /**
42  * \defgroup api_enc_mpeg2 MPEG-2 encoding API
43  *
44  * @{
45  */
46 
47 #define MPEG2_LAST_PICTURE_EOSTREAM  VA_ENC_LAST_PICTURE_EOSTREAM
48 
49 /**
50  * \brief MPEG-2 Quantization Matrix Buffer
51  *
52  */
53 typedef VAIQMatrixBufferMPEG2 VAQMatrixBufferMPEG2;
54 
55 /**
56  * \brief Packed header types specific to MPEG-2 encoding.
57  *
58  * Types of packed headers generally used for MPEG-2 encoding.
59  */
60 typedef enum {
61     /**
62      * \brief Packed Sequence Parameter Set (SPS).
63      *
64      */
65     VAEncPackedHeaderMPEG2_SPS = VAEncPackedHeaderSequence,
66     /**
67      * \brief Packed Picture Parameter Set (PPS).
68      *
69      */
70     VAEncPackedHeaderMPEG2_PPS = VAEncPackedHeaderPicture,
71     /**
72      * \brief Packed slice header.
73      *
74      */
75     VAEncPackedHeaderMPEG2_Slice = VAEncPackedHeaderSlice,
76 } VAEncPackedHeaderTypeMPEG2;
77 
78 /**
79  * \brief Sequence parameter for MPEG-2 encoding
80  *
81  * This structure holds information for \c sequence_header() and
82  * sequence_extension().
83  *
84  * If packed sequence headers mode is used, i.e. if the encoding
85  * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE
86  * flag, then the driver expects two more buffers to be provided to
87  * the same \c vaRenderPicture() as this buffer:
88  * - a #VAEncPackedHeaderParameterBuffer with type set to
89  *   VAEncPackedHeaderType::VAEncPackedHeaderSequence ;
90  * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
91  *   header data.
92  *
93  */
94 typedef struct _VAEncSequenceParameterBufferMPEG2 {
95     /** \brief Period between I frames. */
96     unsigned int intra_period;
97     /** \brief Period between I/P frames. */
98     unsigned int ip_period;
99     /** \brief Picture width.
100      *
101      * A 14bits unsigned inter, the lower 12bits
102      * is horizontal_size_value, and the upper
103      * 2bits is \c horizontal_size_extension
104      *
105      */
106     unsigned short picture_width;
107     /** \brief Picture height.
108      *
109      * A 14bits unsigned inter, the lower 12bits
110      * is vertical_size_value, and the upper 2bits is
111      * vertical_size_size_extension
112      *
113      */
114     unsigned short picture_height;
115     /**
116      * \brief Initial bitrate set for this sequence in CBR or VBR modes.
117      *
118      * This field represents the initial bitrate value for this
119      * sequence if CBR or VBR mode is used, i.e. if the encoder
120      * pipeline was created with a #VAConfigAttribRateControl
121      * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
122      *
123      * bits_per_second may be derived from bit_rate.
124      *
125      */
126     unsigned int bits_per_second;
127     /**
128      * \brief Frame rate
129      *
130      * Derived from frame_rate_value, frame_rate_extension_n and
131      * frame_rate_extension_d
132      *
133      */
134     float frame_rate;
135     /** \brief Same as the element in sequence_header() */
136     unsigned short aspect_ratio_information;
137     /** \brief Define the size of VBV */
138     unsigned int vbv_buffer_size;
139 
140     union {
141         struct {
142             /** \brief Same as the element in Sequence extension() */
143             unsigned int profile_and_level_indication   : 8;
144             /** \brief Same as the element in Sequence extension() */
145             unsigned int progressive_sequence           : 1;
146             /** \brief Same as the element in Sequence extension() */
147             unsigned int chroma_format                  : 2;
148             /** \brief Same as the element in Sequence extension() */
149             unsigned int low_delay                      : 1;
150             /** \brief Same as the element in Sequence extension() */
151             unsigned int frame_rate_extension_n         : 2;
152             /** \brief Same as the element in Sequence extension() */
153             unsigned int frame_rate_extension_d         : 5;
154         } bits;
155         unsigned int value;
156     } sequence_extension;
157 
158     /** \brief Flag to indicate the following GOP header are being updated */
159     unsigned int new_gop_header;
160 
161     union {
162         struct {
163             /** \brief Time code */
164             unsigned int time_code                      : 25;
165             /** \brief Same as the element in GOP header */
166             unsigned int closed_gop                     : 1;
167             /** \brief SAme as the element in GOP header */
168             unsigned int broken_link                    : 1;
169         } bits;
170         unsigned int value;
171     } gop_header;
172 } VAEncSequenceParameterBufferMPEG2;
173 
174 /**
175  * \brief Picture parameter for MPEG-2 encoding
176  *
177  * This structure holds information for picture_header() and
178  * picture_coding_extension()
179  *
180  * If packed picture headers mode is used, i.e. if the encoding
181  * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
182  * flag, then the driver expects two more buffers to be provided to
183  * the same \c vaRenderPicture() as this buffer:
184  * - a #VAEncPackedHeaderParameterBuffer with type set to
185  *   VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
186  * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
187  *   header data.
188  *
189  */
190 typedef struct _VAEncPictureParameterBufferMPEG2 {
191     /** \brief Forward reference picture */
192     VASurfaceID forward_reference_picture;
193     /** \brief Backward reference picture */
194     VASurfaceID backward_reference_picture;
195     /** \brief Reconstructed(decoded) picture */
196     VASurfaceID reconstructed_picture;
197     /**
198      * \brief Output encoded bitstream.
199      *
200      * \ref coded_buf has type #VAEncCodedBufferType. It should be
201      * large enough to hold the compressed NAL slice and possibly SPS
202      * and PPS NAL units.
203      */
204     VABufferID coded_buf;
205     /**
206      * \brief Flag to indicate the picture is the last one or not.
207      *
208      * This fields holds 0 if the picture to be encoded is not
209      * the last one in the stream. Otherwise, it
210      * is \ref MPEG2_LAST_PICTURE_EOSTREAM.
211      */
212     unsigned char last_picture;
213     /** \brief Picture type */
214     VAEncPictureType picture_type;
215     /** \brief Same as the element in picture_header() */
216     unsigned int temporal_reference;
217     /** \brief Same as the element in picture_header() */
218     unsigned int vbv_delay;
219     /** \brief Same as the element in Picture coding extension */
220     unsigned char f_code[2][2];
221     union {
222         struct {
223             /** \brief Same as the element in Picture coding extension */
224             unsigned int intra_dc_precision             : 2;
225             /** \brief Same as the element in Picture coding extension */
226             unsigned int picture_structure              : 2;
227             /** \brief Same as the element in Picture coding extension */
228             unsigned int top_field_first                : 1;
229             /** \brief Same as the element in Picture coding extension */
230             unsigned int frame_pred_frame_dct           : 1;
231             /** \brief Same as the element in Picture coding extension */
232             unsigned int concealment_motion_vectors     : 1;
233             /** \brief Same as the element in Picture coding extension */
234             unsigned int q_scale_type                   : 1;
235             /** \brief Same as the element in Picture coding extension */
236             unsigned int intra_vlc_format               : 1;
237             /** \brief Same as the element in Picture coding extension */
238             unsigned int alternate_scan                 : 1;
239             /** \brief Same as the element in Picture coding extension */
240             unsigned int repeat_first_field             : 1;
241             /** \brief Same as the element in Picture coding extension */
242             unsigned int progressive_frame              : 1;
243             /** \brief Same as the element in Picture coding extension */
244             unsigned int composite_display_flag         : 1;
245         } bits;
246         unsigned int value;
247     } picture_coding_extension;
248 
249     /* \brief Parameters for composite display
250      *
251      * Valid only when omposite_display_flag is 1
252      */
253     union {
254         struct {
255             /** \brief Same as the element in Picture coding extension */
256             unsigned int v_axis                         : 1;
257             /** \brief Same as the element in Picture coding extension */
258             unsigned int field_sequence                 : 3;
259             /** \brief Same as the element in Picture coding extension */
260             unsigned int sub_carrier                    : 1;
261             /** \brief Same as the element in Picture coding extension */
262             unsigned int burst_amplitude                : 7;
263             /** \brief Same as the element in Picture coding extension */
264             unsigned int sub_carrier_phase              : 8;
265         } bits;
266         unsigned int value;
267     } composite_display;
268 } VAEncPictureParameterBufferMPEG2;
269 
270 /**
271  * \brief Slice parameter for MPEG-2 encoding
272  *
273  */
274 typedef struct _VAEncSliceParameterBufferMPEG2 {
275     /** \brief Starting MB address for this slice. */
276     unsigned int macroblock_address;
277     /** \brief Number of macroblocks in this slice. */
278     unsigned int num_macroblocks;
279     /** \brief Same as the element in slice() */
280     int quantiser_scale_code;
281     /** \brief Flag to indicate intra slice */
282     int is_intra_slice;
283 } VAEncSliceParameterBufferMPEG2;
284 
285 /**@}*/
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* _VA_ENC_MPEG2_H_ */
292