better names for globalized tables by me
Originally committed as revision 3905 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -85,6 +85,11 @@ int ff_h263_decode_init(AVCodecContext *avctx) |
85 | 85 |
s->h263_pred = 1; |
86 | 86 |
s->msmpeg4_version=5; |
87 | 87 |
break; |
88 |
+ case CODEC_ID_WMV3: |
|
89 |
+ s->h263_msmpeg4 = 1; |
|
90 |
+ s->h263_pred = 1; |
|
91 |
+ s->msmpeg4_version=6; |
|
92 |
+ break; |
|
88 | 93 |
case CODEC_ID_H263I: |
89 | 94 |
break; |
90 | 95 |
case CODEC_ID_FLV1: |
... | ... |
@@ -75,6 +75,8 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); |
75 | 75 |
static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); |
76 | 76 |
static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); |
77 | 77 |
|
78 |
+/* vc9 externs */ |
|
79 |
+extern uint8_t wmv3_dc_scale_table[32]; |
|
78 | 80 |
|
79 | 81 |
#ifdef DEBUG |
80 | 82 |
int intra_count = 0; |
... | ... |
@@ -175,6 +177,11 @@ static void common_init(MpegEncContext * s) |
175 | 175 |
s->y_dc_scale_table= wmv1_y_dc_scale_table; |
176 | 176 |
s->c_dc_scale_table= wmv1_c_dc_scale_table; |
177 | 177 |
break; |
178 |
+ case 6: |
|
179 |
+ s->y_dc_scale_table= wmv3_dc_scale_table; |
|
180 |
+ s->c_dc_scale_table= wmv3_dc_scale_table; |
|
181 |
+ break; |
|
182 |
+ |
|
178 | 183 |
} |
179 | 184 |
|
180 | 185 |
|
... | ... |
@@ -629,7 +636,7 @@ void msmpeg4_encode_mb(MpegEncContext * s, |
629 | 629 |
if (s->pict_type == I_TYPE) { |
630 | 630 |
set_stat(ST_INTRA_MB); |
631 | 631 |
put_bits(&s->pb, |
632 |
- table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]); |
|
632 |
+ ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); |
|
633 | 633 |
} else { |
634 | 634 |
if (s->use_skip_mb_code) |
635 | 635 |
put_bits(&s->pb, 1, 0); /* mb coded */ |
... | ... |
@@ -1030,9 +1037,9 @@ else |
1030 | 1030 |
/* decoding stuff */ |
1031 | 1031 |
|
1032 | 1032 |
static VLC mb_non_intra_vlc[4]; |
1033 |
-static VLC mb_intra_vlc; |
|
1034 |
-static VLC dc_lum_vlc[2]; |
|
1035 |
-static VLC dc_chroma_vlc[2]; |
|
1033 |
+VLC ff_msmp4_mb_i_vlc; |
|
1034 |
+VLC ff_msmp4_dc_luma_vlc[2]; |
|
1035 |
+VLC ff_msmp4_dc_chroma_vlc[2]; |
|
1036 | 1036 |
static VLC v2_dc_lum_vlc; |
1037 | 1037 |
static VLC v2_dc_chroma_vlc; |
1038 | 1038 |
static VLC cbpy_vlc; |
... | ... |
@@ -1121,16 +1128,16 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) |
1121 | 1121 |
mv->table_mv_code, 2, 2, 1); |
1122 | 1122 |
} |
1123 | 1123 |
|
1124 |
- init_vlc(&dc_lum_vlc[0], DC_VLC_BITS, 120, |
|
1124 |
+ init_vlc(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120, |
|
1125 | 1125 |
&ff_table0_dc_lum[0][1], 8, 4, |
1126 | 1126 |
&ff_table0_dc_lum[0][0], 8, 4, 1); |
1127 |
- init_vlc(&dc_chroma_vlc[0], DC_VLC_BITS, 120, |
|
1127 |
+ init_vlc(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120, |
|
1128 | 1128 |
&ff_table0_dc_chroma[0][1], 8, 4, |
1129 | 1129 |
&ff_table0_dc_chroma[0][0], 8, 4, 1); |
1130 |
- init_vlc(&dc_lum_vlc[1], DC_VLC_BITS, 120, |
|
1130 |
+ init_vlc(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120, |
|
1131 | 1131 |
&ff_table1_dc_lum[0][1], 8, 4, |
1132 | 1132 |
&ff_table1_dc_lum[0][0], 8, 4, 1); |
1133 |
- init_vlc(&dc_chroma_vlc[1], DC_VLC_BITS, 120, |
|
1133 |
+ init_vlc(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120, |
|
1134 | 1134 |
&ff_table1_dc_chroma[0][1], 8, 4, |
1135 | 1135 |
&ff_table1_dc_chroma[0][0], 8, 4, 1); |
1136 | 1136 |
|
... | ... |
@@ -1160,9 +1167,9 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) |
1160 | 1160 |
&wmv2_inter_table[i][0][0], 8, 4, 1); //FIXME name? |
1161 | 1161 |
} |
1162 | 1162 |
|
1163 |
- init_vlc(&mb_intra_vlc, MB_INTRA_VLC_BITS, 64, |
|
1164 |
- &table_mb_intra[0][1], 4, 2, |
|
1165 |
- &table_mb_intra[0][0], 4, 2, 1); |
|
1163 |
+ init_vlc(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64, |
|
1164 |
+ &ff_msmp4_mb_i_table[0][1], 4, 2, |
|
1165 |
+ &ff_msmp4_mb_i_table[0][0], 4, 2, 1); |
|
1166 | 1166 |
|
1167 | 1167 |
init_vlc(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8, |
1168 | 1168 |
intra_MCBPC_bits, 1, 1, |
... | ... |
@@ -1187,6 +1194,8 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) |
1187 | 1187 |
break; |
1188 | 1188 |
case 5: |
1189 | 1189 |
s->decode_mb= wmv2_decode_mb; |
1190 |
+ case 6: |
|
1191 |
+ //FIXME + TODO VC9 decode mb |
|
1190 | 1192 |
break; |
1191 | 1193 |
} |
1192 | 1194 |
|
... | ... |
@@ -1588,7 +1597,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
1588 | 1588 |
} else { |
1589 | 1589 |
set_stat(ST_INTRA_MB); |
1590 | 1590 |
s->mb_intra = 1; |
1591 |
- code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2); |
|
1591 |
+ code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); |
|
1592 | 1592 |
if (code < 0) |
1593 | 1593 |
return -1; |
1594 | 1594 |
/* predict coded block pattern */ |
... | ... |
@@ -1911,9 +1920,9 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) |
1911 | 1911 |
level-=256; |
1912 | 1912 |
}else{ //FIXME optimize use unified tables & index |
1913 | 1913 |
if (n < 4) { |
1914 |
- level = get_vlc2(&s->gb, dc_lum_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
|
1914 |
+ level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
|
1915 | 1915 |
} else { |
1916 |
- level = get_vlc2(&s->gb, dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
|
1916 |
+ level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
|
1917 | 1917 |
} |
1918 | 1918 |
if (level < 0){ |
1919 | 1919 |
av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); |
... | ... |
@@ -4,7 +4,7 @@ |
4 | 4 |
*/ |
5 | 5 |
|
6 | 6 |
/* intra picture macro block coded block pattern */ |
7 |
-static const uint16_t table_mb_intra[64][2] = { |
|
7 |
+const uint16_t ff_msmp4_mb_i_table[64][2] = { |
|
8 | 8 |
{ 0x1, 1 },{ 0x17, 6 },{ 0x9, 5 },{ 0x5, 5 }, |
9 | 9 |
{ 0x6, 5 },{ 0x47, 9 },{ 0x20, 7 },{ 0x10, 7 }, |
10 | 10 |
{ 0x2, 5 },{ 0x7c, 9 },{ 0x3a, 7 },{ 0x1d, 7 }, |
... | ... |
@@ -32,8 +32,14 @@ |
32 | 32 |
#include "avcodec.h" |
33 | 33 |
#include "mpegvideo.h" |
34 | 34 |
#include "vc9data.h" |
35 |
+ |
|
35 | 36 |
extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2]; |
36 | 37 |
extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2]; |
38 |
+extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2]; |
|
39 |
+#define MB_INTRA_VLC_BITS 9 |
|
40 |
+extern VLC ff_msmp4_mb_i_vlc; |
|
41 |
+#define DC_VLC_BITS 9 |
|
42 |
+static const uint16_t table_mb_intra[64][2]; |
|
37 | 43 |
|
38 | 44 |
/* Some inhibiting stuff */ |
39 | 45 |
#define HAS_ADVANCED_PROFILE 1 |
... | ... |
@@ -45,7 +51,7 @@ extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2]; |
45 | 45 |
if (init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, \ |
46 | 46 |
codes, codes_wrap, codes_size, use_static) < 0) \ |
47 | 47 |
{ \ |
48 |
- av_log(v->avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \ |
|
48 |
+ av_log(v->s.avctx, AV_LOG_ERROR, "Error for " # vlc " (%i)\n", i); \ |
|
49 | 49 |
return -1; \ |
50 | 50 |
} |
51 | 51 |
#else |
... | ... |
@@ -134,15 +140,10 @@ static VLC vc9_norm6_vlc; |
134 | 134 |
static VLC vc9_ttmb_vlc[3]; |
135 | 135 |
#define VC9_MV_DIFF_VLC_BITS 9 //15 |
136 | 136 |
static VLC vc9_mv_diff_vlc[4]; |
137 |
-#define VC9_CBPCY_I_VLC_BITS 9 //13 |
|
138 |
-static VLC vc9_cbpcy_i_vlc; |
|
139 | 137 |
#define VC9_CBPCY_P_VLC_BITS 9 //14 |
140 | 138 |
static VLC vc9_cbpcy_p_vlc[4]; |
141 | 139 |
#define VC9_4MV_BLOCK_PATTERN_VLC_BITS 6 |
142 | 140 |
static VLC vc9_4mv_block_pattern_vlc[4]; |
143 |
-#define VC9_DC_VLC_BITS 9 |
|
144 |
-static VLC vc9_luma_dc_vlc[2]; |
|
145 |
-static VLC vc9_chroma_dc_vlc[2]; |
|
146 | 141 |
|
147 | 142 |
//We mainly need data and is_raw, so this struct could be avoided |
148 | 143 |
//to save a level of indirection; feel free to modify |
... | ... |
@@ -155,8 +156,7 @@ typedef struct BitPlane { |
155 | 155 |
|
156 | 156 |
typedef struct VC9Context{ |
157 | 157 |
/* No MpegEnc context, might be good to use it */ |
158 |
- GetBitContext gb; |
|
159 |
- AVCodecContext *avctx; |
|
158 |
+ MpegEncContext s; |
|
160 | 159 |
|
161 | 160 |
/***************************/ |
162 | 161 |
/* Sequence Header */ |
... | ... |
@@ -167,7 +167,6 @@ typedef struct VC9Context{ |
167 | 167 |
int multires; //frame-level RESPIC syntax element present |
168 | 168 |
int res_fasttx; //always 1 |
169 | 169 |
int res_transtab; //always 0 |
170 |
- int syncmarker; //Sync markers presents |
|
171 | 170 |
int rangered; //RANGEREDFRM (range reduction) syntax element present |
172 | 171 |
int res_rtm_flag; //reserved, set to 1 |
173 | 172 |
int reserved; //duh |
... | ... |
@@ -196,8 +195,9 @@ typedef struct VC9Context{ |
196 | 196 |
int loopfilter; |
197 | 197 |
int fastuvmc; //Rounding of qpel vector to hpel ? (not in Simple) |
198 | 198 |
int extended_mv; //Ext MV in P/B (not in Simple) |
199 |
- int dquant; //Q varies with MBs, 2bits (not in Simple) |
|
199 |
+ int dquant; //How qscale varies with MBs, 2bits (not in Simple) |
|
200 | 200 |
int vstransform; //variable-size transform46 |
201 |
+ |
|
201 | 202 |
|
202 | 203 |
int overlap; //overlapped transforms in use |
203 | 204 |
int quantizer_mode; //2, quantizer mode used for sequence, see QUANT_* |
... | ... |
@@ -209,10 +209,8 @@ typedef struct VC9Context{ |
209 | 209 |
/*****************************/ |
210 | 210 |
/* All profiles */ |
211 | 211 |
uint8_t mv_mode, mv_mode2; /* MV coding mode */ |
212 |
- uint8_t pict_type; /* Picture type, mapped on MPEG types */ |
|
213 | 212 |
uint8_t pq, altpq; /* Quantizers */ |
214 | 213 |
uint8_t dquantfrm, dqprofile, dqsbedge, dqbilevel; /* pquant parameters */ |
215 |
- int width_mb, height_mb; |
|
216 | 214 |
int tile; /* 3x2 if (width_mb%3) else 2x3 */ |
217 | 215 |
VLC *luma_ac_vlc, *chroma_ac_vlc, |
218 | 216 |
*luma_dc_vlc, *chroma_dc_vlc; /* transac/dcfrm bits are indexes */ |
... | ... |
@@ -251,7 +249,6 @@ typedef struct VC9Context{ |
251 | 251 |
uint8_t toplefty; |
252 | 252 |
uint8_t bottomrightx; |
253 | 253 |
uint8_t bottomrighty; |
254 |
- uint8_t rndctrl; |
|
255 | 254 |
uint8_t uvsamp; |
256 | 255 |
uint8_t postproc; |
257 | 256 |
int hrd_num_leaky_buckets; |
... | ... |
@@ -299,7 +296,7 @@ static int get_prefix(GetBitContext *gb, int stop, int len) |
299 | 299 |
#endif |
300 | 300 |
} |
301 | 301 |
|
302 |
-static int init_common(VC9Context *v) |
|
302 |
+static int vc9_init_common(VC9Context *v) |
|
303 | 303 |
{ |
304 | 304 |
static int done = 0; |
305 | 305 |
int i; |
... | ... |
@@ -339,24 +336,9 @@ static int init_common(VC9Context *v) |
339 | 339 |
INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64, |
340 | 340 |
vc9_norm6_bits, 1, 1, |
341 | 341 |
vc9_norm6_codes, 2, 2, 1); |
342 |
- INIT_VLC(&vc9_cbpcy_i_vlc, VC9_CBPCY_I_VLC_BITS, 64, |
|
343 |
- vc9_cbpcy_i_bits, 1, 1, |
|
344 |
- vc9_cbpcy_i_codes, 2, 2, 1); |
|
345 | 342 |
INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7, |
346 | 343 |
vc9_imode_bits, 1, 1, |
347 | 344 |
vc9_imode_codes, 1, 1, 1); |
348 |
- INIT_VLC(&vc9_luma_dc_vlc[0], VC9_DC_VLC_BITS, 120, |
|
349 |
- &ff_table0_dc_lum[0][1], 8, 4, |
|
350 |
- &ff_table0_dc_lum[0][0], 8, 4, 1); |
|
351 |
- INIT_VLC(&vc9_chroma_dc_vlc[0], VC9_DC_VLC_BITS, 120, |
|
352 |
- &ff_table0_dc_chroma[0][1], 8, 4, |
|
353 |
- &ff_table0_dc_chroma[0][0], 8, 4, 1); |
|
354 |
- INIT_VLC(&vc9_luma_dc_vlc[1], VC9_DC_VLC_BITS, 120, |
|
355 |
- &ff_table1_dc_lum[0][1], 8, 4, |
|
356 |
- &ff_table1_dc_lum[0][0], 8, 4, 1); |
|
357 |
- INIT_VLC(&vc9_chroma_dc_vlc[1], VC9_DC_VLC_BITS, 120, |
|
358 |
- &ff_table1_dc_chroma[0][1], 8, 4, |
|
359 |
- &ff_table1_dc_chroma[0][0], 8, 4, 1); |
|
360 | 345 |
for (i=0; i<3; i++) |
361 | 346 |
{ |
362 | 347 |
INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16, |
... | ... |
@@ -676,11 +658,11 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) |
676 | 676 |
if (v->profile <= PROFILE_MAIN) |
677 | 677 |
#endif |
678 | 678 |
{ |
679 |
- v->syncmarker = get_bits(gb, 1); |
|
679 |
+ v->s.resync_marker = get_bits(gb, 1); |
|
680 | 680 |
v->rangered = get_bits(gb, 1); |
681 | 681 |
} |
682 | 682 |
|
683 |
- avctx->max_b_frames = get_bits(gb, 3); //common |
|
683 |
+ v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common |
|
684 | 684 |
v->quantizer_mode = get_bits(gb, 2); //common |
685 | 685 |
|
686 | 686 |
#if HAS_ADVANCED_PROFILE |
... | ... |
@@ -703,7 +685,7 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) |
703 | 703 |
"DQuant=%i, Quantizer mode=%i, Max B frames=%i\n", |
704 | 704 |
v->profile, v->frmrtq_postproc, v->bitrtq_postproc, |
705 | 705 |
v->loopfilter, v->multires, v->fastuvmc, v->extended_mv, |
706 |
- v->rangered, v->vstransform, v->overlap, v->syncmarker, |
|
706 |
+ v->rangered, v->vstransform, v->overlap, v->s.resync_marker, |
|
707 | 707 |
v->dquant, v->quantizer_mode, avctx->max_b_frames |
708 | 708 |
); |
709 | 709 |
return 0; |
... | ... |
@@ -778,15 +760,22 @@ int alloc_bitplane(BitPlane *bp, int width, int height) |
778 | 778 |
return 0; |
779 | 779 |
} |
780 | 780 |
|
781 |
+void free_bitplane(BitPlane *bp) |
|
782 |
+{ |
|
783 |
+ bp->width = bp->stride = bp->height = 0; |
|
784 |
+ if (bp->data) av_freep(&bp->data); |
|
785 |
+} |
|
786 |
+ |
|
781 | 787 |
static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
782 | 788 |
int x, y; |
789 |
+ GetBitContext *gb = &v->s.gb; |
|
783 | 790 |
|
784 | 791 |
for (y=0; y<height; y++){ |
785 |
- if (!get_bits(&v->gb, 1)) //rowskip |
|
792 |
+ if (!get_bits(gb, 1)) //rowskip |
|
786 | 793 |
memset(plane, 0, width); |
787 | 794 |
else |
788 | 795 |
for (x=0; x<width; x++) |
789 |
- plane[x] = get_bits(&v->gb, 1); |
|
796 |
+ plane[x] = get_bits(gb, 1); |
|
790 | 797 |
plane += stride; |
791 | 798 |
} |
792 | 799 |
} |
... | ... |
@@ -794,14 +783,15 @@ static void decode_rowskip(uint8_t* plane, int width, int height, int stride, VC |
794 | 794 |
//FIXME optimize |
795 | 795 |
static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ |
796 | 796 |
int x, y; |
797 |
+ GetBitContext *gb = &v->s.gb; |
|
797 | 798 |
|
798 | 799 |
for (x=0; x<width; x++){ |
799 |
- if (!get_bits(&v->gb, 1)) //colskip |
|
800 |
+ if (!get_bits(gb, 1)) //colskip |
|
800 | 801 |
for (y=0; y<height; y++) |
801 | 802 |
plane[y*stride] = 0; |
802 | 803 |
else |
803 | 804 |
for (y=0; y<height; y++) |
804 |
- plane[y*stride] = get_bits(&v->gb, 1); |
|
805 |
+ plane[y*stride] = get_bits(gb, 1); |
|
805 | 806 |
plane ++; |
806 | 807 |
} |
807 | 808 |
} |
... | ... |
@@ -813,11 +803,13 @@ static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC |
813 | 813 |
// later on) |
814 | 814 |
static int bitplane_decoding(BitPlane *bp, VC9Context *v) |
815 | 815 |
{ |
816 |
+ GetBitContext *gb = &v->s.gb; |
|
817 |
+ |
|
816 | 818 |
int imode, x, y, code, use_vertical_tile, tile_w, tile_h; |
817 | 819 |
uint8_t invert, *planep = bp->data; |
818 | 820 |
|
819 |
- invert = get_bits(&v->gb, 1); |
|
820 |
- imode = get_vlc2(&v->gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2); |
|
821 |
+ invert = get_bits(gb, 1); |
|
822 |
+ imode = get_vlc2(gb, vc9_imode_vlc.table, VC9_IMODE_VLC_BITS, 2); |
|
821 | 823 |
|
822 | 824 |
bp->is_raw = 0; |
823 | 825 |
switch (imode) |
... | ... |
@@ -828,9 +820,9 @@ static int bitplane_decoding(BitPlane *bp, VC9Context *v) |
828 | 828 |
return invert; |
829 | 829 |
case IMODE_DIFF2: |
830 | 830 |
case IMODE_NORM2: |
831 |
- if ((bp->height*bp->width) & 1) *(++planep) = get_bits(&v->gb, 1); |
|
831 |
+ if ((bp->height*bp->width) & 1) *(++planep) = get_bits(gb, 1); |
|
832 | 832 |
for(x=0; x<(bp->height*bp->width)>>1; x++){ |
833 |
- code = get_vlc2(&v->gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); |
|
833 |
+ code = get_vlc2(gb, vc9_norm2_vlc.table, VC9_NORM2_VLC_BITS, 2); |
|
834 | 834 |
*(++planep) = code&1; //lsb => left |
835 | 835 |
*(++planep) = code&2; //msb => right - bitplane => only !0 matters |
836 | 836 |
//FIXME width->stride |
... | ... |
@@ -844,9 +836,9 @@ static int bitplane_decoding(BitPlane *bp, VC9Context *v) |
844 | 844 |
|
845 | 845 |
for(y= bp->height%tile_h; y< bp->height; y+=tile_h){ |
846 | 846 |
for(x= bp->width%tile_w; x< bp->width; x+=tile_w){ |
847 |
- code = get_vlc2(&v->gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2); |
|
847 |
+ code = get_vlc2(gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2); |
|
848 | 848 |
if(code<0){ |
849 |
- av_log(v->avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n"); |
|
849 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "inavlid NORM-6 VLC\n"); |
|
850 | 850 |
return -1; |
851 | 851 |
} |
852 | 852 |
//FIXME following is a pure guess and probably wrong |
... | ... |
@@ -912,35 +904,36 @@ static int bitplane_decoding(BitPlane *bp, VC9Context *v) |
912 | 912 |
/*****************************************************************************/ |
913 | 913 |
static int vop_dquant_decoding(VC9Context *v) |
914 | 914 |
{ |
915 |
+ GetBitContext *gb = &v->s.gb; |
|
915 | 916 |
int pqdiff; |
916 | 917 |
|
917 | 918 |
//variable size |
918 | 919 |
if (v->dquant == 2) |
919 | 920 |
{ |
920 |
- pqdiff = get_bits(&v->gb, 3); |
|
921 |
- if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5); |
|
921 |
+ pqdiff = get_bits(gb, 3); |
|
922 |
+ if (pqdiff == 7) v->altpq = get_bits(gb, 5); |
|
922 | 923 |
else v->altpq = v->pq + pqdiff + 1; |
923 | 924 |
} |
924 | 925 |
else |
925 | 926 |
{ |
926 |
- v->dquantfrm = get_bits(&v->gb, 1); |
|
927 |
+ v->dquantfrm = get_bits(gb, 1); |
|
927 | 928 |
if ( v->dquantfrm ) |
928 | 929 |
{ |
929 |
- v->dqprofile = get_bits(&v->gb, 2); |
|
930 |
+ v->dqprofile = get_bits(gb, 2); |
|
930 | 931 |
switch (v->dqprofile) |
931 | 932 |
{ |
932 | 933 |
case DQPROFILE_SINGLE_EDGE: |
933 | 934 |
case DQPROFILE_DOUBLE_EDGES: |
934 |
- v->dqsbedge = get_bits(&v->gb, 2); |
|
935 |
+ v->dqsbedge = get_bits(gb, 2); |
|
935 | 936 |
break; |
936 | 937 |
case DQPROFILE_ALL_MBS: |
937 |
- v->dqbilevel = get_bits(&v->gb, 1); |
|
938 |
+ v->dqbilevel = get_bits(gb, 1); |
|
938 | 939 |
default: break; //Forbidden ? |
939 | 940 |
} |
940 | 941 |
if (!v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) |
941 | 942 |
{ |
942 |
- pqdiff = get_bits(&v->gb, 3); |
|
943 |
- if (pqdiff == 7) v->altpq = get_bits(&v->gb, 5); |
|
943 |
+ pqdiff = get_bits(gb, 3); |
|
944 |
+ if (pqdiff == 7) v->altpq = get_bits(gb, 5); |
|
944 | 945 |
else v->altpq = v->pq + pqdiff + 1; |
945 | 946 |
} |
946 | 947 |
} |
... | ... |
@@ -961,38 +954,40 @@ static int decode_bi_picture_header(VC9Context *v) |
961 | 961 |
- for A Profile, PTYPE already tells so and we can go |
962 | 962 |
directly there |
963 | 963 |
*/ |
964 |
+ GetBitContext *gb = &v->s.gb; |
|
964 | 965 |
int pqindex; |
965 | 966 |
|
966 | 967 |
/* Read the quantization stuff */ |
967 |
- pqindex = get_bits(&v->gb, 5); |
|
968 |
+ pqindex = get_bits(gb, 5); |
|
968 | 969 |
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
969 | 970 |
v->pq = pquant_table[0][pqindex]; |
970 | 971 |
else |
971 | 972 |
{ |
972 | 973 |
v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
973 | 974 |
} |
974 |
- if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
|
975 |
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1); |
|
975 | 976 |
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
976 |
- v->pquantizer = get_bits(&v->gb, 1); |
|
977 |
+ v->pquantizer = get_bits(gb, 1); |
|
977 | 978 |
|
978 | 979 |
/* Read the MV type/mode */ |
979 | 980 |
if (v->extended_mv == 1) |
980 |
- v->mvrange = get_prefix(&v->gb, 0, 3); |
|
981 |
+ v->mvrange = get_prefix(gb, 0, 3); |
|
981 | 982 |
|
982 | 983 |
/* FIXME: what table are used in that case ? */ |
983 | 984 |
v->mv_diff_vlc = &vc9_mv_diff_vlc[0]; |
984 |
- v->cbpcy_vlc = &vc9_cbpcy_i_vlc; |
|
985 |
+ v->cbpcy_vlc = &ff_msmp4_mb_i_vlc; |
|
985 | 986 |
|
986 |
- av_log(v->avctx, AV_LOG_DEBUG, "B frame, QP=%i\n", v->pq); |
|
987 |
- av_log(v->avctx, AV_LOG_ERROR, "BI_TYPE not supported yet\n"); |
|
987 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "B frame, QP=%i\n", v->pq); |
|
988 |
+ av_log(v->s.avctx, AV_LOG_ERROR, "BI_TYPE not supported yet\n"); |
|
988 | 989 |
/* Epilog should be done in caller */ |
989 | 990 |
return -1; |
990 | 991 |
} |
991 | 992 |
|
992 | 993 |
/* Tables 11+12, p62-65 */ |
993 |
-static int decode_b_picture_header(VC9Context *v) |
|
994 |
+static int decode_b_picture_primary_header(VC9Context *v) |
|
994 | 995 |
{ |
995 |
- int pqindex, status; |
|
996 |
+ GetBitContext *gb = &v->s.gb; |
|
997 |
+ int pqindex, status; |
|
996 | 998 |
|
997 | 999 |
/* Prolog common to all frametypes should be done in caller */ |
998 | 1000 |
if (v->profile == PROFILE_SIMPLE) |
... | ... |
@@ -1001,7 +996,7 @@ static int decode_b_picture_header(VC9Context *v) |
1001 | 1001 |
return FRAME_SKIPED; |
1002 | 1002 |
} |
1003 | 1003 |
|
1004 |
- v->bfraction = vc9_bfraction_lut[get_vlc2(&v->gb, vc9_bfraction_vlc.table, |
|
1004 |
+ v->bfraction = vc9_bfraction_lut[get_vlc2(gb, vc9_bfraction_vlc.table, |
|
1005 | 1005 |
VC9_BFRACTION_VLC_BITS, 2)]; |
1006 | 1006 |
if (v->bfraction < -1) |
1007 | 1007 |
{ |
... | ... |
@@ -1015,26 +1010,26 @@ static int decode_b_picture_header(VC9Context *v) |
1015 | 1015 |
} |
1016 | 1016 |
|
1017 | 1017 |
/* Read the quantization stuff */ |
1018 |
- pqindex = get_bits(&v->gb, 5); |
|
1018 |
+ pqindex = get_bits(gb, 5); |
|
1019 | 1019 |
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
1020 | 1020 |
v->pq = pquant_table[0][pqindex]; |
1021 | 1021 |
else |
1022 | 1022 |
{ |
1023 | 1023 |
v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
1024 | 1024 |
} |
1025 |
- if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
|
1025 |
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1); |
|
1026 | 1026 |
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
1027 |
- v->pquantizer = get_bits(&v->gb, 1); |
|
1027 |
+ v->pquantizer = get_bits(gb, 1); |
|
1028 | 1028 |
|
1029 | 1029 |
/* Read the MV type/mode */ |
1030 | 1030 |
if (v->extended_mv == 1) |
1031 |
- v->mvrange = get_prefix(&v->gb, 0, 3); |
|
1032 |
- v->mv_mode = get_bits(&v->gb, 1); |
|
1031 |
+ v->mvrange = get_prefix(gb, 0, 3); |
|
1032 |
+ v->mv_mode = get_bits(gb, 1); |
|
1033 | 1033 |
if (v->pq < 13) |
1034 | 1034 |
{ |
1035 | 1035 |
if (!v->mv_mode) |
1036 | 1036 |
{ |
1037 |
- v->mv_mode = get_bits(&v->gb, 2); |
|
1037 |
+ v->mv_mode = get_bits(gb, 2); |
|
1038 | 1038 |
if (v->mv_mode) |
1039 | 1039 |
av_log(v, AV_LOG_ERROR, |
1040 | 1040 |
"mv_mode for lowquant B frame was %i\n", v->mv_mode); |
... | ... |
@@ -1044,20 +1039,31 @@ static int decode_b_picture_header(VC9Context *v) |
1044 | 1044 |
{ |
1045 | 1045 |
if (!v->mv_mode) |
1046 | 1046 |
{ |
1047 |
- if (get_bits(&v->gb, 1)) |
|
1047 |
+ if (get_bits(gb, 1)) |
|
1048 | 1048 |
av_log(v, AV_LOG_ERROR, |
1049 | 1049 |
"mv_mode for highquant B frame was %i\n", v->mv_mode); |
1050 | 1050 |
} |
1051 | 1051 |
v->mv_mode = 1-v->mv_mode; //To match (pq < 13) mapping |
1052 | 1052 |
} |
1053 | 1053 |
|
1054 |
+ return 0; |
|
1055 |
+} |
|
1056 |
+ |
|
1057 |
+static int decode_b_picture_secondary_header(VC9Context *v) |
|
1058 |
+{ |
|
1059 |
+ GetBitContext *gb = &v->s.gb; |
|
1060 |
+ int status; |
|
1061 |
+ |
|
1062 |
+ bitplane_decoding(&v->skip_mb_plane, v); |
|
1063 |
+ if (status < 0) return -1; |
|
1064 |
+#if TRACE |
|
1054 | 1065 |
if (v->mv_mode == MV_PMODE_MIXED_MV) |
1055 | 1066 |
{ |
1056 | 1067 |
status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1057 | 1068 |
if (status < 0) |
1058 | 1069 |
return -1; |
1059 | 1070 |
#if TRACE |
1060 |
- av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " |
|
1071 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " |
|
1061 | 1072 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1062 | 1073 |
#endif |
1063 | 1074 |
} |
... | ... |
@@ -1066,20 +1072,17 @@ static int decode_b_picture_header(VC9Context *v) |
1066 | 1066 |
status = bitplane_decoding(&v->direct_mb_plane, v); |
1067 | 1067 |
if (status < 0) return -1; |
1068 | 1068 |
#if TRACE |
1069 |
- av_log(v->avctx, AV_LOG_DEBUG, "MB Direct plane encoding: " |
|
1069 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct plane encoding: " |
|
1070 | 1070 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1071 | 1071 |
#endif |
1072 | 1072 |
|
1073 |
- bitplane_decoding(&v->skip_mb_plane, v); |
|
1074 |
- if (status < 0) return -1; |
|
1075 |
-#if TRACE |
|
1076 |
- av_log(v->avctx, AV_LOG_DEBUG, "Skip MB plane encoding: " |
|
1073 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "Skip MB plane encoding: " |
|
1077 | 1074 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1078 | 1075 |
#endif |
1079 | 1076 |
|
1080 | 1077 |
/* FIXME: what is actually chosen for B frames ? */ |
1081 |
- v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)]; |
|
1082 |
- v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)]; |
|
1078 |
+ v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(gb, 2)]; |
|
1079 |
+ v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)]; |
|
1083 | 1080 |
if (v->dquant) |
1084 | 1081 |
{ |
1085 | 1082 |
vop_dquant_decoding(v); |
... | ... |
@@ -1087,10 +1090,10 @@ static int decode_b_picture_header(VC9Context *v) |
1087 | 1087 |
|
1088 | 1088 |
if (v->vstransform) |
1089 | 1089 |
{ |
1090 |
- v->ttmbf = get_bits(&v->gb, 1); |
|
1090 |
+ v->ttmbf = get_bits(gb, 1); |
|
1091 | 1091 |
if (v->ttmbf) |
1092 | 1092 |
{ |
1093 |
- v->ttfrm = get_bits(&v->gb, 2); |
|
1093 |
+ v->ttfrm = get_bits(gb, 2); |
|
1094 | 1094 |
av_log(v, AV_LOG_INFO, "Transform used: %ix%i\n", |
1095 | 1095 |
(v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); |
1096 | 1096 |
} |
... | ... |
@@ -1102,53 +1105,54 @@ static int decode_b_picture_header(VC9Context *v) |
1102 | 1102 |
/* Tables 5+7, p53-54 and 55-57 */ |
1103 | 1103 |
static int decode_i_picture_header(VC9Context *v) |
1104 | 1104 |
{ |
1105 |
- int pqindex, status = 0, ac_pred; |
|
1105 |
+ GetBitContext *gb = &v->s.gb; |
|
1106 |
+ int pqindex, status = 0; |
|
1106 | 1107 |
|
1107 | 1108 |
/* Prolog common to all frametypes should be done in caller */ |
1108 | 1109 |
//BF = Buffer Fullness |
1109 |
- if (v->profile <= PROFILE_MAIN && get_bits(&v->gb, 7)) |
|
1110 |
+ if (v->profile <= PROFILE_MAIN && get_bits(gb, 7)) |
|
1110 | 1111 |
{ |
1111 | 1112 |
av_log(v, AV_LOG_DEBUG, "I BufferFullness not 0\n"); |
1112 | 1113 |
} |
1113 | 1114 |
|
1114 | 1115 |
/* Quantizer stuff */ |
1115 |
- pqindex = get_bits(&v->gb, 5); |
|
1116 |
+ pqindex = get_bits(gb, 5); |
|
1116 | 1117 |
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
1117 | 1118 |
v->pq = pquant_table[0][pqindex]; |
1118 | 1119 |
else |
1119 | 1120 |
{ |
1120 | 1121 |
v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
1121 | 1122 |
} |
1122 |
- if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
|
1123 |
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1); |
|
1123 | 1124 |
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
1124 |
- v->pquantizer = get_bits(&v->gb, 1); |
|
1125 |
- av_log(v->avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n", |
|
1125 |
+ v->pquantizer = get_bits(gb, 1); |
|
1126 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "I frame: QP=%i (+%i/2)\n", |
|
1126 | 1127 |
v->pq, v->halfpq); |
1127 | 1128 |
#if HAS_ADVANCED_PROFILE |
1128 | 1129 |
if (v->profile <= PROFILE_MAIN) |
1129 | 1130 |
#endif |
1130 | 1131 |
{ |
1131 |
- if (v->extended_mv) v->mvrange = get_prefix(&v->gb, 0, 3); |
|
1132 |
- if (v->multires) v->respic = get_bits(&v->gb, 2); |
|
1132 |
+ if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3); |
|
1133 |
+ if (v->multires) v->respic = get_bits(gb, 2); |
|
1133 | 1134 |
} |
1134 | 1135 |
#if HAS_ADVANCED_PROFILE |
1135 | 1136 |
else |
1136 | 1137 |
{ |
1137 |
- ac_pred = get_bits(&v->gb, 1); |
|
1138 |
- if (v->postprocflag) v->postproc = get_bits(&v->gb, 1); |
|
1138 |
+ v->s.ac_pred = get_bits(gb, 1); |
|
1139 |
+ if (v->postprocflag) v->postproc = get_bits(gb, 1); |
|
1139 | 1140 |
/* 7.1.1.34 + 8.5.2 */ |
1140 | 1141 |
if (v->overlap && v->pq<9) |
1141 | 1142 |
{ |
1142 |
- v->condover = get_bits(&v->gb, 1); |
|
1143 |
+ v->condover = get_bits(gb, 1); |
|
1143 | 1144 |
if (v->condover) |
1144 | 1145 |
{ |
1145 |
- v->condover = 2+get_bits(&v->gb, 1); |
|
1146 |
+ v->condover = 2+get_bits(gb, 1); |
|
1146 | 1147 |
if (v->condover == 3) |
1147 | 1148 |
{ |
1148 | 1149 |
status = bitplane_decoding(&v->over_flags_plane, v); |
1149 | 1150 |
if (status < 0) return -1; |
1150 | 1151 |
#if TRACE |
1151 |
- av_log(v->avctx, AV_LOG_DEBUG, "Overflags plane encoding: " |
|
1152 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "Overflags plane encoding: " |
|
1152 | 1153 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1153 | 1154 |
#endif |
1154 | 1155 |
} |
... | ... |
@@ -1162,41 +1166,48 @@ static int decode_i_picture_header(VC9Context *v) |
1162 | 1162 |
} |
1163 | 1163 |
|
1164 | 1164 |
/* Table 9, p58-60 */ |
1165 |
-static int decode_p_picture_header(VC9Context *v) |
|
1165 |
+static int decode_p_picture_primary_header(VC9Context *v) |
|
1166 | 1166 |
{ |
1167 | 1167 |
/* INTERFRM, FRMCNT, RANGEREDFRM read in caller */ |
1168 |
+ GetBitContext *gb = &v->s.gb; |
|
1168 | 1169 |
int lowquant, pqindex, status = 0; |
1169 | 1170 |
|
1170 |
- pqindex = get_bits(&v->gb, 5); |
|
1171 |
+ pqindex = get_bits(gb, 5); |
|
1171 | 1172 |
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) |
1172 | 1173 |
v->pq = pquant_table[0][pqindex]; |
1173 | 1174 |
else |
1174 | 1175 |
{ |
1175 | 1176 |
v->pq = pquant_table[v->quantizer_mode-1][pqindex]; |
1176 | 1177 |
} |
1177 |
- if (pqindex < 9) v->halfpq = get_bits(&v->gb, 1); |
|
1178 |
+ if (pqindex < 9) v->halfpq = get_bits(gb, 1); |
|
1178 | 1179 |
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) |
1179 |
- v->pquantizer = get_bits(&v->gb, 1); |
|
1180 |
- av_log(v->avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n", |
|
1180 |
+ v->pquantizer = get_bits(gb, 1); |
|
1181 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "P Frame: QP=%i (+%i/2)\n", |
|
1181 | 1182 |
v->pq, v->halfpq); |
1182 |
- if (v->extended_mv == 1) v->mvrange = get_prefix(&v->gb, 0, 3); |
|
1183 |
+ if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3); |
|
1183 | 1184 |
#if HAS_ADVANCED_PROFILE |
1184 | 1185 |
if (v->profile > PROFILE_MAIN) |
1185 | 1186 |
{ |
1186 |
- if (v->postprocflag) v->postproc = get_bits(&v->gb, 1); |
|
1187 |
+ if (v->postprocflag) v->postproc = get_bits(gb, 1); |
|
1187 | 1188 |
} |
1188 | 1189 |
else |
1189 | 1190 |
#endif |
1190 |
- if (v->multires) v->respic = get_bits(&v->gb, 2); |
|
1191 |
+ if (v->multires) v->respic = get_bits(gb, 2); |
|
1191 | 1192 |
lowquant = (v->pquantizer>12) ? 0 : 1; |
1192 |
- v->mv_mode = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 4)]; |
|
1193 |
+ v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)]; |
|
1193 | 1194 |
if (v->mv_mode == MV_PMODE_INTENSITY_COMP) |
1194 | 1195 |
{ |
1195 |
- v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(&v->gb, 1, 3)]; |
|
1196 |
- v->lumscale = get_bits(&v->gb, 6); |
|
1197 |
- v->lumshift = get_bits(&v->gb, 6); |
|
1196 |
+ v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)]; |
|
1197 |
+ v->lumscale = get_bits(gb, 6); |
|
1198 |
+ v->lumshift = get_bits(gb, 6); |
|
1198 | 1199 |
} |
1200 |
+ return 0; |
|
1201 |
+} |
|
1199 | 1202 |
|
1203 |
+static int decode_p_picture_secondary_header(VC9Context *v) |
|
1204 |
+{ |
|
1205 |
+ GetBitContext *gb = &v->s.gb; |
|
1206 |
+ int status = 0; |
|
1200 | 1207 |
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && |
1201 | 1208 |
v->mv_mode2 == MV_PMODE_MIXED_MV) |
1202 | 1209 |
|| v->mv_mode == MV_PMODE_MIXED_MV) |
... | ... |
@@ -1204,7 +1215,7 @@ static int decode_p_picture_header(VC9Context *v) |
1204 | 1204 |
status = bitplane_decoding(&v->mv_type_mb_plane, v); |
1205 | 1205 |
if (status < 0) return -1; |
1206 | 1206 |
#if TRACE |
1207 |
- av_log(v->avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " |
|
1207 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " |
|
1208 | 1208 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1209 | 1209 |
#endif |
1210 | 1210 |
} |
... | ... |
@@ -1212,27 +1223,27 @@ static int decode_p_picture_header(VC9Context *v) |
1212 | 1212 |
status = bitplane_decoding(&v->skip_mb_plane, v); |
1213 | 1213 |
if (status < 0) return -1; |
1214 | 1214 |
#if TRACE |
1215 |
- av_log(v->avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " |
|
1215 |
+ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " |
|
1216 | 1216 |
"Imode: %i, Invert: %i\n", status>>1, status&1); |
1217 | 1217 |
#endif |
1218 | 1218 |
|
1219 | 1219 |
/* Hopefully this is correct for P frames */ |
1220 |
- v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(&v->gb, 2)]; |
|
1221 |
- v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(&v->gb, 2)]; |
|
1220 |
+ v->mv_diff_vlc = &vc9_mv_diff_vlc[get_bits(gb, 2)]; |
|
1221 |
+ v->cbpcy_vlc = &vc9_cbpcy_p_vlc[get_bits(gb, 2)]; |
|
1222 | 1222 |
|
1223 | 1223 |
if (v->dquant) |
1224 | 1224 |
{ |
1225 |
- av_log(v->avctx, AV_LOG_INFO, "VOP DQuant info\n"); |
|
1225 |
+ av_log(v->s.avctx, AV_LOG_INFO, "VOP DQuant info\n"); |
|
1226 | 1226 |
vop_dquant_decoding(v); |
1227 | 1227 |
} |
1228 | 1228 |
|
1229 | 1229 |
if (v->vstransform) |
1230 | 1230 |
{ |
1231 |
- v->ttmbf = get_bits(&v->gb, 1); |
|
1231 |
+ v->ttmbf = get_bits(gb, 1); |
|
1232 | 1232 |
if (v->ttmbf) |
1233 | 1233 |
{ |
1234 |
- v->ttfrm = get_bits(&v->gb, 2); |
|
1235 |
- av_log(v->avctx, AV_LOG_INFO, "Transform used: %ix%i\n", |
|
1234 |
+ v->ttfrm = get_bits(gb, 2); |
|
1235 |
+ av_log(v->s.avctx, AV_LOG_INFO, "Transform used: %ix%i\n", |
|
1236 | 1236 |
(v->ttfrm & 2) ? 4 : 8, (v->ttfrm & 1) ? 4 : 8); |
1237 | 1237 |
} |
1238 | 1238 |
} |
... | ... |
@@ -1241,27 +1252,28 @@ static int decode_p_picture_header(VC9Context *v) |
1241 | 1241 |
} |
1242 | 1242 |
|
1243 | 1243 |
|
1244 |
-static int standard_decode_picture_header(VC9Context *v) |
|
1244 |
+static int standard_decode_picture_primary_header(VC9Context *v) |
|
1245 | 1245 |
{ |
1246 |
- int status = 0, index; |
|
1246 |
+ GetBitContext *gb = &v->s.gb; |
|
1247 |
+ int status = 0; |
|
1247 | 1248 |
|
1248 |
- if (v->finterpflag) v->interpfrm = get_bits(&v->gb, 1); |
|
1249 |
- skip_bits(&v->gb, 2); //framecnt unused |
|
1250 |
- if (v->rangered) v->rangeredfrm = get_bits(&v->gb, 1); |
|
1251 |
- v->pict_type = get_bits(&v->gb, 1); |
|
1252 |
- if (v->avctx->max_b_frames && !v->pict_type) |
|
1249 |
+ if (v->finterpflag) v->interpfrm = get_bits(gb, 1); |
|
1250 |
+ skip_bits(gb, 2); //framecnt unused |
|
1251 |
+ if (v->rangered) v->rangeredfrm = get_bits(gb, 1); |
|
1252 |
+ v->s.pict_type = get_bits(gb, 1); |
|
1253 |
+ if (v->s.avctx->max_b_frames && !v->s.pict_type) |
|
1253 | 1254 |
{ |
1254 |
- if (get_bits(&v->gb, 1)) v->pict_type = I_TYPE; |
|
1255 |
- else v->pict_type = P_TYPE; |
|
1255 |
+ if (get_bits(gb, 1)) v->s.pict_type = I_TYPE; |
|
1256 |
+ else v->s.pict_type = P_TYPE; |
|
1256 | 1257 |
} |
1257 |
- else v->pict_type++; //P_TYPE |
|
1258 |
+ else v->s.pict_type++; //P_TYPE |
|
1258 | 1259 |
|
1259 |
- switch (v->pict_type) |
|
1260 |
+ switch (v->s.pict_type) |
|
1260 | 1261 |
{ |
1261 | 1262 |
case I_TYPE: status = decode_i_picture_header(v); break; |
1262 |
- case BI_TYPE: status = decode_b_picture_header(v); break; |
|
1263 |
- case P_TYPE: status = decode_p_picture_header(v); break; |
|
1264 |
- case B_TYPE: status = decode_b_picture_header(v); break; |
|
1263 |
+ case BI_TYPE: status = decode_bi_picture_header(v); break; |
|
1264 |
+ case P_TYPE: status = decode_p_picture_primary_header(v); break; |
|
1265 |
+ case B_TYPE: status = decode_b_picture_primary_header(v); break; |
|
1265 | 1266 |
} |
1266 | 1267 |
|
1267 | 1268 |
if (status == FRAME_SKIPED) |
... | ... |
@@ -1269,21 +1281,34 @@ static int standard_decode_picture_header(VC9Context *v) |
1269 | 1269 |
av_log(v, AV_LOG_INFO, "Skipping frame...\n"); |
1270 | 1270 |
return status; |
1271 | 1271 |
} |
1272 |
+ return 0; |
|
1273 |
+} |
|
1274 |
+ |
|
1275 |
+static int standard_decode_picture_secondary_header(VC9Context *v) |
|
1276 |
+{ |
|
1277 |
+ GetBitContext *gb = &v->s.gb; |
|
1278 |
+ int status = 0, index; |
|
1279 |
+ |
|
1280 |
+ switch (v->s.pict_type) |
|
1281 |
+ { |
|
1282 |
+ case P_TYPE: status = decode_p_picture_secondary_header(v); break; |
|
1283 |
+ case B_TYPE: status = decode_b_picture_secondary_header(v); break; |
|
1284 |
+ } |
|
1272 | 1285 |
|
1273 | 1286 |
/* AC Syntax */ |
1274 |
- index = decode012(&v->gb); |
|
1287 |
+ index = decode012(gb); |
|
1275 | 1288 |
v->luma_ac_vlc = NULL + index; //FIXME Add AC table |
1276 | 1289 |
v->chroma_ac_vlc = NULL + index; |
1277 |
- if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE) |
|
1290 |
+ if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) |
|
1278 | 1291 |
{ |
1279 |
- index = decode012(&v->gb); |
|
1292 |
+ index = decode012(gb); |
|
1280 | 1293 |
v->luma_ac2_vlc = NULL + index; //FIXME Add AC2 table |
1281 | 1294 |
v->chroma_ac2_vlc = NULL + index; |
1282 | 1295 |
} |
1283 | 1296 |
/* DC Syntax */ |
1284 |
- index = decode012(&v->gb); |
|
1285 |
- v->luma_dc_vlc = vc9_luma_dc_vlc + index; |
|
1286 |
- v->chroma_dc_vlc = vc9_chroma_dc_vlc + index; |
|
1297 |
+ index = decode012(gb); |
|
1298 |
+ v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index]; |
|
1299 |
+ v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index]; |
|
1287 | 1300 |
|
1288 | 1301 |
return 0; |
1289 | 1302 |
} |
... | ... |
@@ -1293,30 +1318,31 @@ static int standard_decode_picture_header(VC9Context *v) |
1293 | 1293 |
/******************************************************************************/ |
1294 | 1294 |
/* Advanced Profile picture header decoding specific functions */ |
1295 | 1295 |
/******************************************************************************/ |
1296 |
-static int advanced_decode_picture_header(VC9Context *v) |
|
1296 |
+static int advanced_decode_picture_primary_header(VC9Context *v) |
|
1297 | 1297 |
{ |
1298 |
+ GetBitContext *gb = &v->s.gb; |
|
1298 | 1299 |
static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE }; |
1299 |
- int type, i, index; |
|
1300 |
+ int type, i; |
|
1300 | 1301 |
|
1301 | 1302 |
if (v->interlace) |
1302 | 1303 |
{ |
1303 |
- v->fcm = get_bits(&v->gb, 1); |
|
1304 |
- if (v->fcm) v->fcm = 2+get_bits(&v->gb, 1); |
|
1304 |
+ v->fcm = get_bits(gb, 1); |
|
1305 |
+ if (v->fcm) v->fcm = 2+get_bits(gb, 1); |
|
1305 | 1306 |
} |
1306 | 1307 |
|
1307 |
- type = get_prefix(&v->gb, 0, 4); |
|
1308 |
+ type = get_prefix(gb, 0, 4); |
|
1308 | 1309 |
if (type > 4 || type < 0) return FRAME_SKIPED; |
1309 |
- v->pict_type = type_table[type]; |
|
1310 |
- av_log(v->avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->pict_type); |
|
1310 |
+ v->s.pict_type = type_table[type]; |
|
1311 |
+ av_log(v->s.avctx, AV_LOG_INFO, "AP Frame Type: %i\n", v->s.pict_type); |
|
1311 | 1312 |
|
1312 |
- if (v->tfcntrflag) v->tfcntr = get_bits(&v->gb, 8); |
|
1313 |
+ if (v->tfcntrflag) v->tfcntr = get_bits(gb, 8); |
|
1313 | 1314 |
if (v->broadcast) |
1314 | 1315 |
{ |
1315 |
- if (!v->interlace) v->rptfrm = get_bits(&v->gb, 2); |
|
1316 |
+ if (!v->interlace) v->rptfrm = get_bits(gb, 2); |
|
1316 | 1317 |
else |
1317 | 1318 |
{ |
1318 |
- v->tff = get_bits(&v->gb, 1); |
|
1319 |
- v->rff = get_bits(&v->gb, 1); |
|
1319 |
+ v->tff = get_bits(gb, 1); |
|
1320 |
+ v->rff = get_bits(gb, 1); |
|
1320 | 1321 |
} |
1321 | 1322 |
} |
1322 | 1323 |
|
... | ... |
@@ -1325,42 +1351,56 @@ static int advanced_decode_picture_header(VC9Context *v) |
1325 | 1325 |
#if 0 |
1326 | 1326 |
for (i=0; i<v->numpanscanwin; i++) |
1327 | 1327 |
{ |
1328 |
- v->topleftx[i] = get_bits(&v->gb, 16); |
|
1329 |
- v->toplefty[i] = get_bits(&v->gb, 16); |
|
1330 |
- v->bottomrightx[i] = get_bits(&v->gb, 16); |
|
1331 |
- v->bottomrighty[i] = get_bits(&v->gb, 16); |
|
1328 |
+ v->topleftx[i] = get_bits(gb, 16); |
|
1329 |
+ v->toplefty[i] = get_bits(gb, 16); |
|
1330 |
+ v->bottomrightx[i] = get_bits(gb, 16); |
|
1331 |
+ v->bottomrighty[i] = get_bits(gb, 16); |
|
1332 | 1332 |
} |
1333 | 1333 |
#else |
1334 |
- skip_bits(&v->gb, 16*4*v->numpanscanwin); |
|
1334 |
+ skip_bits(gb, 16*4*v->numpanscanwin); |
|
1335 | 1335 |
#endif |
1336 | 1336 |
} |
1337 |
- v->rndctrl = get_bits(&v->gb, 1); |
|
1338 |
- v->uvsamp = get_bits(&v->gb, 1); |
|
1339 |
- if (v->finterpflag == 1) v->interpfrm = get_bits(&v->gb, 1); |
|
1337 |
+ v->s.no_rounding = !get_bits(gb, 1); |
|
1338 |
+ v->uvsamp = get_bits(gb, 1); |
|
1339 |
+ if (v->finterpflag == 1) v->interpfrm = get_bits(gb, 1); |
|
1340 | 1340 |
|
1341 |
- switch(v->pict_type) |
|
1341 |
+ switch(v->s.pict_type) |
|
1342 | 1342 |
{ |
1343 | 1343 |
case I_TYPE: if (decode_i_picture_header(v) < 0) return -1; |
1344 |
- case P_TYPE: if (decode_p_picture_header(v) < 0) return -1; |
|
1344 |
+ case P_TYPE: if (decode_p_picture_primary_header(v) < 0) return -1; |
|
1345 | 1345 |
case BI_TYPE: |
1346 |
- case B_TYPE: if (decode_b_picture_header(v) < 0) return FRAME_SKIPED; |
|
1346 |
+ case B_TYPE: if (decode_b_picture_primary_header(v) < 0) return FRAME_SKIPED; |
|
1347 |
+ default: break; |
|
1348 |
+ } |
|
1349 |
+ return 0; |
|
1350 |
+} |
|
1351 |
+ |
|
1352 |
+static int advanced_decode_picture_secondary_header(VC9Context *v) |
|
1353 |
+{ |
|
1354 |
+ GetBitContext *gb = &v->s.gb; |
|
1355 |
+ int index; |
|
1356 |
+ |
|
1357 |
+ switch(v->s.pict_type) |
|
1358 |
+ { |
|
1359 |
+ case P_TYPE: if (decode_p_picture_secondary_header(v) < 0) return -1; |
|
1360 |
+ case B_TYPE: if (decode_b_picture_secondary_header(v) < 0) return FRAME_SKIPED; |
|
1347 | 1361 |
default: break; |
1348 | 1362 |
} |
1349 | 1363 |
|
1350 | 1364 |
/* AC Syntax */ |
1351 |
- index = decode012(&v->gb); |
|
1365 |
+ index = decode012(gb); |
|
1352 | 1366 |
v->luma_ac_vlc = NULL + index; //FIXME |
1353 | 1367 |
v->chroma_ac_vlc = NULL + index; //FIXME |
1354 |
- if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE) |
|
1368 |
+ if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) |
|
1355 | 1369 |
{ |
1356 |
- index = decode012(&v->gb); //FIXME |
|
1370 |
+ index = decode012(gb); //FIXME |
|
1357 | 1371 |
v->luma_ac2_vlc = NULL + index; |
1358 | 1372 |
v->chroma_ac2_vlc = NULL + index; |
1359 | 1373 |
} |
1360 | 1374 |
/* DC Syntax */ |
1361 |
- index = decode012(&v->gb); |
|
1362 |
- v->luma_dc_vlc = vc9_luma_dc_vlc + index; |
|
1363 |
- v->chroma_dc_vlc = vc9_chroma_dc_vlc + index; |
|
1375 |
+ index = decode012(gb); |
|
1376 |
+ v->luma_dc_vlc = &ff_msmp4_dc_luma_vlc[index]; |
|
1377 |
+ v->chroma_dc_vlc = &ff_msmp4_dc_chroma_vlc[index]; |
|
1364 | 1378 |
|
1365 | 1379 |
return 0; |
1366 | 1380 |
} |
... | ... |
@@ -1373,27 +1413,28 @@ static int advanced_decode_picture_header(VC9Context *v) |
1373 | 1373 |
/* FIXME proper integration (unusable and lots of parameters to send */ |
1374 | 1374 |
int decode_luma_intra_block(VC9Context *v, int mquant) |
1375 | 1375 |
{ |
1376 |
+ GetBitContext *gb = &v->s.gb; |
|
1376 | 1377 |
int dcdiff; |
1377 | 1378 |
|
1378 |
- dcdiff = get_vlc2(&v->gb, v->luma_dc_vlc->table, |
|
1379 |
- VC9_DC_VLC_BITS, 2); |
|
1379 |
+ dcdiff = get_vlc2(gb, v->luma_dc_vlc->table, |
|
1380 |
+ DC_VLC_BITS, 2); |
|
1380 | 1381 |
if (dcdiff) |
1381 | 1382 |
{ |
1382 | 1383 |
if (dcdiff == 119 /* ESC index value */) |
1383 | 1384 |
{ |
1384 | 1385 |
/* TODO: Optimize */ |
1385 |
- if (mquant == 1) dcdiff = get_bits(&v->gb, 10); |
|
1386 |
- else if (mquant == 2) dcdiff = get_bits(&v->gb, 9); |
|
1387 |
- else dcdiff = get_bits(&v->gb, 8); |
|
1386 |
+ if (mquant == 1) dcdiff = get_bits(gb, 10); |
|
1387 |
+ else if (mquant == 2) dcdiff = get_bits(gb, 9); |
|
1388 |
+ else dcdiff = get_bits(gb, 8); |
|
1388 | 1389 |
} |
1389 | 1390 |
else |
1390 | 1391 |
{ |
1391 | 1392 |
if (mquant == 1) |
1392 |
- dcdiff = (dcdiff<<2) + get_bits(&v->gb, 2) - 3; |
|
1393 |
+ dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; |
|
1393 | 1394 |
else if (mquant == 2) |
1394 |
- dcdiff = (dcdiff<<1) + get_bits(&v->gb, 1) - 1; |
|
1395 |
+ dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1; |
|
1395 | 1396 |
} |
1396 |
- if (get_bits(&v->gb, 1)) |
|
1397 |
+ if (get_bits(gb, 1)) |
|
1397 | 1398 |
dcdiff = -dcdiff; |
1398 | 1399 |
} |
1399 | 1400 |
/* FIXME: 8.1.1.15, p(1)13, coeff scaling for Adv Profile */ |
... | ... |
@@ -1407,7 +1448,7 @@ int decode_luma_intra_block(VC9Context *v, int mquant) |
1407 | 1407 |
/* 8.1.1.5, p(1)02-(1)03 */ |
1408 | 1408 |
/* We only need to store 3 flags, but math with 4 is easier */ |
1409 | 1409 |
#define GET_CBPCY(table, bits) \ |
1410 |
- predicted_cbpcy = get_vlc2(&v->gb, table, bits, 2); \ |
|
1410 |
+ predicted_cbpcy = get_vlc2(gb, table, bits, 2); \ |
|
1411 | 1411 |
cbpcy[0] = (p_cbpcy[-1] == p_cbpcy[2]) \ |
1412 | 1412 |
? previous_cbpcy[1] : p_cbpcy[+2]; \ |
1413 | 1413 |
cbpcy[0] ^= ((predicted_cbpcy>>5)&0x01); \ |
... | ... |
@@ -1422,32 +1463,33 @@ int decode_luma_intra_block(VC9Context *v, int mquant) |
1422 | 1422 |
/* 8.1, p100 */ |
1423 | 1423 |
static int standard_decode_i_mbs(VC9Context *v) |
1424 | 1424 |
{ |
1425 |
- int x, y, current_mb = 0; /* MB/Block Position info */ |
|
1426 |
- int ac_pred; |
|
1425 |
+ GetBitContext *gb = &v->s.gb; |
|
1426 |
+ MpegEncContext *s = &v->s; |
|
1427 |
+ int current_mb = 0; /* MB/Block Position info */ |
|
1427 | 1428 |
/* FIXME: better to use a pointer than using (x<<4) */ |
1428 | 1429 |
uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, |
1429 | 1430 |
*p_cbpcy /* Pointer to skip some math */; |
1430 | 1431 |
|
1431 | 1432 |
/* Reset CBPCY predictors */ |
1432 |
- memset(v->previous_line_cbpcy, 0, (v->width_mb+1)<<2); |
|
1433 |
+ memset(v->previous_line_cbpcy, 0, s->mb_stride<<2); |
|
1433 | 1434 |
|
1434 | 1435 |
/* Select ttmb table depending on pq */ |
1435 | 1436 |
if (v->pq < 5) v->ttmb_vlc = &vc9_ttmb_vlc[0]; |
1436 | 1437 |
else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; |
1437 | 1438 |
else v->ttmb_vlc = &vc9_ttmb_vlc[2]; |
1438 | 1439 |
|
1439 |
- for (y=0; y<v->height_mb; y++) |
|
1440 |
+ for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++) |
|
1440 | 1441 |
{ |
1441 | 1442 |
/* Init CBPCY for line */ |
1442 | 1443 |
*((uint32_t*)previous_cbpcy) = 0x00000000; |
1443 | 1444 |
p_cbpcy = v->previous_line_cbpcy+4; |
1444 | 1445 |
|
1445 |
- for (x=0; x<v->width_mb; x++, p_cbpcy += 4) |
|
1446 |
+ for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++, p_cbpcy += 4) |
|
1446 | 1447 |
{ |
1447 | 1448 |
/* Get CBPCY */ |
1448 |
- GET_CBPCY(vc9_cbpcy_i_vlc.table, VC9_CBPCY_I_VLC_BITS); |
|
1449 |
+ GET_CBPCY(ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS); |
|
1449 | 1450 |
|
1450 |
- ac_pred = get_bits(&v->gb, 1); |
|
1451 |
+ s->ac_pred = get_bits(gb, 1); |
|
1451 | 1452 |
|
1452 | 1453 |
/* TODO: Decode blocks from that mb wrt cbpcy */ |
1453 | 1454 |
|
... | ... |
@@ -1467,20 +1509,20 @@ static int standard_decode_i_mbs(VC9Context *v) |
1467 | 1467 |
{ \ |
1468 | 1468 |
if (v->dqbilevel) \ |
1469 | 1469 |
{ \ |
1470 |
- mquant = (get_bits(&v->gb, 1)) ? v->pq : v->altpq; \ |
|
1470 |
+ mquant = (get_bits(gb, 1)) ? v->pq : v->altpq; \ |
|
1471 | 1471 |
} \ |
1472 | 1472 |
else \ |
1473 | 1473 |
{ \ |
1474 |
- mqdiff = get_bits(&v->gb, 3); \ |
|
1474 |
+ mqdiff = get_bits(gb, 3); \ |
|
1475 | 1475 |
if (mqdiff != 7) mquant = v->pq + mqdiff; \ |
1476 |
- else mquant = get_bits(&v->gb, 5); \ |
|
1476 |
+ else mquant = get_bits(gb, 5); \ |
|
1477 | 1477 |
} \ |
1478 | 1478 |
} \ |
1479 | 1479 |
} |
1480 | 1480 |
|
1481 | 1481 |
/* MVDATA decoding from 8.3.5.2, p(1)20 */ |
1482 | 1482 |
#define GET_MVDATA(_dmv_x, _dmv_y) \ |
1483 |
- index = 1 + get_vlc2(&v->gb, v->mv_diff_vlc->table, \ |
|
1483 |
+ index = 1 + get_vlc2(gb, v->mv_diff_vlc->table, \ |
|
1484 | 1484 |
VC9_MV_DIFF_VLC_BITS, 2); \ |
1485 | 1485 |
if (index > 36) \ |
1486 | 1486 |
{ \ |
... | ... |
@@ -1492,8 +1534,8 @@ static int standard_decode_i_mbs(VC9Context *v) |
1492 | 1492 |
if (!index) { _dmv_x = _dmv_y = 0; } \ |
1493 | 1493 |
else if (index == 35) \ |
1494 | 1494 |
{ \ |
1495 |
- _dmv_x = get_bits(&v->gb, k_x); \ |
|
1496 |
- _dmv_y = get_bits(&v->gb, k_y); \ |
|
1495 |
+ _dmv_x = get_bits(gb, k_x); \ |
|
1496 |
+ _dmv_y = get_bits(gb, k_y); \ |
|
1497 | 1497 |
mb_is_intra = 1; \ |
1498 | 1498 |
} \ |
1499 | 1499 |
else \ |
... | ... |
@@ -1501,14 +1543,14 @@ static int standard_decode_i_mbs(VC9Context *v) |
1501 | 1501 |
index1 = index%6; \ |
1502 | 1502 |
if (hpel_flag && index1 == 5) val = 1; \ |
1503 | 1503 |
else val = 0; \ |
1504 |
- val = get_bits(&v->gb, size_table[index1] - val); \ |
|
1504 |
+ val = get_bits(gb, size_table[index1] - val); \ |
|
1505 | 1505 |
sign = 0 - (val&1); \ |
1506 | 1506 |
_dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ |
1507 | 1507 |
\ |
1508 | 1508 |
index1 = index/6; \ |
1509 | 1509 |
if (hpel_flag && index1 == 5) val = 1; \ |
1510 | 1510 |
else val = 0; \ |
1511 |
- val = get_bits(&v->gb, size_table[index1] - val); \ |
|
1511 |
+ val = get_bits(gb, size_table[index1] - val); \ |
|
1512 | 1512 |
sign = 0 - (val&1); \ |
1513 | 1513 |
_dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ |
1514 | 1514 |
} |
... | ... |
@@ -1516,10 +1558,12 @@ static int standard_decode_i_mbs(VC9Context *v) |
1516 | 1516 |
/* 8.1, p(1)15 */ |
1517 | 1517 |
static int decode_p_mbs(VC9Context *v) |
1518 | 1518 |
{ |
1519 |
- int x, y, current_mb = 0, i; /* MB/Block Position info */ |
|
1519 |
+ MpegEncContext *s = &v->s; |
|
1520 |
+ GetBitContext *gb = &v->s.gb; |
|
1521 |
+ int current_mb = 0, i; /* MB/Block Position info */ |
|
1520 | 1522 |
uint8_t cbpcy[4], previous_cbpcy[4], predicted_cbpcy, |
1521 | 1523 |
*p_cbpcy /* Pointer to skip some math */; |
1522 |
- int hybrid_pred, ac_pred; /* Prediction types */ |
|
1524 |
+ int hybrid_pred; /* Prediction types */ |
|
1523 | 1525 |
int mv_mode_bit = 0; |
1524 | 1526 |
int mqdiff, mquant; /* MB quantization */ |
1525 | 1527 |
int ttmb; /* MB Transform type */ |
... | ... |
@@ -1552,20 +1596,20 @@ static int decode_p_mbs(VC9Context *v) |
1552 | 1552 |
k_y -= hpel_flag; |
1553 | 1553 |
|
1554 | 1554 |
/* Reset CBPCY predictors */ |
1555 |
- memset(v->previous_line_cbpcy, 0, (v->width_mb+1)<<2); |
|
1555 |
+ memset(v->previous_line_cbpcy, 0, s->mb_stride<<2); |
|
1556 | 1556 |
|
1557 |
- for (y=0; y<v->height_mb; y++) |
|
1557 |
+ for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++) |
|
1558 | 1558 |
{ |
1559 | 1559 |
/* Init CBPCY for line */ |
1560 | 1560 |
*((uint32_t*)previous_cbpcy) = 0x00000000; |
1561 | 1561 |
p_cbpcy = v->previous_line_cbpcy+4; |
1562 | 1562 |
|
1563 |
- for (x=0; x<v->width_mb; x++) |
|
1563 |
+ for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++) |
|
1564 | 1564 |
{ |
1565 | 1565 |
if (v->mv_type_mb_plane.is_raw) |
1566 |
- v->mv_type_mb_plane.data[current_mb] = get_bits(&v->gb, 1); |
|
1566 |
+ v->mv_type_mb_plane.data[current_mb] = get_bits(gb, 1); |
|
1567 | 1567 |
if (v->skip_mb_plane.is_raw) |
1568 |
- v->skip_mb_plane.data[current_mb] = get_bits(&v->gb, 1); |
|
1568 |
+ v->skip_mb_plane.data[current_mb] = get_bits(gb, 1); |
|
1569 | 1569 |
if (!mv_mode_bit) /* 1MV mode */ |
1570 | 1570 |
{ |
1571 | 1571 |
if (!v->skip_mb_plane.data[current_mb]) |
... | ... |
@@ -1575,20 +1619,20 @@ static int decode_p_mbs(VC9Context *v) |
1575 | 1575 |
/* hybrid mv pred, 8.3.5.3.4 */ |
1576 | 1576 |
if (v->mv_mode == MV_PMODE_1MV || |
1577 | 1577 |
v->mv_mode == MV_PMODE_MIXED_MV) |
1578 |
- hybrid_pred = get_bits(&v->gb, 1); |
|
1578 |
+ hybrid_pred = get_bits(gb, 1); |
|
1579 | 1579 |
if (mb_is_intra && !mb_has_coeffs) |
1580 | 1580 |
{ |
1581 | 1581 |
GET_MQUANT(); |
1582 |
- ac_pred = get_bits(&v->gb, 1); |
|
1582 |
+ s->ac_pred = get_bits(gb, 1); |
|
1583 | 1583 |
} |
1584 | 1584 |
else if (mb_has_coeffs) |
1585 | 1585 |
{ |
1586 |
- if (mb_is_intra) ac_pred = get_bits(&v->gb, 1); |
|
1586 |
+ if (mb_is_intra) s->ac_pred = get_bits(gb, 1); |
|
1587 | 1587 |
GET_CBPCY(v->cbpcy_vlc->table, VC9_CBPCY_P_VLC_BITS); |
1588 | 1588 |
GET_MQUANT(); |
1589 | 1589 |
} |
1590 | 1590 |
if (!v->ttmbf) |
1591 |
- ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
|
1591 |
+ ttmb = get_vlc2(gb, v->ttmb_vlc->table, |
|
1592 | 1592 |
VC9_TTMB_VLC_BITS, 12); |
1593 | 1593 |
/* TODO: decode blocks from that mb wrt cbpcy */ |
1594 | 1594 |
} |
... | ... |
@@ -1597,7 +1641,7 @@ static int decode_p_mbs(VC9Context *v) |
1597 | 1597 |
/* hybrid mv pred, 8.3.5.3.4 */ |
1598 | 1598 |
if (v->mv_mode == MV_PMODE_1MV || |
1599 | 1599 |
v->mv_mode == MV_PMODE_MIXED_MV) |
1600 |
- hybrid_pred = get_bits(&v->gb, 1); |
|
1600 |
+ hybrid_pred = get_bits(gb, 1); |
|
1601 | 1601 |
} |
1602 | 1602 |
} //1MV mode |
1603 | 1603 |
else //4MV mode |
... | ... |
@@ -1613,13 +1657,13 @@ static int decode_p_mbs(VC9Context *v) |
1613 | 1613 |
GET_MVDATA(dmv_x, dmv_y); |
1614 | 1614 |
} |
1615 | 1615 |
if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */) |
1616 |
- hybrid_pred = get_bits(&v->gb, 1); |
|
1616 |
+ hybrid_pred = get_bits(gb, 1); |
|
1617 | 1617 |
GET_MQUANT(); |
1618 | 1618 |
if (mb_is_intra /* One of the 4 blocks is intra */ && |
1619 | 1619 |
index /* non-zero pred for that block */) |
1620 |
- ac_pred = get_bits(&v->gb, 1); |
|
1620 |
+ s->ac_pred = get_bits(gb, 1); |
|
1621 | 1621 |
if (!v->ttmbf) |
1622 |
- ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
|
1622 |
+ ttmb = get_vlc2(gb, v->ttmb_vlc->table, |
|
1623 | 1623 |
VC9_TTMB_VLC_BITS, 12); |
1624 | 1624 |
|
1625 | 1625 |
/* TODO: Process blocks wrt cbpcy */ |
... | ... |
@@ -1631,7 +1675,7 @@ static int decode_p_mbs(VC9Context *v) |
1631 | 1631 |
for (i=0; i<4; i++) //All 4 Y blocks |
1632 | 1632 |
{ |
1633 | 1633 |
if (v->mv_mode == MV_PMODE_MIXED_MV /* Hybrid pred */) |
1634 |
- hybrid_pred = get_bits(&v->gb, 1); |
|
1634 |
+ hybrid_pred = get_bits(gb, 1); |
|
1635 | 1635 |
|
1636 | 1636 |
/* TODO: do something */ |
1637 | 1637 |
} |
... | ... |
@@ -1640,7 +1684,7 @@ static int decode_p_mbs(VC9Context *v) |
1640 | 1640 |
|
1641 | 1641 |
/* Update for next block */ |
1642 | 1642 |
#if TRACE > 2 |
1643 |
- av_log(v->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i," |
|
1643 |
+ av_log(s->avctx, AV_LOG_DEBUG, "Block %4i: p_cbpcy=%i%i%i%i, previous_cbpcy=%i%i%i%i," |
|
1644 | 1644 |
" cbpcy=%i%i%i%i\n", current_mb, |
1645 | 1645 |
p_cbpcy[0], p_cbpcy[1], p_cbpcy[2], p_cbpcy[3], |
1646 | 1646 |
previous_cbpcy[0], previous_cbpcy[1], previous_cbpcy[2], previous_cbpcy[3], |
... | ... |
@@ -1656,8 +1700,9 @@ static int decode_p_mbs(VC9Context *v) |
1656 | 1656 |
|
1657 | 1657 |
static int decode_b_mbs(VC9Context *v) |
1658 | 1658 |
{ |
1659 |
- int x, y, current_mb = 0, i /* MB / B postion information */; |
|
1660 |
- int ac_pred; |
|
1659 |
+ MpegEncContext *s = &v->s; |
|
1660 |
+ GetBitContext *gb = &v->s.gb; |
|
1661 |
+ int current_mb = 0, i /* MB / B postion information */; |
|
1661 | 1662 |
int b_mv_type = BMV_TYPE_BACKWARD; |
1662 | 1663 |
int mquant, mqdiff; /* MB quant stuff */ |
1663 | 1664 |
int ttmb; /* MacroBlock transform type */ |
... | ... |
@@ -1688,20 +1733,20 @@ static int decode_b_mbs(VC9Context *v) |
1688 | 1688 |
else if (v->pq < 13) v->ttmb_vlc = &vc9_ttmb_vlc[1]; |
1689 | 1689 |
else v->ttmb_vlc = &vc9_ttmb_vlc[2]; |
1690 | 1690 |
|
1691 |
- for (y=0; y<v->height_mb; y++) |
|
1691 |
+ for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++) |
|
1692 | 1692 |
{ |
1693 |
- for (x=0; x<v->width_mb; x++) |
|
1693 |
+ for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++) |
|
1694 | 1694 |
{ |
1695 | 1695 |
if (v->direct_mb_plane.is_raw) |
1696 |
- v->direct_mb_plane.data[current_mb] = get_bits(&v->gb, 1); |
|
1696 |
+ v->direct_mb_plane.data[current_mb] = get_bits(gb, 1); |
|
1697 | 1697 |
if (v->skip_mb_plane.is_raw) |
1698 |
- v->skip_mb_plane.data[current_mb] = get_bits(&v->gb, 1); |
|
1698 |
+ v->skip_mb_plane.data[current_mb] = get_bits(gb, 1); |
|
1699 | 1699 |
|
1700 | 1700 |
if (!v->direct_mb_plane.data[current_mb]) |
1701 | 1701 |
{ |
1702 | 1702 |
if (v->skip_mb_plane.data[current_mb]) |
1703 | 1703 |
{ |
1704 |
- b_mv_type = decode012(&v->gb); |
|
1704 |
+ b_mv_type = decode012(gb); |
|
1705 | 1705 |
if (v->bfraction > 420 /*1/2*/ && |
1706 | 1706 |
b_mv_type < 3) b_mv_type = 1-b_mv_type; |
1707 | 1707 |
} |
... | ... |
@@ -1712,7 +1757,7 @@ static int decode_b_mbs(VC9Context *v) |
1712 | 1712 |
if (!mb_is_intra /* b_mv1 tells not intra */) |
1713 | 1713 |
{ |
1714 | 1714 |
/* FIXME: actually read it */ |
1715 |
- b_mv_type = decode012(&v->gb); |
|
1715 |
+ b_mv_type = decode012(gb); |
|
1716 | 1716 |
if (v->bfraction > 420 /*1/2*/ && |
1717 | 1717 |
b_mv_type < 3) b_mv_type = 1-b_mv_type; |
1718 | 1718 |
} |
... | ... |
@@ -1724,7 +1769,7 @@ static int decode_b_mbs(VC9Context *v) |
1724 | 1724 |
{ |
1725 | 1725 |
GET_MQUANT(); |
1726 | 1726 |
if (mb_is_intra /* intra mb */) |
1727 |
- ac_pred = get_bits(&v->gb, 1); |
|
1727 |
+ s->ac_pred = get_bits(gb, 1); |
|
1728 | 1728 |
} |
1729 | 1729 |
else |
1730 | 1730 |
{ |
... | ... |
@@ -1737,14 +1782,14 @@ static int decode_b_mbs(VC9Context *v) |
1737 | 1737 |
if (mb_has_coeffs /* b_mv2 == "last" */) |
1738 | 1738 |
{ |
1739 | 1739 |
if (mb_is_intra /* intra_mb */) |
1740 |
- ac_pred = get_bits(&v->gb, 1); |
|
1740 |
+ s->ac_pred = get_bits(gb, 1); |
|
1741 | 1741 |
GET_MQUANT(); |
1742 | 1742 |
} |
1743 | 1743 |
} |
1744 | 1744 |
} |
1745 | 1745 |
//End1 |
1746 | 1746 |
if (v->ttmbf) |
1747 |
- ttmb = get_vlc2(&v->gb, v->ttmb_vlc->table, |
|
1747 |
+ ttmb = get_vlc2(gb, v->ttmb_vlc->table, |
|
1748 | 1748 |
VC9_TTMB_VLC_BITS, 12); |
1749 | 1749 |
|
1750 | 1750 |
//End2 |
... | ... |
@@ -1762,16 +1807,20 @@ static int decode_b_mbs(VC9Context *v) |
1762 | 1762 |
#if HAS_ADVANCED_PROFILE |
1763 | 1763 |
static int advanced_decode_i_mbs(VC9Context *v) |
1764 | 1764 |
{ |
1765 |
- int x, y, mqdiff, mquant, ac_pred, current_mb = 0, over_flags_mb = 0; |
|
1765 |
+ MpegEncContext *s = &v->s; |
|
1766 |
+ GetBitContext *gb = &v->s.gb; |
|
1767 |
+ int mqdiff, mquant, current_mb = 0, over_flags_mb = 0; |
|
1766 | 1768 |
|
1767 |
- for (y=0; y<v->height_mb; y++) |
|
1769 |
+ for (s->mb_y=0; s->mb_y<s->mb_height; s->mb_y++) |
|
1768 | 1770 |
{ |
1769 |
- for (x=0; x<v->width_mb; x++) |
|
1771 |
+ for (s->mb_x=0; s->mb_x<s->mb_width; s->mb_x++) |
|
1770 | 1772 |
{ |
1771 |
- if (v->ac_pred_plane.data[current_mb]) |
|
1772 |
- ac_pred = get_bits(&v->gb, 1); |
|
1773 |
+ if (v->ac_pred_plane.is_raw) |
|
1774 |
+ s->ac_pred = get_bits(gb, 1); |
|
1775 |
+ else |
|
1776 |
+ s->ac_pred = v->ac_pred_plane.data[current_mb]; |
|
1773 | 1777 |
if (v->condover == 3 && v->over_flags_plane.is_raw) |
1774 |
- over_flags_mb = get_bits(&v->gb, 1); |
|
1778 |
+ over_flags_mb = get_bits(gb, 1); |
|
1775 | 1779 |
GET_MQUANT(); |
1776 | 1780 |
|
1777 | 1781 |
/* TODO: lots */ |
... | ... |
@@ -1785,13 +1834,16 @@ static int advanced_decode_i_mbs(VC9Context *v) |
1785 | 1785 |
static int vc9_decode_init(AVCodecContext *avctx) |
1786 | 1786 |
{ |
1787 | 1787 |
VC9Context *v = avctx->priv_data; |
1788 |
+ MpegEncContext *s = &v->s; |
|
1788 | 1789 |
GetBitContext gb; |
1789 | 1790 |
|
1790 | 1791 |
if (!avctx->extradata_size || !avctx->extradata) return -1; |
1791 | 1792 |
avctx->pix_fmt = PIX_FMT_YUV420P; |
1792 |
- v->avctx = avctx; |
|
1793 |
+ v->s.avctx = avctx; |
|
1793 | 1794 |
|
1794 |
- if (init_common(v) < 0) return -1; |
|
1795 |
+ if(ff_h263_decode_init(avctx) < 0) |
|
1796 |
+ return -1; |
|
1797 |
+ if (vc9_init_common(v) < 0) return -1; |
|
1795 | 1798 |
|
1796 | 1799 |
avctx->coded_width = avctx->width; |
1797 | 1800 |
avctx->coded_height = avctx->height; |
... | ... |
@@ -1799,68 +1851,68 @@ static int vc9_decode_init(AVCodecContext *avctx) |
1799 | 1799 |
{ |
1800 | 1800 |
int count = 0; |
1801 | 1801 |
|
1802 |
- // looks like WMV3 has a sequence header stored in the extradata |
|
1803 |
- // advanced sequence header may be before the first frame |
|
1804 |
- // the last byte of the extradata is a version number, 1 for the |
|
1805 |
- // samples we can decode |
|
1802 |
+ // looks like WMV3 has a sequence header stored in the extradata |
|
1803 |
+ // advanced sequence header may be before the first frame |
|
1804 |
+ // the last byte of the extradata is a version number, 1 for the |
|
1805 |
+ // samples we can decode |
|
1806 | 1806 |
|
1807 |
- init_get_bits(&gb, avctx->extradata, avctx->extradata_size); |
|
1808 |
- |
|
1809 |
- decode_sequence_header(avctx, &gb); |
|
1807 |
+ init_get_bits(&gb, avctx->extradata, avctx->extradata_size); |
|
1808 |
+ |
|
1809 |
+ decode_sequence_header(avctx, &gb); |
|
1810 | 1810 |
|
1811 |
- count = avctx->extradata_size*8 - get_bits_count(&gb); |
|
1812 |
- if (count>0) |
|
1813 |
- { |
|
1814 |
- av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", |
|
1815 |
- count, get_bits(&gb, count)); |
|
1816 |
- } |
|
1817 |
- else |
|
1818 |
- { |
|
1819 |
- av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); |
|
1820 |
- } |
|
1811 |
+ count = avctx->extradata_size*8 - get_bits_count(&gb); |
|
1812 |
+ if (count>0) |
|
1813 |
+ { |
|
1814 |
+ av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", |
|
1815 |
+ count, get_bits(&gb, count)); |
|
1816 |
+ } |
|
1817 |
+ else |
|
1818 |
+ { |
|
1819 |
+ av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); |
|
1820 |
+ } |
|
1821 | 1821 |
} |
1822 |
+ avctx->has_b_frames= !!(avctx->max_b_frames); |
|
1822 | 1823 |
|
1823 |
- /* Done with header parsing */ |
|
1824 |
- //FIXME I feel like this is wrong |
|
1825 |
- v->width_mb = (avctx->coded_width+15)>>4; |
|
1826 |
- v->height_mb = (avctx->coded_height+15)>>4; |
|
1824 |
+ s->mb_width = (avctx->coded_width+15)>>4; |
|
1825 |
+ s->mb_height = (avctx->coded_height+15)>>4; |
|
1827 | 1826 |
|
1828 | 1827 |
/* Allocate mb bitplanes */ |
1829 |
- if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) |
|
1828 |
+ if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0) |
|
1830 | 1829 |
return -1; |
1831 |
- if (alloc_bitplane(&v->mv_type_mb_plane, v->width_mb, v->height_mb) < 0) |
|
1830 |
+ if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0) |
|
1832 | 1831 |
return -1; |
1833 |
- if (alloc_bitplane(&v->skip_mb_plane, v->width_mb, v->height_mb) < 0) |
|
1832 |
+ if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0) |
|
1834 | 1833 |
return -1; |
1835 |
- if (alloc_bitplane(&v->direct_mb_plane, v->width_mb, v->height_mb) < 0) |
|
1834 |
+ if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0) |
|
1836 | 1835 |
return -1; |
1837 | 1836 |
|
1838 | 1837 |
/* For predictors */ |
1839 |
- v->previous_line_cbpcy = (uint8_t *)av_malloc((v->width_mb+1)*4); |
|
1838 |
+ v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4); |
|
1840 | 1839 |
if (!v->previous_line_cbpcy) return -1; |
1841 | 1840 |
|
1842 | 1841 |
#if HAS_ADVANCED_PROFILE |
1843 | 1842 |
if (v->profile > PROFILE_MAIN) |
1844 | 1843 |
{ |
1845 |
- if (alloc_bitplane(&v->over_flags_plane, v->width_mb, v->height_mb) < 0) |
|
1844 |
+ if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0) |
|
1846 | 1845 |
return -1; |
1847 |
- if (alloc_bitplane(&v->ac_pred_plane, v->width_mb, v->height_mb) < 0) |
|
1846 |
+ if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0) |
|
1848 | 1847 |
return -1; |
1849 | 1848 |
} |
1850 | 1849 |
#endif |
1851 | 1850 |
|
1852 | 1851 |
return 0; |
1853 |
-} |
|
1852 |
+ } |
|
1854 | 1853 |
|
1855 | 1854 |
static int vc9_decode_frame(AVCodecContext *avctx, |
1856 | 1855 |
void *data, int *data_size, |
1857 | 1856 |
uint8_t *buf, int buf_size) |
1858 | 1857 |
{ |
1859 | 1858 |
VC9Context *v = avctx->priv_data; |
1859 |
+ MpegEncContext *s = &v->s; |
|
1860 | 1860 |
int ret = FRAME_SKIPED, len, start_code; |
1861 | 1861 |
AVFrame *pict = data; |
1862 | 1862 |
uint8_t *tmp_buf; |
1863 |
- v->avctx = avctx; |
|
1863 |
+ v->s.avctx = avctx; |
|
1864 | 1864 |
|
1865 | 1865 |
//buf_size = 0 -> last frame |
1866 | 1866 |
if (!buf_size) return 0; |
... | ... |
@@ -1871,41 +1923,7 @@ static int vc9_decode_frame(AVCodecContext *avctx, |
1871 | 1871 |
avpicture_fill((AVPicture *)pict, tmp_buf, avctx->pix_fmt, |
1872 | 1872 |
avctx->width, avctx->height); |
1873 | 1873 |
|
1874 |
- if (avctx->codec_id == CODEC_ID_WMV3) |
|
1875 |
- { |
|
1876 |
- //No IDU |
|
1877 |
- init_get_bits(&v->gb, buf, buf_size*8); |
|
1878 |
- |
|
1879 |
-#if HAS_ADVANCED_PROFILE |
|
1880 |
- if (v->profile > PROFILE_MAIN) |
|
1881 |
- { |
|
1882 |
- if (advanced_decode_picture_header(v) == FRAME_SKIPED) return buf_size; |
|
1883 |
- switch(v->pict_type) |
|
1884 |
- { |
|
1885 |
- case I_TYPE: ret = advanced_decode_i_mbs(v); break; |
|
1886 |
- case P_TYPE: ret = decode_p_mbs(v); break; |
|
1887 |
- case B_TYPE: |
|
1888 |
- case BI_TYPE: ret = decode_b_mbs(v); break; |
|
1889 |
- default: ret = FRAME_SKIPED; |
|
1890 |
- } |
|
1891 |
- if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures |
|
1892 |
- } |
|
1893 |
- else |
|
1894 |
-#endif |
|
1895 |
- { |
|
1896 |
- if (standard_decode_picture_header(v) == FRAME_SKIPED) return buf_size; |
|
1897 |
- switch(v->pict_type) |
|
1898 |
- { |
|
1899 |
- case I_TYPE: ret = standard_decode_i_mbs(v); break; |
|
1900 |
- case P_TYPE: ret = decode_p_mbs(v); break; |
|
1901 |
- case B_TYPE: |
|
1902 |
- case BI_TYPE: ret = decode_b_mbs(v); break; |
|
1903 |
- default: ret = FRAME_SKIPED; |
|
1904 |
- } |
|
1905 |
- if (ret == FRAME_SKIPED) return buf_size; |
|
1906 |
- } |
|
1907 |
- } |
|
1908 |
- else |
|
1874 |
+ if (avctx->codec_id == CODEC_ID_VC9) |
|
1909 | 1875 |
{ |
1910 | 1876 |
#if 0 |
1911 | 1877 |
// search for IDU's |
... | ... |
@@ -1923,7 +1941,7 @@ static int vc9_decode_frame(AVCodecContext *avctx, |
1923 | 1923 |
|
1924 | 1924 |
scs = buf[i++]; |
1925 | 1925 |
|
1926 |
- init_get_bits(&v->gb, buf+i, (buf_size-i)*8); |
|
1926 |
+ init_get_bits(gb, buf+i, (buf_size-i)*8); |
|
1927 | 1927 |
|
1928 | 1928 |
switch(scs) |
1929 | 1929 |
{ |
... | ... |
@@ -1941,24 +1959,162 @@ static int vc9_decode_frame(AVCodecContext *avctx, |
1941 | 1941 |
if (v->profile <= MAIN_PROFILE) |
1942 | 1942 |
av_log(avctx, AV_LOG_ERROR, |
1943 | 1943 |
"Found an entry point in profile %i\n", v->profile); |
1944 |
- advanced_entry_point_process(avctx, &v->gb); |
|
1944 |
+ advanced_entry_point_process(avctx, gb); |
|
1945 | 1945 |
break; |
1946 | 1946 |
case 0x0F: //Sequence header Start Code |
1947 |
- decode_sequence_header(avctx, &v->gb); |
|
1947 |
+ decode_sequence_header(avctx, gb); |
|
1948 | 1948 |
break; |
1949 | 1949 |
default: |
1950 | 1950 |
av_log(avctx, AV_LOG_ERROR, |
1951 | 1951 |
"Unsupported IDU suffix %lX\n", scs); |
1952 | 1952 |
} |
1953 | 1953 |
|
1954 |
- i += get_bits_count(&v->gb)*8; |
|
1954 |
+ i += get_bits_count(gb)*8; |
|
1955 | 1955 |
} |
1956 | 1956 |
#else |
1957 | 1957 |
av_abort(); |
1958 | 1958 |
#endif |
1959 | 1959 |
} |
1960 |
+ else |
|
1961 |
+ init_get_bits(&v->s.gb, buf, buf_size*8); |
|
1962 |
+ |
|
1963 |
+ s->flags= avctx->flags; |
|
1964 |
+ s->flags2= avctx->flags2; |
|
1965 |
+ |
|
1966 |
+ /* no supplementary picture */ |
|
1967 |
+ if (buf_size == 0) { |
|
1968 |
+ /* special case for last picture */ |
|
1969 |
+ if (s->low_delay==0 && s->next_picture_ptr) { |
|
1970 |
+ *pict= *(AVFrame*)s->next_picture_ptr; |
|
1971 |
+ s->next_picture_ptr= NULL; |
|
1972 |
+ |
|
1973 |
+ *data_size = sizeof(AVFrame); |
|
1974 |
+ } |
|
1975 |
+ |
|
1976 |
+ return 0; |
|
1977 |
+ } |
|
1978 |
+ |
|
1979 |
+ //No IDU - we mimic ff_h263_decode_frame |
|
1980 |
+ s->bitstream_buffer_size=0; |
|
1981 |
+ |
|
1982 |
+ if (!s->context_initialized) { |
|
1983 |
+ if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix |
|
1984 |
+ return -1; |
|
1985 |
+ } |
|
1986 |
+ |
|
1987 |
+ //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there |
|
1988 |
+ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ |
|
1989 |
+ s->current_picture_ptr= &s->picture[ff_find_unused_picture(s, 0)]; |
|
1990 |
+ } |
|
1991 |
+#if HAS_ADVANCED_PROFILE |
|
1992 |
+ if (v->profile > PROFILE_MAIN) |
|
1993 |
+ ret= advanced_decode_picture_primary_header(v); |
|
1994 |
+ else |
|
1995 |
+#endif |
|
1996 |
+ ret= standard_decode_picture_primary_header(v); |
|
1997 |
+ if (ret == FRAME_SKIPED) return buf_size; |
|
1998 |
+ /* skip if the header was thrashed */ |
|
1999 |
+ if (ret < 0){ |
|
2000 |
+ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); |
|
2001 |
+ return -1; |
|
2002 |
+ } |
|
2003 |
+ |
|
2004 |
+ //No bug workaround yet, no DCT conformance |
|
2005 |
+ |
|
2006 |
+ //WMV9 does have resized images |
|
2007 |
+ if (v->profile <= PROFILE_MAIN && v->multires){ |
|
2008 |
+ //Parse context stuff in here, don't know how appliable it is |
|
2009 |
+ } |
|
2010 |
+ //Not sure about context initialization |
|
2011 |
+ |
|
2012 |
+ // for hurry_up==5 |
|
2013 |
+ s->current_picture.pict_type= s->pict_type; |
|
2014 |
+ s->current_picture.key_frame= s->pict_type == I_TYPE; |
|
2015 |
+ |
|
2016 |
+ /* skip b frames if we dont have reference frames */ |
|
2017 |
+ if(s->last_picture_ptr==NULL && (s->pict_type==B_TYPE || s->dropable)) |
|
2018 |
+ return buf_size; //FIXME simulating all buffer consumed |
|
2019 |
+ /* skip b frames if we are in a hurry */ |
|
2020 |
+ if(avctx->hurry_up && s->pict_type==B_TYPE) |
|
2021 |
+ return buf_size; //FIXME simulating all buffer consumed |
|
2022 |
+ /* skip everything if we are in a hurry>=5 */ |
|
2023 |
+ if(avctx->hurry_up>=5) |
|
2024 |
+ return buf_size; //FIXME simulating all buffer consumed |
|
2025 |
+ |
|
2026 |
+ if(s->next_p_frame_damaged){ |
|
2027 |
+ if(s->pict_type==B_TYPE) |
|
2028 |
+ return buf_size; //FIXME simulating all buffer consumed |
|
2029 |
+ else |
|
2030 |
+ s->next_p_frame_damaged=0; |
|
2031 |
+ } |
|
2032 |
+ |
|
2033 |
+ if(MPV_frame_start(s, avctx) < 0) |
|
2034 |
+ return -1; |
|
2035 |
+ |
|
2036 |
+ ff_er_frame_start(s); |
|
2037 |
+ |
|
2038 |
+ //wmv9 may or may not have skip bits |
|
2039 |
+#if HAS_ADVANCED_PROFILE |
|
2040 |
+ if (v->profile > PROFILE_MAIN) |
|
2041 |
+ ret= advanced_decode_picture_secondary_header(v); |
|
2042 |
+ else |
|
2043 |
+#endif |
|
2044 |
+ ret = standard_decode_picture_secondary_header(v); |
|
2045 |
+ if (ret<0) return FRAME_SKIPED; //FIXME Non fatal for now |
|
2046 |
+ |
|
2047 |
+ //We consider the image coded in only one slice |
|
2048 |
+#if HAS_ADVANCED_PROFILE |
|
2049 |
+ if (v->profile > PROFILE_MAIN) |
|
2050 |
+ { |
|
2051 |
+ switch(s->pict_type) |
|
2052 |
+ { |
|
2053 |
+ case I_TYPE: ret = advanced_decode_i_mbs(v); break; |
|
2054 |
+ case P_TYPE: ret = decode_p_mbs(v); break; |
|
2055 |
+ case B_TYPE: |
|
2056 |
+ case BI_TYPE: ret = decode_b_mbs(v); break; |
|
2057 |
+ default: ret = FRAME_SKIPED; |
|
2058 |
+ } |
|
2059 |
+ if (ret == FRAME_SKIPED) return buf_size; //We ignore for now failures |
|
2060 |
+ } |
|
2061 |
+ else |
|
2062 |
+#endif |
|
2063 |
+ { |
|
2064 |
+ switch(s->pict_type) |
|
2065 |
+ { |
|
2066 |
+ case I_TYPE: ret = standard_decode_i_mbs(v); break; |
|
2067 |
+ case P_TYPE: ret = decode_p_mbs(v); break; |
|
2068 |
+ case B_TYPE: |
|
2069 |
+ case BI_TYPE: ret = decode_b_mbs(v); break; |
|
2070 |
+ default: ret = FRAME_SKIPED; |
|
2071 |
+ } |
|
2072 |
+ if (ret == FRAME_SKIPED) return buf_size; |
|
2073 |
+ } |
|
2074 |
+ |
|
2075 |
+ ff_er_frame_end(s); |
|
2076 |
+ |
|
2077 |
+ MPV_frame_end(s); |
|
2078 |
+ |
|
2079 |
+ assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); |
|
2080 |
+ assert(s->current_picture.pict_type == s->pict_type); |
|
2081 |
+ if(s->pict_type==B_TYPE || s->low_delay){ |
|
2082 |
+ *pict= *(AVFrame*)&s->current_picture; |
|
2083 |
+ ff_print_debug_info(s, pict); |
|
2084 |
+ } else { |
|
2085 |
+ *pict= *(AVFrame*)&s->last_picture; |
|
2086 |
+ if(pict) |
|
2087 |
+ ff_print_debug_info(s, pict); |
|
2088 |
+ } |
|
2089 |
+ |
|
2090 |
+ /* Return the Picture timestamp as the frame number */ |
|
2091 |
+ /* we substract 1 because it is added on utils.c */ |
|
2092 |
+ avctx->frame_number = s->picture_number - 1; |
|
2093 |
+ |
|
2094 |
+ /* dont output the last pic after seeking */ |
|
2095 |
+ if(s->last_picture_ptr || s->low_delay) |
|
2096 |
+ *data_size = sizeof(AVFrame); |
|
2097 |
+ |
|
1960 | 2098 |
av_log(avctx, AV_LOG_DEBUG, "Consumed %i/%i bits\n", |
1961 |
- get_bits_count(&v->gb), buf_size*8); |
|
2099 |
+ get_bits_count(&s->gb), buf_size*8); |
|
1962 | 2100 |
|
1963 | 2101 |
/* Fake consumption of all data */ |
1964 | 2102 |
*data_size = len; |
... | ... |
@@ -1973,9 +2129,10 @@ static int vc9_decode_end(AVCodecContext *avctx) |
1973 | 1973 |
av_freep(&v->hrd_rate); |
1974 | 1974 |
av_freep(&v->hrd_buffer); |
1975 | 1975 |
#endif |
1976 |
- av_freep(&v->mv_type_mb_plane); |
|
1977 |
- av_freep(&v->skip_mb_plane); |
|
1978 |
- av_freep(&v->direct_mb_plane); |
|
1976 |
+ MPV_common_end(&v->s); |
|
1977 |
+ free_bitplane(&v->mv_type_mb_plane); |
|
1978 |
+ free_bitplane(&v->skip_mb_plane); |
|
1979 |
+ free_bitplane(&v->direct_mb_plane); |
|
1979 | 1980 |
return 0; |
1980 | 1981 |
} |
1981 | 1982 |
|
... | ... |
@@ -167,23 +167,8 @@ static const uint8_t vc9_4mv_block_pattern_bits[4][16] = { |
167 | 167 |
{ 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4} |
168 | 168 |
}; |
169 | 169 |
|
170 |
-/* I-Picture CBPCY VLC tables */ |
|
171 |
-//same as msmpeg4 table_mb_intra |
|
172 |
-static const uint16_t vc9_cbpcy_i_codes[64] = { |
|
173 |
- 1, 23, 9, 5, 6, 71, 32, 16, |
|
174 |
- 2, 124, 58, 29, 2, 236, 119, 0, |
|
175 |
- 3, 183, 44, 19, 1, 360, 70, 63, |
|
176 |
- 30, 1810, 181, 66, 34, 453, 286, 135, |
|
177 |
- 6, 3, 30, 28, 18, 904, 68, 112, |
|
178 |
- 31, 574, 57, 142, 1, 454, 182, 69, |
|
179 |
- 20, 575, 125, 24, 7, 455, 134, 25, |
|
180 |
- 21, 475, 2, 70, 13, 1811, 474, 361 |
|
181 |
-}; |
|
182 |
-static const uint8_t vc9_cbpcy_i_bits[64] = { |
|
183 |
- 1, 6, 5, 5, 5, 9, 7, 7, 5, 9, 7, 7, 6, 9, 8, 8, |
|
184 |
- 5, 9, 7, 7, 6, 10, 8, 8, 6, 13, 9, 8, 7, 11, 10, 9, |
|
185 |
- 4, 9, 7, 6, 7, 12, 9, 9, 6, 11, 8, 9, 7, 11, 9, 9, |
|
186 |
- 6, 11, 9, 9, 7, 11, 9, 9, 6, 10, 9, 9, 8, 13, 10, 10 |
|
170 |
+const uint8_t wmv3_dc_scale_table[32]={ |
|
171 |
+ 0, 4, 6, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 |
|
187 | 172 |
}; |
188 | 173 |
|
189 | 174 |
/* P-Picture CBPCY VLC tables */ |
... | ... |
@@ -244,7 +244,7 @@ void ff_wmv2_encode_mb(MpegEncContext * s, |
244 | 244 |
if (s->pict_type == I_TYPE) { |
245 | 245 |
set_stat(ST_INTRA_MB); |
246 | 246 |
put_bits(&s->pb, |
247 |
- table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]); |
|
247 |
+ ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); |
|
248 | 248 |
} else { |
249 | 249 |
put_bits(&s->pb, |
250 | 250 |
wmv2_inter_table[w->cbp_table_index][cbp][1], |
... | ... |
@@ -734,7 +734,7 @@ static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
734 | 734 |
cbp = code & 0x3f; |
735 | 735 |
} else { |
736 | 736 |
s->mb_intra = 1; |
737 |
- code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2); |
|
737 |
+ code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); |
|
738 | 738 |
if (code < 0){ |
739 | 739 |
av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y); |
740 | 740 |
return -1; |