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 */
|
49
|
978 // printf("MB error: %d \n",(UBITS (bit_buf, 11))); // FIXME!
|
142
|
979 // return 0;
|
|
980 return -1;
|
1
|
981 }
|
|
982 }
|
|
983
|
|
984 #undef bit_buf
|
|
985 #undef bits
|
|
986 #undef bit_ptr
|
|
987 }
|
|
988
|
36
|
989 static inline void slice_intra_DCT (picture_t * picture, int cc,
|
|
990 uint8_t * dest, int stride)
|
1
|
991 {
|
36
|
992 #define bit_buf (picture->bitstream_buf)
|
|
993 #define bits (picture->bitstream_bits)
|
|
994 #define bit_ptr (picture->bitstream_ptr)
|
1
|
995 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
996 /* Get the intra DC coefficient and inverse quantize it */
|
1
|
997 if (cc == 0)
|
36
|
998 picture->dc_dct_pred[0] += get_luma_dc_dct_diff (picture);
|
1
|
999 else
|
36
|
1000 picture->dc_dct_pred[cc] += get_chroma_dc_dct_diff (picture);
|
|
1001 picture->DCTblock[0] =
|
|
1002 picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision);
|
|
1003 memset (picture->DCTblock + 1, 0, 63 * sizeof (int16_t));
|
1
|
1004
|
|
1005 if (picture->mpeg1) {
|
|
1006 if (picture->picture_coding_type != D_TYPE)
|
36
|
1007 get_mpeg1_intra_block (picture);
|
1
|
1008 } else if (picture->intra_vlc_format)
|
36
|
1009 get_intra_block_B15 (picture);
|
1
|
1010 else
|
36
|
1011 get_intra_block_B14 (picture);
|
|
1012 idct_block_copy (picture->DCTblock, dest, stride);
|
1
|
1013 #undef bit_buf
|
|
1014 #undef bits
|
|
1015 #undef bit_ptr
|
|
1016 }
|
|
1017
|
36
|
1018 static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest,
|
|
1019 int stride)
|
1
|
1020 {
|
36
|
1021 memset (picture->DCTblock, 0, 64 * sizeof (int16_t));
|
1
|
1022 if (picture->mpeg1)
|
36
|
1023 get_mpeg1_non_intra_block (picture);
|
1
|
1024 else
|
36
|
1025 get_non_intra_block (picture);
|
|
1026 idct_block_add (picture->DCTblock, dest, stride);
|
1
|
1027 }
|
|
1028
|
49
|
1029 #define MOTION_Y(table,offset_x,offset_y,motion_x,motion_y, \
|
|
1030 dest,src,offset_dest,offset_src,stride,height) \
|
|
1031 do { \
|
|
1032 int xy_half; \
|
|
1033 int total_offset; \
|
|
1034 \
|
|
1035 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
|
|
1036 total_offset = ((offset_y + (motion_y >> 1)) * stride + \
|
|
1037 offset_x + (motion_x >> 1) + (offset_src)); \
|
|
1038 table[xy_half] (dest[0] + offset_x + (offset_dest), \
|
|
1039 src[0] + total_offset, stride, height); \
|
|
1040 } while (0)
|
|
1041
|
|
1042 #define MOTION_UV(table,offset_x,offset_y,motion_x,motion_y, \
|
|
1043 dest,src,offset_dest,offset_src,stride,height) \
|
|
1044 do { \
|
|
1045 int xy_half; \
|
|
1046 int total_offset; \
|
|
1047 \
|
|
1048 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
|
|
1049 total_offset = (((offset_y + motion_y) >> 1) * (stride) + \
|
|
1050 ((offset_x + motion_x) >> 1) + (offset_src)); \
|
|
1051 table[4+xy_half] (dest[1] + (offset_x >> 1) + (offset_dest), \
|
|
1052 src[1] + total_offset, stride, height); \
|
|
1053 table[4+xy_half] (dest[2] + (offset_x >> 1) + (offset_dest), \
|
|
1054 src[2] + total_offset, stride, height); \
|
|
1055 } while (0)
|
|
1056
|
1
|
1057 static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
|
49
|
1058 int32_t, int32_t),
|
|
1059 int x_offset, int y_offset, int mb_y_8_offset,
|
|
1060 int src_field, int dest_field,
|
1
|
1061 int x_pred, int y_pred,
|
49
|
1062 uint8_t * dest[3], uint8_t * src[3],
|
|
1063 int stride, int height)
|
1
|
1064 {
|
49
|
1065 MOTION_Y (table, x_offset, y_offset, x_pred, y_pred, dest, src,
|
|
1066 dest_field + mb_y_8_offset*8*stride, src_field, stride, height);
|
1
|
1067
|
|
1068 x_pred /= 2;
|
|
1069 y_pred /= 2;
|
|
1070 stride >>= 1;
|
|
1071 height >>= 1;
|
|
1072
|
49
|
1073 MOTION_UV (table, x_offset, y_offset, x_pred, y_pred, dest, src,
|
|
1074 (dest_field >> 1) + mb_y_8_offset*4*stride, src_field >> 1,
|
|
1075 stride, height);
|
1
|
1076 }
|
|
1077
|
36
|
1078 static void motion_mp1 (picture_t * picture, motion_t * motion,
|
|
1079 uint8_t * dest[3], int offset, int stride,
|
1
|
1080 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1081 {
|
36
|
1082 #define bit_buf (picture->bitstream_buf)
|
|
1083 #define bits (picture->bitstream_bits)
|
|
1084 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1085 int motion_x, motion_y;
|
|
1086
|
|
1087 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1088 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1089 motion->f_code[0]);
|
1
|
1090 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1091 motion->pmv[0][0] = motion_x;
|
|
1092
|
|
1093 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1094 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1095 motion->f_code[0]);
|
1
|
1096 motion_y = bound_motion_vector (motion_y, motion->f_code[0]);
|
|
1097 motion->pmv[0][1] = motion_y;
|
|
1098
|
|
1099 if (motion->f_code[1]) {
|
|
1100 motion_x <<= 1;
|
|
1101 motion_y <<= 1;
|
|
1102 }
|
|
1103
|
49
|
1104 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1105 motion_x, motion_y, dest, motion->ref[0], stride, 16);
|
1
|
1106 #undef bit_buf
|
|
1107 #undef bits
|
|
1108 #undef bit_ptr
|
|
1109 }
|
|
1110
|
36
|
1111 static void motion_mp1_reuse (picture_t * picture, motion_t * motion,
|
|
1112 uint8_t * dest[3], int offset, int stride,
|
1
|
1113 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1114 {
|
|
1115 int motion_x, motion_y;
|
|
1116
|
|
1117 motion_x = motion->pmv[0][0];
|
|
1118 motion_y = motion->pmv[0][1];
|
|
1119
|
|
1120 if (motion->f_code[1]) {
|
|
1121 motion_x <<= 1;
|
|
1122 motion_y <<= 1;
|
|
1123 }
|
|
1124
|
49
|
1125 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1126 motion_x, motion_y, dest, motion->ref[0], stride, 16);
|
1
|
1127 }
|
|
1128
|
36
|
1129 static void motion_fr_frame (picture_t * picture, motion_t * motion,
|
|
1130 uint8_t * dest[3], int offset, int stride,
|
1
|
1131 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1132 {
|
36
|
1133 #define bit_buf (picture->bitstream_buf)
|
|
1134 #define bits (picture->bitstream_bits)
|
|
1135 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1136 int motion_x, motion_y;
|
|
1137
|
|
1138 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1139 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1140 motion->f_code[0]);
|
1
|
1141 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1142 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1143
|
|
1144 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1145 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1146 motion->f_code[1]);
|
1
|
1147 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1148 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1149
|
49
|
1150 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1151 motion_x, motion_y, dest, motion->ref[0], stride, 16);
|
1
|
1152 #undef bit_buf
|
|
1153 #undef bits
|
|
1154 #undef bit_ptr
|
|
1155 }
|
|
1156
|
36
|
1157 static void motion_fr_field (picture_t * picture, motion_t * motion,
|
|
1158 uint8_t * dest[3], int offset, int stride,
|
1
|
1159 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1160 {
|
36
|
1161 #define bit_buf (picture->bitstream_buf)
|
|
1162 #define bits (picture->bitstream_bits)
|
|
1163 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1164 int motion_x, motion_y;
|
|
1165 int field_select;
|
|
1166
|
|
1167 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1168 field_select = SBITS (bit_buf, 1);
|
|
1169 DUMPBITS (bit_buf, bits, 1);
|
|
1170
|
36
|
1171 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1172 motion->f_code[0]);
|
1
|
1173 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1174 motion->pmv[0][0] = motion_x;
|
|
1175
|
|
1176 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1177 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
|
1
|
1178 motion->f_code[1]);
|
36
|
1179 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1180 motion->pmv[0][1] = motion_y << 1;
|
|
1181
|
49
|
1182 motion_block (table, offset, picture->v_offset >> 1,
|
|
1183 0, (field_select & stride), 0,
|
|
1184 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1185
|
|
1186 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1187 field_select = SBITS (bit_buf, 1);
|
|
1188 DUMPBITS (bit_buf, bits, 1);
|
|
1189
|
36
|
1190 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
|
|
1191 motion->f_code[0]);
|
1
|
1192 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1193 motion->pmv[1][0] = motion_x;
|
|
1194
|
|
1195 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1196 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture,
|
1
|
1197 motion->f_code[1]);
|
36
|
1198 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1199 motion->pmv[1][1] = motion_y << 1;
|
|
1200
|
49
|
1201 motion_block (table, offset, picture->v_offset >> 1,
|
|
1202 0, (field_select & stride), stride,
|
|
1203 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1204 #undef bit_buf
|
|
1205 #undef bits
|
|
1206 #undef bit_ptr
|
|
1207 }
|
|
1208
|
36
|
1209 static void motion_fr_dmv (picture_t * picture, motion_t * motion,
|
|
1210 uint8_t * dest[3], int offset, int stride,
|
1
|
1211 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1212 {
|
36
|
1213 #define bit_buf (picture->bitstream_buf)
|
|
1214 #define bits (picture->bitstream_bits)
|
|
1215 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1216 int motion_x, motion_y;
|
|
1217 int dmv_x, dmv_y;
|
|
1218 int m;
|
|
1219 int other_x, other_y;
|
|
1220
|
|
1221 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1222 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1223 motion->f_code[0]);
|
1
|
1224 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1225 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1226
|
|
1227 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1228 dmv_x = get_dmv (picture);
|
1
|
1229
|
|
1230 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1231 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
|
1
|
1232 motion->f_code[1]);
|
36
|
1233 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
|
1
|
1234 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
|
|
1235
|
|
1236 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1237 dmv_y = get_dmv (picture);
|
1
|
1238
|
49
|
1239 motion_block (mc_functions.put, offset, picture->v_offset >> 1, 0, 0, 0,
|
|
1240 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1241
|
36
|
1242 m = picture->top_field_first ? 1 : 3;
|
1
|
1243 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
|
|
1244 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
|
49
|
1245 motion_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, stride, 0,
|
|
1246 other_x, other_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1247
|
49
|
1248 motion_block (mc_functions.put, offset, picture->v_offset >> 1,
|
|
1249 0, stride, stride,
|
|
1250 motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1251
|
36
|
1252 m = picture->top_field_first ? 3 : 1;
|
1
|
1253 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
|
|
1254 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
|
49
|
1255 motion_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, 0, stride,
|
|
1256 other_x, other_y, dest, motion->ref[0], stride * 2, 8);
|
1
|
1257 #undef bit_buf
|
|
1258 #undef bits
|
|
1259 #undef bit_ptr
|
|
1260 }
|
|
1261
|
36
|
1262 /* like motion_frame, but reuse previous motion vectors */
|
|
1263 static void motion_fr_reuse (picture_t * picture, motion_t * motion,
|
|
1264 uint8_t * dest[3], int offset, int stride,
|
1
|
1265 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1266 {
|
49
|
1267 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1268 motion->pmv[0][0], motion->pmv[0][1],
|
|
1269 dest, motion->ref[0], stride, 16);
|
1
|
1270 }
|
|
1271
|
36
|
1272 /* like motion_frame, but use null motion vectors */
|
|
1273 static void motion_fr_zero (picture_t * picture, motion_t * motion,
|
|
1274 uint8_t * dest[3], int offset, int stride,
|
1
|
1275 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1276 {
|
49
|
1277 motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
|
|
1278 dest, motion->ref[0], stride, 16);
|
1
|
1279 }
|
|
1280
|
36
|
1281 /* like motion_frame, but parsing without actual motion compensation */
|
|
1282 static void motion_fr_conceal (picture_t * picture)
|
1
|
1283 {
|
36
|
1284 #define bit_buf (picture->bitstream_buf)
|
|
1285 #define bits (picture->bitstream_bits)
|
|
1286 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1287 int tmp;
|
|
1288
|
|
1289 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1290 tmp = (picture->f_motion.pmv[0][0] +
|
|
1291 get_motion_delta (picture, picture->f_motion.f_code[0]));
|
|
1292 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
|
|
1293 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
|
1
|
1294
|
|
1295 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1296 tmp = (picture->f_motion.pmv[0][1] +
|
|
1297 get_motion_delta (picture, picture->f_motion.f_code[1]));
|
|
1298 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
|
|
1299 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
|
1
|
1300
|
36
|
1301 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
|
1
|
1302 #undef bit_buf
|
|
1303 #undef bits
|
|
1304 #undef bit_ptr
|
|
1305 }
|
|
1306
|
36
|
1307 static void motion_fi_field (picture_t * picture, motion_t * motion,
|
|
1308 uint8_t * dest[3], int offset, int stride,
|
1
|
1309 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1310 {
|
36
|
1311 #define bit_buf (picture->bitstream_buf)
|
|
1312 #define bits (picture->bitstream_bits)
|
|
1313 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1314 int motion_x, motion_y;
|
|
1315 int field_select;
|
|
1316
|
|
1317 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1318 field_select = UBITS (bit_buf, 1);
|
|
1319 DUMPBITS (bit_buf, bits, 1);
|
|
1320
|
|
1321 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1322 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1323 motion->f_code[0]);
|
1
|
1324 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1325 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1326
|
|
1327 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1328 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1329 motion->f_code[1]);
|
1
|
1330 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1331 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1332
|
49
|
1333 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1334 motion_x, motion_y,
|
|
1335 dest, motion->ref[field_select], stride, 16);
|
1
|
1336 #undef bit_buf
|
|
1337 #undef bits
|
|
1338 #undef bit_ptr
|
|
1339 }
|
|
1340
|
36
|
1341 static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
|
|
1342 uint8_t * dest[3], int offset, int stride,
|
1
|
1343 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1344 {
|
36
|
1345 #define bit_buf (picture->bitstream_buf)
|
|
1346 #define bits (picture->bitstream_bits)
|
|
1347 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1348 int motion_x, motion_y;
|
|
1349 int field_select;
|
|
1350
|
|
1351 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1352 field_select = UBITS (bit_buf, 1);
|
|
1353 DUMPBITS (bit_buf, bits, 1);
|
|
1354
|
|
1355 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1356 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1357 motion->f_code[0]);
|
1
|
1358 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1359 motion->pmv[0][0] = motion_x;
|
|
1360
|
|
1361 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1362 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1363 motion->f_code[1]);
|
1
|
1364 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1365 motion->pmv[0][1] = motion_y;
|
|
1366
|
49
|
1367 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1368 motion_x, motion_y,
|
|
1369 dest, motion->ref[field_select], stride, 8);
|
1
|
1370
|
|
1371 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1372 field_select = UBITS (bit_buf, 1);
|
|
1373 DUMPBITS (bit_buf, bits, 1);
|
|
1374
|
|
1375 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1376 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
|
|
1377 motion->f_code[0]);
|
1
|
1378 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1379 motion->pmv[1][0] = motion_x;
|
|
1380
|
|
1381 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1382 motion_y = motion->pmv[1][1] + get_motion_delta (picture,
|
|
1383 motion->f_code[1]);
|
1
|
1384 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1385 motion->pmv[1][1] = motion_y;
|
|
1386
|
49
|
1387 motion_block (table, offset, picture->v_offset+8, 1, 0, 0,
|
|
1388 motion_x, motion_y,
|
|
1389 dest, motion->ref[field_select], stride, 8);
|
1
|
1390 #undef bit_buf
|
|
1391 #undef bits
|
|
1392 #undef bit_ptr
|
|
1393 }
|
|
1394
|
36
|
1395 static void motion_fi_dmv (picture_t * picture, motion_t * motion,
|
|
1396 uint8_t * dest[3], int offset, int stride,
|
1
|
1397 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1398 {
|
36
|
1399 #define bit_buf (picture->bitstream_buf)
|
|
1400 #define bits (picture->bitstream_bits)
|
|
1401 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1402 int motion_x, motion_y;
|
|
1403 int dmv_x, dmv_y;
|
|
1404
|
|
1405 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1406 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
|
|
1407 motion->f_code[0]);
|
1
|
1408 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
|
|
1409 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
|
|
1410
|
|
1411 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1412 dmv_x = get_dmv (picture);
|
1
|
1413
|
|
1414 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1415 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
|
|
1416 motion->f_code[1]);
|
1
|
1417 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
|
|
1418 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
|
|
1419
|
|
1420 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1421 dmv_y = get_dmv (picture);
|
1
|
1422
|
49
|
1423 motion_block (mc_functions.put, offset, picture->v_offset, 0, 0, 0,
|
|
1424 motion_x, motion_y,
|
|
1425 dest, motion->ref[picture->current_field], stride, 16);
|
1
|
1426
|
|
1427 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
|
|
1428 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
|
36
|
1429 2 * picture->current_field - 1;
|
49
|
1430 motion_block (mc_functions.avg, offset, picture->v_offset, 0, 0, 0,
|
|
1431 motion_x, motion_y,
|
|
1432 dest, motion->ref[!picture->current_field], stride, 16);
|
1
|
1433 #undef bit_buf
|
|
1434 #undef bits
|
|
1435 #undef bit_ptr
|
|
1436 }
|
|
1437
|
36
|
1438 static void motion_fi_reuse (picture_t * picture, motion_t * motion,
|
|
1439 uint8_t * dest[3], int offset, int stride,
|
1
|
1440 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1441 {
|
49
|
1442 motion_block (table, offset, picture->v_offset, 0, 0, 0,
|
|
1443 motion->pmv[0][0], motion->pmv[0][1],
|
|
1444 dest, motion->ref[picture->current_field], stride, 16);
|
1
|
1445 }
|
|
1446
|
36
|
1447 static void motion_fi_zero (picture_t * picture, motion_t * motion,
|
|
1448 uint8_t * dest[3], int offset, int stride,
|
1
|
1449 void (** table) (uint8_t *, uint8_t *, int, int))
|
|
1450 {
|
49
|
1451 motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
|
|
1452 dest, motion->ref[picture->current_field], stride, 16);
|
1
|
1453 }
|
|
1454
|
36
|
1455 static void motion_fi_conceal (picture_t * picture)
|
1
|
1456 {
|
36
|
1457 #define bit_buf (picture->bitstream_buf)
|
|
1458 #define bits (picture->bitstream_bits)
|
|
1459 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1460 int tmp;
|
|
1461
|
|
1462 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1463 DUMPBITS (bit_buf, bits, 1); /* remove field_select */
|
1
|
1464
|
|
1465 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1466 tmp = (picture->f_motion.pmv[0][0] +
|
|
1467 get_motion_delta (picture, picture->f_motion.f_code[0]));
|
|
1468 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
|
|
1469 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
|
1
|
1470
|
|
1471 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1472 tmp = (picture->f_motion.pmv[0][1] +
|
|
1473 get_motion_delta (picture, picture->f_motion.f_code[1]));
|
|
1474 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
|
|
1475 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
|
1
|
1476
|
36
|
1477 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
|
1
|
1478 #undef bit_buf
|
|
1479 #undef bits
|
|
1480 #undef bit_ptr
|
|
1481 }
|
|
1482
|
36
|
1483 #define MOTION(routine,direction) \
|
1
|
1484 do { \
|
|
1485 if ((direction) & MACROBLOCK_MOTION_FORWARD) \
|
36
|
1486 routine (picture, &(picture->f_motion), dest, offset, stride, \
|
1
|
1487 mc_functions.put); \
|
|
1488 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
|
36
|
1489 routine (picture, &(picture->b_motion), dest, offset, stride, \
|
1
|
1490 ((direction) & MACROBLOCK_MOTION_FORWARD ? \
|
|
1491 mc_functions.avg : mc_functions.put)); \
|
|
1492 } while (0)
|
|
1493
|
36
|
1494 #define CHECK_DISPLAY \
|
|
1495 do { \
|
|
1496 if (offset == picture->coded_picture_width) { \
|
|
1497 do { /* just so we can use the break statement */ \
|
|
1498 if (picture->current_frame->copy) { \
|
|
1499 picture->current_frame->copy (picture->current_frame, \
|
|
1500 dest); \
|
|
1501 if (picture->picture_coding_type == B_TYPE) \
|
|
1502 break; \
|
|
1503 } \
|
|
1504 dest[0] += 16 * stride; \
|
|
1505 dest[1] += 4 * stride; \
|
|
1506 dest[2] += 4 * stride; \
|
|
1507 } while (0); \
|
49
|
1508 if (! (picture->mpeg1)) \
|
|
1509 return 0; \
|
|
1510 picture->v_offset += 16; \
|
|
1511 if (picture->v_offset >= picture->coded_picture_height) \
|
|
1512 return 0; \
|
41
|
1513 offset = 0; ++code; \
|
36
|
1514 } \
|
1
|
1515 } while (0)
|
|
1516
|
|
1517 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
|
|
1518 {
|
36
|
1519 #define bit_buf (picture->bitstream_buf)
|
|
1520 #define bits (picture->bitstream_bits)
|
|
1521 #define bit_ptr (picture->bitstream_ptr)
|
1
|
1522 int macroblock_modes;
|
36
|
1523 int stride;
|
1
|
1524 uint8_t * dest[3];
|
|
1525 int offset;
|
|
1526 uint8_t ** forward_ref[2];
|
|
1527
|
36
|
1528 stride = picture->coded_picture_width;
|
|
1529 offset = (code - 1) * stride * 4;
|
49
|
1530 picture->v_offset = (code - 1) * 16;
|
1
|
1531
|
36
|
1532 forward_ref[0] = picture->forward_reference_frame->base;
|
1
|
1533 if (picture->picture_structure != FRAME_PICTURE) {
|
49
|
1534 forward_ref[1] = picture->forward_reference_frame->base;
|
1
|
1535 offset <<= 1;
|
36
|
1536 picture->current_field = (picture->picture_structure == BOTTOM_FIELD);
|
1
|
1537 if ((picture->second_field) &&
|
|
1538 (picture->picture_coding_type != B_TYPE))
|
|
1539 forward_ref[picture->picture_structure == TOP_FIELD] =
|
36
|
1540 picture->current_frame->base;
|
49
|
1541
|
|
1542 picture->f_motion.ref[1][0] = forward_ref[1][0] + stride;
|
|
1543 picture->f_motion.ref[1][1] = forward_ref[1][1] + (stride >> 1);
|
|
1544 picture->f_motion.ref[1][2] = forward_ref[1][2] + (stride >> 1);
|
|
1545
|
|
1546 picture->b_motion.ref[1][0] =
|
|
1547 picture->backward_reference_frame->base[0] + stride;
|
36
|
1548 picture->b_motion.ref[1][1] =
|
49
|
1549 picture->backward_reference_frame->base[1] + (stride >> 1);
|
36
|
1550 picture->b_motion.ref[1][2] =
|
49
|
1551 picture->backward_reference_frame->base[2] + (stride >> 1);
|
1
|
1552 }
|
|
1553
|
49
|
1554 picture->f_motion.ref[0][0] = forward_ref[0][0];
|
|
1555 picture->f_motion.ref[0][1] = forward_ref[0][1];
|
|
1556 picture->f_motion.ref[0][2] = forward_ref[0][2];
|
|
1557
|
36
|
1558 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1559 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
49
|
1560
|
|
1561 picture->b_motion.ref[0][0] = picture->backward_reference_frame->base[0];
|
|
1562 picture->b_motion.ref[0][1] = picture->backward_reference_frame->base[1];
|
|
1563 picture->b_motion.ref[0][2] = picture->backward_reference_frame->base[2];
|
|
1564
|
36
|
1565 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
|
|
1566 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
|
1
|
1567
|
36
|
1568 if ((picture->current_frame->copy) &&
|
1
|
1569 (picture->picture_coding_type == B_TYPE))
|
|
1570 offset = 0;
|
|
1571
|
36
|
1572 dest[0] = picture->current_frame->base[0] + offset * 4;
|
|
1573 dest[1] = picture->current_frame->base[1] + offset;
|
|
1574 dest[2] = picture->current_frame->base[2] + offset;
|
1
|
1575
|
|
1576 switch (picture->picture_structure) {
|
|
1577 case BOTTOM_FIELD:
|
36
|
1578 dest[0] += stride;
|
|
1579 dest[1] += stride >> 1;
|
|
1580 dest[2] += stride >> 1;
|
|
1581 /* follow thru */
|
1
|
1582 case TOP_FIELD:
|
36
|
1583 stride <<= 1;
|
1
|
1584 }
|
|
1585
|
36
|
1586 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1587 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
|
1
|
1588
|
36
|
1589 bitstream_init (picture, buffer);
|
1
|
1590
|
36
|
1591 picture->quantizer_scale = get_quantizer_scale (picture);
|
1
|
1592
|
36
|
1593 /* ignore intra_slice and all the extra data */
|
1
|
1594 while (bit_buf & 0x80000000) {
|
|
1595 DUMPBITS (bit_buf, bits, 9);
|
|
1596 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1597 }
|
|
1598 DUMPBITS (bit_buf, bits, 1);
|
|
1599
|
|
1600 NEEDBITS (bit_buf, bits, bit_ptr);
|
36
|
1601 offset = get_macroblock_address_increment (picture) << 4;
|
1
|
1602
|
|
1603 while (1) {
|
|
1604 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1605
|
36
|
1606 macroblock_modes = get_macroblock_modes (picture);
|
1
|
1607
|
36
|
1608 /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */
|
1
|
1609 if (macroblock_modes & MACROBLOCK_QUANT)
|
36
|
1610 picture->quantizer_scale = get_quantizer_scale (picture);
|
1
|
1611
|
|
1612 if (macroblock_modes & MACROBLOCK_INTRA) {
|
|
1613
|
|
1614 int DCT_offset, DCT_stride;
|
|
1615
|
|
1616 if (picture->concealment_motion_vectors) {
|
|
1617 if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1618 motion_fr_conceal (picture);
|
1
|
1619 else
|
36
|
1620 motion_fi_conceal (picture);
|
1
|
1621 } else {
|
36
|
1622 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1623 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
|
1624 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
|
|
1625 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
|
1
|
1626 }
|
|
1627
|
|
1628 if (macroblock_modes & DCT_TYPE_INTERLACED) {
|
36
|
1629 DCT_offset = stride;
|
|
1630 DCT_stride = stride * 2;
|
1
|
1631 } else {
|
36
|
1632 DCT_offset = stride * 8;
|
|
1633 DCT_stride = stride;
|
1
|
1634 }
|
|
1635
|
36
|
1636 slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride);
|
|
1637 slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride);
|
|
1638 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset,
|
|
1639 DCT_stride);
|
|
1640 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8,
|
|
1641 DCT_stride);
|
1
|
1642
|
36
|
1643 slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1);
|
|
1644 slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1);
|
1
|
1645
|
|
1646 if (picture->picture_coding_type == D_TYPE) {
|
|
1647 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1648 DUMPBITS (bit_buf, bits, 1);
|
|
1649 }
|
|
1650 } else {
|
|
1651
|
|
1652 if (picture->mpeg1) {
|
|
1653 if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME)
|
36
|
1654 MOTION (motion_mp1, macroblock_modes);
|
1
|
1655 else {
|
36
|
1656 /* non-intra mb without forward mv in a P picture */
|
|
1657 picture->f_motion.pmv[0][0] = 0;
|
|
1658 picture->f_motion.pmv[0][1] = 0;
|
|
1659 picture->f_motion.pmv[1][0] = 0;
|
|
1660 picture->f_motion.pmv[1][1] = 0;
|
|
1661 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1662 }
|
|
1663 } else if (picture->picture_structure == FRAME_PICTURE)
|
|
1664 switch (macroblock_modes & MOTION_TYPE_MASK) {
|
|
1665 case MC_FRAME:
|
36
|
1666 MOTION (motion_fr_frame, macroblock_modes);
|
1
|
1667 break;
|
|
1668
|
|
1669 case MC_FIELD:
|
36
|
1670 MOTION (motion_fr_field, macroblock_modes);
|
1
|
1671 break;
|
|
1672
|
|
1673 case MC_DMV:
|
36
|
1674 MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
|
1
|
1675 break;
|
|
1676
|
|
1677 case 0:
|
36
|
1678 /* non-intra mb without forward mv in a P picture */
|
|
1679 picture->f_motion.pmv[0][0] = 0;
|
|
1680 picture->f_motion.pmv[0][1] = 0;
|
|
1681 picture->f_motion.pmv[1][0] = 0;
|
|
1682 picture->f_motion.pmv[1][1] = 0;
|
|
1683 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1684 break;
|
|
1685 }
|
|
1686 else
|
|
1687 switch (macroblock_modes & MOTION_TYPE_MASK) {
|
|
1688 case MC_FIELD:
|
36
|
1689 MOTION (motion_fi_field, macroblock_modes);
|
1
|
1690 break;
|
|
1691
|
|
1692 case MC_16X8:
|
36
|
1693 MOTION (motion_fi_16x8, macroblock_modes);
|
1
|
1694 break;
|
|
1695
|
|
1696 case MC_DMV:
|
36
|
1697 MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
|
1
|
1698 break;
|
|
1699
|
|
1700 case 0:
|
36
|
1701 /* non-intra mb without forward mv in a P picture */
|
|
1702 picture->f_motion.pmv[0][0] = 0;
|
|
1703 picture->f_motion.pmv[0][1] = 0;
|
|
1704 picture->f_motion.pmv[1][0] = 0;
|
|
1705 picture->f_motion.pmv[1][1] = 0;
|
|
1706 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1707 break;
|
|
1708 }
|
|
1709
|
|
1710 if (macroblock_modes & MACROBLOCK_PATTERN) {
|
|
1711 int coded_block_pattern;
|
|
1712 int DCT_offset, DCT_stride;
|
|
1713
|
|
1714 if (macroblock_modes & DCT_TYPE_INTERLACED) {
|
36
|
1715 DCT_offset = stride;
|
|
1716 DCT_stride = stride * 2;
|
1
|
1717 } else {
|
36
|
1718 DCT_offset = stride * 8;
|
|
1719 DCT_stride = stride;
|
1
|
1720 }
|
|
1721
|
36
|
1722 coded_block_pattern = get_coded_block_pattern (picture);
|
1
|
1723
|
|
1724 if (coded_block_pattern & 0x20)
|
36
|
1725 slice_non_intra_DCT (picture, dest[0] + offset,
|
|
1726 DCT_stride);
|
1
|
1727 if (coded_block_pattern & 0x10)
|
36
|
1728 slice_non_intra_DCT (picture, dest[0] + offset + 8,
|
|
1729 DCT_stride);
|
1
|
1730 if (coded_block_pattern & 0x08)
|
36
|
1731 slice_non_intra_DCT (picture,
|
1
|
1732 dest[0] + offset + DCT_offset,
|
|
1733 DCT_stride);
|
|
1734 if (coded_block_pattern & 0x04)
|
36
|
1735 slice_non_intra_DCT (picture,
|
1
|
1736 dest[0] + offset + DCT_offset + 8,
|
|
1737 DCT_stride);
|
|
1738
|
|
1739 if (coded_block_pattern & 0x2)
|
36
|
1740 slice_non_intra_DCT (picture, dest[1] + (offset >> 1),
|
|
1741 stride >> 1);
|
1
|
1742 if (coded_block_pattern & 0x1)
|
36
|
1743 slice_non_intra_DCT (picture, dest[2] + (offset >> 1),
|
|
1744 stride >> 1);
|
1
|
1745 }
|
|
1746
|
36
|
1747 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1748 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
|
1
|
1749 }
|
|
1750
|
41
|
1751 #ifdef MPEG12_POSTPROC
|
|
1752 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1753 #endif
|
1
|
1754 offset += 16;
|
|
1755 CHECK_DISPLAY;
|
|
1756
|
|
1757 NEEDBITS (bit_buf, bits, bit_ptr);
|
|
1758
|
142
|
1759 if (0 /* FIXME */ && (bit_buf & 0x80000000)) {
|
1
|
1760 DUMPBITS (bit_buf, bits, 1);
|
|
1761 } else {
|
|
1762 int mba_inc;
|
|
1763
|
36
|
1764 mba_inc = get_macroblock_address_increment (picture);
|
1
|
1765 if (!mba_inc)
|
142
|
1766 continue;
|
|
1767 else if (mba_inc < 0)
|
1
|
1768 break;
|
|
1769
|
36
|
1770 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
|
|
1771 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
|
1
|
1772
|
|
1773 if (picture->picture_coding_type == P_TYPE) {
|
36
|
1774 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
|
|
1775 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
|
1
|
1776
|
|
1777 do {
|
|
1778 if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1779 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1780 else
|
36
|
1781 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
|
1
|
1782
|
41
|
1783 #ifdef MPEG12_POSTPROC
|
|
1784 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1785 #endif
|
|
1786
|
1
|
1787 offset += 16;
|
|
1788 CHECK_DISPLAY;
|
|
1789 } while (--mba_inc);
|
|
1790 } else {
|
|
1791 do {
|
|
1792 if (picture->mpeg1)
|
36
|
1793 MOTION (motion_mp1_reuse, macroblock_modes);
|
1
|
1794 else if (picture->picture_structure == FRAME_PICTURE)
|
36
|
1795 MOTION (motion_fr_reuse, macroblock_modes);
|
1
|
1796 else
|
36
|
1797 MOTION (motion_fi_reuse, macroblock_modes);
|
1
|
1798
|
41
|
1799 #ifdef MPEG12_POSTPROC
|
|
1800 quant_store[code][(offset>>4)+1] = picture->quantizer_scale;
|
|
1801 #endif
|
|
1802
|
1
|
1803 offset += 16;
|
|
1804 CHECK_DISPLAY;
|
|
1805 } while (--mba_inc);
|
|
1806 }
|
|
1807 }
|
|
1808 }
|
|
1809
|
|
1810 return 0;
|
|
1811 #undef bit_buf
|
|
1812 #undef bits
|
|
1813 #undef bit_ptr
|
|
1814 }
|