Mercurial > libavcodec.hg
annotate h263dec.c @ 664:00a882f626bd libavcodec
interlaced mpeg4 b frame decoding
| author | michaelni |
|---|---|
| date | Fri, 13 Sep 2002 09:45:32 +0000 |
| parents | dc8df8792a24 |
| children | b4bddbde44f3 |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * H263 decoder | |
| 429 | 3 * Copyright (c) 2001 Fabrice Bellard. |
| 0 | 4 * |
| 429 | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 0 | 9 * |
| 429 | 10 * This library is distributed in the hope that it will be useful, |
| 0 | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 429 | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Lesser General Public License for more details. | |
| 0 | 14 * |
| 429 | 15 * You should have received a copy of the GNU Lesser General Public |
| 16 * License along with this library; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 0 | 18 */ |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
384
diff
changeset
|
19 #include "avcodec.h" |
| 0 | 20 #include "dsputil.h" |
| 21 #include "mpegvideo.h" | |
| 22 | |
| 23 //#define DEBUG | |
| 384 | 24 //#define PRINT_FRAME_TIME |
| 25 #ifdef PRINT_FRAME_TIME | |
| 26 static inline long long rdtsc() | |
| 27 { | |
| 28 long long l; | |
| 29 asm volatile( "rdtsc\n\t" | |
| 30 : "=A" (l) | |
| 31 ); | |
| 32 // printf("%d\n", int(l/1000)); | |
| 33 return l; | |
| 34 } | |
| 35 #endif | |
| 0 | 36 |
| 37 static int h263_decode_init(AVCodecContext *avctx) | |
| 38 { | |
| 39 MpegEncContext *s = avctx->priv_data; | |
| 60 | 40 |
| 67 | 41 s->avctx = avctx; |
| 0 | 42 s->out_format = FMT_H263; |
| 43 | |
| 44 s->width = avctx->width; | |
| 45 s->height = avctx->height; | |
|
411
5c8b3a717929
workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents:
396
diff
changeset
|
46 s->workaround_bugs= avctx->workaround_bugs; |
| 0 | 47 |
| 48 /* select sub codec */ | |
| 49 switch(avctx->codec->id) { | |
| 50 case CODEC_ID_H263: | |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
51 s->gob_number = 0; |
| 454 | 52 s->first_slice_line = 0; |
| 0 | 53 break; |
| 67 | 54 case CODEC_ID_MPEG4: |
| 0 | 55 s->time_increment_bits = 4; /* default value for broken headers */ |
| 56 s->h263_pred = 1; | |
| 336 | 57 s->has_b_frames = 1; //default, might be overriden in the vol header during header parsing |
| 0 | 58 break; |
| 307 | 59 case CODEC_ID_MSMPEG4V1: |
| 0 | 60 s->h263_msmpeg4 = 1; |
| 61 s->h263_pred = 1; | |
| 307 | 62 s->msmpeg4_version=1; |
| 63 break; | |
| 64 case CODEC_ID_MSMPEG4V2: | |
| 65 s->h263_msmpeg4 = 1; | |
| 66 s->h263_pred = 1; | |
| 67 s->msmpeg4_version=2; | |
| 68 break; | |
| 69 case CODEC_ID_MSMPEG4V3: | |
| 70 s->h263_msmpeg4 = 1; | |
| 71 s->h263_pred = 1; | |
| 72 s->msmpeg4_version=3; | |
| 0 | 73 break; |
| 311 | 74 case CODEC_ID_WMV1: |
| 75 s->h263_msmpeg4 = 1; | |
| 76 s->h263_pred = 1; | |
| 77 s->msmpeg4_version=4; | |
| 78 break; | |
| 498 | 79 case CODEC_ID_WMV2: |
| 80 s->h263_msmpeg4 = 1; | |
| 81 s->h263_pred = 1; | |
| 82 s->msmpeg4_version=5; | |
| 83 break; | |
| 0 | 84 case CODEC_ID_H263I: |
| 85 s->h263_intel = 1; | |
| 86 break; | |
| 87 default: | |
| 88 return -1; | |
| 89 } | |
| 344 | 90 s->codec_id= avctx->codec->id; |
| 553 | 91 |
| 0 | 92 /* for h263, we allocate the images after having read the header */ |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
93 if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4) |
| 144 | 94 if (MPV_common_init(s) < 0) |
| 95 return -1; | |
| 0 | 96 |
| 97 if (s->h263_msmpeg4) | |
| 498 | 98 ff_msmpeg4_decode_init(s); |
| 0 | 99 else |
| 100 h263_decode_init_vlc(s); | |
| 101 | |
| 102 return 0; | |
| 103 } | |
| 104 | |
| 105 static int h263_decode_end(AVCodecContext *avctx) | |
| 106 { | |
| 107 MpegEncContext *s = avctx->priv_data; | |
| 108 | |
| 109 MPV_common_end(s); | |
| 110 return 0; | |
| 111 } | |
| 112 | |
| 655 | 113 /** |
| 114 * retunrs the number of bytes consumed for building the current frame | |
| 115 */ | |
| 116 static int get_consumed_bytes(MpegEncContext *s, int buf_size){ | |
| 117 int pos= (get_bits_count(&s->gb)+7)>>3; | |
| 118 | |
| 119 if(s->divx_version>=500){ | |
| 120 //we would have to scan through the whole buf to handle the weird reordering ... | |
| 121 return buf_size; | |
| 122 }else{ | |
| 123 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) | |
| 658 | 124 if(pos+10>buf_size) pos=buf_size; // oops ;) |
| 655 | 125 |
| 126 return pos; | |
| 127 } | |
| 128 } | |
| 129 | |
| 0 | 130 static int h263_decode_frame(AVCodecContext *avctx, |
| 131 void *data, int *data_size, | |
| 132 UINT8 *buf, int buf_size) | |
| 133 { | |
| 134 MpegEncContext *s = avctx->priv_data; | |
| 135 int ret; | |
| 136 AVPicture *pict = data; | |
| 384 | 137 #ifdef PRINT_FRAME_TIME |
| 138 uint64_t time= rdtsc(); | |
| 139 #endif | |
| 0 | 140 #ifdef DEBUG |
| 141 printf("*****frame %d size=%d\n", avctx->frame_number, buf_size); | |
| 142 printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); | |
| 143 #endif | |
| 345 | 144 |
| 145 s->hurry_up= avctx->hurry_up; | |
| 454 | 146 s->error_resilience= avctx->error_resilience; |
| 147 s->workaround_bugs= avctx->workaround_bugs; | |
| 485 | 148 s->flags= avctx->flags; |
| 454 | 149 |
| 657 | 150 *data_size = 0; |
| 151 | |
| 152 /* no supplementary picture */ | |
| 0 | 153 if (buf_size == 0) { |
| 154 return 0; | |
| 155 } | |
| 156 | |
| 465 | 157 if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder |
| 333 | 158 init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size); |
| 353 | 159 }else |
| 333 | 160 init_get_bits(&s->gb, buf, buf_size); |
| 465 | 161 s->bitstream_buffer_size=0; |
| 0 | 162 |
| 163 /* let's go :-) */ | |
| 164 if (s->h263_msmpeg4) { | |
| 165 ret = msmpeg4_decode_picture_header(s); | |
| 166 } else if (s->h263_pred) { | |
| 167 ret = mpeg4_decode_picture_header(s); | |
| 336 | 168 s->has_b_frames= !s->low_delay; |
| 0 | 169 } else if (s->h263_intel) { |
| 170 ret = intel_h263_decode_picture_header(s); | |
| 171 } else { | |
| 172 ret = h263_decode_picture_header(s); | |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
173 } |
| 556 | 174 avctx->has_b_frames= s->has_b_frames; |
|
585
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
175 #if 0 // dump bits per frame / qp / complexity |
|
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
176 { |
|
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
177 static FILE *f=NULL; |
|
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
178 if(!f) f=fopen("rate_qp_cplx.txt", "w"); |
|
589
507e688d57b2
10l found by R?mi Guyomarch <rguyom at pobox dot com>
michaelni
parents:
585
diff
changeset
|
179 fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale); |
|
585
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
180 } |
|
86ebb02c6693
dump bits per frame / qp / frame complexity support
michaelni
parents:
562
diff
changeset
|
181 #endif |
| 553 | 182 |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
183 /* After H263 & mpeg4 header decode we have the height, width,*/ |
| 160 | 184 /* and other parameters. So then we could init the picture */ |
| 185 /* FIXME: By the way H263 decoder is evolving it should have */ | |
| 186 /* an H263EncContext */ | |
| 553 | 187 if (s->width != avctx->width || s->height != avctx->height) { |
| 188 /* H.263 could change picture size any time */ | |
| 189 MPV_common_end(s); | |
| 190 s->context_initialized=0; | |
| 191 } | |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
192 if (!s->context_initialized) { |
|
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
193 avctx->width = s->width; |
|
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
194 avctx->height = s->height; |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
274
diff
changeset
|
195 avctx->aspect_ratio_info= s->aspect_ratio_info; |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
196 if (MPV_common_init(s) < 0) |
|
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
197 return -1; |
| 0 | 198 } |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
273
diff
changeset
|
199 |
| 655 | 200 if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_size); |
| 454 | 201 /* skip if the header was thrashed */ |
| 498 | 202 if (ret < 0){ |
| 203 fprintf(stderr, "header damaged\n"); | |
| 0 | 204 return -1; |
| 498 | 205 } |
| 341 | 206 /* skip b frames if we dont have reference frames */ |
| 655 | 207 if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size); |
| 345 | 208 /* skip b frames if we are in a hurry */ |
| 655 | 209 if(s->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size); |
| 454 | 210 |
| 211 if(s->next_p_frame_damaged){ | |
| 212 if(s->pict_type==B_TYPE) | |
| 655 | 213 return get_consumed_bytes(s, buf_size); |
| 454 | 214 else |
| 215 s->next_p_frame_damaged=0; | |
| 216 } | |
| 217 | |
| 553 | 218 MPV_frame_start(s, avctx); |
| 0 | 219 |
| 220 #ifdef DEBUG | |
| 221 printf("qscale=%d\n", s->qscale); | |
| 222 #endif | |
| 223 | |
| 454 | 224 /* init resync/ error resilience specific variables */ |
| 225 s->next_resync_qscale= s->qscale; | |
| 226 s->next_resync_gb= s->gb; | |
| 227 if(s->resync_marker) s->mb_num_left= 0; | |
| 228 else s->mb_num_left= s->mb_num; | |
| 229 | |
| 0 | 230 /* decode each macroblock */ |
| 266 | 231 s->block_wrap[0]= |
| 232 s->block_wrap[1]= | |
| 233 s->block_wrap[2]= | |
| 234 s->block_wrap[3]= s->mb_width*2 + 2; | |
| 235 s->block_wrap[4]= | |
| 236 s->block_wrap[5]= s->mb_width + 2; | |
| 0 | 237 for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { |
| 162 | 238 /* Check for GOB headers on H.263 */ |
| 239 /* FIXME: In the future H.263+ will have intra prediction */ | |
| 240 /* and we are gonna need another way to detect MPEG4 */ | |
| 241 if (s->mb_y && !s->h263_pred) { | |
| 454 | 242 s->first_slice_line = h263_decode_gob_header(s); |
| 243 } | |
| 244 | |
| 245 if(s->msmpeg4_version==1){ | |
| 246 s->last_dc[0]= | |
| 247 s->last_dc[1]= | |
| 248 s->last_dc[2]= 128; | |
| 162 | 249 } |
| 296 | 250 |
| 498 | 251 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
| 252 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
| 253 | |
| 266 | 254 s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1; |
| 255 s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1); | |
| 256 s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1; | |
| 257 s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2); | |
| 258 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 259 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 0 | 260 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { |
| 266 | 261 s->block_index[0]+=2; |
| 262 s->block_index[1]+=2; | |
| 263 s->block_index[2]+=2; | |
| 264 s->block_index[3]+=2; | |
| 265 s->block_index[4]++; | |
| 266 s->block_index[5]++; | |
| 0 | 267 #ifdef DEBUG |
| 268 printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); | |
| 269 #endif | |
| 454 | 270 |
| 271 if(s->resync_marker){ | |
| 272 if(s->mb_num_left<=0){ | |
| 273 /* except the first block */ | |
| 274 if(s->mb_x!=0 || s->mb_y!=0){ | |
| 275 /* did we miss the next resync marker without noticing an error yet */ | |
| 276 if(((get_bits_count(&s->gb)+8)&(~7)) != s->next_resync_pos && s->decoding_error==0){ | |
| 277 fprintf(stderr, "slice end missmatch x:%d y:%d %d %d\n", | |
| 278 s->mb_x, s->mb_y, get_bits_count(&s->gb), s->next_resync_pos); | |
| 279 ff_conceal_past_errors(s, 1); | |
| 280 } | |
| 281 } | |
| 282 s->qscale= s->next_resync_qscale; | |
| 498 | 283 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
| 284 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
| 285 | |
| 454 | 286 s->gb= s->next_resync_gb; |
| 287 s->resync_mb_x= s->mb_x; //we know that the marker is here cuz mb_num_left was the distance to it | |
| 288 s->resync_mb_y= s->mb_y; | |
| 289 s->first_slice_line=1; | |
| 290 | |
| 291 if(s->codec_id==CODEC_ID_MPEG4){ | |
| 292 ff_mpeg4_clean_buffers(s); | |
| 293 ff_mpeg4_resync(s); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 if( s->resync_mb_x==s->mb_x | |
| 298 && s->resync_mb_y==s->mb_y && s->decoding_error!=0){ | |
| 299 fprintf(stderr, "resynced at %d %d\n", s->mb_x, s->mb_y); | |
| 300 s->decoding_error= 0; | |
| 301 } | |
| 302 } | |
| 303 | |
| 144 | 304 //fprintf(stderr,"\nFrame: %d\tMB: %d",avctx->frame_number, (s->mb_y * s->mb_width) + s->mb_x); |
| 0 | 305 /* DCT & quantize */ |
| 454 | 306 if(s->decoding_error!=DECODING_DESYNC){ |
| 307 int last_error= s->decoding_error; | |
| 308 clear_blocks(s->block[0]); | |
| 296 | 309 |
| 454 | 310 s->mv_dir = MV_DIR_FORWARD; |
| 311 s->mv_type = MV_TYPE_16X16; | |
| 312 if (s->h263_msmpeg4) { | |
| 313 if (msmpeg4_decode_mb(s, s->block) < 0) { | |
| 314 fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
| 315 s->decoding_error=DECODING_DESYNC; | |
| 316 } | |
| 317 } else { | |
| 318 if (h263_decode_mb(s, s->block) < 0) { | |
| 319 fprintf(stderr,"Error at MB: %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
| 320 s->decoding_error=DECODING_DESYNC; | |
| 321 } | |
| 322 } | |
| 323 | |
| 324 if(s->decoding_error!=last_error){ | |
| 325 ff_conceal_past_errors(s, 0); | |
| 161 | 326 } |
| 0 | 327 } |
| 454 | 328 |
| 329 /* conceal errors */ | |
| 330 if( s->decoding_error==DECODING_DESYNC | |
| 331 || (s->decoding_error==DECODING_ACDC_LOST && s->mb_intra)){ | |
| 332 s->mv_dir = MV_DIR_FORWARD; | |
| 333 s->mv_type = MV_TYPE_16X16; | |
| 334 s->mb_skiped=0; | |
| 335 s->mb_intra=0; | |
| 336 s->mv[0][0][0]=0; //FIXME this is not optimal | |
| 337 s->mv[0][0][1]=0; | |
| 338 clear_blocks(s->block[0]); | |
| 339 }else if(s->decoding_error && !s->mb_intra){ | |
| 340 clear_blocks(s->block[0]); | |
| 341 } | |
| 342 //FIXME remove AC for intra | |
| 343 | |
|
12
4d50c7d89e0f
use block[] in structure to have it aligned on 8 bytes for mmx optimizations
glantau
parents:
0
diff
changeset
|
344 MPV_decode_mb(s, s->block); |
| 454 | 345 |
| 346 s->mb_num_left--; | |
| 0 | 347 } |
| 341 | 348 if ( avctx->draw_horiz_band |
| 349 && (s->num_available_buffers>=1 || (!s->has_b_frames)) ) { | |
| 67 | 350 UINT8 *src_ptr[3]; |
| 351 int y, h, offset; | |
| 352 y = s->mb_y * 16; | |
| 353 h = s->height - y; | |
| 354 if (h > 16) | |
| 355 h = 16; | |
| 356 offset = y * s->linesize; | |
| 308 | 357 if(s->pict_type==B_TYPE || (!s->has_b_frames)){ |
| 358 src_ptr[0] = s->current_picture[0] + offset; | |
| 359 src_ptr[1] = s->current_picture[1] + (offset >> 2); | |
| 360 src_ptr[2] = s->current_picture[2] + (offset >> 2); | |
| 361 } else { | |
| 362 src_ptr[0] = s->last_picture[0] + offset; | |
| 363 src_ptr[1] = s->last_picture[1] + (offset >> 2); | |
| 364 src_ptr[2] = s->last_picture[2] + (offset >> 2); | |
| 365 } | |
| 67 | 366 avctx->draw_horiz_band(avctx, src_ptr, s->linesize, |
| 367 y, s->width, h); | |
| 368 } | |
| 0 | 369 } |
| 208 | 370 |
| 311 | 371 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE) |
| 208 | 372 if(msmpeg4_decode_ext_header(s, buf_size) < 0) return -1; |
| 333 | 373 |
| 374 /* divx 5.01+ bistream reorder stuff */ | |
| 655 | 375 if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_version>=500){ |
| 454 | 376 int current_pos= get_bits_count(&s->gb)>>3; |
| 377 | |
| 333 | 378 if( buf_size - current_pos > 5 |
| 379 && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){ | |
| 454 | 380 int i; |
| 381 int startcode_found=0; | |
| 655 | 382 for(i=current_pos; i<buf_size-3; i++){ |
| 454 | 383 if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){ |
| 384 startcode_found=1; | |
| 385 break; | |
| 386 } | |
| 387 } | |
| 388 if(startcode_found){ | |
| 389 memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos); | |
| 390 s->bitstream_buffer_size= buf_size - current_pos; | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 if(s->bitstream_buffer_size==0 && s->error_resilience>0){ | |
| 396 int left= s->gb.size*8 - get_bits_count(&s->gb); | |
| 397 int max_extra=8; | |
| 398 | |
| 399 if(s->codec_id==CODEC_ID_MPEG4) max_extra+=32; | |
| 400 | |
| 401 if(left>max_extra){ | |
| 402 fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24)); | |
| 403 if(s->decoding_error==0) | |
| 404 ff_conceal_past_errors(s, 1); | |
| 405 } | |
| 406 if(left<0){ | |
| 407 fprintf(stderr, "overreading %d bits\n", -left); | |
| 408 if(s->decoding_error==0) | |
| 409 ff_conceal_past_errors(s, 1); | |
| 333 | 410 } |
| 353 | 411 } |
| 333 | 412 |
| 0 | 413 MPV_frame_end(s); |
| 361 | 414 #if 0 //dirty show MVs, we should export the MV tables and write a filter to show them |
| 415 { | |
| 416 int mb_y; | |
| 417 s->has_b_frames=1; | |
| 418 for(mb_y=0; mb_y<s->mb_height; mb_y++){ | |
| 419 int mb_x; | |
|
411
5c8b3a717929
workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents:
396
diff
changeset
|
420 int y= mb_y*16 + 8; |
| 361 | 421 for(mb_x=0; mb_x<s->mb_width; mb_x++){ |
|
411
5c8b3a717929
workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents:
396
diff
changeset
|
422 int x= mb_x*16 + 8; |
| 361 | 423 uint8_t *ptr= s->last_picture[0]; |
| 424 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); | |
| 425 int mx= (s->motion_val[xy][0]>>1) + x; | |
| 426 int my= (s->motion_val[xy][1]>>1) + y; | |
| 427 int i; | |
| 428 int max; | |
| 429 | |
| 430 if(mx<0) mx=0; | |
| 431 if(my<0) my=0; | |
| 432 if(mx>=s->width) mx= s->width -1; | |
| 433 if(my>=s->height) my= s->height-1; | |
| 434 max= ABS(mx-x); | |
| 435 if(ABS(my-y) > max) max= ABS(my-y); | |
| 436 /* the ugliest linedrawing routine ... */ | |
| 437 for(i=0; i<max; i++){ | |
| 438 int x1= x + (mx-x)*i/max; | |
| 439 int y1= y + (my-y)*i/max; | |
| 440 ptr[y1*s->linesize + x1]+=100; | |
| 441 } | |
|
411
5c8b3a717929
workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents:
396
diff
changeset
|
442 ptr[y*s->linesize + x]+=100; |
| 361 | 443 s->mbskip_table[mb_x + mb_y*s->mb_width]=0; |
| 444 } | |
| 445 } | |
| 446 | |
| 447 } | |
| 448 #endif | |
|
273
34f40a0fc840
msmpeg4 bugfix (wrong frame displayed if some frames are skipped)
michaelni
parents:
266
diff
changeset
|
449 if(s->pict_type==B_TYPE || (!s->has_b_frames)){ |
| 262 | 450 pict->data[0] = s->current_picture[0]; |
| 451 pict->data[1] = s->current_picture[1]; | |
| 452 pict->data[2] = s->current_picture[2]; | |
| 453 } else { | |
| 454 pict->data[0] = s->last_picture[0]; | |
| 455 pict->data[1] = s->last_picture[1]; | |
| 456 pict->data[2] = s->last_picture[2]; | |
| 457 } | |
| 0 | 458 pict->linesize[0] = s->linesize; |
| 556 | 459 pict->linesize[1] = s->uvlinesize; |
| 460 pict->linesize[2] = s->uvlinesize; | |
| 0 | 461 |
| 462 avctx->quality = s->qscale; | |
| 231 | 463 |
| 464 /* Return the Picture timestamp as the frame number */ | |
| 465 /* we substract 1 because it is added on utils.c */ | |
| 466 avctx->frame_number = s->picture_number - 1; | |
| 467 | |
| 341 | 468 /* dont output the last pic after seeking |
| 469 note we allready added +1 for the current pix in MPV_frame_end(s) */ | |
| 470 if(s->num_available_buffers>=2 || (!s->has_b_frames)) | |
| 471 *data_size = sizeof(AVPicture); | |
| 384 | 472 #ifdef PRINT_FRAME_TIME |
| 473 printf("%Ld\n", rdtsc()-time); | |
| 474 #endif | |
| 655 | 475 return get_consumed_bytes(s, buf_size); |
| 0 | 476 } |
| 477 | |
| 67 | 478 AVCodec mpeg4_decoder = { |
| 479 "mpeg4", | |
| 0 | 480 CODEC_TYPE_VIDEO, |
| 67 | 481 CODEC_ID_MPEG4, |
| 0 | 482 sizeof(MpegEncContext), |
| 483 h263_decode_init, | |
| 484 NULL, | |
| 485 h263_decode_end, | |
| 486 h263_decode_frame, | |
| 553 | 487 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 0 | 488 }; |
| 489 | |
| 490 AVCodec h263_decoder = { | |
| 491 "h263", | |
| 492 CODEC_TYPE_VIDEO, | |
| 493 CODEC_ID_H263, | |
| 494 sizeof(MpegEncContext), | |
| 495 h263_decode_init, | |
| 496 NULL, | |
| 497 h263_decode_end, | |
| 498 h263_decode_frame, | |
| 553 | 499 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 0 | 500 }; |
| 501 | |
| 307 | 502 AVCodec msmpeg4v1_decoder = { |
| 503 "msmpeg4v1", | |
| 504 CODEC_TYPE_VIDEO, | |
| 505 CODEC_ID_MSMPEG4V1, | |
| 506 sizeof(MpegEncContext), | |
| 507 h263_decode_init, | |
| 508 NULL, | |
| 509 h263_decode_end, | |
| 510 h263_decode_frame, | |
| 553 | 511 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 307 | 512 }; |
| 513 | |
| 514 AVCodec msmpeg4v2_decoder = { | |
| 515 "msmpeg4v2", | |
| 516 CODEC_TYPE_VIDEO, | |
| 517 CODEC_ID_MSMPEG4V2, | |
| 518 sizeof(MpegEncContext), | |
| 519 h263_decode_init, | |
| 520 NULL, | |
| 521 h263_decode_end, | |
| 522 h263_decode_frame, | |
| 553 | 523 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 307 | 524 }; |
| 525 | |
| 526 AVCodec msmpeg4v3_decoder = { | |
| 0 | 527 "msmpeg4", |
| 528 CODEC_TYPE_VIDEO, | |
| 307 | 529 CODEC_ID_MSMPEG4V3, |
| 0 | 530 sizeof(MpegEncContext), |
| 531 h263_decode_init, | |
| 532 NULL, | |
| 533 h263_decode_end, | |
| 534 h263_decode_frame, | |
| 553 | 535 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 0 | 536 }; |
| 537 | |
| 311 | 538 AVCodec wmv1_decoder = { |
| 539 "wmv1", | |
| 540 CODEC_TYPE_VIDEO, | |
| 541 CODEC_ID_WMV1, | |
| 542 sizeof(MpegEncContext), | |
| 543 h263_decode_init, | |
| 544 NULL, | |
| 545 h263_decode_end, | |
| 546 h263_decode_frame, | |
| 553 | 547 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 311 | 548 }; |
| 549 | |
| 498 | 550 AVCodec wmv2_decoder = { |
| 551 "wmv2", | |
| 552 CODEC_TYPE_VIDEO, | |
| 553 CODEC_ID_WMV2, | |
| 554 sizeof(MpegEncContext), | |
| 555 h263_decode_init, | |
| 556 NULL, | |
| 557 h263_decode_end, | |
| 558 h263_decode_frame, | |
| 553 | 559 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 498 | 560 }; |
| 561 | |
| 0 | 562 AVCodec h263i_decoder = { |
| 563 "h263i", | |
| 564 CODEC_TYPE_VIDEO, | |
| 565 CODEC_ID_H263I, | |
| 566 sizeof(MpegEncContext), | |
| 567 h263_decode_init, | |
| 568 NULL, | |
| 569 h263_decode_end, | |
| 570 h263_decode_frame, | |
| 553 | 571 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
| 0 | 572 }; |
| 573 |
