---
 libavcodec/h264_refs.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 2a71ac1..755f115 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -62,20 +62,22 @@ static int split_field_copy(Picture *dest, Picture *src,
     return match;
 }
 
-static int build_def_list(Picture *def, Picture **in, int len, int is_long, 
int sel){
+static int build_def_list(Picture *def, Picture **in, int len, int is_long,
+                          int sel, int index)
+{
     int i[2]={0};
-    int index=0;
 
-    while(i[0]<len || i[1]<len){
+    while ((i[0] < len || i[1] < len) && index < 32) {
         while (i[0] < len && !(in[ i[0] ] && (in[ i[0] ]->f.reference & sel)))
             i[0]++;
         while (i[1] < len && !(in[ i[1] ] && (in[ i[1] ]->f.reference & 
(sel^3))))
             i[1]++;
-        if(i[0] < len){
+
+        if (i[0] < len && index < 32) {
             in[ i[0] ]->pic_id= is_long ? i[0] : in[ i[0] ]->frame_num;
             split_field_copy(&def[index++], in[ i[0]++ ], sel  , 1);
         }
-        if(i[1] < len){
+        if (i[1] < len && index < 32) {
             in[ i[1] ]->pic_id= is_long ? i[1] : in[ i[1] ]->frame_num;
             split_field_copy(&def[index++], in[ i[1]++ ], sel^3, 0);
         }
@@ -120,11 +122,15 @@ int ff_h264_fill_default_ref_list(H264Context *h){
             cur_poc= s->current_picture_ptr->poc;
 
         for(list= 0; list<2; list++){
-            len= add_sorted(sorted    , h->short_ref, h->short_ref_count, 
cur_poc, 1^list);
-            len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, 
cur_poc, 0^list);
+            len  = add_sorted(sorted    , h->short_ref, h->short_ref_count,
+                              cur_poc, 1^list);
+            len += add_sorted(sorted+len, h->short_ref, h->short_ref_count,
+                              cur_poc, 0^list);
             assert(len<=32);
-            len= build_def_list(h->default_ref_list[list]    , sorted     , 
len, 0, s->picture_structure);
-            len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 
, 1, s->picture_structure);
+            len = build_def_list(h->default_ref_list[list], sorted, len, 0,
+                                 s->picture_structure, 0);
+            len = build_def_list(h->default_ref_list[list], h->long_ref, 16, 1,
+                                 s->picture_structure, len);
             assert(len<=32);
 
             if(len < h->ref_count[list])
@@ -138,8 +144,10 @@ int ff_h264_fill_default_ref_list(H264Context *h){
                 FFSWAP(Picture, h->default_ref_list[1][0], 
h->default_ref_list[1][1]);
         }
     }else{
-        len = build_def_list(h->default_ref_list[0]    , h->short_ref, 
h->short_ref_count, 0, s->picture_structure);
-        len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16      
          , 1, s->picture_structure);
+        len = build_def_list(h->default_ref_list[0], h->short_ref,
+                             h->short_ref_count, 0, s->picture_structure, 0);
+        len = build_def_list(h->default_ref_list[0], h-> long_ref, 16, 1,
+                             s->picture_structure, len);
         assert(len <= 32);
         if(len < h->ref_count[0])
             memset(&h->default_ref_list[0][len], 0, 
sizeof(Picture)*(h->ref_count[0] - len));
-- 
1.7.12.4

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to