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 AVFrame golden_frame
;
215 AVFrame current_frame
;
220 int last_quality_index
;
222 int superblock_count
;
223 int superblock_width
;
224 int superblock_height
;
225 int u_superblock_start
;
226 int v_superblock_start
;
227 unsigned char *superblock_coding
;
229 int macroblock_count
;
230 int macroblock_width
;
231 int macroblock_height
;
237 Vp3Fragment
*all_fragments
;
238 int u_fragment_start
;
239 int v_fragment_start
;
241 /* this is a list of indices into the all_fragments array indicating
242 * which of the fragments are coded */
243 int *coded_fragment_list
;
244 int coded_fragment_list_index
;
245 int pixel_addresses_inited
;
253 int16_t intra_y_dequant
[64];
254 int16_t intra_c_dequant
[64];
255 int16_t inter_dequant
[64];
257 /* This table contains superblock_count * 16 entries. Each set of 16
258 * numbers corresponds to the fragment indices 0..15 of the superblock.
259 * An entry will be -1 to indicate that no entry corresponds to that
261 int *superblock_fragments
;
263 /* This table contains superblock_count * 4 entries. Each set of 4
264 * numbers corresponds to the macroblock indices 0..3 of the superblock.
265 * An entry will be -1 to indicate that no entry corresponds to that
267 int *superblock_macroblocks
;
269 /* This table contains macroblock_count * 6 entries. Each set of 6
270 * numbers corresponds to the fragment indices 0..5 which comprise
271 * the macroblock (4 Y fragments and 2 C fragments). */
272 int *macroblock_fragments
;
273 /* This is an array of flags indicating whether a particular
274 * macroblock is coded. */
275 unsigned char *macroblock_coded
;
279 /************************************************************************
280 * VP3 specific functions
281 ************************************************************************/
284 * This function sets up all of the various blocks mappings:
285 * superblocks <-> fragments, macroblocks <-> fragments,
286 * superblocks <-> macroblocks
288 static void init_block_mapping(Vp3DecodeContext
*s
)
291 signed int hilbert_walk_y
[16];
292 signed int hilbert_walk_c
[16];
293 signed int hilbert_walk_mb
[4];
295 int current_fragment
= 0;
296 int current_width
= 0;
297 int current_height
= 0;
300 int superblock_row_inc
= 0;
302 int mapping_index
= 0;
304 int current_macroblock
;
307 signed char travel_width
[16] = {
314 signed char travel_height
[16] = {
321 signed char travel_width_mb
[4] = {
325 signed char travel_height_mb
[4] = {
329 debug_vp3(" vp3: initialize block mapping tables\n");
331 /* figure out hilbert pattern per these frame dimensions */
332 hilbert_walk_y
[0] = 1;
333 hilbert_walk_y
[1] = 1;
334 hilbert_walk_y
[2] = s
->fragment_width
;
335 hilbert_walk_y
[3] = -1;
336 hilbert_walk_y
[4] = s
->fragment_width
;
337 hilbert_walk_y
[5] = s
->fragment_width
;
338 hilbert_walk_y
[6] = 1;
339 hilbert_walk_y
[7] = -s
->fragment_width
;
340 hilbert_walk_y
[8] = 1;
341 hilbert_walk_y
[9] = s
->fragment_width
;
342 hilbert_walk_y
[10] = 1;
343 hilbert_walk_y
[11] = -s
->fragment_width
;
344 hilbert_walk_y
[12] = -s
->fragment_width
;
345 hilbert_walk_y
[13] = -1;
346 hilbert_walk_y
[14] = -s
->fragment_width
;
347 hilbert_walk_y
[15] = 1;
349 hilbert_walk_c
[0] = 1;
350 hilbert_walk_c
[1] = 1;
351 hilbert_walk_c
[2] = s
->fragment_width
/ 2;
352 hilbert_walk_c
[3] = -1;
353 hilbert_walk_c
[4] = s
->fragment_width
/ 2;
354 hilbert_walk_c
[5] = s
->fragment_width
/ 2;
355 hilbert_walk_c
[6] = 1;
356 hilbert_walk_c
[7] = -s
->fragment_width
/ 2;
357 hilbert_walk_c
[8] = 1;
358 hilbert_walk_c
[9] = s
->fragment_width
/ 2;
359 hilbert_walk_c
[10] = 1;
360 hilbert_walk_c
[11] = -s
->fragment_width
/ 2;
361 hilbert_walk_c
[12] = -s
->fragment_width
/ 2;
362 hilbert_walk_c
[13] = -1;
363 hilbert_walk_c
[14] = -s
->fragment_width
/ 2;
364 hilbert_walk_c
[15] = 1;
366 hilbert_walk_mb
[0] = 1;
367 hilbert_walk_mb
[1] = s
->macroblock_width
;
368 hilbert_walk_mb
[2] = 1;
369 hilbert_walk_mb
[3] = -s
->macroblock_width
;
371 /* iterate through each superblock (all planes) and map the fragments */
372 for (i
= 0; i
< s
->superblock_count
; i
++) {
373 debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n",
374 i
, s
->u_superblock_start
, s
->v_superblock_start
);
376 /* time to re-assign the limits? */
379 /* start of Y superblocks */
380 right_edge
= s
->fragment_width
;
381 bottom_edge
= s
->fragment_height
;
384 superblock_row_inc
= 3 * s
->fragment_width
;
385 hilbert
= hilbert_walk_y
;
387 /* the first operation for this variable is to advance by 1 */
388 current_fragment
= -1;
390 } else if (i
== s
->u_superblock_start
) {
392 /* start of U superblocks */
393 right_edge
= s
->fragment_width
/ 2;
394 bottom_edge
= s
->fragment_height
/ 2;
397 superblock_row_inc
= 3 * (s
->fragment_width
/ 2);
398 hilbert
= hilbert_walk_c
;
400 /* the first operation for this variable is to advance by 1 */
401 current_fragment
= s
->u_fragment_start
- 1;
403 } else if (i
== s
->v_superblock_start
) {
405 /* start of V superblocks */
406 right_edge
= s
->fragment_width
/ 2;
407 bottom_edge
= s
->fragment_height
/ 2;
410 superblock_row_inc
= 3 * (s
->fragment_width
/ 2);
411 hilbert
= hilbert_walk_c
;
413 /* the first operation for this variable is to advance by 1 */
414 current_fragment
= s
->v_fragment_start
- 1;
418 if (current_width
>= right_edge
) {
419 /* reset width and move to next superblock row */
423 /* fragment is now at the start of a new superblock row */
424 current_fragment
+= superblock_row_inc
;
427 /* iterate through all 16 fragments in a superblock */
428 for (j
= 0; j
< 16; j
++) {
429 current_fragment
+= hilbert
[j
];
430 current_height
+= travel_height
[j
];
432 /* check if the fragment is in bounds */
433 if ((current_width
<= right_edge
) &&
434 (current_height
< bottom_edge
)) {
435 s
->superblock_fragments
[mapping_index
] = current_fragment
;
436 debug_init(" mapping fragment %d to superblock %d, position %d\n",
437 s
->superblock_fragments
[mapping_index
], i
, j
);
439 s
->superblock_fragments
[mapping_index
] = -1;
440 debug_init(" superblock %d, position %d has no fragment\n",
444 current_width
+= travel_width
[j
];
449 /* initialize the superblock <-> macroblock mapping; iterate through
450 * all of the Y plane superblocks to build this mapping */
451 right_edge
= s
->macroblock_width
;
452 bottom_edge
= s
->macroblock_height
;
455 superblock_row_inc
= s
->macroblock_width
;
456 hilbert
= hilbert_walk_mb
;
458 current_macroblock
= -1;
459 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
461 if (current_width
>= right_edge
) {
462 /* reset width and move to next superblock row */
466 /* macroblock is now at the start of a new superblock row */
467 current_macroblock
+= superblock_row_inc
;
470 /* iterate through each potential macroblock in the superblock */
471 for (j
= 0; j
< 4; j
++) {
472 current_macroblock
+= hilbert_walk_mb
[j
];
473 current_height
+= travel_height_mb
[j
];
475 /* check if the macroblock is in bounds */
476 if ((current_width
<= right_edge
) &&
477 (current_height
< bottom_edge
)) {
478 s
->superblock_macroblocks
[mapping_index
] = current_macroblock
;
479 debug_init(" mapping macroblock %d to superblock %d, position %d\n",
480 s
->superblock_macroblocks
[mapping_index
], i
, j
);
482 s
->superblock_macroblocks
[mapping_index
] = -1;
483 debug_init(" superblock %d, position %d has no macroblock\n",
487 current_width
+= travel_width_mb
[j
];
492 /* initialize the macroblock <-> fragment mapping */
493 current_fragment
= 0;
494 current_macroblock
= 0;
496 for (i
= 0; i
< s
->fragment_height
; i
+= 2) {
498 for (j
= 0; j
< s
->fragment_width
; j
+= 2) {
500 debug_init(" macroblock %d contains fragments: ", current_macroblock
);
501 s
->all_fragments
[current_fragment
].macroblock
= current_macroblock
;
502 s
->macroblock_fragments
[mapping_index
++] = current_fragment
;
503 debug_init("%d ", current_fragment
);
505 if (j
+ 1 < s
->fragment_width
) {
506 s
->all_fragments
[current_fragment
+ 1].macroblock
= current_macroblock
;
507 s
->macroblock_fragments
[mapping_index
++] = current_fragment
+ 1;
508 debug_init("%d ", current_fragment
+ 1);
510 s
->macroblock_fragments
[mapping_index
++] = -1;
512 if (i
+ 1 < s
->fragment_height
) {
513 s
->all_fragments
[current_fragment
+ s
->fragment_width
].macroblock
=
515 s
->macroblock_fragments
[mapping_index
++] =
516 current_fragment
+ s
->fragment_width
;
517 debug_init("%d ", current_fragment
+ s
->fragment_width
);
519 s
->macroblock_fragments
[mapping_index
++] = -1;
521 if ((j
+ 1 < s
->fragment_width
) && (i
+ 1 < s
->fragment_height
)) {
522 s
->all_fragments
[current_fragment
+ s
->fragment_width
+ 1].macroblock
=
524 s
->macroblock_fragments
[mapping_index
++] =
525 current_fragment
+ s
->fragment_width
+ 1;
526 debug_init("%d ", current_fragment
+ s
->fragment_width
+ 1);
528 s
->macroblock_fragments
[mapping_index
++] = -1;
531 c_fragment
= s
->u_fragment_start
+
532 (i
* s
->fragment_width
/ 4) + (j
/ 2);
533 s
->all_fragments
[c_fragment
].macroblock
= s
->macroblock_count
;
534 s
->macroblock_fragments
[mapping_index
++] = c_fragment
;
535 debug_init("%d ", c_fragment
);
537 c_fragment
= s
->v_fragment_start
+
538 (i
* s
->fragment_width
/ 4) + (j
/ 2);
539 s
->all_fragments
[c_fragment
].macroblock
= s
->macroblock_count
;
540 s
->macroblock_fragments
[mapping_index
++] = c_fragment
;
541 debug_init("%d ", c_fragment
);
545 if (j
+ 2 <= s
->fragment_width
)
546 current_fragment
+= 2;
549 current_macroblock
++;
552 current_fragment
+= s
->fragment_width
;
557 * This function unpacks a single token (which should be in the range 0..31)
558 * and returns a zero run (number of zero coefficients in current DCT matrix
559 * before next non-zero coefficient), the next DCT coefficient, and the
560 * number of consecutive, non-EOB'd DCT blocks to EOB.
562 static void unpack_token(GetBitContext
*gb
, int token
, int *zero_run
,
563 DCTELEM
*coeff
, int *eob_run
)
571 debug_token(" vp3 token %d: ", token
);
575 debug_token("DCT_EOB_TOKEN, EOB next block\n");
580 debug_token("DCT_EOB_PAIR_TOKEN, EOB next 2 blocks\n");
585 debug_token("DCT_EOB_TRIPLE_TOKEN, EOB next 3 blocks\n");
590 debug_token("DCT_REPEAT_RUN_TOKEN, ");
591 *eob_run
= get_bits(gb
, 2) + 4;
592 debug_token("EOB the next %d blocks\n", *eob_run
);
596 debug_token("DCT_REPEAT_RUN2_TOKEN, ");
597 *eob_run
= get_bits(gb
, 3) + 8;
598 debug_token("EOB the next %d blocks\n", *eob_run
);
602 debug_token("DCT_REPEAT_RUN3_TOKEN, ");
603 *eob_run
= get_bits(gb
, 4) + 16;
604 debug_token("EOB the next %d blocks\n", *eob_run
);
608 debug_token("DCT_REPEAT_RUN4_TOKEN, ");
609 *eob_run
= get_bits(gb
, 12);
610 debug_token("EOB the next %d blocks\n", *eob_run
);
614 debug_token("DCT_SHORT_ZRL_TOKEN, ");
615 /* note that this token actually indicates that (3 extra bits) + 1 0s
616 * should be output; this case specifies a run of (3 EBs) 0s and a
617 * coefficient of 0. */
618 *zero_run
= get_bits(gb
, 3);
620 debug_token("skip the next %d positions in output matrix\n", *zero_run
+ 1);
624 debug_token("DCT_ZRL_TOKEN, ");
625 /* note that this token actually indicates that (6 extra bits) + 1 0s
626 * should be output; this case specifies a run of (6 EBs) 0s and a
627 * coefficient of 0. */
628 *zero_run
= get_bits(gb
, 6);
630 debug_token("skip the next %d positions in output matrix\n", *zero_run
+ 1);
634 debug_token("ONE_TOKEN, output 1\n");
639 debug_token("MINUS_ONE_TOKEN, output -1\n");
644 debug_token("TWO_TOKEN, output 2\n");
649 debug_token("MINUS_TWO_TOKEN, output -2\n");
657 debug_token("LOW_VAL_TOKENS, ");
659 *coeff
= -(3 + (token
- 13));
661 *coeff
= 3 + (token
- 13);
662 debug_token("output %d\n", *coeff
);
666 debug_token("DCT_VAL_CATEGORY3, ");
667 sign
= get_bits(gb
, 1);
668 *coeff
= 7 + get_bits(gb
, 1);
671 debug_token("output %d\n", *coeff
);
675 debug_token("DCT_VAL_CATEGORY4, ");
676 sign
= get_bits(gb
, 1);
677 *coeff
= 9 + get_bits(gb
, 2);
680 debug_token("output %d\n", *coeff
);
684 debug_token("DCT_VAL_CATEGORY5, ");
685 sign
= get_bits(gb
, 1);
686 *coeff
= 13 + get_bits(gb
, 3);
689 debug_token("output %d\n", *coeff
);
693 debug_token("DCT_VAL_CATEGORY6, ");
694 sign
= get_bits(gb
, 1);
695 *coeff
= 21 + get_bits(gb
, 4);
698 debug_token("output %d\n", *coeff
);
702 debug_token("DCT_VAL_CATEGORY7, ");
703 sign
= get_bits(gb
, 1);
704 *coeff
= 37 + get_bits(gb
, 5);
707 debug_token("output %d\n", *coeff
);
711 debug_token("DCT_VAL_CATEGORY8, ");
712 sign
= get_bits(gb
, 1);
713 *coeff
= 69 + get_bits(gb
, 9);
716 debug_token("output %d\n", *coeff
);
724 debug_token("DCT_RUN_CATEGORY1, ");
725 *zero_run
= token
- 22;
730 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
734 debug_token("DCT_RUN_CATEGORY1B, ");
739 *zero_run
= 6 + get_bits(gb
, 2);
740 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
744 debug_token("DCT_RUN_CATEGORY1C, ");
749 *zero_run
= 10 + get_bits(gb
, 3);
750 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
754 debug_token("DCT_RUN_CATEGORY2, ");
755 sign
= get_bits(gb
, 1);
756 *coeff
= 2 + get_bits(gb
, 1);
760 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
764 debug_token("DCT_RUN_CATEGORY2, ");
765 sign
= get_bits(gb
, 1);
766 *coeff
= 2 + get_bits(gb
, 1);
769 *zero_run
= 2 + get_bits(gb
, 1);
770 debug_token("output %d 0s, then %d\n", *zero_run
, *coeff
);
774 printf (" vp3: help! Got a bad token: %d > 31\n", token
);
781 * This function wipes out all of the fragment data.
783 static void init_frame(Vp3DecodeContext
*s
, GetBitContext
*gb
)
787 /* zero out all of the fragment information */
788 s
->coded_fragment_list_index
= 0;
789 for (i
= 0; i
< s
->fragment_count
; i
++) {
790 memset(s
->all_fragments
[i
].coeffs
, 0, 64 * sizeof(DCTELEM
));
791 s
->all_fragments
[i
].coeff_count
= 0;
792 s
->all_fragments
[i
].last_coeff
= 0;
797 * This function sets of the dequantization tables used for a particular
800 static void init_dequantizer(Vp3DecodeContext
*s
)
803 int quality_scale
= vp31_quality_threshold
[s
->quality_index
];
804 int dc_scale_factor
= vp31_dc_scale_factor
[s
->quality_index
];
807 debug_vp3(" vp3: initializing dequantization tables\n");
810 * Scale dequantizers:
816 * where sf = dc_scale_factor for DC quantizer
817 * or quality_scale for AC quantizer
819 * Then, saturate the result to a lower limit of MIN_DEQUANT_VAL.
823 /* scale DC quantizers */
824 s
->intra_y_dequant
[0] = vp31_intra_y_dequant
[0] * dc_scale_factor
/ 100;
825 if (s
->intra_y_dequant
[0] < MIN_DEQUANT_VAL
* 2)
826 s
->intra_y_dequant
[0] = MIN_DEQUANT_VAL
* 2;
827 s
->intra_y_dequant
[0] *= SCALER
;
829 s
->intra_c_dequant
[0] = vp31_intra_c_dequant
[0] * dc_scale_factor
/ 100;
830 if (s
->intra_c_dequant
[0] < MIN_DEQUANT_VAL
* 2)
831 s
->intra_c_dequant
[0] = MIN_DEQUANT_VAL
* 2;
832 s
->intra_c_dequant
[0] *= SCALER
;
834 s
->inter_dequant
[0] = vp31_inter_dequant
[0] * dc_scale_factor
/ 100;
835 if (s
->inter_dequant
[0] < MIN_DEQUANT_VAL
* 4)
836 s
->inter_dequant
[0] = MIN_DEQUANT_VAL
* 4;
837 s
->inter_dequant
[0] *= SCALER
;
839 /* scale AC quantizers, zigzag at the same time in preparation for
840 * the dequantization phase */
841 for (i
= 1; i
< 64; i
++) {
845 s
->intra_y_dequant
[j
] = vp31_intra_y_dequant
[i
] * quality_scale
/ 100;
846 if (s
->intra_y_dequant
[j
] < MIN_DEQUANT_VAL
)
847 s
->intra_y_dequant
[j
] = MIN_DEQUANT_VAL
;
848 s
->intra_y_dequant
[j
] *= SCALER
;
850 s
->intra_c_dequant
[j
] = vp31_intra_c_dequant
[i
] * quality_scale
/ 100;
851 if (s
->intra_c_dequant
[j
] < MIN_DEQUANT_VAL
)
852 s
->intra_c_dequant
[j
] = MIN_DEQUANT_VAL
;
853 s
->intra_c_dequant
[j
] *= SCALER
;
855 s
->inter_dequant
[j
] = vp31_inter_dequant
[i
] * quality_scale
/ 100;
856 if (s
->inter_dequant
[j
] < MIN_DEQUANT_VAL
* 2)
857 s
->inter_dequant
[j
] = MIN_DEQUANT_VAL
* 2;
858 s
->inter_dequant
[j
] *= SCALER
;
861 /* print debug information as requested */
862 debug_dequantizers("intra Y dequantizers:\n");
863 for (i
= 0; i
< 8; i
++) {
864 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
865 debug_dequantizers(" %4d,", s
->intra_y_dequant
[j
]);
867 debug_dequantizers("\n");
869 debug_dequantizers("\n");
871 debug_dequantizers("intra C dequantizers:\n");
872 for (i
= 0; i
< 8; i
++) {
873 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
874 debug_dequantizers(" %4d,", s
->intra_c_dequant
[j
]);
876 debug_dequantizers("\n");
878 debug_dequantizers("\n");
880 debug_dequantizers("interframe dequantizers:\n");
881 for (i
= 0; i
< 8; i
++) {
882 for (j
= i
* 8; j
< i
* 8 + 8; j
++) {
883 debug_dequantizers(" %4d,", s
->inter_dequant
[j
]);
885 debug_dequantizers("\n");
887 debug_dequantizers("\n");
891 * This function is used to fetch runs of 1s or 0s from the bitstream for
892 * use in determining which superblocks are fully and partially coded.
901 * 111111xxxxxxxxxxxx 34-4129
903 static int get_superblock_run_length(GetBitContext
*gb
)
906 if (get_bits(gb
, 1) == 0)
909 else if (get_bits(gb
, 1) == 0)
910 return (2 + get_bits(gb
, 1));
912 else if (get_bits(gb
, 1) == 0)
913 return (4 + get_bits(gb
, 1));
915 else if (get_bits(gb
, 1) == 0)
916 return (6 + get_bits(gb
, 2));
918 else if (get_bits(gb
, 1) == 0)
919 return (10 + get_bits(gb
, 3));
921 else if (get_bits(gb
, 1) == 0)
922 return (18 + get_bits(gb
, 4));
925 return (34 + get_bits(gb
, 12));
930 * This function is used to fetch runs of 1s or 0s from the bitstream for
931 * use in determining which particular fragments are coded.
941 static int get_fragment_run_length(GetBitContext
*gb
)
944 if (get_bits(gb
, 1) == 0)
945 return (1 + get_bits(gb
, 1));
947 else if (get_bits(gb
, 1) == 0)
948 return (3 + get_bits(gb
, 1));
950 else if (get_bits(gb
, 1) == 0)
951 return (5 + get_bits(gb
, 1));
953 else if (get_bits(gb
, 1) == 0)
954 return (7 + get_bits(gb
, 2));
956 else if (get_bits(gb
, 1) == 0)
957 return (11 + get_bits(gb
, 2));
960 return (15 + get_bits(gb
, 4));
965 * This function decodes a VLC from the bitstream and returns a number
966 * that ranges from 0..7. The number indicates which of the 8 coding
980 static int get_mode_code(GetBitContext
*gb
)
983 if (get_bits(gb
, 1) == 0)
986 else if (get_bits(gb
, 1) == 0)
989 else if (get_bits(gb
, 1) == 0)
992 else if (get_bits(gb
, 1) == 0)
995 else if (get_bits(gb
, 1) == 0)
998 else if (get_bits(gb
, 1) == 0)
1001 else if (get_bits(gb
, 1) == 0)
1010 * This function extracts a motion vector from the bitstream using a VLC
1011 * scheme. 3 bits are fetched from the bitstream and 1 of 8 actions is
1012 * taken depending on the value on those 3 bits:
1017 * 3: if (next bit is 1) return -2, else return 2
1018 * 4: if (next bit is 1) return -3, else return 3
1019 * 5: return 4 + (next 2 bits), next bit is sign
1020 * 6: return 8 + (next 3 bits), next bit is sign
1021 * 7: return 16 + (next 4 bits), next bit is sign
1023 static int get_motion_vector_vlc(GetBitContext
*gb
)
1027 bits
= get_bits(gb
, 3);
1044 if (get_bits(gb
, 1) == 0)
1051 if (get_bits(gb
, 1) == 0)
1058 bits
= 4 + get_bits(gb
, 2);
1059 if (get_bits(gb
, 1) == 1)
1064 bits
= 8 + get_bits(gb
, 3);
1065 if (get_bits(gb
, 1) == 1)
1070 bits
= 16 + get_bits(gb
, 4);
1071 if (get_bits(gb
, 1) == 1)
1081 * This function fetches a 5-bit number from the stream followed by
1082 * a sign and calls it a motion vector.
1084 static int get_motion_vector_fixed(GetBitContext
*gb
)
1089 bits
= get_bits(gb
, 5);
1091 if (get_bits(gb
, 1) == 1)
1098 * This function unpacks all of the superblock/macroblock/fragment coding
1099 * information from the bitstream.
1101 static void unpack_superblocks(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1104 int current_superblock
= 0;
1105 int current_run
= 0;
1106 int decode_fully_flags
= 0;
1107 int decode_partial_blocks
= 0;
1110 int current_fragment
;
1112 debug_vp3(" vp3: unpacking superblock coding\n");
1116 debug_vp3(" keyframe-- all superblocks are fully coded\n");
1117 memset(s
->superblock_coding
, SB_FULLY_CODED
, s
->superblock_count
);
1121 /* unpack the list of partially-coded superblocks */
1122 bit
= get_bits(gb
, 1);
1123 /* toggle the bit because as soon as the first run length is
1124 * fetched the bit will be toggled again */
1126 while (current_superblock
< s
->superblock_count
) {
1127 if (current_run
== 0) {
1129 current_run
= get_superblock_run_length(gb
);
1130 debug_block_coding(" setting superblocks %d..%d to %s\n",
1132 current_superblock
+ current_run
- 1,
1133 (bit
) ?
"partially coded" : "not coded");
1135 /* if any of the superblocks are not partially coded, flag
1136 * a boolean to decode the list of fully-coded superblocks */
1138 decode_fully_flags
= 1;
1141 /* make a note of the fact that there are partially coded
1143 decode_partial_blocks
= 1;
1146 s
->superblock_coding
[current_superblock
++] =
1147 (bit
) ? SB_PARTIALLY_CODED
: SB_NOT_CODED
;
1151 /* unpack the list of fully coded superblocks if any of the blocks were
1152 * not marked as partially coded in the previous step */
1153 if (decode_fully_flags
) {
1155 current_superblock
= 0;
1157 bit
= get_bits(gb
, 1);
1158 /* toggle the bit because as soon as the first run length is
1159 * fetched the bit will be toggled again */
1161 while (current_superblock
< s
->superblock_count
) {
1163 /* skip any superblocks already marked as partially coded */
1164 if (s
->superblock_coding
[current_superblock
] == SB_NOT_CODED
) {
1166 if (current_run
== 0) {
1168 current_run
= get_superblock_run_length(gb
);
1171 debug_block_coding(" setting superblock %d to %s\n",
1173 (bit
) ?
"fully coded" : "not coded");
1174 s
->superblock_coding
[current_superblock
] =
1175 (bit
) ? SB_FULLY_CODED
: SB_NOT_CODED
;
1178 current_superblock
++;
1182 /* if there were partial blocks, initialize bitstream for
1183 * unpacking fragment codings */
1184 if (decode_partial_blocks
) {
1187 bit
= get_bits(gb
, 1);
1188 /* toggle the bit because as soon as the first run length is
1189 * fetched the bit will be toggled again */
1194 /* figure out which fragments are coded; iterate through each
1195 * superblock (all planes) */
1196 s
->coded_fragment_list_index
= 0;
1197 memset(s
->macroblock_coded
, 0, s
->macroblock_count
);
1198 for (i
= 0; i
< s
->superblock_count
; i
++) {
1200 /* iterate through all 16 fragments in a superblock */
1201 for (j
= 0; j
< 16; j
++) {
1203 /* if the fragment is in bounds, check its coding status */
1204 current_fragment
= s
->superblock_fragments
[i
* 16 + j
];
1205 if (current_fragment
!= -1) {
1206 if (s
->superblock_coding
[i
] == SB_NOT_CODED
) {
1208 /* copy all the fragments from the prior frame */
1209 s
->all_fragments
[current_fragment
].coding_method
=
1212 } else if (s
->superblock_coding
[i
] == SB_PARTIALLY_CODED
) {
1214 /* fragment may or may not be coded; this is the case
1215 * that cares about the fragment coding runs */
1216 if (current_run
== 0) {
1218 current_run
= get_fragment_run_length(gb
);
1222 /* mode will be decoded in the next phase */
1223 s
->all_fragments
[current_fragment
].coding_method
=
1225 s
->coded_fragment_list
[s
->coded_fragment_list_index
++] =
1227 s
->macroblock_coded
[s
->all_fragments
[current_fragment
].macroblock
] = 1;
1228 debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
1229 i
, current_fragment
);
1231 /* not coded; copy this fragment from the prior frame */
1232 s
->all_fragments
[current_fragment
].coding_method
=
1234 debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n",
1235 i
, current_fragment
);
1242 /* fragments are fully coded in this superblock; actual
1243 * coding will be determined in next step */
1244 s
->all_fragments
[current_fragment
].coding_method
=
1246 s
->coded_fragment_list
[s
->coded_fragment_list_index
++] =
1248 s
->macroblock_coded
[s
->all_fragments
[current_fragment
].macroblock
] = 1;
1249 debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
1250 i
, current_fragment
);
1258 * This function unpacks all the coding mode data for individual macroblocks
1259 * from the bitstream.
1261 static void unpack_modes(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1265 int current_macroblock
;
1266 int current_fragment
;
1269 debug_vp3(" vp3: unpacking encoding modes\n");
1272 debug_vp3(" keyframe-- all blocks are coded as INTRA\n");
1274 for (i
= 0; i
< s
->fragment_count
; i
++)
1275 s
->all_fragments
[i
].coding_method
= MODE_INTRA
;
1279 /* fetch the mode coding scheme for this frame */
1280 scheme
= get_bits(gb
, 3);
1281 debug_modes(" using mode alphabet %d\n", scheme
);
1283 /* is it a custom coding scheme? */
1285 debug_modes(" custom mode alphabet ahead:\n");
1286 for (i
= 0; i
< 8; i
++)
1287 ModeAlphabet
[0][i
] = get_bits(gb
, 3);
1290 for (i
= 0; i
< 8; i
++)
1291 debug_modes(" mode[%d][%d] = %d\n", scheme
, i
,
1292 ModeAlphabet
[scheme
][i
]);
1294 /* iterate through all of the macroblocks that contain 1 or more
1295 * coded fragments */
1296 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
1298 for (j
= 0; j
< 4; j
++) {
1299 current_macroblock
= s
->superblock_macroblocks
[i
* 4 + j
];
1300 if ((current_macroblock
== -1) ||
1301 (!s
->macroblock_coded
[current_macroblock
]))
1304 /* mode 7 means get 3 bits for each coding mode */
1306 coding_mode
= get_bits(gb
, 3);
1308 coding_mode
= ModeAlphabet
[scheme
][get_mode_code(gb
)];
1310 for (k
= 0; k
< 6; k
++) {
1312 s
->macroblock_fragments
[current_macroblock
* 6 + k
];
1313 if (s
->all_fragments
[current_fragment
].coding_method
!=
1315 s
->all_fragments
[current_fragment
].coding_method
=
1319 debug_modes(" coding method for macroblock starting @ fragment %d = %d\n",
1320 s
->macroblock_fragments
[current_macroblock
* 6], coding_mode
);
1328 * This function unpacks all the motion vectors for the individual
1329 * macroblocks from the bitstream.
1331 static void unpack_vectors(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1337 int last_motion_x
= 0;
1338 int last_motion_y
= 0;
1339 int prior_last_motion_x
= 0;
1340 int prior_last_motion_y
= 0;
1341 int current_macroblock
;
1342 int current_fragment
;
1344 debug_vp3(" vp3: unpacking motion vectors\n");
1348 debug_vp3(" keyframe-- there are no motion vectors\n");
1352 memset(motion_x
, 0, 6 * sizeof(int));
1353 memset(motion_y
, 0, 6 * sizeof(int));
1355 /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */
1356 coding_mode
= get_bits(gb
, 1);
1357 debug_vectors(" using %s scheme for unpacking motion vectors\n",
1358 (coding_mode
== 0) ?
"VLC" : "fixed-length");
1360 /* iterate through all of the macroblocks that contain 1 or more
1361 * coded fragments */
1362 for (i
= 0; i
< s
->u_superblock_start
; i
++) {
1364 for (j
= 0; j
< 4; j
++) {
1365 current_macroblock
= s
->superblock_macroblocks
[i
* 4 + j
];
1366 if ((current_macroblock
== -1) ||
1367 (!s
->macroblock_coded
[current_macroblock
]))
1370 current_fragment
= s
->macroblock_fragments
[current_macroblock
* 6];
1371 switch (s
->all_fragments
[current_fragment
].coding_method
) {
1373 case MODE_INTER_PLUS_MV
:
1374 case MODE_GOLDEN_MV
:
1375 /* all 6 fragments use the same motion vector */
1376 if (coding_mode
== 0) {
1377 motion_x
[0] = get_motion_vector_vlc(gb
);
1378 motion_y
[0] = get_motion_vector_vlc(gb
);
1380 motion_x
[0] = get_motion_vector_fixed(gb
);
1381 motion_y
[0] = get_motion_vector_fixed(gb
);
1383 for (k
= 1; k
< 6; k
++) {
1384 motion_x
[k
] = motion_x
[0];
1385 motion_y
[k
] = motion_y
[0];
1388 /* vector maintenance, only on MODE_INTER_PLUS_MV */
1389 if (s
->all_fragments
[current_fragment
].coding_method
==
1390 MODE_INTER_PLUS_MV
) {
1391 prior_last_motion_x
= last_motion_x
;
1392 prior_last_motion_y
= last_motion_y
;
1393 last_motion_x
= motion_x
[0];
1394 last_motion_y
= motion_y
[0];
1398 case MODE_INTER_FOURMV
:
1399 /* fetch 4 vectors from the bitstream, one for each
1400 * Y fragment, then average for the C fragment vectors */
1401 motion_x
[4] = motion_y
[4] = 0;
1402 for (k
= 0; k
< 4; k
++) {
1403 if (coding_mode
== 0) {
1404 motion_x
[k
] = get_motion_vector_vlc(gb
);
1405 motion_y
[k
] = get_motion_vector_vlc(gb
);
1407 motion_x
[k
] = get_motion_vector_fixed(gb
);
1408 motion_y
[k
] = get_motion_vector_fixed(gb
);
1410 motion_x
[4] += motion_x
[k
];
1411 motion_y
[4] += motion_y
[k
];
1414 if (motion_x
[4] >= 0)
1415 motion_x
[4] = (motion_x
[4] + 2) / 4;
1417 motion_x
[4] = (motion_x
[4] - 2) / 4;
1418 motion_x
[5] = motion_x
[4];
1420 if (motion_y
[4] >= 0)
1421 motion_y
[4] = (motion_y
[4] + 2) / 4;
1423 motion_y
[4] = (motion_y
[4] - 2) / 4;
1424 motion_y
[5] = motion_y
[4];
1426 /* vector maintenance; vector[3] is treated as the
1427 * last vector in this case */
1428 prior_last_motion_x
= last_motion_x
;
1429 prior_last_motion_y
= last_motion_y
;
1430 last_motion_x
= motion_x
[3];
1431 last_motion_y
= motion_y
[3];
1434 case MODE_INTER_LAST_MV
:
1435 /* all 6 fragments use the last motion vector */
1436 motion_x
[0] = last_motion_x
;
1437 motion_y
[0] = last_motion_y
;
1438 for (k
= 1; k
< 6; k
++) {
1439 motion_x
[k
] = motion_x
[0];
1440 motion_y
[k
] = motion_y
[0];
1443 /* no vector maintenance (last vector remains the
1447 case MODE_INTER_PRIOR_LAST
:
1448 /* all 6 fragments use the motion vector prior to the
1449 * last motion vector */
1450 motion_x
[0] = prior_last_motion_x
;
1451 motion_y
[0] = prior_last_motion_y
;
1452 for (k
= 1; k
< 6; k
++) {
1453 motion_x
[k
] = motion_x
[0];
1454 motion_y
[k
] = motion_y
[0];
1457 /* vector maintenance */
1458 prior_last_motion_x
= last_motion_x
;
1459 prior_last_motion_y
= last_motion_y
;
1460 last_motion_x
= motion_x
[0];
1461 last_motion_y
= motion_y
[0];
1465 /* assign the motion vectors to the correct fragments */
1466 debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
1468 s
->all_fragments
[current_fragment
].coding_method
);
1469 for (k
= 0; k
< 6; k
++) {
1471 s
->macroblock_fragments
[current_macroblock
* 6 + k
];
1472 s
->all_fragments
[current_fragment
].motion_x
= motion_x
[k
];
1473 s
->all_fragments
[current_fragment
].motion_x
= motion_y
[k
];
1474 debug_vectors(" vector %d: fragment %d = (%d, %d)\n",
1475 k
, current_fragment
, motion_x
[k
], motion_y
[k
]);
1483 * This function is called by unpack_dct_coeffs() to extract the VLCs from
1484 * the bitstream. The VLCs encode tokens which are used to unpack DCT
1485 * data. This function unpacks all the VLCs for either the Y plane or both
1486 * C planes, and is called for DC coefficients or different AC coefficient
1487 * levels (since different coefficient types require different VLC tables.
1489 * This function returns a residual eob run. E.g, if a particular token gave
1490 * instructions to EOB the next 5 fragments and there were only 2 fragments
1491 * left in the current fragment range, 3 would be returned so that it could
1492 * be passed into the next call to this same function.
1494 static int unpack_vlcs(Vp3DecodeContext
*s
, GetBitContext
*gb
,
1495 VLC
*table
, int coeff_index
,
1496 int first_fragment
, int last_fragment
,
1503 Vp3Fragment
*fragment
;
1505 for (i
= first_fragment
; i
< last_fragment
; i
++) {
1507 fragment
= &s
->all_fragments
[s
->coded_fragment_list
[i
]];
1508 if (fragment
->coeff_count
> coeff_index
)
1512 /* decode a VLC into a token */
1513 token
= get_vlc2(gb
, table
->table
, 5, 3);
1514 debug_vlc(" token = %2d, ", token
);
1515 /* use the token to get a zero run, a coefficient, and an eob run */
1516 unpack_token(gb
, token
, &zero_run
, &coeff
, &eob_run
);
1520 fragment
->coeff_count
+= zero_run
;
1521 if (fragment
->coeff_count
< 64)
1522 fragment
->coeffs
[fragment
->coeff_count
++] = coeff
;
1523 debug_vlc(" fragment %d coeff = %d\n",
1524 s
->coded_fragment_list
[i
], fragment
->coeffs
[coeff_index
]);
1526 fragment
->last_coeff
= fragment
->coeff_count
;
1527 fragment
->coeff_count
= 64;
1528 debug_vlc(" fragment %d eob with %d coefficients\n",
1529 s
->coded_fragment_list
[i
], fragment
->last_coeff
);
1538 * This function unpacks all of the DCT coefficient data from the
1541 static void unpack_dct_coeffs(Vp3DecodeContext
*s
, GetBitContext
*gb
)
1548 int residual_eob_run
= 0;
1550 /* for the binary search */
1551 int left
, middle
, right
, found
;
1552 /* this indicates the first fragment of the color plane data */
1553 int plane_split
= 0;
1555 debug_vp3(" vp3: unpacking DCT coefficients\n");
1557 /* find the plane split (the first color plane fragment) using a binary
1558 * search; test the boundaries first */
1559 if (s
->coded_fragment_list_index
== 0)
1561 if (s
->u_fragment_start
<= s
->coded_fragment_list
[0])
1562 plane_split
= 0; /* this means no Y fragments */
1563 else if (s
->coded_fragment_list
[s
->coded_fragment_list_index
- 1] >
1564 s
->u_fragment_start
) {
1567 right
= s
->coded_fragment_list_index
- 1;
1570 middle
= (left
+ right
+ 1) / 2;
1571 if ((s
->coded_fragment_list
[middle
] >= s
->u_fragment_start
) &&
1572 (s
->coded_fragment_list
[middle
- 1] < s
->u_fragment_start
))
1574 else if (s
->coded_fragment_list
[middle
] < s
->u_fragment_start
)
1580 plane_split
= middle
;
1583 debug_vp3(" plane split @ index %d (fragment %d)\n", plane_split
,
1584 s
->coded_fragment_list
[plane_split
]);
1586 /* fetch the DC table indices */
1587 dc_y_table
= get_bits(gb
, 4);
1588 dc_c_table
= get_bits(gb
, 4);
1590 /* unpack the Y plane DC coefficients */
1591 debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
1593 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->dc_vlc
[dc_y_table
], 0,
1594 0, plane_split
, residual_eob_run
);
1596 /* unpack the C plane DC coefficients */
1597 debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
1599 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->dc_vlc
[dc_c_table
], 0,
1600 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1602 /* fetch the level 1 AC table indices */
1603 ac_y_table
= get_bits(gb
, 4);
1604 ac_c_table
= get_bits(gb
, 4);
1606 /* unpack the level 1 AC coefficients (coeffs 1-5) */
1607 for (i
= 1; i
<= 5; i
++) {
1609 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1611 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_1
[ac_y_table
], i
,
1612 0, plane_split
, residual_eob_run
);
1614 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1616 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_1
[ac_c_table
], i
,
1617 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1620 /* unpack the level 2 AC coefficients (coeffs 6-14) */
1621 for (i
= 6; i
<= 14; i
++) {
1623 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1625 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_2
[ac_y_table
], i
,
1626 0, plane_split
, residual_eob_run
);
1628 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1630 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_2
[ac_c_table
], i
,
1631 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1634 /* unpack the level 3 AC coefficients (coeffs 15-27) */
1635 for (i
= 15; i
<= 27; i
++) {
1637 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1639 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_3
[ac_y_table
], i
,
1640 0, plane_split
, residual_eob_run
);
1642 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1644 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_3
[ac_c_table
], i
,
1645 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1648 /* unpack the level 4 AC coefficients (coeffs 28-63) */
1649 for (i
= 28; i
<= 63; i
++) {
1651 debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
1653 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_4
[ac_y_table
], i
,
1654 0, plane_split
, residual_eob_run
);
1656 debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
1658 residual_eob_run
= unpack_vlcs(s
, gb
, &s
->ac_vlc_4
[ac_c_table
], i
,
1659 plane_split
, s
->coded_fragment_list_index
, residual_eob_run
);
1664 * This function reverses the DC prediction for each coded fragment in
1665 * the frame. Much of this function is adapted directly from the original
1668 #define COMPATIBLE_FRAME(x) \
1669 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1670 #define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY)
1671 #define HIGHBITDUPPED(X) (((signed short) X) >> 15)
1672 static inline int iabs (int x
) { return ((x
< 0) ?
-x
: x
); }
1674 static void reverse_dc_prediction(Vp3DecodeContext
*s
,
1677 int fragment_height
)
1686 int i
= first_fragment
;
1689 * Fragment prediction groups:
1697 * Note: Groups 5 and 7 do not exist as it would mean that the
1698 * fragment's x coordinate is both 0 and (width - 1) at the same time.
1700 int predictor_group
;
1703 /* validity flags for the left, up-left, up, and up-right fragments */
1704 int fl
, ful
, fu
, fur
;
1706 /* DC values for the left, up-left, up, and up-right fragments */
1707 int vl
, vul
, vu
, vur
;
1709 /* indices for the left, up-left, up, and up-right fragments */
1713 * The 6 fields mean:
1714 * 0: up-left multiplier
1716 * 2: up-right multiplier
1717 * 3: left multiplier
1719 * 5: right bit shift divisor (e.g., 7 means >>=7, a.k.a. div by 128)
1721 int predictor_transform
[16][6] = {
1722 { 0, 0, 0, 0, 0, 0 },
1723 { 0, 0, 0, 1, 0, 0 }, // PL
1724 { 0, 0, 1, 0, 0, 0 }, // PUR
1725 { 0, 0, 53, 75, 127, 7 }, // PUR|PL
1726 { 0, 1, 0, 0, 0, 0 }, // PU
1727 { 0, 1, 0, 1, 1, 1 }, // PU|PL
1728 { 0, 1, 0, 0, 0, 0 }, // PU|PUR
1729 { 0, 0, 53, 75, 127, 7 }, // PU|PUR|PL
1730 { 1, 0, 0, 0, 0, 0 }, // PUL
1731 { 0, 0, 0, 1, 0, 0 }, // PUL|PL
1732 { 1, 0, 1, 0, 1, 1 }, // PUL|PUR
1733 { 0, 0, 53, 75, 127, 7 }, // PUL|PUR|PL
1734 { 0, 1, 0, 0, 0, 0 }, // PUL|PU
1735 {-26, 29, 0, 29, 31, 5 }, // PUL|PU|PL
1736 { 3, 10, 3, 0, 15, 4 }, // PUL|PU|PUR
1737 {-26, 29, 0, 29, 31, 5 } // PUL|PU|PUR|PL
1740 /* This table shows which types of blocks can use other blocks for
1741 * prediction. For example, INTRA is the only mode in this table to
1742 * have a frame number of 0. That means INTRA blocks can only predict
1743 * from other INTRA blocks. There are 2 golden frame coding types;
1744 * blocks encoding in these modes can only predict from other blocks
1745 * that were encoded with these 1 of these 2 modes. */
1746 unsigned char compatible_frame
[8] = {
1747 1, /* MODE_INTER_NO_MV */
1749 1, /* MODE_INTER_PLUS_MV */
1750 1, /* MODE_INTER_LAST_MV */
1751 1, /* MODE_INTER_PRIOR_MV */
1752 2, /* MODE_USING_GOLDEN */
1753 2, /* MODE_GOLDEN_MV */
1754 1 /* MODE_INTER_FOUR_MV */
1756 int current_frame_type
;
1758 /* there is a last DC predictor for each of the 3 frame types */
1763 debug_vp3(" vp3: reversing DC prediction\n");
1765 vul
= vu
= vur
= vl
= 0;
1766 last_dc
[0] = last_dc
[1] = last_dc
[2] = 0;
1768 /* for each fragment row... */
1769 for (y
= 0; y
< fragment_height
; y
++) {
1771 /* for each fragment in a row... */
1772 for (x
= 0; x
< fragment_width
; x
++, i
++) {
1774 /* reverse prediction if this block was coded */
1775 if (s
->all_fragments
[i
].coding_method
!= MODE_COPY
) {
1777 current_frame_type
=
1778 compatible_frame
[s
->all_fragments
[i
].coding_method
];
1779 predictor_group
= (x
== 0) + ((y
== 0) << 1) +
1780 ((x
+ 1 == fragment_width
) << 2);
1781 debug_dc_pred(" frag %d: group %d, orig DC = %d, ",
1782 i
, predictor_group
, s
->all_fragments
[i
].coeffs
[0]);
1784 switch (predictor_group
) {
1787 /* main body of fragments; consider all 4 possible
1788 * fragments for prediction */
1790 /* calculate the indices of the predicting fragments */
1791 ul
= i
- fragment_width
- 1;
1792 u
= i
- fragment_width
;
1793 ur
= i
- fragment_width
+ 1;
1796 /* fetch the DC values for the predicting fragments */
1797 vul
= s
->all_fragments
[ul
].coeffs
[0];
1798 vu
= s
->all_fragments
[u
].coeffs
[0];
1799 vur
= s
->all_fragments
[ur
].coeffs
[0];
1800 vl
= s
->all_fragments
[l
].coeffs
[0];
1802 /* figure out which fragments are valid */
1803 ful
= FRAME_CODED(ul
) && COMPATIBLE_FRAME(ul
);
1804 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1805 fur
= FRAME_CODED(ur
) && COMPATIBLE_FRAME(ur
);
1806 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1808 /* decide which predictor transform to use */
1809 transform
= (fl
*PL
) | (fu
*PU
) | (ful
*PUL
) | (fur
*PUR
);
1814 /* left column of fragments, not including top corner;
1815 * only consider up and up-right fragments */
1817 /* calculate the indices of the predicting fragments */
1818 u
= i
- fragment_width
;
1819 ur
= i
- fragment_width
+ 1;
1821 /* fetch the DC values for the predicting fragments */
1822 vu
= s
->all_fragments
[u
].coeffs
[0];
1823 vur
= s
->all_fragments
[ur
].coeffs
[0];
1825 /* figure out which fragments are valid */
1826 fur
= FRAME_CODED(ur
) && COMPATIBLE_FRAME(ur
);
1827 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1829 /* decide which predictor transform to use */
1830 transform
= (fu
*PU
) | (fur
*PUR
);
1836 /* top row of fragments, not including top-left frag;
1837 * only consider the left fragment for prediction */
1839 /* calculate the indices of the predicting fragments */
1842 /* fetch the DC values for the predicting fragments */
1843 vl
= s
->all_fragments
[l
].coeffs
[0];
1845 /* figure out which fragments are valid */
1846 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1848 /* decide which predictor transform to use */
1849 transform
= (fl
*PL
);
1854 /* top-left fragment */
1856 /* nothing to predict from in this case */
1862 /* right column of fragments, not including top corner;
1863 * consider up-left, up, and left fragments for
1866 /* calculate the indices of the predicting fragments */
1867 ul
= i
- fragment_width
- 1;
1868 u
= i
- fragment_width
;
1871 /* fetch the DC values for the predicting fragments */
1872 vul
= s
->all_fragments
[ul
].coeffs
[0];
1873 vu
= s
->all_fragments
[u
].coeffs
[0];
1874 vl
= s
->all_fragments
[l
].coeffs
[0];
1876 /* figure out which fragments are valid */
1877 ful
= FRAME_CODED(ul
) && COMPATIBLE_FRAME(ul
);
1878 fu
= FRAME_CODED(u
) && COMPATIBLE_FRAME(u
);
1879 fl
= FRAME_CODED(l
) && COMPATIBLE_FRAME(l
);
1881 /* decide which predictor transform to use */
1882 transform
= (fl
*PL
) | (fu
*PU
) | (ful
*PUL
);
1888 debug_dc_pred("transform = %d, ", transform
);
1890 if (transform
== 0) {
1892 /* if there were no fragments to predict from, use last
1894 s
->all_fragments
[i
].coeffs
[0] += last_dc
[current_frame_type
];
1895 debug_dc_pred("from last DC (%d) = %d\n",
1896 current_frame_type
, s
->all_fragments
[i
].coeffs
[0]);
1900 /* apply the appropriate predictor transform */
1902 (predictor_transform
[transform
][0] * vul
) +
1903 (predictor_transform
[transform
][1] * vu
) +
1904 (predictor_transform
[transform
][2] * vur
) +
1905 (predictor_transform
[transform
][3] * vl
);
1907 /* if there is a shift value in the transform, add
1908 * the sign bit before the shift */
1909 if (predictor_transform
[transform
][5] != 0) {
1910 predicted_dc
+= ((predicted_dc
>> 15) &
1911 predictor_transform
[transform
][4]);
1912 predicted_dc
>>= predictor_transform
[transform
][5];
1915 /* check for outranging on the [ul u l] and
1916 * [ul u ur l] predictors */
1917 if ((transform
== 13) || (transform
== 15)) {
1918 if (iabs(predicted_dc
- vu
) > 128)
1920 else if (iabs(predicted_dc
- vl
) > 128)
1922 else if (iabs(predicted_dc
- vul
) > 128)
1926 /* at long last, apply the predictor */
1927 s
->all_fragments
[i
].coeffs
[0] += predicted_dc
;
1928 debug_dc_pred("from pred DC = %d\n",
1929 s
->all_fragments
[i
].coeffs
[0]);
1933 last_dc
[current_frame_type
] = s
->all_fragments
[i
].coeffs
[0];
1940 * This function performs the final rendering of each fragment's data
1941 * onto the output frame.
1943 static void render_fragments(Vp3DecodeContext
*s
,
1946 int fragment_height
,
1947 int plane
/* 0 = Y, 1 = U, 2 = V */)
1951 int i
= first_fragment
;
1953 int16_t *dequantizer
;
1954 DCTELEM dequant_block
[64];
1955 unsigned char *output_plane
;
1956 unsigned char *last_plane
;
1957 unsigned char *golden_plane
;
1960 debug_vp3(" vp3: rendering final fragments for %s\n",
1961 (plane
== 0) ?
"Y plane" : (plane
== 1) ?
"U plane" : "V plane");
1963 /* set up plane-specific parameters */
1965 dequantizer
= s
->intra_y_dequant
;
1966 output_plane
= s
->current_frame
.data
[0];
1967 last_plane
= s
->last_frame
.data
[0];
1968 golden_plane
= s
->golden_frame
.data
[0];
1969 stride
= -s
->current_frame
.linesize
[0];
1970 } else if (plane
== 1) {
1971 dequantizer
= s
->intra_c_dequant
;
1972 output_plane
= s
->current_frame
.data
[1];
1973 last_plane
= s
->last_frame
.data
[1];
1974 golden_plane
= s
->golden_frame
.data
[1];
1975 stride
= -s
->current_frame
.linesize
[1];
1977 dequantizer
= s
->intra_c_dequant
;
1978 output_plane
= s
->current_frame
.data
[2];
1979 last_plane
= s
->last_frame
.data
[2];
1980 golden_plane
= s
->golden_frame
.data
[2];
1981 stride
= -s
->current_frame
.linesize
[2];
1984 /* for each fragment row... */
1985 for (y
= 0; y
< fragment_height
; y
++) {
1987 /* for each fragment in a row... */
1988 for (x
= 0; x
< fragment_width
; x
++, i
++) {
1990 /* transform if this block was coded */
1991 if (s
->all_fragments
[i
].coding_method
== MODE_INTRA
) {
1992 /* dequantize the DCT coefficients */
1993 for (j
= 0; j
< 64; j
++)
1994 dequant_block
[dequant_index
[j
]] =
1995 s
->all_fragments
[i
].coeffs
[j
] *
1997 dequant_block
[0] += 1024;
1999 debug_idct("fragment %d:\n", i
);
2000 debug_idct("dequantized block:\n");
2001 for (m
= 0; m
< 8; m
++) {
2002 for (n
= 0; n
< 8; n
++) {
2003 debug_idct(" %5d", dequant_block
[m
* 8 + n
]);
2009 /* invert DCT and place in final output */
2011 output_plane
+ s
->all_fragments
[i
].first_pixel
,
2012 stride
, dequant_block
);
2015 debug_idct("idct block:\n");
2016 for (m = 0; m < 8; m++) {
2017 for (n = 0; n < 8; n++) {
2018 debug_idct(" %3d", pixels[m * 8 + n]);
2024 } else if (s
->all_fragments
[i
].coding_method
== MODE_COPY
) {
2026 /* copy directly from the previous frame */
2027 for (m
= 0; m
< 8; m
++)
2029 output_plane
+ s
->all_fragments
[i
].first_pixel
+ stride
* m
,
2030 last_plane
+ s
->all_fragments
[i
].first_pixel
+ stride
* m
,
2035 /* carry out the motion compensation */
2046 * This function computes the first pixel addresses for each fragment.
2047 * This function needs to be invoked after the first frame is allocated
2048 * so that it has access to the plane strides.
2050 static void vp3_calculate_pixel_addresses(Vp3DecodeContext
*s
)
2055 /* figure out the first pixel addresses for each of the fragments */
2058 for (y
= s
->fragment_height
; y
> 0; y
--) {
2059 for (x
= 0; x
< s
->fragment_width
; x
++) {
2060 s
->all_fragments
[i
++].first_pixel
=
2061 s
->golden_frame
.linesize
[0] * y
* FRAGMENT_PIXELS
-
2062 s
->golden_frame
.linesize
[0] +
2063 x
* FRAGMENT_PIXELS
;
2064 debug_init(" fragment %d, first pixel @ %d\n",
2065 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2070 i
= s
->u_fragment_start
;
2071 for (y
= s
->fragment_height
/ 2; y
> 0; y
--) {
2072 for (x
= 0; x
< s
->fragment_width
/ 2; x
++) {
2073 s
->all_fragments
[i
++].first_pixel
=
2074 s
->golden_frame
.linesize
[1] * y
* FRAGMENT_PIXELS
-
2075 s
->golden_frame
.linesize
[1] +
2076 x
* FRAGMENT_PIXELS
;
2077 debug_init(" fragment %d, first pixel @ %d\n",
2078 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2083 i
= s
->v_fragment_start
;
2084 for (y
= s
->fragment_height
/ 2; y
> 0; y
--) {
2085 for (x
= 0; x
< s
->fragment_width
/ 2; x
++) {
2086 s
->all_fragments
[i
++].first_pixel
=
2087 s
->golden_frame
.linesize
[2] * y
* FRAGMENT_PIXELS
-
2088 s
->golden_frame
.linesize
[2] +
2089 x
* FRAGMENT_PIXELS
;
2090 debug_init(" fragment %d, first pixel @ %d\n",
2091 i
-1, s
->all_fragments
[i
-1].first_pixel
);
2097 * This is the ffmpeg/libavcodec API init function.
2099 static int vp3_decode_init(AVCodecContext
*avctx
)
2101 Vp3DecodeContext
*s
= avctx
->priv_data
;
2105 s
->width
= avctx
->width
;
2106 s
->height
= avctx
->height
;
2107 avctx
->pix_fmt
= PIX_FMT_YUV420P
;
2108 avctx
->has_b_frames
= 0;
2109 dsputil_init(&s
->dsp
, avctx
);
2111 /* initialize to an impossible value which will force a recalculation
2112 * in the first frame decode */
2113 s
->quality_index
= -1;
2115 s
->superblock_width
= (s
->width
+ 31) / 32;
2116 s
->superblock_height
= (s
->height
+ 31) / 32;
2117 s
->superblock_count
= s
->superblock_width
* s
->superblock_height
* 3 / 2;
2118 s
->u_superblock_start
= s
->superblock_width
* s
->superblock_height
;
2119 s
->v_superblock_start
= s
->superblock_width
* s
->superblock_height
* 5 / 4;
2120 s
->superblock_coding
= av_malloc(s
->superblock_count
);
2122 s
->macroblock_width
= (s
->width
+ 15) / 16;
2123 s
->macroblock_height
= (s
->height
+ 15) / 16;
2124 s
->macroblock_count
= s
->macroblock_width
* s
->macroblock_height
;
2126 s
->fragment_width
= s
->width
/ FRAGMENT_PIXELS
;
2127 s
->fragment_height
= s
->height
/ FRAGMENT_PIXELS
;
2129 /* fragment count covers all 8x8 blocks for all 3 planes */
2130 s
->fragment_count
= s
->fragment_width
* s
->fragment_height
* 3 / 2;
2131 s
->u_fragment_start
= s
->fragment_width
* s
->fragment_height
;
2132 s
->v_fragment_start
= s
->fragment_width
* s
->fragment_height
* 5 / 4;
2134 debug_init(" width: %d x %d\n", s
->width
, s
->height
);
2135 debug_init(" superblocks: %d x %d, %d total\n",
2136 s
->superblock_width
, s
->superblock_height
, s
->superblock_count
);
2137 debug_init(" macroblocks: %d x %d, %d total\n",
2138 s
->macroblock_width
, s
->macroblock_height
, s
->macroblock_count
);
2139 debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
2143 s
->u_fragment_start
,
2144 s
->v_fragment_start
);
2146 s
->all_fragments
= av_malloc(s
->fragment_count
* sizeof(Vp3Fragment
));
2147 s
->coded_fragment_list
= av_malloc(s
->fragment_count
* sizeof(int));
2148 s
->pixel_addresses_inited
= 0;
2150 /* init VLC tables */
2151 for (i
= 0; i
< 16; i
++) {
2154 init_vlc(&s
->dc_vlc
[i
], 5, 32,
2155 &dc_bias
[i
][0][1], 4, 2,
2156 &dc_bias
[i
][0][0], 4, 2);
2158 /* level 1 AC histograms */
2159 init_vlc(&s
->ac_vlc_1
[i
], 5, 32,
2160 &ac_bias_0
[i
][0][1], 4, 2,
2161 &ac_bias_0
[i
][0][0], 4, 2);
2163 /* level 2 AC histograms */
2164 init_vlc(&s
->ac_vlc_2
[i
], 5, 32,
2165 &ac_bias_1
[i
][0][1], 4, 2,
2166 &ac_bias_1
[i
][0][0], 4, 2);
2168 /* level 3 AC histograms */
2169 init_vlc(&s
->ac_vlc_3
[i
], 5, 32,
2170 &ac_bias_2
[i
][0][1], 4, 2,
2171 &ac_bias_2
[i
][0][0], 4, 2);
2173 /* level 4 AC histograms */
2174 init_vlc(&s
->ac_vlc_4
[i
], 5, 32,
2175 &ac_bias_3
[i
][0][1], 4, 2,
2176 &ac_bias_3
[i
][0][0], 4, 2);
2179 /* build quantization table */
2180 for (i
= 0; i
< 64; i
++)
2181 quant_index
[dequant_index
[i
]] = i
;
2183 /* work out the block mapping tables */
2184 s
->superblock_fragments
= av_malloc(s
->superblock_count
* 16 * sizeof(int));
2185 s
->superblock_macroblocks
= av_malloc(s
->superblock_count
* 4 * sizeof(int));
2186 s
->macroblock_fragments
= av_malloc(s
->macroblock_count
* 6 * sizeof(int));
2187 s
->macroblock_coded
= av_malloc(s
->macroblock_count
+ 1);
2188 init_block_mapping(s
);
2190 /* make sure that frames are available to be freed on the first decode */
2191 if(avctx
->get_buffer(avctx
, &s
->golden_frame
) < 0) {
2192 printf("vp3: get_buffer() failed\n");
2200 * This is the ffmpeg/libavcodec API frame decode function.
2202 static int vp3_decode_frame(AVCodecContext
*avctx
,
2203 void *data
, int *data_size
,
2204 uint8_t *buf
, int buf_size
)
2206 Vp3DecodeContext
*s
= avctx
->priv_data
;
2208 static int counter
= 0;
2212 init_get_bits(&gb
, buf
, buf_size
* 8);
2214 s
->keyframe
= get_bits(&gb
, 1);
2217 s
->last_quality_index
= s
->quality_index
;
2218 s
->quality_index
= get_bits(&gb
, 6);
2219 if (s
->quality_index
!= s
->last_quality_index
)
2220 init_dequantizer(s
);
2222 debug_vp3(" VP3 frame #%d: Q index = %d", counter
, s
->quality_index
);
2226 /* release the previous golden frame and get a new one */
2227 avctx
->release_buffer(avctx
, &s
->golden_frame
);
2229 s
->golden_frame
.reference
= 0;
2230 if(avctx
->get_buffer(avctx
, &s
->golden_frame
) < 0) {
2231 printf("vp3: get_buffer() failed\n");
2235 /* golden frame is also the current frame */
2236 memcpy(&s
->current_frame
, &s
->golden_frame
, sizeof(AVFrame
));
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);
2279 *data_size
=sizeof(AVFrame
);
2280 *(AVFrame
*)data
= s
->current_frame
;
2282 /* release the last frame, if it was allocated */
2283 avctx
->release_buffer(avctx
, &s
->last_frame
);
2285 /* shuffle frames (last = current) */
2286 memcpy(&s
->last_frame
, &s
->current_frame
, sizeof(AVFrame
));
2292 * This is the ffmpeg/libavcodec API module cleanup function.
2294 static int vp3_decode_end(AVCodecContext
*avctx
)
2296 Vp3DecodeContext
*s
= avctx
->priv_data
;
2298 av_free(s
->all_fragments
);
2299 av_free(s
->coded_fragment_list
);
2300 av_free(s
->superblock_fragments
);
2301 av_free(s
->superblock_macroblocks
);
2302 av_free(s
->macroblock_fragments
);
2303 av_free(s
->macroblock_coded
);
2305 /* release all frames */
2306 avctx
->release_buffer(avctx
, &s
->golden_frame
);
2307 avctx
->release_buffer(avctx
, &s
->last_frame
);
2308 avctx
->release_buffer(avctx
, &s
->current_frame
);
2313 AVCodec vp3_decoder
= {
2317 sizeof(Vp3DecodeContext
),