Mercurial > libavcodec.hg
annotate msmpeg4.c @ 10795:342c2dbe0f94 libavcodec
More doxy
author | michael |
---|---|
date | Thu, 07 Jan 2010 15:12:31 +0000 |
parents | f108c5d10793 |
children | 4605bd2fdb7f |
rev | line source |
---|---|
0 | 1 /* |
2 * MSMPEG4 backend for ffmpeg encoder and decoder | |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8596
diff
changeset
|
3 * Copyright (c) 2001 Fabrice Bellard |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1651
diff
changeset
|
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 5 * |
5214 | 6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at> |
7 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
8 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
9 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
10 * FFmpeg is free software; you can redistribute it and/or |
429 | 11 * modify it under the terms of the GNU Lesser General Public |
12 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
13 * version 2.1 of the License, or (at your option) any later version. |
0 | 14 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
15 * FFmpeg is distributed in the hope that it will be useful, |
0 | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 * Lesser General Public License for more details. | |
0 | 19 * |
429 | 20 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3781
diff
changeset
|
21 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 23 */ |
1106 | 24 |
25 /** | |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8629
diff
changeset
|
26 * @file libavcodec/msmpeg4.c |
1106 | 27 * MSMPEG4 backend for ffmpeg encoder and decoder. |
28 */ | |
29 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
347
diff
changeset
|
30 #include "avcodec.h" |
0 | 31 #include "dsputil.h" |
32 #include "mpegvideo.h" | |
5884 | 33 #include "msmpeg4.h" |
10071
6ac0d4957d35
Replace #ifdef PIC checks with the more appropriate HAVE_EBX_AVAILABLE/HAVE_7REGS.
reimar
parents:
9998
diff
changeset
|
34 #include "libavutil/x86_cpu.h" |
411
5c8b3a717929
workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents:
396
diff
changeset
|
35 |
0 | 36 /* |
2967 | 37 * You can also call this codec : MPEG4 with a twist ! |
0 | 38 * |
2967 | 39 * TODO: |
0 | 40 * - (encoding) select best mv table (two choices) |
2967 | 41 * - (encoding) select best vlc/dc table |
0 | 42 */ |
43 //#define DEBUG | |
44 | |
531 | 45 #define DC_VLC_BITS 9 |
46 #define CBPY_VLC_BITS 6 | |
47 #define V1_INTRA_CBPC_VLC_BITS 6 | |
48 #define V1_INTER_CBPC_VLC_BITS 6 | |
49 #define V2_INTRA_CBPC_VLC_BITS 3 | |
50 #define V2_MB_TYPE_VLC_BITS 7 | |
51 #define MV_VLC_BITS 9 | |
52 #define V2_MV_VLC_BITS 9 | |
53 #define TEX_VLC_BITS 9 | |
54 | |
578 | 55 #define II_BITRATE 128*1024 |
56 #define MBAC_BITRATE 50*1024 | |
57 | |
936 | 58 #define DEFAULT_INTER_INDEX 3 |
59 | |
1064 | 60 static uint32_t v2_dc_lum_table[512][2]; |
61 static uint32_t v2_dc_chroma_table[512][2]; | |
307 | 62 |
3359 | 63 /* vc1 externs */ |
6146 | 64 extern const uint8_t wmv3_dc_scale_table[32]; |
601 | 65 |
0 | 66 #ifdef DEBUG |
67 int frame_count = 0; | |
68 #endif | |
69 | |
70 #include "msmpeg4data.h" | |
71 | |
8590 | 72 #if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced |
1064 | 73 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]; |
1325 | 74 #endif //CONFIG_ENCODERS |
601 | 75 |
4668 | 76 static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3]; |
77 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
78 /* This table is practically identical to the one from h263 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
79 * except that it is inverted. */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
80 static av_cold void init_h263_dc_for_msmpeg4(void) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
81 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
82 int level, uni_code, uni_len; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
83 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
84 for(level=-256; level<256; level++){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
85 int size, v, l; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
86 /* find number of bits */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
87 size = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
88 v = abs(level); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
89 while (v) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
90 v >>= 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
91 size++; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
92 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
93 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
94 if (level < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
95 l= (-level) ^ ((1 << size) - 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
96 else |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
97 l= level; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
98 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
99 /* luminance h263 */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
100 uni_code= DCtab_lum[size][0]; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
101 uni_len = DCtab_lum[size][1]; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
102 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
103 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
104 if (size > 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
105 uni_code<<=size; uni_code|=l; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
106 uni_len+=size; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
107 if (size > 8){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
108 uni_code<<=1; uni_code|=1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
109 uni_len++; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
110 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
111 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
112 v2_dc_lum_table[level+256][0]= uni_code; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
113 v2_dc_lum_table[level+256][1]= uni_len; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
114 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
115 /* chrominance h263 */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
116 uni_code= DCtab_chrom[size][0]; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
117 uni_len = DCtab_chrom[size][1]; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
118 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
119 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
120 if (size > 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
121 uni_code<<=size; uni_code|=l; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
122 uni_len+=size; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
123 if (size > 8){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
124 uni_code<<=1; uni_code|=1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
125 uni_len++; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
126 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
127 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
128 v2_dc_chroma_table[level+256][0]= uni_code; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
129 v2_dc_chroma_table[level+256][1]= uni_len; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
130 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
131 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
132 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
133 |
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8780
diff
changeset
|
134 static av_cold void common_init(MpegEncContext * s) |
499 | 135 { |
6350 | 136 static int initialized=0; |
2967 | 137 |
499 | 138 switch(s->msmpeg4_version){ |
139 case 1: | |
140 case 2: | |
141 s->y_dc_scale_table= | |
142 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
143 break; | |
144 case 3: | |
145 if(s->workaround_bugs){ | |
146 s->y_dc_scale_table= old_ff_y_dc_scale_table; | |
7136 | 147 s->c_dc_scale_table= wmv1_c_dc_scale_table; |
499 | 148 } else{ |
149 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; | |
150 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; | |
151 } | |
152 break; | |
153 case 4: | |
936 | 154 case 5: |
499 | 155 s->y_dc_scale_table= wmv1_y_dc_scale_table; |
156 s->c_dc_scale_table= wmv1_c_dc_scale_table; | |
157 break; | |
9995
3141f69e3905
Do not check for both CONFIG_VC1_DECODER and CONFIG_WMV3_DECODER,
diego
parents:
9455
diff
changeset
|
158 #if CONFIG_VC1_DECODER |
2474 | 159 case 6: |
160 s->y_dc_scale_table= wmv3_dc_scale_table; | |
161 s->c_dc_scale_table= wmv3_dc_scale_table; | |
162 break; | |
2639 | 163 #endif |
2474 | 164 |
499 | 165 } |
166 | |
2967 | 167 |
936 | 168 if(s->msmpeg4_version>=4){ |
1273 | 169 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , wmv1_scantable[1]); |
170 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, wmv1_scantable[2]); | |
171 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, wmv1_scantable[3]); | |
172 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , wmv1_scantable[0]); | |
499 | 173 } |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
174 //Note the default tables are set in common_init in mpegvideo.c |
2967 | 175 |
6350 | 176 if(!initialized){ |
177 initialized=1; | |
499 | 178 |
179 init_h263_dc_for_msmpeg4(); | |
180 } | |
181 } | |
182 | |
8590 | 183 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
184 |
0 | 185 /* build the table which associate a (x,y) motion vector to a vlc */ |
186 static void init_mv_table(MVTable *tab) | |
187 { | |
188 int i, x, y; | |
189 | |
1064 | 190 tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096); |
0 | 191 /* mark all entries as not used */ |
192 for(i=0;i<4096;i++) | |
193 tab->table_mv_index[i] = tab->n; | |
2967 | 194 |
0 | 195 for(i=0;i<tab->n;i++) { |
196 x = tab->table_mvx[i]; | |
197 y = tab->table_mvy[i]; | |
198 tab->table_mv_index[(x << 6) | y] = i; | |
199 } | |
200 } | |
201 | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
202 void ff_msmpeg4_code012(PutBitContext *pb, int n) |
0 | 203 { |
204 if (n == 0) { | |
205 put_bits(pb, 1, 0); | |
206 } else { | |
207 put_bits(pb, 1, 1); | |
208 put_bits(pb, 1, (n >= 2)); | |
209 } | |
210 } | |
211 | |
499 | 212 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){ |
213 int size=0; | |
214 int code; | |
215 int run_diff= intra ? 0 : 1; | |
2967 | 216 |
499 | 217 code = get_rl_index(rl, last, run, level); |
218 size+= rl->table_vlc[code][1]; | |
219 if (code == rl->n) { | |
220 int level1, run1; | |
221 | |
222 level1 = level - rl->max_level[last][run]; | |
2967 | 223 if (level1 < 1) |
499 | 224 goto esc2; |
225 code = get_rl_index(rl, last, run, level1); | |
226 if (code == rl->n) { | |
227 esc2: | |
228 size++; | |
229 if (level > MAX_LEVEL) | |
230 goto esc3; | |
231 run1 = run - rl->max_run[last][level] - run_diff; | |
232 if (run1 < 0) | |
233 goto esc3; | |
234 code = get_rl_index(rl, last, run1, level); | |
235 if (code == rl->n) { | |
236 esc3: | |
237 /* third escape */ | |
238 size+=1+1+6+8; | |
239 } else { | |
240 /* second escape */ | |
241 size+= 1+1+ rl->table_vlc[code][1]; | |
242 } | |
243 } else { | |
244 /* first escape */ | |
245 size+= 1+1+ rl->table_vlc[code][1]; | |
246 } | |
247 } else { | |
248 size++; | |
249 } | |
250 return size; | |
251 } | |
252 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
253 av_cold void ff_msmpeg4_encode_init(MpegEncContext *s) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
254 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
255 static int init_done=0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
256 int i; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
257 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
258 common_init(s); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
259 if(s->msmpeg4_version>=4){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
260 s->min_qcoeff= -255; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
261 s->max_qcoeff= 255; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
262 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
263 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
264 if (!init_done) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
265 /* init various encoding tables */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
266 init_done = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
267 init_mv_table(&mv_tables[0]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
268 init_mv_table(&mv_tables[1]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
269 for(i=0;i<NB_RL_TABLES;i++) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
270 init_rl(&rl_table[i], static_rl_table_store[i]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
271 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
272 for(i=0; i<NB_RL_TABLES; i++){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
273 int level; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
274 for(level=0; level<=MAX_LEVEL; level++){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
275 int run; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
276 for(run=0; run<=MAX_RUN; run++){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
277 int last; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
278 for(last=0; last<2; last++){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
279 rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
280 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
281 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
282 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
283 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
284 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
285 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
286 |
7994
ecade9a77827
Mark the ff_find_best_tables symbol static to msmpeg4. Patch by Diego Petten«Ò
lu_zero
parents:
7831
diff
changeset
|
287 static void find_best_tables(MpegEncContext * s) |
499 | 288 { |
289 int i; | |
290 int best =-1, best_size =9999999; | |
291 int chroma_best=-1, best_chroma_size=9999999; | |
601 | 292 |
499 | 293 for(i=0; i<3; i++){ |
294 int level; | |
295 int chroma_size=0; | |
296 int size=0; | |
297 | |
298 if(i>0){// ;) | |
2967 | 299 size++; |
499 | 300 chroma_size++; |
301 } | |
302 for(level=0; level<=MAX_LEVEL; level++){ | |
303 int run; | |
304 for(run=0; run<=MAX_RUN; run++){ | |
305 int last; | |
601 | 306 const int last_size= size + chroma_size; |
499 | 307 for(last=0; last<2; last++){ |
308 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last]; | |
309 int intra_luma_count = s->ac_stats[1][0][level][run][last]; | |
310 int intra_chroma_count= s->ac_stats[1][1][level][run][last]; | |
2967 | 311 |
6481 | 312 if(s->pict_type==FF_I_TYPE){ |
774
baa66649df35
mergeing inter & intra rl_length tables (50% smaller & no meassureable difference in filesize/quality)
michaelni
parents:
773
diff
changeset
|
313 size += intra_luma_count *rl_length[i ][level][run][last]; |
baa66649df35
mergeing inter & intra rl_length tables (50% smaller & no meassureable difference in filesize/quality)
michaelni
parents:
773
diff
changeset
|
314 chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last]; |
499 | 315 }else{ |
774
baa66649df35
mergeing inter & intra rl_length tables (50% smaller & no meassureable difference in filesize/quality)
michaelni
parents:
773
diff
changeset
|
316 size+= intra_luma_count *rl_length[i ][level][run][last] |
baa66649df35
mergeing inter & intra rl_length tables (50% smaller & no meassureable difference in filesize/quality)
michaelni
parents:
773
diff
changeset
|
317 +intra_chroma_count*rl_length[i+3][level][run][last] |
baa66649df35
mergeing inter & intra rl_length tables (50% smaller & no meassureable difference in filesize/quality)
michaelni
parents:
773
diff
changeset
|
318 +inter_count *rl_length[i+3][level][run][last]; |
2967 | 319 } |
499 | 320 } |
601 | 321 if(last_size == size+chroma_size) break; |
499 | 322 } |
323 } | |
324 if(size<best_size){ | |
325 best_size= size; | |
326 best= i; | |
327 } | |
328 if(chroma_size<best_chroma_size){ | |
329 best_chroma_size= chroma_size; | |
330 chroma_best= i; | |
331 } | |
332 } | |
601 | 333 |
2967 | 334 // printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n", |
499 | 335 // s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size); |
2967 | 336 |
6481 | 337 if(s->pict_type==FF_P_TYPE) chroma_best= best; |
499 | 338 |
339 memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2); | |
340 | |
341 s->rl_table_index = best; | |
342 s->rl_chroma_table_index= chroma_best; | |
2967 | 343 |
499 | 344 if(s->pict_type != s->last_non_b_pict_type){ |
345 s->rl_table_index= 2; | |
6481 | 346 if(s->pict_type==FF_I_TYPE) |
499 | 347 s->rl_chroma_table_index= 1; |
348 else | |
349 s->rl_chroma_table_index= 2; | |
350 } | |
351 | |
352 } | |
353 | |
457 | 354 /* write MSMPEG4 compatible frame header */ |
0 | 355 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) |
356 { | |
7994
ecade9a77827
Mark the ff_find_best_tables symbol static to msmpeg4. Patch by Diego Petten«Ò
lu_zero
parents:
7831
diff
changeset
|
357 find_best_tables(s); |
0 | 358 |
359 align_put_bits(&s->pb); | |
360 put_bits(&s->pb, 2, s->pict_type - 1); | |
361 | |
362 put_bits(&s->pb, 5, s->qscale); | |
499 | 363 if(s->msmpeg4_version<=2){ |
364 s->rl_table_index = 2; | |
365 s->rl_chroma_table_index = 2; | |
366 } | |
310 | 367 |
0 | 368 s->dc_table_index = 1; |
369 s->mv_table_index = 1; /* only if P frame */ | |
370 s->use_skip_mb_code = 1; /* only if P frame */ | |
499 | 371 s->per_mb_rl_table = 0; |
759 | 372 if(s->msmpeg4_version==4) |
6481 | 373 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==FF_P_TYPE); |
936 | 374 //printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height); |
499 | 375 |
6481 | 376 if (s->pict_type == FF_I_TYPE) { |
519 | 377 s->slice_height= s->mb_height/1; |
378 put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height); | |
2967 | 379 |
499 | 380 if(s->msmpeg4_version==4){ |
381 msmpeg4_encode_ext_header(s); | |
578 | 382 if(s->bit_rate>MBAC_BITRATE) |
519 | 383 put_bits(&s->pb, 1, s->per_mb_rl_table); |
499 | 384 } |
0 | 385 |
457 | 386 if(s->msmpeg4_version>2){ |
499 | 387 if(!s->per_mb_rl_table){ |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
388 ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index); |
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
389 ff_msmpeg4_code012(&s->pb, s->rl_table_index); |
499 | 390 } |
0 | 391 |
310 | 392 put_bits(&s->pb, 1, s->dc_table_index); |
393 } | |
0 | 394 } else { |
395 put_bits(&s->pb, 1, s->use_skip_mb_code); | |
2967 | 396 |
578 | 397 if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE) |
499 | 398 put_bits(&s->pb, 1, s->per_mb_rl_table); |
399 | |
457 | 400 if(s->msmpeg4_version>2){ |
499 | 401 if(!s->per_mb_rl_table) |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
402 ff_msmpeg4_code012(&s->pb, s->rl_table_index); |
0 | 403 |
310 | 404 put_bits(&s->pb, 1, s->dc_table_index); |
0 | 405 |
310 | 406 put_bits(&s->pb, 1, s->mv_table_index); |
407 } | |
0 | 408 } |
409 | |
499 | 410 s->esc3_level_length= 0; |
411 s->esc3_run_length= 0; | |
0 | 412 } |
413 | |
208 | 414 void msmpeg4_encode_ext_header(MpegEncContext * s) |
415 { | |
2637 | 416 put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29 |
208 | 417 |
847 | 418 put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047)); |
208 | 419 |
1163 | 420 if(s->msmpeg4_version>=3) |
457 | 421 put_bits(&s->pb, 1, s->flipflop_rounding); |
1163 | 422 else |
423 assert(s->flipflop_rounding==0); | |
208 | 424 } |
425 | |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
426 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
427 |
0 | 428 /* predict coded block */ |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
429 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr) |
0 | 430 { |
299 | 431 int xy, wrap, pred, a, b, c; |
0 | 432 |
299 | 433 xy = s->block_index[n]; |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1739
diff
changeset
|
434 wrap = s->b8_stride; |
0 | 435 |
436 /* B C | |
2967 | 437 * A X |
0 | 438 */ |
299 | 439 a = s->coded_block[xy - 1 ]; |
440 b = s->coded_block[xy - 1 - wrap]; | |
441 c = s->coded_block[xy - wrap]; | |
2967 | 442 |
0 | 443 if (b == c) { |
444 pred = a; | |
445 } else { | |
446 pred = c; | |
447 } | |
2967 | 448 |
0 | 449 /* store value */ |
299 | 450 *coded_block_ptr = &s->coded_block[xy]; |
0 | 451 |
452 return pred; | |
453 } | |
454 | |
8590 | 455 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
456 |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
457 void ff_msmpeg4_encode_motion(MpegEncContext * s, |
0 | 458 int mx, int my) |
459 { | |
460 int code; | |
461 MVTable *mv; | |
462 | |
463 /* modulo encoding */ | |
464 /* WARNING : you cannot reach all the MVs even with the modulo | |
465 encoding. This is a somewhat strange compromise they took !!! */ | |
466 if (mx <= -64) | |
467 mx += 64; | |
468 else if (mx >= 64) | |
469 mx -= 64; | |
470 if (my <= -64) | |
471 my += 64; | |
472 else if (my >= 64) | |
473 my -= 64; | |
2967 | 474 |
0 | 475 mx += 32; |
476 my += 32; | |
477 #if 0 | |
478 if ((unsigned)mx >= 64 || | |
2967 | 479 (unsigned)my >= 64) |
3177 | 480 av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my); |
0 | 481 #endif |
482 mv = &mv_tables[s->mv_table_index]; | |
483 | |
484 code = mv->table_mv_index[(mx << 6) | my]; | |
2967 | 485 put_bits(&s->pb, |
486 mv->table_mv_bits[code], | |
0 | 487 mv->table_mv_code[code]); |
488 if (code == mv->n) { | |
5129 | 489 /* escape : code literally */ |
0 | 490 put_bits(&s->pb, 6, mx); |
491 put_bits(&s->pb, 6, my); | |
492 } | |
493 } | |
494 | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
495 void ff_msmpeg4_handle_slices(MpegEncContext *s){ |
519 | 496 if (s->mb_x == 0) { |
497 if (s->slice_height && (s->mb_y % s->slice_height) == 0) { | |
983 | 498 if(s->msmpeg4_version < 4){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
499 ff_mpeg4_clean_buffers(s); |
519 | 500 } |
501 s->first_slice_line = 1; | |
502 } else { | |
2967 | 503 s->first_slice_line = 0; |
519 | 504 } |
505 } | |
506 } | |
507 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
508 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
509 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
510 int range, bit_size, sign, code, bits; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
511 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
512 if (val == 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
513 /* zero vector */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
514 code = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
515 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
516 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
517 bit_size = s->f_code - 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
518 range = 1 << bit_size; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
519 if (val <= -64) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
520 val += 64; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
521 else if (val >= 64) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
522 val -= 64; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
523 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
524 if (val >= 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
525 sign = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
526 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
527 val = -val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
528 sign = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
529 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
530 val--; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
531 code = (val >> bit_size) + 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
532 bits = val & (range - 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
533 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
534 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
535 if (bit_size > 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
536 put_bits(&s->pb, bit_size, bits); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
537 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
538 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
539 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
540 |
2967 | 541 void msmpeg4_encode_mb(MpegEncContext * s, |
0 | 542 DCTELEM block[6][64], |
543 int motion_x, int motion_y) | |
544 { | |
545 int cbp, coded_cbp, i; | |
546 int pred_x, pred_y; | |
1064 | 547 uint8_t *coded_block; |
0 | 548 |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
549 ff_msmpeg4_handle_slices(s); |
2967 | 550 |
0 | 551 if (!s->mb_intra) { |
2979 | 552 /* compute cbp */ |
553 cbp = 0; | |
554 for (i = 0; i < 6; i++) { | |
555 if (s->block_last_index[i] >= 0) | |
556 cbp |= 1 << (5 - i); | |
557 } | |
558 if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) { | |
559 /* skip macroblock */ | |
560 put_bits(&s->pb, 1, 1); | |
1164 | 561 s->last_bits++; |
2979 | 562 s->misc_bits++; |
1216 | 563 s->skip_count++; |
1164 | 564 |
2979 | 565 return; |
566 } | |
0 | 567 if (s->use_skip_mb_code) |
2979 | 568 put_bits(&s->pb, 1, 0); /* mb coded */ |
2967 | 569 |
457 | 570 if(s->msmpeg4_version<=2){ |
2967 | 571 put_bits(&s->pb, |
572 v2_mb_type[cbp&3][1], | |
310 | 573 v2_mb_type[cbp&3][0]); |
574 if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C; | |
575 else coded_cbp= cbp; | |
0 | 576 |
2967 | 577 put_bits(&s->pb, |
578 cbpy_tab[coded_cbp>>2][1], | |
310 | 579 cbpy_tab[coded_cbp>>2][0]); |
1164 | 580 |
581 s->misc_bits += get_bits_diff(s); | |
582 | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1739
diff
changeset
|
583 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
310 | 584 msmpeg4v2_encode_motion(s, motion_x - pred_x); |
585 msmpeg4v2_encode_motion(s, motion_y - pred_y); | |
586 }else{ | |
2967 | 587 put_bits(&s->pb, |
588 table_mb_non_intra[cbp + 64][1], | |
310 | 589 table_mb_non_intra[cbp + 64][0]); |
590 | |
1164 | 591 s->misc_bits += get_bits_diff(s); |
592 | |
310 | 593 /* motion vector */ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1739
diff
changeset
|
594 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
595 ff_msmpeg4_encode_motion(s, motion_x - pred_x, |
310 | 596 motion_y - pred_y); |
597 } | |
1164 | 598 |
599 s->mv_bits += get_bits_diff(s); | |
600 | |
601 for (i = 0; i < 6; i++) { | |
5178 | 602 ff_msmpeg4_encode_block(s, block[i], i); |
1164 | 603 } |
604 s->p_tex_bits += get_bits_diff(s); | |
0 | 605 } else { |
2979 | 606 /* compute cbp */ |
607 cbp = 0; | |
0 | 608 coded_cbp = 0; |
2979 | 609 for (i = 0; i < 6; i++) { |
0 | 610 int val, pred; |
611 val = (s->block_last_index[i] >= 1); | |
612 cbp |= val << (5 - i); | |
613 if (i < 4) { | |
614 /* predict value for close blocks only for luma */ | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
615 pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block); |
0 | 616 *coded_block = val; |
617 val = val ^ pred; | |
618 } | |
619 coded_cbp |= val << (5 - i); | |
2979 | 620 } |
0 | 621 #if 0 |
622 if (coded_cbp) | |
623 printf("cbp=%x %x\n", cbp, coded_cbp); | |
624 #endif | |
625 | |
457 | 626 if(s->msmpeg4_version<=2){ |
6481 | 627 if (s->pict_type == FF_I_TYPE) { |
2967 | 628 put_bits(&s->pb, |
310 | 629 v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]); |
630 } else { | |
631 if (s->use_skip_mb_code) | |
2979 | 632 put_bits(&s->pb, 1, 0); /* mb coded */ |
2967 | 633 put_bits(&s->pb, |
634 v2_mb_type[(cbp&3) + 4][1], | |
310 | 635 v2_mb_type[(cbp&3) + 4][0]); |
636 } | |
2979 | 637 put_bits(&s->pb, 1, 0); /* no AC prediction yet */ |
2967 | 638 put_bits(&s->pb, |
639 cbpy_tab[cbp>>2][1], | |
310 | 640 cbpy_tab[cbp>>2][0]); |
641 }else{ | |
6481 | 642 if (s->pict_type == FF_I_TYPE) { |
2967 | 643 put_bits(&s->pb, |
2474 | 644 ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); |
310 | 645 } else { |
646 if (s->use_skip_mb_code) | |
2979 | 647 put_bits(&s->pb, 1, 0); /* mb coded */ |
2967 | 648 put_bits(&s->pb, |
649 table_mb_non_intra[cbp][1], | |
310 | 650 table_mb_non_intra[cbp][0]); |
651 } | |
2979 | 652 put_bits(&s->pb, 1, 0); /* no AC prediction yet */ |
578 | 653 if(s->inter_intra_pred){ |
654 s->h263_aic_dir=0; | |
655 put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]); | |
656 } | |
0 | 657 } |
1164 | 658 s->misc_bits += get_bits_diff(s); |
0 | 659 |
1164 | 660 for (i = 0; i < 6; i++) { |
5178 | 661 ff_msmpeg4_encode_block(s, block[i], i); |
1164 | 662 } |
663 s->i_tex_bits += get_bits_diff(s); | |
1216 | 664 s->i_count++; |
0 | 665 } |
666 } | |
667 | |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
668 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1064
diff
changeset
|
669 |
2967 | 670 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n, |
1064 | 671 int32_t **dc_val_ptr) |
457 | 672 { |
673 int i; | |
674 | |
675 if (n < 4) { | |
676 i= 0; | |
677 } else { | |
678 i= n-3; | |
679 } | |
2967 | 680 |
457 | 681 *dc_val_ptr= &s->last_dc[i]; |
2967 | 682 return s->last_dc[i]; |
457 | 683 } |
684 | |
519 | 685 static int get_dc(uint8_t *src, int stride, int scale) |
686 { | |
687 int y; | |
688 int sum=0; | |
689 for(y=0; y<8; y++){ | |
690 int x; | |
691 for(x=0; x<8; x++){ | |
692 sum+=src[x + y*stride]; | |
693 } | |
694 } | |
1261
362947395f5c
fastdiv patch by (BERO <bero at geocities dot co dot jp>) with fixes & cleanup by me
michaelni
parents:
1255
diff
changeset
|
695 return FASTDIV((sum + (scale>>1)), scale); |
519 | 696 } |
697 | |
0 | 698 /* dir = 0: left, dir = 1: top prediction */ |
2967 | 699 static inline int msmpeg4_pred_dc(MpegEncContext * s, int n, |
3781 | 700 int16_t **dc_val_ptr, int *dir_ptr) |
0 | 701 { |
299 | 702 int a, b, c, wrap, pred, scale; |
3781 | 703 int16_t *dc_val; |
0 | 704 |
705 /* find prediction */ | |
706 if (n < 4) { | |
2979 | 707 scale = s->y_dc_scale; |
0 | 708 } else { |
2979 | 709 scale = s->c_dc_scale; |
0 | 710 } |
2967 | 711 |
299 | 712 wrap = s->block_wrap[n]; |
713 dc_val= s->dc_val[0] + s->block_index[n]; | |
0 | 714 |
715 /* B C | |
2967 | 716 * A X |
0 | 717 */ |
299 | 718 a = dc_val[ - 1]; |
719 b = dc_val[ - 1 - wrap]; | |
720 c = dc_val[ - wrap]; | |
2967 | 721 |
983 | 722 if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
723 b=c=1024; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
724 } |
0 | 725 |
726 /* XXX: the following solution consumes divisions, but it does not | |
727 necessitate to modify mpegvideo.c. The problem comes from the | |
728 fact they decided to store the quantized DC (which would lead | |
729 to problems if Q could vary !) */ | |
10071
6ac0d4957d35
Replace #ifdef PIC checks with the more appropriate HAVE_EBX_AVAILABLE/HAVE_7REGS.
reimar
parents:
9998
diff
changeset
|
730 #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE |
8031 | 731 __asm__ volatile( |
2979 | 732 "movl %3, %%eax \n\t" |
733 "shrl $1, %%eax \n\t" | |
734 "addl %%eax, %2 \n\t" | |
735 "addl %%eax, %1 \n\t" | |
736 "addl %0, %%eax \n\t" | |
737 "mull %4 \n\t" | |
738 "movl %%edx, %0 \n\t" | |
739 "movl %1, %%eax \n\t" | |
740 "mull %4 \n\t" | |
741 "movl %%edx, %1 \n\t" | |
742 "movl %2, %%eax \n\t" | |
743 "mull %4 \n\t" | |
744 "movl %%edx, %2 \n\t" | |
745 : "+b" (a), "+c" (b), "+D" (c) | |
4174 | 746 : "g" (scale), "S" (ff_inverse[scale]) |
2979 | 747 : "%eax", "%edx" |
204 | 748 ); |
221 | 749 #else |
8590 | 750 /* #elif ARCH_ALPHA */ |
214
73df666cacc7
Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents:
208
diff
changeset
|
751 /* Divisions are extremely costly on Alpha; optimize the most |
221 | 752 common case. But they are costly everywhere... |
753 */ | |
214
73df666cacc7
Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents:
208
diff
changeset
|
754 if (scale == 8) { |
2979 | 755 a = (a + (8 >> 1)) / 8; |
756 b = (b + (8 >> 1)) / 8; | |
757 c = (c + (8 >> 1)) / 8; | |
214
73df666cacc7
Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents:
208
diff
changeset
|
758 } else { |
2979 | 759 a = FASTDIV((a + (scale >> 1)), scale); |
760 b = FASTDIV((b + (scale >> 1)), scale); | |
761 c = FASTDIV((c + (scale >> 1)), scale); | |
214
73df666cacc7
Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents:
208
diff
changeset
|
762 } |
204 | 763 #endif |
0 | 764 /* XXX: WARNING: they did not choose the same test as MPEG4. This |
765 is very important ! */ | |
501
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
766 if(s->msmpeg4_version>3){ |
519 | 767 if(s->inter_intra_pred){ |
768 uint8_t *dest; | |
769 int wrap; | |
2967 | 770 |
519 | 771 if(n==1){ |
772 pred=a; | |
773 *dir_ptr = 0; | |
774 }else if(n==2){ | |
775 pred=c; | |
776 *dir_ptr = 1; | |
777 }else if(n==3){ | |
778 if (abs(a - b) < abs(b - c)) { | |
779 pred = c; | |
780 *dir_ptr = 1; | |
781 } else { | |
782 pred = a; | |
783 *dir_ptr = 0; | |
784 } | |
785 }else{ | |
786 if(n<4){ | |
787 wrap= s->linesize; | |
903 | 788 dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8; |
519 | 789 }else{ |
556 | 790 wrap= s->uvlinesize; |
903 | 791 dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8; |
519 | 792 } |
793 if(s->mb_x==0) a= (1024 + (scale>>1))/scale; | |
794 else a= get_dc(dest-8, wrap, scale*8); | |
795 if(s->mb_y==0) c= (1024 + (scale>>1))/scale; | |
796 else c= get_dc(dest-8*wrap, wrap, scale*8); | |
2967 | 797 |
519 | 798 if (s->h263_aic_dir==0) { |
799 pred= a; | |
800 *dir_ptr = 0; | |
801 }else if (s->h263_aic_dir==1) { | |
802 if(n==0){ | |
803 pred= c; | |
804 *dir_ptr = 1; | |
805 }else{ | |
806 pred= a; | |
807 *dir_ptr = 0; | |
808 } | |
809 }else if (s->h263_aic_dir==2) { | |
810 if(n==0){ | |
811 pred= a; | |
812 *dir_ptr = 0; | |
813 }else{ | |
814 pred= c; | |
815 *dir_ptr = 1; | |
816 } | |
817 } else { | |
818 pred= c; | |
819 *dir_ptr = 1; | |
820 } | |
821 } | |
822 }else{ | |
823 if (abs(a - b) < abs(b - c)) { | |
824 pred = c; | |
825 *dir_ptr = 1; | |
826 } else { | |
827 pred = a; | |
828 *dir_ptr = 0; | |
829 } | |
501
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
830 } |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
831 }else{ |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
832 if (abs(a - b) <= abs(b - c)) { |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
833 pred = c; |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
834 *dir_ptr = 1; |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
835 } else { |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
836 pred = a; |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
837 *dir_ptr = 0; |
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
838 } |
0 | 839 } |
840 | |
841 /* update predictor */ | |
299 | 842 *dc_val_ptr = &dc_val[0]; |
0 | 843 return pred; |
844 } | |
845 | |
846 #define DC_MAX 119 | |
847 | |
848 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr) | |
849 { | |
850 int sign, code; | |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
851 int pred, extquant; |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
852 int extrabits = 0; |
0 | 853 |
457 | 854 if(s->msmpeg4_version==1){ |
1064 | 855 int32_t *dc_val; |
457 | 856 pred = msmpeg4v1_pred_dc(s, n, &dc_val); |
2967 | 857 |
457 | 858 /* update predictor */ |
859 *dc_val= level; | |
860 }else{ | |
3781 | 861 int16_t *dc_val; |
501
2241bce35bb9
fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents:
499
diff
changeset
|
862 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); |
457 | 863 |
864 /* update predictor */ | |
865 if (n < 4) { | |
866 *dc_val = level * s->y_dc_scale; | |
867 } else { | |
868 *dc_val = level * s->c_dc_scale; | |
869 } | |
0 | 870 } |
871 | |
872 /* do the prediction */ | |
873 level -= pred; | |
874 | |
457 | 875 if(s->msmpeg4_version<=2){ |
310 | 876 if (n < 4) { |
2967 | 877 put_bits(&s->pb, |
310 | 878 v2_dc_lum_table[level+256][1], |
879 v2_dc_lum_table[level+256][0]); | |
880 }else{ | |
2967 | 881 put_bits(&s->pb, |
310 | 882 v2_dc_chroma_table[level+256][1], |
883 v2_dc_chroma_table[level+256][0]); | |
884 } | |
885 }else{ | |
886 sign = 0; | |
887 if (level < 0) { | |
888 level = -level; | |
889 sign = 1; | |
890 } | |
891 code = level; | |
2967 | 892 if (code > DC_MAX) |
310 | 893 code = DC_MAX; |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
894 else if( s->msmpeg4_version>=6 ) { |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
895 if( s->qscale == 1 ) { |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
896 extquant = (level + 3) & 0x3; |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
897 code = ((level+3)>>2); |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
898 } else if( s->qscale == 2 ) { |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
899 extquant = (level + 1) & 0x1; |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
900 code = ((level+1)>>1); |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
901 } |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
902 } |
0 | 903 |
310 | 904 if (s->dc_table_index == 0) { |
905 if (n < 4) { | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
906 put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]); |
310 | 907 } else { |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
908 put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]); |
310 | 909 } |
0 | 910 } else { |
310 | 911 if (n < 4) { |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
912 put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]); |
310 | 913 } else { |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
914 put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]); |
310 | 915 } |
0 | 916 } |
2967 | 917 |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
918 if(s->msmpeg4_version>=6 && s->qscale<=2) |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
919 extrabits = 3 - s->qscale; |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
920 |
310 | 921 if (code == DC_MAX) |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
922 put_bits(&s->pb, 8 + extrabits, level); |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
923 else if(extrabits > 0)//== VC1 && s->qscale<=2 |
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
924 put_bits(&s->pb, extrabits, extquant); |
2967 | 925 |
310 | 926 if (level != 0) { |
927 put_bits(&s->pb, 1, sign); | |
928 } | |
0 | 929 } |
930 } | |
931 | |
932 /* Encoding of a block. Very similar to MPEG4 except for a different | |
933 escape coding (same as H263) and more vlc tables. | |
934 */ | |
5178 | 935 void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n) |
0 | 936 { |
937 int level, run, last, i, j, last_index; | |
938 int last_non_zero, sign, slevel; | |
939 int code, run_diff, dc_pred_dir; | |
940 const RLTable *rl; | |
1064 | 941 const uint8_t *scantable; |
0 | 942 |
943 if (s->mb_intra) { | |
944 msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir); | |
945 i = 1; | |
946 if (n < 4) { | |
947 rl = &rl_table[s->rl_table_index]; | |
948 } else { | |
949 rl = &rl_table[3 + s->rl_chroma_table_index]; | |
950 } | |
5496 | 951 run_diff = s->msmpeg4_version>=4; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
952 scantable= s->intra_scantable.permutated; |
0 | 953 } else { |
954 i = 0; | |
955 rl = &rl_table[3 + s->rl_table_index]; | |
457 | 956 if(s->msmpeg4_version<=2) |
310 | 957 run_diff = 0; |
958 else | |
959 run_diff = 1; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
960 scantable= s->inter_scantable.permutated; |
0 | 961 } |
962 | |
499 | 963 /* recalculate block_last_index for M$ wmv1 */ |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
964 if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){ |
499 | 965 for(last_index=63; last_index>=0; last_index--){ |
966 if(block[scantable[last_index]]) break; | |
967 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
968 s->block_last_index[n]= last_index; |
499 | 969 }else |
970 last_index = s->block_last_index[n]; | |
0 | 971 /* AC coefs */ |
972 last_non_zero = i - 1; | |
973 for (; i <= last_index; i++) { | |
2979 | 974 j = scantable[i]; |
975 level = block[j]; | |
976 if (level) { | |
977 run = i - last_non_zero - 1; | |
978 last = (i == last_index); | |
979 sign = 0; | |
980 slevel = level; | |
981 if (level < 0) { | |
982 sign = 1; | |
983 level = -level; | |
984 } | |
601 | 985 |
499 | 986 if(level<=MAX_LEVEL && run<=MAX_RUN){ |
987 s->ac_stats[s->mb_intra][n>3][level][run][last]++; | |
988 } | |
989 #if 0 | |
990 else | |
991 s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like | |
992 #endif | |
0 | 993 code = get_rl_index(rl, last, run, level); |
994 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
995 if (code == rl->n) { | |
996 int level1, run1; | |
997 | |
998 level1 = level - rl->max_level[last][run]; | |
2967 | 999 if (level1 < 1) |
0 | 1000 goto esc2; |
1001 code = get_rl_index(rl, last, run, level1); | |
1002 if (code == rl->n) { | |
1003 esc2: | |
1004 put_bits(&s->pb, 1, 0); | |
1005 if (level > MAX_LEVEL) | |
1006 goto esc3; | |
1007 run1 = run - rl->max_run[last][level] - run_diff; | |
1008 if (run1 < 0) | |
1009 goto esc3; | |
5496 | 1010 code = get_rl_index(rl, last, run1+1, level); |
1011 if (s->msmpeg4_version == 4 && code == rl->n) | |
1012 goto esc3; | |
0 | 1013 code = get_rl_index(rl, last, run1, level); |
1014 if (code == rl->n) { | |
1015 esc3: | |
1016 /* third escape */ | |
1017 put_bits(&s->pb, 1, 0); | |
1018 put_bits(&s->pb, 1, last); | |
936 | 1019 if(s->msmpeg4_version>=4){ |
499 | 1020 if(s->esc3_level_length==0){ |
1021 s->esc3_level_length=8; | |
1022 s->esc3_run_length= 6; | |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
1023 //ESCLVLSZ + ESCRUNSZ |
499 | 1024 if(s->qscale<8) |
5179
04bbac6e28df
modify msmpeg4 functions to generate VC1 compatible block layer bitstream
benoit
parents:
5178
diff
changeset
|
1025 put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3); |
499 | 1026 else |
1027 put_bits(&s->pb, 8, 3); | |
1028 } | |
1029 put_bits(&s->pb, s->esc3_run_length, run); | |
1030 put_bits(&s->pb, 1, sign); | |
1031 put_bits(&s->pb, s->esc3_level_length, level); | |
1032 }else{ | |
1033 put_bits(&s->pb, 6, run); | |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7136
diff
changeset
|
1034 put_sbits(&s->pb, 8, slevel); |
499 | 1035 } |
0 | 1036 } else { |
1037 /* second escape */ | |
1038 put_bits(&s->pb, 1, 1); | |
1039 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1040 put_bits(&s->pb, 1, sign); | |
1041 } | |
1042 } else { | |
1043 /* first escape */ | |
1044 put_bits(&s->pb, 1, 1); | |
1045 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1046 put_bits(&s->pb, 1, sign); | |
1047 } | |
1048 } else { | |
1049 put_bits(&s->pb, 1, sign); | |
1050 } | |
2979 | 1051 last_non_zero = i; |
1052 } | |
0 | 1053 } |
1054 } | |
1055 | |
1056 /****************************************/ | |
1057 /* decoding stuff */ | |
1058 | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
1059 VLC ff_mb_non_intra_vlc[4]; |
307 | 1060 static VLC v2_dc_lum_vlc; |
1061 static VLC v2_dc_chroma_vlc; | |
1062 static VLC cbpy_vlc; | |
1063 static VLC v2_intra_cbpc_vlc; | |
1064 static VLC v2_mb_type_vlc; | |
1065 static VLC v2_mv_vlc; | |
457 | 1066 static VLC v1_intra_cbpc_vlc; |
1067 static VLC v1_inter_cbpc_vlc; | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
1068 VLC ff_inter_intra_vlc; |
307 | 1069 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1070 /* This is identical to h263 except that its range is multiplied by 2. */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1071 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) |
307 | 1072 { |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1073 int code, val, sign, shift; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1074 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1075 code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1076 // printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1077 if (code < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1078 return 0xffff; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1079 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1080 if (code == 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1081 return pred; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1082 sign = get_bits1(&s->gb); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1083 shift = f_code - 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1084 val = code; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1085 if (shift) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1086 val = (val - 1) << shift; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1087 val |= get_bits(&s->gb, shift); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1088 val++; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1089 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1090 if (sign) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1091 val = -val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1092 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1093 val += pred; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1094 if (val <= -64) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1095 val += 64; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1096 else if (val >= 64) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1097 val -= 64; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1098 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1099 return val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1100 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1101 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1102 static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1103 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1104 int cbp, code, i; |
307 | 1105 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1106 if (s->pict_type == FF_P_TYPE) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1107 if (s->use_skip_mb_code) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1108 if (get_bits1(&s->gb)) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1109 /* skip mb */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1110 s->mb_intra = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1111 for(i=0;i<6;i++) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1112 s->block_last_index[i] = -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1113 s->mv_dir = MV_DIR_FORWARD; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1114 s->mv_type = MV_TYPE_16X16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1115 s->mv[0][0][0] = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1116 s->mv[0][0][1] = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1117 s->mb_skipped = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1118 return 0; |
307 | 1119 } |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1120 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1121 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1122 if(s->msmpeg4_version==2) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1123 code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1124 else |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1125 code = get_vlc2(&s->gb, v1_inter_cbpc_vlc.table, V1_INTER_CBPC_VLC_BITS, 3); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1126 if(code<0 || code>7){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1127 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1128 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1129 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1130 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1131 s->mb_intra = code >>2; |
307 | 1132 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1133 cbp = code & 0x3; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1134 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1135 s->mb_intra = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1136 if(s->msmpeg4_version==2) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1137 cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1138 else |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1139 cbp= get_vlc2(&s->gb, v1_intra_cbpc_vlc.table, V1_INTRA_CBPC_VLC_BITS, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1140 if(cbp<0 || cbp>3){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1141 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1142 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1143 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1144 } |
307 | 1145 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1146 if (!s->mb_intra) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1147 int mx, my, cbpy; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1148 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1149 cbpy= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1150 if(cbpy<0){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1151 av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1152 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1153 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1154 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1155 cbp|= cbpy<<2; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1156 if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1157 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1158 h263_pred_motion(s, 0, 0, &mx, &my); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1159 mx= msmpeg4v2_decode_motion(s, mx, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1160 my= msmpeg4v2_decode_motion(s, my, 1); |
307 | 1161 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1162 s->mv_dir = MV_DIR_FORWARD; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1163 s->mv_type = MV_TYPE_16X16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1164 s->mv[0][0][0] = mx; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1165 s->mv[0][0][1] = my; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1166 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1167 if(s->msmpeg4_version==2){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1168 s->ac_pred = get_bits1(&s->gb); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1169 cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1170 } else{ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1171 s->ac_pred = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1172 cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1173 if(s->pict_type==FF_P_TYPE) cbp^=0x3C; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1174 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1175 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1176 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1177 s->dsp.clear_blocks(s->block[0]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1178 for (i = 0; i < 6; i++) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1179 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1180 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1181 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1182 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1183 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1184 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1185 return 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1186 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1187 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1188 static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1189 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1190 int cbp, code, i; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1191 uint8_t *coded_val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1192 uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1193 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1194 if (s->pict_type == FF_P_TYPE) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1195 if (s->use_skip_mb_code) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1196 if (get_bits1(&s->gb)) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1197 /* skip mb */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1198 s->mb_intra = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1199 for(i=0;i<6;i++) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1200 s->block_last_index[i] = -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1201 s->mv_dir = MV_DIR_FORWARD; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1202 s->mv_type = MV_TYPE_16X16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1203 s->mv[0][0][0] = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1204 s->mv[0][0][1] = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1205 s->mb_skipped = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1206 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1207 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1208 return 0; |
307 | 1209 } |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1210 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1211 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1212 code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1213 if (code < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1214 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1215 //s->mb_intra = (code & 0x40) ? 0 : 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1216 s->mb_intra = (~code & 0x40) >> 6; |
307 | 1217 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1218 cbp = code & 0x3f; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1219 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1220 s->mb_intra = 1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1221 code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1222 if (code < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1223 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1224 /* predict coded block pattern */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1225 cbp = 0; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1226 for(i=0;i<6;i++) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1227 int val = ((code >> (5 - i)) & 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1228 if (i < 4) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1229 int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1230 val = val ^ pred; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1231 *coded_val = val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1232 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1233 cbp |= val << (5 - i); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1234 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1235 } |
2967 | 1236 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1237 if (!s->mb_intra) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1238 int mx, my; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1239 //printf("P at %d %d\n", s->mb_x, s->mb_y); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1240 if(s->per_mb_rl_table && cbp){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1241 s->rl_table_index = decode012(&s->gb); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1242 s->rl_chroma_table_index = s->rl_table_index; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1243 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1244 h263_pred_motion(s, 0, 0, &mx, &my); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1245 if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1246 return -1; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1247 s->mv_dir = MV_DIR_FORWARD; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1248 s->mv_type = MV_TYPE_16X16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1249 s->mv[0][0][0] = mx; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1250 s->mv[0][0][1] = my; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1251 *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1252 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1253 //printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1254 s->ac_pred = get_bits1(&s->gb); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1255 *mb_type_ptr = MB_TYPE_INTRA; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1256 if(s->inter_intra_pred){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1257 s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1258 // printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1259 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1260 if(s->per_mb_rl_table && cbp){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1261 s->rl_table_index = decode012(&s->gb); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1262 s->rl_chroma_table_index = s->rl_table_index; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1263 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1264 } |
307 | 1265 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1266 s->dsp.clear_blocks(s->block[0]); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1267 for (i = 0; i < 6; i++) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1268 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1269 { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1270 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1271 return -1; |
307 | 1272 } |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1273 } |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1274 |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1275 return 0; |
307 | 1276 } |
0 | 1277 |
1278 /* init all vlc decoding tables */ | |
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8780
diff
changeset
|
1279 av_cold int ff_msmpeg4_decode_init(MpegEncContext *s) |
0 | 1280 { |
483 | 1281 static int done = 0; |
0 | 1282 int i; |
1283 MVTable *mv; | |
1284 | |
499 | 1285 common_init(s); |
483 | 1286 |
1287 if (!done) { | |
1288 done = 1; | |
0 | 1289 |
483 | 1290 for(i=0;i<NB_RL_TABLES;i++) { |
4668 | 1291 init_rl(&rl_table[i], static_rl_table_store[i]); |
483 | 1292 } |
6940
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1293 INIT_VLC_RL(rl_table[0], 642); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1294 INIT_VLC_RL(rl_table[1], 1104); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1295 INIT_VLC_RL(rl_table[2], 554); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1296 INIT_VLC_RL(rl_table[3], 940); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1297 INIT_VLC_RL(rl_table[4], 962); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6481
diff
changeset
|
1298 INIT_VLC_RL(rl_table[5], 554); |
483 | 1299 |
9396 | 1300 mv = &mv_tables[0]; |
1301 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1, | |
1302 mv->table_mv_bits, 1, 1, | |
1303 mv->table_mv_code, 2, 2, 3714); | |
1304 mv = &mv_tables[1]; | |
1305 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1, | |
1306 mv->table_mv_bits, 1, 1, | |
1307 mv->table_mv_code, 2, 2, 2694); | |
1308 | |
1309 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120, | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
1310 &ff_table0_dc_lum[0][1], 8, 4, |
9396 | 1311 &ff_table0_dc_lum[0][0], 8, 4, 1158); |
1312 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120, | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
1313 &ff_table0_dc_chroma[0][1], 8, 4, |
9396 | 1314 &ff_table0_dc_chroma[0][0], 8, 4, 1118); |
1315 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120, | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
1316 &ff_table1_dc_lum[0][1], 8, 4, |
9396 | 1317 &ff_table1_dc_lum[0][0], 8, 4, 1476); |
1318 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120, | |
2465
5565203c95ee
use dc tables from msmpeg4 instead of duplicating them patch by anonymous
michael
parents:
2464
diff
changeset
|
1319 &ff_table1_dc_chroma[0][1], 8, 4, |
9396 | 1320 &ff_table1_dc_chroma[0][0], 8, 4, 1216); |
2967 | 1321 |
9396 | 1322 INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512, |
483 | 1323 &v2_dc_lum_table[0][1], 8, 4, |
9396 | 1324 &v2_dc_lum_table[0][0], 8, 4, 1472); |
1325 INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512, | |
483 | 1326 &v2_dc_chroma_table[0][1], 8, 4, |
9396 | 1327 &v2_dc_chroma_table[0][0], 8, 4, 1506); |
2967 | 1328 |
9396 | 1329 INIT_VLC_STATIC(&cbpy_vlc, CBPY_VLC_BITS, 16, |
483 | 1330 &cbpy_tab[0][1], 2, 1, |
9396 | 1331 &cbpy_tab[0][0], 2, 1, 64); |
1332 INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4, | |
483 | 1333 &v2_intra_cbpc[0][1], 2, 1, |
9396 | 1334 &v2_intra_cbpc[0][0], 2, 1, 8); |
1335 INIT_VLC_STATIC(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8, | |
483 | 1336 &v2_mb_type[0][1], 2, 1, |
9396 | 1337 &v2_mb_type[0][0], 2, 1, 128); |
1338 INIT_VLC_STATIC(&v2_mv_vlc, V2_MV_VLC_BITS, 33, | |
483 | 1339 &mvtab[0][1], 2, 1, |
9396 | 1340 &mvtab[0][0], 2, 1, 538); |
0 | 1341 |
9396 | 1342 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[0], MB_NON_INTRA_VLC_BITS, 128, |
1343 &wmv2_inter_table[0][0][1], 8, 4, | |
1344 &wmv2_inter_table[0][0][0], 8, 4, 1636); | |
1345 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[1], MB_NON_INTRA_VLC_BITS, 128, | |
1346 &wmv2_inter_table[1][0][1], 8, 4, | |
1347 &wmv2_inter_table[1][0][0], 8, 4, 2648); | |
1348 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[2], MB_NON_INTRA_VLC_BITS, 128, | |
1349 &wmv2_inter_table[2][0][1], 8, 4, | |
1350 &wmv2_inter_table[2][0][0], 8, 4, 1532); | |
1351 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[3], MB_NON_INTRA_VLC_BITS, 128, | |
1352 &wmv2_inter_table[3][0][1], 8, 4, | |
1353 &wmv2_inter_table[3][0][0], 8, 4, 2488); | |
2967 | 1354 |
9396 | 1355 INIT_VLC_STATIC(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64, |
1356 &ff_msmp4_mb_i_table[0][1], 4, 2, | |
1357 &ff_msmp4_mb_i_table[0][0], 4, 2, 536); | |
1358 | |
1359 INIT_VLC_STATIC(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8, | |
483 | 1360 intra_MCBPC_bits, 1, 1, |
9396 | 1361 intra_MCBPC_code, 1, 1, 64); |
1362 INIT_VLC_STATIC(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25, | |
483 | 1363 inter_MCBPC_bits, 1, 1, |
9396 | 1364 inter_MCBPC_code, 1, 1, 104); |
2967 | 1365 |
9396 | 1366 INIT_VLC_STATIC(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4, |
519 | 1367 &table_inter_intra[0][1], 2, 1, |
9396 | 1368 &table_inter_intra[0][0], 2, 1, 8); |
483 | 1369 } |
2967 | 1370 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1371 switch(s->msmpeg4_version){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1372 case 1: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1373 case 2: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1374 s->decode_mb= msmpeg4v12_decode_mb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1375 break; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1376 case 3: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1377 case 4: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1378 s->decode_mb= msmpeg4v34_decode_mb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1379 break; |
936 | 1380 case 5: |
8596
68e959302527
replace all occurrence of ENABLE_ by the corresponding CONFIG_, HAVE_ or ARCH_
aurel
parents:
8590
diff
changeset
|
1381 if (CONFIG_WMV2_DECODER) |
5885 | 1382 s->decode_mb= ff_wmv2_decode_mb; |
2474 | 1383 case 6: |
3359 | 1384 //FIXME + TODO VC1 decode mb |
936 | 1385 break; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
743
diff
changeset
|
1386 } |
2967 | 1387 |
5127 | 1388 s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe |
2967 | 1389 |
0 | 1390 return 0; |
1391 } | |
1392 | |
307 | 1393 int msmpeg4_decode_picture_header(MpegEncContext * s) |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1394 { |
499 | 1395 int code; |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1396 |
311 | 1397 #if 0 |
1398 { | |
1399 int i; | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
983
diff
changeset
|
1400 for(i=0; i<s->gb.size_in_bits; i++) |
3177 | 1401 av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); |
311 | 1402 // get_bits1(&s->gb); |
3177 | 1403 av_log(s->avctx, AV_LOG_DEBUG, "END\n"); |
311 | 1404 return -1; |
1405 } | |
1406 #endif | |
457 | 1407 |
1408 if(s->msmpeg4_version==1){ | |
9455
6cb61c6220c3
Get rid of an unused variable, found by the clang static analyzer.
michael
parents:
9396
diff
changeset
|
1409 int start_code; |
457 | 1410 start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16); |
1411 if(start_code!=0x00000100){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1412 av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n"); |
457 | 1413 return -1; |
1414 } | |
1415 | |
9455
6cb61c6220c3
Get rid of an unused variable, found by the clang static analyzer.
michael
parents:
9396
diff
changeset
|
1416 skip_bits(&s->gb, 5); // frame number */ |
457 | 1417 } |
1418 | |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1419 s->pict_type = get_bits(&s->gb, 2) + 1; |
6481 | 1420 if (s->pict_type != FF_I_TYPE && |
1421 s->pict_type != FF_P_TYPE){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1422 av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n"); |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1423 return -1; |
457 | 1424 } |
519 | 1425 #if 0 |
1426 { | |
1427 static int had_i=0; | |
6481 | 1428 if(s->pict_type == FF_I_TYPE) had_i=1; |
519 | 1429 if(!had_i) return -1; |
1430 } | |
1431 #endif | |
1651 | 1432 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); |
1063
fdeac9642346
check for qscale==0 (fixes 1/0 on one corrupted stream)
michaelni
parents:
1057
diff
changeset
|
1433 if(s->qscale==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1434 av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n"); |
1063
fdeac9642346
check for qscale==0 (fixes 1/0 on one corrupted stream)
michaelni
parents:
1057
diff
changeset
|
1435 return -1; |
fdeac9642346
check for qscale==0 (fixes 1/0 on one corrupted stream)
michaelni
parents:
1057
diff
changeset
|
1436 } |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1437 |
6481 | 1438 if (s->pict_type == FF_I_TYPE) { |
2967 | 1439 code = get_bits(&s->gb, 5); |
457 | 1440 if(s->msmpeg4_version==1){ |
1441 if(code==0 || code>s->mb_height){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1442 av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); |
457 | 1443 return -1; |
1444 } | |
1445 | |
1446 s->slice_height = code; | |
1447 }else{ | |
1448 /* 0x17: one slice, 0x18: two slices, ... */ | |
519 | 1449 if (code < 0x17){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1450 av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code); |
457 | 1451 return -1; |
519 | 1452 } |
457 | 1453 |
1454 s->slice_height = s->mb_height / (code - 0x16); | |
1455 } | |
311 | 1456 |
1457 switch(s->msmpeg4_version){ | |
457 | 1458 case 1: |
311 | 1459 case 2: |
307 | 1460 s->rl_chroma_table_index = 2; |
1461 s->rl_table_index = 2; | |
300
d874359e58f1
msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents:
299
diff
changeset
|
1462 |
307 | 1463 s->dc_table_index = 0; //not used |
311 | 1464 break; |
1465 case 3: | |
307 | 1466 s->rl_chroma_table_index = decode012(&s->gb); |
1467 s->rl_table_index = decode012(&s->gb); | |
0 | 1468 |
307 | 1469 s->dc_table_index = get_bits1(&s->gb); |
311 | 1470 break; |
1471 case 4: | |
499 | 1472 msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8); |
1473 | |
578 | 1474 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb); |
1475 else s->per_mb_rl_table= 0; | |
2967 | 1476 |
499 | 1477 if(!s->per_mb_rl_table){ |
1478 s->rl_chroma_table_index = decode012(&s->gb); | |
1479 s->rl_table_index = decode012(&s->gb); | |
311 | 1480 } |
1481 | |
499 | 1482 s->dc_table_index = get_bits1(&s->gb); |
519 | 1483 s->inter_intra_pred= 0; |
311 | 1484 break; |
307 | 1485 } |
0 | 1486 s->no_rounding = 1; |
1388 | 1487 if(s->avctx->debug&FF_DEBUG_PICT_INFO) |
2979 | 1488 av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n", |
1489 s->qscale, | |
1490 s->rl_chroma_table_index, | |
1491 s->rl_table_index, | |
1492 s->dc_table_index, | |
519 | 1493 s->per_mb_rl_table, |
1388 | 1494 s->slice_height); |
0 | 1495 } else { |
457 | 1496 switch(s->msmpeg4_version){ |
1497 case 1: | |
1498 case 2: | |
1499 if(s->msmpeg4_version==1) | |
1500 s->use_skip_mb_code = 1; | |
1501 else | |
1502 s->use_skip_mb_code = get_bits1(&s->gb); | |
307 | 1503 s->rl_table_index = 2; |
1504 s->rl_chroma_table_index = s->rl_table_index; | |
1505 s->dc_table_index = 0; //not used | |
1506 s->mv_table_index = 0; | |
457 | 1507 break; |
1508 case 3: | |
1509 s->use_skip_mb_code = get_bits1(&s->gb); | |
307 | 1510 s->rl_table_index = decode012(&s->gb); |
1511 s->rl_chroma_table_index = s->rl_table_index; | |
0 | 1512 |
307 | 1513 s->dc_table_index = get_bits1(&s->gb); |
1514 | |
1515 s->mv_table_index = get_bits1(&s->gb); | |
457 | 1516 break; |
499 | 1517 case 4: |
1518 s->use_skip_mb_code = get_bits1(&s->gb); | |
519 | 1519 |
578 | 1520 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb); |
1521 else s->per_mb_rl_table= 0; | |
519 | 1522 |
499 | 1523 if(!s->per_mb_rl_table){ |
1524 s->rl_table_index = decode012(&s->gb); | |
1525 s->rl_chroma_table_index = s->rl_table_index; | |
1526 } | |
1527 | |
1528 s->dc_table_index = get_bits1(&s->gb); | |
1529 | |
1530 s->mv_table_index = get_bits1(&s->gb); | |
578 | 1531 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE); |
499 | 1532 break; |
307 | 1533 } |
2967 | 1534 |
1388 | 1535 if(s->avctx->debug&FF_DEBUG_PICT_INFO) |
2979 | 1536 av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n", |
1537 s->use_skip_mb_code, | |
1538 s->rl_table_index, | |
1539 s->rl_chroma_table_index, | |
1540 s->dc_table_index, | |
1541 s->mv_table_index, | |
519 | 1542 s->per_mb_rl_table, |
1388 | 1543 s->qscale); |
1544 | |
2979 | 1545 if(s->flipflop_rounding){ |
1546 s->no_rounding ^= 1; | |
1547 }else{ | |
1548 s->no_rounding = 0; | |
1549 } | |
0 | 1550 } |
936 | 1551 //printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height); |
499 | 1552 |
1553 s->esc3_level_length= 0; | |
1554 s->esc3_run_length= 0; | |
307 | 1555 |
0 | 1556 return 0; |
1557 } | |
1558 | |
208 | 1559 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) |
1560 { | |
457 | 1561 int left= buf_size*8 - get_bits_count(&s->gb); |
1562 int length= s->msmpeg4_version>=3 ? 17 : 16; | |
208 | 1563 /* the alt_bitstream reader could read over the end so we need to check it */ |
457 | 1564 if(left>=length && left<length+8) |
208 | 1565 { |
251
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
246
diff
changeset
|
1566 int fps; |
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
246
diff
changeset
|
1567 |
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
246
diff
changeset
|
1568 fps= get_bits(&s->gb, 5); |
578 | 1569 s->bit_rate= get_bits(&s->gb, 11)*1024; |
457 | 1570 if(s->msmpeg4_version>=3) |
1571 s->flipflop_rounding= get_bits1(&s->gb); | |
1572 else | |
1573 s->flipflop_rounding= 0; | |
251
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
246
diff
changeset
|
1574 |
578 | 1575 // printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate/1024, s->flipflop_rounding); |
457 | 1576 } |
1577 else if(left<length+8) | |
1578 { | |
1579 s->flipflop_rounding= 0; | |
1399 | 1580 if(s->msmpeg4_version != 2) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1581 av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); |
208 | 1582 } |
1583 else | |
1584 { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1585 av_log(s->avctx, AV_LOG_ERROR, "I frame too long, ignoring ext header\n"); |
208 | 1586 } |
251
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
246
diff
changeset
|
1587 |
208 | 1588 return 0; |
1589 } | |
1590 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1591 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) |
310 | 1592 { |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1593 int level, pred; |
457 | 1594 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1595 if(s->msmpeg4_version<=2){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1596 if (n < 4) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1597 level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1598 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1599 level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3); |
307 | 1600 } |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1601 if (level < 0) |
457 | 1602 return -1; |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1603 level-=256; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1604 }else{ //FIXME optimize use unified tables & index |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1605 if (n < 4) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1606 level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1607 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1608 level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); |
457 | 1609 } |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1610 if (level < 0){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1611 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); |
457 | 1612 return -1; |
1613 } | |
307 | 1614 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1615 if (level == DC_MAX) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1616 level = get_bits(&s->gb, 8); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1617 if (get_bits1(&s->gb)) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1618 level = -level; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1619 } else if (level != 0) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1620 if (get_bits1(&s->gb)) |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1621 level = -level; |
457 | 1622 } |
307 | 1623 } |
1624 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1625 if(s->msmpeg4_version==1){ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1626 int32_t *dc_val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1627 pred = msmpeg4v1_pred_dc(s, n, &dc_val); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1628 level += pred; |
0 | 1629 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1630 /* update predictor */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1631 *dc_val= level; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1632 }else{ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1633 int16_t *dc_val; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1634 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1635 level += pred; |
2967 | 1636 |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1637 /* update predictor */ |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1638 if (n < 4) { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1639 *dc_val = level * s->y_dc_scale; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1640 } else { |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1641 *dc_val = level * s->c_dc_scale; |
0 | 1642 } |
1643 } | |
1644 | |
10751
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1645 return level; |
74e8feb81c6d
cosmetics: Reorder functions to avoid forward declarations.
diego
parents:
10750
diff
changeset
|
1646 } |
0 | 1647 |
563 | 1648 //#define ERROR_DETAILS |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
1649 int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
936 | 1650 int n, int coded, const uint8_t *scan_table) |
0 | 1651 { |
542 | 1652 int level, i, last, run, run_diff; |
8780
56c41adae7d8
Fix: libavcodec/msmpeg4.c:1612: warning: ¡Ædc_pred_dir¡Ç may be used uninitialized in this function
michael
parents:
8718
diff
changeset
|
1653 int av_uninit(dc_pred_dir); |
0 | 1654 RLTable *rl; |
542 | 1655 RL_VLC_ELEM *rl_vlc; |
200 | 1656 int qmul, qadd; |
0 | 1657 |
1658 if (s->mb_intra) { | |
200 | 1659 qmul=1; |
1660 qadd=0; | |
1661 | |
2979 | 1662 /* DC coef */ |
0 | 1663 level = msmpeg4_decode_dc(s, n, &dc_pred_dir); |
2967 | 1664 |
457 | 1665 if (level < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1666 av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); |
519 | 1667 if(s->inter_intra_pred) level=0; |
1668 else return -1; | |
457 | 1669 } |
0 | 1670 if (n < 4) { |
1671 rl = &rl_table[s->rl_table_index]; | |
457 | 1672 if(level > 256*s->y_dc_scale){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1673 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale); |
519 | 1674 if(!s->inter_intra_pred) return -1; |
457 | 1675 } |
0 | 1676 } else { |
1677 rl = &rl_table[3 + s->rl_chroma_table_index]; | |
457 | 1678 if(level > 256*s->c_dc_scale){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1679 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale); |
519 | 1680 if(!s->inter_intra_pred) return -1; |
457 | 1681 } |
0 | 1682 } |
457 | 1683 block[0] = level; |
200 | 1684 |
5496 | 1685 run_diff = s->msmpeg4_version >= 4; |
542 | 1686 i = 0; |
0 | 1687 if (!coded) { |
1688 goto not_coded; | |
1689 } | |
1690 if (s->ac_pred) { | |
2967 | 1691 if (dc_pred_dir == 0) |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
1692 scan_table = s->intra_v_scantable.permutated; /* left */ |
0 | 1693 else |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
1694 scan_table = s->intra_h_scantable.permutated; /* top */ |
0 | 1695 } else { |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
601
diff
changeset
|
1696 scan_table = s->intra_scantable.permutated; |
0 | 1697 } |
542 | 1698 rl_vlc= rl->rl_vlc[0]; |
0 | 1699 } else { |
200 | 1700 qmul = s->qscale << 1; |
1701 qadd = (s->qscale - 1) | 1; | |
542 | 1702 i = -1; |
0 | 1703 rl = &rl_table[3 + s->rl_table_index]; |
307 | 1704 |
1705 if(s->msmpeg4_version==2) | |
1706 run_diff = 0; | |
1707 else | |
1708 run_diff = 1; | |
1709 | |
0 | 1710 if (!coded) { |
542 | 1711 s->block_last_index[n] = i; |
0 | 1712 return 0; |
1713 } | |
936 | 1714 if(!scan_table) |
1715 scan_table = s->inter_scantable.permutated; | |
542 | 1716 rl_vlc= rl->rl_vlc[s->qscale]; |
0 | 1717 } |
542 | 1718 { |
1719 OPEN_READER(re, &s->gb); | |
0 | 1720 for(;;) { |
542 | 1721 UPDATE_CACHE(re, &s->gb); |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2474
diff
changeset
|
1722 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); |
542 | 1723 if (level==0) { |
1724 int cache; | |
1725 cache= GET_CACHE(re, &s->gb); | |
0 | 1726 /* escape */ |
542 | 1727 if (s->msmpeg4_version==1 || (cache&0x80000000)==0) { |
1728 if (s->msmpeg4_version==1 || (cache&0x40000000)==0) { | |
0 | 1729 /* third escape */ |
542 | 1730 if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2); |
1731 UPDATE_CACHE(re, &s->gb); | |
499 | 1732 if(s->msmpeg4_version<=3){ |
542 | 1733 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); |
1734 run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); | |
1735 level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8); | |
1736 SKIP_COUNTER(re, &s->gb, 1+6+8); | |
2967 | 1737 }else{ |
499 | 1738 int sign; |
542 | 1739 last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); |
499 | 1740 if(!s->esc3_level_length){ |
1741 int ll; | |
1742 //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y); | |
1743 if(s->qscale<8){ | |
542 | 1744 ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); |
499 | 1745 if(ll==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1746 if(SHOW_UBITS(re, &s->gb, 1)) av_log(s->avctx, AV_LOG_ERROR, "cool a new vlc code ,contact the ffmpeg developers and upload the file\n"); |
542 | 1747 SKIP_BITS(re, &s->gb, 1); |
499 | 1748 ll=8; |
1749 } | |
1750 }else{ | |
1751 ll=2; | |
542 | 1752 while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){ |
1753 ll++; | |
1754 SKIP_BITS(re, &s->gb, 1); | |
1755 } | |
578 | 1756 if(ll<8) SKIP_BITS(re, &s->gb, 1); |
499 | 1757 } |
1758 | |
1759 s->esc3_level_length= ll; | |
542 | 1760 s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); |
499 | 1761 //printf("level length:%d, run length: %d\n", ll, s->esc3_run_length); |
578 | 1762 UPDATE_CACHE(re, &s->gb); |
499 | 1763 } |
2967 | 1764 run= SHOW_UBITS(re, &s->gb, s->esc3_run_length); |
542 | 1765 SKIP_BITS(re, &s->gb, s->esc3_run_length); |
2967 | 1766 |
1767 sign= SHOW_UBITS(re, &s->gb, 1); | |
542 | 1768 SKIP_BITS(re, &s->gb, 1); |
2967 | 1769 |
1770 level= SHOW_UBITS(re, &s->gb, s->esc3_level_length); | |
542 | 1771 SKIP_BITS(re, &s->gb, s->esc3_level_length); |
499 | 1772 if(sign) level= -level; |
1773 } | |
1774 //printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y); | |
457 | 1775 #if 0 // waste of time / this will detect very few errors |
1776 { | |
4001 | 1777 const int abs_level= FFABS(level); |
457 | 1778 const int run1= run - rl->max_run[last][abs_level] - run_diff; |
1779 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ | |
1780 if(abs_level <= rl->max_level[last][run]){ | |
3177 | 1781 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); |
457 | 1782 return DECODING_AC_LOST; |
1783 } | |
1784 if(abs_level <= rl->max_level[last][run]*2){ | |
3177 | 1785 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); |
457 | 1786 return DECODING_AC_LOST; |
1787 } | |
499 | 1788 if(run1>=0 && abs_level <= rl->max_level[last][run1]){ |
3177 | 1789 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); |
457 | 1790 return DECODING_AC_LOST; |
1791 } | |
1792 } | |
1793 } | |
1794 #endif | |
2979 | 1795 //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ; |
1796 if (level>0) level= level * qmul + qadd; | |
457 | 1797 else level= level * qmul - qadd; |
1798 #if 0 // waste of time too :( | |
1799 if(level>2048 || level<-2048){ | |
3177 | 1800 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n"); |
457 | 1801 return DECODING_AC_LOST; |
1802 } | |
1803 #endif | |
542 | 1804 i+= run + 1; |
1805 if(last) i+=192; | |
563 | 1806 #ifdef ERROR_DETAILS |
1807 if(run==66) | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1808 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level); |
563 | 1809 else if((i>62 && i<192) || i>192+63) |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1810 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level); |
563 | 1811 #endif |
0 | 1812 } else { |
1813 /* second escape */ | |
542 | 1814 #if MIN_CACHE_BITS < 23 |
1815 LAST_SKIP_BITS(re, &s->gb, 2); | |
1816 UPDATE_CACHE(re, &s->gb); | |
1817 #else | |
1818 SKIP_BITS(re, &s->gb, 2); | |
1819 #endif | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2474
diff
changeset
|
1820 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
542 | 1821 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing |
1822 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1823 LAST_SKIP_BITS(re, &s->gb, 1); | |
563 | 1824 #ifdef ERROR_DETAILS |
1825 if(run==66) | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1826 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level); |
563 | 1827 else if((i>62 && i<192) || i>192+63) |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1828 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level); |
563 | 1829 #endif |
0 | 1830 } |
1831 } else { | |
1832 /* first escape */ | |
542 | 1833 #if MIN_CACHE_BITS < 22 |
1834 LAST_SKIP_BITS(re, &s->gb, 1); | |
1835 UPDATE_CACHE(re, &s->gb); | |
1836 #else | |
1837 SKIP_BITS(re, &s->gb, 1); | |
1838 #endif | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2474
diff
changeset
|
1839 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
542 | 1840 i+= run; |
1841 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing | |
1842 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1843 LAST_SKIP_BITS(re, &s->gb, 1); | |
563 | 1844 #ifdef ERROR_DETAILS |
1845 if(run==66) | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1846 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level); |
563 | 1847 else if((i>62 && i<192) || i>192+63) |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1848 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level); |
563 | 1849 #endif |
0 | 1850 } |
1851 } else { | |
542 | 1852 i+= run; |
1853 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1854 LAST_SKIP_BITS(re, &s->gb, 1); | |
563 | 1855 #ifdef ERROR_DETAILS |
1856 if(run==66) | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1857 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level); |
563 | 1858 else if((i>62 && i<192) || i>192+63) |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2639
diff
changeset
|
1859 av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level); |
563 | 1860 #endif |
0 | 1861 } |
542 | 1862 if (i > 62){ |
1863 i-= 192; | |
1864 if(i&(~63)){ | |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
10071
diff
changeset
|
1865 const int left= get_bits_left(&s->gb); |
7831 | 1866 if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1867 av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); |
563 | 1868 break; |
1869 }else{ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1870 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
563 | 1871 return -1; |
1872 } | |
542 | 1873 } |
1874 | |
1875 block[scan_table[i]] = level; | |
1876 break; | |
499 | 1877 } |
457 | 1878 |
542 | 1879 block[scan_table[i]] = level; |
0 | 1880 } |
542 | 1881 CLOSE_READER(re, &s->gb); |
1882 } | |
0 | 1883 not_coded: |
1884 if (s->mb_intra) { | |
1885 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
1886 if (s->ac_pred) { | |
542 | 1887 i = 63; /* XXX: not optimal */ |
0 | 1888 } |
1889 } | |
936 | 1890 if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize |
542 | 1891 s->block_last_index[n] = i; |
2967 | 1892 |
0 | 1893 return 0; |
1894 } | |
1895 | |
5882
51fc10d9fdff
rename some msmpeg4 symbols and make them non-static
aurel
parents:
5543
diff
changeset
|
1896 int ff_msmpeg4_decode_motion(MpegEncContext * s, |
0 | 1897 int *mx_ptr, int *my_ptr) |
1898 { | |
1899 MVTable *mv; | |
1900 int code, mx, my; | |
1901 | |
1902 mv = &mv_tables[s->mv_table_index]; | |
1903 | |
531 | 1904 code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2); |
499 | 1905 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1399
diff
changeset
|
1906 av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y); |
0 | 1907 return -1; |
499 | 1908 } |
0 | 1909 if (code == mv->n) { |
499 | 1910 //printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y); |
0 | 1911 mx = get_bits(&s->gb, 6); |
1912 my = get_bits(&s->gb, 6); | |
1913 } else { | |
1914 mx = mv->table_mvx[code]; | |
1915 my = mv->table_mvy[code]; | |
1916 } | |
1917 | |
1918 mx += *mx_ptr - 32; | |
1919 my += *my_ptr - 32; | |
1920 /* WARNING : they do not do exactly modulo encoding */ | |
1921 if (mx <= -64) | |
1922 mx += 64; | |
1923 else if (mx >= 64) | |
1924 mx -= 64; | |
1925 | |
1926 if (my <= -64) | |
1927 my += 64; | |
1928 else if (my >= 64) | |
1929 my -= 64; | |
1930 *mx_ptr = mx; | |
1931 *my_ptr = my; | |
1932 return 0; | |
1933 } |