3 * Copyright (C) 2003 the ffmpeg project
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * VP3 Video Decoder by Mike Melanson (melanson@pcisys.net)
25 * On2 VP3 Video Decoder
36 #include "mpegvideo.h"
42 #define FRAGMENT_PIXELS 8
47 * Define one or more of the following compile-time variables to 1 to obtain
48 * elaborate information about certain aspects of the decoding process.
50 * DEBUG_VP3: high-level decoding flow
51 * DEBUG_INIT: initialization parameters
52 * DEBUG_DEQUANTIZERS: display how the dequanization tables are built
53 * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding
54 * DEBUG_MODES: unpacking the coding modes for individual fragments
55 * DEBUG_VECTORS: display the motion vectors
56 * DEBUG_TOKEN: display exhaustive information about each DCT token
57 * DEBUG_VLC: display the VLCs as they are extracted from the stream
58 * DEBUG_DC_PRED: display the process of reversing DC prediction
59 * DEBUG_IDCT: show every detail of the IDCT process
64 #define DEBUG_DEQUANTIZERS 0
65 #define DEBUG_BLOCK_CODING 0
67 #define DEBUG_VECTORS 0
70 #define DEBUG_DC_PRED 0
74 #define debug_vp3 printf
76 static inline void debug_vp3(const char *format
, ...) { }
80 #define debug_init printf
82 static inline void debug_init(const char *format
, ...) { }
85 #if DEBUG_DEQUANTIZERS
86 #define debug_dequantizers printf
88 static inline void debug_dequantizers(const char *format
, ...) { }
91 #if DEBUG_BLOCK_CODING
92 #define debug_block_coding printf
94 static inline void debug_block_coding(const char *format
, ...) { }
98 #define debug_modes printf
100 static inline void debug_modes(const char *format
, ...) { }
104 #define debug_vectors printf
106 static inline void debug_vectors(const char *format
, ...) { }
110 #define debug_token printf
112 static inline void debug_token(const char *format
, ...) { }
116 #define debug_vlc printf
118 static inline void debug_vlc(const char *format
, ...) { }
122 #define debug_dc_pred printf
124 static inline void debug_dc_pred(const char *format
, ...) { }
128 #define debug_idct printf
130 static inline void debug_idct(const char *format
, ...) { }
133 typedef struct Vp3Fragment
{
140 /* address of first pixel taking into account which plane the fragment
141 * lives on as well as the plane stride */
143 /* this is the macroblock that the fragment belongs to */
147 #define SB_NOT_CODED 0
148 #define SB_PARTIALLY_CODED 1
149 #define SB_FULLY_CODED 2
151 #define MODE_INTER_NO_MV 0
153 #define MODE_INTER_PLUS_MV 2
154 #define MODE_INTER_LAST_MV 3
155 #define MODE_INTER_PRIOR_LAST 4
156 #define MODE_USING_GOLDEN 5
157 #define MODE_GOLDEN_MV 6
158 #define MODE_INTER_FOURMV 7
159 #define CODING_MODE_COUNT 8
161 /* special internal mode */
164 /* There are 6 preset schemes, plus a free-form scheme */
165 static int ModeAlphabet
[7][CODING_MODE_COUNT
] =
167 /* this is the custom scheme */
168 { 0, 0, 0, 0, 0, 0, 0, 0 },
170 /* scheme 1: Last motion vector dominates */
171 { MODE_INTER_LAST_MV
, MODE_INTER_PRIOR_LAST
,
172 MODE_INTER_PLUS_MV
, MODE_INTER_NO_MV
,
173 MODE_INTRA
, MODE_USING_GOLDEN
,
174 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
177 { MODE_INTER_LAST_MV
, MODE_INTER_PRIOR_LAST
,
178 MODE_INTER_NO_MV
, MODE_INTER_PLUS_MV
,
179 MODE_INTRA
, MODE_USING_GOLDEN
,
180 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
183 { MODE_INTER_LAST_MV
, MODE_INTER_PLUS_MV
,
184 MODE_INTER_PRIOR_LAST
, MODE_INTER_NO_MV
,
185 MODE_INTRA
, MODE_USING_GOLDEN
,
186 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
189 { MODE_INTER_LAST_MV
, MODE_INTER_PLUS_MV
,
190 MODE_INTER_NO_MV
, MODE_INTER_PRIOR_LAST
,
191 MODE_INTRA
, MODE_USING_GOLDEN
,
192 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
194 /* scheme 5: No motion vector dominates */
195 { MODE_INTER_NO_MV
, MODE_INTER_LAST_MV
,
196 MODE_INTER_PRIOR_LAST
, MODE_INTER_PLUS_MV
,
197 MODE_INTRA
, MODE_USING_GOLDEN
,
198 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
201 { MODE_INTER_NO_MV
, MODE_USING_GOLDEN
,
202 MODE_INTER_LAST_MV
, MODE_INTER_PRIOR_LAST
,
203 MODE_INTER_PLUS_MV
, MODE_INTRA
,
204 MODE_GOLDEN_MV
, MODE_INTER_FOURMV
},
208 #define MIN_DEQUANT_VAL 2
210 typedef struct Vp3DecodeContext
{
211 AVCodecContext
*avctx
;
213 unsigned char *current_picture
[3]; /* picture structure */
215 AVFrame golden_frame
;
217 AVFrame current_frame
;
222 int last_quality_index
;
224 int superblock_count
;
225 int superblock_width
;
226 int superblock_height
;
227 int u_superblock_start
;
228 int v_superblock_start
;
229 unsigned char *superblock_coding
;
231 int macroblock_count
;
232 int macroblock_width
;
233 int macroblock_height
;
239 Vp3Fragment
*all_fragments
;
240 int u_fragment_start
;
241 int v_fragment_start
;
243 /* this is a list of indices into the all_fragments array indicating
244 * which of the fragments are coded */
245 int *coded_fragment_list
;
246 int coded_fragment_list_index
;
247 int pixel_addresses_inited
;
255 int16_t intra_y_dequant
[64];
256 int16_t intra_c_dequant
[64];
257 int16_t inter_dequant
[64];
259 /* This table contains superblock_count * 16 entries. Each set of 16
260 * numbers corresponds to the fragment indices 0..15 of the superblock.
261 * An entry will be -1 to indicate that no entry corresponds to that
263 int *superblock_fragments
;
265 /* This table contains superblock_count * 4 entries. Each set of 4
266 * numbers corresponds to the macroblock indices 0..3 of the superblock.
267 * An entry will be -1 to indicate that no entry corresponds to that
269 int *superblock_macroblocks
;
271 /* This table contains macroblock_count * 6 entries. Each set of 6
272 * numbers corresponds to the fragment indices 0..5 which comprise
273 * the macroblock (4 Y fragments and 2 C fragments). */
274 int *macroblock_fragments
;
275 /* This is an array of flags indicating whether a particular
276 * macroblock is coded. */
277 unsigned char *macroblock_coded
;
281 /************************************************************************
282 * VP3 specific functions
283 ************************************************************************/
286 * This function sets up all of the various blocks mappings:
287 * superblocks <-> fragments, macroblocks <-> fragments,
288 * superblocks <-> macroblocks
290 static void init_block_mapping(Vp3DecodeContext
*s
)
293 signed int hilbert_walk_y
[16];
294 signed int hilbert_walk_c
[16];
295 signed int hilbert_walk_mb
[4];
297 int current_fragment
= 0;
298 int current_width
= 0;
299 int current_height
= 0;
302 int superblock_row_inc
= 0;
304 int mapping_index
= 0;
306 int current_macroblock
;
309 signed char travel_width
[16] = {
316 signed char travel_height
[16] = {
323 signed char travel_width_mb
[4] = {
327 signed char travel_height_mb
[4] = {
331 debug_vp3(" vp3: initialize block mapping tables\n");
333 /* figure out hilbert pattern per these frame dimensions */
334 hilbert_walk_y
[0] = 1;
335 hilbert_walk_y
[1] = 1;
336 hilbert_walk_y
[2] = s
->fragment_width
;
337 hilbert_walk_y
[3] = -1;
338 hilbert_walk_y
[4] = s
->fragment_width
;
339 hilbert_walk_y
[5] = s
->fragment_width
;
340 hilbert_walk_y
[6] = 1;
341 hilbert_walk_y
[7] = -s
->fragment_width
;
342 hilbert_walk_y
[8] = 1;
343 hilbert_walk_y
[9] = s
->fragment_width
;
344 hilbert_walk_y
[10] = 1;
345 hilbert_walk_y
[11] = -s
->fragment_width
;
346 hilbert_walk_y
[12] = -s
->fragment_width
;
347 hilbert_walk_y
[13] = -1;
348 hilbert_walk_y
[14] = -s
->fragment_width
;
349 hilbert_walk_y
[15] = 1;
351 hilbert_walk_c
[0] = 1;
352 hilbert_walk_c
[1] = 1;
353 hilbert_walk_c
[2] = s
->fragment_width
/ 2;
354 hilbert_walk_c
[3] = -1;
355 hilbert_walk_c
[4] = s
->fragment_width
/ 2;
356 hilbert_walk_c
[5] = s
->fragment_width
/ 2;
357 hilbert_walk_c
[6] = 1;
358 hilbert_walk_c
[7] = -s
->fragment_width
/ 2;
359 hilbert_walk_c
[8] = 1;
360 hilbert_walk_c
[9] = s
->fragment_width
/ 2;
361 hilbert_walk_c
[10] = 1;
362 hilbert_walk_c
[11] = -s
->fragment_width
/ 2;
363 hilbert_walk_c
[12] = -s
->fragment_width
/ 2;
364 hilbert_walk_c
[13] = -1;
365 hilbert_walk_c
[14] = -s
->fragment_width
/ 2;
366 hilbert_walk_c
[15] = 1;
368 hilbert_walk_mb
[0] = 1;
369 hilbert_walk_mb
[1] = s
->macroblock_width
;
370 hilbert_walk_mb
[2] = 1;
371 hilbert_walk_mb
[3] = -s
->macroblock_width
;
373 /* iterate through each superblock (all planes) and map the fragments */
374 for (i
= 0; i
< s
->superblock_count
; i
++) {
375 debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n",
376 i
, s
->u_superblock_start
, s
->v_superblock_start
);
378 /* time to re-assign the limits? */
381 /* start of Y superblocks */
382 right_edge
= s
->fragment_width
;
383 bottom_edge
= s
->fragment_height
;
386 superblock_row_inc
= 3 * s
->fragment_width
;
387 hilbert
= hilbert_walk_y
;
389 /* the first operation for this variable is to advance by 1 */
390 current_fragment
= -1;
392 } else if (i
== s
->u_superblock_start
) {
394 /* start of U superblocks */
395 right_edge
= s
->fragment_width
/ 2;
396 bottom_edge
= s
->fragment_height
/ 2;
399 superblock_row_inc
= 3 * (s
->fragment_width
/ 2);
400 hilbert
= hilbert_walk_c
;
402 /* the first operation for this variable is to advance by 1 */
403 current_fragment
= s
->u_fragment_start
- 1;
405 } else if (i
== s
->v_superblock_start
) {
407 /* start of V superblocks */
408 right_edge
= s
->fragment_width
/ 2;
409 bottom_edge
= s
->fragment_height
/ 2;
412 superblock_row_inc
= 3 * (s
->fragment_width
/ 2);
413 hilbert
= hilbert_walk_c
;
415 /* the first operation for this variable is to advance by 1 */
416 current_fragment
= s
->v_fragment_start
- 1;
420 if (current_width
>= right_edge
) {
421 /* reset width and move to next superblock row */
425 /* fragment is now at the start of a new superblock row */
426 current_fragment
+= superblock_row_inc
;
429 /* iterate through all 16 fragments in a superblock */
430 for (j
= 0; j
< 16; j
++) {
431 current_fragment
+= hilbert
[j
];
432 current_height
+= travel_height
[j
];
434 /* check if the fragment is in bounds */
435 if ((current_width
<= right_edge
) &&
436 (current_height
< bottom_edge
)) {
437 s
->superblock_fragments
[mapping_index
] = current_fragment
;
438 debug_init(" mapping fragment %d to superblock %d, position %d\n",
439 s
->superblock_fragments
[mapping_index
], i
, j
);
441 s
->superblock_fragments
[mapping_index
] = -1;
442 debug_init(" superblock %d, position %d has no fragment\n",
446 current_width
+= travel_width
[j
];
451 /* initialize the superblock <-> macroblock mapping; iterate through
452 * all of the Y plane superblocks to build this mapping */
453 right_edge
= s
->macroblock_width
;
454 bottom_edge
= s
->macroblock_height
;
457 superblock_row_inc
= s
->macroblock_width
;
458 hilbert
= hilbert_walk_mb
;
460 current_macroblock
= -1;
461 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
463 if (current_width
>= right_edge
) {
464 /* reset width and move to next superblock row */
468 /* macroblock is now at the start of a new superblock row */
469 current_macroblock
+= superblock_row_inc
;
472 /* iterate through each potential macroblock in the superblock */
473 for (j
= 0; j
< 4; j
++) {
474 current_macroblock
+= hilbert_walk_mb
[j
];
475 current_height
+= travel_height_mb
[j
];
477 /* check if the macroblock is in bounds */
478 if ((current_width
<= right_edge
) &&
479 (current_height
< bottom_edge
)) {
480 s
->superblock_macroblocks
[mapping_index
] = current_macroblock
;
481 debug_init(" mapping macroblock %d to superblock %d, position %d\n",
482 s
->superblock_macroblocks
[mapping_index
], i
, j
);
484 s
->superblock_macroblocks
[mapping_index
] = -1;
485 debug_init(" superblock %d, position %d has no macroblock\n",
489 current_width
+= travel_width_mb
[j
];
494 /* initialize the macroblock <-> fragment mapping */
495 current_fragment
= 0;
496 current_macroblock
= 0;
498 for (i
= 0; i
< s
->fragment_height
; i
+= 2) {
500 for (j
= 0; j
< s
->fragment_width
; j
+= 2) {
502 debug_init(" macroblock %d contains fragments: ", current_macroblock
);
503 s
->all_fragments
[current_fragment
].macroblock
= current_macroblock
;
504 s
->macroblock_fragments
[mapping_index
++] = current_fragment
;
505 debug_init("%d ", current_fragment
);
507 if (j
+ 1 < s
->fragment_width
) {
508 s
->all_fragments
[current_fragment
+ 1].macroblock
= current_macroblock
;
509 s
->macroblock_fragments
[mapping_index
++] = current_fragment
+ 1;
510 debug_init("%d ", current_fragment
+ 1);
512 s
->macroblock_fragments
[mapping_index
++] = -1;
514 if (i
+ 1 < s
->fragment_height
) {
515 s
->all_fragments
[current_fragment
+ s
->fragment_width
].macroblock
=
517 s
->macroblock_fragments
[mapping_index
++] =
518 current_fragment
+ s
->fragment_width
;
519 debug_init("%d ", current_fragment
+ s
->fragment_width
);
521 s
->macroblock_fragments
[mapping_index
++] = -1;
523 if ((j
+ 1 < s
->fragment_width
) && (i
+ 1 < s
->fragment_height
)) {
524 s
->all_fragments
[current_fragment
+ s
->fragment_width
+ 1].macroblock
=
526 s
->macroblock_fragments
[mapping_index
++] =
527 current_fragment
+ s
->fragment_width
+ 1;
528 debug_init("%d ", current_fragment
+ s
->fragment_width
+ 1);
530 s
->macroblock_fragments
[mapping_index
++] = -1;
533 c_fragment
= s
->u_fragment_start
+
534 (i
* s
->fragment_width
/ 4) + (j
/ 2);
535 s
->all_fragments
[c_fragment
].macroblock
= s
->macroblock_count
;
536 s
->macroblock_fragments
[mapping_index
++] = c_fragment
;
537 debug_init("%d ", c_fragment
);
539 c_fragment
= s
->v_fragment_start
+
540 (i
* s
->fragment_width
/ 4) + (j
/ 2);
541 s
->all_fragments
[c_fragment
].macroblock
= s
->macroblock_count
;
542 s
->macroblock_fragments
[mapping_index
++] = c_fragment
;
543 debug_init("%d ", c_fragment
);
547 if (j
+ 2 <= s
->fragment_width
)
548 current_fragment
+= 2;
551 current_macroblock
++;
554 current_fragment
+= s
->fragment_width
;
559 * This function unpacks a single token (which should be in the range 0..31)
560 * and returns a zero run (number of zero coefficients in current DCT matrix
561 * before next non-zero coefficient), the next DCT coefficient, and the
562 * number of consecutive, non-EOB'd DCT blocks to EOB.
564 static void unpack_token(GetBitContext
*gb
, int token
, int *zero_run
,
565 DCTELEM
*coeff
, int *eob_run
)
573 debug_token(" vp3 token %d: ", token
);
577 debug_token("DCT_EOB_TOKEN, EOB next block\n");
582 debug_token("DCT_EOB_PAIR_TOKEN, EOB next 2 blocks\n");
587 debug_token("DCT_EOB_TRIPLE_TOKEN, EOB next 3 blocks\n");
592 debug_token("DCT_REPEAT_RUN_TOKEN, ");
593 *eob_run
= get_bits(gb
, 2) + 4;
594 debug_token("EOB the next %d blocks\n", *eob_run
);
598 debug_token("DCT_REPEAT_RUN2_TOKEN, ");
599 *eob_run
= get_bits(gb
, 3) + 8;
600 debug_token("EOB the next %d blocks\n", *eob_run
);
604 debug_token("DCT_REPEAT_RUN3_TOKEN, ");
605 *eob_run
= get_bits(gb
, 4) + 16;
606 debug_token("EOB the next %d blocks\n", *eob_run
);
610 debug_token("DCT_REPEAT_RUN4_TOKEN, ");
611 *eob_run
= get_bits(gb
, 12);
612 debug_token("EOB the next %d blocks\n", *eob_run
);
616 debug_token("DCT_SHORT_ZRL_TOKEN, ");
617 /* note that this token actually indicates that (3 extra bits) + 1 0s
618 * should be output; this case specifies a run of (3 EBs) 0s and a
619 * coefficient of 0. */
620 *zero_run
= get_bits(gb
, 3);
622 debug_token("skip the next %d positions in output matrix\n", *zero_run
+ 1);
626 debug_token("DCT_ZRL_TOKEN, ");
627 /* note that this token actually indicates that (6 extra bits) + 1 0s
628 * should be output; this case specifies a run of (6 EBs) 0s and a
629 * coefficient of 0. */
630 *zero_run
= get_bits(gb
, 6);
632 debug_token("skip the next %d positions in output matrix\n", *zero_run
+ 1);
636 debug_token("ONE_TOKEN, output 1\n");
641 debug_token("MINUS_ONE_TOKEN, output -1\n");
646 debug_token("TWO_TOKEN, output 2\n");
651 debug_token("MINUS_TWO_TOKEN, output -2\n");
659 debug_token("LOW_VAL_TOKENS, ");
661 *coeff
= -(3 + (token
- 13));
663 *coeff
= 3 + (token
- 13);
664 debug_token("output %d\n", *coeff
);
668 debug_token("DCT_VAL_CATEGORY3, ");
669 sign
= get_bits(gb
, 1);
670 *coeff
= 7 + get_bits(gb
, 1);
673 debug_token("output %d\n", *coeff
);
677 debug_token("DCT_VAL_CATEGORY4, ");
678 sign
= get_bits(gb
, 1);
679 *coeff
= 9 + get_bits(gb
, 2);
682 debug_token("output %d\n", *coeff
);
686 debug_token("DCT_VAL_CATEGORY5, ");
687 sign
= get_bits(gb
, 1);
688 *coeff
= 13 + get_bits(gb
, 3);
691 debug_token("output %d\n", *coeff
);
695 debug_token("DCT_VAL_CATEGORY6, ");
696 sign
= get_bits(gb
, 1);
697 *coeff
= 21 + get_bits(gb
, 4);
700 debug_token("output %d\n", *coeff
);
704 debug_token("DCT_VAL_CATEGORY7, ");
705 sign
= get_bits(gb
, 1);
706 *coeff
= 37 + get_bits(gb
, 5);
709 debug_token("output %d\n", *coeff
);
713 debug_token("DCT_VAL_CATEGORY8, ");
714 sign
= get_bits(gb
, 1);
715 *coeff
= 69 + get_bits(gb
, 9);
718 debug_token("output %d\n", *coeff
);
726 debug_token("DCT_RUN_CATEGORY1, ");
727 *zero_run
= token
- 22;
732 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
736 debug_token("DCT_RUN_CATEGORY1B, ");
741 *zero_run
= 6 + get_bits(gb
, 2);
742 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
746 debug_token("DCT_RUN_CATEGORY1C, ");
751 *zero_run
= 10 + get_bits(gb
, 3);
752 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
756 debug_token("DCT_RUN_CATEGORY2, ");
757 sign
= get_bits(gb
, 1);
758 *coeff
= 2 + get_bits(gb
, 1);
762 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
766 debug_token("DCT_RUN_CATEGORY2, ");
767 sign
= get_bits(gb
, 1);
768 *coeff
= 2 + get_bits(gb
, 1);
771 *zero_run
= 2 + get_bits(gb
, 1);
772 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
776 printf (" vp3: help! Got a bad token: %d > 31\n", token
);
783 * This function wipes out all of the fragment data.
785 static void init_frame(Vp3DecodeContext
*s
, GetBitContext
*gb
)
789 /* zero out all of the fragment information */
790 s
->coded_fragment_list_index
= 0;
791 for (i
= 0; i
< s
->fragment_count
; i
++) {
792 memset(s
->all_fragments
[i
].coeffs
, 0, 64 * sizeof(DCTELEM
));
793 s
->all_fragments
[i
].coeff_count
= 0;
794 s
->all_fragments
[i
].last_coeff
= 0;
799 * This function sets of the dequantization tables used for a particular
802 static void init_dequantizer(Vp3DecodeContext
*s
)
805 int quality_scale
= vp31_quality_threshold
[s
->quality_index
];
806 int dc_scale_factor
= vp31_dc_scale_factor
[s
->quality_index
];
809 debug_vp3(" vp3: initializing dequantization tables\n");
812 * Scale dequantizers:
818 * where sf = dc_scale_factor for DC quantizer
819 * or quality_scale for AC quantizer
821 * Then, saturate the result to a lower limit of MIN_DEQUANT_VAL.
825 /* scale DC quantizers */
826 s
->intra_y_dequant
[0] = vp31_intra_y_dequant
[0] * dc_scale_factor
/ 100;
827 if (s
->intra_y_dequant
[0] < MIN_DEQUANT_VAL
* 2)
828 s
->intra_y_dequant
[0] = MIN_DEQUANT_VAL
* 2;
829 s
->intra_y_dequant
[0] *= SCALER
;
831 s
->intra_c_dequant
[0] = vp31_intra_c_dequant
[0] * dc_scale_factor
/ 100;
832 if (s
->intra_c_dequant
[0] < MIN_DEQUANT_VAL
* 2)
833 s
->intra_c_dequant
[0] = MIN_DEQUANT_VAL
* 2;
834 s
->intra_c_dequant
[0] *= SCALER
;
836 s
->inter_dequant
[0] = vp31_inter_dequant
[0] * dc_scale_factor
/ 100;
837 if (s
->inter_dequant
[0] < MIN_DEQUANT_VAL
* 4)
838 s
->inter_dequant
[0] = MIN_DEQUANT_VAL
* 4;
839 s
->inter_dequant
[0] *= SCALER
;
841 /* scale AC quantizers, zigzag at the same time in preparation for
842 * the dequantization phase */
843 for (i
= 1; i
< 64; i
++) {
847 s
->intra_y_dequant
[j
] = vp31_intra_y_dequant
[i
] * quality_scale
/ 100;
848 if (s
->intra_y_dequant
[j
] < MIN_DEQUANT_VAL
)
849 s
->intra_y_dequant
[j
] = MIN_DEQUANT_VAL
;
850 s
->intra_y_dequant
[j
] *= SCALER
;
852 s
->intra_c_dequant
[j
] = vp31_intra_c_dequant
[i
] * quality_scale
/ 100;
853 if (s
->intra_c_dequant
[j
] < MIN_DEQUANT_VAL
)
854 s
->intra_c_dequant
[j
] = MIN_DEQUANT_VAL
;
855 s
->intra_c_dequant
[j
] *= SCALER
;
857 s
->inter_dequant
[j
] = vp31_inter_dequant
[i
] * quality_scale
/ 100;
858 if (s
->inter_dequant
[j
] < MIN_DEQUANT_VAL
* 2)
859 s
->inter_dequant
[j
] = MIN_DEQUANT_VAL
* 2;
860 s
->inter_dequant
[j
] *= SCALER
;
863 /* print debug information as requested */
864 debug_dequantizers("intra Y dequantizers:\n");
865 for (i
= 0; i
< 8; i
++) {
866 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
867 debug_dequantizers(" %4d,", s
->intra_y_dequant
[j
]);
869 debug_dequantizers("\n");
871 debug_dequantizers("\n");
873 debug_dequantizers("intra C dequantizers:\n");
874 for (i
= 0; i
< 8; i
++) {
875 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
876 debug_dequantizers(" %4d,", s
->intra_c_dequant
[j
]);
878 debug_dequantizers("\n");
880 debug_dequantizers("\n");
882 debug_dequantizers("interframe dequantizers:\n");
883 for (i
= 0; i
< 8; i
++) {
884 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
885 debug_dequantizers(" %4d,", s
->inter_dequant
[j
]);
887 debug_dequantizers("\n");
889 debug_dequantizers("\n");
893 * This function is used to fetch runs of 1s or 0s from the bitstream for
894 * use in determining which superblocks are fully and partially coded.
903 * 111111xxxxxxxxxxxx 34-4129
905 static int get_superblock_run_length(GetBitContext
*gb
)
908 if (get_bits(gb
, 1) == 0)
911 else if (get_bits(gb
, 1) == 0)
912 return (2 + get_bits(gb
, 1));
914 else if (get_bits(gb
, 1) == 0)
915 return (4 + get_bits(gb
, 1));
917 else if (get_bits(gb
, 1) == 0)
918 return (6 + get_bits(gb
, 2));
920 else if (get_bits(gb
, 1) == 0)
921 return (10 + get_bits(gb
, 3));
923 else if (get_bits(gb
, 1) == 0)
924 return (18 + get_bits(gb
, 4));
927 return (34 + get_bits(gb
, 12));
932 * This function is used to fetch runs of 1s or 0s from the bitstream for
933 * use in determining which particular fragments are coded.
943 static int get_fragment_run_length(GetBitContext
*gb
)
946 if (get_bits(gb
, 1) == 0)
947 return (1 + get_bits(gb
, 1));
949 else if (get_bits(gb
, 1) == 0)
950 return (3 + get_bits(gb
, 1));
952 else if (get_bits(gb
, 1) == 0)
953 return (5 + get_bits(gb
, 1));
955 else if (get_bits(gb
, 1) == 0)
956 return (7 + get_bits(gb
, 2));
958 else if (get_bits(gb
, 1) == 0)
959 return (11 + get_bits(gb
, 2));
962 return (15 + get_bits(gb
, 4));
967 * This function decodes a VLC from the bitstream and returns a number
968 * that ranges from 0..7. The number indicates which of the 8 coding
982 static int get_mode_code(GetBitContext
*gb
)
985 if (get_bits(gb
, 1) == 0)
988 else if (get_bits(gb
, 1) == 0)
991 else if (get_bits(gb
, 1) == 0)
994 else if (get_bits(gb
, 1) == 0)
997 else if (get_bits(gb
, 1) == 0)
1000 else if (get_bits(gb
, 1) == 0)
1003 else if (get_bits(gb
, 1) == 0)
1012 * This function extracts a motion vector from the bitstream using a VLC
1013 * scheme. 3 bits are fetched from the bitstream and 1 of 8 actions is
1014 * taken depending on the value on those 3 bits:
1019 * 3: if (next bit is 1) return -2, else return 2
1020 * 4: if (next bit is 1) return -3, else return 3
1021 * 5: return 4 + (next 2 bits), next bit is sign
1022 * 6: return 8 + (next 3 bits), next bit is sign
1023 * 7: return 16 + (next 4 bits), next bit is sign
1025 static int get_motion_vector_vlc(GetBitContext
*gb
)
1029 bits
= get_bits(gb
, 3);
1046 if (get_bits(gb
, 1) == 0)
1053 if (get_bits(gb
, 1) == 0)
1060 bits
= 4 + get_bits(gb
, 2);
1061 if (get_bits(gb
, 1) == 1)
1066 bits
= 8 + get_bits(gb
, 3);
1067 if (get_bits(gb
, 1) == 1)
1072 bits
= 16 + get_bits(gb
, 4);
1073 if (get_bits(gb
, 1) == 1)
1083 * This function fetches a 5-bit number from the stream followed by
1084 * a sign and calls it a motion vector.
1086 static int get_motion_vector_fixed(GetBitContext
*gb
)
1091 bits
= get_bits(gb
, 5);
1093 if (get_bits(gb
, 1) == 1)
1100 * This function unpacks all of the superblock/macroblock/fragment coding
1101 * information from the bitstream.
1103 static void unpack_superblocks(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1106 int current_superblock
= 0;
1107 int current_run
= 0;
1108 int decode_fully_flags
= 0;
1109 int decode_partial_blocks
= 0;
1112 int current_fragment
;
1114 debug_vp3(" vp3: unpacking superblock coding\n");
1118 debug_vp3(" keyframe-- all superblocks are fully coded\n");
1119 memset(s
->superblock_coding
, SB_FULLY_CODED
, s
->superblock_count
);
1123 /* unpack the list of partially-coded superblocks */
1124 bit
= get_bits(gb
, 1);
1125 /* toggle the bit because as soon as the first run length is
1126 * fetched the bit will be toggled again */
1128 while (current_superblock
< s
->superblock_count
) {
1129 if (current_run
== 0) {
1131 current_run
= get_superblock_run_length(gb
);
1132 debug_block_coding(" setting superblocks %d..%d to %s\n",
1134 current_superblock
+ current_run
- 1,
1135 (bit
) ?
"partially coded" : "not coded");
1137 /* if any of the superblocks are not partially coded, flag
1138 * a boolean to decode the list of fully-coded superblocks */
1140 decode_fully_flags
= 1;
1143 /* make a note of the fact that there are partially coded
1145 decode_partial_blocks
= 1;
1148 s
->superblock_coding
[current_superblock
++] =
1149 (bit
) ? SB_PARTIALLY_CODED
: SB_NOT_CODED
;
1153 /* unpack the list of fully coded superblocks if any of the blocks were
1154 * not marked as partially coded in the previous step */
1155 if (decode_fully_flags
) {
1157 current_superblock
= 0;
1159 bit
= get_bits(gb
, 1);
1160 /* toggle the bit because as soon as the first run length is
1161 * fetched the bit will be toggled again */
1163 while (current_superblock
< s
->superblock_count
) {
1165 /* skip any superblocks already marked as partially coded */
1166 if (s
->superblock_coding
[current_superblock
] == SB_NOT_CODED
) {
1168 if (current_run
== 0) {
1170 current_run
= get_superblock_run_length(gb
);
1173 debug_block_coding(" setting superblock %d to %s\n",
1175 (bit
) ?
"fully coded" : "not coded");
1176 s
->superblock_coding
[current_superblock
] =
1177 (bit
) ? SB_FULLY_CODED
: SB_NOT_CODED
;
1180 current_superblock
++;
1184 /* if there were partial blocks, initialize bitstream for
1185 * unpacking fragment codings */
1186 if (decode_partial_blocks
) {
1189 bit
= get_bits(gb
, 1);
1190 /* toggle the bit because as soon as the first run length is
1191 * fetched the bit will be toggled again */
1196 /* figure out which fragments are coded; iterate through each
1197 * superblock (all planes) */
1198 s
->coded_fragment_list_index
= 0;
1199 memset(s
->macroblock_coded
, 0, s
->macroblock_count
);
1200 for (i
= 0; i
< s
->superblock_count
; i
++) {
1202 /* iterate through all 16 fragments in a superblock */
1203 for (j
= 0; j
< 16; j
++) {
1205 /* if the fragment is in bounds, check its coding status */
1206 current_fragment
= s
->superblock_fragments
[i
* 16 + j
];
1207 if (current_fragment
!= -1) {
1208 if (s
->superblock_coding
[i
] == SB_NOT_CODED
) {
1210 /* copy all the fragments from the prior frame */
1211 s
->all_fragments
[current_fragment
].coding_method
=
1214 } else if (s
->superblock_coding
[i
] == SB_PARTIALLY_CODED
) {
1216 /* fragment may or may not be coded; this is the case
1217 * that cares about the fragment coding runs */
1218 if (current_run
== 0) {
1220 current_run
= get_fragment_run_length(gb
);
1224 /* mode will be decoded in the next phase */
1225 s
->all_fragments
[current_fragment
].coding_method
=
1227 s
->coded_fragment_list
[s
->coded_fragment_list_index
++] =
1229 s
->macroblock_coded
[s
->all_fragments
[current_fragment
].macroblock
] = 1;
1230 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
1231 i
, current_fragment
);
1233 /* not coded; copy this fragment from the prior frame */
1234 s
->all_fragments
[current_fragment
].coding_method
=
1236 debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n",
1237 i
, current_fragment
);
1244 /* fragments are fully coded in this superblock; actual
1245 * coding will be determined in next step */
1246 s
->all_fragments
[current_fragment
].coding_method
=
1248 s
->coded_fragment_list
[s
->coded_fragment_list_index
++] =
1250 s
->macroblock_coded
[s
->all_fragments
[current_fragment
].macroblock
] = 1;
1251 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
1252 i
, current_fragment
);
1260 * This function unpacks all the coding mode data for individual macroblocks
1261 * from the bitstream.
1263 static void unpack_modes(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1267 int current_macroblock
;
1268 int current_fragment
;
1271 debug_vp3(" vp3: unpacking encoding modes\n");
1274 debug_vp3(" keyframe-- all blocks are coded as INTRA\n");
1276 for (i
= 0; i
< s
->fragment_count
; i
++)
1277 s
->all_fragments
[i
].coding_method
= MODE_INTRA
;
1281 /* fetch the mode coding scheme for this frame */
1282 scheme
= get_bits(gb
, 3);
1283 debug_modes(" using mode alphabet %d\n", scheme
);
1285 /* is it a custom coding scheme? */
1287 debug_modes(" custom mode alphabet ahead:\n");
1288 for (i
= 0; i
< 8; i
++)
1289 ModeAlphabet
[0][i
] = get_bits(gb
, 3);
1292 for (i
= 0; i
< 8; i
++)
1293 debug_modes(" mode[%d][%d] = %d\n", scheme
, i
,
1294 ModeAlphabet
[scheme
][i
]);
1296 /* iterate through all of the macroblocks that contain 1 or more
1297 * coded fragments */
1298 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
1300 for (j
= 0; j
< 4; j
++) {
1301 current_macroblock
= s
->superblock_macroblocks
[i
* 4 + j
];
1302 if ((current_macroblock
== -1) ||
1303 (!s
->macroblock_coded
[current_macroblock
]))
1306 /* mode 7 means get 3 bits for each coding mode */
1308 coding_mode
= get_bits(gb
, 3);
1310 coding_mode
= ModeAlphabet
[scheme
][get_mode_code(gb
)];
1312 for (k
= 0; k
< 6; k
++) {
1314 s
->macroblock_fragments
[current_macroblock
* 6 + k
];
1315 if (s
->all_fragments
[current_fragment
].coding_method
!=
1317 s
->all_fragments
[current_fragment
].coding_method
=
1321 debug_modes(" coding method for macroblock starting @ fragment %d = %d\n",
1322 s
->macroblock_fragments
[current_macroblock
* 6], coding_mode
);
1330 * This function unpacks all the motion vectors for the individual
1331 * macroblocks from the bitstream.
1333 static void unpack_vectors(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1339 int last_motion_x
= 0;
1340 int last_motion_y
= 0;
1341 int prior_last_motion_x
= 0;
1342 int prior_last_motion_y
= 0;
1343 int current_macroblock
;
1344 int current_fragment
;
1346 debug_vp3(" vp3: unpacking motion vectors\n");
1350 debug_vp3(" keyframe-- there are no motion vectors\n");
1354 memset(motion_x
, 0, 6 * sizeof(int));
1355 memset(motion_y
, 0, 6 * sizeof(int));
1357 /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */
1358 coding_mode
= get_bits(gb
, 1);
1359 debug_vectors(" using %s scheme for unpacking motion vectors\n",
1360 (coding_mode
== 0) ?
"VLC" : "fixed-length");
1362 /* iterate through all of the macroblocks that contain 1 or more
1363 * coded fragments */
1364 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
1366 for (j
= 0; j
< 4; j
++) {
1367 current_macroblock
= s
->superblock_macroblocks
[i
* 4 + j
];
1368 if ((current_macroblock
== -1) ||
1369 (!s
->macroblock_coded
[current_macroblock
]))
1372 current_fragment
= s
->macroblock_fragments
[current_macroblock
* 6];
1373 switch (s
->all_fragments
[current_fragment
].coding_method
) {
1375 case MODE_INTER_PLUS_MV
:
1376 case MODE_GOLDEN_MV
:
1377 /* all 6 fragments use the same motion vector */
1378 if (coding_mode
== 0) {
1379 motion_x
[0] = get_motion_vector_vlc(gb
);
1380 motion_y
[0] = get_motion_vector_vlc(gb
);
1382 motion_x
[0] = get_motion_vector_fixed(gb
);
1383 motion_y
[0] = get_motion_vector_fixed(gb
);
1385 for (k
= 1; k
< 6; k
++) {
1386 motion_x
[k
] = motion_x
[0];
1387 motion_y
[k
] = motion_y
[0];
1390 /* vector maintenance, only on MODE_INTER_PLUS_MV */
1391 if (s
->all_fragments
[current_fragment
].coding_method
==
1392 MODE_INTER_PLUS_MV
) {
1393 prior_last_motion_x
= last_motion_x
;
1394 prior_last_motion_y
= last_motion_y
;
1395 last_motion_x
= motion_x
[0];
1396 last_motion_y
= motion_y
[0];
1400 case MODE_INTER_FOURMV
:
1401 /* fetch 4 vectors from the bitstream, one for each
1402 * Y fragment, then average for the C fragment vectors */
1403 motion_x
[4] = motion_y
[4] = 0;
1404 for (k
= 0; k
< 4; k
++) {
1405 if (coding_mode
== 0) {
1406 motion_x
[k
] = get_motion_vector_vlc(gb
);
1407 motion_y
[k
] = get_motion_vector_vlc(gb
);
1409 motion_x
[k
] = get_motion_vector_fixed(gb
);
1410 motion_y
[k
] = get_motion_vector_fixed(gb
);
1412 motion_x
[4] += motion_x
[k
];
1413 motion_y
[4] += motion_y
[k
];
1416 if (motion_x
[4] >= 0)
1417 motion_x
[4] = (motion_x
[4] + 2) / 4;
1419 motion_x
[4] = (motion_x
[4] - 2) / 4;
1420 motion_x
[5] = motion_x
[4];
1422 if (motion_y
[4] >= 0)
1423 motion_y
[4] = (motion_y
[4] + 2) / 4;
1425 motion_y
[4] = (motion_y
[4] - 2) / 4;
1426 motion_y
[5] = motion_y
[4];
1428 /* vector maintenance; vector[3] is treated as the
1429 * last vector in this case */
1430 prior_last_motion_x
= last_motion_x
;
1431 prior_last_motion_y
= last_motion_y
;
1432 last_motion_x
= motion_x
[3];
1433 last_motion_y
= motion_y
[3];
1436 case MODE_INTER_LAST_MV
:
1437 /* all 6 fragments use the last motion vector */
1438 motion_x
[0] = last_motion_x
;
1439 motion_y
[0] = last_motion_y
;
1440 for (k
= 1; k
< 6; k
++) {
1441 motion_x
[k
] = motion_x
[0];
1442 motion_y
[k
] = motion_y
[0];
1445 /* no vector maintenance (last vector remains the
1449 case MODE_INTER_PRIOR_LAST
:
1450 /* all 6 fragments use the motion vector prior to the
1451 * last motion vector */
1452 motion_x
[0] = prior_last_motion_x
;
1453 motion_y
[0] = prior_last_motion_y
;
1454 for (k
= 1; k
< 6; k
++) {
1455 motion_x
[k
] = motion_x
[0];
1456 motion_y
[k
] = motion_y
[0];
1459 /* vector maintenance */
1460 prior_last_motion_x
= last_motion_x
;
1461 prior_last_motion_y
= last_motion_y
;
1462 last_motion_x
= motion_x
[0];
1463 last_motion_y
= motion_y
[0];
1467 /* assign the motion vectors to the correct fragments */
1468 debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
1470 s
->all_fragments
[current_fragment
].coding_method
);
1471 for (k
= 0; k
< 6; k
++) {
1473 s
->macroblock_fragments
[current_macroblock
* 6 + k
];
1474 s
->all_fragments
[current_fragment
].motion_x
= motion_x
[k
];
1475 s
->all_fragments
[current_fragment
].motion_x
= motion_y
[k
];
1476 debug_vectors(" vector %d: fragment %d = (%d, %d)\n",
1477 k
, current_fragment
, motion_x
[k
], motion_y
[k
]);
1485 * This function is called by unpack_dct_coeffs() to extract the VLCs from
1486 * the bitstream. The VLCs encode tokens which are used to unpack DCT
1487 * data. This function unpacks all the VLCs for either the Y plane or both
1488 * C planes, and is called for DC coefficients or different AC coefficient
1489 * levels (since different coefficient types require different VLC tables.
1491 * This function returns a residual eob run. E.g, if a particular token gave
1492 * instructions to EOB the next 5 fragments and there were only 2 fragments
1493 * left in the current fragment range, 3 would be returned so that it could
1494 * be passed into the next call to this same function.
1496 static int unpack_vlcs(Vp3DecodeContext
*s
, GetBitContext
*gb
,
1497 VLC
*table
, int coeff_index
,
1498 int first_fragment
, int last_fragment
,
1505 Vp3Fragment
*fragment
;
1507 for (i
= first_fragment
; i
< last_fragment
; i
++) {
1509 fragment
= &s
->all_fragments
[s
->coded_fragment_list
[i
]];
1510 if (fragment
->coeff_count
> coeff_index
)
1514 /* decode a VLC into a token */
1515 token
= get_vlc2(gb
, table
->table
, 5, 3);
1516 debug_vlc(" token = %2d, ", token
);
1517 /* use the token to get a zero run, a coefficient, and an eob run */
1518 unpack_token(gb
, token
, &zero_run
, &coeff
, &eob_run
);
1522 fragment
->coeff_count
+= zero_run
;
1523 if (fragment
->coeff_count
< 64)
1524 fragment
->coeffs
[fragment
->coeff_count
++] = coeff
;
1525 debug_vlc(" fragment %d coeff = %d\n",
1526 s
->coded_fragment_list
[i
], fragment
->coeffs
[coeff_index
]);
1528 fragment
->last_coeff
= fragment
->coeff_count
;
1529 fragment
->coeff_count
= 64;
1530 debug_vlc(" fragment %d eob with %d coefficients\n",
1531 s
->coded_fragment_list
[i
], fragment
->last_coeff
);
1540 * This function unpacks all of the DCT coefficient data from the
1543 static void unpack_dct_coeffs(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1550 int residual_eob_run
= 0;
1552 /* for the binary search */
1553 int left
, middle
, right
, found
;
1554 /* this indicates the first fragment of the color plane data */
1555 int plane_split
= 0;
1557 debug_vp3(" vp3: unpacking DCT coefficients\n");
1559 /* find the plane split (the first color plane fragment) using a binary
1560 * search; test the boundaries first */
1561 if (s
->coded_fragment_list_index
== 0)
1563 if (s
->u_fragment_start
<= s
->coded_fragment_list
[0])
1564 plane_split
= 0; /* this means no Y fragments */
1565 else if (s
->coded_fragment_list
[s
->coded_fragment_list_index
- 1] >
1566 s
->u_fragment_start
) {
1569 right
= s
->coded_fragment_list_index
- 1;
1572 middle
= (left
+ right
+ 1) / 2;
1573 if ((s
->coded_fragment_list
[middle
] >= s
->u_fragment_start
) &&
1574 (s
->coded_fragment_list
[middle
- 1] < s
->u_fragment_start
))
1576 else if (s
->coded_fragment_list
[middle
] < s
->u_fragment_start
)
1582 plane_split
= middle
;
1585 debug_vp3(" plane split @ index %d (fragment %d)\n", plane_split
,
1586 s
->coded_fragment_list
[plane_split
]);
1588 /* fetch the DC table indices */
1589 dc_y_table
= get_bits(gb
, 4);
1590 dc_c_table
= get_bits(gb
, 4);
1592 /* unpack the Y plane DC coefficients */
1593 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
1595 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->dc_vlc
[dc_y_table
], 0,
1596 0, plane_split
, residual_eob_run
);
1598 /* unpack the C plane DC coefficients */
1599 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
1601 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->dc_vlc
[dc_c_table
], 0,
1602 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1604 /* fetch the level 1 AC table indices */
1605 ac_y_table
= get_bits(gb
, 4);
1606 ac_c_table
= get_bits(gb
, 4);
1608 /* unpack the level 1 AC coefficients (coeffs 1-5) */
1609 for (i
= 1; i
<= 5; i
++) {
1611 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1613 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_1
[ac_y_table
], i
,
1614 0, plane_split
, residual_eob_run
);
1616 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1618 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_1
[ac_c_table
], i
,
1619 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1622 /* unpack the level 2 AC coefficients (coeffs 6-14) */
1623 for (i
= 6; i
<= 14; i
++) {
1625 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1627 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_2
[ac_y_table
], i
,
1628 0, plane_split
, residual_eob_run
);
1630 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1632 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_2
[ac_c_table
], i
,
1633 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1636 /* unpack the level 3 AC coefficients (coeffs 15-27) */
1637 for (i
= 15; i
<= 27; i
++) {
1639 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1641 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_3
[ac_y_table
], i
,
1642 0, plane_split
, residual_eob_run
);
1644 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1646 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_3
[ac_c_table
], i
,
1647 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1650 /* unpack the level 4 AC coefficients (coeffs 28-63) */
1651 for (i
= 28; i
<= 63; i
++) {
1653 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1655 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_4
[ac_y_table
], i
,
1656 0, plane_split
, residual_eob_run
);
1658 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1660 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_4
[ac_c_table
], i
,
1661 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1666 * This function reverses the DC prediction for each coded fragment in
1667 * the frame. Much of this function is adapted directly from the original
1670 #define COMPATIBLE_FRAME(x) \
1671 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1672 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY)
1673 #define HIGHBITDUPPED(X) (((signed short) X) >> 15)
1674 static inline int iabs (int x
) { return ((x
< 0) ?
-x
: x
); }
1676 static void reverse_dc_prediction(Vp3DecodeContext
*s
,
1679 int fragment_height
)
1688 int i
= first_fragment
;
1691 * Fragment prediction groups:
1699 * Note: Groups 5 and 7 do not exist as it would mean that the
1700 * fragment's x coordinate is both 0 and (width - 1) at the same time.
1702 int predictor_group
;
1705 /* validity flags for the left, up-left, up, and up-right fragments */
1706 int fl
, ful
, fu
, fur
;
1708 /* DC values for the left, up-left, up, and up-right fragments */
1709 int vl
, vul
, vu
, vur
;
1711 /* indices for the left, up-left, up, and up-right fragments */
1715 * The 6 fields mean:
1716 * 0: up-left multiplier
1718 * 2: up-right multiplier
1719 * 3: left multiplier
1721 * 5: right bit shift divisor (e.g., 7 means >>=7, a.k.a. div by 128)
1723 int predictor_transform
[16][6] = {
1724 { 0, 0, 0, 0, 0, 0 },
1725 { 0, 0, 0, 1, 0, 0 }, // PL
1726 { 0, 0, 1, 0, 0, 0 }, // PUR
1727 { 0, 0, 53, 75, 127, 7 }, // PUR|PL
1728 { 0, 1, 0, 0, 0, 0 }, // PU
1729 { 0, 1, 0, 1, 1, 1 }, // PU|PL
1730 { 0, 1, 0, 0, 0, 0 }, // PU|PUR
1731 { 0, 0, 53, 75, 127, 7 }, // PU|PUR|PL
1732 { 1, 0, 0, 0, 0, 0 }, // PUL
1733 { 0, 0, 0, 1, 0, 0 }, // PUL|PL
1734 { 1, 0, 1, 0, 1, 1 }, // PUL|PUR
1735 { 0, 0, 53, 75, 127, 7 }, // PUL|PUR|PL
1736 { 0, 1, 0, 0, 0, 0 }, // PUL|PU
1737 {-26, 29, 0, 29, 31, 5 }, // PUL|PU|PL
1738 { 3, 10, 3, 0, 15, 4 }, // PUL|PU|PUR
1739 {-26, 29, 0, 29, 31, 5 } // PUL|PU|PUR|PL
1742 /* This table shows which types of blocks can use other blocks for
1743 * prediction. For example, INTRA is the only mode in this table to
1744 * have a frame number of 0. That means INTRA blocks can only predict
1745 * from other INTRA blocks. There are 2 golden frame coding types;
1746 * blocks encoding in these modes can only predict from other blocks
1747 * that were encoded with these 1 of these 2 modes. */
1748 unsigned char compatible_frame
[8] = {
1749 1, /* MODE_INTER_NO_MV */
1751 1, /* MODE_INTER_PLUS_MV */
1752 1, /* MODE_INTER_LAST_MV */
1753 1, /* MODE_INTER_PRIOR_MV */
1754 2, /* MODE_USING_GOLDEN */
1755 2, /* MODE_GOLDEN_MV */
1756 1 /* MODE_INTER_FOUR_MV */
1758 int current_frame_type
;
1760 /* there is a last DC predictor for each of the 3 frame types */
1765 debug_vp3(" vp3: reversing DC prediction\n");
1767 vul
= vu
= vur
= vl
= 0;
1768 last_dc
[0] = last_dc
[1] = last_dc
[2] = 0;
1770 /* for each fragment row... */
1771 for (y
= 0; y
< fragment_height
; y
++) {
1773 /* for each fragment in a row... */
1774 for (x
= 0; x
< fragment_width
; x
++, i
++) {
1776 /* reverse prediction if this block was coded */
1777 if (s
->all_fragments
[i
].coding_method
!= MODE_COPY
) {
1779 current_frame_type
=
1780 compatible_frame
[s
->all_fragments
[i
].coding_method
];
1781 predictor_group
= (x
== 0) + ((y
== 0) << 1) +
1782 ((x
+ 1 == fragment_width
) << 2);
1783 debug_dc_pred(" frag %d: group %d, orig DC = %d, ",
1784 i
, predictor_group
, s
->all_fragments
[i
].coeffs
[0]);
1786 switch (predictor_group
) {
1789 /* main body of fragments; consider all 4 possible
1790 * fragments for prediction */
1792 /* calculate the indices of the predicting fragments */
1793 ul
= i
- fragment_width
- 1;
1794 u
= i
- fragment_width
;
1795 ur
= i
- fragment_width
+ 1;
1798 /* fetch the DC values for the predicting fragments */
1799 vul
= s
->all_fragments
[ul
].coeffs
[0];
1800 vu
= s
->all_fragments
[u
].coeffs
[0];
1801 vur
= s
->all_fragments
[ur
].coeffs
[0];
1802 vl
= s
->all_fragments
[l
].coeffs
[0];
1804 /* figure out which fragments are valid */
1805 ful
= FRAME_CODED(ul
) && COMPATIBLE_FRAME(ul
);
1806 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1807 fur
= FRAME_CODED(ur
) && COMPATIBLE_FRAME(ur
);
1808 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1810 /* decide which predictor transform to use */
1811 transform
= (fl
*PL
) | (fu
*PU
) | (ful
*PUL
) | (fur
*PUR
);
1816 /* left column of fragments, not including top corner;
1817 * only consider up and up-right fragments */
1819 /* calculate the indices of the predicting fragments */
1820 u
= i
- fragment_width
;
1821 ur
= i
- fragment_width
+ 1;
1823 /* fetch the DC values for the predicting fragments */
1824 vu
= s
->all_fragments
[u
].coeffs
[0];
1825 vur
= s
->all_fragments
[ur
].coeffs
[0];
1827 /* figure out which fragments are valid */
1828 fur
= FRAME_CODED(ur
) && COMPATIBLE_FRAME(ur
);
1829 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1831 /* decide which predictor transform to use */
1832 transform
= (fu
*PU
) | (fur
*PUR
);
1838 /* top row of fragments, not including top-left frag;
1839 * only consider the left fragment for prediction */
1841 /* calculate the indices of the predicting fragments */
1844 /* fetch the DC values for the predicting fragments */
1845 vl
= s
->all_fragments
[l
].coeffs
[0];
1847 /* figure out which fragments are valid */
1848 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1850 /* decide which predictor transform to use */
1851 transform
= (fl
*PL
);
1856 /* top-left fragment */
1858 /* nothing to predict from in this case */
1864 /* right column of fragments, not including top corner;
1865 * consider up-left, up, and left fragments for
1868 /* calculate the indices of the predicting fragments */
1869 ul
= i
- fragment_width
- 1;
1870 u
= i
- fragment_width
;
1873 /* fetch the DC values for the predicting fragments */
1874 vul
= s
->all_fragments
[ul
].coeffs
[0];
1875 vu
= s
->all_fragments
[u
].coeffs
[0];
1876 vl
= s
->all_fragments
[l
].coeffs
[0];
1878 /* figure out which fragments are valid */
1879 ful
= FRAME_CODED(ul
) && COMPATIBLE_FRAME(ul
);
1880 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1881 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1883 /* decide which predictor transform to use */
1884 transform
= (fl
*PL
) | (fu
*PU
) | (ful
*PUL
);
1890 debug_dc_pred("transform = %d, ", transform
);
1892 if (transform
== 0) {
1894 /* if there were no fragments to predict from, use last
1896 s
->all_fragments
[i
].coeffs
[0] += last_dc
[current_frame_type
];
1897 debug_dc_pred("from last DC (%d) = %d\n",
1898 current_frame_type
, s
->all_fragments
[i
].coeffs
[0]);
1902 /* apply the appropriate predictor transform */
1904 (predictor_transform
[transform
][0] * vul
) +
1905 (predictor_transform
[transform
][1] * vu
) +
1906 (predictor_transform
[transform
][2] * vur
) +
1907 (predictor_transform
[transform
][3] * vl
);
1909 /* if there is a shift value in the transform, add
1910 * the sign bit before the shift */
1911 if (predictor_transform
[transform
][5] != 0) {
1912 predicted_dc
+= ((predicted_dc
>> 15) &
1913 predictor_transform
[transform
][4]);
1914 predicted_dc
>>= predictor_transform
[transform
][5];
1917 /* check for outranging on the [ul u l] and
1918 * [ul u ur l] predictors */
1919 if ((transform
== 13) || (transform
== 15)) {
1920 if (iabs(predicted_dc
- vu
) > 128)
1922 else if (iabs(predicted_dc
- vl
) > 128)
1924 else if (iabs(predicted_dc
- vul
) > 128)
1928 /* at long last, apply the predictor */
1929 s
->all_fragments
[i
].coeffs
[0] += predicted_dc
;
1930 debug_dc_pred("from pred DC = %d\n",
1931 s
->all_fragments
[i
].coeffs
[0]);
1935 last_dc
[current_frame_type
] = s
->all_fragments
[i
].coeffs
[0];
1942 * This function performs the final rendering of each fragment's data
1943 * onto the output frame.
1945 static void render_fragments(Vp3DecodeContext
*s
,
1948 int fragment_height
,
1949 int plane
/* 0 = Y, 1 = U, 2 = V */)
1953 int i
= first_fragment
;
1955 int16_t *dequantizer
;
1956 DCTELEM dequant_block
[64];
1957 unsigned char *output_plane
;
1958 unsigned char *last_plane
;
1959 unsigned char *golden_plane
;
1962 debug_vp3(" vp3: rendering final fragments for %s\n",
1963 (plane
== 0) ?
"Y plane" : (plane
== 1) ?
"U plane" : "V plane");
1965 /* set up plane-specific parameters */
1967 dequantizer
= s
->intra_y_dequant
;
1968 output_plane
= s
->current_frame
.data
[0];
1969 last_plane
= s
->current_frame
.data
[0];
1970 golden_plane
= s
->current_frame
.data
[0];
1971 stride
= -s
->current_frame
.linesize
[0];
1972 } else if (plane
== 1) {
1973 dequantizer
= s
->intra_c_dequant
;
1974 output_plane
= s
->current_frame
.data
[1];
1975 last_plane
= s
->current_frame
.data
[1];
1976 golden_plane
= s
->current_frame
.data
[1];
1977 stride
= -s
->current_frame
.linesize
[1];
1979 dequantizer
= s
->intra_c_dequant
;
1980 output_plane
= s
->current_frame
.data
[2];
1981 last_plane
= s
->current_frame
.data
[2];
1982 golden_plane
= s
->current_frame
.data
[2];
1983 stride
= -s
->current_frame
.linesize
[2];
1986 /* for each fragment row... */
1987 for (y
= 0; y
< fragment_height
; y
++) {
1989 /* for each fragment in a row... */
1990 for (x
= 0; x
< fragment_width
; x
++, i
++) {
1992 /* transform if this block was coded */
1993 if (s
->all_fragments
[i
].coding_method
== MODE_INTRA
) {
1994 /* dequantize the DCT coefficients */
1995 for (j
= 0; j
< 64; j
++)
1996 dequant_block
[dequant_index
[j
]] =
1997 s
->all_fragments
[i
].coeffs
[j
] *
1999 dequant_block
[0] += 1024;
2001 debug_idct("fragment %d:\n", i
);
2002 debug_idct("dequantized block:\n");
2003 for (m
= 0; m
< 8; m
++) {
2004 for (n
= 0; n
< 8; n
++) {
2005 debug_idct(" %5d", dequant_block
[m
* 8 + n
]);
2011 /* invert DCT and place in final output */
2013 output_plane
+ s
->all_fragments
[i
].first_pixel
,
2014 stride
, dequant_block
);
2017 debug_idct("idct block:\n");
2018 for (m = 0; m < 8; m++) {
2019 for (n = 0; n < 8; n++) {
2020 debug_idct(" %3d", pixels[m * 8 + n]);
2026 } else if (s
->all_fragments
[i
].coding_method
== MODE_COPY
) {
2028 /* copy directly from the previous frame */
2029 for (m
= 0; m
< 8; m
++)
2031 output_plane
+ s
->all_fragments
[i
].first_pixel
+ stride
* m
,
2032 last_plane
+ s
->all_fragments
[i
].first_pixel
+ stride
* m
,
2037 /* carry out the motion compensation */
2048 * This function computes the first pixel addresses for each fragment.
2049 * This function needs to be invoked after the first frame is allocated
2050 * so that it has access to the plane strides.
2052 static void vp3_calculate_pixel_addresses(Vp3DecodeContext
*s
)
2057 /* figure out the first pixel addresses for each of the fragments */
2060 for (y
= s
->fragment_height
; y
> 0; y
--) {
2061 for (x
= 0; x
< s
->fragment_width
; x
++) {
2062 s
->all_fragments
[i
++].first_pixel
=
2063 s
->golden_frame
.linesize
[0] * y
* FRAGMENT_PIXELS
-
2064 s
->golden_frame
.linesize
[0] +
2065 x
* FRAGMENT_PIXELS
;
2066 debug_init(" fragment %d, first pixel @ %d\n",
2067 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2072 i
= s
->u_fragment_start
;
2073 for (y
= s
->fragment_height
/ 2; y
> 0; y
--) {
2074 for (x
= 0; x
< s
->fragment_width
/ 2; x
++) {
2075 s
->all_fragments
[i
++].first_pixel
=
2076 s
->golden_frame
.linesize
[1] * y
* FRAGMENT_PIXELS
-
2077 s
->golden_frame
.linesize
[1] +
2078 x
* FRAGMENT_PIXELS
;
2079 debug_init(" fragment %d, first pixel @ %d\n",
2080 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2085 i
= s
->v_fragment_start
;
2086 for (y
= s
->fragment_height
/ 2; y
> 0; y
--) {
2087 for (x
= 0; x
< s
->fragment_width
/ 2; x
++) {
2088 s
->all_fragments
[i
++].first_pixel
=
2089 s
->golden_frame
.linesize
[2] * y
* FRAGMENT_PIXELS
-
2090 s
->golden_frame
.linesize
[2] +
2091 x
* FRAGMENT_PIXELS
;
2092 debug_init(" fragment %d, first pixel @ %d\n",
2093 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2099 * This is the ffmpeg/libavcodec API init function.
2101 static int vp3_decode_init(AVCodecContext
*avctx
)
2103 Vp3DecodeContext
*s
= avctx
->priv_data
;
2107 s
->width
= avctx
->width
;
2108 s
->height
= avctx
->height
;
2109 avctx
->pix_fmt
= PIX_FMT_YUV420P
;
2110 avctx
->has_b_frames
= 0;
2111 dsputil_init(&s
->dsp
, avctx
);
2113 /* initialize to an impossible value which will force a recalculation
2114 * in the first frame decode */
2115 s
->quality_index
= -1;
2117 s
->superblock_width
= (s
->width
+ 31) / 32;
2118 s
->superblock_height
= (s
->height
+ 31) / 32;
2119 s
->superblock_count
= s
->superblock_width
* s
->superblock_height
* 3 / 2;
2120 s
->u_superblock_start
= s
->superblock_width
* s
->superblock_height
;
2121 s
->v_superblock_start
= s
->superblock_width
* s
->superblock_height
* 5 / 4;
2122 s
->superblock_coding
= av_malloc(s
->superblock_count
);
2124 s
->macroblock_width
= (s
->width
+ 15) / 16;
2125 s
->macroblock_height
= (s
->height
+ 15) / 16;
2126 s
->macroblock_count
= s
->macroblock_width
* s
->macroblock_height
;
2128 s
->fragment_width
= s
->width
/ FRAGMENT_PIXELS
;
2129 s
->fragment_height
= s
->height
/ FRAGMENT_PIXELS
;
2131 /* fragment count covers all 8x8 blocks for all 3 planes */
2132 s
->fragment_count
= s
->fragment_width
* s
->fragment_height
* 3 / 2;
2133 s
->u_fragment_start
= s
->fragment_width
* s
->fragment_height
;
2134 s
->v_fragment_start
= s
->fragment_width
* s
->fragment_height
* 5 / 4;
2136 debug_init(" width: %d x %d\n", s
->width
, s
->height
);
2137 debug_init(" superblocks: %d x %d, %d total\n",
2138 s
->superblock_width
, s
->superblock_height
, s
->superblock_count
);
2139 debug_init(" macroblocks: %d x %d, %d total\n",
2140 s
->macroblock_width
, s
->macroblock_height
, s
->macroblock_count
);
2141 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
2145 s
->u_fragment_start
,
2146 s
->v_fragment_start
);
2148 s
->all_fragments
= av_malloc(s
->fragment_count
* sizeof(Vp3Fragment
));
2149 s
->coded_fragment_list
= av_malloc(s
->fragment_count
* sizeof(int));
2150 s
->pixel_addresses_inited
= 0;
2152 /* init VLC tables */
2153 for (i
= 0; i
< 16; i
++) {
2156 init_vlc(&s
->dc_vlc
[i
], 5, 32,
2157 &dc_bias
[i
][0][1], 4, 2,
2158 &dc_bias
[i
][0][0], 4, 2);
2160 /* level 1 AC histograms */
2161 init_vlc(&s
->ac_vlc_1
[i
], 5, 32,
2162 &ac_bias_0
[i
][0][1], 4, 2,
2163 &ac_bias_0
[i
][0][0], 4, 2);
2165 /* level 2 AC histograms */
2166 init_vlc(&s
->ac_vlc_2
[i
], 5, 32,
2167 &ac_bias_1
[i
][0][1], 4, 2,
2168 &ac_bias_1
[i
][0][0], 4, 2);
2170 /* level 3 AC histograms */
2171 init_vlc(&s
->ac_vlc_3
[i
], 5, 32,
2172 &ac_bias_2
[i
][0][1], 4, 2,
2173 &ac_bias_2
[i
][0][0], 4, 2);
2175 /* level 4 AC histograms */
2176 init_vlc(&s
->ac_vlc_4
[i
], 5, 32,
2177 &ac_bias_3
[i
][0][1], 4, 2,
2178 &ac_bias_3
[i
][0][0], 4, 2);
2181 /* build quantization table */
2182 for (i
= 0; i
< 64; i
++)
2183 quant_index
[dequant_index
[i
]] = i
;
2185 /* work out the block mapping tables */
2186 s
->superblock_fragments
= av_malloc(s
->superblock_count
* 16 * sizeof(int));
2187 s
->superblock_macroblocks
= av_malloc(s
->superblock_count
* 4 * sizeof(int));
2188 s
->macroblock_fragments
= av_malloc(s
->macroblock_count
* 6 * sizeof(int));
2189 s
->macroblock_coded
= av_malloc(s
->macroblock_count
+ 1);
2190 init_block_mapping(s
);
2196 * This is the ffmpeg/libavcodec API frame decode function.
2198 static int vp3_decode_frame(AVCodecContext
*avctx
,
2199 void *data
, int *data_size
,
2200 uint8_t *buf
, int buf_size
)
2202 Vp3DecodeContext
*s
= avctx
->priv_data
;
2204 static int counter
= 0;
2208 init_get_bits(&gb
, buf
, buf_size
* 8);
2210 s
->keyframe
= get_bits(&gb
, 1);
2213 s
->last_quality_index
= s
->quality_index
;
2214 s
->quality_index
= get_bits(&gb
, 6);
2215 if (s
->quality_index
!= s
->last_quality_index
)
2216 init_dequantizer(s
);
2218 debug_vp3(" VP3 frame #%d: Q index = %d", counter
, s
->quality_index
);
2222 /* release the previous golden frame and get a new one */
2224 avctx
->release_buffer(avctx
, &s
->golden_frame
);
2226 s
->golden_frame
.reference
= 0;
2227 if(avctx
->get_buffer(avctx
, &s
->golden_frame
) < 0) {
2228 printf("vp3: get_buffer() failed\n");
2232 /* last frame is hereby invalidated */
2233 avctx
->release_buffer(avctx
, &s
->last_frame
);
2235 /* golden frame is also the current frame */
2236 s
->current_frame
= s
->golden_frame
;
2238 /* time to figure out pixel addresses? */
2239 if (!s
->pixel_addresses_inited
)
2240 vp3_calculate_pixel_addresses(s
);
2244 /* allocate a new current frame */
2245 s
->current_frame
.reference
= 0;
2246 if(avctx
->get_buffer(avctx
, &s
->current_frame
) < 0) {
2247 printf("vp3: get_buffer() failed\n");
2254 debug_vp3(", keyframe\n");
2255 /* skip the other 2 header bytes for now */
2262 unpack_superblocks(s
, &gb
);
2263 unpack_modes(s
, &gb
);
2264 unpack_vectors(s
, &gb
);
2265 unpack_dct_coeffs(s
, &gb
);
2267 reverse_dc_prediction(s
, 0, s
->fragment_width
, s
->fragment_height
);
2268 reverse_dc_prediction(s
, s
->u_fragment_start
,
2269 s
->fragment_width
/ 2, s
->fragment_height
/ 2);
2270 reverse_dc_prediction(s
, s
->v_fragment_start
,
2271 s
->fragment_width
/ 2, s
->fragment_height
/ 2);
2273 render_fragments(s
, 0, s
->fragment_width
, s
->fragment_height
, 0);
2274 render_fragments(s
, s
->u_fragment_start
,
2275 s
->fragment_width
/ 2, s
->fragment_height
/ 2, 1);
2276 render_fragments(s
, s
->v_fragment_start
,
2277 s
->fragment_width
/ 2, s
->fragment_height
/ 2, 2);
2280 *data_size
=sizeof(AVFrame
);
2281 *(AVFrame
*)data
= s
->current_frame
;
2283 /* release the last frame, if it was allocated */
2284 avctx
->release_buffer(avctx
, &s
->last_frame
);
2286 /* shuffle frames */
2287 s
->last_frame
= s
->current_frame
;
2293 * This is the ffmpeg/libavcodec API module cleanup function.
2295 static int vp3_decode_end(AVCodecContext
*avctx
)
2297 Vp3DecodeContext
*s
= avctx
->priv_data
;
2299 av_free(s
->all_fragments
);
2300 av_free(s
->coded_fragment_list
);
2301 av_free(s
->superblock_fragments
);
2302 av_free(s
->superblock_macroblocks
);
2303 av_free(s
->macroblock_fragments
);
2304 av_free(s
->macroblock_coded
);
2306 /* release all frames */
2307 avctx
->release_buffer(avctx
, &s
->golden_frame
);
2308 avctx
->release_buffer(avctx
, &s
->last_frame
);
2309 avctx
->release_buffer(avctx
, &s
->current_frame
);
2314 AVCodec vp3_decoder
= {
2318 sizeof(Vp3DecodeContext
),