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