comparison h264.c @ 7396:9f765ea6d6df libavcodec

Make remove_short() match remove_long() in that it calls unreference_pic().
author michael
date Fri, 25 Jul 2008 14:00:01 +0000
parents 08e81ea44a38
children 535664ced6f0
comparison
equal deleted inserted replaced
7395:08e81ea44a38 7396:9f765ea6d6df
3368 3368
3369 /** 3369 /**
3370 * 3370 *
3371 * @return the removed picture or NULL if an error occurs 3371 * @return the removed picture or NULL if an error occurs
3372 */ 3372 */
3373 static Picture * remove_short(H264Context *h, int frame_num){ 3373 static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){
3374 MpegEncContext * const s = &h->s; 3374 MpegEncContext * const s = &h->s;
3375 Picture *pic; 3375 Picture *pic;
3376 int i; 3376 int i;
3377 3377
3378 if(s->avctx->debug&FF_DEBUG_MMCO) 3378 if(s->avctx->debug&FF_DEBUG_MMCO)
3379 av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); 3379 av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count);
3380 3380
3381 pic = find_short(h, frame_num, &i); 3381 pic = find_short(h, frame_num, &i);
3382 if (pic) 3382 if (pic){
3383 if(unreference_pic(h, pic, ref_mask))
3383 remove_short_at_index(h, i); 3384 remove_short_at_index(h, i);
3385 }
3384 3386
3385 return pic; 3387 return pic;
3386 } 3388 }
3387 3389
3388 /** 3390 /**
3465 3467
3466 switch(mmco[i].opcode){ 3468 switch(mmco[i].opcode){
3467 case MMCO_SHORT2UNUSED: 3469 case MMCO_SHORT2UNUSED:
3468 if(s->avctx->debug&FF_DEBUG_MMCO) 3470 if(s->avctx->debug&FF_DEBUG_MMCO)
3469 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); 3471 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);
3470 if (unreference_pic(h, pic, structure ^ PICT_FRAME)) 3472 remove_short(h, frame_num, structure ^ PICT_FRAME);
3471 remove_short_at_index(h, j);
3472 break; 3473 break;
3473 case MMCO_SHORT2LONG: 3474 case MMCO_SHORT2LONG:
3474 if (h->long_ref[mmco[i].long_arg] != pic) 3475 if (h->long_ref[mmco[i].long_arg] != pic)
3475 remove_long(h, mmco[i].long_arg, 0); 3476 remove_long(h, mmco[i].long_arg, 0);
3476 3477
3477 h->long_ref[ mmco[i].long_arg ]= remove_short(h, frame_num); 3478 remove_short_at_index(h, j);
3479 h->long_ref[ mmco[i].long_arg ]= pic;
3478 if (h->long_ref[ mmco[i].long_arg ]){ 3480 if (h->long_ref[ mmco[i].long_arg ]){
3479 h->long_ref[ mmco[i].long_arg ]->long_ref=1; 3481 h->long_ref[ mmco[i].long_arg ]->long_ref=1;
3480 h->long_ref_count++; 3482 h->long_ref_count++;
3481 } 3483 }
3482 break; 3484 break;
3515 remove_long(h, j, 0); 3517 remove_long(h, j, 0);
3516 } 3518 }
3517 break; 3519 break;
3518 case MMCO_RESET: 3520 case MMCO_RESET:
3519 while(h->short_ref_count){ 3521 while(h->short_ref_count){
3520 pic= remove_short(h, h->short_ref[0]->frame_num); 3522 remove_short(h, h->short_ref[0]->frame_num, 0);
3521 if(pic) unreference_pic(h, pic, 0);
3522 } 3523 }
3523 for(j = 0; j < 16; j++) { 3524 for(j = 0; j < 16; j++) {
3524 remove_long(h, j, 0); 3525 remove_long(h, j, 0);
3525 } 3526 }
3526 s->current_picture_ptr->poc= 3527 s->current_picture_ptr->poc=
3549 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference " 3550 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference "
3550 "assignment for second field " 3551 "assignment for second field "
3551 "in complementary field pair " 3552 "in complementary field pair "
3552 "(first field is long term)\n"); 3553 "(first field is long term)\n");
3553 } else { 3554 } else {
3554 pic= remove_short(h, s->current_picture_ptr->frame_num); 3555 pic= remove_short(h, s->current_picture_ptr->frame_num, 0);
3555 if(pic){ 3556 if(pic){
3556 unreference_pic(h, pic, 0);
3557 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); 3557 av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n");
3558 } 3558 }
3559 3559
3560 if(h->short_ref_count) 3560 if(h->short_ref_count)
3561 memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); 3561 memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*));
3583 3583
3584 assert(i < 16); 3584 assert(i < 16);
3585 remove_long(h, i, 0); 3585 remove_long(h, i, 0);
3586 } else { 3586 } else {
3587 pic = h->short_ref[h->short_ref_count - 1]; 3587 pic = h->short_ref[h->short_ref_count - 1];
3588 remove_short_at_index(h, h->short_ref_count - 1); 3588 remove_short(h, pic->frame_num, 0);
3589 unreference_pic(h, pic, 0);
3590 } 3589 }
3591 } 3590 }
3592 3591
3593 print_short_term(h); 3592 print_short_term(h);
3594 print_long_term(h); 3593 print_long_term(h);