Browse code

fixed msmpeg4 infinite loop if buggy stream rewrote quantizer fixed bias (+10% compression/quality for h263 like codecs) qscale=1 support mpeg1 intra frames looks far less blocky added codec_id field

Originally committed as revision 423 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2002/04/27 21:30:26
Showing 10 changed files
... ...
@@ -157,6 +157,9 @@ inline void dprintf(const char* fmt,...) {}
157 157
 
158 158
 #endif /* HAVE_AV_CONFIG_H */
159 159
 
160
+/* assume b>0 */
161
+#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
162
+
160 163
 /* bit output */
161 164
 
162 165
 struct PutBitContext;
... ...
@@ -904,8 +904,26 @@ void h263_encode_init(MpegEncContext *s)
904 904
     s->mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p
905 905
     
906 906
     // use fcodes >1 only for mpeg4 & h263 & h263p FIXME
907
-    if(s->h263_plus) s->fcode_tab= umv_fcode_tab;
908
-    else if(s->h263_pred && !s->h263_msmpeg4) s->fcode_tab= fcode_tab;
907
+    switch(s->codec_id){
908
+    case CODEC_ID_MPEG4:
909
+        s->fcode_tab= fcode_tab;
910
+        s->min_qcoeff= -2048;
911
+        s->max_qcoeff=  2047;
912
+        break;
913
+    case CODEC_ID_H263P:
914
+        s->fcode_tab= umv_fcode_tab;
915
+        s->min_qcoeff= -128;
916
+        s->max_qcoeff=  127;
917
+        break;
918
+    default: //nothing needed default table allready set in mpegvideo.c
919
+        s->min_qcoeff= -128;
920
+        s->max_qcoeff=  127;
921
+    }
922
+
923
+    /* h263 type bias */
924
+    //FIXME mpeg4 mpeg quantizer    
925
+    s->intra_quant_bias=0;
926
+    s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
909 927
 }
910 928
 
911 929
 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
... ...
@@ -2702,8 +2720,8 @@ int mpeg4_decode_picture_header(MpegEncContext * s)
2702 2702
                     s->chroma_intra_matrix[i]= v;
2703 2703
                     
2704 2704
                     v= ff_mpeg4_default_non_intra_matrix[i];
2705
-                    s->non_intra_matrix[i]= v;
2706
-                    s->chroma_non_intra_matrix[i]= v;
2705
+                    s->inter_matrix[i]= v;
2706
+                    s->chroma_inter_matrix[i]= v;
2707 2707
                 }
2708 2708
 
2709 2709
                 /* load custom intra matrix */
... ...
@@ -2725,15 +2743,15 @@ int mpeg4_decode_picture_header(MpegEncContext * s)
2725 2725
                         if(v==0) break;
2726 2726
 
2727 2727
                         j= zigzag_direct[i];
2728
-                        s->non_intra_matrix[j]= v;
2729
-                        s->chroma_non_intra_matrix[j]= v;
2728
+                        s->inter_matrix[j]= v;
2729
+                        s->chroma_inter_matrix[j]= v;
2730 2730
                     }
2731 2731
 
2732 2732
                     /* replicate last value */
2733 2733
                     for(; i<64; i++){
2734 2734
                         j= zigzag_direct[i];
2735
-                        s->non_intra_matrix[j]= v;
2736
-                        s->chroma_non_intra_matrix[j]= v;
2735
+                        s->inter_matrix[j]= v;
2736
+                        s->chroma_inter_matrix[j]= v;
2737 2737
                     }
2738 2738
                 }
2739 2739
 
... ...
@@ -73,17 +73,13 @@ static int h263_decode_init(AVCodecContext *avctx)
73 73
     default:
74 74
         return -1;
75 75
     }
76
-
76
+    s->codec_id= avctx->codec->id;
77
+    
77 78
     /* for h263, we allocate the images after having read the header */
78 79
     if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
79 80
         if (MPV_common_init(s) < 0)
80 81
             return -1;
81 82
 
82
-    /* XXX: suppress this matrix init, only needed because using mpeg1
83
-       dequantize in mmx case */
84
-    for(i=0;i<64;i++)
85
-        s->non_intra_matrix[i] = default_non_intra_matrix[i];
86
-
87 83
     if (s->h263_msmpeg4)
88 84
         msmpeg4_decode_init_vlc(s);
89 85
     else
... ...
@@ -251,7 +247,7 @@ static int h263_decode_frame(AVCodecContext *avctx,
251 251
         if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1;
252 252
     
253 253
     /* divx 5.01+ bistream reorder stuff */
254
-    if(s->h263_pred && s->bitstream_buffer_size==0){
254
+    if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0){
255 255
         int current_pos= get_bits_count(&s->gb)/8;
256 256
         if(   buf_size - current_pos > 5 
257 257
            && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){
... ...
@@ -26,8 +26,6 @@
26 26
 #include "../mangle.h"
27 27
 
28 28
 extern UINT8 zigzag_end[64];
29
-extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w);
30
-extern int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale);
31 29
 
32 30
 extern UINT8 zigzag_direct_noperm[64];
33 31
 extern UINT16 inv_zigzag_direct16[64];
... ...
@@ -260,7 +258,7 @@ asm volatile(
260 260
         block[0]= block0;
261 261
 
262 262
         } else {
263
-        quant_matrix = s->non_intra_matrix;
263
+        quant_matrix = s->inter_matrix;
264 264
 asm volatile(
265 265
 		"pcmpeqw %%mm7, %%mm7		\n\t"
266 266
 		"psrlw $15, %%mm7		\n\t"
... ...
@@ -382,7 +380,7 @@ asm volatile(
382 382
         //Note, we dont do mismatch control for intra as errors cannot accumulate
383 383
 
384 384
     } else {
385
-        quant_matrix = s->non_intra_matrix;
385
+        quant_matrix = s->inter_matrix;
386 386
 asm volatile(
387 387
 		"pcmpeqw %%mm7, %%mm7		\n\t"
388 388
                 "psrlq $48, %%mm7		\n\t"
... ...
@@ -33,149 +33,160 @@
33 33
 
34 34
 static int RENAME(dct_quantize)(MpegEncContext *s,
35 35
                             DCTELEM *block, int n,
36
-                            int qscale)
36
+                            int qscale, int *overflow)
37 37
 {
38
-    int i, level, last_non_zero_p1, q;
39
-    const UINT16 *qmat;
38
+    int level=0, last_non_zero_p1, q; //=0 is cuz gcc says uninitalized ...
39
+    const UINT16 *qmat, *bias;
40 40
     static __align8 INT16 temp_block[64];
41
-    int minLevel, maxLevel;
42
-    
43
-    if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){
44
-	/* mpeg4 */
45
-        minLevel= -2048;
46
-	maxLevel= 2047;
47
-    }else if(s->out_format==FMT_MPEG1){
48
-	/* mpeg1 */
49
-        minLevel= -255;
50
-	maxLevel= 255;
51
-    }else if(s->out_format==FMT_MJPEG){
52
-	/* (m)jpeg */
53
-        minLevel= -1023;
54
-	maxLevel= 1023;
55
-    }else{
56
-	/* h263 / msmpeg4 */
57
-        minLevel= -128;
58
-	maxLevel= 127;
59
-    }
60 41
 
61 42
     av_fdct (block);
62
-    
43
+
63 44
     if (s->mb_intra) {
64 45
         int dummy;
65 46
         if (n < 4)
66 47
             q = s->y_dc_scale;
67 48
         else
68 49
             q = s->c_dc_scale;
69
-        
70 50
         /* note: block[0] is assumed to be positive */
71 51
 #if 1
72
-	asm volatile (
73
-		"xorl %%edx, %%edx	\n\t"
74
-		"mul %%ecx		\n\t"
75
-		: "=d" (temp_block[0]), "=a"(dummy)
76
-		: "a" (block[0] + (q >> 1)), "c" (inverse[q])
77
-	);
52
+        asm volatile (
53
+        	"xorl %%edx, %%edx	\n\t"
54
+        	"mul %%ecx		\n\t"
55
+        	: "=d" (level), "=a"(dummy)
56
+        	: "a" (block[0] + (q >> 1)), "c" (inverse[q])
57
+        );
78 58
 #else
79
-	asm volatile (
80
-		"xorl %%edx, %%edx	\n\t"
81
-		"divw %%cx		\n\t"
82
-		"movzwl %%ax, %%eax	\n\t"
83
-		: "=a" (temp_block[0])
84
-		: "a" (block[0] + (q >> 1)), "c" (q)
85
-		: "%edx"
86
-	);
59
+        asm volatile (
60
+        	"xorl %%edx, %%edx	\n\t"
61
+        	"divw %%cx		\n\t"
62
+        	"movzwl %%ax, %%eax	\n\t"
63
+        	: "=a" (level)
64
+        	: "a" (block[0] + (q >> 1)), "c" (q)
65
+        	: "%edx"
66
+        );
87 67
 #endif
68
+        block[0]=0; //avoid fake overflow
88 69
 //        temp_block[0] = (block[0] + (q >> 1)) / q;
89
-        i = 1;
90 70
         last_non_zero_p1 = 1;
91
-        if (s->out_format == FMT_H263) {
92
-            qmat = s->q_non_intra_matrix16;
93
-        } else {
94
-            qmat = s->q_intra_matrix16;
95
-        }
96
-        for(i=1;i<4;i++) {
97
-            level = block[i] * qmat[i];
98
-            level = level / (1 << (QMAT_SHIFT_MMX - 3));
99
-            /* XXX: currently, this code is not optimal. the range should be:
100
-               mpeg1: -255..255
101
-               mpeg2: -2048..2047
102
-               h263:  -128..127
103
-               mpeg4: -2048..2047
104
-            */
105
-            if (level > maxLevel)
106
-                level = maxLevel;
107
-            else if (level < minLevel)
108
-                level = minLevel;
109
-            temp_block[i] = level;
110
-
111
-	    if(level) 
112
-	        if(last_non_zero_p1 < inv_zigzag_direct16[i]) last_non_zero_p1= inv_zigzag_direct16[i];
113
-	    block[i]=0;
114
-        }
71
+        bias = s->q_intra_matrix16_bias[qscale];
72
+        qmat = s->q_intra_matrix16[qscale];
115 73
     } else {
116
-        i = 0;
117 74
         last_non_zero_p1 = 0;
118
-        qmat = s->q_non_intra_matrix16;
75
+        bias = s->q_inter_matrix16_bias[qscale];
76
+        qmat = s->q_inter_matrix16[qscale];
119 77
     }
120 78
 
121
-    asm volatile( /* XXX: small rounding bug, but it shouldnt matter */
122
-	"movd %3, %%mm3			\n\t"
123
-	SPREADW(%%mm3)
124
-	"movd %4, %%mm4			\n\t"
125
-	SPREADW(%%mm4)
126
-#ifndef HAVE_MMX2	
127
-	"movd %5, %%mm5			\n\t"
128
-	SPREADW(%%mm5)
129
-#endif
130
-	"pxor %%mm7, %%mm7		\n\t"
131
-	"movd %%eax, %%mm2		\n\t"
132
-	SPREADW(%%mm2)
133
-	"movl %6, %%eax			\n\t"
134
-	".balign 16			\n\t"
135
-	"1:				\n\t"
136
-	"movq (%1, %%eax), %%mm0	\n\t"
137
-	"movq (%2, %%eax), %%mm1	\n\t"
138
-	"movq %%mm0, %%mm6		\n\t"
139
-	"psraw $15, %%mm6		\n\t"
140
-	"pmulhw %%mm0, %%mm1		\n\t"
141
-	"psubsw %%mm6, %%mm1		\n\t"
142
-#ifdef HAVE_MMX2
143
-	"pminsw %%mm3, %%mm1		\n\t"
144
-	"pmaxsw %%mm4, %%mm1		\n\t"
145
-#else
146
-	"paddsw %%mm3, %%mm1		\n\t"
147
-	"psubusw %%mm4, %%mm1		\n\t"
148
-	"paddsw %%mm5, %%mm1		\n\t"
149
-#endif
150
-	"movq %%mm1, (%8, %%eax)	\n\t"
151
-	"pcmpeqw %%mm7, %%mm1		\n\t"
152
-	"movq (%7, %%eax), %%mm0	\n\t"
153
-	"movq %%mm7, (%1, %%eax)	\n\t"
154
-	"pandn %%mm0, %%mm1		\n\t"
155
-	PMAXW(%%mm1, %%mm2)
156
-	"addl $8, %%eax			\n\t"
157
-	" js 1b				\n\t"
158
-	"movq %%mm2, %%mm0		\n\t"
159
-	"psrlq $32, %%mm2		\n\t"
160
-	PMAXW(%%mm0, %%mm2)
161
-	"movq %%mm2, %%mm0		\n\t"
162
-	"psrlq $16, %%mm2		\n\t"
163
-	PMAXW(%%mm0, %%mm2)
164
-	"movd %%mm2, %%eax		\n\t"
165
-	"movzbl %%al, %%eax		\n\t"
166
-	: "+a" (last_non_zero_p1)
167
-	: "r" (block+64), "r" (qmat+64), 
168
-#ifdef HAVE_MMX2
169
-	  "m" (maxLevel),          "m" (minLevel),                    "m" (minLevel /* dummy */), "g" (2*i - 128),
170
-#else
171
-	  "m" (0x7FFF - maxLevel), "m" (0x7FFF -maxLevel + minLevel), "m" (minLevel),             "g" (2*i - 128),
172
-#endif
173
-	  "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
174
-    );
79
+    if(s->out_format == FMT_H263){
80
+    
81
+        asm volatile(
82
+            "movd %%eax, %%mm3			\n\t" // last_non_zero_p1
83
+            SPREADW(%%mm3)
84
+            "pxor %%mm7, %%mm7			\n\t" // 0
85
+            "pxor %%mm4, %%mm4			\n\t" // 0
86
+            "movq (%2), %%mm5			\n\t" // qmat[0]
87
+            "pxor %%mm6, %%mm6			\n\t"
88
+            "psubw (%3), %%mm6			\n\t" // -bias[0]
89
+            "movl $-128, %%eax			\n\t"
90
+            ".balign 16				\n\t"
91
+            "1:					\n\t"
92
+            "pxor %%mm1, %%mm1			\n\t" // 0
93
+            "movq (%1, %%eax), %%mm0		\n\t" // block[i]
94
+            "pcmpgtw %%mm0, %%mm1		\n\t" // block[i] <= 0 ? 0xFF : 0x00
95
+            "pxor %%mm1, %%mm0			\n\t" 
96
+            "psubw %%mm1, %%mm0			\n\t" // ABS(block[i])
97
+            "psubusw %%mm6, %%mm0		\n\t" // ABS(block[i]) + bias[0]
98
+            "pmulhw %%mm5, %%mm0		\n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
99
+            "por %%mm0, %%mm4			\n\t" 
100
+            "pxor %%mm1, %%mm0			\n\t" 
101
+            "psubw %%mm1, %%mm0			\n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
102
+            "movq %%mm0, (%5, %%eax)		\n\t"
103
+            "pcmpeqw %%mm7, %%mm0		\n\t" // out==0 ? 0xFF : 0x00
104
+            "movq (%4, %%eax), %%mm1		\n\t" 
105
+            "movq %%mm7, (%1, %%eax)		\n\t" // 0
106
+            "pandn %%mm1, %%mm0			\n\t"
107
+	    PMAXW(%%mm0, %%mm3)
108
+            "addl $8, %%eax			\n\t"
109
+            " js 1b				\n\t"
110
+            "movq %%mm3, %%mm0			\n\t"
111
+            "psrlq $32, %%mm3			\n\t"
112
+	    PMAXW(%%mm0, %%mm3)
113
+            "movq %%mm3, %%mm0			\n\t"
114
+            "psrlq $16, %%mm3			\n\t"
115
+	    PMAXW(%%mm0, %%mm3)
116
+            "movd %%mm3, %%eax			\n\t"
117
+            "movzbl %%al, %%eax			\n\t" // last_non_zero_p1
118
+	    : "+a" (last_non_zero_p1)
119
+            : "r" (block+64), "r" (qmat), "r" (bias),
120
+              "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
121
+        );
122
+        // note the asm is split cuz gcc doesnt like that many operands ...
123
+        asm volatile(
124
+            "movd %1, %%mm1			\n\t" // max_qcoeff
125
+	    SPREADW(%%mm1)
126
+            "psubusw %%mm1, %%mm4		\n\t" 
127
+            "packuswb %%mm4, %%mm4		\n\t"
128
+            "movd %%mm4, %0			\n\t" // *overflow
129
+        : "=g" (*overflow)
130
+        : "g" (s->max_qcoeff)
131
+        );
132
+    }else{ // FMT_H263
133
+        asm volatile(
134
+            "movd %%eax, %%mm3			\n\t" // last_non_zero_p1
135
+            SPREADW(%%mm3)
136
+            "pxor %%mm7, %%mm7			\n\t" // 0
137
+            "pxor %%mm4, %%mm4			\n\t" // 0
138
+            "movl $-128, %%eax			\n\t"
139
+            ".balign 16				\n\t"
140
+            "1:					\n\t"
141
+            "pxor %%mm1, %%mm1			\n\t" // 0
142
+            "movq (%1, %%eax), %%mm0		\n\t" // block[i]
143
+            "pcmpgtw %%mm0, %%mm1		\n\t" // block[i] <= 0 ? 0xFF : 0x00
144
+            "pxor %%mm1, %%mm0			\n\t" 
145
+            "psubw %%mm1, %%mm0			\n\t" // ABS(block[i])
146
+            "movq (%3, %%eax), %%mm6		\n\t" // bias[0]
147
+            "paddusw %%mm6, %%mm0		\n\t" // ABS(block[i]) + bias[0]
148
+            "movq (%2, %%eax), %%mm5		\n\t" // qmat[i]
149
+            "pmulhw %%mm5, %%mm0		\n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16
150
+            "por %%mm0, %%mm4			\n\t" 
151
+            "pxor %%mm1, %%mm0			\n\t" 
152
+            "psubw %%mm1, %%mm0			\n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
153
+            "movq %%mm0, (%5, %%eax)		\n\t"
154
+            "pcmpeqw %%mm7, %%mm0		\n\t" // out==0 ? 0xFF : 0x00
155
+            "movq (%4, %%eax), %%mm1		\n\t" 
156
+            "movq %%mm7, (%1, %%eax)		\n\t" // 0
157
+            "pandn %%mm1, %%mm0			\n\t"
158
+	    PMAXW(%%mm0, %%mm3)
159
+            "addl $8, %%eax			\n\t"
160
+            " js 1b				\n\t"
161
+            "movq %%mm3, %%mm0			\n\t"
162
+            "psrlq $32, %%mm3			\n\t"
163
+	    PMAXW(%%mm0, %%mm3)
164
+            "movq %%mm3, %%mm0			\n\t"
165
+            "psrlq $16, %%mm3			\n\t"
166
+	    PMAXW(%%mm0, %%mm3)
167
+            "movd %%mm3, %%eax			\n\t"
168
+            "movzbl %%al, %%eax			\n\t" // last_non_zero_p1
169
+	    : "+a" (last_non_zero_p1)
170
+            : "r" (block+64), "r" (qmat+64), "r" (bias+64),
171
+              "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
172
+        );
173
+        // note the asm is split cuz gcc doesnt like that many operands ...
174
+        asm volatile(
175
+            "movd %1, %%mm1			\n\t" // max_qcoeff
176
+	    SPREADW(%%mm1)
177
+            "psubusw %%mm1, %%mm4		\n\t" 
178
+            "packuswb %%mm4, %%mm4		\n\t"
179
+            "movd %%mm4, %0			\n\t" // *overflow
180
+        : "=g" (*overflow)
181
+        : "g" (s->max_qcoeff)
182
+        );
183
+    }
184
+
185
+    if(s->mb_intra) temp_block[0]= level; //FIXME move afer permute
175 186
 // last_non_zero_p1=64;       
176 187
     /* permute for IDCT */
177 188
     asm volatile(
178
-	"movl %0, %%eax			\n\t"
189
+        "movl %0, %%eax			\n\t"
179 190
 	"pushl %%ebp			\n\t"
180 191
 	"movl %%esp, " MANGLE(esp_temp) "\n\t"
181 192
 	"1:				\n\t"
... ...
@@ -203,5 +214,6 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
203 203
     }
204 204
 */
205 205
 //block_permute(block);
206
+
206 207
     return last_non_zero_p1 - 1;
207 208
 }
... ...
@@ -160,6 +160,9 @@ int mjpeg_init(MpegEncContext *s)
160 160
     m = malloc(sizeof(MJpegContext));
161 161
     if (!m)
162 162
         return -1;
163
+    
164
+    s->min_qcoeff=-1023;
165
+    s->max_qcoeff= 1023;
163 166
 
164 167
     /* build all the huffman tables */
165 168
     build_huffman_codes(m->huff_size_dc_luminance,
... ...
@@ -399,8 +399,11 @@ void mpeg1_encode_init(MpegEncContext *s)
399 399
         }
400 400
     }
401 401
     s->mv_penalty= mv_penalty;
402
-    
403 402
     s->fcode_tab= fcode_tab;
403
+    s->min_qcoeff=-255;
404
+    s->max_qcoeff= 255;
405
+    s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
406
+    s->inter_quant_bias= 0;
404 407
 }
405 408
  
406 409
 static inline void encode_dc(MpegEncContext *s, int diff, int component)
... ...
@@ -1027,9 +1030,9 @@ static int mpeg2_decode_block_non_intra(MpegEncContext *s,
1027 1027
         UINT8 *buf_ptr;
1028 1028
         i = 0;
1029 1029
         if (n < 4) 
1030
-            matrix = s->non_intra_matrix;
1030
+            matrix = s->inter_matrix;
1031 1031
         else
1032
-            matrix = s->chroma_non_intra_matrix;
1032
+            matrix = s->chroma_inter_matrix;
1033 1033
             
1034 1034
         /* special case for the first coef. no need to add a second vlc table */
1035 1035
         SAVE_BITS(&s->gb);
... ...
@@ -1183,6 +1186,7 @@ static int mpeg_decode_init(AVCodecContext *avctx)
1183 1183
     s->buf_ptr = s->buffer;
1184 1184
     s->mpeg_enc_ctx.picture_number = 0;
1185 1185
     s->repeat_field = 0;
1186
+    s->mpeg_enc_ctx.codec_id= avctx->codec->id;
1186 1187
     return 0;
1187 1188
 }
1188 1189
 
... ...
@@ -1292,8 +1296,8 @@ static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
1292 1292
         for(i=0;i<64;i++) {
1293 1293
             v = get_bits(&s->gb, 8);
1294 1294
             j = zigzag_direct[i];
1295
-            s->non_intra_matrix[j] = v;
1296
-            s->chroma_non_intra_matrix[j] = v;
1295
+            s->inter_matrix[j] = v;
1296
+            s->chroma_inter_matrix[j] = v;
1297 1297
         }
1298 1298
     }
1299 1299
     if (get_bits1(&s->gb)) {
... ...
@@ -1307,7 +1311,7 @@ static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
1307 1307
         for(i=0;i<64;i++) {
1308 1308
             v = get_bits(&s->gb, 8);
1309 1309
             j = zigzag_direct[i];
1310
-            s->chroma_non_intra_matrix[j] = v;
1310
+            s->chroma_inter_matrix[j] = v;
1311 1311
         }
1312 1312
     }
1313 1313
 }
... ...
@@ -1386,7 +1390,6 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
1386 1386
     s->mb_x = -1;
1387 1387
     s->mb_y = start_code;
1388 1388
     s->mb_incr = 0;
1389
-
1390 1389
     /* start frame decoding */
1391 1390
     if (s->first_slice) {
1392 1391
         s->first_slice = 0;
... ...
@@ -1526,20 +1529,20 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
1526 1526
         for(i=0;i<64;i++) {
1527 1527
             v = get_bits(&s->gb, 8);
1528 1528
             j = zigzag_direct[i];
1529
-            s->non_intra_matrix[j] = v;
1530
-            s->chroma_non_intra_matrix[j] = v;
1529
+            s->inter_matrix[j] = v;
1530
+            s->chroma_inter_matrix[j] = v;
1531 1531
         }
1532 1532
 #ifdef DEBUG
1533 1533
         dprintf("non intra matrix present\n");
1534 1534
         for(i=0;i<64;i++)
1535
-            dprintf(" %d", s->non_intra_matrix[zigzag_direct[i]]);
1535
+            dprintf(" %d", s->inter_matrix[zigzag_direct[i]]);
1536 1536
         printf("\n");
1537 1537
 #endif
1538 1538
     } else {
1539 1539
         for(i=0;i<64;i++) {
1540 1540
             v = default_non_intra_matrix[i];
1541
-            s->non_intra_matrix[i] = v;
1542
-            s->chroma_non_intra_matrix[i] = v;
1541
+            s->inter_matrix[i] = v;
1542
+            s->chroma_inter_matrix[i] = v;
1543 1543
         }
1544 1544
     }
1545 1545
 
... ...
@@ -1566,7 +1569,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
1566 1566
     dprintf("fill_buffer\n");
1567 1567
 
1568 1568
     *data_size = 0;
1569
-    
1569
+
1570 1570
     /* special case for last picture */
1571 1571
     if (buf_size == 0) {
1572 1572
         if (s2->picture_number > 0) {
... ...
@@ -1591,7 +1594,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
1591 1591
         *data_size = sizeof(AVPicture);
1592 1592
         goto the_end;
1593 1593
     }
1594
-        
1594
+
1595 1595
     while (buf_ptr < buf_end) {
1596 1596
         buf_start = buf_ptr;
1597 1597
         /* find start next code */
... ...
@@ -38,9 +38,9 @@ static void dct_unquantize_mpeg2_c(MpegEncContext *s,
38 38
 static void dct_unquantize_h263_c(MpegEncContext *s, 
39 39
                                   DCTELEM *block, int n, int qscale);
40 40
 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w);
41
-static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale);
41
+static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
42 42
 
43
-int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale)= dct_quantize_c;
43
+int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)= dct_quantize_c;
44 44
 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c;
45 45
 
46 46
 #define EDGE_WIDTH 16
... ...
@@ -78,29 +78,38 @@ extern UINT8 zigzag_end[64];
78 78
 /* default motion estimation */
79 79
 int motion_estimation_method = ME_EPZS;
80 80
 
81
-static void convert_matrix(int *qmat, UINT16 *qmat16, const UINT16 *quant_matrix, int qscale)
81
+static void convert_matrix(int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64],
82
+                           const UINT16 *quant_matrix, int bias)
82 83
 {
83
-    int i;
84
-
85
-    if (av_fdct == jpeg_fdct_ifast) {
86
-        for(i=0;i<64;i++) {
87
-            /* 16 <= qscale * quant_matrix[i] <= 7905 */
88
-            /* 19952         <= aanscales[i] * qscale * quant_matrix[i]           <= 249205026 */
89
-            /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
90
-            /* 3444240       >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
91
-            
92
-            qmat[block_permute_op(i)] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / 
93
-                            (aanscales[i] * qscale * quant_matrix[block_permute_op(i)]));
94
-        }
95
-    } else {
96
-        for(i=0;i<64;i++) {
97
-            /* We can safely suppose that 16 <= quant_matrix[i] <= 255
98
-               So 16           <= qscale * quant_matrix[i]             <= 7905
99
-               so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
100
-               so 32768        >= (1<<19) / (qscale * quant_matrix[i]) >= 67
101
-            */
102
-            qmat[i]   = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
103
-            qmat16[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]);
84
+    int qscale;
85
+
86
+    for(qscale=1; qscale<32; qscale++){
87
+        int i;
88
+        if (av_fdct == jpeg_fdct_ifast) {
89
+            for(i=0;i<64;i++) {
90
+                const int j= block_permute_op(i);
91
+                /* 16 <= qscale * quant_matrix[i] <= 7905 */
92
+                /* 19952         <= aanscales[i] * qscale * quant_matrix[i]           <= 249205026 */
93
+                /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
94
+                /* 3444240       >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
95
+                
96
+                qmat[qscale][j] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / 
97
+                                (aanscales[i] * qscale * quant_matrix[j]));
98
+            }
99
+        } else {
100
+            for(i=0;i<64;i++) {
101
+                /* We can safely suppose that 16 <= quant_matrix[i] <= 255
102
+                   So 16           <= qscale * quant_matrix[i]             <= 7905
103
+                   so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
104
+                   so 32768        >= (1<<19) / (qscale * quant_matrix[i]) >= 67
105
+                */
106
+                qmat  [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
107
+                qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]);
108
+
109
+                if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1;
110
+
111
+                qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]);
112
+            }
104 113
         }
105 114
     }
106 115
 }
... ...
@@ -388,7 +397,8 @@ int MPV_encode_init(AVCodecContext *avctx)
388 388
     s->max_b_frames= avctx->max_b_frames;
389 389
     s->rc_strategy= avctx->rc_strategy;
390 390
     s->b_frame_strategy= avctx->b_frame_strategy;
391
-    
391
+    s->codec_id= avctx->codec->id;
392
+
392 393
     if (s->gop_size <= 1) {
393 394
         s->intra_only = 1;
394 395
         s->gop_size = 12;
... ...
@@ -523,8 +533,21 @@ int MPV_encode_init(AVCodecContext *avctx)
523 523
     
524 524
     /* init default q matrix */
525 525
     for(i=0;i<64;i++) {
526
-        s->intra_matrix[i] = default_intra_matrix[i];
527
-        s->non_intra_matrix[i] = default_non_intra_matrix[i];
526
+        if(s->out_format == FMT_H263)
527
+            s->intra_matrix[i] = default_non_intra_matrix[i];
528
+        else
529
+            s->intra_matrix[i] = default_intra_matrix[i];
530
+
531
+        s->inter_matrix[i] = default_non_intra_matrix[i];
532
+    }
533
+
534
+    /* precompute matrix */
535
+        /* for mjpeg, we do include qscale in the matrix */
536
+    if (s->out_format != FMT_MJPEG) {
537
+        convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, 
538
+                       s->intra_matrix, s->intra_quant_bias);
539
+        convert_matrix(s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, 
540
+                       s->inter_matrix, s->inter_quant_bias);
528 541
     }
529 542
 
530 543
     if(ff_rate_control_init(s) < 0)
... ...
@@ -1307,6 +1330,21 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
1307 1307
     emms_c(); //FIXME remove
1308 1308
 }
1309 1309
 
1310
+static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index)
1311
+{
1312
+    int i;
1313
+    const int maxlevel= s->max_qcoeff;
1314
+    const int minlevel= s->min_qcoeff;
1315
+
1316
+    for(i=0; i<=last_index; i++){
1317
+        const int j = zigzag_direct[i];
1318
+        int level = block[j];
1319
+       
1320
+        if     (level>maxlevel) level=maxlevel;
1321
+        else if(level<minlevel) level=minlevel;
1322
+        block[j]= level;
1323
+    }
1324
+}
1310 1325
 
1311 1326
 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
1312 1327
 {
... ...
@@ -1407,8 +1445,19 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
1407 1407
         s->y_dc_scale = 8;
1408 1408
         s->c_dc_scale = 8;
1409 1409
     }
1410
-    for(i=0;i<6;i++) {
1411
-        s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale);
1410
+    if(s->out_format==FMT_MJPEG){
1411
+        for(i=0;i<6;i++) {
1412
+            int overflow;
1413
+            s->block_last_index[i] = dct_quantize(s, s->block[i], i, 8, &overflow);
1414
+            if(overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
1415
+        }
1416
+    }else{
1417
+        for(i=0;i<6;i++) {
1418
+            int overflow;
1419
+            s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale, &overflow);
1420
+            // FIXME we could decide to change to quantizer instead of clipping
1421
+            if(overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
1422
+        }
1412 1423
     }
1413 1424
 
1414 1425
     /* huffman encode */
... ...
@@ -1596,17 +1645,13 @@ static void encode_picture(MpegEncContext *s, int picture_number)
1596 1596
     else if (!s->fixed_qscale) 
1597 1597
         s->qscale = ff_rate_estimate_qscale(s);
1598 1598
 
1599
-
1600
-    /* precompute matrix */
1601 1599
     if (s->out_format == FMT_MJPEG) {
1602 1600
         /* for mjpeg, we do include qscale in the matrix */
1603 1601
         s->intra_matrix[0] = default_intra_matrix[0];
1604 1602
         for(i=1;i<64;i++)
1605 1603
             s->intra_matrix[i] = (default_intra_matrix[i] * s->qscale) >> 3;
1606
-        convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, 8);
1607
-    } else {
1608
-        convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->qscale);
1609
-        convert_matrix(s->q_non_intra_matrix, s->q_non_intra_matrix16, s->non_intra_matrix, s->qscale);
1604
+        convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, 
1605
+                       s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias);
1610 1606
     }
1611 1607
 
1612 1608
     s->last_bits= get_bit_count(&s->pb);
... ...
@@ -1957,29 +2002,13 @@ static void encode_picture(MpegEncContext *s, int picture_number)
1957 1957
 
1958 1958
 static int dct_quantize_c(MpegEncContext *s, 
1959 1959
                         DCTELEM *block, int n,
1960
-                        int qscale)
1960
+                        int qscale, int *overflow)
1961 1961
 {
1962 1962
     int i, j, level, last_non_zero, q;
1963 1963
     const int *qmat;
1964
-    int minLevel, maxLevel;
1965
-
1966
-    if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){
1967
-	/* mpeg4 */
1968
-        minLevel= -2048;
1969
-	maxLevel= 2047;
1970
-    }else if(s->out_format==FMT_MPEG1){
1971
-	/* mpeg1 */
1972
-        minLevel= -255;
1973
-	maxLevel= 255;
1974
-    }else if(s->out_format==FMT_MJPEG){
1975
-	/* (m)jpeg */
1976
-        minLevel= -1023;
1977
-	maxLevel= 1023;
1978
-    }else{
1979
-	/* h263 / msmpeg4 */
1980
-        minLevel= -128;
1981
-	maxLevel= 127;
1982
-    }
1964
+    int bias;
1965
+    int max=0;
1966
+    unsigned int threshold1, threshold2;
1983 1967
 
1984 1968
     av_fdct (block);
1985 1969
 
... ...
@@ -1998,71 +2027,40 @@ static int dct_quantize_c(MpegEncContext *s,
1998 1998
         block[0] = (block[0] + (q >> 1)) / q;
1999 1999
         i = 1;
2000 2000
         last_non_zero = 0;
2001
-        if (s->out_format == FMT_H263) {
2002
-            qmat = s->q_non_intra_matrix;
2003
-        } else {
2004
-            qmat = s->q_intra_matrix;
2005
-        }
2001
+        qmat = s->q_intra_matrix[qscale];
2002
+        bias= s->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);
2006 2003
     } else {
2007 2004
         i = 0;
2008 2005
         last_non_zero = -1;
2009
-        qmat = s->q_non_intra_matrix;
2006
+        qmat = s->q_inter_matrix[qscale];
2007
+        bias= s->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT);
2010 2008
     }
2009
+    threshold1= (1<<(QMAT_SHIFT - 3)) - bias - 1;
2010
+    threshold2= threshold1<<1;
2011 2011
 
2012 2012
     for(;i<64;i++) {
2013 2013
         j = zigzag_direct[i];
2014 2014
         level = block[j];
2015 2015
         level = level * qmat[j];
2016
-#ifdef PARANOID
2017
-        {
2018
-            static int count = 0;
2019
-            int level1, level2, qmat1;
2020
-            double val;
2021
-            if (qmat == s->q_non_intra_matrix) {
2022
-                qmat1 = default_non_intra_matrix[j] * s->qscale;
2023
-            } else {
2024
-                qmat1 = default_intra_matrix[j] * s->qscale;
2025
-            }
2026
-            if (av_fdct != jpeg_fdct_ifast)
2027
-                val = ((double)block[j] * 8.0) / (double)qmat1;
2028
-            else
2029
-                val = ((double)block[j] * 8.0 * 2048.0) / 
2030
-                    ((double)qmat1 * aanscales[j]);
2031
-            level1 = (int)val;
2032
-            level2 = level / (1 << (QMAT_SHIFT - 3));
2033
-            if (level1 != level2) {
2034
-                fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n", 
2035
-                        count, level2, level1, block[j], qmat1, qmat[j],
2036
-                        val);
2037
-                count++;
2038
-            }
2039 2016
 
2040
-        }
2041
-#endif
2042
-        /* XXX: slight error for the low range. Test should be equivalent to
2043
-           (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 <<
2044
-           (QMAT_SHIFT - 3)))
2045
-        */
2046
-        if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != 
2047
-            level) {
2048
-            level = level / (1 << (QMAT_SHIFT - 3));
2049
-            /* XXX: currently, this code is not optimal. the range should be:
2050
-               mpeg1: -255..255
2051
-               mpeg2: -2048..2047
2052
-               h263:  -128..127
2053
-               mpeg4: -2048..2047
2054
-            */
2055
-            if (level > maxLevel)
2056
-                level = maxLevel;
2057
-            else if (level < minLevel)
2058
-                level = minLevel;
2059
-
2060
-            block[j] = level;
2017
+//        if(   bias+level >= (1<<(QMAT_SHIFT - 3))
2018
+//           || bias-level >= (1<<(QMAT_SHIFT - 3))){
2019
+        if(((unsigned)(level+threshold1))>threshold2){
2020
+            if(level>0){
2021
+                level= (bias + level)>>(QMAT_SHIFT - 3);
2022
+                block[j]= level;
2023
+            }else{
2024
+                level= (bias - level)>>(QMAT_SHIFT - 3);
2025
+                block[j]= -level;
2026
+            }
2027
+            max |=level;
2061 2028
             last_non_zero = i;
2062
-        } else {
2063
-            block[j] = 0;
2029
+        }else{
2030
+            block[j]=0;
2064 2031
         }
2065 2032
     }
2033
+    *overflow= s->max_qcoeff < max; //overflow might have happend
2034
+    
2066 2035
     return last_non_zero;
2067 2036
 }
2068 2037
 
... ...
@@ -2104,7 +2102,7 @@ static void dct_unquantize_mpeg1_c(MpegEncContext *s,
2104 2104
         }
2105 2105
     } else {
2106 2106
         i = 0;
2107
-        quant_matrix = s->non_intra_matrix;
2107
+        quant_matrix = s->inter_matrix;
2108 2108
         for(;i<nCoeffs;i++) {
2109 2109
             int j= zigzag_direct[i];
2110 2110
             level = block[j];
... ...
@@ -2166,7 +2164,7 @@ static void dct_unquantize_mpeg2_c(MpegEncContext *s,
2166 2166
     } else {
2167 2167
         int sum=-1;
2168 2168
         i = 0;
2169
-        quant_matrix = s->non_intra_matrix;
2169
+        quant_matrix = s->inter_matrix;
2170 2170
         for(;i<nCoeffs;i++) {
2171 2171
             int j= zigzag_direct[i];
2172 2172
             level = block[j];
... ...
@@ -83,11 +83,15 @@ typedef struct MpegEncContext {
83 83
     int bit_rate;        /* wanted bit rate */
84 84
     int bit_rate_tolerance; /* amount of +- bits (>0)*/
85 85
     enum OutputFormat out_format; /* output format */
86
+    int h263_pred;    /* use mpeg4/h263 ac/dc predictions */
87
+
88
+/* the following codec id fields are deprecated in favor of codec_id */
86 89
     int h263_plus; /* h263 plus headers */
87 90
     int h263_rv10; /* use RV10 variation for H263 */
88
-    int h263_pred; /* use mpeg4/h263 ac/dc predictions */
89
-    int h263_msmpeg4; /* generate MSMPEG4 compatible stream */
91
+    int h263_msmpeg4; /* generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)*/
90 92
     int h263_intel; /* use I263 intel h263 header */
93
+    
94
+    int codec_id;     /* see CODEC_ID_xxx */
91 95
     int fixed_qscale; /* fixed qscale if non zero */
92 96
     float qcompress;  /* amount of qscale change between easy & hard scenes (0.0-1.0) */
93 97
     float qblur;      /* amount of qscale smoothing over time (0.0-1.0) */
... ...
@@ -213,14 +217,21 @@ typedef struct MpegEncContext {
213 213
     /* matrix transmitted in the bitstream */
214 214
     UINT16 intra_matrix[64];
215 215
     UINT16 chroma_intra_matrix[64];
216
-    UINT16 non_intra_matrix[64];
217
-    UINT16 chroma_non_intra_matrix[64];
216
+    UINT16 inter_matrix[64];
217
+    UINT16 chroma_inter_matrix[64];
218
+#define QUANT_BIAS_SHIFT 4
219
+    int intra_quant_bias;    /* bias for the quantizer */
220
+    int inter_quant_bias;    /* bias for the quantizer */
221
+    int min_qcoeff;          /* minimum encodable coefficient */
222
+    int max_qcoeff;          /* maximum encodable coefficient */
218 223
     /* precomputed matrix (combine qscale and DCT renorm) */
219
-    int q_intra_matrix[64];
220
-    int q_non_intra_matrix[64];
224
+    int q_intra_matrix[32][64];
225
+    int q_inter_matrix[32][64];
221 226
     /* identical to the above but for MMX & these are not permutated */
222
-    UINT16 __align8 q_intra_matrix16[64];
223
-    UINT16 __align8 q_non_intra_matrix16[64];
227
+    UINT16 __align8 q_intra_matrix16[32][64];
228
+    UINT16 __align8 q_inter_matrix16[32][64];
229
+    UINT16 __align8 q_intra_matrix16_bias[32][64];
230
+    UINT16 __align8 q_inter_matrix16_bias[32][64];
224 231
     int block_last_index[6];  /* last non zero coefficient in block */
225 232
 
226 233
     void *opaque; /* private data for the user */
... ...
@@ -328,7 +339,7 @@ typedef struct MpegEncContext {
328 328
     int first_slice_line;  /* used in mpeg4 too to handle resync markers */
329 329
     int flipflop_rounding;
330 330
     int bitrate;
331
-    int msmpeg4_version;   /* 1=mp41, 2=mp42, 3=mp43/divx3 */
331
+    int msmpeg4_version;   /* 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 */
332 332
     /* decompression specific */
333 333
     GetBitContext gb;
334 334
 
... ...
@@ -386,6 +397,8 @@ void MPV_frame_end(MpegEncContext *s);
386 386
 #ifdef HAVE_MMX
387 387
 void MPV_common_init_mmx(MpegEncContext *s);
388 388
 #endif
389
+int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
390
+void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w);
389 391
 
390 392
 /* motion_est.c */
391 393
 void ff_estimate_p_frame_motion(MpegEncContext * s,
... ...
@@ -340,6 +340,7 @@ static int rv10_decode_init(AVCodecContext *avctx)
340 340
     int i;
341 341
     static int done;
342 342
 
343
+//    s->avctx= avctx;
343 344
     s->out_format = FMT_H263;
344 345
 
345 346
     s->width = avctx->width;
... ...
@@ -351,11 +352,6 @@ static int rv10_decode_init(AVCodecContext *avctx)
351 351
     if (MPV_common_init(s) < 0)
352 352
         return -1;
353 353
 
354
-    /* XXX: suppress this matrix init, only needed because using mpeg1
355
-       dequantize in mmx case */
356
-    for(i=0;i<64;i++)
357
-        s->non_intra_matrix[i] = default_non_intra_matrix[i];
358
-
359 354
     h263_decode_init_vlc(s);
360 355
 
361 356
     /* init rv vlc */