Mercurial > libavcodec.hg
annotate mpeg12.c @ 1739:07a484280a82 libavcodec
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
author | michael |
---|---|
date | Sat, 10 Jan 2004 16:04:55 +0000 |
parents | f716b8f47d98 |
children | 7b11032507e2 |
rev | line source |
---|---|
0 | 1 /* |
1106 | 2 * MPEG1 codec / MPEG2 decoder |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1732
diff
changeset
|
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 5 * |
429 | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
0 | 10 * |
429 | 11 * This library is distributed in the hope that it will be useful, |
0 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Lesser General Public License for more details. | |
0 | 15 * |
429 | 16 * You should have received a copy of the GNU Lesser General Public |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
0 | 19 */ |
1106 | 20 |
21 /** | |
22 * @file mpeg12.c | |
1421 | 23 * MPEG1/2 codec |
1106 | 24 */ |
25 | |
76 | 26 //#define DEBUG |
0 | 27 #include "avcodec.h" |
28 #include "dsputil.h" | |
29 #include "mpegvideo.h" | |
30 | |
31 #include "mpeg12data.h" | |
32 | |
1708 | 33 //#undef NDEBUG |
34 //#include <assert.h> | |
35 | |
694 | 36 |
0 | 37 /* Start codes. */ |
38 #define SEQ_END_CODE 0x000001b7 | |
39 #define SEQ_START_CODE 0x000001b3 | |
40 #define GOP_START_CODE 0x000001b8 | |
41 #define PICTURE_START_CODE 0x00000100 | |
42 #define SLICE_MIN_START_CODE 0x00000101 | |
43 #define SLICE_MAX_START_CODE 0x000001af | |
44 #define EXT_START_CODE 0x000001b5 | |
45 #define USER_START_CODE 0x000001b2 | |
46 | |
552 | 47 #define DC_VLC_BITS 9 |
48 #define MV_VLC_BITS 9 | |
49 #define MBINCR_VLC_BITS 9 | |
50 #define MB_PAT_VLC_BITS 9 | |
51 #define MB_PTYPE_VLC_BITS 6 | |
52 #define MB_BTYPE_VLC_BITS 6 | |
53 #define TEX_VLC_BITS 9 | |
54 | |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1503
diff
changeset
|
55 #ifdef CONFIG_ENCODERS |
0 | 56 static void mpeg1_encode_block(MpegEncContext *s, |
57 DCTELEM *block, | |
58 int component); | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
59 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1503
diff
changeset
|
60 #endif //CONFIG_ENCODERS |
0 | 61 static void mpeg1_skip_picture(MpegEncContext *s, int pict_num); |
711 | 62 static inline int mpeg1_decode_block_inter(MpegEncContext *s, |
63 DCTELEM *block, | |
64 int n); | |
65 static inline int mpeg1_decode_block_intra(MpegEncContext *s, | |
0 | 66 DCTELEM *block, |
67 int n); | |
714 | 68 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, |
0 | 69 DCTELEM *block, |
70 int n); | |
714 | 71 static inline int mpeg2_decode_block_intra(MpegEncContext *s, |
0 | 72 DCTELEM *block, |
73 int n); | |
74 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); | |
1620 | 75 static void exchange_uv(MpegEncContext *s); |
0 | 76 |
1381 | 77 #ifdef HAVE_XVMC |
78 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); | |
79 extern int XVMC_field_end(MpegEncContext *s); | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
80 extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp); |
1620 | 81 extern void XVMC_init_block(MpegEncContext *s);//set s->block |
1381 | 82 #endif |
83 | |
947 | 84 #ifdef CONFIG_ENCODERS |
1162 | 85 static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL; |
1064 | 86 static uint8_t fcode_tab[MAX_MV*2+1]; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
87 |
947 | 88 static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2]; |
89 static uint8_t uni_mpeg1_ac_vlc_len [64*64*2]; | |
1325 | 90 |
91 /* simple include everything table for dc, first byte is bits number next 3 are code*/ | |
92 static uint32_t mpeg1_lum_dc_uni[512]; | |
93 static uint32_t mpeg1_chr_dc_uni[512]; | |
94 | |
95 static uint8_t mpeg1_index_run[2][64]; | |
96 static int8_t mpeg1_max_level[2][64]; | |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1503
diff
changeset
|
97 #endif //CONFIG_ENCODERS |
947 | 98 |
552 | 99 static void init_2d_vlc_rl(RLTable *rl) |
100 { | |
620
a5aa53b6e648
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michaelni
parents:
617
diff
changeset
|
101 int i; |
552 | 102 |
103 init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2, | |
104 &rl->table_vlc[0][1], 4, 2, | |
105 &rl->table_vlc[0][0], 4, 2); | |
106 | |
107 | |
108 rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); | |
109 for(i=0; i<rl->vlc.table_size; i++){ | |
110 int code= rl->vlc.table[i][0]; | |
111 int len = rl->vlc.table[i][1]; | |
112 int level, run; | |
113 | |
114 if(len==0){ // illegal code | |
115 run= 65; | |
116 level= MAX_LEVEL; | |
117 }else if(len<0){ //more bits needed | |
118 run= 0; | |
119 level= code; | |
120 }else{ | |
121 if(code==rl->n){ //esc | |
122 run= 65; | |
123 level= 0; | |
124 }else if(code==rl->n+1){ //eob | |
711 | 125 run= 0; |
126 level= 127; | |
552 | 127 }else{ |
128 run= rl->table_run [code] + 1; | |
129 level= rl->table_level[code]; | |
130 } | |
131 } | |
132 rl->rl_vlc[0][i].len= len; | |
133 rl->rl_vlc[0][i].level= level; | |
134 rl->rl_vlc[0][i].run= run; | |
135 } | |
136 } | |
137 | |
1325 | 138 #ifdef CONFIG_ENCODERS |
947 | 139 static void init_uni_ac_vlc(RLTable *rl, uint32_t *uni_ac_vlc_bits, uint8_t *uni_ac_vlc_len){ |
140 int i; | |
141 | |
142 for(i=0; i<128; i++){ | |
143 int level= i-64; | |
144 int run; | |
145 for(run=0; run<64; run++){ | |
146 int len, bits, code; | |
147 | |
148 int alevel= ABS(level); | |
149 int sign= (level>>31)&1; | |
150 | |
151 if (alevel > rl->max_level[0][run]) | |
152 code= 111; /*rl->n*/ | |
153 else | |
154 code= rl->index_run[0][run] + alevel - 1; | |
155 | |
156 if (code < 111 /* rl->n */) { | |
157 /* store the vlc & sign at once */ | |
158 len= mpeg1_vlc[code][1]+1; | |
159 bits= (mpeg1_vlc[code][0]<<1) + sign; | |
160 } else { | |
161 len= mpeg1_vlc[111/*rl->n*/][1]+6; | |
162 bits= mpeg1_vlc[111/*rl->n*/][0]<<6; | |
163 | |
164 bits|= run; | |
165 if (alevel < 128) { | |
166 bits<<=8; len+=8; | |
167 bits|= level & 0xff; | |
168 } else { | |
169 bits<<=16; len+=16; | |
170 bits|= level & 0xff; | |
171 if (level < 0) { | |
172 bits|= 0x8001 + level + 255; | |
173 } else { | |
174 bits|= level & 0xffff; | |
175 } | |
176 } | |
177 } | |
178 | |
179 uni_ac_vlc_bits[UNI_AC_ENC_INDEX(run, i)]= bits; | |
180 uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len; | |
181 } | |
182 } | |
183 } | |
552 | 184 |
0 | 185 static void put_header(MpegEncContext *s, int header) |
186 { | |
187 align_put_bits(&s->pb); | |
236 | 188 put_bits(&s->pb, 16, header>>16); |
189 put_bits(&s->pb, 16, header&0xFFFF); | |
0 | 190 } |
191 | |
192 /* put sequence header if needed */ | |
193 static void mpeg1_encode_sequence_header(MpegEncContext *s) | |
194 { | |
195 unsigned int vbv_buffer_size; | |
1 | 196 unsigned int fps, v; |
918 | 197 int n, i; |
1064 | 198 uint64_t time_code; |
918 | 199 float best_aspect_error= 1E10; |
1548 | 200 float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); |
1479 | 201 int constraint_parameter_flag; |
918 | 202 |
1548 | 203 if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) |
0 | 204 |
903 | 205 if (s->current_picture.key_frame) { |
0 | 206 /* mpeg1 header repeated every gop */ |
207 put_header(s, SEQ_START_CODE); | |
208 | |
209 /* search closest frame rate */ | |
210 { | |
211 int i, dmin, d; | |
212 s->frame_rate_index = 0; | |
213 dmin = 0x7fffffff; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
214 for(i=1;i<14;i++) { |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
215 if(s->avctx->strict_std_compliance >= 0 && i>=9) break; |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
216 |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
217 d = abs(MPEG1_FRAME_RATE_BASE*(int64_t)s->avctx->frame_rate/s->avctx->frame_rate_base - frame_rate_tab[i]); |
0 | 218 if (d < dmin) { |
219 dmin = d; | |
220 s->frame_rate_index = i; | |
221 } | |
222 } | |
223 } | |
224 | |
225 put_bits(&s->pb, 12, s->width); | |
226 put_bits(&s->pb, 12, s->height); | |
918 | 227 |
228 for(i=1; i<15; i++){ | |
1550 | 229 float error= aspect_ratio; |
230 if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) | |
1587
b69b086f5570
100l (SAR is written as height/width instead of width/height in the MPEG1 standard)
michael
parents:
1580
diff
changeset
|
231 error-= 1.0/mpeg1_aspect[i]; |
1550 | 232 else |
233 error-= av_q2d(mpeg2_aspect[i])*s->height/s->width; | |
234 | |
918 | 235 error= ABS(error); |
236 | |
237 if(error < best_aspect_error){ | |
238 best_aspect_error= error; | |
239 s->aspect_ratio_info= i; | |
240 } | |
241 } | |
242 | |
243 put_bits(&s->pb, 4, s->aspect_ratio_info); | |
0 | 244 put_bits(&s->pb, 4, s->frame_rate_index); |
1430
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
245 |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
246 if(s->avctx->rc_max_rate){ |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
247 v = (s->avctx->rc_max_rate + 399) / 400; |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
248 if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
249 v = 0x3ffff; |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
250 }else{ |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
251 v= 0x3FFFF; |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
252 } |
639
f449913e8419
new vbv calculation patch by (Henry Mason <talus25 at speakeasy dot net>) with slight modification by me
michaelni
parents:
620
diff
changeset
|
253 |
f449913e8419
new vbv calculation patch by (Henry Mason <talus25 at speakeasy dot net>) with slight modification by me
michaelni
parents:
620
diff
changeset
|
254 if(s->avctx->rc_buffer_size) |
f449913e8419
new vbv calculation patch by (Henry Mason <talus25 at speakeasy dot net>) with slight modification by me
michaelni
parents:
620
diff
changeset
|
255 vbv_buffer_size = s->avctx->rc_buffer_size; |
f449913e8419
new vbv calculation patch by (Henry Mason <talus25 at speakeasy dot net>) with slight modification by me
michaelni
parents:
620
diff
changeset
|
256 else |
f449913e8419
new vbv calculation patch by (Henry Mason <talus25 at speakeasy dot net>) with slight modification by me
michaelni
parents:
620
diff
changeset
|
257 /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ |
1430
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
258 vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
259 vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
260 |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
261 put_bits(&s->pb, 18, v & 0x3FFFF); |
248d9ae1033c
bit_rate in mpeg1/2 should be 0x3FFFF for vbr or at least >= max_bitrate
michaelni
parents:
1429
diff
changeset
|
262 put_bits(&s->pb, 1, 1); /* marker */ |
1479 | 263 put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); |
264 | |
265 constraint_parameter_flag= | |
266 s->width <= 768 && s->height <= 576 && | |
267 s->mb_width * s->mb_height <= 396 && | |
268 s->mb_width * s->mb_height * frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*396*25 && | |
269 frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*30 && | |
270 vbv_buffer_size <= 20 && | |
271 v <= 1856000/400 && | |
272 s->codec_id == CODEC_ID_MPEG1VIDEO; | |
273 | |
274 put_bits(&s->pb, 1, constraint_parameter_flag); | |
1411 | 275 |
276 ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); | |
277 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); | |
0 | 278 |
1421 | 279 if(s->codec_id == CODEC_ID_MPEG2VIDEO){ |
280 put_header(s, EXT_START_CODE); | |
281 put_bits(&s->pb, 4, 1); //seq ext | |
282 put_bits(&s->pb, 1, 0); //esc | |
283 put_bits(&s->pb, 3, 4); //profile | |
284 put_bits(&s->pb, 4, 8); //level | |
1677 | 285 put_bits(&s->pb, 1, s->progressive_sequence); |
1421 | 286 put_bits(&s->pb, 2, 1); //chroma format 4:2:0 |
287 put_bits(&s->pb, 2, 0); //horizontal size ext | |
288 put_bits(&s->pb, 2, 0); //vertical size ext | |
289 put_bits(&s->pb, 12, v>>18); //bitrate ext | |
290 put_bits(&s->pb, 1, 1); //marker | |
291 put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext | |
292 put_bits(&s->pb, 1, s->low_delay); | |
293 put_bits(&s->pb, 2, 0); // frame_rate_ext_n | |
294 put_bits(&s->pb, 5, 0); // frame_rate_ext_d | |
295 } | |
296 | |
0 | 297 put_header(s, GOP_START_CODE); |
298 put_bits(&s->pb, 1, 0); /* do drop frame */ | |
299 /* time code : we must convert from the real frame rate to a | |
300 fake mpeg frame rate in case of low frame rate */ | |
1727 | 301 fps = (frame_rate_tab[s->frame_rate_index] + MPEG1_FRAME_RATE_BASE/2)/ MPEG1_FRAME_RATE_BASE; |
302 time_code = s->fake_picture_number; | |
0 | 303 s->gop_picture_number = s->fake_picture_number; |
1064 | 304 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); |
305 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); | |
0 | 306 put_bits(&s->pb, 1, 1); |
1064 | 307 put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); |
1727 | 308 put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); |
1429 | 309 put_bits(&s->pb, 1, 0); /* closed gop */ |
0 | 310 put_bits(&s->pb, 1, 0); /* broken link */ |
311 } | |
312 | |
1725
4bc18915485a
frame rate emulation "fix" by (Mean <fixounet at free dot fr>)
michael
parents:
1721
diff
changeset
|
313 if (s->avctx->frame_rate < (23 * s->avctx->frame_rate_base) && s->picture_number > 0) { |
0 | 314 /* insert empty P pictures to slow down to the desired |
315 frame rate. Each fake pictures takes about 20 bytes */ | |
316 fps = frame_rate_tab[s->frame_rate_index]; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
317 n = av_rescale((int64_t)s->picture_number * s->avctx->frame_rate_base, fps, s->avctx->frame_rate) / MPEG1_FRAME_RATE_BASE - 1; |
0 | 318 while (s->fake_picture_number < n) { |
319 mpeg1_skip_picture(s, s->fake_picture_number - | |
320 s->gop_picture_number); | |
321 s->fake_picture_number++; | |
322 } | |
323 | |
324 } | |
325 } | |
326 | |
1160 | 327 static inline void encode_mb_skip_run(MpegEncContext *s, int run){ |
328 while (run >= 33) { | |
329 put_bits(&s->pb, 11, 0x008); | |
330 run -= 33; | |
331 } | |
332 put_bits(&s->pb, mbAddrIncrTable[run][1], | |
333 mbAddrIncrTable[run][0]); | |
334 } | |
0 | 335 |
336 /* insert a fake P picture */ | |
337 static void mpeg1_skip_picture(MpegEncContext *s, int pict_num) | |
338 { | |
1421 | 339 assert(s->codec_id == CODEC_ID_MPEG1VIDEO); // mpeg2 can do these repeat things |
340 | |
0 | 341 /* mpeg1 picture header */ |
342 put_header(s, PICTURE_START_CODE); | |
343 /* temporal reference */ | |
344 put_bits(&s->pb, 10, pict_num & 0x3ff); | |
345 | |
346 put_bits(&s->pb, 3, P_TYPE); | |
347 put_bits(&s->pb, 16, 0xffff); /* non constant bit rate */ | |
348 | |
349 put_bits(&s->pb, 1, 1); /* integer coordinates */ | |
350 put_bits(&s->pb, 3, 1); /* forward_f_code */ | |
351 | |
352 put_bits(&s->pb, 1, 0); /* extra bit picture */ | |
353 | |
354 /* only one slice */ | |
355 put_header(s, SLICE_MIN_START_CODE); | |
356 put_bits(&s->pb, 5, 1); /* quantizer scale */ | |
357 put_bits(&s->pb, 1, 0); /* slice extra information */ | |
358 | |
1160 | 359 encode_mb_skip_run(s, 0); |
0 | 360 |
361 /* empty macroblock */ | |
362 put_bits(&s->pb, 3, 1); /* motion only */ | |
363 | |
364 /* zero motion x & y */ | |
365 put_bits(&s->pb, 1, 1); | |
366 put_bits(&s->pb, 1, 1); | |
367 | |
368 /* output a number of empty slice */ | |
1160 | 369 encode_mb_skip_run(s, s->mb_width * s->mb_height - 2); |
0 | 370 |
371 /* empty macroblock */ | |
372 put_bits(&s->pb, 3, 1); /* motion only */ | |
373 | |
374 /* zero motion x & y */ | |
375 put_bits(&s->pb, 1, 1); | |
376 put_bits(&s->pb, 1, 1); | |
377 } | |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1503
diff
changeset
|
378 #endif //CONFIG_ENCODERS |
0 | 379 |
498 | 380 static void common_init(MpegEncContext *s) |
381 { | |
382 s->y_dc_scale_table= | |
383 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
384 } | |
385 | |
1325 | 386 void ff_mpeg1_clean_buffers(MpegEncContext *s){ |
387 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); | |
388 s->last_dc[1] = s->last_dc[0]; | |
389 s->last_dc[2] = s->last_dc[0]; | |
390 memset(s->last_mv, 0, sizeof(s->last_mv)); | |
391 } | |
392 | |
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
|
393 #ifdef CONFIG_ENCODERS |
1160 | 394 |
395 void ff_mpeg1_encode_slice_header(MpegEncContext *s){ | |
396 put_header(s, SLICE_MIN_START_CODE + s->mb_y); | |
397 put_bits(&s->pb, 5, s->qscale); /* quantizer scale */ | |
398 put_bits(&s->pb, 1, 0); /* slice extra information */ | |
399 } | |
400 | |
0 | 401 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) |
402 { | |
403 mpeg1_encode_sequence_header(s); | |
404 | |
405 /* mpeg1 picture header */ | |
406 put_header(s, PICTURE_START_CODE); | |
407 /* temporal reference */ | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
408 |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
409 // RAL: s->picture_number instead of s->fake_picture_number |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
410 put_bits(&s->pb, 10, (s->picture_number - |
0 | 411 s->gop_picture_number) & 0x3ff); |
276
1e2f9ef286d4
- Fix pts calculation on mpeg mux (A/V sync) - Thanks to Lennert Buytenhek
pulento
parents:
275
diff
changeset
|
412 s->fake_picture_number++; |
0 | 413 |
414 put_bits(&s->pb, 3, s->pict_type); | |
1697 | 415 |
416 s->vbv_delay_ptr= s->pb.buf + get_bit_count(&s->pb)/8; | |
417 put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ | |
0 | 418 |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
419 // RAL: Forward f_code also needed for B frames |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
420 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { |
0 | 421 put_bits(&s->pb, 1, 0); /* half pel coordinates */ |
1432 | 422 if(s->codec_id == CODEC_ID_MPEG1VIDEO) |
423 put_bits(&s->pb, 3, s->f_code); /* forward_f_code */ | |
424 else | |
425 put_bits(&s->pb, 3, 7); /* forward_f_code */ | |
0 | 426 } |
427 | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
428 // RAL: Backward f_code necessary for B frames |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
429 if (s->pict_type == B_TYPE) { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
430 put_bits(&s->pb, 1, 0); /* half pel coordinates */ |
1432 | 431 if(s->codec_id == CODEC_ID_MPEG1VIDEO) |
432 put_bits(&s->pb, 3, s->b_code); /* backward_f_code */ | |
433 else | |
434 put_bits(&s->pb, 3, 7); /* backward_f_code */ | |
1421 | 435 } |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
436 |
0 | 437 put_bits(&s->pb, 1, 0); /* extra bit picture */ |
1677 | 438 |
439 s->frame_pred_frame_dct = 1; | |
1421 | 440 if(s->codec_id == CODEC_ID_MPEG2VIDEO){ |
441 put_header(s, EXT_START_CODE); | |
442 put_bits(&s->pb, 4, 8); //pic ext | |
1432 | 443 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { |
444 put_bits(&s->pb, 4, s->f_code); | |
445 put_bits(&s->pb, 4, s->f_code); | |
446 }else{ | |
447 put_bits(&s->pb, 8, 255); | |
448 } | |
449 if (s->pict_type == B_TYPE) { | |
450 put_bits(&s->pb, 4, s->b_code); | |
451 put_bits(&s->pb, 4, s->b_code); | |
452 }else{ | |
453 put_bits(&s->pb, 8, 255); | |
454 } | |
1421 | 455 put_bits(&s->pb, 2, s->intra_dc_precision); |
456 put_bits(&s->pb, 2, s->picture_structure= PICT_FRAME); | |
1682 | 457 if (s->progressive_sequence) { |
458 put_bits(&s->pb, 1, 0); /* no repeat */ | |
459 } else { | |
460 put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); | |
461 } | |
1677 | 462 /* XXX: optimize the generation of this flag with entropy |
463 measures */ | |
464 s->frame_pred_frame_dct = s->progressive_sequence; | |
465 | |
466 put_bits(&s->pb, 1, s->frame_pred_frame_dct); | |
1421 | 467 put_bits(&s->pb, 1, s->concealment_motion_vectors); |
468 put_bits(&s->pb, 1, s->q_scale_type); | |
469 put_bits(&s->pb, 1, s->intra_vlc_format); | |
470 put_bits(&s->pb, 1, s->alternate_scan); | |
471 put_bits(&s->pb, 1, s->repeat_first_field); | |
472 put_bits(&s->pb, 1, s->chroma_420_type=1); | |
1677 | 473 s->progressive_frame = s->progressive_sequence; |
474 put_bits(&s->pb, 1, s->progressive_frame); | |
1421 | 475 put_bits(&s->pb, 1, 0); //composite_display_flag |
476 } | |
1721 | 477 if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){ |
478 int i; | |
479 | |
480 put_header(s, USER_START_CODE); | |
481 for(i=0; i<sizeof(svcd_scan_offset_placeholder); i++){ | |
482 put_bits(&s->pb, 8, svcd_scan_offset_placeholder[i]); | |
483 } | |
484 } | |
1421 | 485 |
1160 | 486 s->mb_y=0; |
487 ff_mpeg1_encode_slice_header(s); | |
0 | 488 } |
489 | |
1677 | 490 static inline void put_mb_modes(MpegEncContext *s, int n, int bits, |
1708 | 491 int has_mv, int field_motion) |
1677 | 492 { |
493 put_bits(&s->pb, n, bits); | |
494 if (!s->frame_pred_frame_dct) { | |
495 if (has_mv) | |
1708 | 496 put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */ |
1677 | 497 put_bits(&s->pb, 1, s->interlaced_dct); |
498 } | |
499 } | |
500 | |
0 | 501 void mpeg1_encode_mb(MpegEncContext *s, |
502 DCTELEM block[6][64], | |
503 int motion_x, int motion_y) | |
504 { | |
1160 | 505 int i, cbp; |
506 const int mb_x = s->mb_x; | |
507 const int mb_y = s->mb_y; | |
508 const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y; | |
0 | 509 |
510 /* compute cbp */ | |
511 cbp = 0; | |
512 for(i=0;i<6;i++) { | |
513 if (s->block_last_index[i] >= 0) | |
514 cbp |= 1 << (5 - i); | |
515 } | |
1708 | 516 |
1421 | 517 if (cbp == 0 && !first_mb && (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && |
1708 | 518 ((s->pict_type == P_TYPE && s->mv_type == MV_TYPE_16X16 && (motion_x | motion_y) == 0) || |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
519 (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) | |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
520 ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) { |
1160 | 521 s->mb_skip_run++; |
694 | 522 s->qscale -= s->dquant; |
740 | 523 s->skip_count++; |
524 s->misc_bits++; | |
525 s->last_bits++; | |
1708 | 526 if(s->pict_type == P_TYPE){ |
527 s->last_mv[0][1][0]= s->last_mv[0][0][0]= | |
528 s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0; | |
529 } | |
0 | 530 } else { |
1160 | 531 if(first_mb){ |
532 assert(s->mb_skip_run == 0); | |
533 encode_mb_skip_run(s, s->mb_x); | |
534 }else{ | |
535 encode_mb_skip_run(s, s->mb_skip_run); | |
0 | 536 } |
537 | |
538 if (s->pict_type == I_TYPE) { | |
694 | 539 if(s->dquant && cbp){ |
1708 | 540 put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ |
694 | 541 put_bits(&s->pb, 5, s->qscale); |
542 }else{ | |
1708 | 543 put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */ |
694 | 544 s->qscale -= s->dquant; |
545 } | |
740 | 546 s->misc_bits+= get_bits_diff(s); |
547 s->i_count++; | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
548 } else if (s->mb_intra) { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
549 if(s->dquant && cbp){ |
1708 | 550 put_mb_modes(s, 6, 0x01, 0, 0); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
551 put_bits(&s->pb, 5, s->qscale); |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
552 }else{ |
1708 | 553 put_mb_modes(s, 5, 0x03, 0, 0); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
554 s->qscale -= s->dquant; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
555 } |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
556 s->misc_bits+= get_bits_diff(s); |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
557 s->i_count++; |
1708 | 558 memset(s->last_mv, 0, sizeof(s->last_mv)); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
559 } else if (s->pict_type == P_TYPE) { |
1708 | 560 if(s->mv_type == MV_TYPE_16X16){ |
0 | 561 if (cbp != 0) { |
1708 | 562 if ((motion_x|motion_y) == 0) { |
694 | 563 if(s->dquant){ |
1708 | 564 put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */ |
694 | 565 put_bits(&s->pb, 5, s->qscale); |
566 }else{ | |
1708 | 567 put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */ |
694 | 568 } |
740 | 569 s->misc_bits+= get_bits_diff(s); |
0 | 570 } else { |
694 | 571 if(s->dquant){ |
1708 | 572 put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ |
694 | 573 put_bits(&s->pb, 5, s->qscale); |
574 }else{ | |
1708 | 575 put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ |
694 | 576 } |
740 | 577 s->misc_bits+= get_bits_diff(s); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
578 mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
579 mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added |
740 | 580 s->mv_bits+= get_bits_diff(s); |
0 | 581 } |
582 } else { | |
583 put_bits(&s->pb, 3, 1); /* motion only */ | |
1677 | 584 if (!s->frame_pred_frame_dct) |
585 put_bits(&s->pb, 2, 2); /* motion_type: frame */ | |
1708 | 586 s->misc_bits+= get_bits_diff(s); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
587 mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
588 mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added |
694 | 589 s->qscale -= s->dquant; |
740 | 590 s->mv_bits+= get_bits_diff(s); |
0 | 591 } |
1708 | 592 s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x; |
593 s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y; | |
594 }else{ | |
595 assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD); | |
596 | |
597 if (cbp) { | |
598 if(s->dquant){ | |
599 put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ | |
600 put_bits(&s->pb, 5, s->qscale); | |
601 }else{ | |
602 put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ | |
603 } | |
604 } else { | |
605 put_bits(&s->pb, 3, 1); /* motion only */ | |
606 put_bits(&s->pb, 2, 1); /* motion_type: field */ | |
607 s->qscale -= s->dquant; | |
608 } | |
609 s->misc_bits+= get_bits_diff(s); | |
610 for(i=0; i<2; i++){ | |
611 put_bits(&s->pb, 1, s->field_select[0][i]); | |
612 mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); | |
613 mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); | |
614 s->last_mv[0][i][0]= s->mv[0][i][0]; | |
615 s->last_mv[0][i][1]= 2*s->mv[0][i][1]; | |
616 } | |
617 s->mv_bits+= get_bits_diff(s); | |
618 } | |
619 if(cbp) | |
620 put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]); | |
621 s->f_count++; | |
622 } else{ | |
623 static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi | |
624 | |
625 if(s->mv_type == MV_TYPE_16X16){ | |
626 if (cbp){ // With coded bloc pattern | |
627 if (s->dquant) { | |
628 if(s->mv_dir == MV_DIR_FORWARD) | |
629 put_mb_modes(s, 6, 3, 1, 0); | |
630 else | |
631 put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0); | |
632 put_bits(&s->pb, 5, s->qscale); | |
633 } else { | |
634 put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0); | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
635 } |
1708 | 636 }else{ // No coded bloc pattern |
637 put_bits(&s->pb, mb_type_len[s->mv_dir], 2); | |
638 if (!s->frame_pred_frame_dct) | |
639 put_bits(&s->pb, 2, 2); /* motion_type: frame */ | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
640 s->qscale -= s->dquant; |
1708 | 641 } |
642 s->misc_bits += get_bits_diff(s); | |
643 if (s->mv_dir&MV_DIR_FORWARD){ | |
644 mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); | |
645 mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); | |
646 s->last_mv[0][0][0]=s->last_mv[0][1][0]= s->mv[0][0][0]; | |
647 s->last_mv[0][0][1]=s->last_mv[0][1][1]= s->mv[0][0][1]; | |
648 s->f_count++; | |
649 } | |
650 if (s->mv_dir&MV_DIR_BACKWARD){ | |
651 mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code); | |
652 mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); | |
653 s->last_mv[1][0][0]=s->last_mv[1][1][0]= s->mv[1][0][0]; | |
654 s->last_mv[1][0][1]=s->last_mv[1][1][1]= s->mv[1][0][1]; | |
655 s->b_count++; | |
656 } | |
657 }else{ | |
658 assert(s->mv_type == MV_TYPE_FIELD); | |
659 assert(!s->frame_pred_frame_dct); | |
660 if (cbp){ // With coded bloc pattern | |
661 if (s->dquant) { | |
662 if(s->mv_dir == MV_DIR_FORWARD) | |
663 put_mb_modes(s, 6, 3, 1, 1); | |
664 else | |
665 put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1); | |
666 put_bits(&s->pb, 5, s->qscale); | |
667 } else { | |
668 put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1); | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
669 } |
1708 | 670 }else{ // No coded bloc pattern |
671 put_bits(&s->pb, mb_type_len[s->mv_dir], 2); | |
672 put_bits(&s->pb, 2, 1); /* motion_type: field */ | |
673 s->qscale -= s->dquant; | |
674 } | |
675 s->misc_bits += get_bits_diff(s); | |
676 if (s->mv_dir&MV_DIR_FORWARD){ | |
677 for(i=0; i<2; i++){ | |
678 put_bits(&s->pb, 1, s->field_select[0][i]); | |
679 mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); | |
680 mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); | |
681 s->last_mv[0][i][0]= s->mv[0][i][0]; | |
682 s->last_mv[0][i][1]= 2*s->mv[0][i][1]; | |
683 } | |
684 s->f_count++; | |
685 } | |
686 if (s->mv_dir&MV_DIR_BACKWARD){ | |
687 for(i=0; i<2; i++){ | |
688 put_bits(&s->pb, 1, s->field_select[1][i]); | |
689 mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code); | |
690 mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code); | |
691 s->last_mv[1][i][0]= s->mv[1][i][0]; | |
692 s->last_mv[1][i][1]= 2*s->mv[1][i][1]; | |
693 } | |
694 s->b_count++; | |
695 } | |
0 | 696 } |
1708 | 697 s->mv_bits += get_bits_diff(s); |
698 if(cbp) | |
699 put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]); | |
700 } | |
0 | 701 for(i=0;i<6;i++) { |
702 if (cbp & (1 << (5 - i))) { | |
703 mpeg1_encode_block(s, block[i], i); | |
704 } | |
705 } | |
1160 | 706 s->mb_skip_run = 0; |
740 | 707 if(s->mb_intra) |
708 s->i_tex_bits+= get_bits_diff(s); | |
709 else | |
710 s->p_tex_bits+= get_bits_diff(s); | |
0 | 711 } |
712 } | |
713 | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
714 // RAL: Parameter added: f_or_b_code |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
715 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) |
0 | 716 { |
717 int code, bit_size, l, m, bits, range, sign; | |
718 | |
719 if (val == 0) { | |
720 /* zero vector */ | |
721 code = 0; | |
722 put_bits(&s->pb, | |
723 mbMotionVectorTable[0][1], | |
724 mbMotionVectorTable[0][0]); | |
725 } else { | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
726 bit_size = f_or_b_code - 1; |
0 | 727 range = 1 << bit_size; |
728 /* modulo encoding */ | |
729 l = 16 * range; | |
730 m = 2 * l; | |
731 if (val < -l) { | |
732 val += m; | |
733 } else if (val >= l) { | |
734 val -= m; | |
735 } | |
736 | |
737 if (val >= 0) { | |
738 val--; | |
739 code = (val >> bit_size) + 1; | |
740 bits = val & (range - 1); | |
741 sign = 0; | |
742 } else { | |
743 val = -val; | |
744 val--; | |
745 code = (val >> bit_size) + 1; | |
746 bits = val & (range - 1); | |
747 sign = 1; | |
748 } | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
749 |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
750 assert(code > 0 && code <= 16); |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
751 |
0 | 752 put_bits(&s->pb, |
753 mbMotionVectorTable[code][1], | |
754 mbMotionVectorTable[code][0]); | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1025
diff
changeset
|
755 |
0 | 756 put_bits(&s->pb, 1, sign); |
757 if (bit_size > 0) { | |
758 put_bits(&s->pb, bit_size, bits); | |
759 } | |
760 } | |
761 } | |
762 | |
498 | 763 void ff_mpeg1_encode_init(MpegEncContext *s) |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
764 { |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
765 static int done=0; |
498 | 766 |
767 common_init(s); | |
768 | |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
769 if(!done){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
770 int f_code; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
771 int mv; |
498 | 772 int i; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
773 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
774 done=1; |
498 | 775 init_rl(&rl_mpeg1); |
947 | 776 |
498 | 777 for(i=0; i<64; i++) |
778 { | |
779 mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; | |
780 mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; | |
781 } | |
947 | 782 |
783 init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_bits, uni_mpeg1_ac_vlc_len); | |
498 | 784 |
785 /* build unified dc encoding tables */ | |
786 for(i=-255; i<256; i++) | |
787 { | |
788 int adiff, index; | |
789 int bits, code; | |
790 int diff=i; | |
791 | |
792 adiff = ABS(diff); | |
793 if(diff<0) diff--; | |
794 index = vlc_dc_table[adiff]; | |
795 | |
796 bits= vlc_dc_lum_bits[index] + index; | |
797 code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)); | |
798 mpeg1_lum_dc_uni[i+255]= bits + (code<<8); | |
799 | |
800 bits= vlc_dc_chroma_bits[index] + index; | |
801 code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)); | |
802 mpeg1_chr_dc_uni[i+255]= bits + (code<<8); | |
803 } | |
804 | |
1162 | 805 mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); |
806 | |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
807 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
808 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
809 int len; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
810 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
811 if(mv==0) len= mbMotionVectorTable[0][1]; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
812 else{ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
813 int val, bit_size, range, code; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
814 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
815 bit_size = s->f_code - 1; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
816 range = 1 << bit_size; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
817 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
818 val=mv; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
819 if (val < 0) |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
820 val = -val; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
821 val--; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
822 code = (val >> bit_size) + 1; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
823 if(code<17){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
824 len= mbMotionVectorTable[code][1] + 1 + bit_size; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
825 }else{ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
826 len= mbMotionVectorTable[16][1] + 2 + bit_size; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
827 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
828 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
829 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
830 mv_penalty[f_code][mv+MAX_MV]= len; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
831 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
832 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
833 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
834 |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
835 for(f_code=MAX_FCODE; f_code>0; f_code--){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
836 for(mv=-(8<<f_code); mv<(8<<f_code); mv++){ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
837 fcode_tab[mv+MAX_MV]= f_code; |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
838 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
839 } |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
840 } |
936 | 841 s->me.mv_penalty= mv_penalty; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
842 s->fcode_tab= fcode_tab; |
1421 | 843 if(s->codec_id == CODEC_ID_MPEG1VIDEO){ |
844 s->min_qcoeff=-255; | |
845 s->max_qcoeff= 255; | |
846 }else{ | |
847 s->min_qcoeff=-2047; | |
848 s->max_qcoeff= 2047; | |
849 } | |
947 | 850 s->intra_ac_vlc_length= |
1503 | 851 s->inter_ac_vlc_length= |
852 s->intra_ac_vlc_last_length= | |
853 s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len; | |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
854 } |
498 | 855 |
0 | 856 static inline void encode_dc(MpegEncContext *s, int diff, int component) |
857 { | |
858 if (component == 0) { | |
237
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
859 put_bits( |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
860 &s->pb, |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
861 mpeg1_lum_dc_uni[diff+255]&0xFF, |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
862 mpeg1_lum_dc_uni[diff+255]>>8); |
0 | 863 } else { |
237
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
864 put_bits( |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
865 &s->pb, |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
866 mpeg1_chr_dc_uni[diff+255]&0xFF, |
75123d30f862
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
michaelni
parents:
236
diff
changeset
|
867 mpeg1_chr_dc_uni[diff+255]>>8); |
0 | 868 } |
869 } | |
870 | |
871 static void mpeg1_encode_block(MpegEncContext *s, | |
872 DCTELEM *block, | |
873 int n) | |
874 { | |
875 int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; | |
876 int code, component; | |
236 | 877 // RLTable *rl = &rl_mpeg1; |
0 | 878 |
879 last_index = s->block_last_index[n]; | |
880 | |
881 /* DC coef */ | |
882 if (s->mb_intra) { | |
883 component = (n <= 3 ? 0 : n - 4 + 1); | |
884 dc = block[0]; /* overflow is impossible */ | |
885 diff = dc - s->last_dc[component]; | |
886 encode_dc(s, diff, component); | |
887 s->last_dc[component] = dc; | |
888 i = 1; | |
1421 | 889 /* |
890 if (s->intra_vlc_format) | |
891 rl = &rl_mpeg2; | |
892 else | |
893 rl = &rl_mpeg1; | |
894 */ | |
0 | 895 } else { |
896 /* encode the first coefficient : needs to be done here because | |
897 it is handled slightly differently */ | |
898 level = block[0]; | |
899 if (abs(level) == 1) { | |
1064 | 900 code = ((uint32_t)level >> 31); /* the sign bit */ |
0 | 901 put_bits(&s->pb, 2, code | 0x02); |
902 i = 1; | |
903 } else { | |
904 i = 0; | |
905 last_non_zero = -1; | |
906 goto next_coef; | |
907 } | |
908 } | |
909 | |
910 /* now quantify & encode AC coefs */ | |
911 last_non_zero = i - 1; | |
236 | 912 |
0 | 913 for(;i<=last_index;i++) { |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
914 j = s->intra_scantable.permutated[i]; |
0 | 915 level = block[j]; |
916 next_coef: | |
917 #if 0 | |
918 if (level != 0) | |
919 dprintf("level[%d]=%d\n", i, level); | |
920 #endif | |
921 /* encode using VLC */ | |
922 if (level != 0) { | |
923 run = i - last_non_zero - 1; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
924 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
925 alevel= level; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
926 MASK_ABS(sign, alevel) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
927 sign&=1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
928 |
236 | 929 // code = get_rl_index(rl, 0, run, alevel); |
947 | 930 if (alevel <= mpeg1_max_level[0][run]){ |
236 | 931 code= mpeg1_index_run[0][run] + alevel - 1; |
932 /* store the vlc & sign at once */ | |
933 put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign); | |
0 | 934 } else { |
236 | 935 /* escape seems to be pretty rare <5% so i dont optimize it */ |
936 put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]); | |
0 | 937 /* escape: only clip in this case */ |
938 put_bits(&s->pb, 6, run); | |
1421 | 939 if(s->codec_id == CODEC_ID_MPEG1VIDEO){ |
940 if (alevel < 128) { | |
941 put_bits(&s->pb, 8, level & 0xff); | |
0 | 942 } else { |
1421 | 943 if (level < 0) { |
944 put_bits(&s->pb, 16, 0x8001 + level + 255); | |
945 } else { | |
946 put_bits(&s->pb, 16, level & 0xffff); | |
947 } | |
0 | 948 } |
1421 | 949 }else{ |
950 put_bits(&s->pb, 12, level & 0xfff); | |
0 | 951 } |
952 } | |
953 last_non_zero = i; | |
954 } | |
955 } | |
956 /* end of block */ | |
957 put_bits(&s->pb, 2, 0x2); | |
958 } | |
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
|
959 #endif //CONFIG_ENCODERS |
0 | 960 |
961 /******************************************/ | |
962 /* decoding */ | |
963 | |
964 static VLC dc_lum_vlc; | |
965 static VLC dc_chroma_vlc; | |
966 static VLC mv_vlc; | |
967 static VLC mbincr_vlc; | |
968 static VLC mb_ptype_vlc; | |
969 static VLC mb_btype_vlc; | |
970 static VLC mb_pat_vlc; | |
971 | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
972 static void init_vlcs() |
0 | 973 { |
974 static int done = 0; | |
975 | |
976 if (!done) { | |
494 | 977 done = 1; |
0 | 978 |
568 | 979 init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12, |
0 | 980 vlc_dc_lum_bits, 1, 1, |
981 vlc_dc_lum_code, 2, 2); | |
568 | 982 init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12, |
0 | 983 vlc_dc_chroma_bits, 1, 1, |
984 vlc_dc_chroma_code, 2, 2); | |
545 | 985 init_vlc(&mv_vlc, MV_VLC_BITS, 17, |
0 | 986 &mbMotionVectorTable[0][1], 2, 1, |
987 &mbMotionVectorTable[0][0], 2, 1); | |
1181 | 988 init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36, |
0 | 989 &mbAddrIncrTable[0][1], 2, 1, |
990 &mbAddrIncrTable[0][0], 2, 1); | |
545 | 991 init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 63, |
0 | 992 &mbPatTable[0][1], 2, 1, |
993 &mbPatTable[0][0], 2, 1); | |
994 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
995 init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7, |
0 | 996 &table_mb_ptype[0][1], 2, 1, |
997 &table_mb_ptype[0][0], 2, 1); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
998 init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11, |
0 | 999 &table_mb_btype[0][1], 2, 1, |
1000 &table_mb_btype[0][0], 2, 1); | |
1001 init_rl(&rl_mpeg1); | |
1002 init_rl(&rl_mpeg2); | |
552 | 1003 |
1004 init_2d_vlc_rl(&rl_mpeg1); | |
1005 init_2d_vlc_rl(&rl_mpeg2); | |
0 | 1006 } |
1007 } | |
1008 | |
1009 static inline int get_dmv(MpegEncContext *s) | |
1010 { | |
21 | 1011 if(get_bits1(&s->gb)) |
1012 return 1 - (get_bits1(&s->gb) << 1); | |
0 | 1013 else |
1014 return 0; | |
1015 } | |
1016 | |
54 | 1017 static inline int get_qscale(MpegEncContext *s) |
1018 { | |
1253
5642ebadf1b5
small optimize mpeg12.c/get_qscale patch by (BERO <bero at geocities dot co dot jp>) and the return idea by arpi
michaelni
parents:
1220
diff
changeset
|
1019 int qscale = get_bits(&s->gb, 5); |
1728 | 1020 if (s->q_scale_type) { |
1021 return non_linear_qscale[qscale]; | |
1022 } else { | |
1023 return qscale << 1; | |
54 | 1024 } |
1025 } | |
1026 | |
0 | 1027 /* motion type (for mpeg2) */ |
1028 #define MT_FIELD 1 | |
1029 #define MT_FRAME 2 | |
1030 #define MT_16X8 2 | |
1031 #define MT_DMV 3 | |
1032 | |
1033 static int mpeg_decode_mb(MpegEncContext *s, | |
1034 DCTELEM block[6][64]) | |
1035 { | |
751 | 1036 int i, j, k, cbp, val, mb_type, motion_type; |
0 | 1037 |
1038 dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); | |
1039 | |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1040 assert(s->mb_skiped==0); |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1041 |
1160 | 1042 if (s->mb_skip_run-- != 0) { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1043 if(s->pict_type == I_TYPE){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1044 av_log(s->avctx, AV_LOG_ERROR, "skiped MB in I frame at %d %d\n", s->mb_x, s->mb_y); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1045 return -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1046 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1047 |
0 | 1048 /* skip mb */ |
1049 s->mb_intra = 0; | |
1050 for(i=0;i<6;i++) | |
1051 s->block_last_index[i] = -1; | |
1052 s->mv_type = MV_TYPE_16X16; | |
1053 if (s->pict_type == P_TYPE) { | |
1054 /* if P type, zero motion vector is implied */ | |
1055 s->mv_dir = MV_DIR_FORWARD; | |
1056 s->mv[0][0][0] = s->mv[0][0][1] = 0; | |
1057 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; | |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1058 s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1059 s->mb_skiped = 1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1060 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; |
0 | 1061 } else { |
1062 /* if B type, reuse previous vectors and directions */ | |
1063 s->mv[0][0][0] = s->last_mv[0][0][0]; | |
1064 s->mv[0][0][1] = s->last_mv[0][0][1]; | |
1065 s->mv[1][0][0] = s->last_mv[1][0][0]; | |
1066 s->mv[1][0][1] = s->last_mv[1][0][1]; | |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1067 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1068 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1069 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1] | MB_TYPE_SKIP; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1070 // assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8)); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1071 |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1072 if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0) |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
947
diff
changeset
|
1073 s->mb_skiped = 1; |
0 | 1074 } |
930 | 1075 |
0 | 1076 return 0; |
1077 } | |
1078 | |
1079 switch(s->pict_type) { | |
1080 default: | |
1081 case I_TYPE: | |
21 | 1082 if (get_bits1(&s->gb) == 0) { |
1376 | 1083 if (get_bits1(&s->gb) == 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1084 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 1085 return -1; |
1376 | 1086 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1087 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; |
0 | 1088 } else { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1089 mb_type = MB_TYPE_INTRA; |
0 | 1090 } |
1091 break; | |
1092 case P_TYPE: | |
545 | 1093 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); |
568 | 1094 if (mb_type < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1095 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 1096 return -1; |
568 | 1097 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1098 mb_type = ptype2mb_type[ mb_type ]; |
0 | 1099 break; |
1100 case B_TYPE: | |
545 | 1101 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); |
568 | 1102 if (mb_type < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1103 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 1104 return -1; |
568 | 1105 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1106 mb_type = btype2mb_type[ mb_type ]; |
0 | 1107 break; |
1108 } | |
1109 dprintf("mb_type=%x\n", mb_type); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1110 // motion_type = 0; /* avoid warning */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1111 if (IS_INTRA(mb_type)) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1112 /* compute dct type */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1113 if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1114 !s->frame_pred_frame_dct) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1115 s->interlaced_dct = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1116 } |
0 | 1117 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1118 if (IS_QUANT(mb_type)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1119 s->qscale = get_qscale(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1120 |
0 | 1121 if (s->concealment_motion_vectors) { |
1122 /* just parse them */ | |
1123 if (s->picture_structure != PICT_FRAME) | |
21 | 1124 skip_bits1(&s->gb); /* field select */ |
1323 | 1125 |
1126 s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] = | |
1127 mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]); | |
1128 s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] = | |
1129 mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]); | |
1130 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1131 skip_bits1(&s->gb); /* marker */ |
1323 | 1132 }else |
1133 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ | |
0 | 1134 s->mb_intra = 1; |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1135 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1136 //one 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1137 if(s->avctx->xvmc_acceleration > 1){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1138 XVMC_pack_pblocks(s,-1);//inter are always full blocks |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1139 if(s->swap_uv){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1140 exchange_uv(s); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1141 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1142 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1143 #endif |
0 | 1144 |
1421 | 1145 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
0 | 1146 for(i=0;i<6;i++) { |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1147 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) |
711 | 1148 return -1; |
0 | 1149 } |
1150 } else { | |
1151 for(i=0;i<6;i++) { | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1152 if (mpeg1_decode_block_intra(s, s->pblocks[i], i) < 0) |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1153 return -1; |
0 | 1154 } |
1155 } | |
1156 } else { | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1157 if (mb_type & MB_TYPE_ZERO_MV){ |
1655 | 1158 assert(mb_type & MB_TYPE_CBP); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1159 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1160 /* compute dct type */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1161 if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1162 !s->frame_pred_frame_dct) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1163 s->interlaced_dct = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1164 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1165 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1166 if (IS_QUANT(mb_type)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1167 s->qscale = get_qscale(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1168 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1169 s->mv_dir = MV_DIR_FORWARD; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1170 s->mv_type = MV_TYPE_16X16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1171 s->last_mv[0][0][0] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1172 s->last_mv[0][0][1] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1173 s->last_mv[0][1][0] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1174 s->last_mv[0][1][1] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1175 s->mv[0][0][0] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1176 s->mv[0][0][1] = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1177 }else{ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1178 assert(mb_type & MB_TYPE_L0L1); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1179 //FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1180 /* get additionnal motion vector type */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1181 if (s->frame_pred_frame_dct) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1182 motion_type = MT_FRAME; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1183 else{ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1184 motion_type = get_bits(&s->gb, 2); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1185 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1186 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1187 /* compute dct type */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1188 if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? |
1655 | 1189 !s->frame_pred_frame_dct && HAS_CBP(mb_type)) { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1190 s->interlaced_dct = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1191 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1192 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1193 if (IS_QUANT(mb_type)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1194 s->qscale = get_qscale(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1195 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1196 /* motion vectors */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1197 s->mv_dir = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1198 for(i=0;i<2;i++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1199 if (USES_LIST(mb_type, i)) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1200 s->mv_dir |= (MV_DIR_FORWARD >> i); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1201 dprintf("motion_type=%d\n", motion_type); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1202 switch(motion_type) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1203 case MT_FRAME: /* or MT_16X8 */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1204 if (s->picture_structure == PICT_FRAME) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1205 /* MT_FRAME */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1206 mb_type |= MB_TYPE_16x16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1207 s->mv_type = MV_TYPE_16X16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1208 s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] = |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1209 mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1210 s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] = |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1211 mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1212 /* full_pel: only for mpeg1 */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1213 if (s->full_pel[i]){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1214 s->mv[i][0][0] <<= 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1215 s->mv[i][0][1] <<= 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1216 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1217 } else { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1218 /* MT_16X8 */ |
1673 | 1219 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1220 s->mv_type = MV_TYPE_16X8; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1221 for(j=0;j<2;j++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1222 s->field_select[i][j] = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1223 for(k=0;k<2;k++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1224 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1225 s->last_mv[i][j][k]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1226 s->last_mv[i][j][k] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1227 s->mv[i][j][k] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1228 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1229 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1230 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1231 break; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1232 case MT_FIELD: |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1233 s->mv_type = MV_TYPE_FIELD; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1234 if (s->picture_structure == PICT_FRAME) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1235 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1236 for(j=0;j<2;j++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1237 s->field_select[i][j] = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1238 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1239 s->last_mv[i][j][0]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1240 s->last_mv[i][j][0] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1241 s->mv[i][j][0] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1242 dprintf("fmx=%d\n", val); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1243 val = mpeg_decode_motion(s, s->mpeg_f_code[i][1], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1244 s->last_mv[i][j][1] >> 1); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1245 s->last_mv[i][j][1] = val << 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1246 s->mv[i][j][1] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1247 dprintf("fmy=%d\n", val); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1248 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1249 } else { |
1673 | 1250 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1251 s->field_select[i][0] = get_bits1(&s->gb); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1252 for(k=0;k<2;k++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1253 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1254 s->last_mv[i][0][k]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1255 s->last_mv[i][0][k] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1256 s->last_mv[i][1][k] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1257 s->mv[i][0][k] = val; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1258 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1259 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1260 break; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1261 case MT_DMV: |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1262 { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1263 int dmx, dmy, mx, my, m; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1264 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1265 mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1266 s->last_mv[i][0][0]); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1267 s->last_mv[i][0][0] = mx; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1268 s->last_mv[i][1][0] = mx; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1269 dmx = get_dmv(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1270 my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1271 s->last_mv[i][0][1] >> 1); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1272 dmy = get_dmv(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1273 s->mv_type = MV_TYPE_DMV; |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1274 |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1275 |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1276 s->last_mv[i][0][1] = my<<1; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1277 s->last_mv[i][1][1] = my<<1; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1278 |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1279 s->mv[i][0][0] = mx; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1280 s->mv[i][0][1] = my; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1281 s->mv[i][1][0] = mx;//not used |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1282 s->mv[i][1][1] = my;//not used |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1283 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1284 if (s->picture_structure == PICT_FRAME) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1285 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1286 |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1287 //m = 1 + 2 * s->top_field_first; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1288 m = s->top_field_first ? 1 : 3; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1289 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1290 /* top -> top pred */ |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1291 s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1292 s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1293 m = 4 - m; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1294 s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1295 s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1296 } else { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1297 mb_type |= MB_TYPE_16x16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1298 |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1299 s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1300 s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1301 if(s->picture_structure == PICT_TOP_FIELD) |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1302 s->mv[i][2][1]--; |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1303 else |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
1304 s->mv[i][2][1]++; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1305 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1306 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1307 break; |
1673 | 1308 default: |
1309 av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); | |
1310 return -1; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1311 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1312 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1313 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1314 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1315 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1316 s->mb_intra = 0; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1317 |
1655 | 1318 if (HAS_CBP(mb_type)) { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1319 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1320 if (cbp < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1321 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1322 return -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1323 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1324 cbp++; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1325 |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1326 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1327 //on 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1328 if(s->avctx->xvmc_acceleration > 1){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1329 XVMC_pack_pblocks(s,cbp); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1330 if(s->swap_uv){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1331 exchange_uv(s); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1332 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1333 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1334 #endif |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1335 |
1421 | 1336 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1337 for(i=0;i<6;i++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1338 if (cbp & 32) { |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1339 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0) |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1340 return -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1341 } else { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1342 s->block_last_index[i] = -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1343 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1344 cbp+=cbp; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1345 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1346 } else { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1347 for(i=0;i<6;i++) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1348 if (cbp & 32) { |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1349 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0) |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1350 return -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1351 } else { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1352 s->block_last_index[i] = -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1353 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1354 cbp+=cbp; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1355 } |
711 | 1356 } |
1357 }else{ | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1358 for(i=0;i<6;i++) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1359 s->block_last_index[i] = -1; |
0 | 1360 } |
1361 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1362 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1363 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1364 |
0 | 1365 return 0; |
1366 } | |
1367 | |
1368 /* as h263, but only 17 codes */ | |
1369 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) | |
1370 { | |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1371 int code, sign, val, l, shift; |
0 | 1372 |
545 | 1373 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1374 if (code == 0) { |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1375 return pred; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1376 } |
0 | 1377 if (code < 0) { |
1378 return 0xffff; | |
1379 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1380 |
21 | 1381 sign = get_bits1(&s->gb); |
0 | 1382 shift = fcode - 1; |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1383 val = code; |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1384 if (shift) { |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1385 val = (val - 1) << shift; |
0 | 1386 val |= get_bits(&s->gb, shift); |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1387 val++; |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1388 } |
0 | 1389 if (sign) |
1390 val = -val; | |
1391 val += pred; | |
1392 | |
1393 /* modulo decoding */ | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1394 l = 1 << (shift+4); |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
1395 val = ((val + l)&(l*2-1)) - l; |
0 | 1396 return val; |
1397 } | |
1398 | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1399 static inline int decode_dc(GetBitContext *gb, int component) |
0 | 1400 { |
1401 int code, diff; | |
1402 | |
1403 if (component == 0) { | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1404 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2); |
0 | 1405 } else { |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1406 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); |
0 | 1407 } |
568 | 1408 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1409 av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n"); |
0 | 1410 return 0xffff; |
568 | 1411 } |
0 | 1412 if (code == 0) { |
1413 diff = 0; | |
1414 } else { | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1415 diff = get_xbits(gb, code); |
0 | 1416 } |
1417 return diff; | |
1418 } | |
1419 | |
711 | 1420 static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
0 | 1421 DCTELEM *block, |
1422 int n) | |
1423 { | |
1424 int level, dc, diff, i, j, run; | |
711 | 1425 int component; |
0 | 1426 RLTable *rl = &rl_mpeg1; |
1064 | 1427 uint8_t * const scantable= s->intra_scantable.permutated; |
1428 const uint16_t *quant_matrix= s->intra_matrix; | |
711 | 1429 const int qscale= s->qscale; |
0 | 1430 |
711 | 1431 /* DC coef */ |
1432 component = (n <= 3 ? 0 : n - 4 + 1); | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1433 diff = decode_dc(&s->gb, component); |
711 | 1434 if (diff >= 0xffff) |
1435 return -1; | |
1436 dc = s->last_dc[component]; | |
1437 dc += diff; | |
1438 s->last_dc[component] = dc; | |
1439 block[0] = dc<<3; | |
1440 dprintf("dc=%d diff=%d\n", dc, diff); | |
1441 i = 0; | |
1442 { | |
1443 OPEN_READER(re, &s->gb); | |
1444 /* now quantify & encode AC coefs */ | |
1445 for(;;) { | |
1446 UPDATE_CACHE(re, &s->gb); | |
1447 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); | |
1448 | |
1449 if(level == 127){ | |
1450 break; | |
1451 } else if(level != 0) { | |
1452 i += run; | |
1453 j = scantable[i]; | |
1728 | 1454 level= (level*qscale*quant_matrix[j])>>4; |
711 | 1455 level= (level-1)|1; |
1456 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1457 LAST_SKIP_BITS(re, &s->gb, 1); | |
1458 } else { | |
1459 /* escape */ | |
1460 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1461 UPDATE_CACHE(re, &s->gb); | |
1462 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | |
1463 if (level == -128) { | |
1464 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); | |
1465 } else if (level == 0) { | |
1466 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); | |
1467 } | |
1468 i += run; | |
1469 j = scantable[i]; | |
1470 if(level<0){ | |
1471 level= -level; | |
1728 | 1472 level= (level*qscale*quant_matrix[j])>>4; |
711 | 1473 level= (level-1)|1; |
1474 level= -level; | |
1475 }else{ | |
1728 | 1476 level= (level*qscale*quant_matrix[j])>>4; |
711 | 1477 level= (level-1)|1; |
1478 } | |
1479 } | |
1480 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1481 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
711 | 1482 return -1; |
1483 } | |
1484 | |
1485 block[j] = level; | |
1486 } | |
1487 CLOSE_READER(re, &s->gb); | |
1488 } | |
1489 s->block_last_index[n] = i; | |
1490 return 0; | |
1491 } | |
1492 | |
1493 static inline int mpeg1_decode_block_inter(MpegEncContext *s, | |
1494 DCTELEM *block, | |
1495 int n) | |
1496 { | |
1497 int level, i, j, run; | |
1498 RLTable *rl = &rl_mpeg1; | |
1064 | 1499 uint8_t * const scantable= s->intra_scantable.permutated; |
1500 const uint16_t *quant_matrix= s->inter_matrix; | |
711 | 1501 const int qscale= s->qscale; |
1502 | |
1503 { | |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1504 int v; |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1505 OPEN_READER(re, &s->gb); |
711 | 1506 i = -1; |
0 | 1507 /* special case for the first coef. no need to add a second vlc table */ |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1508 UPDATE_CACHE(re, &s->gb); |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1509 v= SHOW_UBITS(re, &s->gb, 2); |
0 | 1510 if (v & 2) { |
714 | 1511 LAST_SKIP_BITS(re, &s->gb, 2); |
1728 | 1512 level= (3*qscale*quant_matrix[0])>>5; |
711 | 1513 level= (level-1)|1; |
1514 if(v&1) | |
1515 level= -level; | |
714 | 1516 block[0] = level; |
711 | 1517 i++; |
0 | 1518 } |
714 | 1519 |
711 | 1520 /* now quantify & encode AC coefs */ |
1521 for(;;) { | |
1522 UPDATE_CACHE(re, &s->gb); | |
1523 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); | |
1524 | |
1525 if(level == 127){ | |
1526 break; | |
1527 } else if(level != 0) { | |
1528 i += run; | |
1529 j = scantable[i]; | |
1728 | 1530 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 1531 level= (level-1)|1; |
1532 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1533 LAST_SKIP_BITS(re, &s->gb, 1); | |
1534 } else { | |
1535 /* escape */ | |
1536 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1537 UPDATE_CACHE(re, &s->gb); | |
1538 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | |
1539 if (level == -128) { | |
1540 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); | |
1541 } else if (level == 0) { | |
1542 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); | |
1543 } | |
1544 i += run; | |
1545 j = scantable[i]; | |
1546 if(level<0){ | |
1547 level= -level; | |
1728 | 1548 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 1549 level= (level-1)|1; |
1550 level= -level; | |
1551 }else{ | |
1728 | 1552 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 1553 level= (level-1)|1; |
1554 } | |
1555 } | |
1556 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1557 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
711 | 1558 return -1; |
1559 } | |
0 | 1560 |
711 | 1561 block[j] = level; |
0 | 1562 } |
711 | 1563 CLOSE_READER(re, &s->gb); |
0 | 1564 } |
711 | 1565 s->block_last_index[n] = i; |
0 | 1566 return 0; |
1567 } | |
1568 | |
1569 /* Also does unquantization here, since I will never support mpeg2 | |
1570 encoding */ | |
714 | 1571 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, |
1572 DCTELEM *block, | |
1573 int n) | |
0 | 1574 { |
1575 int level, i, j, run; | |
1576 RLTable *rl = &rl_mpeg1; | |
1064 | 1577 uint8_t * const scantable= s->intra_scantable.permutated; |
1578 const uint16_t *quant_matrix; | |
714 | 1579 const int qscale= s->qscale; |
0 | 1580 int mismatch; |
1581 | |
1582 mismatch = 1; | |
1583 | |
1584 { | |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1585 int v; |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1586 OPEN_READER(re, &s->gb); |
714 | 1587 i = -1; |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1588 if (n < 4) |
714 | 1589 quant_matrix = s->inter_matrix; |
0 | 1590 else |
714 | 1591 quant_matrix = s->chroma_inter_matrix; |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1592 |
0 | 1593 /* special case for the first coef. no need to add a second vlc table */ |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1594 UPDATE_CACHE(re, &s->gb); |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1595 v= SHOW_UBITS(re, &s->gb, 2); |
0 | 1596 if (v & 2) { |
714 | 1597 LAST_SKIP_BITS(re, &s->gb, 2); |
1598 level= (3*qscale*quant_matrix[0])>>5; | |
1599 if(v&1) | |
1600 level= -level; | |
1601 block[0] = level; | |
1602 mismatch ^= level; | |
1603 i++; | |
1604 } | |
1605 | |
1606 /* now quantify & encode AC coefs */ | |
1607 for(;;) { | |
1608 UPDATE_CACHE(re, &s->gb); | |
1609 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); | |
1610 | |
1611 if(level == 127){ | |
1612 break; | |
1613 } else if(level != 0) { | |
1614 i += run; | |
1615 j = scantable[i]; | |
1616 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | |
1617 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1618 LAST_SKIP_BITS(re, &s->gb, 1); | |
1619 } else { | |
1620 /* escape */ | |
1621 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1622 UPDATE_CACHE(re, &s->gb); | |
1623 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
1624 | |
1625 i += run; | |
1626 j = scantable[i]; | |
1627 if(level<0){ | |
1628 level= ((-level*2+1)*qscale*quant_matrix[j])>>5; | |
1629 level= -level; | |
1630 }else{ | |
1631 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | |
1632 } | |
1633 } | |
1634 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1635 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
714 | 1636 return -1; |
1637 } | |
1638 | |
1639 mismatch ^= level; | |
1640 block[j] = level; | |
0 | 1641 } |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
498
diff
changeset
|
1642 CLOSE_READER(re, &s->gb); |
0 | 1643 } |
1644 block[63] ^= (mismatch & 1); | |
714 | 1645 |
0 | 1646 s->block_last_index[n] = i; |
1647 return 0; | |
1648 } | |
1649 | |
714 | 1650 static inline int mpeg2_decode_block_intra(MpegEncContext *s, |
1651 DCTELEM *block, | |
1652 int n) | |
0 | 1653 { |
1654 int level, dc, diff, i, j, run; | |
714 | 1655 int component; |
0 | 1656 RLTable *rl; |
1064 | 1657 uint8_t * const scantable= s->intra_scantable.permutated; |
1658 const uint16_t *quant_matrix; | |
714 | 1659 const int qscale= s->qscale; |
0 | 1660 int mismatch; |
1661 | |
1662 /* DC coef */ | |
714 | 1663 if (n < 4){ |
1664 quant_matrix = s->intra_matrix; | |
1665 component = 0; | |
1666 }else{ | |
1667 quant_matrix = s->chroma_intra_matrix; | |
1668 component = n - 3; | |
1669 } | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1670 diff = decode_dc(&s->gb, component); |
0 | 1671 if (diff >= 0xffff) |
1672 return -1; | |
1673 dc = s->last_dc[component]; | |
1674 dc += diff; | |
1675 s->last_dc[component] = dc; | |
1676 block[0] = dc << (3 - s->intra_dc_precision); | |
1677 dprintf("dc=%d\n", block[0]); | |
58
0e0a24def67a
fixed last zero mv for field - fixed mismatch handling for intra coefs
glantau
parents:
54
diff
changeset
|
1678 mismatch = block[0] ^ 1; |
714 | 1679 i = 0; |
0 | 1680 if (s->intra_vlc_format) |
1681 rl = &rl_mpeg2; | |
1682 else | |
1683 rl = &rl_mpeg1; | |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1684 |
714 | 1685 { |
1686 OPEN_READER(re, &s->gb); | |
1687 /* now quantify & encode AC coefs */ | |
1688 for(;;) { | |
1689 UPDATE_CACHE(re, &s->gb); | |
1690 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); | |
1691 | |
1692 if(level == 127){ | |
1693 break; | |
1694 } else if(level != 0) { | |
1695 i += run; | |
1696 j = scantable[i]; | |
1697 level= (level*qscale*quant_matrix[j])>>4; | |
1698 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1699 LAST_SKIP_BITS(re, &s->gb, 1); | |
1700 } else { | |
1701 /* escape */ | |
1702 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1703 UPDATE_CACHE(re, &s->gb); | |
1704 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
1705 i += run; | |
1706 j = scantable[i]; | |
1707 if(level<0){ | |
1708 level= (-level*qscale*quant_matrix[j])>>4; | |
1709 level= -level; | |
1710 }else{ | |
1711 level= (level*qscale*quant_matrix[j])>>4; | |
1712 } | |
1713 } | |
1714 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1715 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
714 | 1716 return -1; |
1717 } | |
1718 | |
1719 mismatch^= level; | |
1720 block[j] = level; | |
568 | 1721 } |
714 | 1722 CLOSE_READER(re, &s->gb); |
0 | 1723 } |
714 | 1724 block[63]^= mismatch&1; |
1725 | |
0 | 1726 s->block_last_index[n] = i; |
1727 return 0; | |
1728 } | |
1729 | |
1730 typedef struct Mpeg1Context { | |
1731 MpegEncContext mpeg_enc_ctx; | |
1732 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ | |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
1733 int repeat_field; /* true if we must repeat the field */ |
1546 | 1734 AVPanScan pan_scan; /** some temporary storage for the panscan */ |
0 | 1735 } Mpeg1Context; |
1736 | |
1737 static int mpeg_decode_init(AVCodecContext *avctx) | |
1738 { | |
1739 Mpeg1Context *s = avctx->priv_data; | |
498 | 1740 |
1732
f716b8f47d98
uninitalized variables fix by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1728
diff
changeset
|
1741 s->mpeg_enc_ctx.avctx= avctx; |
558 | 1742 s->mpeg_enc_ctx.flags= avctx->flags; |
498 | 1743 common_init(&s->mpeg_enc_ctx); |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1744 init_vlcs(); |
0 | 1745 |
1746 s->mpeg_enc_ctx_allocated = 0; | |
1747 s->mpeg_enc_ctx.picture_number = 0; | |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
1748 s->repeat_field = 0; |
344 | 1749 s->mpeg_enc_ctx.codec_id= avctx->codec->id; |
0 | 1750 return 0; |
1751 } | |
1752 | |
1753 /* return the 8 bit start code value and update the search | |
1754 state. Return -1 if no start code found */ | |
1211 | 1755 static int find_start_code(uint8_t **pbuf_ptr, uint8_t *buf_end) |
0 | 1756 { |
1064 | 1757 uint8_t *buf_ptr; |
1211 | 1758 unsigned int state=0xFFFFFFFF, v; |
0 | 1759 int val; |
1760 | |
1761 buf_ptr = *pbuf_ptr; | |
1762 while (buf_ptr < buf_end) { | |
1763 v = *buf_ptr++; | |
1764 if (state == 0x000001) { | |
1765 state = ((state << 8) | v) & 0xffffff; | |
1766 val = state; | |
1767 goto found; | |
1768 } | |
1769 state = ((state << 8) | v) & 0xffffff; | |
1770 } | |
1771 val = -1; | |
1772 found: | |
1773 *pbuf_ptr = buf_ptr; | |
1774 return val; | |
1775 } | |
1776 | |
1777 static int mpeg1_decode_picture(AVCodecContext *avctx, | |
1064 | 1778 uint8_t *buf, int buf_size) |
0 | 1779 { |
1780 Mpeg1Context *s1 = avctx->priv_data; | |
1781 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1697 | 1782 int ref, f_code, vbv_delay; |
0 | 1783 |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1021
diff
changeset
|
1784 init_get_bits(&s->gb, buf, buf_size*8); |
0 | 1785 |
1786 ref = get_bits(&s->gb, 10); /* temporal ref */ | |
1787 s->pict_type = get_bits(&s->gb, 3); | |
872 | 1788 |
1697 | 1789 vbv_delay= get_bits(&s->gb, 16); |
0 | 1790 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { |
21 | 1791 s->full_pel[0] = get_bits1(&s->gb); |
0 | 1792 f_code = get_bits(&s->gb, 3); |
1793 if (f_code == 0) | |
1794 return -1; | |
1795 s->mpeg_f_code[0][0] = f_code; | |
1796 s->mpeg_f_code[0][1] = f_code; | |
1797 } | |
1798 if (s->pict_type == B_TYPE) { | |
21 | 1799 s->full_pel[1] = get_bits1(&s->gb); |
0 | 1800 f_code = get_bits(&s->gb, 3); |
1801 if (f_code == 0) | |
1802 return -1; | |
1803 s->mpeg_f_code[1][0] = f_code; | |
1804 s->mpeg_f_code[1][1] = f_code; | |
1805 } | |
903 | 1806 s->current_picture.pict_type= s->pict_type; |
1807 s->current_picture.key_frame= s->pict_type == I_TYPE; | |
911 | 1808 |
1727 | 1809 // if(avctx->debug & FF_DEBUG_PICT_INFO) |
1810 // av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d\n", vbv_delay, ref); | |
1811 | |
0 | 1812 s->y_dc_scale = 8; |
1813 s->c_dc_scale = 8; | |
1814 s->first_slice = 1; | |
1815 return 0; | |
1816 } | |
1817 | |
1818 static void mpeg_decode_sequence_extension(MpegEncContext *s) | |
1819 { | |
1820 int horiz_size_ext, vert_size_ext; | |
1721 | 1821 int bit_rate_ext; |
0 | 1822 int frame_rate_ext_n, frame_rate_ext_d; |
1421 | 1823 int level, profile; |
0 | 1824 |
1421 | 1825 skip_bits(&s->gb, 1); /* profil and level esc*/ |
1826 profile= get_bits(&s->gb, 3); | |
1827 level= get_bits(&s->gb, 4); | |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
1828 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ |
21 | 1829 skip_bits(&s->gb, 2); /* chroma_format */ |
0 | 1830 horiz_size_ext = get_bits(&s->gb, 2); |
1831 vert_size_ext = get_bits(&s->gb, 2); | |
1832 s->width |= (horiz_size_ext << 12); | |
1833 s->height |= (vert_size_ext << 12); | |
1834 bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */ | |
1835 s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400; | |
21 | 1836 skip_bits1(&s->gb); /* marker */ |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
1837 s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10; |
1346 | 1838 |
917 | 1839 s->low_delay = get_bits1(&s->gb); |
1346 | 1840 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; |
1841 | |
0 | 1842 frame_rate_ext_n = get_bits(&s->gb, 2); |
1843 frame_rate_ext_d = get_bits(&s->gb, 5); | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1844 av_reduce( |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1845 &s->avctx->frame_rate, |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1846 &s->avctx->frame_rate_base, |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1847 frame_rate_tab[s->frame_rate_index] * (frame_rate_ext_n+1), |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1848 MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d+1), |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1849 1<<30); |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1850 |
0 | 1851 dprintf("sequence extension\n"); |
1421 | 1852 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; |
401
e20655449d4a
mpeg1/2 identifier - fixed frame rate for some bad mpeg1 streams
glantau
parents:
391
diff
changeset
|
1853 s->avctx->sub_id = 2; /* indicates mpeg2 found */ |
917 | 1854 |
1548 | 1855 if(s->aspect_ratio_info <= 1) |
1856 s->avctx->sample_aspect_ratio= mpeg2_aspect[s->aspect_ratio_info]; | |
1857 else{ | |
1858 s->avctx->sample_aspect_ratio= | |
1859 av_div_q( | |
1860 mpeg2_aspect[s->aspect_ratio_info], | |
1861 (AVRational){s->width, s->height} | |
1862 ); | |
1863 } | |
1421 | 1864 |
1865 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
1866 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n", |
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
1867 profile, level, s->avctx->rc_buffer_size, s->bit_rate); |
0 | 1868 } |
1869 | |
1546 | 1870 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1) |
1871 { | |
1872 MpegEncContext *s= &s1->mpeg_enc_ctx; | |
1873 int color_description, w, h; | |
1874 | |
1875 skip_bits(&s->gb, 3); /* video format */ | |
1876 color_description= get_bits1(&s->gb); | |
1877 if(color_description){ | |
1878 skip_bits(&s->gb, 8); /* color primaries */ | |
1879 skip_bits(&s->gb, 8); /* transfer_characteristics */ | |
1880 skip_bits(&s->gb, 8); /* matrix_coefficients */ | |
1881 } | |
1882 w= get_bits(&s->gb, 14); | |
1883 skip_bits(&s->gb, 1); //marker | |
1884 h= get_bits(&s->gb, 14); | |
1885 skip_bits(&s->gb, 1); //marker | |
1886 | |
1887 s1->pan_scan.width= 16*w; | |
1888 s1->pan_scan.height=16*h; | |
1889 | |
1548 | 1890 if(s->aspect_ratio_info > 1) |
1891 s->avctx->sample_aspect_ratio= | |
1892 av_div_q( | |
1893 mpeg2_aspect[s->aspect_ratio_info], | |
1894 (AVRational){w, h} | |
1895 ); | |
1546 | 1896 |
1897 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1898 av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h); |
1546 | 1899 } |
1900 | |
1901 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) | |
1902 { | |
1903 MpegEncContext *s= &s1->mpeg_enc_ctx; | |
1904 int i; | |
1905 | |
1906 for(i=0; i<1; i++){ //FIXME count | |
1907 s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16); | |
1908 skip_bits(&s->gb, 1); //marker | |
1909 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); | |
1910 skip_bits(&s->gb, 1); //marker | |
1911 } | |
1912 | |
1913 if(s->avctx->debug & FF_DEBUG_PICT_INFO) | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1914 av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n", |
1546 | 1915 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], |
1916 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], | |
1917 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1] | |
1918 ); | |
1919 } | |
1920 | |
0 | 1921 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) |
1922 { | |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1923 int i, v, j; |
0 | 1924 |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1925 dprintf("matrix extension\n"); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1926 |
21 | 1927 if (get_bits1(&s->gb)) { |
0 | 1928 for(i=0;i<64;i++) { |
1929 v = get_bits(&s->gb, 8); | |
1092 | 1930 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1931 s->intra_matrix[j] = v; |
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1932 s->chroma_intra_matrix[j] = v; |
0 | 1933 } |
1934 } | |
21 | 1935 if (get_bits1(&s->gb)) { |
0 | 1936 for(i=0;i<64;i++) { |
1937 v = get_bits(&s->gb, 8); | |
1092 | 1938 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
344 | 1939 s->inter_matrix[j] = v; |
1940 s->chroma_inter_matrix[j] = v; | |
0 | 1941 } |
1942 } | |
21 | 1943 if (get_bits1(&s->gb)) { |
0 | 1944 for(i=0;i<64;i++) { |
1945 v = get_bits(&s->gb, 8); | |
1092 | 1946 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1947 s->chroma_intra_matrix[j] = v; |
0 | 1948 } |
1949 } | |
21 | 1950 if (get_bits1(&s->gb)) { |
0 | 1951 for(i=0;i<64;i++) { |
1952 v = get_bits(&s->gb, 8); | |
1092 | 1953 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
344 | 1954 s->chroma_inter_matrix[j] = v; |
0 | 1955 } |
1956 } | |
1957 } | |
1958 | |
1959 static void mpeg_decode_picture_coding_extension(MpegEncContext *s) | |
1960 { | |
1961 s->full_pel[0] = s->full_pel[1] = 0; | |
1962 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4); | |
1963 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4); | |
1964 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4); | |
1965 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4); | |
1966 s->intra_dc_precision = get_bits(&s->gb, 2); | |
1967 s->picture_structure = get_bits(&s->gb, 2); | |
21 | 1968 s->top_field_first = get_bits1(&s->gb); |
1969 s->frame_pred_frame_dct = get_bits1(&s->gb); | |
1970 s->concealment_motion_vectors = get_bits1(&s->gb); | |
1971 s->q_scale_type = get_bits1(&s->gb); | |
1972 s->intra_vlc_format = get_bits1(&s->gb); | |
1973 s->alternate_scan = get_bits1(&s->gb); | |
1974 s->repeat_first_field = get_bits1(&s->gb); | |
1975 s->chroma_420_type = get_bits1(&s->gb); | |
1976 s->progressive_frame = get_bits1(&s->gb); | |
1708 | 1977 |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1978 if(s->picture_structure == PICT_FRAME) |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1979 s->first_field=0; |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1980 else{ |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1981 s->first_field ^= 1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1982 memset(s->mbskip_table, 0, s->mb_stride*s->mb_height); |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1983 } |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
1984 |
715
8b3ccabfce4a
move scantable init from block-decode to header parser
michaelni
parents:
714
diff
changeset
|
1985 if(s->alternate_scan){ |
1273 | 1986 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); |
1987 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); | |
715
8b3ccabfce4a
move scantable init from block-decode to header parser
michaelni
parents:
714
diff
changeset
|
1988 }else{ |
1273 | 1989 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); |
1990 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); | |
715
8b3ccabfce4a
move scantable init from block-decode to header parser
michaelni
parents:
714
diff
changeset
|
1991 } |
8b3ccabfce4a
move scantable init from block-decode to header parser
michaelni
parents:
714
diff
changeset
|
1992 |
0 | 1993 /* composite display not parsed */ |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
1994 dprintf("intra_dc_precision=%d\n", s->intra_dc_precision); |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1995 dprintf("picture_structure=%d\n", s->picture_structure); |
383
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
1996 dprintf("top field first=%d\n", s->top_field_first); |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
1997 dprintf("repeat first field=%d\n", s->repeat_first_field); |
0 | 1998 dprintf("conceal=%d\n", s->concealment_motion_vectors); |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1999 dprintf("intra_vlc_format=%d\n", s->intra_vlc_format); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2000 dprintf("alternate_scan=%d\n", s->alternate_scan); |
0 | 2001 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2002 dprintf("progressive_frame=%d\n", s->progressive_frame); |
0 | 2003 } |
2004 | |
2005 static void mpeg_decode_extension(AVCodecContext *avctx, | |
1064 | 2006 uint8_t *buf, int buf_size) |
0 | 2007 { |
2008 Mpeg1Context *s1 = avctx->priv_data; | |
2009 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
2010 int ext_type; | |
2011 | |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1021
diff
changeset
|
2012 init_get_bits(&s->gb, buf, buf_size*8); |
0 | 2013 |
2014 ext_type = get_bits(&s->gb, 4); | |
2015 switch(ext_type) { | |
2016 case 0x1: | |
2017 mpeg_decode_sequence_extension(s); | |
2018 break; | |
1546 | 2019 case 0x2: |
2020 mpeg_decode_sequence_display_extension(s1); | |
2021 break; | |
0 | 2022 case 0x3: |
2023 mpeg_decode_quant_matrix_extension(s); | |
2024 break; | |
1546 | 2025 case 0x7: |
2026 mpeg_decode_picture_display_extension(s1); | |
2027 break; | |
0 | 2028 case 0x8: |
2029 mpeg_decode_picture_coding_extension(s); | |
2030 break; | |
2031 } | |
2032 } | |
2033 | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2034 static void exchange_uv(MpegEncContext *s){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2035 short * tmp; |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2036 |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2037 tmp = s->pblocks[4]; |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2038 s->pblocks[4] = s->pblocks[5]; |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2039 s->pblocks[5] = tmp; |
1380 | 2040 } |
2041 | |
826 | 2042 #define DECODE_SLICE_FATAL_ERROR -2 |
2043 #define DECODE_SLICE_ERROR -1 | |
2044 #define DECODE_SLICE_OK 0 | |
2045 | |
2046 /** | |
2047 * decodes a slice. | |
2048 * @return DECODE_SLICE_FATAL_ERROR if a non recoverable error occured<br> | |
2049 * DECODE_SLICE_ERROR if the slice is damaged<br> | |
2050 * DECODE_SLICE_OK if this slice is ok<br> | |
2051 */ | |
0 | 2052 static int mpeg_decode_slice(AVCodecContext *avctx, |
925 | 2053 AVFrame *pict, |
0 | 2054 int start_code, |
1211 | 2055 uint8_t **buf, int buf_size) |
0 | 2056 { |
2057 Mpeg1Context *s1 = avctx->priv_data; | |
2058 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
2059 int ret; | |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
2060 const int field_pic= s->picture_structure != PICT_FRAME; |
0 | 2061 |
1285 | 2062 s->resync_mb_x= s->mb_x = |
2063 s->resync_mb_y= s->mb_y = -1; | |
2064 | |
0 | 2065 start_code = (start_code - 1) & 0xff; |
568 | 2066 if (start_code >= s->mb_height){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2067 av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", start_code, s->mb_height); |
1285 | 2068 return -1; |
568 | 2069 } |
1160 | 2070 |
2071 ff_mpeg1_clean_buffers(s); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2072 s->interlaced_dct = 0; |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
2073 |
0 | 2074 /* start frame decoding */ |
1138 | 2075 if (s->first_slice) { |
2076 if(s->first_field || s->picture_structure==PICT_FRAME){ | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
751
diff
changeset
|
2077 if(MPV_frame_start(s, avctx) < 0) |
826 | 2078 return DECODE_SLICE_FATAL_ERROR; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2079 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2080 ff_er_frame_start(s); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2081 |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2082 /* first check if we must repeat the frame */ |
1409 | 2083 s->current_picture_ptr->repeat_pict = 0; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2084 if (s->repeat_first_field) { |
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2085 if (s->progressive_sequence) { |
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2086 if (s->top_field_first) |
1409 | 2087 s->current_picture_ptr->repeat_pict = 4; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2088 else |
1409 | 2089 s->current_picture_ptr->repeat_pict = 2; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2090 } else if (s->progressive_frame) { |
1409 | 2091 s->current_picture_ptr->repeat_pict = 1; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2092 } |
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
2093 } |
1546 | 2094 |
2095 *s->current_picture_ptr->pan_scan= s1->pan_scan; | |
1138 | 2096 }else{ //second field |
2097 int i; | |
1182
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2098 |
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2099 if(!s->current_picture_ptr){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2100 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n"); |
1182
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2101 return -1; |
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2102 } |
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2103 |
1138 | 2104 for(i=0; i<4; i++){ |
2105 s->current_picture.data[i] = s->current_picture_ptr->data[i]; | |
2106 if(s->picture_structure == PICT_BOTTOM_FIELD){ | |
2107 s->current_picture.data[i] += s->current_picture_ptr->linesize[i]; | |
2108 } | |
2109 } | |
2110 } | |
1381 | 2111 #ifdef HAVE_XVMC |
2112 // MPV_frame_start will call this function too, | |
2113 // but we need to call it on every field | |
2114 if(s->avctx->xvmc_acceleration) | |
2115 XVMC_field_start(s,avctx); | |
2116 #endif | |
2117 }//fi(s->first_slice) | |
0 | 2118 |
1211 | 2119 init_get_bits(&s->gb, *buf, buf_size*8); |
0 | 2120 |
54 | 2121 s->qscale = get_qscale(s); |
1690 | 2122 if (s->first_slice && (s->first_field || s->picture_structure==PICT_FRAME)) { |
2123 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |
1708 | 2124 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n", |
1690 | 2125 s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1], |
2126 s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")), | |
1708 | 2127 s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", |
1690 | 2128 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, |
2129 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); | |
2130 } | |
2131 } | |
2132 | |
2133 s->first_slice = 0; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2134 if(s->qscale == 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2135 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n"); |
1285 | 2136 return -1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2137 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2138 |
0 | 2139 /* extra slice info */ |
21 | 2140 while (get_bits1(&s->gb) != 0) { |
2141 skip_bits(&s->gb, 8); | |
0 | 2142 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2143 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2144 s->mb_x=0; |
0 | 2145 |
716 | 2146 for(;;) { |
2147 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2148 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2149 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); |
1285 | 2150 return -1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2151 } |
716 | 2152 if (code >= 33) { |
2153 if (code == 33) { | |
2154 s->mb_x += 33; | |
2155 } | |
2156 /* otherwise, stuffing, nothing to do */ | |
2157 } else { | |
2158 s->mb_x += code; | |
2159 break; | |
2160 } | |
2161 } | |
1160 | 2162 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2163 s->resync_mb_x= s->mb_x; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2164 s->resync_mb_y= s->mb_y = start_code; |
1160 | 2165 s->mb_skip_run= 0; |
1389 | 2166 ff_init_block_index(s); |
716 | 2167 |
0 | 2168 for(;;) { |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2169 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2170 //one 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2171 if(s->avctx->xvmc_acceleration > 1) |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2172 XVMC_init_block(s);//set s->block |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2173 #endif |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2174 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
844
diff
changeset
|
2175 s->dsp.clear_blocks(s->block[0]); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2176 |
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
7
diff
changeset
|
2177 ret = mpeg_decode_mb(s, s->block); |
1644 | 2178 s->chroma_qscale= s->qscale; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2179 |
0 | 2180 dprintf("ret=%d\n", ret); |
2181 if (ret < 0) | |
2182 return -1; | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2183 |
1692 | 2184 if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs |
2185 const int wrap = field_pic ? 2*s->block_wrap[0] : s->block_wrap[0]; | |
2186 int xy = s->mb_x*2 + 1 + (s->mb_y*2 +1)*wrap; | |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2187 int motion_for_top_x, motion_for_top_y, motion_back_top_x, motion_back_top_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2188 int motion_for_bottom_x, motion_for_bottom_y, motion_back_bottom_x, motion_back_bottom_y; |
1692 | 2189 if(field_pic && !s->first_field) |
2190 xy += wrap/2; | |
2191 | |
1285 | 2192 if (s->mb_intra) { |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2193 motion_for_top_x = motion_for_top_y = motion_back_top_x = motion_back_top_y = |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2194 motion_for_bottom_x = motion_for_bottom_y = motion_back_bottom_x = motion_back_bottom_y = 0; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2195 }else if (s->mv_type == MV_TYPE_16X16){ |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2196 motion_for_top_x = motion_for_bottom_x = s->mv[0][0][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2197 motion_for_top_y = motion_for_bottom_y = s->mv[0][0][1]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2198 motion_back_top_x = motion_back_bottom_x = s->mv[1][0][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2199 motion_back_top_y = motion_back_bottom_y = s->mv[1][0][1]; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2200 } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ { |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2201 motion_for_top_x = s->mv[0][0][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2202 motion_for_top_y = s->mv[0][0][1]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2203 motion_for_bottom_x = s->mv[0][1][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2204 motion_for_bottom_y = s->mv[0][1][1]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2205 motion_back_top_x = s->mv[1][0][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2206 motion_back_top_y = s->mv[1][0][1]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2207 motion_back_bottom_x = s->mv[1][1][0]; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2208 motion_back_bottom_y = s->mv[1][1][1]; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2209 } |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2210 |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2211 s->current_picture.motion_val[0][xy][0] = motion_for_top_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2212 s->current_picture.motion_val[0][xy][1] = motion_for_top_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2213 s->current_picture.motion_val[0][xy + 1][0] = motion_for_top_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2214 s->current_picture.motion_val[0][xy + 1][1] = motion_for_top_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2215 s->current_picture.motion_val[0][xy + wrap][0] = motion_for_bottom_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2216 s->current_picture.motion_val[0][xy + wrap][1] = motion_for_bottom_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2217 s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_for_bottom_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2218 s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_for_bottom_y; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2219 |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2220 if(s->pict_type != B_TYPE){ |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2221 motion_back_top_x = motion_back_top_y = motion_back_bottom_x = motion_back_bottom_y = 0; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2222 } |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2223 |
1691
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2224 s->current_picture.motion_val[1][xy][0] = motion_back_top_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2225 s->current_picture.motion_val[1][xy][1] = motion_back_top_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2226 s->current_picture.motion_val[1][xy + 1][0] = motion_back_top_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2227 s->current_picture.motion_val[1][xy + 1][1] = motion_back_top_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2228 s->current_picture.motion_val[1][xy + wrap][0] = motion_back_bottom_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2229 s->current_picture.motion_val[1][xy + wrap][1] = motion_back_bottom_y; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2230 s->current_picture.motion_val[1][xy + 1 + wrap][0] = motion_back_bottom_x; |
7d8af3b5699a
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1690
diff
changeset
|
2231 s->current_picture.motion_val[1][xy + 1 + wrap][1] = motion_back_bottom_y; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2232 } |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
2233 |
1389 | 2234 s->dest[0] += 16; |
2235 s->dest[1] += 8; | |
2236 s->dest[2] += 8; | |
2237 | |
716 | 2238 MPV_decode_mb(s, s->block); |
1389 | 2239 |
716 | 2240 if (++s->mb_x >= s->mb_width) { |
1380 | 2241 |
1370 | 2242 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
716 | 2243 |
2244 s->mb_x = 0; | |
2245 s->mb_y++; | |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2246 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2247 if(s->mb_y<<field_pic >= s->mb_height){ |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2248 int left= s->gb.size_in_bits - get_bits_count(&s->gb); |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2249 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2250 if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23))) |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2251 || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2252 av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d\n", left); |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2253 return -1; |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2254 }else |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2255 goto eos; |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2256 } |
1389 | 2257 |
2258 ff_init_block_index(s); | |
716 | 2259 } |
2260 | |
2261 /* skip mb handling */ | |
1160 | 2262 if (s->mb_skip_run == -1) { |
716 | 2263 /* read again increment */ |
1160 | 2264 s->mb_skip_run = 0; |
716 | 2265 for(;;) { |
2266 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2267 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2268 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n"); |
1181 | 2269 return -1; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2270 } |
716 | 2271 if (code >= 33) { |
2272 if (code == 33) { | |
1160 | 2273 s->mb_skip_run += 33; |
1181 | 2274 }else if(code == 35){ |
2275 if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2276 av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n"); |
1181 | 2277 return -1; |
2278 } | |
2279 goto eos; /* end of slice */ | |
716 | 2280 } |
2281 /* otherwise, stuffing, nothing to do */ | |
2282 } else { | |
1160 | 2283 s->mb_skip_run += code; |
716 | 2284 break; |
2285 } | |
2286 } | |
2287 } | |
0 | 2288 } |
1285 | 2289 eos: // end of slice |
2290 *buf += get_bits_count(&s->gb)/8 - 1; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2291 //printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y); |
1285 | 2292 return 0; |
2293 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2294 |
1285 | 2295 /** |
2296 * handles slice ends. | |
2297 * @return 1 if it seems to be the last slice of | |
2298 */ | |
2299 static int slice_end(AVCodecContext *avctx, AVFrame *pict) | |
2300 { | |
2301 Mpeg1Context *s1 = avctx->priv_data; | |
2302 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
2303 | |
1402
f662e9c86cf2
* fixing a regression in mpeg encoder (not setting pix_fmt),
romansh
parents:
1389
diff
changeset
|
2304 if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr) |
1311
fc858abf6b10
fixed segfault if sequence header has not been found before slice decoding
bellard
parents:
1289
diff
changeset
|
2305 return 0; |
fc858abf6b10
fixed segfault if sequence header has not been found before slice decoding
bellard
parents:
1289
diff
changeset
|
2306 |
1381 | 2307 #ifdef HAVE_XVMC |
2308 if(s->avctx->xvmc_acceleration) | |
2309 XVMC_field_end(s); | |
2310 #endif | |
0 | 2311 /* end of slice reached */ |
1285 | 2312 if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) { |
0 | 2313 /* end of image */ |
903 | 2314 |
1728 | 2315 s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2; |
1196 | 2316 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2317 ff_er_frame_end(s); |
0 | 2318 |
2319 MPV_frame_end(s); | |
2320 | |
924 | 2321 if (s->pict_type == B_TYPE || s->low_delay) { |
1328 | 2322 *pict= *(AVFrame*)s->current_picture_ptr; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1697
diff
changeset
|
2323 ff_print_debug_info(s, pict); |
0 | 2324 } else { |
903 | 2325 s->picture_number++; |
0 | 2326 /* latency of 1 frame for I and P frames */ |
2327 /* XXX: use another variable than picture_number */ | |
1211 | 2328 if (s->last_picture_ptr != NULL) { |
1328 | 2329 *pict= *(AVFrame*)s->last_picture_ptr; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1697
diff
changeset
|
2330 ff_print_debug_info(s, pict); |
0 | 2331 } |
2332 } | |
1380 | 2333 |
1285 | 2334 return 1; |
0 | 2335 } else { |
1285 | 2336 return 0; |
0 | 2337 } |
2338 } | |
2339 | |
2340 static int mpeg1_decode_sequence(AVCodecContext *avctx, | |
1064 | 2341 uint8_t *buf, int buf_size) |
0 | 2342 { |
2343 Mpeg1Context *s1 = avctx->priv_data; | |
2344 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
2345 int width, height, i, v, j; |
917 | 2346 float aspect; |
401
e20655449d4a
mpeg1/2 identifier - fixed frame rate for some bad mpeg1 streams
glantau
parents:
391
diff
changeset
|
2347 |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1021
diff
changeset
|
2348 init_get_bits(&s->gb, buf, buf_size*8); |
0 | 2349 |
2350 width = get_bits(&s->gb, 12); | |
2351 height = get_bits(&s->gb, 12); | |
917 | 2352 s->aspect_ratio_info= get_bits(&s->gb, 4); |
1674
835964e33ba2
fixed potential problem if aspect_ratio_info == 0 for MPEG stream - fixed aspect ratio problem if CODEC_ID_MPEG2VIDEO is used to decode an MPEG1 stream (which is the recommended codec id for mpeg video)
bellard
parents:
1673
diff
changeset
|
2353 if (s->aspect_ratio_info == 0) |
835964e33ba2
fixed potential problem if aspect_ratio_info == 0 for MPEG stream - fixed aspect ratio problem if CODEC_ID_MPEG2VIDEO is used to decode an MPEG1 stream (which is the recommended codec id for mpeg video)
bellard
parents:
1673
diff
changeset
|
2354 return -1; |
835964e33ba2
fixed potential problem if aspect_ratio_info == 0 for MPEG stream - fixed aspect ratio problem if CODEC_ID_MPEG2VIDEO is used to decode an MPEG1 stream (which is the recommended codec id for mpeg video)
bellard
parents:
1673
diff
changeset
|
2355 aspect= 1.0/mpeg1_aspect[s->aspect_ratio_info]; |
835964e33ba2
fixed potential problem if aspect_ratio_info == 0 for MPEG stream - fixed aspect ratio problem if CODEC_ID_MPEG2VIDEO is used to decode an MPEG1 stream (which is the recommended codec id for mpeg video)
bellard
parents:
1673
diff
changeset
|
2356 avctx->sample_aspect_ratio= av_d2q(aspect, 255); |
917 | 2357 |
0 | 2358 s->frame_rate_index = get_bits(&s->gb, 4); |
2359 if (s->frame_rate_index == 0) | |
2360 return -1; | |
2361 s->bit_rate = get_bits(&s->gb, 18) * 400; | |
21 | 2362 if (get_bits1(&s->gb) == 0) /* marker */ |
0 | 2363 return -1; |
2364 if (width <= 0 || height <= 0 || | |
2365 (width % 2) != 0 || (height % 2) != 0) | |
2366 return -1; | |
2367 if (width != s->width || | |
2368 height != s->height) { | |
2369 /* start new mpeg1 context decoding */ | |
2370 s->out_format = FMT_MPEG1; | |
2371 if (s1->mpeg_enc_ctx_allocated) { | |
2372 MPV_common_end(s); | |
2373 } | |
2374 s->width = width; | |
2375 s->height = height; | |
924 | 2376 avctx->has_b_frames= 1; |
0 | 2377 avctx->width = width; |
2378 avctx->height = height; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2379 av_reduce( |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2380 &avctx->frame_rate, |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2381 &avctx->frame_rate_base, |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2382 frame_rate_tab[s->frame_rate_index], |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2383 MPEG1_FRAME_RATE_BASE, //FIXME store in allready reduced form |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2384 1<<30 |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
2385 ); |
0 | 2386 avctx->bit_rate = s->bit_rate; |
2387 | |
1381 | 2388 //get_format() or set_video(width,height,aspect,pix_fmt); |
2389 //until then pix_fmt may be changed right after codec init | |
2390 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2391 if( avctx->idct_algo == FF_IDCT_AUTO ) |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2392 avctx->idct_algo = FF_IDCT_SIMPLE; |
1381 | 2393 |
0 | 2394 if (MPV_common_init(s) < 0) |
2395 return -1; | |
2396 s1->mpeg_enc_ctx_allocated = 1; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2397 s->swap_uv = 0;//just in case vcr2 and mpeg2 stream have been concatinated |
0 | 2398 } |
2399 | |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2400 s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16; |
21 | 2401 skip_bits(&s->gb, 1); |
0 | 2402 |
2403 /* get matrix */ | |
21 | 2404 if (get_bits1(&s->gb)) { |
0 | 2405 for(i=0;i<64;i++) { |
2406 v = get_bits(&s->gb, 8); | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2407 j = s->intra_scantable.permutated[i]; |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
2408 s->intra_matrix[j] = v; |
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
2409 s->chroma_intra_matrix[j] = v; |
0 | 2410 } |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2411 #ifdef DEBUG |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2412 dprintf("intra matrix present\n"); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2413 for(i=0;i<64;i++) |
710
97377ab86647
forgot zigzag_direct[] behind #ifdef DEBUG (found by Klaas-Pieter Vlieg <vlieg at eurescom dot de>)
michaelni
parents:
706
diff
changeset
|
2414 dprintf(" %d", s->intra_matrix[s->intra_scantable.permutated[i]]); |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2415 printf("\n"); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2416 #endif |
0 | 2417 } else { |
2418 for(i=0;i<64;i++) { | |
1092 | 2419 int j= s->dsp.idct_permutation[i]; |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
520
diff
changeset
|
2420 v = ff_mpeg1_default_intra_matrix[i]; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2421 s->intra_matrix[j] = v; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2422 s->chroma_intra_matrix[j] = v; |
0 | 2423 } |
2424 } | |
21 | 2425 if (get_bits1(&s->gb)) { |
0 | 2426 for(i=0;i<64;i++) { |
2427 v = get_bits(&s->gb, 8); | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2428 j = s->intra_scantable.permutated[i]; |
344 | 2429 s->inter_matrix[j] = v; |
2430 s->chroma_inter_matrix[j] = v; | |
0 | 2431 } |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2432 #ifdef DEBUG |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2433 dprintf("non intra matrix present\n"); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2434 for(i=0;i<64;i++) |
710
97377ab86647
forgot zigzag_direct[] behind #ifdef DEBUG (found by Klaas-Pieter Vlieg <vlieg at eurescom dot de>)
michaelni
parents:
706
diff
changeset
|
2435 dprintf(" %d", s->inter_matrix[s->intra_scantable.permutated[i]]); |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2436 printf("\n"); |
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2437 #endif |
0 | 2438 } else { |
2439 for(i=0;i<64;i++) { | |
1092 | 2440 int j= s->dsp.idct_permutation[i]; |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
520
diff
changeset
|
2441 v = ff_mpeg1_default_non_intra_matrix[i]; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2442 s->inter_matrix[j] = v; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2443 s->chroma_inter_matrix[j] = v; |
0 | 2444 } |
2445 } | |
2446 | |
2447 /* we set mpeg2 parameters so that it emulates mpeg1 */ | |
2448 s->progressive_sequence = 1; | |
2449 s->progressive_frame = 1; | |
2450 s->picture_structure = PICT_FRAME; | |
2451 s->frame_pred_frame_dct = 1; | |
1421 | 2452 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO; |
401
e20655449d4a
mpeg1/2 identifier - fixed frame rate for some bad mpeg1 streams
glantau
parents:
391
diff
changeset
|
2453 avctx->sub_id = 1; /* indicates mpeg1 */ |
1672 | 2454 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2455 |
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2456 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2457 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n", |
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2458 s->avctx->rc_buffer_size, s->bit_rate); |
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2459 |
0 | 2460 return 0; |
2461 } | |
2462 | |
1376 | 2463 static int vcr2_init_sequence(AVCodecContext *avctx) |
2464 { | |
2465 Mpeg1Context *s1 = avctx->priv_data; | |
2466 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1377 | 2467 int i, v; |
1376 | 2468 |
2469 /* start new mpeg1 context decoding */ | |
2470 s->out_format = FMT_MPEG1; | |
2471 if (s1->mpeg_enc_ctx_allocated) { | |
2472 MPV_common_end(s); | |
2473 } | |
2474 s->width = avctx->width; | |
2475 s->height = avctx->height; | |
2476 avctx->has_b_frames= 0; //true? | |
1380 | 2477 s->low_delay= 1; |
1381 | 2478 |
2479 //get_format() or set_video(width,height,aspect,pix_fmt); | |
2480 //until then pix_fmt may be changed right after codec init | |
2481 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2482 if( avctx->idct_algo == FF_IDCT_AUTO ) |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2483 avctx->idct_algo = FF_IDCT_SIMPLE; |
1376 | 2484 |
2485 if (MPV_common_init(s) < 0) | |
2486 return -1; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2487 exchange_uv(s);//common init reset pblocks, so we swap them here |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2488 s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB |
1376 | 2489 s1->mpeg_enc_ctx_allocated = 1; |
2490 | |
2491 for(i=0;i<64;i++) { | |
2492 int j= s->dsp.idct_permutation[i]; | |
2493 v = ff_mpeg1_default_intra_matrix[i]; | |
2494 s->intra_matrix[j] = v; | |
2495 s->chroma_intra_matrix[j] = v; | |
2496 | |
2497 v = ff_mpeg1_default_non_intra_matrix[i]; | |
2498 s->inter_matrix[j] = v; | |
2499 s->chroma_inter_matrix[j] = v; | |
2500 } | |
2501 | |
2502 s->progressive_sequence = 1; | |
2503 s->progressive_frame = 1; | |
2504 s->picture_structure = PICT_FRAME; | |
2505 s->frame_pred_frame_dct = 1; | |
1421 | 2506 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; |
1377 | 2507 avctx->sub_id = 2; /* indicates mpeg2 */ |
1376 | 2508 return 0; |
2509 } | |
2510 | |
2511 | |
1084 | 2512 static void mpeg_decode_user_data(AVCodecContext *avctx, |
2513 const uint8_t *buf, int buf_size) | |
2514 { | |
2515 const uint8_t *p; | |
2516 int len, flags; | |
2517 p = buf; | |
2518 len = buf_size; | |
2519 | |
2520 /* we parse the DTG active format information */ | |
2521 if (len >= 5 && | |
2522 p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') { | |
2523 flags = p[4]; | |
2524 p += 5; | |
2525 len -= 5; | |
2526 if (flags & 0x80) { | |
2527 /* skip event id */ | |
2528 if (len < 2) | |
2529 return; | |
2530 p += 2; | |
2531 len -= 2; | |
2532 } | |
2533 if (flags & 0x40) { | |
2534 if (len < 1) | |
2535 return; | |
2536 avctx->dtg_active_format = p[0] & 0x0f; | |
2537 } | |
2538 } | |
2539 } | |
2540 | |
1211 | 2541 /** |
2542 * finds the end of the current frame in the bitstream. | |
2543 * @return the position of the first byte of the next frame, or -1 | |
2544 */ | |
2545 static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){ | |
2546 ParseContext *pc= &s->parse_context; | |
2547 int i; | |
2548 uint32_t state; | |
2549 | |
2550 state= pc->state; | |
2551 | |
2552 i=0; | |
2553 if(!pc->frame_start_found){ | |
2554 for(i=0; i<buf_size; i++){ | |
2555 state= (state<<8) | buf[i]; | |
2556 if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ | |
2557 i++; | |
2558 pc->frame_start_found=1; | |
2559 break; | |
2560 } | |
2561 } | |
2562 } | |
2563 | |
2564 if(pc->frame_start_found){ | |
2565 for(; i<buf_size; i++){ | |
2566 state= (state<<8) | buf[i]; | |
2567 if((state&0xFFFFFF00) == 0x100){ | |
2568 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ | |
2569 pc->frame_start_found=0; | |
2570 pc->state=-1; | |
2571 return i-3; | |
2572 } | |
2573 } | |
2574 } | |
2575 } | |
2576 pc->state= state; | |
1218
358bbc952e27
10l (returning negative number of consumed bytes if the first startcode of a frame was split between 2 buffers)
michaelni
parents:
1211
diff
changeset
|
2577 return END_NOT_FOUND; |
1211 | 2578 } |
2579 | |
0 | 2580 /* handle buffering and image synchronisation */ |
2581 static int mpeg_decode_frame(AVCodecContext *avctx, | |
2582 void *data, int *data_size, | |
1064 | 2583 uint8_t *buf, int buf_size) |
0 | 2584 { |
2585 Mpeg1Context *s = avctx->priv_data; | |
1211 | 2586 uint8_t *buf_end, *buf_ptr; |
2587 int ret, start_code, input_size; | |
925 | 2588 AVFrame *picture = data; |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2589 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
0 | 2590 dprintf("fill_buffer\n"); |
2591 | |
2592 *data_size = 0; | |
344 | 2593 |
0 | 2594 /* special case for last picture */ |
1372 | 2595 if (buf_size == 0 && s2->low_delay==0 && s2->next_picture_ptr) { |
2596 *picture= *(AVFrame*)s2->next_picture_ptr; | |
2597 s2->next_picture_ptr= NULL; | |
903 | 2598 |
1372 | 2599 *data_size = sizeof(AVFrame); |
0 | 2600 return 0; |
2601 } | |
2602 | |
1211 | 2603 if(s2->flags&CODEC_FLAG_TRUNCATED){ |
1218
358bbc952e27
10l (returning negative number of consumed bytes if the first startcode of a frame was split between 2 buffers)
michaelni
parents:
1211
diff
changeset
|
2604 int next= mpeg1_find_frame_end(s2, buf, buf_size); |
1211 | 2605 |
2606 if( ff_combine_frame(s2, next, &buf, &buf_size) < 0 ) | |
2607 return buf_size; | |
2608 } | |
2609 | |
0 | 2610 buf_ptr = buf; |
2611 buf_end = buf + buf_size; | |
383
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2612 |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2613 #if 0 |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2614 if (s->repeat_field % 2 == 1) { |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2615 s->repeat_field++; |
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2616 //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number, |
383
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2617 // s2->picture_number, s->repeat_field); |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2618 if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) { |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2619 *data_size = sizeof(AVPicture); |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2620 goto the_end; |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2621 } |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2622 } |
383
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2623 #endif |
1376 | 2624 |
2625 if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2")) | |
2626 vcr2_init_sequence(avctx); | |
2627 | |
1211 | 2628 for(;;) { |
0 | 2629 /* find start next code */ |
1211 | 2630 start_code = find_start_code(&buf_ptr, buf_end); |
1220 | 2631 if (start_code < 0){ |
1484 | 2632 if(s2->pict_type != B_TYPE || avctx->hurry_up==0){ |
2633 if (slice_end(avctx, picture)) { | |
1672 | 2634 if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice |
1484 | 2635 *data_size = sizeof(AVPicture); |
2636 } | |
1285 | 2637 } |
1220 | 2638 return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); |
0 | 2639 } |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2640 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2641 input_size = buf_end - buf_ptr; |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2642 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2643 if(avctx->debug & FF_DEBUG_STARTCODE){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
2644 av_log(avctx, AV_LOG_DEBUG, "%3X at %d left %d\n", start_code, buf_ptr-buf, input_size); |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2645 } |
1211 | 2646 |
0 | 2647 /* prepare data for next start code */ |
2648 switch(start_code) { | |
2649 case SEQ_START_CODE: | |
1211 | 2650 mpeg1_decode_sequence(avctx, buf_ptr, |
0 | 2651 input_size); |
2652 break; | |
2653 | |
2654 case PICTURE_START_CODE: | |
2655 /* we have a complete image : we try to decompress it */ | |
2656 mpeg1_decode_picture(avctx, | |
1211 | 2657 buf_ptr, input_size); |
0 | 2658 break; |
2659 case EXT_START_CODE: | |
2660 mpeg_decode_extension(avctx, | |
1211 | 2661 buf_ptr, input_size); |
0 | 2662 break; |
1084 | 2663 case USER_START_CODE: |
2664 mpeg_decode_user_data(avctx, | |
1211 | 2665 buf_ptr, input_size); |
1084 | 2666 break; |
1348 | 2667 case GOP_START_CODE: |
2668 s2->first_field=0; | |
2669 break; | |
0 | 2670 default: |
2671 if (start_code >= SLICE_MIN_START_CODE && | |
911 | 2672 start_code <= SLICE_MAX_START_CODE) { |
917 | 2673 |
2674 /* skip b frames if we dont have reference frames */ | |
1138 | 2675 if(s2->last_picture_ptr==NULL && s2->pict_type==B_TYPE) break; |
917 | 2676 /* skip b frames if we are in a hurry */ |
2677 if(avctx->hurry_up && s2->pict_type==B_TYPE) break; | |
2678 /* skip everything if we are in a hurry>=5 */ | |
2679 if(avctx->hurry_up>=5) break; | |
1211 | 2680 |
1182
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2681 if (!s->mpeg_enc_ctx_allocated) break; |
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
2682 |
0 | 2683 ret = mpeg_decode_slice(avctx, picture, |
1211 | 2684 start_code, &buf_ptr, input_size); |
1285 | 2685 emms_c(); |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1092
diff
changeset
|
2686 |
1285 | 2687 if(ret < 0){ |
2688 if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0) | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
2689 ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR); |
1285 | 2690 if(ret==DECODE_SLICE_FATAL_ERROR) return -1; |
2691 }else{ | |
2692 ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END); | |
0 | 2693 } |
2694 } | |
2695 break; | |
2696 } | |
2697 } | |
2698 } | |
2699 | |
2700 static int mpeg_decode_end(AVCodecContext *avctx) | |
2701 { | |
2702 Mpeg1Context *s = avctx->priv_data; | |
2703 | |
2704 if (s->mpeg_enc_ctx_allocated) | |
2705 MPV_common_end(&s->mpeg_enc_ctx); | |
2706 return 0; | |
2707 } | |
2708 | |
1423 | 2709 AVCodec mpeg1video_decoder = { |
2710 "mpeg1video", | |
0 | 2711 CODEC_TYPE_VIDEO, |
2712 CODEC_ID_MPEG1VIDEO, | |
2713 sizeof(Mpeg1Context), | |
2714 mpeg_decode_init, | |
2715 NULL, | |
2716 mpeg_decode_end, | |
2717 mpeg_decode_frame, | |
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
826
diff
changeset
|
2718 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, |
1368 | 2719 .flush= ff_mpeg_flush, |
0 | 2720 }; |
1381 | 2721 |
1423 | 2722 AVCodec mpeg2video_decoder = { |
2723 "mpeg2video", | |
2724 CODEC_TYPE_VIDEO, | |
2725 CODEC_ID_MPEG2VIDEO, | |
2726 sizeof(Mpeg1Context), | |
2727 mpeg_decode_init, | |
2728 NULL, | |
2729 mpeg_decode_end, | |
2730 mpeg_decode_frame, | |
2731 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, | |
2732 .flush= ff_mpeg_flush, | |
2733 }; | |
2734 | |
1615 | 2735 //legacy decoder |
2736 AVCodec mpegvideo_decoder = { | |
2737 "mpegvideo", | |
2738 CODEC_TYPE_VIDEO, | |
2739 CODEC_ID_MPEG2VIDEO, | |
2740 sizeof(Mpeg1Context), | |
2741 mpeg_decode_init, | |
2742 NULL, | |
2743 mpeg_decode_end, | |
2744 mpeg_decode_frame, | |
2745 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, | |
2746 .flush= ff_mpeg_flush, | |
2747 }; | |
2748 | |
1381 | 2749 #ifdef HAVE_XVMC |
2750 static int mpeg_mc_decode_init(AVCodecContext *avctx){ | |
2751 Mpeg1Context *s; | |
2752 | |
2753 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) | |
2754 return -1; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2755 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){ |
1381 | 2756 dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n"); |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2757 } |
1381 | 2758 mpeg_decode_init(avctx); |
2759 s = avctx->priv_data; | |
2760 | |
2761 avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2762 avctx->xvmc_acceleration = 2;//2 - the blocks are packed! |
1381 | 2763 |
2764 return 0; | |
2765 } | |
2766 | |
2767 AVCodec mpeg_xvmc_decoder = { | |
2768 "mpegvideo_xvmc", | |
2769 CODEC_TYPE_VIDEO, | |
2770 CODEC_ID_MPEG2VIDEO_XVMC, | |
2771 sizeof(Mpeg1Context), | |
2772 mpeg_mc_decode_init, | |
2773 NULL, | |
2774 mpeg_decode_end, | |
2775 mpeg_decode_frame, | |
2776 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED, | |
2777 }; | |
2778 | |
2779 #endif | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
2780 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
2781 /* this is ugly i know, but the alternative is too make |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
2782 hundreds of vars global and prefix them with ff_mpeg1_ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
2783 which is far uglier. */ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
2784 #include "mdec.c" |