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