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 B picture in advanced
10 // profile bitstream.
11 //
12 */
13
14 #include "vc1parse.h"
15 #include "viddec_fw_debug.h" // For DEB
16
17 /*------------------------------------------------------------------------------
18 * Parse picture layer. This function parses progressive B picture for advanced
19 * profile bitstream.
20 * Table 22 of SMPTE 421M after processing up to POSTPROC by
21 * vc1_ParsePictureHeader_Adv() but stopping before processing of macroblock
22 * layer.
23 *------------------------------------------------------------------------------
24 */
25
vc1_ParsePictureHeader_ProgressiveBpicture_Adv(void * ctxt,vc1_Info * pInfo)26 vc1_Status vc1_ParsePictureHeader_ProgressiveBpicture_Adv(void* ctxt, vc1_Info *pInfo)
27 {
28 vc1_Status status = VC1_STATUS_OK;
29 vc1_metadata_t *md = &pInfo->metadata;
30 vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
31
32 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
33 return status;
34
35 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
36 picLayerHeader->MVMODE = (picLayerHeader->MVMODE == 1) ?
37 VC1_MVMODE_1MV : VC1_MVMODE_HPELBI_1MV;
38
39 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
40 md->widthMB, md->heightMB, BPP_DIRECTMB)) != VC1_STATUS_OK)
41 {
42 return status;
43 }
44
45 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
46 md->widthMB, md->heightMB, BPP_SKIPMB)) != VC1_STATUS_OK)
47 {
48 return status;
49 }
50
51 VC1_GET_BITS9(2, picLayerHeader->MVTAB);
52 VC1_GET_BITS9(2, picLayerHeader->CBPTAB);
53
54 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
55 return status;
56
57 if (md->VSTRANSFORM == 1)
58 {
59 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
60 if (picLayerHeader->TTMBF == 1)
61 {
62 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
63 }
64 }
65
66 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
67 if (picLayerHeader->TRANSACFRM == 1)
68 {
69 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
70 picLayerHeader->TRANSACFRM += 2;
71 }
72
73 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
74
75 /* Skip parsing of macroblock layer. */
76
77 return status;
78 }
79
80 /*------------------------------------------------------------------------------
81 * Parse picture layer. This function parses interlace B frame for advanced
82 * profile bitstream.
83 * Table 84 of SMPTE 421M after processing up to POSTPROC by
84 * vc1_ParsePictureHeader_Adv() but stopping before processing of macroblock
85 * layer.
86 *------------------------------------------------------------------------------
87 */
88
vc1_ParsePictureHeader_InterlaceBpicture_Adv(void * ctxt,vc1_Info * pInfo)89 vc1_Status vc1_ParsePictureHeader_InterlaceBpicture_Adv(void* ctxt, vc1_Info *pInfo)
90 {
91 vc1_Status status = VC1_STATUS_OK;
92 vc1_metadata_t *md = &pInfo->metadata;
93 vc1_PictureLayerHeader *picLayerHeader = &pInfo->picLayerHeader;
94
95 if ((status = vc1_DecodeHuffmanPair(ctxt, VC1_BFRACTION_TBL,
96 &picLayerHeader->BFRACTION_NUM, &picLayerHeader->BFRACTION_DEN)) !=
97 VC1_STATUS_OK)
98 {
99 return status;
100 }
101
102 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
103 return status;
104
105 if ((status = vc1_DMVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
106 return status;
107
108 VC1_GET_BITS9(1, picLayerHeader->INTCOMP);
109
110 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
111 md->widthMB, md->heightMB, BPP_DIRECTMB)) != VC1_STATUS_OK)
112 {
113 return status;
114 }
115
116 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
117 md->widthMB, md->heightMB, BPP_SKIPMB)) != VC1_STATUS_OK)
118 {
119 return status;
120 }
121
122 // EPC picLayerHeader->MVMODE = VC1_MVMODE_1MV;
123 VC1_GET_BITS9(2, picLayerHeader->MBMODETAB);
124 VC1_GET_BITS9(2, picLayerHeader->MVTAB); /* IMVTAB. */
125 VC1_GET_BITS9(3, picLayerHeader->CBPTAB); /* ICBPTAB. */
126 VC1_GET_BITS9(2, picLayerHeader->MV2BPTAB); /* 2MVBPTAB. */
127 VC1_GET_BITS9(2, picLayerHeader->MV4BPTAB); /* 4MVBPTAB. */
128
129 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
130 return status;
131
132 if (md->VSTRANSFORM == 1)
133 {
134 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
135 if (picLayerHeader->TTMBF == 1)
136 {
137 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
138 }
139 }
140
141 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
142 if (picLayerHeader->TRANSACFRM == 1)
143 {
144 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
145 picLayerHeader->TRANSACFRM += 2;
146 }
147
148 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
149
150 /* Skip parsing of macroblock layer. */
151
152 return status;
153 }
154
155 /*------------------------------------------------------------------------------
156 * Parse picture layer. This function parses interlace B field for advanced
157 * profile bitstream.
158 * Table 89 of SMPTE 421M after processing up to BFRACTION by
159 * vc1_ParseFieldHeader_Adv() but stopping before processing of macroblock
160 * layer.
161 *------------------------------------------------------------------------------
162 */
163
vc1_ParseFieldHeader_InterlaceBpicture_Adv(void * ctxt,vc1_Info * pInfo)164 vc1_Status vc1_ParseFieldHeader_InterlaceBpicture_Adv(void* ctxt, vc1_Info *pInfo)
165 {
166 uint8_t bit_count;
167 const uint8_t *table;
168 vc1_Status status = VC1_STATUS_OK;
169 vc1_metadata_t *md = &pInfo->metadata;
170 vc1_PictureLayerHeader* picLayerHeader = &pInfo->picLayerHeader;
171
172 VC1_GET_BITS9(5, picLayerHeader->PQINDEX);
173
174 if ((status = vc1_CalculatePQuant(pInfo)) != VC1_STATUS_OK)
175 return status;
176
177 if (picLayerHeader->PQINDEX <= 8)
178 {
179 VC1_GET_BITS9(1, picLayerHeader->HALFQP);
180 }
181 else
182 picLayerHeader->HALFQP = 0;
183
184 if (md->QUANTIZER == 1)
185 {
186 VC1_GET_BITS9(1, picLayerHeader->PQUANTIZER);
187 picLayerHeader->UniformQuant = picLayerHeader->PQUANTIZER;
188 }
189
190 if (md->POSTPROCFLAG == 1)
191 {
192 VC1_GET_BITS9(2, picLayerHeader->POSTPROC);
193 }
194
195 if ((status = vc1_MVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
196 return status;
197
198 if ((status = vc1_DMVRangeDecode(ctxt, pInfo)) != VC1_STATUS_OK)
199 return status;
200
201 if (picLayerHeader->PQUANT > 12)
202 table = VC1_MVMODE_LOW_TBL;
203 else
204 table = VC1_MVMODE_HIGH_TBL;
205
206 bit_count = 0;
207 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
208 while ((picLayerHeader->MVMODE == 0) && (bit_count < 2))
209 {
210 VC1_GET_BITS9(1, picLayerHeader->MVMODE);
211 bit_count++;
212 }
213 if ((bit_count == 2) && (picLayerHeader->MVMODE == 0))
214 bit_count++;
215 picLayerHeader->MVMODE = table[bit_count];
216
217 if ((status = vc1_DecodeBitplane(ctxt, pInfo,
218 md->widthMB, (md->heightMB+1)/2, BPP_FORWARDMB)) !=
219 VC1_STATUS_OK)
220 {
221 return status;
222 }
223
224 VC1_GET_BITS9(3, picLayerHeader->MBMODETAB);
225 VC1_GET_BITS9(3, picLayerHeader->MVTAB); /* IMVTAB. */
226 VC1_GET_BITS9(3, picLayerHeader->CBPTAB); /* ICBPTAB. */
227
228 if (picLayerHeader->MVMODE == VC1_MVMODE_MIXED_MV)
229 {
230 VC1_GET_BITS9(2, picLayerHeader->MV4BPTAB); /* 4MVBPTAB. */
231 }
232
233 if ((status = vc1_VOPDQuant(ctxt, pInfo)) != VC1_STATUS_OK)
234 return status;
235
236 if (md->VSTRANSFORM == 1)
237 {
238 VC1_GET_BITS9(1, picLayerHeader->TTMBF);
239 if (picLayerHeader->TTMBF == 1)
240 {
241 VC1_GET_BITS9(2, picLayerHeader->TTFRM);
242 }
243 }
244
245 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
246 if (picLayerHeader->TRANSACFRM == 1)
247 {
248 VC1_GET_BITS9(1, picLayerHeader->TRANSACFRM);
249 picLayerHeader->TRANSACFRM += 2;
250 }
251
252 VC1_GET_BITS9(1, picLayerHeader->TRANSDCTAB);
253
254 /* Skip parsing of macroblock layer. */
255
256 return status;
257 }
258