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