]> git.sesse.net Git - x264/commitdiff
Update level dpb size calculation to match newer H.264 spec
authorFiona Glaser <fiona@x264.com>
Thu, 11 Oct 2012 20:27:48 +0000 (13:27 -0700)
committerFiona Glaser <fiona@x264.com>
Wed, 7 Nov 2012 22:52:34 +0000 (14:52 -0800)
Doesn't actually change encoding behavior, but makes it more correct.
Warning messages should now be accurate at higher bit depths and non-4:2:0.
Technically, since it redefines x264_level_t, this is an API version increment.

encoder/set.c
x264.c
x264.h

index 531bca0c2d57d969221971d3587b67c7f6f22515..7c7983ed56f4a09db47618d414dd57eb1d2493ee 100644 (file)
@@ -727,23 +727,23 @@ void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s )
 
 const x264_level_t x264_levels[] =
 {
-    { 10,    1485,    99,   152064,     64,    175,  64, 64,  0, 2, 0, 0, 1 },
-    {  9,    1485,    99,   152064,    128,    350,  64, 64,  0, 2, 0, 0, 1 }, /* "1b" */
-    { 11,    3000,   396,   345600,    192,    500, 128, 64,  0, 2, 0, 0, 1 },
-    { 12,    6000,   396,   912384,    384,   1000, 128, 64,  0, 2, 0, 0, 1 },
-    { 13,   11880,   396,   912384,    768,   2000, 128, 64,  0, 2, 0, 0, 1 },
-    { 20,   11880,   396,   912384,   2000,   2000, 128, 64,  0, 2, 0, 0, 1 },
-    { 21,   19800,   792,  1824768,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
-    { 22,   20250,  1620,  3110400,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
-    { 30,   40500,  1620,  3110400,  10000,  10000, 256, 32, 22, 2, 0, 1, 0 },
-    { 31,  108000,  3600,  6912000,  14000,  14000, 512, 16, 60, 4, 1, 1, 0 },
-    { 32,  216000,  5120,  7864320,  20000,  20000, 512, 16, 60, 4, 1, 1, 0 },
-    { 40,  245760,  8192, 12582912,  20000,  25000, 512, 16, 60, 4, 1, 1, 0 },
-    { 41,  245760,  8192, 12582912,  50000,  62500, 512, 16, 24, 2, 1, 1, 0 },
-    { 42,  522240,  8704, 13369344,  50000,  62500, 512, 16, 24, 2, 1, 1, 1 },
-    { 50,  589824, 22080, 42393600, 135000, 135000, 512, 16, 24, 2, 1, 1, 1 },
-    { 51,  983040, 36864, 70778880, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
-    { 52, 2073600, 36864, 70778880, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
+    { 10,    1485,    99,    396,     64,    175,  64, 64,  0, 2, 0, 0, 1 },
+    {  9,    1485,    99,    396,    128,    350,  64, 64,  0, 2, 0, 0, 1 }, /* "1b" */
+    { 11,    3000,   396,    900,    192,    500, 128, 64,  0, 2, 0, 0, 1 },
+    { 12,    6000,   396,   2376,    384,   1000, 128, 64,  0, 2, 0, 0, 1 },
+    { 13,   11880,   396,   2376,    768,   2000, 128, 64,  0, 2, 0, 0, 1 },
+    { 20,   11880,   396,   2376,   2000,   2000, 128, 64,  0, 2, 0, 0, 1 },
+    { 21,   19800,   792,   4752,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
+    { 22,   20250,  1620,   8100,   4000,   4000, 256, 64,  0, 2, 0, 0, 0 },
+    { 30,   40500,  1620,   8100,  10000,  10000, 256, 32, 22, 2, 0, 1, 0 },
+    { 31,  108000,  3600,  18000,  14000,  14000, 512, 16, 60, 4, 1, 1, 0 },
+    { 32,  216000,  5120,  20480,  20000,  20000, 512, 16, 60, 4, 1, 1, 0 },
+    { 40,  245760,  8192,  32786,  20000,  25000, 512, 16, 60, 4, 1, 1, 0 },
+    { 41,  245760,  8192,  32786,  50000,  62500, 512, 16, 24, 2, 1, 1, 0 },
+    { 42,  522240,  8704,  34816,  50000,  62500, 512, 16, 24, 2, 1, 1, 1 },
+    { 50,  589824, 22080, 110400, 135000, 135000, 512, 16, 24, 2, 1, 1, 1 },
+    { 51,  983040, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
+    { 52, 2073600, 36864, 184320, 240000, 240000, 512, 16, 24, 2, 1, 1, 1 },
     { 0 }
 };
 
@@ -758,7 +758,7 @@ int x264_validate_levels( x264_t *h, int verbose )
 {
     int ret = 0;
     int mbs = h->sps->i_mb_width * h->sps->i_mb_height;
-    int dpb = mbs * 384 * h->sps->vui.i_max_dec_frame_buffering;
+    int dpb = mbs * h->sps->vui.i_max_dec_frame_buffering;
     int cbp_factor = h->sps->i_profile_idc>=PROFILE_HIGH422 ? 16 :
                      h->sps->i_profile_idc==PROFILE_HIGH10 ? 12 :
                      h->sps->i_profile_idc==PROFILE_HIGH ? 5 : 4;
@@ -773,8 +773,8 @@ int x264_validate_levels( x264_t *h, int verbose )
         ERROR( "frame MB size (%dx%d) > level limit (%d)\n",
                h->sps->i_mb_width, h->sps->i_mb_height, l->frame_size );
     if( dpb > l->dpb )
-        ERROR( "DPB size (%d frames, %d bytes) > level limit (%d frames, %d bytes)\n",
-                h->sps->vui.i_max_dec_frame_buffering, dpb, (int)(l->dpb / (384*mbs)), l->dpb );
+        ERROR( "DPB size (%d frames, %d mbs) > level limit (%d frames, %d mbs)\n",
+                h->sps->vui.i_max_dec_frame_buffering, dpb, l->dpb / mbs, l->dpb );
 
 #define CHECK( name, limit, val ) \
     if( (val) > (limit) ) \
diff --git a/x264.c b/x264.c
index 901e947da8758dd619e7467b97db0a70dd9ac055..bcea87774bf3504eb4585cfb7fbf0e2e207813d4 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -1616,11 +1616,8 @@ generic_option:
         for( int i = 0; x264_levels[i].level_idc != 0; i++ )
             if( param->i_level_idc == x264_levels[i].level_idc )
             {
-                while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb &&
-                       param->i_frame_reference > 1 )
-                {
+                while( mbs * param->i_frame_reference > x264_levels[i].dpb && param->i_frame_reference > 1 )
                     param->i_frame_reference--;
-                }
                 break;
             }
     }
diff --git a/x264.h b/x264.h
index 5f28bb2e3e58ca9a512b2891d76bfa7f1bd60d02..9529ef89b152a273acb354707342add6fff11cd4 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -41,7 +41,7 @@
 
 #include "x264_config.h"
 
-#define X264_BUILD 128
+#define X264_BUILD 129
 
 /* Application developers planning to link against a shared library version of
  * libx264 from a Microsoft Visual Studio or similar development environment
@@ -523,7 +523,7 @@ typedef struct
     int level_idc;
     int mbps;        /* max macroblock processing rate (macroblocks/sec) */
     int frame_size;  /* max frame size (macroblocks) */
-    int dpb;         /* max decoded picture buffer (bytes) */
+    int dpb;         /* max decoded picture buffer (mbs) */
     int bitrate;     /* max bitrate (kbit/sec) */
     int cpb;         /* max vbv buffer (kbit) */
     int mv_range;    /* max vertical mv component range (pixels) */