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