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