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