1
|
1 /*
|
|
2 * slice.c
|
36
|
3 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
1
|
4 *
|
|
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
6 *
|
|
7 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * mpeg2dec is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include "config.h"
|
|
23
|
|
24 #include <string.h>
|
|
25 #include <inttypes.h>
|
|
26
|
36
|
27 #include "video_out.h"
|
1
|
28 #include "mpeg2_internal.h"
|
|
29 #include "attributes.h"
|
|
30
|
|
31 extern mc_functions_t mc_functions;
|
|
32 extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
|
|
33 extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride);
|
|
34
|
|
35 #include "vlc.h"
|
|
36
|
|
37 static int non_linear_quantizer_scale [] = {
|
|
38 0, 1, 2, 3, 4, 5, 6, 7,
|
|
39 8, 10, 12, 14, 16, 18, 20, 22,
|
|
40 24, 28, 32, 36, 40, 44, 48, 52,
|
|
41 56, 64, 72, 80, 88, 96, 104, 112
|
|
42 };
|
|
43
|
36
|
44 static inline int get_macroblock_modes (picture_t * picture)
|
1
|
45 {
|
36
|
46 #define bit_buf (picture->bitstream_buf)
|
|
47 #define bits (picture->bitstream_bits)
|
|
48 #define bit_ptr (picture->bitstream_ptr)
|
1
|
49 int macroblock_modes;
|
|
50 MBtab * tab;
|
|
51
|
36
|
52 switch (picture->picture_coding_type) {
|
1
|
53 case I_TYPE:
|
|
54
|
|
55 tab = MB_I + UBITS (bit_buf, 1);
|
|
56 DUMPBITS (bit_buf, bits, tab->len);
|
|
57 macroblock_modes = tab->modes;
|
|
58
|
36
|
59 if ((! (picture->frame_pred_frame_dct)) &&
|
|
60 (picture->picture_structure == FRAME_PICTURE)) {
|
1
|
61 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
|
|
62 DUMPBITS (bit_buf, bits, 1);
|
|
63 }
|
|
64
|
|
65 return macroblock_modes;
|
|
66
|
|
67 case P_TYPE:
|
|
68
|
|
69 tab = MB_P + UBITS (bit_buf, 5);
|
|
70 DUMPBITS (bit_buf, bits, tab->len);
|
|
71 macroblock_modes = tab->modes;
|
|
72
|
36
|
73 if (picture->picture_structure != FRAME_PICTURE) {
|
1
|
74 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
|
|
75 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
|
|
76 DUMPBITS (bit_buf, bits, 2);
|
|
77 }
|
|
78 return macroblock_modes;
|
36
|
79 } else if (picture->frame_pred_frame_dct) {
|
1
|
80 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
|
|
81 macroblock_modes |= MC_FRAME;
|
|
82 return macroblock_modes;
|
|
83 } else {
|
|
84 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
|
|
85 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
|
|
86 DUMPBITS (bit_buf, bits, 2);
|
|
87 }
|
|
88 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
|
|
89 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
|
|
90 DUMPBITS (bit_buf, bits, 1);
|
|
91 }
|
|
92 return macroblock_modes;
|
|
93 }
|
|
94
|
|
95 case B_TYPE:
|
|
96
|
|
97 tab = MB_B + UBITS (bit_buf, 6);
|
|
98 DUMPBITS (bit_buf, bits, tab->len);
|
|
99 macroblock_modes = tab->modes;
|
|
100
|
36
|
101 if (picture->picture_structure != FRAME_PICTURE) {
|
1
|
102 if (! (macroblock_modes & MACROBLOCK_INTRA)) {
|
|
103 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
|
|
104 DUMPBITS (bit_buf, bits, 2);
|
|
105 }
|
|
106 return macroblock_modes;
|
36
|
107 } else if (picture->frame_pred_frame_dct) {
|
|
108 /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */
|
1
|
109 macroblock_modes |= MC_FRAME;
|
|
110 return macroblock_modes;
|
|
111 } else {
|
|
112 if (macroblock_modes & MACROBLOCK_INTRA)
|
|
113 goto intra;
|
|
114 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
|
|
115 DUMPBITS (bit_buf, bits, 2);
|
|
116 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
|
|
117 intra:
|
|
118 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
|
|
119 DUMPBITS (bit_buf, bits, 1);
|
|
120 }
|
|
121 return macroblock_modes;
|
|
122 }
|
|
123
|
|
124 case D_TYPE:
|
|
125
|
|
126 DUMPBITS (bit_buf, bits, 1);
|
|
127 return MACROBLOCK_INTRA;
|
|
128
|
|
129 default:
|
|
130 return 0;
|
|
131 }
|
|
132 #undef bit_buf
|
|
133 #undef bits
|
|
134 #undef bit_ptr
|
|
135 }
|
|
136
|
36
|
137 static inline int get_quantizer_scale (picture_t * picture)
|
1
|
138 {
|
36
|
139 #define bit_buf (picture->bitstream_buf)
|
|
140 #define bits (picture->bitstream_bits)
|
|
141 #define bit_ptr (picture->bitstream_ptr)
|
1
|
142
|
|
143 int quantizer_scale_code;
|
|
144
|
|
145 quantizer_scale_code = UBITS (bit_buf, 5);
|
|
146 DUMPBITS (bit_buf, bits, 5);
|
|
147
|
36
|
148 if (picture->q_scale_type)
|
1
|
149 return non_linear_quantizer_scale [quantizer_scale_code];
|
|
150 else
|
|
151 return quantizer_scale_code << 1;
|
|
152 #undef bit_buf
|
|
153 #undef bits
|
|
154 #undef bit_ptr
|
|
155 }
|
|
156
|
36
|
157 static inline int get_motion_delta (picture_t * picture, int f_code)
|
1
|
158 {
|
36
|
159 #define bit_buf (picture->bitstream_buf)
|
|
160 #define bits (picture->bitstream_bits)
|
|
161 #define bit_ptr (picture->bitstream_ptr)
|
1
|
162
|
|
163 int delta;
|
|
164 int sign;
|
|
165 MVtab * tab;
|
|
166
|
|
167 if (bit_buf & 0x80000000) {
|
|
168 DUMPBITS (bit_buf, bits, 1);
|
|
169 return 0;
|
|
170 } else if (bit_buf >= 0x0c000000) {
|
|
171
|
|
172 tab = MV_4 + UBITS (bit_buf, 4);
|
|
173 delta = (tab->delta << f_code) + 1;
|
|
174 bits += tab->len + f_code + 1;
|
|
175 bit_buf <<= tab->len;
|
|
176
|
|
177 sign = SBITS (bit_buf, 1);
|
|
178 bit_buf <<= 1;
|
|
179
|
|
180 if (f_code)
|
|
181 delta += UBITS (bit_buf, f_code);
|
|
182 bit_buf <<= f_code;
|
|
183
|
|
184 return (delta ^ sign) - sign;
|
|
185
|
|
186 } else {
|
|
187
|
|
188 tab = MV_10 + UBITS (bit_buf, 10);
|
|
189 delta = (tab->delta << f_code) + 1;
|
|
190 bits += tab->len + 1;
|
|
191 bit_buf <<= tab->len;
|
|
192
|
|
193 sign = SBITS (bit_buf, 1);
|
|
194 bit_buf <<= 1;
|
|
195
|
|
196 if (f_code) {
|
|
197 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
198 delta += UBITS (bit_buf, f_code);
|
|
199 DUMPBITS (bit_buf, bits, f_code);
|
|
200 }
|
|
201
|
|
202 return (delta ^ sign) - sign;
|
|
203
|
|
204 }
|
|
205 #undef bit_buf
|
|
206 #undef bits
|
|
207 #undef bit_ptr
|
|
208 }
|
|
209
|
|
210 static inline int bound_motion_vector (int vector, int f_code)
|
|
211 {
|
|
212 #if 1
|
|
213 int limit;
|
|
214
|
|
215 limit = 16 << f_code;
|
|
216
|
|
217 if (vector >= limit)
|
|
218 return vector - 2*limit;
|
|
219 else if (vector < -limit)
|
|
220 return vector + 2*limit;
|
|
221 else return vector;
|
|
222 #else
|
|
223 return (vector << (27 - f_code)) >> (27 - f_code);
|
|
224 #endif
|
|
225 }
|
|
226
|
36
|
227 static inline int get_dmv (picture_t * picture)
|
1
|
228 {
|
36
|
229 #define bit_buf (picture->bitstream_buf)
|
|
230 #define bits (picture->bitstream_bits)
|
|
231 #define bit_ptr (picture->bitstream_ptr)
|
1
|
232
|
|
233 DMVtab * tab;
|
|
234
|
|
235 tab = DMV_2 + UBITS (bit_buf, 2);
|
|
236 DUMPBITS (bit_buf, bits, tab->len);
|
|
237 return tab->dmv;
|
|
238 #undef bit_buf
|
|
239 #undef bits
|
|
240 #undef bit_ptr
|
|
241 }
|
|
242
|
36
|
243 static inline int get_coded_block_pattern (picture_t * picture)
|
1
|
244 {
|
36
|
245 #define bit_buf (picture->bitstream_buf)
|
|
246 #define bits (picture->bitstream_bits)
|
|
247 #define bit_ptr (picture->bitstream_ptr)
|
1
|
248
|
|
249 CBPtab * tab;
|
|
250
|
|
251 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
252
|
|
253 if (bit_buf >= 0x20000000) {
|
|
254
|
|
255 tab = CBP_7 - 16 + UBITS (bit_buf, 7);
|
|
256 DUMPBITS (bit_buf, bits, tab->len);
|
|
257 return tab->cbp;
|
|
258
|
|
259 } else {
|
|
260
|
|
261 tab = CBP_9 + UBITS (bit_buf, 9);
|
|
262 DUMPBITS (bit_buf, bits, tab->len);
|
|
263 return tab->cbp;
|
|
264 }
|
|
265
|
|
266 #undef bit_buf
|
|
267 #undef bits
|
|
268 #undef bit_ptr
|
|
269 }
|
|
270
|
36
|
271 static inline int get_luma_dc_dct_diff (picture_t * picture)
|
1
|
272 {
|
36
|
273 #define bit_buf (picture->bitstream_buf)
|
|
274 #define bits (picture->bitstream_bits)
|
|
275 #define bit_ptr (picture->bitstream_ptr)
|
1
|
276 DCtab * tab;
|
|
277 int size;
|
|
278 int dc_diff;
|
|
279
|
|
280 if (bit_buf < 0xf8000000) {
|
|
281 tab = DC_lum_5 + UBITS (bit_buf, 5);
|
|
282 size = tab->size;
|
|
283 if (size) {
|
|
284 bits += tab->len + size;
|
|
285 bit_buf <<= tab->len;
|
|
286 dc_diff =
|
|
287 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
|
|
288 bit_buf <<= size;
|
|
289 return dc_diff;
|
|
290 } else {
|
|
291 DUMPBITS (bit_buf, bits, 3);
|
|
292 return 0;
|
|
293 }
|
|
294 } else {
|
|
295 tab = DC_long - 0x1e0 + UBITS (bit_buf, 9);
|
|
296 size = tab->size;
|
|
297 DUMPBITS (bit_buf, bits, tab->len);
|
|
298 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
299 dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
|
|
300 DUMPBITS (bit_buf, bits, size);
|
|
301 return dc_diff;
|
|
302 }
|
|
303 #undef bit_buf
|
|
304 #undef bits
|
|
305 #undef bit_ptr
|
|
306 }
|
|
307
|
36
|
308 static inline int get_chroma_dc_dct_diff (picture_t * picture)
|
1
|
309 {
|
36
|
310 #define bit_buf (picture->bitstream_buf)
|
|
311 #define bits (picture->bitstream_bits)
|
|
312 #define bit_ptr (picture->bitstream_ptr)
|
1
|
313 DCtab * tab;
|
|
314 int size;
|
|
315 int dc_diff;
|
|
316
|
|
317 if (bit_buf < 0xf8000000) {
|
|
318 tab = DC_chrom_5 + UBITS (bit_buf, 5);
|
|
319 size = tab->size;
|
|
320 if (size) {
|
|
321 bits += tab->len + size;
|
|
322 bit_buf <<= tab->len;
|
|
323 dc_diff =
|
|
324 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
|
|
325 bit_buf <<= size;
|
|
326 return dc_diff;
|
|
327 } else {
|
|
328 DUMPBITS (bit_buf, bits, 2);
|
|
329 return 0;
|
|
330 }
|
|
331 } else {
|
|
332 tab = DC_long - 0x3e0 + UBITS (bit_buf, 10);
|
|
333 size = tab->size;
|
|
334 DUMPBITS (bit_buf, bits, tab->len + 1);
|
|
335 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
336 dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
|
|
337 DUMPBITS (bit_buf, bits, size);
|
|
338 return dc_diff;
|
|
339 }
|
|
340 #undef bit_buf
|
|
341 #undef bits
|
|
342 #undef bit_ptr
|
|
343 }
|
|
344
|
36
|
345 #define SATURATE(val) \
|
|
346 do { \
|
|
347 if ((uint32_t)(val + 2048) > 4095) \
|
|
348 val = (val > 0) ? 2047 : -2048; \
|
1
|
349 } while (0)
|
|
350
|
36
|
351 static void get_intra_block_B14 (picture_t * picture)
|
1
|
352 {
|
|
353 int i;
|
|
354 int j;
|
|
355 int val;
|
|
356 uint8_t * scan = picture->scan;
|
|
357 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
|
36
|
358 int quantizer_scale = picture->quantizer_scale;
|
1
|
359 int mismatch;
|
|
360 DCTtab * tab;
|
|
361 uint32_t bit_buf;
|
|
362 int bits;
|
|
363 uint8_t * bit_ptr;
|
36
|
364 int16_t * dest;
|
1
|
365
|
36
|
366 dest = picture->DCTblock;
|
1
|
367 i = 0;
|
|
368 mismatch = ~dest[0];
|
|
369
|
36
|
370 bit_buf = picture->bitstream_buf;
|
|
371 bits = picture->bitstream_bits;
|
|
372 bit_ptr = picture->bitstream_ptr;
|
1
|
373
|
|
374 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
375
|
|
376 while (1) {
|
|
377 if (bit_buf >= 0x28000000) {
|
|
378
|
|
379 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
|
|
380
|
|
381 i += tab->run;
|
|
382 if (i >= 64)
|
36
|
383 break; /* end of block */
|
1
|
384
|
|
385 normal_code:
|
|
386 j = scan[i];
|
|
387 bit_buf <<= tab->len;
|
|
388 bits += tab->len + 1;
|
|
389 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
|
|
390
|
36
|
391 /* if (bitstream_get (1)) val = -val; */
|
1
|
392 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
|
|
393
|
|
394 SATURATE (val);
|
|
395 dest[j] = val;
|
|
396 mismatch ^= val;
|
|
397
|
|
398 bit_buf <<= 1;
|
|
399 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
400
|
|
401 continue;
|
|
402
|
|
403 } else if (bit_buf >= 0x04000000) {
|
|
404
|
|
405 tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
|
|
406
|
|
407 i += tab->run;
|
|
408 if (i < 64)
|
|
409 goto normal_code;
|
|
410
|
36
|
411 /* escape code */
|
1
|
412
|
|
413 i += UBITS (bit_buf << 6, 6) - 64;
|
|
414 if (i >= 64)
|
36
|
415 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
416
|
|
417 j = scan[i];
|
|
418
|
|
419 DUMPBITS (bit_buf, bits, 12);
|
|
420 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
421 val = (SBITS (bit_buf, 12) *
|
|
422 quantizer_scale * quant_matrix[j]) / 16;
|
|
423
|
|
424 SATURATE (val);
|
|
425 dest[j] = val;
|
|
426 mismatch ^= val;
|
|
427
|
|
428 DUMPBITS (bit_buf, bits, 12);
|
|
429 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
430
|
|
431 continue;
|
|
432
|
|
433 } else if (bit_buf >= 0x02000000) {
|
|
434 tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
|
|
435 i += tab->run;
|
|
436 if (i < 64)
|
|
437 goto normal_code;
|
|
438 } else if (bit_buf >= 0x00800000) {
|
|
439 tab = DCT_13 - 16 + UBITS (bit_buf, 13);
|
|
440 i += tab->run;
|
|
441 if (i < 64)
|
|
442 goto normal_code;
|
|
443 } else if (bit_buf >= 0x00200000) {
|
|
444 tab = DCT_15 - 16 + UBITS (bit_buf, 15);
|
|
445 i += tab->run;
|
|
446 if (i < 64)
|
|
447 goto normal_code;
|
|
448 } else {
|
|
449 tab = DCT_16 + UBITS (bit_buf, 16);
|
|
450 bit_buf <<= 16;
|
|
451 GETWORD (bit_buf, bits + 16, bit_ptr);
|
|
452 i += tab->run;
|
|
453 if (i < 64)
|
|
454 goto normal_code;
|
|
455 }
|
36
|
456 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
457 }
|
|
458 dest[63] ^= mismatch & 1;
|
36
|
459 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
|
|
460 picture->bitstream_buf = bit_buf;
|
|
461 picture->bitstream_bits = bits;
|
|
462 picture->bitstream_ptr = bit_ptr;
|
1
|
463 }
|
|
464
|
36
|
465 static void get_intra_block_B15 (picture_t * picture)
|
1
|
466 {
|
|
467 int i;
|
|
468 int j;
|
|
469 int val;
|
|
470 uint8_t * scan = picture->scan;
|
|
471 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
|
36
|
472 int quantizer_scale = picture->quantizer_scale;
|
1
|
473 int mismatch;
|
|
474 DCTtab * tab;
|
|
475 uint32_t bit_buf;
|
|
476 int bits;
|
|
477 uint8_t * bit_ptr;
|
36
|
478 int16_t * dest;
|
1
|
479
|
36
|
480 dest = picture->DCTblock;
|
1
|
481 i = 0;
|
|
482 mismatch = ~dest[0];
|
|
483
|
36
|
484 bit_buf = picture->bitstream_buf;
|
|
485 bits = picture->bitstream_bits;
|
|
486 bit_ptr = picture->bitstream_ptr;
|
1
|
487
|
|
488 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
489
|
|
490 while (1) {
|
|
491 if (bit_buf >= 0x04000000) {
|
|
492
|
|
493 tab = DCT_B15_8 - 4 + UBITS (bit_buf, 8);
|
|
494
|
|
495 i += tab->run;
|
|
496 if (i < 64) {
|
|
497
|
|
498 normal_code:
|
|
499 j = scan[i];
|
|
500 bit_buf <<= tab->len;
|
|
501 bits += tab->len + 1;
|
|
502 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
|
|
503
|
36
|
504 /* if (bitstream_get (1)) val = -val; */
|
1
|
505 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
|
|
506
|
|
507 SATURATE (val);
|
|
508 dest[j] = val;
|
|
509 mismatch ^= val;
|
|
510
|
|
511 bit_buf <<= 1;
|
|
512 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
513
|
|
514 continue;
|
|
515
|
|
516 } else {
|
|
517
|
36
|
518 /* end of block. I commented out this code because if we */
|
|
519 /* dont exit here we will still exit at the later test :) */
|
1
|
520
|
36
|
521 /* if (i >= 128) break; */ /* end of block */
|
1
|
522
|
36
|
523 /* escape code */
|
1
|
524
|
|
525 i += UBITS (bit_buf << 6, 6) - 64;
|
|
526 if (i >= 64)
|
36
|
527 break; /* illegal, check against buffer overflow */
|
1
|
528
|
|
529 j = scan[i];
|
|
530
|
|
531 DUMPBITS (bit_buf, bits, 12);
|
|
532 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
533 val = (SBITS (bit_buf, 12) *
|
|
534 quantizer_scale * quant_matrix[j]) / 16;
|
|
535
|
|
536 SATURATE (val);
|
|
537 dest[j] = val;
|
|
538 mismatch ^= val;
|
|
539
|
|
540 DUMPBITS (bit_buf, bits, 12);
|
|
541 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
542
|
|
543 continue;
|
|
544
|
|
545 }
|
|
546 } else if (bit_buf >= 0x02000000) {
|
|
547 tab = DCT_B15_10 - 8 + UBITS (bit_buf, 10);
|
|
548 i += tab->run;
|
|
549 if (i < 64)
|
|
550 goto normal_code;
|
|
551 } else if (bit_buf >= 0x00800000) {
|
|
552 tab = DCT_13 - 16 + UBITS (bit_buf, 13);
|
|
553 i += tab->run;
|
|
554 if (i < 64)
|
|
555 goto normal_code;
|
|
556 } else if (bit_buf >= 0x00200000) {
|
|
557 tab = DCT_15 - 16 + UBITS (bit_buf, 15);
|
|
558 i += tab->run;
|
|
559 if (i < 64)
|
|
560 goto normal_code;
|
|
561 } else {
|
|
562 tab = DCT_16 + UBITS (bit_buf, 16);
|
|
563 bit_buf <<= 16;
|
|
564 GETWORD (bit_buf, bits + 16, bit_ptr);
|
|
565 i += tab->run;
|
|
566 if (i < 64)
|
|
567 goto normal_code;
|
|
568 }
|
36
|
569 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
570 }
|
|
571 dest[63] ^= mismatch & 1;
|
36
|
572 DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
|
|
573 picture->bitstream_buf = bit_buf;
|
|
574 picture->bitstream_bits = bits;
|
|
575 picture->bitstream_ptr = bit_ptr;
|
1
|
576 }
|
|
577
|
36
|
578 static void get_non_intra_block (picture_t * picture)
|
1
|
579 {
|
|
580 int i;
|
|
581 int j;
|
|
582 int val;
|
|
583 uint8_t * scan = picture->scan;
|
|
584 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
|
36
|
585 int quantizer_scale = picture->quantizer_scale;
|
1
|
586 int mismatch;
|
|
587 DCTtab * tab;
|
|
588 uint32_t bit_buf;
|
|
589 int bits;
|
|
590 uint8_t * bit_ptr;
|
36
|
591 int16_t * dest;
|
1
|
592
|
|
593 i = -1;
|
|
594 mismatch = 1;
|
36
|
595 dest = picture->DCTblock;
|
1
|
596
|
36
|
597 bit_buf = picture->bitstream_buf;
|
|
598 bits = picture->bitstream_bits;
|
|
599 bit_ptr = picture->bitstream_ptr;
|
1
|
600
|
|
601 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
602 if (bit_buf >= 0x28000000) {
|
|
603 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
|
|
604 goto entry_1;
|
|
605 } else
|
|
606 goto entry_2;
|
|
607
|
|
608 while (1) {
|
|
609 if (bit_buf >= 0x28000000) {
|
|
610
|
|
611 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
|
|
612
|
|
613 entry_1:
|
|
614 i += tab->run;
|
|
615 if (i >= 64)
|
36
|
616 break; /* end of block */
|
1
|
617
|
|
618 normal_code:
|
|
619 j = scan[i];
|
|
620 bit_buf <<= tab->len;
|
|
621 bits += tab->len + 1;
|
|
622 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
|
|
623
|
36
|
624 /* if (bitstream_get (1)) val = -val; */
|
1
|
625 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
|
|
626
|
|
627 SATURATE (val);
|
|
628 dest[j] = val;
|
|
629 mismatch ^= val;
|
|
630
|
|
631 bit_buf <<= 1;
|
|
632 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
633
|
|
634 continue;
|
|
635
|
|
636 }
|
|
637
|
|
638 entry_2:
|
|
639 if (bit_buf >= 0x04000000) {
|
|
640
|
|
641 tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
|
|
642
|
|
643 i += tab->run;
|
|
644 if (i < 64)
|
|
645 goto normal_code;
|
|
646
|
36
|
647 /* escape code */
|
1
|
648
|
|
649 i += UBITS (bit_buf << 6, 6) - 64;
|
|
650 if (i >= 64)
|
36
|
651 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
652
|
|
653 j = scan[i];
|
|
654
|
|
655 DUMPBITS (bit_buf, bits, 12);
|
|
656 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
657 val = 2 * (SBITS (bit_buf, 12) + SBITS (bit_buf, 1)) + 1;
|
|
658 val = (val * quantizer_scale * quant_matrix[j]) / 32;
|
|
659
|
|
660 SATURATE (val);
|
|
661 dest[j] = val;
|
|
662 mismatch ^= val;
|
|
663
|
|
664 DUMPBITS (bit_buf, bits, 12);
|
|
665 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
666
|
|
667 continue;
|
|
668
|
|
669 } else if (bit_buf >= 0x02000000) {
|
|
670 tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
|
|
671 i += tab->run;
|
|
672 if (i < 64)
|
|
673 goto normal_code;
|
|
674 } else if (bit_buf >= 0x00800000) {
|
|
675 tab = DCT_13 - 16 + UBITS (bit_buf, 13);
|
|
676 i += tab->run;
|
|
677 if (i < 64)
|
|
678 goto normal_code;
|
|
679 } else if (bit_buf >= 0x00200000) {
|
|
680 tab = DCT_15 - 16 + UBITS (bit_buf, 15);
|
|
681 i += tab->run;
|
|
682 if (i < 64)
|
|
683 goto normal_code;
|
|
684 } else {
|
|
685 tab = DCT_16 + UBITS (bit_buf, 16);
|
|
686 bit_buf <<= 16;
|
|
687 GETWORD (bit_buf, bits + 16, bit_ptr);
|
|
688 i += tab->run;
|
|
689 if (i < 64)
|
|
690 goto normal_code;
|
|
691 }
|
36
|
692 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
693 }
|
|
694 dest[63] ^= mismatch & 1;
|
36
|
695 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
|
|
696 picture->bitstream_buf = bit_buf;
|
|
697 picture->bitstream_bits = bits;
|
|
698 picture->bitstream_ptr = bit_ptr;
|
1
|
699 }
|
|
700
|
36
|
701 static void get_mpeg1_intra_block (picture_t * picture)
|
1
|
702 {
|
|
703 int i;
|
|
704 int j;
|
|
705 int val;
|
|
706 uint8_t * scan = picture->scan;
|
|
707 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
|
36
|
708 int quantizer_scale = picture->quantizer_scale;
|
1
|
709 DCTtab * tab;
|
|
710 uint32_t bit_buf;
|
|
711 int bits;
|
|
712 uint8_t * bit_ptr;
|
36
|
713 int16_t * dest;
|
1
|
714
|
|
715 i = 0;
|
36
|
716 dest = picture->DCTblock;
|
1
|
717
|
36
|
718 bit_buf = picture->bitstream_buf;
|
|
719 bits = picture->bitstream_bits;
|
|
720 bit_ptr = picture->bitstream_ptr;
|
1
|
721
|
|
722 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
723
|
|
724 while (1) {
|
|
725 if (bit_buf >= 0x28000000) {
|
|
726
|
|
727 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
|
|
728
|
|
729 i += tab->run;
|
|
730 if (i >= 64)
|
36
|
731 break; /* end of block */
|
1
|
732
|
|
733 normal_code:
|
|
734 j = scan[i];
|
|
735 bit_buf <<= tab->len;
|
|
736 bits += tab->len + 1;
|
|
737 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
|
|
738
|
36
|
739 /* oddification */
|
1
|
740 val = (val - 1) | 1;
|
|
741
|
36
|
742 /* if (bitstream_get (1)) val = -val; */
|
1
|
743 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
|
|
744
|
|
745 SATURATE (val);
|
|
746 dest[j] = val;
|
|
747
|
|
748 bit_buf <<= 1;
|
|
749 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
750
|
|
751 continue;
|
|
752
|
|
753 } else if (bit_buf >= 0x04000000) {
|
|
754
|
|
755 tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
|
|
756
|
|
757 i += tab->run;
|
|
758 if (i < 64)
|
|
759 goto normal_code;
|
|
760
|
36
|
761 /* escape code */
|
1
|
762
|
|
763 i += UBITS (bit_buf << 6, 6) - 64;
|
|
764 if (i >= 64)
|
36
|
765 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
766
|
|
767 j = scan[i];
|
|
768
|
|
769 DUMPBITS (bit_buf, bits, 12);
|
|
770 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
771 val = SBITS (bit_buf, 8);
|
|
772 if (! (val & 0x7f)) {
|
|
773 DUMPBITS (bit_buf, bits, 8);
|
|
774 val = UBITS (bit_buf, 8) + 2 * val;
|
|
775 }
|
|
776 val = (val * quantizer_scale * quant_matrix[j]) / 16;
|
|
777
|
36
|
778 /* oddification */
|
1
|
779 val = (val + ~SBITS (val, 1)) | 1;
|
|
780
|
|
781 SATURATE (val);
|
|
782 dest[j] = val;
|
|
783
|
|
784 DUMPBITS (bit_buf, bits, 8);
|
|
785 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
786
|
|
787 continue;
|
|
788
|
|
789 } else if (bit_buf >= 0x02000000) {
|
|
790 tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
|
|
791 i += tab->run;
|
|
792 if (i < 64)
|
|
793 goto normal_code;
|
|
794 } else if (bit_buf >= 0x00800000) {
|
|
795 tab = DCT_13 - 16 + UBITS (bit_buf, 13);
|
|
796 i += tab->run;
|
|
797 if (i < 64)
|
|
798 goto normal_code;
|
|
799 } else if (bit_buf >= 0x00200000) {
|
|
800 tab = DCT_15 - 16 + UBITS (bit_buf, 15);
|
|
801 i += tab->run;
|
|
802 if (i < 64)
|
|
803 goto normal_code;
|
|
804 } else {
|
|
805 tab = DCT_16 + UBITS (bit_buf, 16);
|
|
806 bit_buf <<= 16;
|
|
807 GETWORD (bit_buf, bits + 16, bit_ptr);
|
|
808 i += tab->run;
|
|
809 if (i < 64)
|
|
810 goto normal_code;
|
|
811 }
|
36
|
812 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
813 }
|
36
|
814 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
|
|
815 picture->bitstream_buf = bit_buf;
|
|
816 picture->bitstream_bits = bits;
|
|
817 picture->bitstream_ptr = bit_ptr;
|
1
|
818 }
|
|
819
|
36
|
820 static void get_mpeg1_non_intra_block (picture_t * picture)
|
1
|
821 {
|
|
822 int i;
|
|
823 int j;
|
|
824 int val;
|
|
825 uint8_t * scan = picture->scan;
|
|
826 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
|
36
|
827 int quantizer_scale = picture->quantizer_scale;
|
1
|
828 DCTtab * tab;
|
|
829 uint32_t bit_buf;
|
|
830 int bits;
|
|
831 uint8_t * bit_ptr;
|
36
|
832 int16_t * dest;
|
1
|
833
|
|
834 i = -1;
|
36
|
835 dest = picture->DCTblock;
|
1
|
836
|
36
|
837 bit_buf = picture->bitstream_buf;
|
|
838 bits = picture->bitstream_bits;
|
|
839 bit_ptr = picture->bitstream_ptr;
|
1
|
840
|
|
841 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
842 if (bit_buf >= 0x28000000) {
|
|
843 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
|
|
844 goto entry_1;
|
|
845 } else
|
|
846 goto entry_2;
|
|
847
|
|
848 while (1) {
|
|
849 if (bit_buf >= 0x28000000) {
|
|
850
|
|
851 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
|
|
852
|
|
853 entry_1:
|
|
854 i += tab->run;
|
|
855 if (i >= 64)
|
36
|
856 break; /* end of block */
|
1
|
857
|
|
858 normal_code:
|
|
859 j = scan[i];
|
|
860 bit_buf <<= tab->len;
|
|
861 bits += tab->len + 1;
|
|
862 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
|
|
863
|
36
|
864 /* oddification */
|
1
|
865 val = (val - 1) | 1;
|
|
866
|
36
|
867 /* if (bitstream_get (1)) val = -val; */
|
1
|
868 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
|
|
869
|
|
870 SATURATE (val);
|
|
871 dest[j] = val;
|
|
872
|
|
873 bit_buf <<= 1;
|
|
874 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
875
|
|
876 continue;
|
|
877
|
|
878 }
|
|
879
|
|
880 entry_2:
|
|
881 if (bit_buf >= 0x04000000) {
|
|
882
|
|
883 tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
|
|
884
|
|
885 i += tab->run;
|
|
886 if (i < 64)
|
|
887 goto normal_code;
|
|
888
|
36
|
889 /* escape code */
|
1
|
890
|
|
891 i += UBITS (bit_buf << 6, 6) - 64;
|
|
892 if (i >= 64)
|
36
|
893 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
894
|
|
895 j = scan[i];
|
|
896
|
|
897 DUMPBITS (bit_buf, bits, 12);
|
|
898 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
899 val = SBITS (bit_buf, 8);
|
|
900 if (! (val & 0x7f)) {
|
|
901 DUMPBITS (bit_buf, bits, 8);
|
|
902 val = UBITS (bit_buf, 8) + 2 * val;
|
|
903 }
|
|
904 val = 2 * (val + SBITS (val, 1)) + 1;
|
|
905 val = (val * quantizer_scale * quant_matrix[j]) / 32;
|
|
906
|
36
|
907 /* oddification */
|
1
|
908 val = (val + ~SBITS (val, 1)) | 1;
|
|
909
|
|
910 SATURATE (val);
|
|
911 dest[j] = val;
|
|
912
|
|
913 DUMPBITS (bit_buf, bits, 8);
|
|
914 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
915
|
|
916 continue;
|
|
917
|
|
918 } else if (bit_buf >= 0x02000000) {
|
|
919 tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
|
|
920 i += tab->run;
|
|
921 if (i < 64)
|
|
922 goto normal_code;
|
|
923 } else if (bit_buf >= 0x00800000) {
|
|
924 tab = DCT_13 - 16 + UBITS (bit_buf, 13);
|
|
925 i += tab->run;
|
|
926 if (i < 64)
|
|
927 goto normal_code;
|
|
928 } else if (bit_buf >= 0x00200000) {
|
|
929 tab = DCT_15 - 16 + UBITS (bit_buf, 15);
|
|
930 i += tab->run;
|
|
931 if (i < 64)
|
|
932 goto normal_code;
|
|
933 } else {
|
|
934 tab = DCT_16 + UBITS (bit_buf, 16);
|
|
935 bit_buf <<= 16;
|
|
936 GETWORD (bit_buf, bits + 16, bit_ptr);
|
|
937 i += tab->run;
|
|
938 if (i < 64)
|
|
939 goto normal_code;
|
|
940 }
|
36
|
941 break; /* illegal, check needed to avoid buffer overflow */
|
1
|
942 }
|
36
|
943 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
|
|
944 picture->bitstream_buf = bit_buf;
|
|
945 picture->bitstream_bits = bits;
|
|
946 picture->bitstream_ptr = bit_ptr;
|
1
|
947 }
|
|
948
|
36
|
949 static inline int get_macroblock_address_increment (picture_t * picture)
|
1
|
950 {
|
36
|
951 #define bit_buf (picture->bitstream_buf)
|
|
952 #define bits (picture->bitstream_bits)
|
|
953 #define bit_ptr (picture->bitstream_ptr)
|
1
|
954
|
|
955 MBAtab * tab;
|
|
956 int mba;
|
|
957
|
|
958 mba = 0;
|
|
959
|
|
960 while (1) {
|
|
961 if (bit_buf >= 0x10000000) {
|
|
962 tab = MBA_5 - 2 + UBITS (bit_buf, 5);
|
|
963 DUMPBITS (bit_buf, bits, tab->len);
|
|
964 return mba + tab->mba;
|
|
965 } else if (bit_buf >= 0x03000000) {
|
|
966 tab = MBA_11 - 24 + UBITS (bit_buf, 11);
|
|
967 DUMPBITS (bit_buf, bits, tab->len);
|
|
968 return mba + tab->mba;
|
|
969 } else switch (UBITS (bit_buf, 11)) {
|
36
|
970 case 8: /* macroblock_escape */
|
1
|
971 mba += 33;
|
36
|
972 /* no break here on purpose */
|
|
973 case 15: /* macroblock_stuffing (MPEG1 only) */
|
1
|
974 DUMPBITS (bit_buf, bits, 11);
|
|
975 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
976 break;
|
36
|
977 default: /* end of slice, or error */
|
1
|
978 return 0;
|
|
979 }
|
|
980 }
|
|
981
|
|
982 #undef bit_buf
|
|
983 #undef bits
|
|
984 #undef bit_ptr
|
|
985 }
|
|
986
|
36
|
987 static inline void slice_intra_DCT (picture_t * picture, int cc,
|
|
988 uint8_t * dest, int stride)
|
1
|
989 {
|
36
|
990 #define bit_buf (picture->bitstream_buf)
|
|
991 #define bits (picture->bitstream_bits)
|
|
992 #define bit_ptr (picture->bitstream_ptr)
|
1
|
993 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
994 /* Get the intra DC coefficient and inverse quantize it */
|
1
|
995 if (cc == 0)
|
36
|
996 picture->dc_dct_pred[0] += get_luma_dc_dct_diff (picture);
|
1
|
997 else
|
36
|
998 picture->dc_dct_pred[cc] += get_chroma_dc_dct_diff (picture);
|
|
999 picture->DCTblock[0] =
|
|
1000 picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision);
|
|
1001 memset (picture->DCTblock + 1, 0, 63 * sizeof (int16_t));
|
1
|
1002
|
|
1003 if (picture->mpeg1) {
|
|
1004 if (picture->picture_coding_type != D_TYPE)
|
36
|
1005 get_mpeg1_intra_block (picture);
|
1
|
1006 } else if (picture->intra_vlc_format)
|
36
|
1007 get_intra_block_B15 (picture);
|
1
|
1008 else
|
36
|
1009 get_intra_block_B14 (picture);
|
|
1010 idct_block_copy (picture->DCTblock, dest, stride);
|
1
|
1011 #undef bit_buf
|
|
1012 #undef bits
|
|
1013 #undef bit_ptr
|
|
1014 }
|
|
1015
|
36
|
1016 static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest,
|
|
1017 int stride)
|
1
|
1018 {
|
36
|
1019 memset (picture->DCTblock, 0, 64 * sizeof (int16_t));
|
1
|
1020 if (picture->mpeg1)
|
36
|
1021 get_mpeg1_non_intra_block (picture);
|
1
|
1022 else
|
36
|
1023 get_non_intra_block (picture);
|
|
1024 idct_block_add (picture->DCTblock, dest, stride);
|
1
|
1025 }
|
|
1026
|
|
1027 static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
|
|
1028 int32_t, int32_t),
|
|
1029 int x_pred, int y_pred,
|
|
1030 uint8_t * dest[3], int dest_offset,
|
|
1031 uint8_t * src[3], int src_offset,
|
|
1032 int stride, int height, int second_half)
|
|
1033 {
|
|
1034 int xy_half;
|
|
1035 uint8_t * src1;
|
|
1036 uint8_t * src2;
|
|
1037
|
|
1038 xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
|
|
1039
|
|
1040 src1 = src[0] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride +
|
|
1041 second_half * (stride << 3);
|
|
1042
|
|
1043 table[xy_half] (dest[0] + dest_offset + second_half * (stride << 3),
|
|
1044 src1, stride, height);
|
|
1045
|
|
1046 x_pred /= 2;
|
|
1047 y_pred /= 2;
|
|
1048
|
|
1049 xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
|
|
1050 stride >>= 1;
|
|
1051 height >>= 1;
|
|
1052 src_offset >>= 1; src_offset += second_half * (stride << 2);
|
|
1053 dest_offset >>= 1; dest_offset += second_half * (stride << 2);
|
|
1054
|
|
1055 src1 = src[1] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride;
|
|
1056 src2 = src[2] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride;
|
|
1057
|
|
1058 table[4+xy_half] (dest[1] + dest_offset, src1, stride, height);
|
|
1059 table[4+xy_half] (dest[2] + dest_offset, src2, stride, height);
|
|
1060 }
|
|
1061
|
|
1062
|
36
|
1063 static void motion_mp1 (picture_t * picture, motion_t * motion,
|
|
1064 uint8_t * dest[3], int offset, int stride,
|
1
|
1065 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1066 {
|
36
|
1067 #define bit_buf (picture->bitstream_buf)
|
|
1068 #define bits (picture->bitstream_bits)
|
|
1069 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1070 int motion_x, motion_y;
|
|
1071
|
|
1072 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1073 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1074 motion->f_code[0]);
|
1
|
1075 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1076 motion->pmv[0][0] = motion_x;
|
|
1077
|
|
1078 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1079 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1080 motion->f_code[0]);
|
1
|
1081 motion_y = bound_motion_vector (motion_y, motion->f_code[0]);
|
|
1082 motion->pmv[0][1] = motion_y;
|
|
1083
|
|
1084 if (motion->f_code[1]) {
|
|
1085 motion_x <<= 1;
|
|
1086 motion_y <<= 1;
|
|
1087 }
|
|
1088
|
|
1089 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1090 motion->ref[0], offset, stride, 16, 0);
|
1
|
1091 #undef bit_buf
|
|
1092 #undef bits
|
|
1093 #undef bit_ptr
|
|
1094 }
|
|
1095
|
36
|
1096 static void motion_mp1_reuse (picture_t * picture, motion_t * motion,
|
|
1097 uint8_t * dest[3], int offset, int stride,
|
1
|
1098 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1099 {
|
|
1100 int motion_x, motion_y;
|
|
1101
|
|
1102 motion_x = motion->pmv[0][0];
|
|
1103 motion_y = motion->pmv[0][1];
|
|
1104
|
|
1105 if (motion->f_code[1]) {
|
|
1106 motion_x <<= 1;
|
|
1107 motion_y <<= 1;
|
|
1108 }
|
|
1109
|
|
1110 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1111 motion->ref[0], offset, stride, 16, 0);
|
1
|
1112 }
|
|
1113
|
36
|
1114 static void motion_fr_frame (picture_t * picture, motion_t * motion,
|
|
1115 uint8_t * dest[3], int offset, int stride,
|
1
|
1116 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1117 {
|
36
|
1118 #define bit_buf (picture->bitstream_buf)
|
|
1119 #define bits (picture->bitstream_bits)
|
|
1120 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1121 int motion_x, motion_y;
|
|
1122
|
|
1123 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1124 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1125 motion->f_code[0]);
|
1
|
1126 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1127 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1128
|
|
1129 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1130 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1131 motion->f_code[1]);
|
1
|
1132 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1133 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1134
|
|
1135 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1136 motion->ref[0], offset, stride, 16, 0);
|
1
|
1137 #undef bit_buf
|
|
1138 #undef bits
|
|
1139 #undef bit_ptr
|
|
1140 }
|
|
1141
|
36
|
1142 static void motion_fr_field (picture_t * picture, motion_t * motion,
|
|
1143 uint8_t * dest[3], int offset, int stride,
|
1
|
1144 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1145 {
|
36
|
1146 #define bit_buf (picture->bitstream_buf)
|
|
1147 #define bits (picture->bitstream_bits)
|
|
1148 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1149 int motion_x, motion_y;
|
|
1150 int field_select;
|
|
1151
|
|
1152 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1153 field_select = SBITS (bit_buf, 1);
|
|
1154 DUMPBITS (bit_buf, bits, 1);
|
|
1155
|
36
|
1156 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1157 motion->f_code[0]);
|
1
|
1158 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1159 motion->pmv[0][0] = motion_x;
|
|
1160
|
|
1161 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1162 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
|
1
|
1163 motion->f_code[1]);
|
36
|
1164 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1165 motion->pmv[0][1] = motion_y << 1;
|
|
1166
|
|
1167 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1168 motion->ref[0], offset + (field_select & stride),
|
|
1169 stride * 2, 8, 0);
|
1
|
1170
|
|
1171 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1172 field_select = SBITS (bit_buf, 1);
|
|
1173 DUMPBITS (bit_buf, bits, 1);
|
|
1174
|
36
|
1175 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
|
|
1176 motion->f_code[0]);
|
1
|
1177 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1178 motion->pmv[1][0] = motion_x;
|
|
1179
|
|
1180 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1181 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture,
|
1
|
1182 motion->f_code[1]);
|
36
|
1183 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1184 motion->pmv[1][1] = motion_y << 1;
|
|
1185
|
36
|
1186 motion_block (table, motion_x, motion_y, dest, offset + stride,
|
|
1187 motion->ref[0], offset + (field_select & stride),
|
|
1188 stride * 2, 8, 0);
|
1
|
1189 #undef bit_buf
|
|
1190 #undef bits
|
|
1191 #undef bit_ptr
|
|
1192 }
|
|
1193
|
36
|
1194 static void motion_fr_dmv (picture_t * picture, motion_t * motion,
|
|
1195 uint8_t * dest[3], int offset, int stride,
|
1
|
1196 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1197 {
|
36
|
1198 #define bit_buf (picture->bitstream_buf)
|
|
1199 #define bits (picture->bitstream_bits)
|
|
1200 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1201 int motion_x, motion_y;
|
|
1202 int dmv_x, dmv_y;
|
|
1203 int m;
|
|
1204 int other_x, other_y;
|
|
1205
|
|
1206 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1207 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1208 motion->f_code[0]);
|
1
|
1209 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1210 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1211
|
|
1212 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1213 dmv_x = get_dmv (picture);
|
1
|
1214
|
|
1215 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1216 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
|
1
|
1217 motion->f_code[1]);
|
36
|
1218 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1219 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
|
|
1220
|
|
1221 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1222 dmv_y = get_dmv (picture);
|
1
|
1223
|
|
1224 motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
|
36
|
1225 motion->ref[0], offset, stride * 2, 8, 0);
|
1
|
1226
|
36
|
1227 m = picture->top_field_first ? 1 : 3;
|
1
|
1228 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
|
|
1229 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
|
|
1230 motion_block (mc_functions.avg, other_x, other_y, dest, offset,
|
36
|
1231 motion->ref[0], offset + stride, stride * 2, 8, 0);
|
1
|
1232
|
36
|
1233 motion_block (mc_functions.put, motion_x, motion_y, dest, offset + stride,
|
|
1234 motion->ref[0], offset + stride, stride * 2, 8, 0);
|
1
|
1235
|
36
|
1236 m = picture->top_field_first ? 3 : 1;
|
1
|
1237 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
|
|
1238 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
|
36
|
1239 motion_block (mc_functions.avg, other_x, other_y, dest, offset + stride,
|
|
1240 motion->ref[0], offset, stride * 2, 8, 0);
|
1
|
1241 #undef bit_buf
|
|
1242 #undef bits
|
|
1243 #undef bit_ptr
|
|
1244 }
|
|
1245
|
36
|
1246 /* like motion_frame, but reuse previous motion vectors */
|
|
1247 static void motion_fr_reuse (picture_t * picture, motion_t * motion,
|
|
1248 uint8_t * dest[3], int offset, int stride,
|
1
|
1249 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1250 {
|
|
1251 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
|
36
|
1252 motion->ref[0], offset, stride, 16, 0);
|
1
|
1253 }
|
|
1254
|
36
|
1255 /* like motion_frame, but use null motion vectors */
|
|
1256 static void motion_fr_zero (picture_t * picture, motion_t * motion,
|
|
1257 uint8_t * dest[3], int offset, int stride,
|
1
|
1258 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1259 {
|
|
1260 motion_block (table, 0, 0, dest, offset,
|
36
|
1261 motion->ref[0], offset, stride, 16, 0);
|
1
|
1262 }
|
|
1263
|
36
|
1264 /* like motion_frame, but parsing without actual motion compensation */
|
|
1265 static void motion_fr_conceal (picture_t * picture)
|
1
|
1266 {
|
36
|
1267 #define bit_buf (picture->bitstream_buf)
|
|
1268 #define bits (picture->bitstream_bits)
|
|
1269 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1270 int tmp;
|
|
1271
|
|
1272 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1273 tmp = (picture->f_motion.pmv[0][0] +
|
|
1274 get_motion_delta (picture, picture->f_motion.f_code[0]));
|
|
1275 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
|
|
1276 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
|
1
|
1277
|
|
1278 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1279 tmp = (picture->f_motion.pmv[0][1] +
|
|
1280 get_motion_delta (picture, picture->f_motion.f_code[1]));
|
|
1281 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
|
|
1282 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
|
1
|
1283
|
36
|
1284 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
|
1
|
1285 #undef bit_buf
|
|
1286 #undef bits
|
|
1287 #undef bit_ptr
|
|
1288 }
|
|
1289
|
36
|
1290 static void motion_fi_field (picture_t * picture, motion_t * motion,
|
|
1291 uint8_t * dest[3], int offset, int stride,
|
1
|
1292 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1293 {
|
36
|
1294 #define bit_buf (picture->bitstream_buf)
|
|
1295 #define bits (picture->bitstream_bits)
|
|
1296 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1297 int motion_x, motion_y;
|
|
1298 int field_select;
|
|
1299
|
|
1300 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1301 field_select = UBITS (bit_buf, 1);
|
|
1302 DUMPBITS (bit_buf, bits, 1);
|
|
1303
|
|
1304 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1305 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1306 motion->f_code[0]);
|
1
|
1307 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1308 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1309
|
|
1310 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1311 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1312 motion->f_code[1]);
|
1
|
1313 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1314 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1315
|
|
1316 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1317 motion->ref[field_select], offset, stride, 16, 0);
|
1
|
1318 #undef bit_buf
|
|
1319 #undef bits
|
|
1320 #undef bit_ptr
|
|
1321 }
|
|
1322
|
36
|
1323 static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
|
|
1324 uint8_t * dest[3], int offset, int stride,
|
1
|
1325 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1326 {
|
36
|
1327 #define bit_buf (picture->bitstream_buf)
|
|
1328 #define bits (picture->bitstream_bits)
|
|
1329 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1330 int motion_x, motion_y;
|
|
1331 int field_select;
|
|
1332
|
|
1333 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1334 field_select = UBITS (bit_buf, 1);
|
|
1335 DUMPBITS (bit_buf, bits, 1);
|
|
1336
|
|
1337 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1338 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1339 motion->f_code[0]);
|
1
|
1340 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1341 motion->pmv[0][0] = motion_x;
|
|
1342
|
|
1343 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1344 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1345 motion->f_code[1]);
|
1
|
1346 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1347 motion->pmv[0][1] = motion_y;
|
|
1348
|
|
1349 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1350 motion->ref[field_select], offset, stride, 8, 0);
|
1
|
1351
|
|
1352 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1353 field_select = UBITS (bit_buf, 1);
|
|
1354 DUMPBITS (bit_buf, bits, 1);
|
|
1355
|
|
1356 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1357 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
|
|
1358 motion->f_code[0]);
|
1
|
1359 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1360 motion->pmv[1][0] = motion_x;
|
|
1361
|
|
1362 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1363 motion_y = motion->pmv[1][1] + get_motion_delta (picture,
|
|
1364 motion->f_code[1]);
|
1
|
1365 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1366 motion->pmv[1][1] = motion_y;
|
|
1367
|
|
1368 motion_block (table, motion_x, motion_y, dest, offset,
|
36
|
1369 motion->ref[field_select], offset, stride, 8, 1);
|
1
|
1370 #undef bit_buf
|
|
1371 #undef bits
|
|
1372 #undef bit_ptr
|
|
1373 }
|
|
1374
|
36
|
1375 static void motion_fi_dmv (picture_t * picture, motion_t * motion,
|
|
1376 uint8_t * dest[3], int offset, int stride,
|
1
|
1377 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1378 {
|
36
|
1379 #define bit_buf (picture->bitstream_buf)
|
|
1380 #define bits (picture->bitstream_bits)
|
|
1381 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1382 int motion_x, motion_y;
|
|
1383 int dmv_x, dmv_y;
|
|
1384
|
|
1385 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1386 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1387 motion->f_code[0]);
|
1
|
1388 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1389 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1390
|
|
1391 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1392 dmv_x = get_dmv (picture);
|
1
|
1393
|
|
1394 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1395 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1396 motion->f_code[1]);
|
1
|
1397 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1398 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1399
|
|
1400 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1401 dmv_y = get_dmv (picture);
|
1
|
1402
|
|
1403 motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
|
36
|
1404 motion->ref[picture->current_field], offset, stride, 16, 0);
|
1
|
1405
|
|
1406 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
|
|
1407 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
|
36
|
1408 2 * picture->current_field - 1;
|
1
|
1409 motion_block (mc_functions.avg, motion_x, motion_y, dest, offset,
|
36
|
1410 motion->ref[!picture->current_field], offset, stride, 16, 0);
|
1
|
1411 #undef bit_buf
|
|
1412 #undef bits
|
|
1413 #undef bit_ptr
|
|
1414 }
|
|
1415
|
36
|
1416 static void motion_fi_reuse (picture_t * picture, motion_t * motion,
|
|
1417 uint8_t * dest[3], int offset, int stride,
|
1
|
1418 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1419 {
|
|
1420 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
|
36
|
1421 motion->ref[picture->current_field], offset, stride, 16, 0);
|
1
|
1422 }
|
|
1423
|
36
|
1424 static void motion_fi_zero (picture_t * picture, motion_t * motion,
|
|
1425 uint8_t * dest[3], int offset, int stride,
|
1
|
1426 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1427 {
|
|
1428 motion_block (table, 0, 0, dest, offset,
|
36
|
1429 motion->ref[picture->current_field], offset, stride, 16, 0);
|
1
|
1430 }
|
|
1431
|
36
|
1432 static void motion_fi_conceal (picture_t * picture)
|
1
|
1433 {
|
36
|
1434 #define bit_buf (picture->bitstream_buf)
|
|
1435 #define bits (picture->bitstream_bits)
|
|
1436 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1437 int tmp;
|
|
1438
|
|
1439 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1440 DUMPBITS (bit_buf, bits, 1); /* remove field_select */
|
1
|
1441
|
|
1442 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1443 tmp = (picture->f_motion.pmv[0][0] +
|
|
1444 get_motion_delta (picture, picture->f_motion.f_code[0]));
|
|
1445 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
|
|
1446 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
|
1
|
1447
|
|
1448 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1449 tmp = (picture->f_motion.pmv[0][1] +
|
|
1450 get_motion_delta (picture, picture->f_motion.f_code[1]));
|
|
1451 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
|
|
1452 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
|
1
|
1453
|
36
|
1454 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
|
1
|
1455 #undef bit_buf
|
|
1456 #undef bits
|
|
1457 #undef bit_ptr
|
|
1458 }
|
|
1459
|
36
|
1460 #define MOTION(routine,direction) \
|
1
|
1461 do { \
|
|
1462 if ((direction) & MACROBLOCK_MOTION_FORWARD) \
|
36
|
1463 routine (picture, &(picture->f_motion), dest, offset, stride, \
|
1
|
1464 mc_functions.put); \
|
|
1465 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
|
36
|
1466 routine (picture, &(picture->b_motion), dest, offset, stride, \
|
1
|
1467 ((direction) & MACROBLOCK_MOTION_FORWARD ? \
|
|
1468 mc_functions.avg : mc_functions.put)); \
|
|
1469 } while (0)
|
|
1470
|
36
|
1471 #define CHECK_DISPLAY \
|
|
1472 do { \
|
|
1473 if (offset == picture->coded_picture_width) { \
|
|
1474 picture->f_motion.ref[0][0] += 16 * stride; \
|
|
1475 picture->f_motion.ref[0][1] += 4 * stride; \
|
|
1476 picture->f_motion.ref[0][2] += 4 * stride; \
|
|
1477 picture->b_motion.ref[0][0] += 16 * stride; \
|
|
1478 picture->b_motion.ref[0][1] += 4 * stride; \
|
|
1479 picture->b_motion.ref[0][2] += 4 * stride; \
|
|
1480 do { /* just so we can use the break statement */ \
|
|
1481 if (picture->current_frame->copy) { \
|
|
1482 picture->current_frame->copy (picture->current_frame, \
|
|
1483 dest); \
|
|
1484 if (picture->picture_coding_type == B_TYPE) \
|
|
1485 break; \
|
|
1486 } \
|
|
1487 dest[0] += 16 * stride; \
|
|
1488 dest[1] += 4 * stride; \
|
|
1489 dest[2] += 4 * stride; \
|
|
1490 } while (0); \
|
41
|
1491 offset = 0; ++code; \
|
36
|
1492 } \
|
1
|
1493 } while (0)
|
|
1494
|
|
1495 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
|
|
1496 {
|
36
|
1497 #define bit_buf (picture->bitstream_buf)
|
|
1498 #define bits (picture->bitstream_bits)
|
|
1499 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1500 int macroblock_modes;
|
36
|
1501 int stride;
|
1
|
1502 uint8_t * dest[3];
|
|
1503 int offset;
|
|
1504 uint8_t ** forward_ref[2];
|
|
1505
|
36
|
1506 stride = picture->coded_picture_width;
|
|
1507 offset = (code - 1) * stride * 4;
|
1
|
1508
|
36
|
1509 forward_ref[0] = picture->forward_reference_frame->base;
|
1
|
1510 if (picture->picture_structure != FRAME_PICTURE) {
|
|
1511 offset <<= 1;
|
36
|
1512 forward_ref[1] = picture->forward_reference_frame->base;
|
|
1513 picture->current_field = (picture->picture_structure == BOTTOM_FIELD);
|
1
|
1514 if ((picture->second_field) &&
|
|
1515 (picture->picture_coding_type != B_TYPE))
|
|
1516 forward_ref[picture->picture_structure == TOP_FIELD] =
|
36
|
1517 picture->current_frame->base;
|
|
1518 picture->f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + stride;
|
|
1519 picture->f_motion.ref[1][1] =
|
|
1520 forward_ref[1][1] + offset + (stride >> 1);
|
|
1521 picture->f_motion.ref[1][2] =
|
|
1522 forward_ref[1][2] + offset + (stride >> 1);
|
|
1523 picture->b_motion.ref[1][0] =
|
|
1524 picture->backward_reference_frame->base[0] + offset * 4 + stride;
|
|
1525 picture->b_motion.ref[1][1] =
|
|
1526 (picture->backward_reference_frame->base[1] +
|
|
1527 offset + (stride >> 1));
|
|
1528 picture->b_motion.ref[1][2] =
|
|
1529 (picture->backward_reference_frame->base[2] +
|
|
1530 offset + (stride >> 1));
|
1
|
1531 }
|
|
1532
|
36
|
1533 picture->f_motion.ref[0][0] = forward_ref[0][0] + offset * 4;
|
|
1534 picture->f_motion.ref[0][1] = forward_ref[0][1] + offset;
|
|
1535 picture->f_motion.ref[0][2] = forward_ref[0][2] + offset;
|
|
1536 picture->f_motion.f_code[0] = picture->f_code[0][0];
|
|
1537 picture->f_motion.f_code[1] = picture->f_code[0][1];
|
|
1538 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1539 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
|
1540 picture->b_motion.ref[0][0] =
|
|
1541 picture->backward_reference_frame->base[0] + offset * 4;
|
|
1542 picture->b_motion.ref[0][1] =
|
|
1543 picture->backward_reference_frame->base[1] + offset;
|
|
1544 picture->b_motion.ref[0][2] =
|
|
1545 picture->backward_reference_frame->base[2] + offset;
|
|
1546 picture->b_motion.f_code[0] = picture->f_code[1][0];
|
|
1547 picture->b_motion.f_code[1] = picture->f_code[1][1];
|
|
1548 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
|
|
1549 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
|
1
|
1550
|
36
|
1551 if ((picture->current_frame->copy) &&
|
1
|
1552 (picture->picture_coding_type == B_TYPE))
|
|
1553 offset = 0;
|
|
1554
|
36
|
1555 dest[0] = picture->current_frame->base[0] + offset * 4;
|
|
1556 dest[1] = picture->current_frame->base[1] + offset;
|
|
1557 dest[2] = picture->current_frame->base[2] + offset;
|
1
|
1558
|
|
1559 switch (picture->picture_structure) {
|
|
1560 case BOTTOM_FIELD:
|
36
|
1561 dest[0] += stride;
|
|
1562 dest[1] += stride >> 1;
|
|
1563 dest[2] += stride >> 1;
|
|
1564 /* follow thru */
|
1
|
1565 case TOP_FIELD:
|
36
|
1566 stride <<= 1;
|
1
|
1567 }
|
|
1568
|
36
|
1569 /* reset intra dc predictor */
|
|
1570 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1571 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
|
1
|
1572
|
36
|
1573 bitstream_init (picture, buffer);
|
1
|
1574
|
36
|
1575 picture->quantizer_scale = get_quantizer_scale (picture);
|
1
|
1576
|
36
|
1577 /* ignore intra_slice and all the extra data */
|
1
|
1578 while (bit_buf & 0x80000000) {
|
|
1579 DUMPBITS (bit_buf, bits, 9);
|
|
1580 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1581 }
|
|
1582 DUMPBITS (bit_buf, bits, 1);
|
|
1583
|
|
1584 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1585 offset = get_macroblock_address_increment (picture) << 4;
|
1
|
1586
|
|
1587 while (1) {
|
|
1588 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1589
|
36
|
1590 macroblock_modes = get_macroblock_modes (picture);
|
1
|
1591
|
36
|
1592 /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */
|
1
|
1593 if (macroblock_modes & MACROBLOCK_QUANT)
|
36
|
1594 picture->quantizer_scale = get_quantizer_scale (picture);
|
1
|
1595
|
|
1596 if (macroblock_modes & MACROBLOCK_INTRA) {
|
|
1597
|
|
1598 int DCT_offset, DCT_stride;
|
|
1599
|
|
1600 if (picture->concealment_motion_vectors) {
|
|
1601 if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1602 motion_fr_conceal (picture);
|
1
|
1603 else
|
36
|
1604 motion_fi_conceal (picture);
|
1
|
1605 } else {
|
36
|
1606 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1607 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
|
1608 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
|
|
1609 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
|
1
|
1610 }
|
|
1611
|
|
1612 if (macroblock_modes & DCT_TYPE_INTERLACED) {
|
36
|
1613 DCT_offset = stride;
|
|
1614 DCT_stride = stride * 2;
|
1
|
1615 } else {
|
36
|
1616 DCT_offset = stride * 8;
|
|
1617 DCT_stride = stride;
|
1
|
1618 }
|
|
1619
|
36
|
1620 /* Decode lum blocks */
|
|
1621 slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride);
|
|
1622 slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride);
|
|
1623 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset,
|
|
1624 DCT_stride);
|
|
1625 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8,
|
|
1626 DCT_stride);
|
1
|
1627
|
36
|
1628 /* Decode chroma blocks */
|
|
1629 slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1);
|
|
1630 slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1);
|
1
|
1631
|
|
1632 if (picture->picture_coding_type == D_TYPE) {
|
|
1633 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1634 DUMPBITS (bit_buf, bits, 1);
|
|
1635 }
|
|
1636 } else {
|
|
1637
|
|
1638 if (picture->mpeg1) {
|
|
1639 if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME)
|
36
|
1640 MOTION (motion_mp1, macroblock_modes);
|
1
|
1641 else {
|
36
|
1642 /* non-intra mb without forward mv in a P picture */
|
|
1643 picture->f_motion.pmv[0][0] = 0;
|
|
1644 picture->f_motion.pmv[0][1] = 0;
|
|
1645 picture->f_motion.pmv[1][0] = 0;
|
|
1646 picture->f_motion.pmv[1][1] = 0;
|
|
1647 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1648 }
|
|
1649 } else if (picture->picture_structure == FRAME_PICTURE)
|
|
1650 switch (macroblock_modes & MOTION_TYPE_MASK) {
|
|
1651 case MC_FRAME:
|
36
|
1652 MOTION (motion_fr_frame, macroblock_modes);
|
1
|
1653 break;
|
|
1654
|
|
1655 case MC_FIELD:
|
36
|
1656 MOTION (motion_fr_field, macroblock_modes);
|
1
|
1657 break;
|
|
1658
|
|
1659 case MC_DMV:
|
36
|
1660 MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
|
1
|
1661 break;
|
|
1662
|
|
1663 case 0:
|
36
|
1664 /* non-intra mb without forward mv in a P picture */
|
|
1665 picture->f_motion.pmv[0][0] = 0;
|
|
1666 picture->f_motion.pmv[0][1] = 0;
|
|
1667 picture->f_motion.pmv[1][0] = 0;
|
|
1668 picture->f_motion.pmv[1][1] = 0;
|
|
1669 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1670 break;
|
|
1671 }
|
|
1672 else
|
|
1673 switch (macroblock_modes & MOTION_TYPE_MASK) {
|
|
1674 case MC_FIELD:
|
36
|
1675 MOTION (motion_fi_field, macroblock_modes);
|
1
|
1676 break;
|
|
1677
|
|
1678 case MC_16X8:
|
36
|
1679 MOTION (motion_fi_16x8, macroblock_modes);
|
1
|
1680 break;
|
|
1681
|
|
1682 case MC_DMV:
|
36
|
1683 MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
|
1
|
1684 break;
|
|
1685
|
|
1686 case 0:
|
36
|
1687 /* non-intra mb without forward mv in a P picture */
|
|
1688 picture->f_motion.pmv[0][0] = 0;
|
|
1689 picture->f_motion.pmv[0][1] = 0;
|
|
1690 picture->f_motion.pmv[1][0] = 0;
|
|
1691 picture->f_motion.pmv[1][1] = 0;
|
|
1692 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1693 break;
|
|
1694 }
|
|
1695
|
36
|
1696 /* 6.3.17.4 Coded block pattern */
|
1
|
1697 if (macroblock_modes & MACROBLOCK_PATTERN) {
|
|
1698 int coded_block_pattern;
|
|
1699 int DCT_offset, DCT_stride;
|
|
1700
|
|
1701 if (macroblock_modes & DCT_TYPE_INTERLACED) {
|
36
|
1702 DCT_offset = stride;
|
|
1703 DCT_stride = stride * 2;
|
1
|
1704 } else {
|
36
|
1705 DCT_offset = stride * 8;
|
|
1706 DCT_stride = stride;
|
1
|
1707 }
|
|
1708
|
36
|
1709 coded_block_pattern = get_coded_block_pattern (picture);
|
1
|
1710
|
36
|
1711 /* Decode lum blocks */
|
1
|
1712
|
|
1713 if (coded_block_pattern & 0x20)
|
36
|
1714 slice_non_intra_DCT (picture, dest[0] + offset,
|
|
1715 DCT_stride);
|
1
|
1716 if (coded_block_pattern & 0x10)
|
36
|
1717 slice_non_intra_DCT (picture, dest[0] + offset + 8,
|
|
1718 DCT_stride);
|
1
|
1719 if (coded_block_pattern & 0x08)
|
36
|
1720 slice_non_intra_DCT (picture,
|
1
|
1721 dest[0] + offset + DCT_offset,
|
|
1722 DCT_stride);
|
|
1723 if (coded_block_pattern & 0x04)
|
36
|
1724 slice_non_intra_DCT (picture,
|
1
|
1725 dest[0] + offset + DCT_offset + 8,
|
|
1726 DCT_stride);
|
|
1727
|
36
|
1728 /* Decode chroma blocks */
|
1
|
1729
|
|
1730 if (coded_block_pattern & 0x2)
|
36
|
1731 slice_non_intra_DCT (picture, dest[1] + (offset >> 1),
|
|
1732 stride >> 1);
|
1
|
1733 if (coded_block_pattern & 0x1)
|
36
|
1734 slice_non_intra_DCT (picture, dest[2] + (offset >> 1),
|
|
1735 stride >> 1);
|
1
|
1736 }
|
|
1737
|
36
|
1738 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1739 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
|
1
|
1740 }
|
|
1741
|
41
|
1742 #ifdef MPEG12_POSTPROC
|
|
1743 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1744 #endif
|
1
|
1745 offset += 16;
|
|
1746 CHECK_DISPLAY;
|
|
1747
|
|
1748 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1749
|
|
1750 if (bit_buf & 0x80000000) {
|
|
1751 DUMPBITS (bit_buf, bits, 1);
|
|
1752 } else {
|
|
1753 int mba_inc;
|
|
1754
|
36
|
1755 mba_inc = get_macroblock_address_increment (picture);
|
1
|
1756 if (!mba_inc)
|
|
1757 break;
|
|
1758
|
36
|
1759 /* reset intra dc predictor on skipped block */
|
|
1760 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1761 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
|
1
|
1762
|
36
|
1763 /* handling of skipped mb's differs between P_TYPE and B_TYPE */
|
|
1764 /* pictures */
|
1
|
1765 if (picture->picture_coding_type == P_TYPE) {
|
36
|
1766 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1767 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
1
|
1768
|
|
1769 do {
|
|
1770 if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1771 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1772 else
|
36
|
1773 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1774
|
41
|
1775 #ifdef MPEG12_POSTPROC
|
|
1776 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1777 #endif
|
|
1778
|
1
|
1779 offset += 16;
|
|
1780 CHECK_DISPLAY;
|
|
1781 } while (--mba_inc);
|
|
1782 } else {
|
|
1783 do {
|
|
1784 if (picture->mpeg1)
|
36
|
1785 MOTION (motion_mp1_reuse, macroblock_modes);
|
1
|
1786 else if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1787 MOTION (motion_fr_reuse, macroblock_modes);
|
1
|
1788 else
|
36
|
1789 MOTION (motion_fi_reuse, macroblock_modes);
|
1
|
1790
|
41
|
1791 #ifdef MPEG12_POSTPROC
|
|
1792 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1793 #endif
|
|
1794
|
1
|
1795 offset += 16;
|
|
1796 CHECK_DISPLAY;
|
|
1797 } while (--mba_inc);
|
|
1798 }
|
|
1799 }
|
|
1800 }
|
|
1801
|
|
1802 return 0;
|
|
1803 #undef bit_buf
|
|
1804 #undef bits
|
|
1805 #undef bit_ptr
|
|
1806 }
|