Mercurial > libavcodec.hg
annotate mpeg12.c @ 6938:5096176df88c libavcodec
Remove constant argument.
author | michael |
---|---|
date | Fri, 30 May 2008 20:06:08 +0000 |
parents | 966b86c01ade |
children | 213852a36370 |
rev | line source |
---|---|
0 | 1 /* |
5208 | 2 * MPEG1/2 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 | |
5208 | 25 * MPEG1/2 decoder |
1106 | 26 */ |
2967 | 27 |
76 | 28 //#define DEBUG |
0 | 29 #include "avcodec.h" |
30 #include "dsputil.h" | |
31 #include "mpegvideo.h" | |
32 | |
5208 | 33 #include "mpeg12.h" |
0 | 34 #include "mpeg12data.h" |
5208 | 35 #include "mpeg12decdata.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
|
36 #include "bytestream.h" |
0 | 37 |
1708 | 38 //#undef NDEBUG |
39 //#include <assert.h> | |
40 | |
694 | 41 |
552 | 42 #define DC_VLC_BITS 9 |
43 #define MV_VLC_BITS 9 | |
44 #define MBINCR_VLC_BITS 9 | |
45 #define MB_PAT_VLC_BITS 9 | |
46 #define MB_PTYPE_VLC_BITS 6 | |
47 #define MB_BTYPE_VLC_BITS 6 | |
48 #define TEX_VLC_BITS 9 | |
49 | |
2967 | 50 static inline int mpeg1_decode_block_inter(MpegEncContext *s, |
51 DCTELEM *block, | |
711 | 52 int n); |
2967 | 53 static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
54 DCTELEM *block, | |
0 | 55 int n); |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
56 static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n); |
2967 | 57 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, |
58 DCTELEM *block, | |
0 | 59 int n); |
2967 | 60 static inline int mpeg2_decode_block_intra(MpegEncContext *s, |
61 DCTELEM *block, | |
0 | 62 int n); |
2201 | 63 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n); |
2622 | 64 static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n); |
0 | 65 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); |
1620 | 66 static void exchange_uv(MpegEncContext *s); |
0 | 67 |
1381 | 68 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); |
69 extern int XVMC_field_end(MpegEncContext *s); | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
70 extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp); |
1620 | 71 extern void XVMC_init_block(MpegEncContext *s);//set s->block |
1381 | 72 |
6788 | 73 static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,PIX_FMT_NONE}; |
74 static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,PIX_FMT_NONE}; | |
75 static const enum PixelFormat pixfmt_yuv_444[]= {PIX_FMT_YUV444P,PIX_FMT_NONE}; | |
4180 | 76 static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = { |
1821 | 77 PIX_FMT_XVMC_MPEG2_IDCT, |
78 PIX_FMT_XVMC_MPEG2_MC, | |
6788 | 79 PIX_FMT_NONE}; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
277
diff
changeset
|
80 |
5210 | 81 uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; |
4668 | 82 |
6938 | 83 static void init_2d_vlc_rl(RLTable *rl) |
552 | 84 { |
620
a5aa53b6e648
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michaelni
parents:
617
diff
changeset
|
85 int i; |
2967 | 86 |
87 init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2, | |
552 | 88 &rl->table_vlc[0][1], 4, 2, |
6938 | 89 &rl->table_vlc[0][0], 4, 2, 1); |
552 | 90 |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2302
diff
changeset
|
91 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
|
92 |
552 | 93 for(i=0; i<rl->vlc.table_size; i++){ |
94 int code= rl->vlc.table[i][0]; | |
95 int len = rl->vlc.table[i][1]; | |
96 int level, run; | |
2967 | 97 |
552 | 98 if(len==0){ // illegal code |
99 run= 65; | |
100 level= MAX_LEVEL; | |
101 }else if(len<0){ //more bits needed | |
102 run= 0; | |
103 level= code; | |
104 }else{ | |
105 if(code==rl->n){ //esc | |
106 run= 65; | |
107 level= 0; | |
108 }else if(code==rl->n+1){ //eob | |
711 | 109 run= 0; |
110 level= 127; | |
552 | 111 }else{ |
112 run= rl->table_run [code] + 1; | |
113 level= rl->table_level[code]; | |
114 } | |
115 } | |
116 rl->rl_vlc[0][i].len= len; | |
117 rl->rl_vlc[0][i].level= level; | |
118 rl->rl_vlc[0][i].run= run; | |
119 } | |
120 } | |
121 | |
5210 | 122 void ff_mpeg12_common_init(MpegEncContext *s) |
498 | 123 { |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
124 |
498 | 125 s->y_dc_scale_table= |
1992 | 126 s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision]; |
1903 | 127 |
498 | 128 } |
129 | |
1325 | 130 void ff_mpeg1_clean_buffers(MpegEncContext *s){ |
131 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); | |
132 s->last_dc[1] = s->last_dc[0]; | |
133 s->last_dc[2] = s->last_dc[0]; | |
134 memset(s->last_mv, 0, sizeof(s->last_mv)); | |
135 } | |
136 | |
0 | 137 |
138 /******************************************/ | |
139 /* decoding */ | |
140 | |
141 static VLC dc_lum_vlc; | |
142 static VLC dc_chroma_vlc; | |
143 static VLC mv_vlc; | |
144 static VLC mbincr_vlc; | |
145 static VLC mb_ptype_vlc; | |
146 static VLC mb_btype_vlc; | |
147 static VLC mb_pat_vlc; | |
148 | |
1904 | 149 static void init_vlcs(void) |
0 | 150 { |
151 static int done = 0; | |
152 | |
153 if (!done) { | |
494 | 154 done = 1; |
0 | 155 |
6937 | 156 INIT_VLC_STATIC(&dc_lum_vlc, DC_VLC_BITS, 12, |
5210 | 157 ff_mpeg12_vlc_dc_lum_bits, 1, 1, |
6937 | 158 ff_mpeg12_vlc_dc_lum_code, 2, 2, 512); |
159 INIT_VLC_STATIC(&dc_chroma_vlc, DC_VLC_BITS, 12, | |
5210 | 160 ff_mpeg12_vlc_dc_chroma_bits, 1, 1, |
6937 | 161 ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514); |
162 INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17, | |
5210 | 163 &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1, |
6937 | 164 &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518); |
165 INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36, | |
5210 | 166 &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1, |
6937 | 167 &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538); |
168 INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64, | |
5210 | 169 &ff_mpeg12_mbPatTable[0][1], 2, 1, |
6937 | 170 &ff_mpeg12_mbPatTable[0][0], 2, 1, 512); |
2967 | 171 |
6937 | 172 INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7, |
0 | 173 &table_mb_ptype[0][1], 2, 1, |
6937 | 174 &table_mb_ptype[0][0], 2, 1, 64); |
175 INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11, | |
0 | 176 &table_mb_btype[0][1], 2, 1, |
6937 | 177 &table_mb_btype[0][0], 2, 1, 64); |
5210 | 178 init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); |
179 init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); | |
552 | 180 |
6938 | 181 init_2d_vlc_rl(&ff_rl_mpeg1); |
182 init_2d_vlc_rl(&ff_rl_mpeg2); | |
0 | 183 } |
184 } | |
185 | |
186 static inline int get_dmv(MpegEncContext *s) | |
187 { | |
2967 | 188 if(get_bits1(&s->gb)) |
21 | 189 return 1 - (get_bits1(&s->gb) << 1); |
0 | 190 else |
191 return 0; | |
192 } | |
193 | |
54 | 194 static inline int get_qscale(MpegEncContext *s) |
195 { | |
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
|
196 int qscale = get_bits(&s->gb, 5); |
1728 | 197 if (s->q_scale_type) { |
198 return non_linear_qscale[qscale]; | |
199 } else { | |
200 return qscale << 1; | |
54 | 201 } |
202 } | |
203 | |
0 | 204 /* motion type (for mpeg2) */ |
205 #define MT_FIELD 1 | |
206 #define MT_FRAME 2 | |
207 #define MT_16X8 2 | |
208 #define MT_DMV 3 | |
209 | |
210 static int mpeg_decode_mb(MpegEncContext *s, | |
1848
c72589baee53
initial chroma_format changes,xvmc tweaks and codec_cap
iive
parents:
1841
diff
changeset
|
211 DCTELEM block[12][64]) |
0 | 212 { |
751 | 213 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
|
214 const int mb_block_count = 4 + (1<< s->chroma_format); |
2076 | 215 |
4652 | 216 dprintf(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); |
0 | 217 |
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
|
218 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
|
219 |
1160 | 220 if (s->mb_skip_run-- != 0) { |
6481 | 221 if (s->pict_type == FF_P_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
|
222 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
|
223 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; |
0 | 224 } else { |
2575 | 225 int mb_type; |
2967 | 226 |
2575 | 227 if(s->mb_x) |
228 mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]; | |
229 else | |
2967 | 230 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 | 231 if(IS_INTRA(mb_type)) |
232 return -1; | |
2967 | 233 |
234 s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= | |
2575 | 235 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
|
236 // 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
|
237 |
2967 | 238 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
|
239 s->mb_skipped = 1; |
0 | 240 } |
930 | 241 |
0 | 242 return 0; |
243 } | |
244 | |
245 switch(s->pict_type) { | |
246 default: | |
6481 | 247 case FF_I_TYPE: |
21 | 248 if (get_bits1(&s->gb) == 0) { |
1376 | 249 if (get_bits1(&s->gb) == 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
250 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 251 return -1; |
1376 | 252 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
253 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; |
0 | 254 } 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
|
255 mb_type = MB_TYPE_INTRA; |
0 | 256 } |
257 break; | |
6481 | 258 case FF_P_TYPE: |
545 | 259 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); |
568 | 260 if (mb_type < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
261 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 262 return -1; |
568 | 263 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
264 mb_type = ptype2mb_type[ mb_type ]; |
0 | 265 break; |
6481 | 266 case FF_B_TYPE: |
545 | 267 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); |
568 | 268 if (mb_type < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
269 av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); |
0 | 270 return -1; |
568 | 271 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
272 mb_type = btype2mb_type[ mb_type ]; |
0 | 273 break; |
274 } | |
4652 | 275 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
|
276 // 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
|
277 if (IS_INTRA(mb_type)) { |
2624 | 278 s->dsp.clear_blocks(s->block[0]); |
2967 | 279 |
2624 | 280 if(!s->chroma_y_shift){ |
281 s->dsp.clear_blocks(s->block[6]); | |
282 } | |
2967 | 283 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
284 /* 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
|
285 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
|
286 !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
|
287 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
|
288 } |
0 | 289 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
290 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
|
291 s->qscale = get_qscale(s); |
2967 | 292 |
0 | 293 if (s->concealment_motion_vectors) { |
294 /* just parse them */ | |
2967 | 295 if (s->picture_structure != PICT_FRAME) |
21 | 296 skip_bits1(&s->gb); /* field select */ |
2967 | 297 |
298 s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] = | |
1323 | 299 mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]); |
2967 | 300 s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] = |
1323 | 301 mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]); |
302 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
303 skip_bits1(&s->gb); /* marker */ |
1323 | 304 }else |
305 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ | |
0 | 306 s->mb_intra = 1; |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
307 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
308 //one 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
309 if(s->avctx->xvmc_acceleration > 1){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
310 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
|
311 if(s->swap_uv){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
312 exchange_uv(s); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
313 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
314 } |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
315 #endif |
0 | 316 |
1421 | 317 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
2622 | 318 if(s->flags2 & CODEC_FLAG2_FAST){ |
319 for(i=0;i<6;i++) { | |
320 mpeg2_fast_decode_block_intra(s, s->pblocks[i], i); | |
321 } | |
322 }else{ | |
323 for(i=0;i<mb_block_count;i++) { | |
324 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) | |
325 return -1; | |
326 } | |
0 | 327 } |
328 } else { | |
329 for(i=0;i<6;i++) { | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
330 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
|
331 return -1; |
0 | 332 } |
333 } | |
334 } 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
|
335 if (mb_type & MB_TYPE_ZERO_MV){ |
1655 | 336 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
|
337 |
5437 | 338 s->mv_dir = MV_DIR_FORWARD; |
339 if(s->picture_structure == PICT_FRAME){ | |
340 if(!s->frame_pred_frame_dct) | |
341 s->interlaced_dct = get_bits1(&s->gb); | |
342 s->mv_type = MV_TYPE_16X16; | |
343 }else{ | |
344 s->mv_type = MV_TYPE_FIELD; | |
345 mb_type |= MB_TYPE_INTERLACED; | |
346 s->field_select[0][0]= s->picture_structure - 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
|
347 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
348 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
349 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
|
350 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
|
351 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 }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
|
359 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
|
360 //FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED |
4795 | 361 /* get additional motion vector type */ |
2967 | 362 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
|
363 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
|
364 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
|
365 motion_type = get_bits(&s->gb, 2); |
5438 | 366 if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type)) |
367 s->interlaced_dct = get_bits1(&s->gb); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
368 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
369 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
370 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
|
371 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
|
372 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
373 /* motion vectors */ |
5447 | 374 s->mv_dir= (mb_type>>13)&3; |
5441 | 375 dprintf(s->avctx, "motion_type=%d\n", motion_type); |
376 switch(motion_type) { | |
377 case MT_FRAME: /* or MT_16X8 */ | |
5443
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
378 if (s->picture_structure == PICT_FRAME) { |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
379 mb_type |= MB_TYPE_16x16; |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
380 s->mv_type = MV_TYPE_16X16; |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
381 for(i=0;i<2;i++) { |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
382 if (USES_LIST(mb_type, 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
|
383 /* MT_FRAME */ |
2967 | 384 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
|
385 mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); |
2967 | 386 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
|
387 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
|
388 /* 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
|
389 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
|
390 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
|
391 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
|
392 } |
5443
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
393 } |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
394 } |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
395 } else { |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
396 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
397 s->mv_type = MV_TYPE_16X8; |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
398 for(i=0;i<2;i++) { |
40c87c0f754b
exchange for() and if() order in the MT_FRAME case
michael
parents:
5441
diff
changeset
|
399 if (USES_LIST(mb_type, 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
|
400 /* 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
409 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
410 } |
5441 | 411 } |
412 } | |
413 break; | |
414 case MT_FIELD: | |
415 s->mv_type = MV_TYPE_FIELD; | |
5444 | 416 if (s->picture_structure == PICT_FRAME) { |
417 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; | |
418 for(i=0;i<2;i++) { | |
419 if (USES_LIST(mb_type, 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 s->mv[i][j][0] = val; |
4652 | 426 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
|
427 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
|
428 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
|
429 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
|
430 s->mv[i][j][1] = val; |
4652 | 431 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
|
432 } |
5444 | 433 } |
434 } | |
435 } else { | |
436 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; | |
437 for(i=0;i<2;i++) { | |
438 if (USES_LIST(mb_type, 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
447 } |
5441 | 448 } |
449 } | |
450 break; | |
451 case MT_DMV: | |
452 s->mv_type = MV_TYPE_DMV; | |
453 for(i=0;i<2;i++) { | |
454 if (USES_LIST(mb_type, i)) { | |
455 int dmx, dmy, mx, my, m; | |
456 mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], | |
457 s->last_mv[i][0][0]); | |
458 s->last_mv[i][0][0] = mx; | |
459 s->last_mv[i][1][0] = mx; | |
460 dmx = get_dmv(s); | |
461 my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], | |
462 s->last_mv[i][0][1] >> 1); | |
463 dmy = get_dmv(s); | |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
464 |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
465 |
5441 | 466 s->last_mv[i][0][1] = my<<1; |
467 s->last_mv[i][1][1] = my<<1; | |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
468 |
5441 | 469 s->mv[i][0][0] = mx; |
470 s->mv[i][0][1] = my; | |
471 s->mv[i][1][0] = mx;//not used | |
472 s->mv[i][1][1] = my;//not used | |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1325
diff
changeset
|
473 |
5441 | 474 if (s->picture_structure == PICT_FRAME) { |
475 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
|
476 |
5441 | 477 //m = 1 + 2 * s->top_field_first; |
478 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
|
479 |
5441 | 480 /* top -> top pred */ |
481 s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; | |
482 s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; | |
483 m = 4 - m; | |
484 s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; | |
485 s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; | |
486 } else { | |
487 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
|
488 |
5441 | 489 s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; |
490 s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; | |
491 if(s->picture_structure == PICT_TOP_FIELD) | |
492 s->mv[i][2][1]--; | |
493 else | |
494 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
|
495 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
496 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
497 } |
5441 | 498 break; |
499 default: | |
500 av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); | |
501 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
|
502 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
503 } |
2967 | 504 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
505 s->mb_intra = 0; |
2624 | 506 if (HAS_CBP(mb_type)) { |
507 s->dsp.clear_blocks(s->block[0]); | |
2967 | 508 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
509 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); |
2076 | 510 if(mb_block_count > 6){ |
2979 | 511 cbp<<= mb_block_count-6; |
512 cbp |= get_bits(&s->gb, mb_block_count-6); | |
5440 | 513 s->dsp.clear_blocks(s->block[6]); |
1848
c72589baee53
initial chroma_format changes,xvmc tweaks and codec_cap
iive
parents:
1841
diff
changeset
|
514 } |
5439
f1db308c277b
reorder if() so that the condition can be simplified
michael
parents:
5438
diff
changeset
|
515 if (cbp <= 0){ |
f1db308c277b
reorder if() so that the condition can be simplified
michael
parents:
5438
diff
changeset
|
516 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); |
f1db308c277b
reorder if() so that the condition can be simplified
michael
parents:
5438
diff
changeset
|
517 return -1; |
f1db308c277b
reorder if() so that the condition can be simplified
michael
parents:
5438
diff
changeset
|
518 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
519 |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
520 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
521 //on 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
522 if(s->avctx->xvmc_acceleration > 1){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
523 XVMC_pack_pblocks(s,cbp); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
524 if(s->swap_uv){ |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
525 exchange_uv(s); |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
526 } |
2967 | 527 } |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
528 #endif |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
529 |
1421 | 530 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
2201 | 531 if(s->flags2 & CODEC_FLAG2_FAST){ |
532 for(i=0;i<6;i++) { | |
533 if(cbp & 32) { | |
534 mpeg2_fast_decode_block_non_intra(s, s->pblocks[i], i); | |
535 } else { | |
536 s->block_last_index[i] = -1; | |
537 } | |
538 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
|
539 } |
2201 | 540 }else{ |
541 cbp<<= 12-mb_block_count; | |
2967 | 542 |
2201 | 543 for(i=0;i<mb_block_count;i++) { |
544 if ( cbp & (1<<11) ) { | |
545 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0) | |
546 return -1; | |
547 } else { | |
548 s->block_last_index[i] = -1; | |
549 } | |
550 cbp+=cbp; | |
551 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
552 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
553 } else { |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
554 if(s->flags2 & CODEC_FLAG2_FAST){ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
555 for(i=0;i<6;i++) { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
556 if (cbp & 32) { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
557 mpeg1_fast_decode_block_inter(s, s->pblocks[i], i); |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
558 } else { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
559 s->block_last_index[i] = -1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
560 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
561 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
|
562 } |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
563 }else{ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
564 for(i=0;i<6;i++) { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
565 if (cbp & 32) { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
566 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0) |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
567 return -1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
568 } else { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
569 s->block_last_index[i] = -1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
570 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
571 cbp+=cbp; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
572 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
573 } |
711 | 574 } |
575 }else{ | |
2947
18d47c6673f7
Mark all 12 block unused when there are no coded blocks
iive
parents:
2834
diff
changeset
|
576 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
|
577 s->block_last_index[i] = -1; |
0 | 578 } |
579 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
580 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
581 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
|
582 |
0 | 583 return 0; |
584 } | |
585 | |
586 /* as h263, but only 17 codes */ | |
587 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) | |
588 { | |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
589 int code, sign, val, l, shift; |
0 | 590 |
545 | 591 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
|
592 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
|
593 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
|
594 } |
0 | 595 if (code < 0) { |
596 return 0xffff; | |
597 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
598 |
21 | 599 sign = get_bits1(&s->gb); |
0 | 600 shift = fcode - 1; |
1255
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
601 val = code; |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
602 if (shift) { |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
603 val = (val - 1) << shift; |
0 | 604 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
|
605 val++; |
625ccacd1113
decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1254
diff
changeset
|
606 } |
0 | 607 if (sign) |
608 val = -val; | |
609 val += pred; | |
2967 | 610 |
0 | 611 /* modulo decoding */ |
2093 | 612 l= INT_BIT - 5 - shift; |
613 val = (val<<l)>>l; | |
0 | 614 return val; |
615 } | |
616 | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
617 static inline int decode_dc(GetBitContext *gb, int component) |
0 | 618 { |
619 int code, diff; | |
620 | |
621 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
|
622 code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2); |
0 | 623 } 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
|
624 code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2); |
0 | 625 } |
568 | 626 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
627 av_log(NULL, AV_LOG_ERROR, "invalid dc code at\n"); |
0 | 628 return 0xffff; |
568 | 629 } |
0 | 630 if (code == 0) { |
631 diff = 0; | |
632 } 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
|
633 diff = get_xbits(gb, code); |
0 | 634 } |
635 return diff; | |
636 } | |
637 | |
2967 | 638 static inline int mpeg1_decode_block_intra(MpegEncContext *s, |
639 DCTELEM *block, | |
0 | 640 int n) |
641 { | |
642 int level, dc, diff, i, j, run; | |
711 | 643 int component; |
5210 | 644 RLTable *rl = &ff_rl_mpeg1; |
1064 | 645 uint8_t * const scantable= s->intra_scantable.permutated; |
646 const uint16_t *quant_matrix= s->intra_matrix; | |
711 | 647 const int qscale= s->qscale; |
0 | 648 |
711 | 649 /* DC coef */ |
650 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
|
651 diff = decode_dc(&s->gb, component); |
711 | 652 if (diff >= 0xffff) |
653 return -1; | |
654 dc = s->last_dc[component]; | |
655 dc += diff; | |
656 s->last_dc[component] = dc; | |
657 block[0] = dc<<3; | |
4652 | 658 dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff); |
711 | 659 i = 0; |
660 { | |
2967 | 661 OPEN_READER(re, &s->gb); |
711 | 662 /* now quantify & encode AC coefs */ |
663 for(;;) { | |
664 UPDATE_CACHE(re, &s->gb); | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
665 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 666 |
711 | 667 if(level == 127){ |
668 break; | |
669 } else if(level != 0) { | |
670 i += run; | |
671 j = scantable[i]; | |
1728 | 672 level= (level*qscale*quant_matrix[j])>>4; |
711 | 673 level= (level-1)|1; |
674 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
675 LAST_SKIP_BITS(re, &s->gb, 1); | |
676 } else { | |
677 /* escape */ | |
678 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
679 UPDATE_CACHE(re, &s->gb); | |
680 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | |
681 if (level == -128) { | |
682 level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); | |
683 } else if (level == 0) { | |
684 level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); | |
685 } | |
686 i += run; | |
687 j = scantable[i]; | |
688 if(level<0){ | |
689 level= -level; | |
1728 | 690 level= (level*qscale*quant_matrix[j])>>4; |
711 | 691 level= (level-1)|1; |
692 level= -level; | |
693 }else{ | |
1728 | 694 level= (level*qscale*quant_matrix[j])>>4; |
711 | 695 level= (level-1)|1; |
696 } | |
697 } | |
698 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
699 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
711 | 700 return -1; |
701 } | |
702 | |
703 block[j] = level; | |
704 } | |
705 CLOSE_READER(re, &s->gb); | |
706 } | |
707 s->block_last_index[n] = i; | |
708 return 0; | |
709 } | |
710 | |
2967 | 711 static inline int mpeg1_decode_block_inter(MpegEncContext *s, |
712 DCTELEM *block, | |
711 | 713 int n) |
714 { | |
715 int level, i, j, run; | |
5210 | 716 RLTable *rl = &ff_rl_mpeg1; |
1064 | 717 uint8_t * const scantable= s->intra_scantable.permutated; |
718 const uint16_t *quant_matrix= s->inter_matrix; | |
711 | 719 const int qscale= s->qscale; |
720 | |
721 { | |
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
|
722 OPEN_READER(re, &s->gb); |
711 | 723 i = -1; |
0 | 724 /* 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
|
725 UPDATE_CACHE(re, &s->gb); |
2617 | 726 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
1728 | 727 level= (3*qscale*quant_matrix[0])>>5; |
711 | 728 level= (level-1)|1; |
2617 | 729 if(GET_CACHE(re, &s->gb)&0x40000000) |
711 | 730 level= -level; |
714 | 731 block[0] = level; |
711 | 732 i++; |
2617 | 733 SKIP_BITS(re, &s->gb, 2); |
734 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
735 goto end; | |
0 | 736 } |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
737 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
738 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
739 #endif |
711 | 740 /* now quantify & encode AC coefs */ |
741 for(;;) { | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
742 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 743 |
2617 | 744 if(level != 0) { |
711 | 745 i += run; |
746 j = scantable[i]; | |
1728 | 747 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 748 level= (level-1)|1; |
749 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
2617 | 750 SKIP_BITS(re, &s->gb, 1); |
711 | 751 } else { |
752 /* escape */ | |
753 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
754 UPDATE_CACHE(re, &s->gb); | |
755 level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); | |
756 if (level == -128) { | |
2617 | 757 level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); |
711 | 758 } else if (level == 0) { |
2617 | 759 level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); |
711 | 760 } |
761 i += run; | |
762 j = scantable[i]; | |
763 if(level<0){ | |
764 level= -level; | |
1728 | 765 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 766 level= (level-1)|1; |
767 level= -level; | |
768 }else{ | |
1728 | 769 level= ((level*2+1)*qscale*quant_matrix[j])>>5; |
711 | 770 level= (level-1)|1; |
771 } | |
772 } | |
773 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
774 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
711 | 775 return -1; |
776 } | |
0 | 777 |
711 | 778 block[j] = level; |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
779 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
780 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
781 #endif |
2617 | 782 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
783 break; | |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
784 #if MIN_CACHE_BITS >= 19 |
2617 | 785 UPDATE_CACHE(re, &s->gb); |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
786 #endif |
0 | 787 } |
2617 | 788 end: |
789 LAST_SKIP_BITS(re, &s->gb, 2); | |
711 | 790 CLOSE_READER(re, &s->gb); |
0 | 791 } |
711 | 792 s->block_last_index[n] = i; |
0 | 793 return 0; |
794 } | |
795 | |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
796 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
|
797 { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
798 int level, i, j, run; |
5210 | 799 RLTable *rl = &ff_rl_mpeg1; |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
800 uint8_t * const scantable= s->intra_scantable.permutated; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
801 const int qscale= s->qscale; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
802 |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
803 { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
804 OPEN_READER(re, &s->gb); |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
805 i = -1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
806 /* 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
|
807 UPDATE_CACHE(re, &s->gb); |
2617 | 808 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
2203 | 809 level= (3*qscale)>>1; |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
810 level= (level-1)|1; |
2617 | 811 if(GET_CACHE(re, &s->gb)&0x40000000) |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
812 level= -level; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
813 block[0] = level; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
814 i++; |
2617 | 815 SKIP_BITS(re, &s->gb, 2); |
816 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
817 goto end; | |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
818 } |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
819 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
820 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
821 #endif |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
822 |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
823 /* now quantify & encode AC coefs */ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
824 for(;;) { |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
825 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 826 |
2617 | 827 if(level != 0) { |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
828 i += run; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
829 j = scantable[i]; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
830 level= ((level*2+1)*qscale)>>1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
831 level= (level-1)|1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
832 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
2617 | 833 SKIP_BITS(re, &s->gb, 1); |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
834 } else { |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
835 /* escape */ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
836 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
|
837 UPDATE_CACHE(re, &s->gb); |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
838 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
|
839 if (level == -128) { |
2617 | 840 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
|
841 } else if (level == 0) { |
2617 | 842 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
|
843 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
844 i += run; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
845 j = scantable[i]; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
846 if(level<0){ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
847 level= -level; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
848 level= ((level*2+1)*qscale)>>1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
849 level= (level-1)|1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
850 level= -level; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
851 }else{ |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
852 level= ((level*2+1)*qscale)>>1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
853 level= (level-1)|1; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
854 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
855 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
856 |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
857 block[j] = level; |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
858 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
859 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
860 #endif |
2617 | 861 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
862 break; | |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
863 #if MIN_CACHE_BITS >= 19 |
2617 | 864 UPDATE_CACHE(re, &s->gb); |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
865 #endif |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
866 } |
2617 | 867 end: |
868 LAST_SKIP_BITS(re, &s->gb, 2); | |
2202
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
869 CLOSE_READER(re, &s->gb); |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
870 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
871 s->block_last_index[n] = i; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
872 return 0; |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
873 } |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
874 |
8079b177ff5c
optional non spec compliant optimizations for mpeg1
michael
parents:
2201
diff
changeset
|
875 |
2967 | 876 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, |
877 DCTELEM *block, | |
714 | 878 int n) |
0 | 879 { |
880 int level, i, j, run; | |
5210 | 881 RLTable *rl = &ff_rl_mpeg1; |
1064 | 882 uint8_t * const scantable= s->intra_scantable.permutated; |
883 const uint16_t *quant_matrix; | |
714 | 884 const int qscale= s->qscale; |
0 | 885 int mismatch; |
886 | |
887 mismatch = 1; | |
888 | |
889 { | |
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
|
890 OPEN_READER(re, &s->gb); |
714 | 891 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
|
892 if (n < 4) |
714 | 893 quant_matrix = s->inter_matrix; |
0 | 894 else |
714 | 895 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
|
896 |
0 | 897 /* 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
|
898 UPDATE_CACHE(re, &s->gb); |
2617 | 899 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
714 | 900 level= (3*qscale*quant_matrix[0])>>5; |
2617 | 901 if(GET_CACHE(re, &s->gb)&0x40000000) |
714 | 902 level= -level; |
903 block[0] = level; | |
904 mismatch ^= level; | |
905 i++; | |
2617 | 906 SKIP_BITS(re, &s->gb, 2); |
907 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
908 goto end; | |
714 | 909 } |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
910 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
911 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
912 #endif |
714 | 913 |
914 /* now quantify & encode AC coefs */ | |
915 for(;;) { | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
916 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 917 |
2617 | 918 if(level != 0) { |
714 | 919 i += run; |
920 j = scantable[i]; | |
921 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | |
922 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
2617 | 923 SKIP_BITS(re, &s->gb, 1); |
714 | 924 } else { |
925 /* escape */ | |
926 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
927 UPDATE_CACHE(re, &s->gb); | |
928 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
929 | |
930 i += run; | |
931 j = scantable[i]; | |
932 if(level<0){ | |
933 level= ((-level*2+1)*qscale*quant_matrix[j])>>5; | |
934 level= -level; | |
935 }else{ | |
936 level= ((level*2+1)*qscale*quant_matrix[j])>>5; | |
937 } | |
938 } | |
939 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
940 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
714 | 941 return -1; |
942 } | |
2967 | 943 |
714 | 944 mismatch ^= level; |
945 block[j] = level; | |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
946 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
947 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
948 #endif |
2617 | 949 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
950 break; | |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
951 #if MIN_CACHE_BITS >= 19 |
2617 | 952 UPDATE_CACHE(re, &s->gb); |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
953 #endif |
0 | 954 } |
2617 | 955 end: |
956 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
|
957 CLOSE_READER(re, &s->gb); |
0 | 958 } |
959 block[63] ^= (mismatch & 1); | |
2967 | 960 |
0 | 961 s->block_last_index[n] = i; |
962 return 0; | |
963 } | |
964 | |
2967 | 965 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, |
966 DCTELEM *block, | |
2201 | 967 int n) |
968 { | |
969 int level, i, j, run; | |
5210 | 970 RLTable *rl = &ff_rl_mpeg1; |
2201 | 971 uint8_t * const scantable= s->intra_scantable.permutated; |
972 const int qscale= s->qscale; | |
973 OPEN_READER(re, &s->gb); | |
974 i = -1; | |
975 | |
976 /* special case for the first coef. no need to add a second vlc table */ | |
977 UPDATE_CACHE(re, &s->gb); | |
2617 | 978 if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { |
2201 | 979 level= (3*qscale)>>1; |
2617 | 980 if(GET_CACHE(re, &s->gb)&0x40000000) |
2201 | 981 level= -level; |
982 block[0] = level; | |
983 i++; | |
2617 | 984 SKIP_BITS(re, &s->gb, 2); |
985 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) | |
986 goto end; | |
2201 | 987 } |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
988 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
989 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
990 #endif |
2201 | 991 |
992 /* now quantify & encode AC coefs */ | |
993 for(;;) { | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
994 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 995 |
2617 | 996 if(level != 0) { |
2201 | 997 i += run; |
998 j = scantable[i]; | |
999 level= ((level*2+1)*qscale)>>1; | |
1000 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
2617 | 1001 SKIP_BITS(re, &s->gb, 1); |
2201 | 1002 } else { |
1003 /* escape */ | |
1004 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1005 UPDATE_CACHE(re, &s->gb); | |
1006 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
1007 | |
1008 i += run; | |
1009 j = scantable[i]; | |
1010 if(level<0){ | |
1011 level= ((-level*2+1)*qscale)>>1; | |
1012 level= -level; | |
1013 }else{ | |
1014 level= ((level*2+1)*qscale)>>1; | |
1015 } | |
1016 } | |
2967 | 1017 |
2201 | 1018 block[j] = level; |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
1019 #if MIN_CACHE_BITS < 19 |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
1020 UPDATE_CACHE(re, &s->gb); |
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
1021 #endif |
2617 | 1022 if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) |
1023 break; | |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
1024 #if MIN_CACHE_BITS >=19 |
2617 | 1025 UPDATE_CACHE(re, &s->gb); |
5458
ebe106e3339e
Make MPEG-1/2 decoder work with the libmpeg2-style bitstream reader.
michael
parents:
5449
diff
changeset
|
1026 #endif |
2201 | 1027 } |
2617 | 1028 end: |
2967 | 1029 LAST_SKIP_BITS(re, &s->gb, 2); |
2201 | 1030 CLOSE_READER(re, &s->gb); |
1031 s->block_last_index[n] = i; | |
1032 return 0; | |
1033 } | |
1034 | |
1035 | |
2967 | 1036 static inline int mpeg2_decode_block_intra(MpegEncContext *s, |
1037 DCTELEM *block, | |
714 | 1038 int n) |
0 | 1039 { |
1040 int level, dc, diff, i, j, run; | |
714 | 1041 int component; |
0 | 1042 RLTable *rl; |
1064 | 1043 uint8_t * const scantable= s->intra_scantable.permutated; |
1044 const uint16_t *quant_matrix; | |
714 | 1045 const int qscale= s->qscale; |
0 | 1046 int mismatch; |
1047 | |
1048 /* DC coef */ | |
714 | 1049 if (n < 4){ |
1050 quant_matrix = s->intra_matrix; | |
2967 | 1051 component = 0; |
714 | 1052 }else{ |
1053 quant_matrix = s->chroma_intra_matrix; | |
1848
c72589baee53
initial chroma_format changes,xvmc tweaks and codec_cap
iive
parents:
1841
diff
changeset
|
1054 component = (n&1) + 1; |
714 | 1055 } |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
1409
diff
changeset
|
1056 diff = decode_dc(&s->gb, component); |
0 | 1057 if (diff >= 0xffff) |
1058 return -1; | |
1059 dc = s->last_dc[component]; | |
1060 dc += diff; | |
1061 s->last_dc[component] = dc; | |
1062 block[0] = dc << (3 - s->intra_dc_precision); | |
4652 | 1063 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
|
1064 mismatch = block[0] ^ 1; |
714 | 1065 i = 0; |
0 | 1066 if (s->intra_vlc_format) |
5210 | 1067 rl = &ff_rl_mpeg2; |
0 | 1068 else |
5210 | 1069 rl = &ff_rl_mpeg1; |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1070 |
714 | 1071 { |
2967 | 1072 OPEN_READER(re, &s->gb); |
714 | 1073 /* now quantify & encode AC coefs */ |
1074 for(;;) { | |
1075 UPDATE_CACHE(re, &s->gb); | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2591
diff
changeset
|
1076 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 1077 |
714 | 1078 if(level == 127){ |
1079 break; | |
1080 } else if(level != 0) { | |
1081 i += run; | |
1082 j = scantable[i]; | |
1083 level= (level*qscale*quant_matrix[j])>>4; | |
1084 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1085 LAST_SKIP_BITS(re, &s->gb, 1); | |
1086 } else { | |
1087 /* escape */ | |
1088 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1089 UPDATE_CACHE(re, &s->gb); | |
1090 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
1091 i += run; | |
1092 j = scantable[i]; | |
1093 if(level<0){ | |
1094 level= (-level*qscale*quant_matrix[j])>>4; | |
1095 level= -level; | |
1096 }else{ | |
1097 level= (level*qscale*quant_matrix[j])>>4; | |
1098 } | |
1099 } | |
1100 if (i > 63){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1101 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
714 | 1102 return -1; |
1103 } | |
2967 | 1104 |
714 | 1105 mismatch^= level; |
1106 block[j] = level; | |
568 | 1107 } |
714 | 1108 CLOSE_READER(re, &s->gb); |
0 | 1109 } |
714 | 1110 block[63]^= mismatch&1; |
2967 | 1111 |
0 | 1112 s->block_last_index[n] = i; |
1113 return 0; | |
1114 } | |
1115 | |
2967 | 1116 static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, |
1117 DCTELEM *block, | |
2622 | 1118 int n) |
1119 { | |
1120 int level, dc, diff, j, run; | |
1121 int component; | |
1122 RLTable *rl; | |
1123 uint8_t * scantable= s->intra_scantable.permutated; | |
1124 const uint16_t *quant_matrix; | |
1125 const int qscale= s->qscale; | |
1126 | |
1127 /* DC coef */ | |
1128 if (n < 4){ | |
1129 quant_matrix = s->intra_matrix; | |
2967 | 1130 component = 0; |
2622 | 1131 }else{ |
1132 quant_matrix = s->chroma_intra_matrix; | |
1133 component = (n&1) + 1; | |
1134 } | |
1135 diff = decode_dc(&s->gb, component); | |
1136 if (diff >= 0xffff) | |
1137 return -1; | |
1138 dc = s->last_dc[component]; | |
1139 dc += diff; | |
1140 s->last_dc[component] = dc; | |
1141 block[0] = dc << (3 - s->intra_dc_precision); | |
1142 if (s->intra_vlc_format) | |
5210 | 1143 rl = &ff_rl_mpeg2; |
2622 | 1144 else |
5210 | 1145 rl = &ff_rl_mpeg1; |
2622 | 1146 |
1147 { | |
2967 | 1148 OPEN_READER(re, &s->gb); |
2622 | 1149 /* now quantify & encode AC coefs */ |
1150 for(;;) { | |
1151 UPDATE_CACHE(re, &s->gb); | |
1152 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); | |
2967 | 1153 |
2622 | 1154 if(level == 127){ |
1155 break; | |
1156 } else if(level != 0) { | |
1157 scantable += run; | |
1158 j = *scantable; | |
1159 level= (level*qscale*quant_matrix[j])>>4; | |
1160 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
1161 LAST_SKIP_BITS(re, &s->gb, 1); | |
1162 } else { | |
1163 /* escape */ | |
1164 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); | |
1165 UPDATE_CACHE(re, &s->gb); | |
1166 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); | |
1167 scantable += run; | |
1168 j = *scantable; | |
1169 if(level<0){ | |
1170 level= (-level*qscale*quant_matrix[j])>>4; | |
1171 level= -level; | |
1172 }else{ | |
1173 level= (level*qscale*quant_matrix[j])>>4; | |
1174 } | |
1175 } | |
2967 | 1176 |
2622 | 1177 block[j] = level; |
1178 } | |
1179 CLOSE_READER(re, &s->gb); | |
1180 } | |
2967 | 1181 |
2622 | 1182 s->block_last_index[n] = scantable - s->intra_scantable.permutated; |
1183 return 0; | |
1184 } | |
1185 | |
0 | 1186 typedef struct Mpeg1Context { |
1187 MpegEncContext mpeg_enc_ctx; | |
1188 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
|
1189 int repeat_field; /* true if we must repeat the field */ |
1546 | 1190 AVPanScan pan_scan; /** some temporary storage for the panscan */ |
1827 | 1191 int slice_count; |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1192 int swap_uv;//indicate VCR2 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1193 int save_aspect_info; |
4888
185f5e4feb72
make mpeg decoder handle mid-stream changes in resolution
benoit
parents:
4795
diff
changeset
|
1194 int save_width, save_height; |
2219 | 1195 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
|
1196 |
0 | 1197 } Mpeg1Context; |
1198 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6494
diff
changeset
|
1199 static av_cold int mpeg_decode_init(AVCodecContext *avctx) |
0 | 1200 { |
1201 Mpeg1Context *s = avctx->priv_data; | |
1892 | 1202 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
1990 | 1203 int i; |
2967 | 1204 |
1990 | 1205 //we need some parmutation to store |
1206 //matrixes, until MPV_common_init() | |
2967 | 1207 //set the real permutatuon |
1990 | 1208 for(i=0;i<64;i++) |
1209 s2->dsp.idct_permutation[i]=i; | |
1210 | |
1892 | 1211 MPV_decode_defaults(s2); |
2967 | 1212 |
1732
f716b8f47d98
uninitalized variables fix by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
1728
diff
changeset
|
1213 s->mpeg_enc_ctx.avctx= avctx; |
558 | 1214 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
|
1215 s->mpeg_enc_ctx.flags2= avctx->flags2; |
5210 | 1216 ff_mpeg12_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
|
1217 init_vlcs(); |
0 | 1218 |
1219 s->mpeg_enc_ctx_allocated = 0; | |
1220 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
|
1221 s->repeat_field = 0; |
344 | 1222 s->mpeg_enc_ctx.codec_id= avctx->codec->id; |
0 | 1223 return 0; |
1224 } | |
1225 | |
2967 | 1226 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
|
1227 const uint8_t *new_perm){ |
2219 | 1228 uint16_t temp_matrix[64]; |
1229 int i; | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1230 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1231 memcpy(temp_matrix,matrix,64*sizeof(uint16_t)); |
2967 | 1232 |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1233 for(i=0;i<64;i++){ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1234 matrix[new_perm[i]] = temp_matrix[old_perm[i]]; |
2967 | 1235 } |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1236 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1237 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1238 //Call this function when we know all parameters |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1239 //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
|
1240 static int mpeg_decode_postinit(AVCodecContext *avctx){ |
2219 | 1241 Mpeg1Context *s1 = avctx->priv_data; |
1242 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1243 uint8_t old_permutation[64]; | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1244 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1245 if ( |
2979 | 1246 (s1->mpeg_enc_ctx_allocated == 0)|| |
2270 | 1247 avctx->coded_width != s->width || |
1248 avctx->coded_height != s->height|| | |
4888
185f5e4feb72
make mpeg decoder handle mid-stream changes in resolution
benoit
parents:
4795
diff
changeset
|
1249 s1->save_width != s->width || |
185f5e4feb72
make mpeg decoder handle mid-stream changes in resolution
benoit
parents:
4795
diff
changeset
|
1250 s1->save_height != s->height || |
2590 | 1251 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
|
1252 0) |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1253 { |
2967 | 1254 |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1255 if (s1->mpeg_enc_ctx_allocated) { |
2681 | 1256 ParseContext pc= s->parse_context; |
1257 s->parse_context.buffer=0; | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1258 MPV_common_end(s); |
2681 | 1259 s->parse_context= pc; |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1260 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1261 |
2979 | 1262 if( (s->width == 0 )||(s->height == 0)) |
1263 return -2; | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1264 |
2270 | 1265 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
|
1266 avctx->bit_rate = s->bit_rate; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1267 s1->save_aspect_info = s->aspect_ratio_info; |
4888
185f5e4feb72
make mpeg decoder handle mid-stream changes in resolution
benoit
parents:
4795
diff
changeset
|
1268 s1->save_width = s->width; |
185f5e4feb72
make mpeg decoder handle mid-stream changes in resolution
benoit
parents:
4795
diff
changeset
|
1269 s1->save_height = s->height; |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1270 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1271 //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
|
1272 //that behave like P frames |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1273 avctx->has_b_frames = !(s->low_delay); |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1274 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1275 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
|
1276 //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
|
1277 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
|
1278 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
|
1279 //mpeg1 aspect |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1280 avctx->sample_aspect_ratio= av_d2q( |
5210 | 1281 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1282 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1283 }else{//mpeg2 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1284 //mpeg2 fps |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1285 av_reduce( |
2967 | 1286 &s->avctx->time_base.den, |
1287 &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
|
1288 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
|
1289 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
|
1290 1<<30); |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1291 //mpeg2 aspect |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1292 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
|
1293 if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){ |
2967 | 1294 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
|
1295 av_div_q( |
5210 | 1296 ff_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
|
1297 (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
|
1298 ); |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1299 }else{ |
2967 | 1300 s->avctx->sample_aspect_ratio= |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1301 av_div_q( |
5210 | 1302 ff_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
|
1303 (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
|
1304 ); |
2979 | 1305 } |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1306 }else{ |
2967 | 1307 s->avctx->sample_aspect_ratio= |
5210 | 1308 ff_mpeg2_aspect[s->aspect_ratio_info]; |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1309 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1310 }//mpeg2 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1311 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1312 if(avctx->xvmc_acceleration){ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1313 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
|
1314 }else{ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1315 if(s->chroma_format < 2){ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1316 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
|
1317 }else |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1318 if(s->chroma_format == 2){ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1319 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
|
1320 }else |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1321 if(s->chroma_format > 2){ |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1322 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
|
1323 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1324 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1325 //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
|
1326 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
|
1327 if( avctx->idct_algo == FF_IDCT_AUTO ) |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1328 avctx->idct_algo = FF_IDCT_SIMPLE; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1329 |
2967 | 1330 //quantization matrixes may need reordering |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1331 //if dct permutation is changed |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1332 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
|
1333 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1334 if (MPV_common_init(s) < 0) |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1335 return -2; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1336 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1337 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
|
1338 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
|
1339 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
|
1340 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
|
1341 |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1342 s1->mpeg_enc_ctx_allocated = 1; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1343 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1344 return 0; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1345 } |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1346 |
2967 | 1347 static int mpeg1_decode_picture(AVCodecContext *avctx, |
1862 | 1348 const uint8_t *buf, int buf_size) |
0 | 1349 { |
1350 Mpeg1Context *s1 = avctx->priv_data; | |
1351 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1697 | 1352 int ref, f_code, vbv_delay; |
0 | 1353 |
2967 | 1354 if(mpeg_decode_postinit(s->avctx) < 0) |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1355 return -2; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1356 |
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
|
1357 init_get_bits(&s->gb, buf, buf_size*8); |
0 | 1358 |
1359 ref = get_bits(&s->gb, 10); /* temporal ref */ | |
1360 s->pict_type = get_bits(&s->gb, 3); | |
2575 | 1361 if(s->pict_type == 0 || s->pict_type > 3) |
1362 return -1; | |
872 | 1363 |
1697 | 1364 vbv_delay= get_bits(&s->gb, 16); |
6481 | 1365 if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) { |
21 | 1366 s->full_pel[0] = get_bits1(&s->gb); |
0 | 1367 f_code = get_bits(&s->gb, 3); |
2786 | 1368 if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT) |
0 | 1369 return -1; |
1370 s->mpeg_f_code[0][0] = f_code; | |
1371 s->mpeg_f_code[0][1] = f_code; | |
1372 } | |
6481 | 1373 if (s->pict_type == FF_B_TYPE) { |
21 | 1374 s->full_pel[1] = get_bits1(&s->gb); |
0 | 1375 f_code = get_bits(&s->gb, 3); |
2786 | 1376 if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT) |
0 | 1377 return -1; |
1378 s->mpeg_f_code[1][0] = f_code; | |
1379 s->mpeg_f_code[1][1] = f_code; | |
1380 } | |
903 | 1381 s->current_picture.pict_type= s->pict_type; |
6481 | 1382 s->current_picture.key_frame= s->pict_type == FF_I_TYPE; |
2967 | 1383 |
2575 | 1384 if(avctx->debug & FF_DEBUG_PICT_INFO) |
1385 av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type); | |
2967 | 1386 |
0 | 1387 s->y_dc_scale = 8; |
1388 s->c_dc_scale = 8; | |
1389 s->first_slice = 1; | |
1390 return 0; | |
1391 } | |
1392 | |
2219 | 1393 static void mpeg_decode_sequence_extension(Mpeg1Context *s1) |
0 | 1394 { |
2219 | 1395 MpegEncContext *s= &s1->mpeg_enc_ctx; |
0 | 1396 int horiz_size_ext, vert_size_ext; |
1721 | 1397 int bit_rate_ext; |
0 | 1398 |
1421 | 1399 skip_bits(&s->gb, 1); /* profil and level esc*/ |
2167 | 1400 s->avctx->profile= get_bits(&s->gb, 3); |
1401 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
|
1402 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
|
1403 s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */ |
0 | 1404 horiz_size_ext = get_bits(&s->gb, 2); |
1405 vert_size_ext = get_bits(&s->gb, 2); | |
1406 s->width |= (horiz_size_ext << 12); | |
1407 s->height |= (vert_size_ext << 12); | |
1408 bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */ | |
2540 | 1409 s->bit_rate += (bit_rate_ext << 18) * 400; |
21 | 1410 skip_bits1(&s->gb); /* marker */ |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
1411 s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10; |
1346 | 1412 |
917 | 1413 s->low_delay = get_bits1(&s->gb); |
1346 | 1414 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; |
1415 | |
2219 | 1416 s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1; |
1417 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
|
1418 |
4652 | 1419 dprintf(s->avctx, "sequence extension\n"); |
1421 | 1420 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
|
1421 s->avctx->sub_id = 2; /* indicates mpeg2 found */ |
917 | 1422 |
1421 | 1423 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
2967 | 1424 av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n", |
2167 | 1425 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
|
1426 |
0 | 1427 } |
1428 | |
1546 | 1429 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1) |
1430 { | |
1431 MpegEncContext *s= &s1->mpeg_enc_ctx; | |
1432 int color_description, w, h; | |
1433 | |
1434 skip_bits(&s->gb, 3); /* video format */ | |
1435 color_description= get_bits1(&s->gb); | |
1436 if(color_description){ | |
1437 skip_bits(&s->gb, 8); /* color primaries */ | |
1438 skip_bits(&s->gb, 8); /* transfer_characteristics */ | |
1439 skip_bits(&s->gb, 8); /* matrix_coefficients */ | |
1440 } | |
1441 w= get_bits(&s->gb, 14); | |
1442 skip_bits(&s->gb, 1); //marker | |
1443 h= get_bits(&s->gb, 14); | |
1444 skip_bits(&s->gb, 1); //marker | |
2967 | 1445 |
1546 | 1446 s1->pan_scan.width= 16*w; |
1447 s1->pan_scan.height=16*h; | |
2967 | 1448 |
1546 | 1449 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
|
1450 av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h); |
1546 | 1451 } |
1452 | |
1453 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) | |
1454 { | |
1455 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
|
1456 int i,nofco; |
1546 | 1457 |
1891
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1458 nofco = 1; |
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1459 if(s->progressive_sequence){ |
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1460 if(s->repeat_first_field){ |
2979 | 1461 nofco++; |
1462 if(s->top_field_first) | |
1463 nofco++; | |
1464 } | |
1891
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1465 }else{ |
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1466 if(s->picture_structure == PICT_FRAME){ |
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1467 nofco++; |
2979 | 1468 if(s->repeat_first_field) |
1469 nofco++; | |
1470 } | |
1891
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1471 } |
f403b3e286b3
use pan_scan to remove some weight, proper pan_scan offset reading
iive
parents:
1890
diff
changeset
|
1472 for(i=0; i<nofco; i++){ |
1546 | 1473 s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16); |
1474 skip_bits(&s->gb, 1); //marker | |
1475 s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); | |
1476 skip_bits(&s->gb, 1); //marker | |
1477 } | |
2967 | 1478 |
1546 | 1479 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
2967 | 1480 av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n", |
1481 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], | |
1482 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], | |
1546 | 1483 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1] |
1484 ); | |
1485 } | |
1486 | |
0 | 1487 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) |
1488 { | |
38
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1489 int i, v, j; |
0 | 1490 |
4652 | 1491 dprintf(s->avctx, "matrix extension\n"); |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1492 |
21 | 1493 if (get_bits1(&s->gb)) { |
0 | 1494 for(i=0;i<64;i++) { |
1495 v = get_bits(&s->gb, 8); | |
1092 | 1496 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
|
1497 s->intra_matrix[j] = v; |
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1498 s->chroma_intra_matrix[j] = v; |
0 | 1499 } |
1500 } | |
21 | 1501 if (get_bits1(&s->gb)) { |
0 | 1502 for(i=0;i<64;i++) { |
1503 v = get_bits(&s->gb, 8); | |
1092 | 1504 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
344 | 1505 s->inter_matrix[j] = v; |
1506 s->chroma_inter_matrix[j] = v; | |
0 | 1507 } |
1508 } | |
21 | 1509 if (get_bits1(&s->gb)) { |
0 | 1510 for(i=0;i<64;i++) { |
1511 v = get_bits(&s->gb, 8); | |
1092 | 1512 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
|
1513 s->chroma_intra_matrix[j] = v; |
0 | 1514 } |
1515 } | |
21 | 1516 if (get_bits1(&s->gb)) { |
0 | 1517 for(i=0;i<64;i++) { |
1518 v = get_bits(&s->gb, 8); | |
1092 | 1519 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
344 | 1520 s->chroma_inter_matrix[j] = v; |
0 | 1521 } |
1522 } | |
1523 } | |
1524 | |
1525 static void mpeg_decode_picture_coding_extension(MpegEncContext *s) | |
1526 { | |
1527 s->full_pel[0] = s->full_pel[1] = 0; | |
1528 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4); | |
1529 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4); | |
1530 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4); | |
1531 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4); | |
1532 s->intra_dc_precision = get_bits(&s->gb, 2); | |
1533 s->picture_structure = get_bits(&s->gb, 2); | |
21 | 1534 s->top_field_first = get_bits1(&s->gb); |
1535 s->frame_pred_frame_dct = get_bits1(&s->gb); | |
1536 s->concealment_motion_vectors = get_bits1(&s->gb); | |
1537 s->q_scale_type = get_bits1(&s->gb); | |
1538 s->intra_vlc_format = get_bits1(&s->gb); | |
1539 s->alternate_scan = get_bits1(&s->gb); | |
1540 s->repeat_first_field = get_bits1(&s->gb); | |
1541 s->chroma_420_type = get_bits1(&s->gb); | |
1542 s->progressive_frame = get_bits1(&s->gb); | |
1708 | 1543 |
4070 | 1544 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
|
1545 s->first_field=0; |
4070 | 1546 s->v_edge_pos= 16*s->mb_height; |
1547 }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
|
1548 s->first_field ^= 1; |
4070 | 1549 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
|
1550 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
|
1551 } |
2967 | 1552 |
715
8b3ccabfce4a
move scantable init from block-decode to header parser
michaelni
parents:
714
diff
changeset
|
1553 if(s->alternate_scan){ |
1273 | 1554 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); |
1555 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
|
1556 }else{ |
1273 | 1557 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); |
1558 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
|
1559 } |
2967 | 1560 |
0 | 1561 /* composite display not parsed */ |
4652 | 1562 dprintf(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision); |
1563 dprintf(s->avctx, "picture_structure=%d\n", s->picture_structure); | |
1564 dprintf(s->avctx, "top field first=%d\n", s->top_field_first); | |
1565 dprintf(s->avctx, "repeat first field=%d\n", s->repeat_first_field); | |
1566 dprintf(s->avctx, "conceal=%d\n", s->concealment_motion_vectors); | |
1567 dprintf(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format); | |
1568 dprintf(s->avctx, "alternate_scan=%d\n", s->alternate_scan); | |
1569 dprintf(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); | |
1570 dprintf(s->avctx, "progressive_frame=%d\n", s->progressive_frame); | |
0 | 1571 } |
1572 | |
2967 | 1573 static void mpeg_decode_extension(AVCodecContext *avctx, |
1862 | 1574 const uint8_t *buf, int buf_size) |
0 | 1575 { |
1576 Mpeg1Context *s1 = avctx->priv_data; | |
1577 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1578 int ext_type; | |
1579 | |
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
|
1580 init_get_bits(&s->gb, buf, buf_size*8); |
2967 | 1581 |
0 | 1582 ext_type = get_bits(&s->gb, 4); |
1583 switch(ext_type) { | |
1584 case 0x1: | |
2219 | 1585 mpeg_decode_sequence_extension(s1); |
0 | 1586 break; |
1546 | 1587 case 0x2: |
1588 mpeg_decode_sequence_display_extension(s1); | |
1589 break; | |
0 | 1590 case 0x3: |
1591 mpeg_decode_quant_matrix_extension(s); | |
1592 break; | |
1546 | 1593 case 0x7: |
1594 mpeg_decode_picture_display_extension(s1); | |
1595 break; | |
0 | 1596 case 0x8: |
1597 mpeg_decode_picture_coding_extension(s); | |
1598 break; | |
1599 } | |
1600 } | |
1601 | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1602 static void exchange_uv(MpegEncContext *s){ |
2219 | 1603 short * tmp = s->pblocks[4]; |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1604 s->pblocks[4] = s->pblocks[5]; |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1605 s->pblocks[5] = tmp; |
1380 | 1606 } |
1607 | |
1827 | 1608 static int mpeg_field_start(MpegEncContext *s){ |
1609 AVCodecContext *avctx= s->avctx; | |
1610 Mpeg1Context *s1 = (Mpeg1Context*)s; | |
826 | 1611 |
0 | 1612 /* start frame decoding */ |
1827 | 1613 if(s->first_field || s->picture_structure==PICT_FRAME){ |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
751
diff
changeset
|
1614 if(MPV_frame_start(s, avctx) < 0) |
1827 | 1615 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
|
1616 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1617 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
|
1618 |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1619 /* first check if we must repeat the frame */ |
1409 | 1620 s->current_picture_ptr->repeat_pict = 0; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1621 if (s->repeat_first_field) { |
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1622 if (s->progressive_sequence) { |
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1623 if (s->top_field_first) |
1409 | 1624 s->current_picture_ptr->repeat_pict = 4; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1625 else |
1409 | 1626 s->current_picture_ptr->repeat_pict = 2; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1627 } else if (s->progressive_frame) { |
1409 | 1628 s->current_picture_ptr->repeat_pict = 1; |
1085
9acf4b552047
move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents:
1084
diff
changeset
|
1629 } |
2967 | 1630 } |
1546 | 1631 |
1632 *s->current_picture_ptr->pan_scan= s1->pan_scan; | |
1827 | 1633 }else{ //second field |
1138 | 1634 int i; |
2967 | 1635 |
1182
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
1636 if(!s->current_picture_ptr){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1637 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
|
1638 return -1; |
38e8b8f331cb
some checks to avoid segfaults if the decoder is feeded with junk
michaelni
parents:
1181
diff
changeset
|
1639 } |
2967 | 1640 |
1138 | 1641 for(i=0; i<4; i++){ |
1642 s->current_picture.data[i] = s->current_picture_ptr->data[i]; | |
1643 if(s->picture_structure == PICT_BOTTOM_FIELD){ | |
1644 s->current_picture.data[i] += s->current_picture_ptr->linesize[i]; | |
2967 | 1645 } |
1138 | 1646 } |
1827 | 1647 } |
1381 | 1648 #ifdef HAVE_XVMC |
1649 // MPV_frame_start will call this function too, | |
1650 // but we need to call it on every field | |
1827 | 1651 if(s->avctx->xvmc_acceleration) |
1381 | 1652 XVMC_field_start(s,avctx); |
1653 #endif | |
1827 | 1654 |
1655 return 0; | |
1656 } | |
1657 | |
1658 #define DECODE_SLICE_ERROR -1 | |
1659 #define DECODE_SLICE_OK 0 | |
0 | 1660 |
1827 | 1661 /** |
1662 * decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode | |
1663 * @return DECODE_SLICE_ERROR if the slice is damaged<br> | |
1664 * DECODE_SLICE_OK if this slice is ok<br> | |
1665 */ | |
1666 static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, | |
1862 | 1667 const uint8_t **buf, int buf_size) |
1827 | 1668 { |
1669 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1670 AVCodecContext *avctx= s->avctx; | |
1671 const int field_pic= s->picture_structure != PICT_FRAME; | |
2256 | 1672 const int lowres= s->avctx->lowres; |
1827 | 1673 |
1674 s->resync_mb_x= | |
1675 s->resync_mb_y= -1; | |
1676 | |
1953 | 1677 if (mb_y<<field_pic >= s->mb_height){ |
1678 av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height); | |
1827 | 1679 return -1; |
1680 } | |
2967 | 1681 |
1211 | 1682 init_get_bits(&s->gb, *buf, buf_size*8); |
0 | 1683 |
1827 | 1684 ff_mpeg1_clean_buffers(s); |
1685 s->interlaced_dct = 0; | |
1686 | |
54 | 1687 s->qscale = get_qscale(s); |
1690 | 1688 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1689 if(s->qscale == 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1690 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n"); |
1285 | 1691 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
|
1692 } |
2967 | 1693 |
0 | 1694 /* extra slice info */ |
21 | 1695 while (get_bits1(&s->gb) != 0) { |
1696 skip_bits(&s->gb, 8); | |
0 | 1697 } |
2967 | 1698 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1699 s->mb_x=0; |
0 | 1700 |
716 | 1701 for(;;) { |
1702 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
|
1703 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1704 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); |
1285 | 1705 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
|
1706 } |
716 | 1707 if (code >= 33) { |
1708 if (code == 33) { | |
1709 s->mb_x += 33; | |
1710 } | |
1711 /* otherwise, stuffing, nothing to do */ | |
1712 } else { | |
1713 s->mb_x += code; | |
1714 break; | |
1715 } | |
1716 } | |
4502
ff5472c81ab8
fix segfault with lol-ffplay2.mpg (dunno if this is exploitable, probably not easily)
michael
parents:
4454
diff
changeset
|
1717 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
|
1718 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
|
1719 return -1; |
ff5472c81ab8
fix segfault with lol-ffplay2.mpg (dunno if this is exploitable, probably not easily)
michael
parents:
4454
diff
changeset
|
1720 } |
1827 | 1721 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1722 s->resync_mb_x= s->mb_x; |
1827 | 1723 s->resync_mb_y= s->mb_y= mb_y; |
1160 | 1724 s->mb_skip_run= 0; |
1389 | 1725 ff_init_block_index(s); |
716 | 1726 |
1827 | 1727 if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) { |
1728 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |
2967 | 1729 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 | 1730 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], |
6481 | 1731 s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), |
2967 | 1732 s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", |
1827 | 1733 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, |
1734 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); | |
1735 } | |
2967 | 1736 } |
1737 | |
0 | 1738 for(;;) { |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1739 #ifdef HAVE_XVMC |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1740 //one 1 we memcpy blocks in xvmcvideo |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1741 if(s->avctx->xvmc_acceleration > 1) |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1742 XVMC_init_block(s);//set s->block |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1743 #endif |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
1744 |
5431 | 1745 if(mpeg_decode_mb(s, s->block) < 0) |
0 | 1746 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
|
1747 |
1692 | 1748 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
|
1749 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
|
1750 int xy = s->mb_x*2 + s->mb_y*2*wrap; |
1841 | 1751 int motion_x, motion_y, dir, i; |
1692 | 1752 if(field_pic && !s->first_field) |
1753 xy += wrap/2; | |
1754 | |
1852 | 1755 for(i=0; i<2; i++){ |
1756 for(dir=0; dir<2; dir++){ | |
6481 | 1757 if (s->mb_intra || (dir==1 && s->pict_type != FF_B_TYPE)) { |
1841 | 1758 motion_x = motion_y = 0; |
1946 | 1759 }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){ |
1841 | 1760 motion_x = s->mv[dir][0][0]; |
1761 motion_y = s->mv[dir][0][1]; | |
1762 } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ { | |
1763 motion_x = s->mv[dir][i][0]; | |
1764 motion_y = s->mv[dir][i][1]; | |
1765 } | |
1948 | 1766 |
1841 | 1767 s->current_picture.motion_val[dir][xy ][0] = motion_x; |
1768 s->current_picture.motion_val[dir][xy ][1] = motion_y; | |
1769 s->current_picture.motion_val[dir][xy + 1][0] = motion_x; | |
1770 s->current_picture.motion_val[dir][xy + 1][1] = motion_y; | |
1948 | 1771 s->current_picture.ref_index [dir][xy ]= |
1772 s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i]; | |
2670 | 1773 assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1); |
1841 | 1774 } |
1852 | 1775 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
|
1776 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1777 } |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1655
diff
changeset
|
1778 |
2256 | 1779 s->dest[0] += 16 >> lowres; |
5430 | 1780 s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift; |
1781 s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift; | |
1389 | 1782 |
716 | 1783 MPV_decode_mb(s, s->block); |
2967 | 1784 |
716 | 1785 if (++s->mb_x >= s->mb_width) { |
2261 | 1786 const int mb_size= 16>>s->avctx->lowres; |
1380 | 1787 |
2261 | 1788 ff_draw_horiz_band(s, mb_size*s->mb_y, mb_size); |
716 | 1789 |
1790 s->mb_x = 0; | |
1791 s->mb_y++; | |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
1792 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
1793 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
|
1794 int left= s->gb.size_in_bits - get_bits_count(&s->gb); |
6481 | 1795 int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && avctx->profile==0 && avctx->level==5 |
3287 | 1796 && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0 |
1797 && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/; | |
1798 | |
1799 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
|
1800 || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){ |
3287 | 1801 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
|
1802 return -1; |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
1803 }else |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
1804 goto eos; |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
1805 } |
2967 | 1806 |
1389 | 1807 ff_init_block_index(s); |
716 | 1808 } |
1809 | |
1810 /* skip mb handling */ | |
1160 | 1811 if (s->mb_skip_run == -1) { |
716 | 1812 /* read again increment */ |
1160 | 1813 s->mb_skip_run = 0; |
716 | 1814 for(;;) { |
1815 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
|
1816 if (code < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1587
diff
changeset
|
1817 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n"); |
1181 | 1818 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
|
1819 } |
716 | 1820 if (code >= 33) { |
1821 if (code == 33) { | |
1160 | 1822 s->mb_skip_run += 33; |
1181 | 1823 }else if(code == 35){ |
1824 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
|
1825 av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n"); |
1181 | 1826 return -1; |
1827 } | |
1828 goto eos; /* end of slice */ | |
716 | 1829 } |
1830 /* otherwise, stuffing, nothing to do */ | |
1831 } else { | |
1160 | 1832 s->mb_skip_run += code; |
716 | 1833 break; |
1834 } | |
1835 } | |
5432
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1836 if(s->mb_skip_run){ |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1837 int i; |
6481 | 1838 if(s->pict_type == FF_I_TYPE){ |
5432
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1839 av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y); |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1840 return -1; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1841 } |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1842 |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1843 /* skip mb */ |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1844 s->mb_intra = 0; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1845 for(i=0;i<12;i++) |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1846 s->block_last_index[i] = -1; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1847 if(s->picture_structure == PICT_FRAME) |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1848 s->mv_type = MV_TYPE_16X16; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1849 else |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1850 s->mv_type = MV_TYPE_FIELD; |
6481 | 1851 if (s->pict_type == FF_P_TYPE) { |
5432
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1852 /* if P type, zero motion vector is implied */ |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1853 s->mv_dir = MV_DIR_FORWARD; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1854 s->mv[0][0][0] = s->mv[0][0][1] = 0; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1855 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1856 s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1857 s->field_select[0][0]= s->picture_structure - 1; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1858 } else { |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1859 /* if B type, reuse previous vectors and directions */ |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1860 s->mv[0][0][0] = s->last_mv[0][0][0]; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1861 s->mv[0][0][1] = s->last_mv[0][0][1]; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1862 s->mv[1][0][0] = s->last_mv[1][0][0]; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1863 s->mv[1][0][1] = s->last_mv[1][0][1]; |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1864 } |
e0624692025f
move some code which was executed for every skipped MB so it is only executed
michael
parents:
5431
diff
changeset
|
1865 } |
716 | 1866 } |
0 | 1867 } |
1285 | 1868 eos: // end of slice |
6372 | 1869 *buf += (get_bits_count(&s->gb)-1)/8; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1870 //printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y); |
1285 | 1871 return 0; |
1872 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1873 |
1827 | 1874 static int slice_decode_thread(AVCodecContext *c, void *arg){ |
1875 MpegEncContext *s= arg; | |
1861 | 1876 const uint8_t *buf= s->gb.buffer; |
1827 | 1877 int mb_y= s->start_mb_y; |
1878 | |
1879 s->error_count= 3*(s->end_mb_y - s->start_mb_y)*s->mb_width; | |
1880 | |
1881 for(;;){ | |
3776 | 1882 uint32_t start_code; |
1883 int ret; | |
1827 | 1884 |
1885 ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf); | |
1886 emms_c(); | |
2967 | 1887 //av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n", |
1827 | 1888 //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); |
1889 if(ret < 0){ | |
1890 if(s->resync_mb_x>=0 && s->resync_mb_y>=0) | |
1891 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); | |
1892 }else{ | |
1893 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); | |
1894 } | |
2967 | 1895 |
1827 | 1896 if(s->mb_y == s->end_mb_y) |
1897 return 0; | |
2967 | 1898 |
3086 | 1899 start_code= -1; |
1900 buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code); | |
1827 | 1901 mb_y= start_code - SLICE_MIN_START_CODE; |
1902 if(mb_y < 0 || mb_y >= s->end_mb_y) | |
1903 return -1; | |
1904 } | |
2967 | 1905 |
1827 | 1906 return 0; //not reached |
1907 } | |
1908 | |
1285 | 1909 /** |
1910 * handles slice ends. | |
2967 | 1911 * @return 1 if it seems to be the last slice of |
1285 | 1912 */ |
1913 static int slice_end(AVCodecContext *avctx, AVFrame *pict) | |
1914 { | |
1915 Mpeg1Context *s1 = avctx->priv_data; | |
1916 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
2967 | 1917 |
1402
f662e9c86cf2
* fixing a regression in mpeg encoder (not setting pix_fmt),
romansh
parents:
1389
diff
changeset
|
1918 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
|
1919 return 0; |
fc858abf6b10
fixed segfault if sequence header has not been found before slice decoding
bellard
parents:
1289
diff
changeset
|
1920 |
1381 | 1921 #ifdef HAVE_XVMC |
1922 if(s->avctx->xvmc_acceleration) | |
1923 XVMC_field_end(s); | |
1924 #endif | |
0 | 1925 /* end of slice reached */ |
1285 | 1926 if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) { |
0 | 1927 /* end of image */ |
903 | 1928 |
1728 | 1929 s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2; |
1196 | 1930 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1164
diff
changeset
|
1931 ff_er_frame_end(s); |
0 | 1932 |
1933 MPV_frame_end(s); | |
1934 | |
6481 | 1935 if (s->pict_type == FF_B_TYPE || s->low_delay) { |
1328 | 1936 *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
|
1937 ff_print_debug_info(s, pict); |
0 | 1938 } else { |
903 | 1939 s->picture_number++; |
0 | 1940 /* latency of 1 frame for I and P frames */ |
1941 /* XXX: use another variable than picture_number */ | |
1211 | 1942 if (s->last_picture_ptr != NULL) { |
1328 | 1943 *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
|
1944 ff_print_debug_info(s, pict); |
0 | 1945 } |
1946 } | |
1380 | 1947 |
1285 | 1948 return 1; |
0 | 1949 } else { |
1285 | 1950 return 0; |
0 | 1951 } |
1952 } | |
1953 | |
2967 | 1954 static int mpeg1_decode_sequence(AVCodecContext *avctx, |
1862 | 1955 const uint8_t *buf, int buf_size) |
0 | 1956 { |
1957 Mpeg1Context *s1 = avctx->priv_data; | |
1958 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
|
1959 int width,height; |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1960 int i, v, j; |
401
e20655449d4a
mpeg1/2 identifier - fixed frame rate for some bad mpeg1 streams
glantau
parents:
391
diff
changeset
|
1961 |
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
|
1962 init_get_bits(&s->gb, buf, buf_size*8); |
0 | 1963 |
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
|
1964 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
|
1965 height = get_bits(&s->gb, 12); |
6866 | 1966 if (width <= 0 || height <= 0) |
1890
a07406ac4725
mpeg12 fix 10l of aspect calucalations, return gop perser to print debug info, and make mpeg1_seq_header hot overwrite height/width
iive
parents:
1888
diff
changeset
|
1967 return -1; |
917 | 1968 s->aspect_ratio_info= get_bits(&s->gb, 4); |
6493
bed080a7ccbd
log aspect ratio forbidden value, and fail if error resilience is high
bcoudurier
parents:
6492
diff
changeset
|
1969 if (s->aspect_ratio_info == 0) { |
bed080a7ccbd
log aspect ratio forbidden value, and fail if error resilience is high
bcoudurier
parents:
6492
diff
changeset
|
1970 av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n"); |
bed080a7ccbd
log aspect ratio forbidden value, and fail if error resilience is high
bcoudurier
parents:
6492
diff
changeset
|
1971 if (avctx->error_resilience >= FF_ER_COMPLIANT) |
bed080a7ccbd
log aspect ratio forbidden value, and fail if error resilience is high
bcoudurier
parents:
6492
diff
changeset
|
1972 return -1; |
bed080a7ccbd
log aspect ratio forbidden value, and fail if error resilience is high
bcoudurier
parents:
6492
diff
changeset
|
1973 } |
0 | 1974 s->frame_rate_index = get_bits(&s->gb, 4); |
1837 | 1975 if (s->frame_rate_index == 0 || s->frame_rate_index > 13) |
0 | 1976 return -1; |
1977 s->bit_rate = get_bits(&s->gb, 18) * 400; | |
21 | 1978 if (get_bits1(&s->gb) == 0) /* marker */ |
0 | 1979 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
|
1980 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
|
1981 s->height = height; |
0 | 1982 |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
1983 s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16; |
21 | 1984 skip_bits(&s->gb, 1); |
0 | 1985 |
1986 /* get matrix */ | |
21 | 1987 if (get_bits1(&s->gb)) { |
0 | 1988 for(i=0;i<64;i++) { |
1989 v = get_bits(&s->gb, 8); | |
1809 | 1990 if(v==0){ |
1991 av_log(s->avctx, AV_LOG_ERROR, "intra matrix damaged\n"); | |
1992 return -1; | |
1993 } | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
1994 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
|
1995 s->intra_matrix[j] = v; |
5bf15419d47e
changed quant matrix order (should fix mmx mpeg decoding bug)
glantau
parents:
21
diff
changeset
|
1996 s->chroma_intra_matrix[j] = v; |
0 | 1997 } |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
1998 #ifdef DEBUG |
4652 | 1999 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
|
2000 for(i=0;i<64;i++) |
4652 | 2001 dprintf(s->avctx, " %d", s->intra_matrix[s->dsp.idct_permutation[i]]); |
2002 dprintf(s->avctx, "\n"); | |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2003 #endif |
0 | 2004 } else { |
2005 for(i=0;i<64;i++) { | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
2006 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
|
2007 v = ff_mpeg1_default_intra_matrix[i]; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2008 s->intra_matrix[j] = v; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2009 s->chroma_intra_matrix[j] = v; |
0 | 2010 } |
2011 } | |
21 | 2012 if (get_bits1(&s->gb)) { |
0 | 2013 for(i=0;i<64;i++) { |
2014 v = get_bits(&s->gb, 8); | |
1809 | 2015 if(v==0){ |
2016 av_log(s->avctx, AV_LOG_ERROR, "inter matrix damaged\n"); | |
2017 return -1; | |
2018 } | |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
2019 j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
344 | 2020 s->inter_matrix[j] = v; |
2021 s->chroma_inter_matrix[j] = v; | |
0 | 2022 } |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2023 #ifdef DEBUG |
4652 | 2024 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
|
2025 for(i=0;i<64;i++) |
4652 | 2026 dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]); |
2027 dprintf(s->avctx, "\n"); | |
59
efd3c19f6d62
fixed mpeg2 non intra dequant - fixed MPEG1 and 2 matrix parsing
glantau
parents:
58
diff
changeset
|
2028 #endif |
0 | 2029 } else { |
2030 for(i=0;i<64;i++) { | |
1092 | 2031 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
|
2032 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
|
2033 s->inter_matrix[j] = v; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
694
diff
changeset
|
2034 s->chroma_inter_matrix[j] = v; |
0 | 2035 } |
2036 } | |
2967 | 2037 |
1809 | 2038 if(show_bits(&s->gb, 23) != 0){ |
2039 av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n"); | |
2040 return -1; | |
2041 } | |
0 | 2042 |
2043 /* we set mpeg2 parameters so that it emulates mpeg1 */ | |
2044 s->progressive_sequence = 1; | |
2045 s->progressive_frame = 1; | |
2046 s->picture_structure = PICT_FRAME; | |
2047 s->frame_pred_frame_dct = 1; | |
1850 | 2048 s->chroma_format = 1; |
1421 | 2049 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
|
2050 avctx->sub_id = 1; /* indicates mpeg1 */ |
1888
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
2051 s->out_format = FMT_MPEG1; |
4bbe33eed9f0
move MPV_common_init after parsing stream parameters, matrix rebuild
iive
parents:
1880
diff
changeset
|
2052 s->swap_uv = 0;//AFAIK VCR2 don't have SEQ_HEADER |
1672 | 2053 if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; |
2967 | 2054 |
1710
4a68b20eeb2c
print vbv buffer size & bitrate when decoding with -debug 1
michael
parents:
1708
diff
changeset
|
2055 if(s->avctx->debug & FF_DEBUG_PICT_INFO) |
2967 | 2056 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
|
2057 s->avctx->rc_buffer_size, s->bit_rate); |
2967 | 2058 |
0 | 2059 return 0; |
2060 } | |
2061 | |
1376 | 2062 static int vcr2_init_sequence(AVCodecContext *avctx) |
2063 { | |
2064 Mpeg1Context *s1 = avctx->priv_data; | |
2065 MpegEncContext *s = &s1->mpeg_enc_ctx; | |
1377 | 2066 int i, v; |
1376 | 2067 |
2068 /* start new mpeg1 context decoding */ | |
2069 s->out_format = FMT_MPEG1; | |
2070 if (s1->mpeg_enc_ctx_allocated) { | |
2071 MPV_common_end(s); | |
2072 } | |
2270 | 2073 s->width = avctx->coded_width; |
2074 s->height = avctx->coded_height; | |
1376 | 2075 avctx->has_b_frames= 0; //true? |
1380 | 2076 s->low_delay= 1; |
1381 | 2077 |
1821 | 2078 if(avctx->xvmc_acceleration){ |
2079 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); | |
2080 }else{ | |
2081 avctx->pix_fmt = avctx->get_format(avctx,pixfmt_yuv_420); | |
2082 } | |
2083 | |
1381 | 2084 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
|
2085 if( avctx->idct_algo == FF_IDCT_AUTO ) |
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2086 avctx->idct_algo = FF_IDCT_SIMPLE; |
2967 | 2087 |
1376 | 2088 if (MPV_common_init(s) < 0) |
2089 return -1; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2090 exchange_uv(s);//common init reset pblocks, so we swap them here |
2967 | 2091 s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB |
1376 | 2092 s1->mpeg_enc_ctx_allocated = 1; |
2093 | |
2094 for(i=0;i<64;i++) { | |
2095 int j= s->dsp.idct_permutation[i]; | |
2096 v = ff_mpeg1_default_intra_matrix[i]; | |
2097 s->intra_matrix[j] = v; | |
2098 s->chroma_intra_matrix[j] = v; | |
2099 | |
2100 v = ff_mpeg1_default_non_intra_matrix[i]; | |
2101 s->inter_matrix[j] = v; | |
2102 s->chroma_inter_matrix[j] = v; | |
2103 } | |
2104 | |
2105 s->progressive_sequence = 1; | |
2106 s->progressive_frame = 1; | |
2107 s->picture_structure = PICT_FRAME; | |
2108 s->frame_pred_frame_dct = 1; | |
1850 | 2109 s->chroma_format = 1; |
1421 | 2110 s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; |
1377 | 2111 avctx->sub_id = 2; /* indicates mpeg2 */ |
1376 | 2112 return 0; |
2113 } | |
2114 | |
2115 | |
2967 | 2116 static void mpeg_decode_user_data(AVCodecContext *avctx, |
1084 | 2117 const uint8_t *buf, int buf_size) |
2118 { | |
2119 const uint8_t *p; | |
2120 int len, flags; | |
2121 p = buf; | |
2122 len = buf_size; | |
2123 | |
2124 /* we parse the DTG active format information */ | |
2125 if (len >= 5 && | |
2126 p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') { | |
2127 flags = p[4]; | |
2128 p += 5; | |
2129 len -= 5; | |
2130 if (flags & 0x80) { | |
2131 /* skip event id */ | |
2132 if (len < 2) | |
2133 return; | |
2134 p += 2; | |
2135 len -= 2; | |
2136 } | |
2137 if (flags & 0x40) { | |
2138 if (len < 1) | |
2139 return; | |
2140 avctx->dtg_active_format = p[0] & 0x0f; | |
2141 } | |
2142 } | |
2143 } | |
2144 | |
2967 | 2145 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
|
2146 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
|
2147 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
|
2148 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
|
2149 |
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
|
2150 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
|
2151 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
|
2152 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
|
2153 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
|
2154 |
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
|
2155 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
|
2156 |
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
|
2157 drop_frame_flag = get_bits1(&s->gb); |
2967 | 2158 |
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
|
2159 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
|
2160 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
|
2161 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
|
2162 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
|
2163 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
|
2164 |
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
|
2165 /*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
|
2166 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
|
2167 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
|
2168 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
|
2169 |
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
|
2170 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
|
2171 av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) broken_link=%d\n", |
2979 | 2172 time_code_hours, time_code_minutes, time_code_seconds, |
2173 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
|
2174 } |
1211 | 2175 /** |
2176 * finds the end of the current frame in the bitstream. | |
2177 * @return the position of the first byte of the next frame, or -1 | |
2178 */ | |
4916
13ef168891b0
add a ff_ prefix to the now exported mpeg1_find_frame_end() function
aurel
parents:
4915
diff
changeset
|
2179 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) |
1988 | 2180 { |
1211 | 2181 int i; |
3086 | 2182 uint32_t state= pc->state; |
2967 | 2183 |
6380
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2184 /* EOF considered as end of frame */ |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2185 if (buf_size == 0) |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2186 return 0; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2187 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2188 /* |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2189 0 frame start -> 1/4 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2190 1 first_SEQEXT -> 0/2 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2191 2 first field start -> 3/0 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2192 3 second_SEQEXT -> 2/0 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2193 4 searching end |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2194 */ |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2195 |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2196 for(i=0; i<buf_size; i++){ |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2197 assert(pc->frame_start_found>=0 && pc->frame_start_found<=4); |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2198 if(pc->frame_start_found&1){ |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2199 if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80) |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2200 pc->frame_start_found--; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2201 else if(state == EXT_START_CODE+2){ |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2202 if((buf[i]&3) == 3) pc->frame_start_found= 0; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2203 else pc->frame_start_found= (pc->frame_start_found+1)&3; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2204 } |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2205 state++; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2206 }else{ |
3086 | 2207 i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; |
6380
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2208 if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ |
1211 | 2209 i++; |
6380
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2210 pc->frame_start_found=4; |
1211 | 2211 } |
5449 | 2212 if(state == SEQ_END_CODE){ |
2213 pc->state=-1; | |
2214 return i+1; | |
2215 } | |
6380
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2216 if(pc->frame_start_found==2 && state == SEQ_START_CODE) |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2217 pc->frame_start_found= 0; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2218 if(pc->frame_start_found<4 && state == EXT_START_CODE) |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2219 pc->frame_start_found++; |
464938b9c2b0
Make find_frame_end() merge 2 mpeg2 field pictures. This should make mpeg2
michael
parents:
6372
diff
changeset
|
2220 if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){ |
1211 | 2221 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ |
2222 pc->frame_start_found=0; | |
2967 | 2223 pc->state=-1; |
1211 | 2224 return i-3; |
2225 } | |
2226 } | |
2227 } | |
2967 | 2228 } |
1211 | 2229 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
|
2230 return END_NOT_FOUND; |
1211 | 2231 } |
2232 | |
6562 | 2233 static int decode_chunks(AVCodecContext *avctx, |
2234 AVFrame *picture, int *data_size, | |
2235 const uint8_t *buf, int buf_size); | |
2236 | |
0 | 2237 /* handle buffering and image synchronisation */ |
2967 | 2238 static int mpeg_decode_frame(AVCodecContext *avctx, |
0 | 2239 void *data, int *data_size, |
6220 | 2240 const uint8_t *buf, int buf_size) |
0 | 2241 { |
2242 Mpeg1Context *s = avctx->priv_data; | |
925 | 2243 AVFrame *picture = data; |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2244 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
4652 | 2245 dprintf(avctx, "fill_buffer\n"); |
0 | 2246 |
5449 | 2247 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) { |
2979 | 2248 /* special case for last picture */ |
2249 if (s2->low_delay==0 && s2->next_picture_ptr) { | |
2250 *picture= *(AVFrame*)s2->next_picture_ptr; | |
2251 s2->next_picture_ptr= NULL; | |
2252 | |
2253 *data_size = sizeof(AVFrame); | |
2254 } | |
5814
14a9ceb162d2
Prevent infinite loop when buffer holds SEQ_END_CODE only. Fix for r9870
ramiro
parents:
5458
diff
changeset
|
2255 return buf_size; |
0 | 2256 } |
2257 | |
1211 | 2258 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
|
2259 int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); |
2967 | 2260 |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4916
diff
changeset
|
2261 if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) |
1211 | 2262 return buf_size; |
2967 | 2263 } |
2264 | |
2265 #if 0 | |
2266 if (s->repeat_field % 2 == 1) { | |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2267 s->repeat_field++; |
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2268 //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
|
2269 // s2->picture_number, s->repeat_field); |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2270 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
|
2271 *data_size = sizeof(AVPicture); |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2272 goto the_end; |
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2273 } |
267
e10840e4f773
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
pulento
parents:
241
diff
changeset
|
2274 } |
383
e6b64bc3bc87
- repeat_pict meaning changed, now it signals the extra delay for the
pulento
parents:
377
diff
changeset
|
2275 #endif |
1376 | 2276 |
2277 if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2")) | |
2278 vcr2_init_sequence(avctx); | |
2967 | 2279 |
1827 | 2280 s->slice_count= 0; |
2967 | 2281 |
6563 | 2282 if(avctx->extradata && !avctx->frame_number) |
2283 decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size); | |
2284 | |
6562 | 2285 return decode_chunks(avctx, picture, data_size, buf, buf_size); |
2286 } | |
2287 | |
2288 static int decode_chunks(AVCodecContext *avctx, | |
2289 AVFrame *picture, int *data_size, | |
2290 const uint8_t *buf, int buf_size) | |
2291 { | |
2292 Mpeg1Context *s = avctx->priv_data; | |
2293 MpegEncContext *s2 = &s->mpeg_enc_ctx; | |
2294 const uint8_t *buf_ptr = buf; | |
2295 const uint8_t *buf_end = buf + buf_size; | |
2296 int ret, input_size; | |
2297 | |
1211 | 2298 for(;;) { |
0 | 2299 /* find start next code */ |
6562 | 2300 uint32_t start_code = -1; |
3086 | 2301 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); |
3776 | 2302 if (start_code > 0x1ff){ |
6481 | 2303 if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ |
1827 | 2304 if(avctx->thread_count > 1){ |
2305 int i; | |
2306 | |
2307 avctx->execute(avctx, slice_decode_thread, (void**)&(s2->thread_context[0]), NULL, s->slice_count); | |
2308 for(i=0; i<s->slice_count; i++) | |
2309 s2->error_count += s2->thread_context[i]->error_count; | |
2310 } | |
1484 | 2311 if (slice_end(avctx, picture)) { |
1672 | 2312 if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice |
1484 | 2313 *data_size = sizeof(AVPicture); |
2314 } | |
1285 | 2315 } |
1220 | 2316 return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); |
0 | 2317 } |
2967 | 2318 |
1289
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2319 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
|
2320 |
57172377849a
fix mpeg1/2 decoding if there are no 0 bytes after the bitstream
michaelni
parents:
1285
diff
changeset
|
2321 if(avctx->debug & FF_DEBUG_STARTCODE){ |
6494
1144fc79b912
Use correct t printf modifier for pointer differences.
diego
parents:
6493
diff
changeset
|
2322 av_log(avctx, AV_LOG_DEBUG, "%3X at %td 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
|
2323 } |
1211 | 2324 |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2325 /* prepare data for next start code */ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2326 switch(start_code) { |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2327 case SEQ_START_CODE: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2328 mpeg1_decode_sequence(avctx, buf_ptr, |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2329 input_size); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2330 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2331 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2332 case PICTURE_START_CODE: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2333 /* 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
|
2334 mpeg1_decode_picture(avctx, |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2335 buf_ptr, input_size); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2336 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2337 case EXT_START_CODE: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2338 mpeg_decode_extension(avctx, |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2339 buf_ptr, input_size); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2340 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2341 case USER_START_CODE: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2342 mpeg_decode_user_data(avctx, |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2343 buf_ptr, input_size); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2344 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2345 case GOP_START_CODE: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2346 s2->first_field=0; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2347 mpeg_decode_gop(avctx, |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2348 buf_ptr, input_size); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2349 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2350 default: |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2351 if (start_code >= SLICE_MIN_START_CODE && |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2352 start_code <= SLICE_MAX_START_CODE) { |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2353 int mb_y= start_code - SLICE_MIN_START_CODE; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2354 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2355 if(s2->last_picture_ptr==NULL){ |
5127 | 2356 /* Skip B-frames if we do not have reference frames. */ |
6481 | 2357 if(s2->pict_type==FF_B_TYPE) break; |
6109 | 2358 } |
2359 if(s2->next_picture_ptr==NULL){ | |
5127 | 2360 /* Skip P-frames if we do not have reference frame no valid header. */ |
6481 | 2361 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2362 } |
5127 | 2363 /* Skip B-frames if we are in a hurry. */ |
6481 | 2364 if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; |
2365 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) | |
2366 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE) | |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2367 || avctx->skip_frame >= AVDISCARD_ALL) |
0 | 2368 break; |
5127 | 2369 /* 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
|
2370 if(avctx->hurry_up>=5) break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2371 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2372 if (!s->mpeg_enc_ctx_allocated) break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2373 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2374 if(s2->codec_id == CODEC_ID_MPEG2VIDEO){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2375 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
|
2376 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2377 } |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2378 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2379 if(s2->first_slice){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2380 s2->first_slice=0; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2381 if(mpeg_field_start(s2) < 0) |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2382 return -1; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2383 } |
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
|
2384 if(!s2->current_picture_ptr){ |
5129 | 2385 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
|
2386 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
|
2387 } |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2388 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2389 if(avctx->thread_count > 1){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2390 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
|
2391 if(threshold <= mb_y){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2392 MpegEncContext *thread_context= s2->thread_context[s->slice_count]; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2393 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2394 thread_context->start_mb_y= mb_y; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2395 thread_context->end_mb_y = s2->mb_height; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2396 if(s->slice_count){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2397 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
|
2398 ff_update_duplicate_context(thread_context, s2); |
2786 | 2399 } |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2400 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
|
2401 s->slice_count++; |
0 | 2402 } |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2403 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
|
2404 }else{ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2405 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
|
2406 emms_c(); |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2407 |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2408 if(ret < 0){ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2409 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
|
2410 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
|
2411 }else{ |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2412 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
|
2413 } |
0 | 2414 } |
4119
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2415 } |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2416 break; |
85438e10d72d
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
4070
diff
changeset
|
2417 } |
0 | 2418 } |
2419 } | |
2420 | |
2421 static int mpeg_decode_end(AVCodecContext *avctx) | |
2422 { | |
2423 Mpeg1Context *s = avctx->priv_data; | |
2424 | |
2425 if (s->mpeg_enc_ctx_allocated) | |
2426 MPV_common_end(&s->mpeg_enc_ctx); | |
2427 return 0; | |
2428 } | |
2429 | |
1423 | 2430 AVCodec mpeg1video_decoder = { |
2431 "mpeg1video", | |
0 | 2432 CODEC_TYPE_VIDEO, |
2433 CODEC_ID_MPEG1VIDEO, | |
2434 sizeof(Mpeg1Context), | |
2435 mpeg_decode_init, | |
2436 NULL, | |
2437 mpeg_decode_end, | |
2438 mpeg_decode_frame, | |
2453 | 2439 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
1368 | 2440 .flush= ff_mpeg_flush, |
6717 | 2441 .long_name= "MPEG-1 video", |
0 | 2442 }; |
1381 | 2443 |
1423 | 2444 AVCodec mpeg2video_decoder = { |
2445 "mpeg2video", | |
2446 CODEC_TYPE_VIDEO, | |
2447 CODEC_ID_MPEG2VIDEO, | |
2448 sizeof(Mpeg1Context), | |
2449 mpeg_decode_init, | |
2450 NULL, | |
2451 mpeg_decode_end, | |
2452 mpeg_decode_frame, | |
2453 | 2453 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
1423 | 2454 .flush= ff_mpeg_flush, |
6717 | 2455 .long_name= "MPEG-2 video", |
1423 | 2456 }; |
2457 | |
1615 | 2458 //legacy decoder |
2459 AVCodec mpegvideo_decoder = { | |
2460 "mpegvideo", | |
2461 CODEC_TYPE_VIDEO, | |
2462 CODEC_ID_MPEG2VIDEO, | |
2463 sizeof(Mpeg1Context), | |
2464 mpeg_decode_init, | |
2465 NULL, | |
2466 mpeg_decode_end, | |
2467 mpeg_decode_frame, | |
2453 | 2468 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
1615 | 2469 .flush= ff_mpeg_flush, |
6717 | 2470 .long_name= "MPEG-1 video", |
1615 | 2471 }; |
2472 | |
1381 | 2473 #ifdef HAVE_XVMC |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6494
diff
changeset
|
2474 static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ |
1381 | 2475 Mpeg1Context *s; |
2476 | |
2967 | 2477 if( avctx->thread_count > 1) |
2076 | 2478 return -1; |
1381 | 2479 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) |
2480 return -1; | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1550
diff
changeset
|
2481 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){ |
4652 | 2482 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
|
2483 } |
1381 | 2484 mpeg_decode_init(avctx); |
2485 s = avctx->priv_data; | |
2486 | |
2487 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
|
2488 avctx->xvmc_acceleration = 2;//2 - the blocks are packed! |
1381 | 2489 |
2490 return 0; | |
2491 } | |
2492 | |
2493 AVCodec mpeg_xvmc_decoder = { | |
2494 "mpegvideo_xvmc", | |
2495 CODEC_TYPE_VIDEO, | |
2496 CODEC_ID_MPEG2VIDEO_XVMC, | |
2497 sizeof(Mpeg1Context), | |
2498 mpeg_mc_decode_init, | |
2499 NULL, | |
2500 mpeg_decode_end, | |
2501 mpeg_decode_frame, | |
2453 | 2502 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
|
2503 .flush= ff_mpeg_flush, |
6717 | 2504 .long_name = "MPEG-1 video XvMC (X-Video Motion Compensation)", |
1381 | 2505 }; |
2506 | |
2507 #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
|
2508 |
2967 | 2509 /* 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
|
2510 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
|
2511 which is far uglier. */ |
2967 | 2512 #include "mdec.c" |