1 /* ///////////////////////////////////////////////////////////////////////
2 //
3 // INTEL CORPORATION PROPRIETARY INFORMATION
4 // This software is supplied under the terms of a license agreement or
5 // nondisclosure agreement with Intel Corporation and may not be copied
6 // or disclosed except in accordance with the terms of that agreement.
7 // Copyright (c) 2008 Intel Corporation. All Rights Reserved.
8 //
9 // Description: Parses VC-1 picture layer for progressive P picture in advanced
10 // profile bitstream.
11 //
12 */
13
14 #include "vc1parse.h"
15 #include "viddec_fw_debug.h"
16 /*------------------------------------------------------------------------------
17 * Parse picture layer. This function parses progressive P picture for advanced
18 * profile bitstream.
19 * Table 20 of SMPTE 421M after processing up to POSTPROC by
20 * vc1_ParsePictureHeader_Adv() but stopping before processing of macroblock
21 * layer.
22 *------------------------------------------------------------------------------
23 */
24
vc1_ParsePictureHeader_ProgressivePpicture_Adv(void * ctxt,vc1_Info * pInfo)25 vc1_Status vc1_ParsePictureHeader_ProgressivePpicture_Adv(void* ctxt, vc1_Info *pInfo)
26 {
27 uint8_t bit_count;
28 const uint8_t *table;
29 vc1_Status status = VC1_STATUS_OK;
30 vc1_metadata_t *md = &pInfo->metadata;
31 vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
32
33 /* MVRANGE. */
34 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
35 return status;
36
37 if (picLayerHeader->PQUANT > 12)
38 table = VC1_MVMODE_LOW_TBL;
39 else
40 table = VC1_MVMODE_HIGH_TBL;
41
42 bit_count = 0;
43 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
44 while ((picLayerHeader->MVMODE == 0) && (bit_count < 3))
45 {
46 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
47 bit_count++;
48 }
49 if (bit_count == 3)
50 bit_count += picLayerHeader->MVMODE;
51 picLayerHeader->MVMODE = table[bit_count];
52
53 if (picLayerHeader->MVMODE == VC1_MVMODE_INTENSCOMP)
54 {
55 bit_count = 0;
56 VC1_GET_BITS9(1, picLayerHeader->MVMODE2);
57 while ((picLayerHeader->MVMODE2 == 0) && (bit_count < 2))
58 {
59 VC1_GET_BITS9(1, picLayerHeader->MVMODE2);
60 bit_count++;
61 }
62 if (bit_count == 2 && picLayerHeader->MVMODE2 == 0)
63 bit_count++;
64 picLayerHeader->MVMODE2 = table[bit_count];
65 VC1_GET_BITS9(6, picLayerHeader->LUMSCALE);
66 VC1_GET_BITS9(6, picLayerHeader->LUMSHIFT);
67 md->LUMSCALE2 = picLayerHeader->LUMSCALE;
68 md->LUMSHIFT2 = picLayerHeader->LUMSHIFT;
69 }
70 else
71 #ifdef VBP
72 picLayerHeader->MVMODE2 = 0;
73 #else
74 picLayerHeader->MVMODE2 = picLayerHeader->MVMODE;
75 #endif
76
77 if ((picLayerHeader->MVMODE == VC1_MVMODE_MIXED_MV) ||
78 ((picLayerHeader->MVMODE == VC1_MVMODE_INTENSCOMP) &&
79 (picLayerHeader->MVMODE2 == VC1_MVMODE_MIXED_MV)))
80 {
81 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
82 md->widthMB, md->heightMB, BPP_MVTYPEMB)) !=
83 VC1_STATUS_OK)
84 {
85 return status;
86 }
87 }
88
89 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
90 md->widthMB, md->heightMB, BPP_SKIPMB)) != VC1_STATUS_OK)
91 {
92 return status;
93 }
94
95 VC1_GET_BITS9(2, picLayerHeader->MVTAB);
96 VC1_GET_BITS9(2, picLayerHeader->CBPTAB);
97
98 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
99 return status;
100
101 if (md->VSTRANSFORM == 1)
102 {
103 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
104 if (picLayerHeader->TTMBF == 1)
105 {
106 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
107 }
108 }
109
110 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
111 if (picLayerHeader->TRANSACFRM == 1)
112 {
113 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
114 picLayerHeader->TRANSACFRM += 2;
115 }
116
117 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
118
119 /* Skip parsing of macroblock layer. */
120
121 return status;
122 }
123
124 /*------------------------------------------------------------------------------
125 * Parse picture layer. This function parses interlace P frame for advanced
126 * profile bitstream.
127 * Table 83 of SMPTE 421M after processing up to POSTPROC by
128 * vc1_ParsePictureHeader_Adv() but stopping before processing of macroblock
129 * layer.
130 *------------------------------------------------------------------------------
131 */
132
vc1_ParsePictureHeader_InterlacePpicture_Adv(void * ctxt,vc1_Info * pInfo)133 vc1_Status vc1_ParsePictureHeader_InterlacePpicture_Adv(void* ctxt, vc1_Info *pInfo)
134 {
135 vc1_Status status = VC1_STATUS_OK;
136 vc1_metadata_t *md = &pInfo->metadata;
137 vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
138
139 /* MVRANGE. */
140 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
141 return status;
142
143 /* DMVRANGE. */
144 if ((status = vc1_DMVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
145 return status;
146
147 VC1_GET_BITS9(1, picLayerHeader->MV4SWITCH);
148
149 VC1_GET_BITS9(1, picLayerHeader->INTCOMP);
150 if (picLayerHeader->INTCOMP)
151 {
152 VC1_GET_BITS9(6, picLayerHeader->LUMSCALE);
153 VC1_GET_BITS9(6, picLayerHeader->LUMSHIFT);
154 md->LUMSCALE2 = picLayerHeader->LUMSCALE;
155 md->LUMSHIFT2 = picLayerHeader->LUMSHIFT;
156 }
157
158 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
159 md->widthMB, md->heightMB, BPP_SKIPMB)) != VC1_STATUS_OK)
160 {
161 return status;
162 }
163
164 VC1_GET_BITS9(2, picLayerHeader->MBMODETAB);
165 VC1_GET_BITS9(2, picLayerHeader->MVTAB); /* IMVTAB. */
166 VC1_GET_BITS9(3, picLayerHeader->CBPTAB); /* ICBPTAB. */
167 VC1_GET_BITS9(2, picLayerHeader->MV2BPTAB); /* 2MVBPTAB. */
168
169 if (picLayerHeader->MV4SWITCH == 1)
170 {
171 VC1_GET_BITS9(2, picLayerHeader->MV4BPTAB); /* 4MVBPTAB. */
172 }
173
174 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
175 return status;
176
177 if (md->VSTRANSFORM == 1)
178 {
179 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
180 if (picLayerHeader->TTMBF == 1)
181 {
182 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
183 }
184 }
185
186 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
187 if (picLayerHeader->TRANSACFRM == 1)
188 {
189 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
190 picLayerHeader->TRANSACFRM += 2;
191 }
192
193 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
194
195 /* Skip parsing of macroblock layer. */
196
197 return status;
198 }
199
200 /*------------------------------------------------------------------------------
201 * Parse picture layer. This function parses interlace P field for advanced
202 * profile bitstream.
203 * Table 88 of SMPTE 421M after processing up to BFRACTION by
204 * vc1_ParseFieldHeader_Adv() but stopping before processing of macroblock
205 * layer.
206 *------------------------------------------------------------------------------
207 */
208
vc1_ParseFieldHeader_InterlacePpicture_Adv(void * ctxt,vc1_Info * pInfo)209 vc1_Status vc1_ParseFieldHeader_InterlacePpicture_Adv(void* ctxt, vc1_Info *pInfo)
210 {
211 uint8_t bit_count;
212 const uint8_t *table;
213 vc1_Status status = VC1_STATUS_OK;
214 vc1_metadata_t *md = &pInfo->metadata;
215 vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
216
217
218 VC1_GET_BITS9(5, picLayerHeader->PQINDEX);
219 if ((status = vc1_CalculatePQuant(pInfo)) != VC1_STATUS_OK)
220 return status;
221
222 if (picLayerHeader->PQINDEX <= 8)
223 {
224 VC1_GET_BITS9(1, picLayerHeader->HALFQP);
225 }
226 else
227 picLayerHeader->HALFQP = 0;
228
229
230 if (md->QUANTIZER == 1)
231 {
232 VC1_GET_BITS9(1, picLayerHeader->PQUANTIZER);
233 picLayerHeader->UniformQuant = picLayerHeader->PQUANTIZER;
234 }
235
236 if (md->POSTPROCFLAG == 1)
237 {
238 VC1_GET_BITS9(2, picLayerHeader->POSTPROC);
239 }
240
241 VC1_GET_BITS9(1, picLayerHeader->NUMREF);
242
243 if (picLayerHeader->NUMREF == 0)
244 {
245 VC1_GET_BITS9(1, picLayerHeader->REFFIELD);
246 }
247
248 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK) {
249 DEB("Error in vc1_MVRangeDecode \n");
250 return status;
251 }
252
253 if ((status = vc1_DMVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
254 return status;
255
256 if (picLayerHeader->PQUANT > 12)
257 table = VC1_MVMODE_LOW_TBL;
258 else
259 table = VC1_MVMODE_HIGH_TBL;
260
261 bit_count = 0;
262 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
263 while ((picLayerHeader->MVMODE == 0) && (bit_count < 2))
264 {
265 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
266 bit_count++;
267 }
268 if (bit_count == 2 && picLayerHeader->MVMODE == 0) {
269 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
270
271 if ( picLayerHeader->MVMODE == 1)
272 bit_count ++;
273
274 bit_count++;
275 }
276 picLayerHeader->MVMODE = table[bit_count];
277
278 if (picLayerHeader->MVMODE == VC1_MVMODE_INTENSCOMP)
279 {
280 bit_count = 0;
281 VC1_GET_BITS9(1, picLayerHeader->MVMODE2);
282 while ((picLayerHeader->MVMODE2 == 0) && (bit_count < 2))
283 {
284 VC1_GET_BITS9(1, picLayerHeader->MVMODE2);
285 bit_count++;
286 }
287 if (bit_count == 2 && picLayerHeader->MVMODE2 == 0)
288 bit_count++;
289 picLayerHeader->MVMODE2 = table[bit_count];
290
291 VC1_GET_BITS9(1, md->INTCOMPFIELD);
292 if (md->INTCOMPFIELD == 1)
293 md->INTCOMPFIELD = VC1_INTCOMP_BOTH_FIELD;
294 else
295 {
296 VC1_GET_BITS9(1, md->INTCOMPFIELD);
297 if(md->INTCOMPFIELD == 1)
298 md->INTCOMPFIELD = VC1_INTCOMP_BOTTOM_FIELD;
299 else
300 md->INTCOMPFIELD = VC1_INTCOMP_TOP_FIELD;
301 }
302 VC1_GET_BITS9(6, picLayerHeader->LUMSCALE); /* LUMSCALE1. */
303 VC1_GET_BITS9(6, picLayerHeader->LUMSHIFT); /* LUMSHIFT1. */
304 if ( md->INTCOMPFIELD == VC1_INTCOMP_BOTTOM_FIELD ) {
305 md->LUMSCALE2 = picLayerHeader->LUMSCALE;
306 md->LUMSHIFT2 = picLayerHeader->LUMSHIFT;
307 }
308 if (md->INTCOMPFIELD == VC1_INTCOMP_BOTH_FIELD)
309 {
310 VC1_GET_BITS9(6, md->LUMSCALE2);
311 VC1_GET_BITS9(6, md->LUMSHIFT2);
312 }
313 }
314 else
315 #ifdef VBP
316 picLayerHeader->MVMODE2 = 0;
317 #else
318 picLayerHeader->MVMODE2 = picLayerHeader->MVMODE;
319 #endif
320
321 VC1_GET_BITS9(3, picLayerHeader->MBMODETAB);
322
323 if (picLayerHeader->NUMREF)
324 {
325 VC1_GET_BITS9(3, picLayerHeader->MVTAB); /* IMVTAB. */
326 }
327 else
328 {
329 VC1_GET_BITS9(2, picLayerHeader->MVTAB); /* IMVTAB. */
330 }
331
332 VC1_GET_BITS9(3, picLayerHeader->CBPTAB); /* ICBPTAB. */
333
334 #ifdef VBP
335 if (picLayerHeader->MVMODE == VC1_MVMODE_MIXED_MV)
336 #else
337 if (picLayerHeader->MVMODE2 == VC1_MVMODE_MIXED_MV)
338 #endif
339 {
340 VC1_GET_BITS9(2, picLayerHeader->MV4BPTAB); /* 4MVBPTAB. */
341 }
342
343 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
344 return status;
345
346 if (md->VSTRANSFORM == 1)
347 {
348 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
349 if (picLayerHeader->TTMBF == 1)
350 {
351 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
352 }
353 }
354
355 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
356 if (picLayerHeader->TRANSACFRM == 1)
357 {
358 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
359 picLayerHeader->TRANSACFRM += 2;
360 }
361 picLayerHeader->TRANSACFRM2 = 0;
362
363 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
364
365 /* Skip parsing of macroblock layer. */
366
367 return status;
368 }
369