]> git.videolan.org Git - x264.git/commitdiff
Remove reordering restrictions from weightp
authorJason Garrett-Glaser <darkshikari@gmail.com>
Mon, 19 Apr 2010 18:02:27 +0000 (11:02 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Fri, 23 Apr 2010 19:40:20 +0000 (12:40 -0700)
Apparently the spec does allow two consecutive copies of the same frame in the reference list.
This involves an incredibly ugly hack to wrap around the frame number.
Very slight compression improvement.

encoder/encoder.c
encoder/ratecontrol.c

index 0f9ba87f89336aeb8488548aae3fe4dc6b4f4f26..f641f63896500e9447a7781352efd002aeec8187 100644 (file)
@@ -140,10 +140,8 @@ static void x264_slice_header_init( x264_t *h, x264_slice_header_t *sh,
         for( int i = 0; i < h->i_ref0; i++ )
         {
             int diff = h->fref0[i]->i_frame_num - pred_frame_num;
-            if( diff == 0 )
-                x264_log( h, X264_LOG_ERROR, "diff frame num == 0\n" );
             sh->ref_pic_list_order[0][i].idc = ( diff > 0 );
-            sh->ref_pic_list_order[0][i].arg = abs( diff ) - 1;
+            sh->ref_pic_list_order[0][i].arg = (abs(diff) - 1) & ((1 << sps->i_log2_max_frame_num) - 1);
             pred_frame_num = h->fref0[i]->i_frame_num;
         }
     }
@@ -1336,24 +1334,11 @@ static inline void x264_reference_check_reorder( x264_t *h )
 int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w )
 {
     int i = h->i_ref0;
-    int j;
+    int j = 1;
     x264_frame_t *newframe;
     if( i <= 1 ) /* empty list, definitely can't duplicate frame */
         return -1;
 
-    /* Find a place to insert the duplicate in the reference list. */
-    for( j = 0; j < i; j++ )
-        if( h->fref0[i_ref]->i_frame != h->fref0[j]->i_frame )
-        {
-            /* found a place, after j, make sure there is not already a duplicate there */
-            if( j == i-1 || ( h->fref0[i_ref]->i_frame != h->fref0[j+1]->i_frame ) )
-                break;
-        }
-
-    if( j == i ) /* No room in the reference list for the duplicate. */
-        return -1;
-    j++;
-
     newframe = x264_frame_pop_blank_unused( h );
 
     //FIXME: probably don't need to copy everything
index 1b4dda4117ccbf4b41281b590ee7af338d5fd8b8..c29e8c505ca4e489b7fbf10653a0d8f6578cee5a 100644 (file)
@@ -375,9 +375,8 @@ int x264_reference_build_list_optimal( x264_t *h )
         int bestref = 1;
 
         for( int i = 1; i < h->i_ref0; i++ )
-            if( !frames[i]->b_duplicate || frames[i]->i_frame != h->fref0[ref-1]->i_frame )
-                /* Favor lower POC as a tiebreaker. */
-                COPY2_IF_GT( max, refcount[i], bestref, i );
+            /* Favor lower POC as a tiebreaker. */
+            COPY2_IF_GT( max, refcount[i], bestref, i );
 
         /* FIXME: If there are duplicates from frames other than ref0 then it is possible
          * that the optimal ordering doesnt place every duplicate. */