changeset 7394:4ac8769cbb01 libavcodec

Make remove_long() call unreference_pic() internally.
author michael
date Fri, 25 Jul 2008 13:09:06 +0000
parents 309c59802769
children 08e81ea44a38
files h264.c
diffstat 1 files changed, 17 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/h264.c	Fri Jul 25 12:56:58 2008 +0000
+++ b/h264.c	Fri Jul 25 13:09:06 2008 +0000
@@ -61,7 +61,7 @@
 static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
 static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
 static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
-static Picture * remove_long(H264Context *h, int i);
+static Picture * remove_long(H264Context *h, int i, int ref_mask);
 
 static av_always_inline uint32_t pack16to32(int a, int b){
 #ifdef WORDS_BIGENDIAN
@@ -3297,10 +3297,7 @@
     int i;
 
     for(i=0; i<16; i++){
-        if (h->long_ref[i] != NULL) {
-            unreference_pic(h, h->long_ref[i], 0);
-            remove_long(h, i);
-        }
+        remove_long(h, i, 0);
     }
     assert(h->long_ref_count==0);
 
@@ -3393,15 +3390,17 @@
  * that list.
  * @return the removed picture or NULL if an error occurs
  */
-static Picture * remove_long(H264Context *h, int i){
+static Picture * remove_long(H264Context *h, int i, int ref_mask){
     Picture *pic;
 
     pic= h->long_ref[i];
     if (pic){
-        assert(h->long_ref[i]->long_ref == 1);
-        h->long_ref[i]->long_ref= 0;
-        h->long_ref[i]= NULL;
-        h->long_ref_count--;
+        if(unreference_pic(h, pic, ref_mask)){
+            assert(h->long_ref[i]->long_ref == 1);
+            h->long_ref[i]->long_ref= 0;
+            h->long_ref[i]= NULL;
+            h->long_ref_count--;
+        }
     }
 
     return pic;
@@ -3474,8 +3473,7 @@
             } else {
                 int frame_num = mmco[i].short_pic_num >> FIELD_PICTURE;
 
-                pic= remove_long(h, mmco[i].long_arg);
-                if(pic) unreference_pic(h, pic, 0);
+                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 ]){
@@ -3488,8 +3486,7 @@
             j = pic_num_extract(h, mmco[i].long_arg, &structure);
             pic = h->long_ref[j];
             if (pic) {
-                if (unreference_pic(h, pic, structure ^ PICT_FRAME))
-                    remove_long(h, j);
+                remove_long(h, j, structure ^ PICT_FRAME);
             } else if(s->avctx->debug&FF_DEBUG_MMCO)
                 av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n");
             break;
@@ -3503,8 +3500,7 @@
                      */
 
             if (h->long_ref[mmco[i].long_arg] != s->current_picture_ptr) {
-                pic= remove_long(h, mmco[i].long_arg);
-                if(pic) unreference_pic(h, pic, 0);
+                remove_long(h, mmco[i].long_arg, 0);
 
                 h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr;
                 h->long_ref[ mmco[i].long_arg ]->long_ref=1;
@@ -3518,8 +3514,7 @@
             assert(mmco[i].long_arg <= 16);
             // just remove the long term which index is greater than new max
             for(j = mmco[i].long_arg; j<16; j++){
-                pic = remove_long(h, j);
-                if (pic) unreference_pic(h, pic, 0);
+                remove_long(h, j, 0);
             }
             break;
         case MMCO_RESET:
@@ -3528,8 +3523,7 @@
                 if(pic) unreference_pic(h, pic, 0);
             }
             for(j = 0; j < 16; j++) {
-                pic= remove_long(h, j);
-                if(pic) unreference_pic(h, pic, 0);
+                remove_long(h, j, 0);
             }
             s->current_picture_ptr->poc=
             s->current_picture_ptr->field_poc[0]=
@@ -3590,13 +3584,12 @@
                     break;
 
             assert(i < 16);
-            pic = h->long_ref[i];
-            remove_long(h, i);
+            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);
+            unreference_pic(h, pic, 0);
+        }
     }
 
     print_short_term(h);