00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "internal.h"
00029 #include "avcodec.h"
00030 #include "dsputil.h"
00031 #include "mpegvideo.h"
00032 #include "h263_parser.h"
00033 #include "mpeg4video_parser.h"
00034 #include "msmpeg4.h"
00035
00036
00037
00038
00039 av_cold int ff_h263_decode_init(AVCodecContext *avctx)
00040 {
00041 MpegEncContext *s = avctx->priv_data;
00042
00043 s->avctx = avctx;
00044 s->out_format = FMT_H263;
00045
00046 s->width = avctx->coded_width;
00047 s->height = avctx->coded_height;
00048 s->workaround_bugs= avctx->workaround_bugs;
00049
00050
00051 MPV_decode_defaults(s);
00052 s->quant_precision=5;
00053 s->decode_mb= ff_h263_decode_mb;
00054 s->low_delay= 1;
00055 avctx->pix_fmt= avctx->get_format(avctx, avctx->codec->pix_fmts);
00056 s->unrestricted_mv= 1;
00057
00058
00059 switch(avctx->codec->id) {
00060 case CODEC_ID_H263:
00061 s->unrestricted_mv= 0;
00062 break;
00063 case CODEC_ID_MPEG4:
00064 s->decode_mb= ff_mpeg4_decode_mb;
00065 s->time_increment_bits = 4;
00066 s->h263_pred = 1;
00067 s->low_delay = 0;
00068 break;
00069 case CODEC_ID_MSMPEG4V1:
00070 s->h263_msmpeg4 = 1;
00071 s->h263_pred = 1;
00072 s->msmpeg4_version=1;
00073 break;
00074 case CODEC_ID_MSMPEG4V2:
00075 s->h263_msmpeg4 = 1;
00076 s->h263_pred = 1;
00077 s->msmpeg4_version=2;
00078 break;
00079 case CODEC_ID_MSMPEG4V3:
00080 s->h263_msmpeg4 = 1;
00081 s->h263_pred = 1;
00082 s->msmpeg4_version=3;
00083 break;
00084 case CODEC_ID_WMV1:
00085 s->h263_msmpeg4 = 1;
00086 s->h263_pred = 1;
00087 s->msmpeg4_version=4;
00088 break;
00089 case CODEC_ID_WMV2:
00090 s->h263_msmpeg4 = 1;
00091 s->h263_pred = 1;
00092 s->msmpeg4_version=5;
00093 break;
00094 case CODEC_ID_VC1:
00095 case CODEC_ID_WMV3:
00096 s->h263_msmpeg4 = 1;
00097 s->h263_pred = 1;
00098 s->msmpeg4_version=6;
00099 break;
00100 case CODEC_ID_H263I:
00101 break;
00102 case CODEC_ID_FLV1:
00103 s->h263_flv = 1;
00104 break;
00105 default:
00106 return -1;
00107 }
00108 s->codec_id= avctx->codec->id;
00109 avctx->hwaccel= ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
00110
00111
00112 if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
00113 if (MPV_common_init(s) < 0)
00114 return -1;
00115
00116 if (CONFIG_MSMPEG4_DECODER && s->h263_msmpeg4)
00117 ff_msmpeg4_decode_init(s);
00118 else
00119 h263_decode_init_vlc(s);
00120
00121 return 0;
00122 }
00123
00124 av_cold int ff_h263_decode_end(AVCodecContext *avctx)
00125 {
00126 MpegEncContext *s = avctx->priv_data;
00127
00128 MPV_common_end(s);
00129 return 0;
00130 }
00131
00135 static int get_consumed_bytes(MpegEncContext *s, int buf_size){
00136 int pos= (get_bits_count(&s->gb)+7)>>3;
00137
00138 if(s->divx_packed || s->avctx->hwaccel){
00139
00140 return buf_size;
00141 }else if(s->flags&CODEC_FLAG_TRUNCATED){
00142 pos -= s->parse_context.last_index;
00143 if(pos<0) pos=0;
00144 return pos;
00145 }else{
00146 if(pos==0) pos=1;
00147 if(pos+10>buf_size) pos=buf_size;
00148
00149 return pos;
00150 }
00151 }
00152
00153 static int decode_slice(MpegEncContext *s){
00154 const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
00155 const int mb_size= 16>>s->avctx->lowres;
00156 s->last_resync_gb= s->gb;
00157 s->first_slice_line= 1;
00158
00159 s->resync_mb_x= s->mb_x;
00160 s->resync_mb_y= s->mb_y;
00161
00162 ff_set_qscale(s, s->qscale);
00163
00164 if (s->avctx->hwaccel) {
00165 const uint8_t *start= s->gb.buffer + get_bits_count(&s->gb)/8;
00166 const uint8_t *end = ff_h263_find_resync_marker(start + 1, s->gb.buffer_end);
00167 skip_bits_long(&s->gb, 8*(end - start));
00168 return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start);
00169 }
00170
00171 if(s->partitioned_frame){
00172 const int qscale= s->qscale;
00173
00174 if(s->codec_id==CODEC_ID_MPEG4){
00175 if(ff_mpeg4_decode_partitions(s) < 0)
00176 return -1;
00177 }
00178
00179
00180 s->first_slice_line=1;
00181 s->mb_x= s->resync_mb_x;
00182 s->mb_y= s->resync_mb_y;
00183 ff_set_qscale(s, qscale);
00184 }
00185
00186 for(; s->mb_y < s->mb_height; s->mb_y++) {
00187
00188 if(s->msmpeg4_version){
00189 if(s->resync_mb_y + s->slice_height == s->mb_y){
00190 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);
00191
00192 return 0;
00193 }
00194 }
00195
00196 if(s->msmpeg4_version==1){
00197 s->last_dc[0]=
00198 s->last_dc[1]=
00199 s->last_dc[2]= 128;
00200 }
00201
00202 ff_init_block_index(s);
00203 for(; s->mb_x < s->mb_width; s->mb_x++) {
00204 int ret;
00205
00206 ff_update_block_index(s);
00207
00208 if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){
00209 s->first_slice_line=0;
00210 }
00211
00212
00213
00214 s->mv_dir = MV_DIR_FORWARD;
00215 s->mv_type = MV_TYPE_16X16;
00216
00217
00218 ret= s->decode_mb(s, s->block);
00219
00220 if (s->pict_type!=FF_B_TYPE)
00221 ff_h263_update_motion_val(s);
00222
00223 if(ret<0){
00224 const int xy= s->mb_x + s->mb_y*s->mb_stride;
00225 if(ret==SLICE_END){
00226 MPV_decode_mb(s, s->block);
00227 if(s->loop_filter)
00228 ff_h263_loop_filter(s);
00229
00230
00231 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
00232
00233 s->padding_bug_score--;
00234
00235 if(++s->mb_x >= s->mb_width){
00236 s->mb_x=0;
00237 ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
00238 s->mb_y++;
00239 }
00240 return 0;
00241 }else if(ret==SLICE_NOEND){
00242 av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);
00243 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)&part_mask);
00244 return -1;
00245 }
00246 av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
00247 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)&part_mask);
00248
00249 return -1;
00250 }
00251
00252 MPV_decode_mb(s, s->block);
00253 if(s->loop_filter)
00254 ff_h263_loop_filter(s);
00255 }
00256
00257 ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
00258
00259 s->mb_x= 0;
00260 }
00261
00262 assert(s->mb_x==0 && s->mb_y==s->mb_height);
00263
00264
00265 if( s->codec_id==CODEC_ID_MPEG4
00266 && (s->workaround_bugs&FF_BUG_AUTODETECT)
00267 && s->gb.size_in_bits - get_bits_count(&s->gb) >=0
00268 && s->gb.size_in_bits - get_bits_count(&s->gb) < 48
00269
00270 && !s->data_partitioning){
00271
00272 const int bits_count= get_bits_count(&s->gb);
00273 const int bits_left = s->gb.size_in_bits - bits_count;
00274
00275 if(bits_left==0){
00276 s->padding_bug_score+=16;
00277 } else if(bits_left != 1){
00278 int v= show_bits(&s->gb, 8);
00279 v|= 0x7F >> (7-(bits_count&7));
00280
00281 if(v==0x7F && bits_left<=8)
00282 s->padding_bug_score--;
00283 else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16)
00284 s->padding_bug_score+= 4;
00285 else
00286 s->padding_bug_score++;
00287 }
00288 }
00289
00290 if(s->workaround_bugs&FF_BUG_AUTODETECT){
00291 if(s->padding_bug_score > -2 && !s->data_partitioning )
00292 s->workaround_bugs |= FF_BUG_NO_PADDING;
00293 else
00294 s->workaround_bugs &= ~FF_BUG_NO_PADDING;
00295 }
00296
00297
00298 if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){
00299 int left= s->gb.size_in_bits - get_bits_count(&s->gb);
00300 int max_extra=7;
00301
00302
00303 if(s->msmpeg4_version && s->pict_type==FF_I_TYPE)
00304 max_extra+= 17;
00305
00306
00307 if((s->workaround_bugs&FF_BUG_NO_PADDING) && s->error_recognition>=3)
00308 max_extra+= 48;
00309 else if((s->workaround_bugs&FF_BUG_NO_PADDING))
00310 max_extra+= 256*256*256*64;
00311
00312 if(left>max_extra){
00313 av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
00314 }
00315 else if(left<0){
00316 av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
00317 }else
00318 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);
00319
00320 return 0;
00321 }
00322
00323 av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
00324 s->gb.size_in_bits - get_bits_count(&s->gb),
00325 show_bits(&s->gb, 24), s->padding_bug_score);
00326
00327 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
00328
00329 return -1;
00330 }
00331
00332 int ff_h263_decode_frame(AVCodecContext *avctx,
00333 void *data, int *data_size,
00334 const uint8_t *buf, int buf_size)
00335 {
00336 MpegEncContext *s = avctx->priv_data;
00337 int ret;
00338 AVFrame *pict = data;
00339
00340 #ifdef PRINT_FRAME_TIME
00341 uint64_t time= rdtsc();
00342 #endif
00343 #ifdef DEBUG
00344 av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
00345 if(buf_size>0)
00346 av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
00347 #endif
00348 s->flags= avctx->flags;
00349 s->flags2= avctx->flags2;
00350
00351
00352 if (buf_size == 0) {
00353
00354 if (s->low_delay==0 && s->next_picture_ptr) {
00355 *pict= *(AVFrame*)s->next_picture_ptr;
00356 s->next_picture_ptr= NULL;
00357
00358 *data_size = sizeof(AVFrame);
00359 }
00360
00361 return 0;
00362 }
00363
00364 if(s->flags&CODEC_FLAG_TRUNCATED){
00365 int next;
00366
00367 if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){
00368 next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
00369 }else if(CONFIG_H263_DECODER && s->codec_id==CODEC_ID_H263){
00370 next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
00371 }else{
00372 av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
00373 return -1;
00374 }
00375
00376 if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
00377 return buf_size;
00378 }
00379
00380
00381 retry:
00382
00383 if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){
00384 init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
00385 }else
00386 init_get_bits(&s->gb, buf, buf_size*8);
00387 s->bitstream_buffer_size=0;
00388
00389 if (!s->context_initialized) {
00390 if (MPV_common_init(s) < 0)
00391 return -1;
00392 }
00393
00394
00395
00396 if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
00397 int i= ff_find_unused_picture(s, 0);
00398 s->current_picture_ptr= &s->picture[i];
00399 }
00400
00401
00402 if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5) {
00403 ret= ff_wmv2_decode_picture_header(s);
00404 } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
00405 ret = msmpeg4_decode_picture_header(s);
00406 } else if (s->h263_pred) {
00407 if(s->avctx->extradata_size && s->picture_number==0){
00408 GetBitContext gb;
00409
00410 init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
00411 ret = ff_mpeg4_decode_picture_header(s, &gb);
00412 }
00413 ret = ff_mpeg4_decode_picture_header(s, &s->gb);
00414 } else if (s->codec_id == CODEC_ID_H263I) {
00415 ret = intel_h263_decode_picture_header(s);
00416 } else if (s->h263_flv) {
00417 ret = flv_h263_decode_picture_header(s);
00418 } else {
00419 ret = h263_decode_picture_header(s);
00420 }
00421
00422 if(ret==FRAME_SKIPPED) return get_consumed_bytes(s, buf_size);
00423
00424
00425 if (ret < 0){
00426 av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
00427 return -1;
00428 }
00429
00430 avctx->has_b_frames= !s->low_delay;
00431
00432 if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
00433 if(s->stream_codec_tag == AV_RL32("XVID") ||
00434 s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") ||
00435 s->codec_tag == AV_RL32("RMP4"))
00436 s->xvid_build= -1;
00437 #if 0
00438 if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
00439 && s->padding_bug_score > 0 && s->low_delay)
00440 s->xvid_build= -1;
00441 #endif
00442 }
00443
00444 if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
00445 if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
00446 s->divx_version= 400;
00447 }
00448
00449 if(s->xvid_build && s->divx_version){
00450 s->divx_version=
00451 s->divx_build= 0;
00452 }
00453
00454 if(s->workaround_bugs&FF_BUG_AUTODETECT){
00455 if(s->codec_tag == AV_RL32("XVIX"))
00456 s->workaround_bugs|= FF_BUG_XVID_ILACE;
00457
00458 if(s->codec_tag == AV_RL32("UMP4")){
00459 s->workaround_bugs|= FF_BUG_UMP4;
00460 }
00461
00462 if(s->divx_version>=500 && s->divx_build<1814){
00463 s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
00464 }
00465
00466 if(s->divx_version>502 && s->divx_build<1814){
00467 s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
00468 }
00469
00470 if(s->xvid_build && s->xvid_build<=3)
00471 s->padding_bug_score= 256*256*256*64;
00472
00473 if(s->xvid_build && s->xvid_build<=1)
00474 s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
00475
00476 if(s->xvid_build && s->xvid_build<=12)
00477 s->workaround_bugs|= FF_BUG_EDGE;
00478
00479 if(s->xvid_build && s->xvid_build<=32)
00480 s->workaround_bugs|= FF_BUG_DC_CLIP;
00481
00482 #define SET_QPEL_FUNC(postfix1, postfix2) \
00483 s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
00484 s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\
00485 s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
00486
00487 if(s->lavc_build && s->lavc_build<4653)
00488 s->workaround_bugs|= FF_BUG_STD_QPEL;
00489
00490 if(s->lavc_build && s->lavc_build<4655)
00491 s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
00492
00493 if(s->lavc_build && s->lavc_build<4670){
00494 s->workaround_bugs|= FF_BUG_EDGE;
00495 }
00496
00497 if(s->lavc_build && s->lavc_build<=4712)
00498 s->workaround_bugs|= FF_BUG_DC_CLIP;
00499
00500 if(s->divx_version)
00501 s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
00502
00503 if(s->divx_version==501 && s->divx_build==20020416)
00504 s->padding_bug_score= 256*256*256*64;
00505
00506 if(s->divx_version && s->divx_version<500){
00507 s->workaround_bugs|= FF_BUG_EDGE;
00508 }
00509
00510 if(s->divx_version)
00511 s->workaround_bugs|= FF_BUG_HPEL_CHROMA;
00512 #if 0
00513 if(s->divx_version==500)
00514 s->padding_bug_score= 256*256*256*64;
00515
00516
00517
00518
00519 if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0
00520 && s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)
00521 s->workaround_bugs|= FF_BUG_NO_PADDING;
00522
00523 if(s->lavc_build && s->lavc_build<4609)
00524 s->workaround_bugs|= FF_BUG_NO_PADDING;
00525 #endif
00526 }
00527
00528 if(s->workaround_bugs& FF_BUG_STD_QPEL){
00529 SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
00530 SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
00531 SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
00532 SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
00533 SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
00534 SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
00535
00536 SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
00537 SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
00538 SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
00539 SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
00540 SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
00541 SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
00542 }
00543
00544 if(avctx->debug & FF_DEBUG_BUGS)
00545 av_log(s->avctx, AV_LOG_DEBUG, "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
00546 s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
00547 s->divx_packed ? "p" : "");
00548
00549 #if 0 // dump bits per frame / qp / complexity
00550 {
00551 static FILE *f=NULL;
00552 if(!f) f=fopen("rate_qp_cplx.txt", "w");
00553 fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
00554 }
00555 #endif
00556
00557 #if HAVE_MMX
00558 if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & FF_MM_MMX)){
00559 avctx->idct_algo= FF_IDCT_XVIDMMX;
00560 avctx->coded_width= 0;
00561
00562 s->picture_number=0;
00563 }
00564 #endif
00565
00566
00567
00568
00569
00570
00571 if ( s->width != avctx->coded_width
00572 || s->height != avctx->coded_height) {
00573
00574 ParseContext pc= s->parse_context;
00575 s->parse_context.buffer=0;
00576 MPV_common_end(s);
00577 s->parse_context= pc;
00578 }
00579 if (!s->context_initialized) {
00580 avcodec_set_dimensions(avctx, s->width, s->height);
00581
00582 goto retry;
00583 }
00584
00585 if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I))
00586 s->gob_index = ff_h263_get_gob_height(s);
00587
00588
00589 s->current_picture.pict_type= s->pict_type;
00590 s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
00591
00592
00593 if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size);
00594
00595 if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return get_consumed_bytes(s, buf_size);
00596 if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE)
00597 || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE)
00598 || avctx->skip_frame >= AVDISCARD_ALL)
00599 return get_consumed_bytes(s, buf_size);
00600
00601 if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
00602
00603 if(s->next_p_frame_damaged){
00604 if(s->pict_type==FF_B_TYPE)
00605 return get_consumed_bytes(s, buf_size);
00606 else
00607 s->next_p_frame_damaged=0;
00608 }
00609
00610 if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==FF_B_TYPE){
00611 s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
00612 s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
00613 }else if((!s->no_rounding) || s->pict_type==FF_B_TYPE){
00614 s->me.qpel_put= s->dsp.put_qpel_pixels_tab;
00615 s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
00616 }else{
00617 s->me.qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
00618 s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
00619 }
00620
00621 if(MPV_frame_start(s, avctx) < 0)
00622 return -1;
00623
00624 if (avctx->hwaccel) {
00625 if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
00626 return -1;
00627 }
00628
00629 #ifdef DEBUG
00630 av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
00631 #endif
00632
00633 ff_er_frame_start(s);
00634
00635
00636
00637 if (CONFIG_WMV2_DECODER && s->msmpeg4_version==5){
00638 ret = ff_wmv2_decode_secondary_picture_header(s);
00639 if(ret<0) return ret;
00640 if(ret==1) goto intrax8_decoded;
00641 }
00642
00643
00644 s->mb_x=0;
00645 s->mb_y=0;
00646
00647 decode_slice(s);
00648 while(s->mb_y<s->mb_height){
00649 if(s->msmpeg4_version){
00650 if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
00651 break;
00652 }else{
00653 if(ff_h263_resync(s)<0)
00654 break;
00655 }
00656
00657 if(s->msmpeg4_version<4 && s->h263_pred)
00658 ff_mpeg4_clean_buffers(s);
00659
00660 decode_slice(s);
00661 }
00662
00663 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==FF_I_TYPE)
00664 if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){
00665 s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
00666 }
00667
00668
00669 if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){
00670 int current_pos= get_bits_count(&s->gb)>>3;
00671 int startcode_found=0;
00672
00673 if(buf_size - current_pos > 5){
00674 int i;
00675 for(i=current_pos; i<buf_size-3; i++){
00676 if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
00677 startcode_found=1;
00678 break;
00679 }
00680 }
00681 }
00682 if(s->gb.buffer == s->bitstream_buffer && buf_size>20){
00683 startcode_found=1;
00684 current_pos=0;
00685 }
00686
00687 if(startcode_found){
00688 s->bitstream_buffer= av_fast_realloc(
00689 s->bitstream_buffer,
00690 &s->allocated_bitstream_buffer_size,
00691 buf_size - current_pos + FF_INPUT_BUFFER_PADDING_SIZE);
00692 memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
00693 s->bitstream_buffer_size= buf_size - current_pos;
00694 }
00695 }
00696
00697 intrax8_decoded:
00698 ff_er_frame_end(s);
00699
00700 if (avctx->hwaccel) {
00701 if (avctx->hwaccel->end_frame(avctx) < 0)
00702 return -1;
00703 }
00704
00705 MPV_frame_end(s);
00706
00707 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
00708 assert(s->current_picture.pict_type == s->pict_type);
00709 if (s->pict_type == FF_B_TYPE || s->low_delay) {
00710 *pict= *(AVFrame*)s->current_picture_ptr;
00711 } else if (s->last_picture_ptr != NULL) {
00712 *pict= *(AVFrame*)s->last_picture_ptr;
00713 }
00714
00715 if(s->last_picture_ptr || s->low_delay){
00716 *data_size = sizeof(AVFrame);
00717 ff_print_debug_info(s, pict);
00718 }
00719
00720
00721
00722 avctx->frame_number = s->picture_number - 1;
00723
00724 #ifdef PRINT_FRAME_TIME
00725 av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time);
00726 #endif
00727
00728 return get_consumed_bytes(s, buf_size);
00729 }
00730
00731 AVCodec mpeg4_decoder = {
00732 "mpeg4",
00733 CODEC_TYPE_VIDEO,
00734 CODEC_ID_MPEG4,
00735 sizeof(MpegEncContext),
00736 ff_h263_decode_init,
00737 NULL,
00738 ff_h263_decode_end,
00739 ff_h263_decode_frame,
00740 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
00741 .flush= ff_mpeg_flush,
00742 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
00743 .pix_fmts= ff_hwaccel_pixfmt_list_420,
00744 };
00745
00746 AVCodec h263_decoder = {
00747 "h263",
00748 CODEC_TYPE_VIDEO,
00749 CODEC_ID_H263,
00750 sizeof(MpegEncContext),
00751 ff_h263_decode_init,
00752 NULL,
00753 ff_h263_decode_end,
00754 ff_h263_decode_frame,
00755 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
00756 .flush= ff_mpeg_flush,
00757 .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
00758 .pix_fmts= ff_hwaccel_pixfmt_list_420,
00759 };
00760
00761 AVCodec msmpeg4v1_decoder = {
00762 "msmpeg4v1",
00763 CODEC_TYPE_VIDEO,
00764 CODEC_ID_MSMPEG4V1,
00765 sizeof(MpegEncContext),
00766 ff_h263_decode_init,
00767 NULL,
00768 ff_h263_decode_end,
00769 ff_h263_decode_frame,
00770 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00771 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
00772 .pix_fmts= ff_pixfmt_list_420,
00773 };
00774
00775 AVCodec msmpeg4v2_decoder = {
00776 "msmpeg4v2",
00777 CODEC_TYPE_VIDEO,
00778 CODEC_ID_MSMPEG4V2,
00779 sizeof(MpegEncContext),
00780 ff_h263_decode_init,
00781 NULL,
00782 ff_h263_decode_end,
00783 ff_h263_decode_frame,
00784 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00785 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
00786 .pix_fmts= ff_pixfmt_list_420,
00787 };
00788
00789 AVCodec msmpeg4v3_decoder = {
00790 "msmpeg4",
00791 CODEC_TYPE_VIDEO,
00792 CODEC_ID_MSMPEG4V3,
00793 sizeof(MpegEncContext),
00794 ff_h263_decode_init,
00795 NULL,
00796 ff_h263_decode_end,
00797 ff_h263_decode_frame,
00798 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00799 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
00800 .pix_fmts= ff_pixfmt_list_420,
00801 };
00802
00803 AVCodec wmv1_decoder = {
00804 "wmv1",
00805 CODEC_TYPE_VIDEO,
00806 CODEC_ID_WMV1,
00807 sizeof(MpegEncContext),
00808 ff_h263_decode_init,
00809 NULL,
00810 ff_h263_decode_end,
00811 ff_h263_decode_frame,
00812 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00813 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
00814 .pix_fmts= ff_pixfmt_list_420,
00815 };
00816
00817 AVCodec h263i_decoder = {
00818 "h263i",
00819 CODEC_TYPE_VIDEO,
00820 CODEC_ID_H263I,
00821 sizeof(MpegEncContext),
00822 ff_h263_decode_init,
00823 NULL,
00824 ff_h263_decode_end,
00825 ff_h263_decode_frame,
00826 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00827 .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
00828 .pix_fmts= ff_pixfmt_list_420,
00829 };
00830
00831 AVCodec flv_decoder = {
00832 "flv",
00833 CODEC_TYPE_VIDEO,
00834 CODEC_ID_FLV1,
00835 sizeof(MpegEncContext),
00836 ff_h263_decode_init,
00837 NULL,
00838 ff_h263_decode_end,
00839 ff_h263_decode_frame,
00840 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
00841 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV)"),
00842 .pix_fmts= ff_pixfmt_list_420,
00843 };