*
* @return the removed picture or NULL if an error occurs
*/
-static Picture * remove_short(H264Context *h, int frame_num){
+static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){
MpegEncContext * const s = &h->s;
Picture *pic;
int i;
av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count);
pic = find_short(h, frame_num, &i);
- if (pic)
+ if (pic){
+ if(unreference_pic(h, pic, ref_mask))
remove_short_at_index(h, i);
+ }
return pic;
}
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);
- if (unreference_pic(h, pic, structure ^ PICT_FRAME))
- remove_short_at_index(h, j);
+ remove_short(h, frame_num, structure ^ PICT_FRAME);
break;
case MMCO_SHORT2LONG:
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);
+ remove_short_at_index(h, j);
+ h->long_ref[ mmco[i].long_arg ]= pic;
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_RESET:
while(h->short_ref_count){
- pic= remove_short(h, h->short_ref[0]->frame_num);
- if(pic) unreference_pic(h, pic, 0);
+ remove_short(h, h->short_ref[0]->frame_num, 0);
}
for(j = 0; j < 16; j++) {
remove_long(h, j, 0);
"in complementary field pair "
"(first field is long term)\n");
} else {
- pic= remove_short(h, s->current_picture_ptr->frame_num);
+ pic= remove_short(h, s->current_picture_ptr->frame_num, 0);
if(pic){
- unreference_pic(h, pic, 0);
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n");
}
remove_long(h, i, 0);
} else {
pic = h->short_ref[h->short_ref_count - 1];
- remove_short_at_index(h, h->short_ref_count - 1);
- unreference_pic(h, pic, 0);
+ remove_short(h, pic->frame_num, 0);
}
}