]> git.sesse.net Git - x264/blobdiff - encoder/set.c
copy current macroblock to a smaller buffer, to improve cache coherency and reduce...
[x264] / encoder / set.c
index 7d905edb7cc130f410be712013bae98ecea57344..26549c21122ef665a38cb85cebe3061e9c322aae 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <stdarg.h>
 #include <math.h>
 
-#include "x264.h"
 #include "common/common.h"
 #ifndef _MSC_VER
 #include "config.h"
@@ -46,15 +38,31 @@ static void scaling_list_write( bs_t *s, x264_pps_t *pps, int idx )
     const uint8_t *def_list = (idx==CQM_4IC) ? pps->scaling_list[CQM_4IY]
                             : (idx==CQM_4PC) ? pps->scaling_list[CQM_4PY]
                             : x264_cqm_jvt[idx];
-    int j;
-    if( memcmp( list, def_list, len ) )
+    if( !memcmp( list, def_list, len ) )
+        bs_write( s, 1, 0 ); // scaling_list_present_flag
+    else if( !memcmp( list, x264_cqm_jvt[idx], len ) )
     {
         bs_write( s, 1, 1 ); // scaling_list_present_flag
-        for( j = 0; j < len; j++ )
-            bs_write_se( s, list[zigzag[j]] - (j>0 ? list[zigzag[j-1]] : 8) ); // delta
+        bs_write_se( s, -8 ); // use jvt list
     }
     else
-        bs_write( s, 1, 0 ); // scaling_list_present_flag
+    {
+        int j, run;
+        bs_write( s, 1, 1 ); // scaling_list_present_flag
+
+        // try run-length compression of trailing values
+        for( run = len; run > 1; run-- )
+            if( list[zigzag[run-1]] != list[zigzag[run-2]] )
+                break;
+        if( run < len && len - run < bs_size_se( (int8_t)-list[zigzag[run]] ) )
+            run = len;
+
+        for( j = 0; j < run; j++ )
+            bs_write_se( s, (int8_t)(list[zigzag[j]] - (j>0 ? list[zigzag[j-1]] : 8)) ); // delta
+
+        if( run < len )
+            bs_write_se( s, (int8_t)-list[zigzag[run]] );
+    }
 }
 
 void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
@@ -104,11 +112,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
         }
     }
 
-    sps->vui.i_num_reorder_frames = param->b_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0;
-    /* extra slot with pyramid so that we don't have to override the
-     * order of forgetting old pictures */
-    sps->vui.i_max_dec_frame_buffering =
-    sps->i_num_ref_frames = X264_MIN(16, param->i_frame_reference + sps->vui.i_num_reorder_frames + param->b_bframe_pyramid);
+    sps->b_vui = 1;
 
     sps->b_gaps_in_frame_num_value_allowed = 0;
     sps->i_mb_width = ( param->i_width + 15 ) / 16;
@@ -129,21 +133,17 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     sps->b_crop = sps->crop.i_left  || sps->crop.i_top ||
                   sps->crop.i_right || sps->crop.i_bottom;
 
-    sps->b_vui = 0;
     sps->vui.b_aspect_ratio_info_present = 0;
-
     if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 )
     {
         sps->vui.b_aspect_ratio_info_present = 1;
         sps->vui.i_sar_width = param->vui.i_sar_width;
         sps->vui.i_sar_height= param->vui.i_sar_height;
     }
-    sps->b_vui |= sps->vui.b_aspect_ratio_info_present;
     
     sps->vui.b_overscan_info_present = ( param->vui.i_overscan ? 1 : 0 );
     if( sps->vui.b_overscan_info_present )
         sps->vui.b_overscan_info = ( param->vui.i_overscan == 2 ? 1 : 0 );
-    sps->b_vui |= sps->vui.b_overscan_info_present;
     
     sps->vui.b_signal_type_present = 0;
     sps->vui.i_vidformat = ( param->vui.i_vidformat <= 5 ? param->vui.i_vidformat : 5 );
@@ -166,7 +166,6 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     {
         sps->vui.b_signal_type_present = 1;
     }
-    sps->b_vui |= sps->vui.b_signal_type_present;
     
     /* FIXME: not sufficient for interlaced video */
     sps->vui.b_chroma_loc_info_present = ( param->vui.i_chroma_loc ? 1 : 0 );
@@ -175,21 +174,23 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
         sps->vui.i_chroma_loc_top = param->vui.i_chroma_loc;
         sps->vui.i_chroma_loc_bottom = param->vui.i_chroma_loc;
     }
-    sps->b_vui |= sps->vui.b_chroma_loc_info_present;
 
     sps->vui.b_timing_info_present = 0;
     if( param->i_fps_num > 0 && param->i_fps_den > 0)
     {
         sps->vui.b_timing_info_present = 1;
-        /* The standard is confusing me, but this seems to work best
-           with other encoders */
         sps->vui.i_num_units_in_tick = param->i_fps_den;
-        sps->vui.i_time_scale = param->i_fps_num;
+        sps->vui.i_time_scale = param->i_fps_num * 2;
         sps->vui.b_fixed_frame_rate = 1;
     }
-    sps->b_vui |= sps->vui.b_timing_info_present;
 
-    sps->vui.b_bitstream_restriction = param->i_bframe > 0;
+    sps->vui.i_num_reorder_frames = param->b_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0;
+    /* extra slot with pyramid so that we don't have to override the
+     * order of forgetting old pictures */
+    sps->vui.i_max_dec_frame_buffering =
+    sps->i_num_ref_frames = X264_MIN(16, param->i_frame_reference + sps->vui.i_num_reorder_frames + param->b_bframe_pyramid);
+
+    sps->vui.b_bitstream_restriction = 1;
     if( sps->vui.b_bitstream_restriction )
     {
         sps->vui.b_motion_vectors_over_pic_boundaries = 1;
@@ -198,7 +199,6 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
         sps->vui.i_log2_max_mv_length_horizontal =
         sps->vui.i_log2_max_mv_length_vertical = (int)(log(param->analyse.i_mv_range*4-1)/log(2)) + 1;
     }
-    sps->b_vui |= sps->vui.b_bitstream_restriction;
 }
 
 
@@ -447,7 +447,7 @@ void x264_pps_write( bs_t *s, x264_pps_t *pps )
     bs_rbsp_trailing( s );
 }
 
-void x264_sei_version_write( bs_t *s )
+void x264_sei_version_write( x264_t *h, bs_t *s )
 {
     int i;
     // random ID number generated according to ISO-11578
@@ -455,16 +455,21 @@ void x264_sei_version_write( bs_t *s )
         0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7,
         0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef
     };
-    char version[256];
+    char version[1200];
     int length;
-    sprintf( version, "x264 - core %d%s - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html",
-             X264_BUILD, X264_VERSION );
+    char *opts = x264_param2string( &h->param, 0 );
+
+    sprintf( version, "x264 - core %d%s - H.264/MPEG-4 AVC codec - "
+             "Copyleft 2005 - http://www.videolan.org/x264.html - options: %s",
+             X264_BUILD, X264_VERSION, opts );
+    x264_free( opts );
     length = strlen(version)+1+16;
 
     bs_write( s, 8, 0x5 ); // payload_type = user_data_unregistered
-    while( length > 255 )
-        bs_write( s, 8, 255 ), length -= 255;
-    bs_write( s, 8, length ); // payload_size
+    // payload_size
+    for( i = 0; i <= length-255; i += 255 )
+        bs_write( s, 8, 255 );
+    bs_write( s, 8, length-i );
 
     for( i = 0; i < 16; i++ )
         bs_write( s, 8, uuid[i] );
@@ -477,7 +482,7 @@ void x264_sei_version_write( bs_t *s )
 const x264_level_t x264_levels[] =
 {
     { 10,   1485,    99,   152064,     64,    175,  64, 64,  0, 0, 0, 1 },
-    {  9,   1485,    99,   152064,    128,    350,  64, 64,  0, 0, 0, 1 },
+//  {"1b",  1485,    99,   152064,    128,    350,  64, 64,  0, 0, 0, 1 },
     { 11,   3000,   396,   345600,    192,    500, 128, 64,  0, 0, 0, 1 },
     { 12,   6000,   396,   912384,    384,   1000, 128, 64,  0, 0, 0, 1 },
     { 13,  11880,   396,   912384,    768,   2000, 128, 64,  0, 0, 0, 1 },