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