diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 10ec839cc0..8a74edde7b 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -3453,34 +3453,32 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ if(s->avctx->debug&FF_DEBUG_MMCO) av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); + if( mmco[i].opcode == MMCO_SHORT2UNUSED + || mmco[i].opcode == MMCO_SHORT2LONG){ + frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); + pic = find_short(h, frame_num, &j); + if(!pic){ + av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); + continue; + } + } + switch(mmco[i].opcode){ case MMCO_SHORT2UNUSED: if(s->avctx->debug&FF_DEBUG_MMCO) av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); - frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); - pic = find_short(h, frame_num, &j); - if (pic) { if (unreference_pic(h, pic, structure ^ PICT_FRAME)) remove_short_at_index(h, j); - } else if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short failure\n"); break; case MMCO_SHORT2LONG: - if (FIELD_PICTURE && mmco[i].long_arg < h->long_ref_count && - h->long_ref[mmco[i].long_arg]->frame_num == - mmco[i].short_pic_num / 2) { - /* do nothing, we've already moved this field pair. */ - } else { - int frame_num = mmco[i].short_pic_num >> FIELD_PICTURE; - - remove_long(h, mmco[i].long_arg, 0); + if (h->long_ref[mmco[i].long_arg] != pic) + remove_long(h, mmco[i].long_arg, 0); h->long_ref[ mmco[i].long_arg ]= remove_short(h, frame_num); if (h->long_ref[ mmco[i].long_arg ]){ h->long_ref[ mmco[i].long_arg ]->long_ref=1; h->long_ref_count++; } - } break; case MMCO_LONG2UNUSED: j = pic_num_extract(h, mmco[i].long_arg, &structure);