1 /*
2     This file is provided under a dual BSD/GPLv2 license.  When using or
3     redistributing this file, you may do so under either license.
4 
5     GPL LICENSE SUMMARY
6 
7     Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
8 
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of version 2 of the GNU General Public License as
11     published by the Free Software Foundation.
12 
13     This program is distributed in the hope that it will be useful, but
14     WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21     The full GNU General Public License is included in this distribution
22     in the file called LICENSE.GPL.
23 
24     Contact Information:
25 
26     BSD LICENSE
27 
28     Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
29     All rights reserved.
30 
31     Redistribution and use in source and binary forms, with or without
32     modification, are permitted provided that the following conditions
33     are met:
34 
35     * Redistributions of source code must retain the above copyright
36     notice, this list of conditions and the following disclaimer.
37     * Redistributions in binary form must reproduce the above copyright
38     notice, this list of conditions and the following disclaimer in
39     the documentation and/or other materials provided with the
40     distribution.
41     * Neither the name of Intel Corporation nor the names of its
42     contributors may be used to endorse or promote products derived
43     from this software without specific prior written permission.
44 
45     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 
57 */
58 #ifndef VIDDEC_FW_FRAME_ATTR_H
59 #define VIDDEC_FW_FRAME_ATTR_H
60 
61 #define VIDDEC_PANSCAN_MAX_OFFSETS 4
62 #define VIDDEC_MAX_CPB_CNT 32
63 
64 /**
65 This enumeration lists all the frame types defined by the MPEG, VC1 and H264 specifications.
66 Frame types applicable to a single codec are specified in the comments.
67 */
68 typedef enum
69 {
70     VIDDEC_FRAME_TYPE_INVALID=0,   /** Unknown type - default value */
71     VIDDEC_FRAME_TYPE_IDR=0x1,       /** IDR frame - h264 only */
72     VIDDEC_FRAME_TYPE_I=0x2,         /** I frame */
73     VIDDEC_FRAME_TYPE_P=0x3,         /** P frame */
74     VIDDEC_FRAME_TYPE_B=0x4,         /** B frame */
75     VIDDEC_FRAME_TYPE_BI=0x5,        /** BI frame - Intracoded B frame - vc1 only */
76     VIDDEC_FRAME_TYPE_SKIP=0x6,      /** Skipped frame - vc1 only */
77     VIDDEC_FRAME_TYPE_D=0x7,         /** D frame - mpeg1 only */
78     VIDDEC_FRAME_TYPE_S=0x8,         /** SVOP frame - mpeg4 only - sprite encoded frame - treat as P */
79     VIDDEC_FRAME_TYPE_MAX,
80 } viddec_frame_type_t;
81 
82 /**
83 This structure contains the content size info extracted from the stream.
84 */
85 typedef struct viddec_rect_size
86 {
87     unsigned int width;
88     unsigned int height;
89 }viddec_rect_size_t;
90 
91 /**
92 This structure contains MPEG2 specific pan scan offsets extracted from the stream.
93 */
94 typedef struct viddec_mpeg2_frame_center_offset
95 {
96     int horz;
97     int vert;
98 }viddec_mpeg2_frame_center_offset_t;
99 
100 /**
101 This structure contains the MPEG2 specific frame attributes.
102 */
103 typedef struct viddec_mpeg2_frame_attributes
104 {
105     /**
106     10 bit unsigned integer corresponding to the display order of each coded picture
107     in the stream (or gop if gop header is present).
108     Refer to "temporal_reference" of the picture header in ITU-T H.262 Specification.
109     */
110     unsigned int temporal_ref;
111 
112     /**
113     Pan/Scan rectangle info
114     Refer to the picture display extension in ITU-T H.262 Specification.
115     */
116     viddec_mpeg2_frame_center_offset_t frame_center_offset[VIDDEC_PANSCAN_MAX_OFFSETS];
117     unsigned int number_of_frame_center_offsets;
118 
119     /**
120     Top-Field first flag
121     Refer to "top_field_first" of the picture coding extension in ITU-T H.262 Specification.
122     */
123     unsigned int top_field_first;
124 
125     /**
126     Progressive frame flag - Indicates if current frame is progressive or not.
127     Refer to "progressive_frame" of the picture coding extension in ITU-T H.262 Specification.
128     */
129     unsigned int progressive_frame;
130 
131     /**
132     Frame/field polarity for each coded picture.
133     Refer to Table 6-14 in ITU-T H.262 Specification.
134     */
135     unsigned int picture_struct;
136 
137     /**
138     Repeat field/frame flag.
139     Refer to "repeat_first_field" of the picture coding extension in ITU-T H.262 Specification.
140     */
141     unsigned int repeat_first_field;
142 
143 }viddec_mpeg2_frame_attributes_t;
144 
145 /**
146 This structure contains MPEG2 specific pan scan offsets extracted from the stream.
147 */
148 typedef struct viddec_vc1_pan_scan_window
149 {
150     unsigned int hoffset;
151     unsigned int voffset;
152     unsigned int width;
153     unsigned int height;
154 }viddec_vc1_pan_scan_window_t;
155 
156 /**
157 This structure contains the VC1 specific frame attributes.
158 */
159 typedef struct viddec_vc1_frame_attributes
160 {
161     /**
162     Temporal Reference of frame/field.
163     Refer to "TFCNTR" in the picture layer of the SMPTE VC1 Specification.
164     */
165     unsigned int tfcntr;
166 
167     /**
168     Frame/field repeat information in the bitstream.
169     Refer to "RPTFRM", "TFF", "BFF" in the picture layer
170     of the SMPTE VC1 Specification.
171     */
172     unsigned int rptfrm;
173     unsigned int tff;
174     unsigned int rff;
175 
176     /**
177     Pan-scan information in the bitstream.
178     Refer to "PANSCAN_FLAG" in the entrypoint layer, "PS_PRESENT", "PS_HOFFSET", "PS_VOFFSET",
179     "PS_WIDTH" and "PS_HEIGHT" in the picture layer of the SMPTE VC1 Specification.
180     */
181     unsigned int panscan_flag;
182     unsigned int ps_present;
183     unsigned int num_of_pan_scan_windows;
184     viddec_vc1_pan_scan_window_t pan_scan_window[VIDDEC_PANSCAN_MAX_OFFSETS];
185 
186 }viddec_vc1_frame_attributes_t;
187 
188 /**
189 This structure contains the H264 specific frame attributes.
190 */
191 typedef struct viddec_h264_frame_attributes
192 {
193 	/**
194 	used_for_reference : 1 means this frame is used as ref frame of others. 0 means no any frame ref to this frame
195 	*/
196 	///// This flag hasn't been enable so far
197 	unsigned int used_for_reference;
198 
199 
200 	/** -
201 	Picture Order Count for the current frame/field.-
202 	This value is computed using information from the bitstream.-
203 	Refer to Section 8.2.1, function 8-1 of the ITU-T H.264 Specification.-
204 	*/
205 	// These fileds will be supported in future
206 	int top_field_poc;
207 	int bottom_field_poc;
208 
209 	/**
210 	Display size, which is cropped from content size.
211 	Currently, the cont_size is cropped, so this paramter is redundant, but in future, cont_size may be changed
212 	*/
213 	viddec_rect_size_t cropped_size;
214 
215 	/**
216 	top_field_first: 0 means bottom_field_POC is smaller than top_field_POC, else 1
217 	*/
218 	unsigned int top_field_first;
219 
220 	/**
221 	field_frame_flag: 0 means all slice of this frame are frame-base encoded, else 1
222 	*/
223 	unsigned int field_pic_flag;
224 
225 }viddec_h264_frame_attributes_t;
226 
227 /**
228 This structure contains the MPEG4 specific frame attributes.
229 */
230 typedef struct viddec_mpeg4_frame_attributes
231 {
232     /**
233     Top-Field first flag
234     Refer to "top_field_first" of the Video Object Plane of the MPEG4 Spec.
235     */
236     unsigned int top_field_first;
237 
238 }viddec_mpeg4_frame_attributes_t;
239 
240 /**
241 This structure groups all the frame attributes that are exported by the firmware.
242 The frame attributes are split into attributes that are common to all codecs and
243 that are specific to codec type.
244 As of this release, it is populated only for mpeg2 only.
245 */
246 typedef struct viddec_frame_attributes
247 {
248     /**
249     Content size specified in the stream.
250     For MPEG2, refer to "horizontal_size_value, vertical_size_value" of the sequence header and
251     "horizontal_size_extension, vertical_size_extension" of the sequence extension in ITU-T H.262 Specification.
252     For H264, refer to "pic_width_in_mbs_minus1" and "pic_height_in_map_units_minus1" of the
253     sequence parameter set in ITU-T H.264 Specification.
254     For VC1, refer to "MAX_CODED_WIDTH" and "MAX_CODED_HEIGHT" in the sequence layer,
255     "CODED_SIZE_FLAG", "CODED_WIDTH" and "CODED_HEIGHT" in the entrypoint layer of the SMPTE VC1 Specification.
256     */
257     viddec_rect_size_t cont_size;
258 
259     /**
260     Type of frame populated in the workload.
261     frame_type contains the frame type for progressive frame and the field type for the top field for interlaced frames.
262     bottom_field_type contains the field type for the bottom field for interlaced frames.
263     For MPEG2, refer to "picture_coding_type" in picture header (Table 6-12) in ITU-T H.262 Specification.
264     For H264, refer to "slice_type" in slice header (Table 7-6) in ITU-T H.264 Specification.
265     For VC1, refer to "PTYPE" and FPTYPE in the picture layer (Tables 33, 34, 35, 105) in SMPTE VC1 Specification.
266     */
267     viddec_frame_type_t frame_type;
268     viddec_frame_type_t bottom_field_type;
269 
270     /** Codec specific attributes */
271     union
272     {
273         viddec_mpeg2_frame_attributes_t  mpeg2;
274         viddec_vc1_frame_attributes_t    vc1;
275         viddec_h264_frame_attributes_t   h264;
276         viddec_mpeg4_frame_attributes_t  mpeg4;
277     };
278 
279 }viddec_frame_attributes_t;
280 
281 #endif /* VIDDEC_FRAME_ATTR_H */
282