]> git.sesse.net Git - x264/blobdiff - common/common.c
Make a bunch of small functions ALWAYS_INLINE
[x264] / common / common.c
index 51d89294dd6860d6633dc3f9628a8e8337353fa2..73a848a248935ea486b7d7895b952d33dc52431a 100644 (file)
@@ -158,6 +158,9 @@ void x264_param_default( x264_param_t *param )
     param->b_aud = 0;
     param->b_vfr_input = 1;
     param->b_dts_compress = 0;
+    param->i_nal_hrd = X264_NAL_HRD_NONE;
+    param->b_tff = 1;
+    param->b_pic_struct = 0;
 }
 
 static int x264_param_apply_preset( x264_param_t *param, const char *preset )
@@ -259,7 +262,7 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset )
     }
     else
     {
-        fprintf( stderr, "x264 [error]: invalid preset '%s'\n", preset );
+        x264_log( NULL, X264_LOG_ERROR, "invalid preset '%s'\n", preset );
         return -1;
     }
     return 0;
@@ -331,6 +334,7 @@ static int x264_param_apply_tune( x264_param_t *param, const char *tune )
             param->i_sync_lookahead = 0;
             param->i_bframe = 0;
             param->b_sliced_threads = 1;
+            param->b_vfr_input = 0;
         }
         else if( !strncasecmp( s, "touhou", 6 ) )
         {
@@ -345,14 +349,14 @@ static int x264_param_apply_tune( x264_param_t *param, const char *tune )
         }
         else
         {
-            fprintf( stderr, "x264 [error]: invalid tune '%s'\n", s );
+            x264_log( NULL, X264_LOG_ERROR, "invalid tune '%s'\n", s );
             x264_free( tmp );
             return -1;
         }
         if( 0 )
         {
     psy_failure:
-            fprintf( stderr, "x264 [warning]: only 1 psy tuning can be used: ignoring tune %s\n", s );
+            x264_log( NULL, X264_LOG_WARNING, "only 1 psy tuning can be used: ignoring tune %s\n", s );
         }
         s = strtok( NULL, ",./-+" );
     }
@@ -374,7 +378,7 @@ int x264_param_default_preset( x264_param_t *param, const char *preset, const ch
 void x264_param_apply_fastfirstpass( x264_param_t *param )
 {
     /* Set faster options in case of turbo firstpass. */
-    if( param->rc.b_stat_read && !param->rc.b_stat_write )
+    if( param->rc.b_stat_write && !param->rc.b_stat_read )
     {
         param->i_frame_reference = 1;
         param->analyse.b_transform_8x8 = 0;
@@ -399,7 +403,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
         param->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
         if( param->b_interlaced )
         {
-            fprintf( stderr, "x264 [error]: baseline profile doesn't support interlacing\n" );
+            x264_log( NULL, X264_LOG_ERROR, "baseline profile doesn't support interlacing\n" );
             return -1;
         }
     }
@@ -414,13 +418,13 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
     }
     else
     {
-        fprintf( stderr, "x264 [error]: invalid profile: %s\n", profile );
+        x264_log( NULL, X264_LOG_ERROR, "invalid profile: %s\n", profile );
         return -1;
     }
     if( (param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant == 0) ||
         (param->rc.i_rc_method == X264_RC_CRF && param->rc.f_rf_constant == 0) )
     {
-        fprintf( stderr, "x264 [error]: %s profile doesn't support lossless\n", profile );
+        x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );
         return -1;
     }
     return 0;
@@ -676,6 +680,13 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->i_cabac_init_idc = atoi(value);
     OPT("interlaced")
         p->b_interlaced = atobool(value);
+    OPT("tff")
+        p->b_interlaced = p->b_tff = atobool(value);
+    OPT("bff")
+    {
+        p->b_interlaced = atobool(value);
+        p->b_tff = !p->b_interlaced;
+    }
     OPT("constrained-intra")
         p->b_constrained_intra = atobool(value);
     OPT("cqm")
@@ -834,6 +845,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->rc.f_rf_constant = atof(value);
         p->rc.i_rc_method = X264_RC_CRF;
     }
+    OPT("crf-max")
+        p->rc.f_rf_constant_max = atof(value);
     OPT("rc-lookahead")
         p->rc.i_lookahead = atoi(value);
     OPT2("qpmin", "qp-min")
@@ -895,6 +908,10 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->b_annexb = atobool(value);
     OPT("force-cfr")
         p->b_vfr_input = !atobool(value);
+    OPT("nal-hrd")
+        b_error |= parse_enum( value, x264_nal_hrd_names, &p->i_nal_hrd );
+    OPT("pic-struct")
+        p->b_pic_struct = atobool(value);
     else
         return X264_PARAM_BAD_NAME;
 #undef OPT
@@ -970,6 +987,7 @@ int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_heigh
     pic->img.i_stride[1] = i_width / 2;
     pic->img.i_stride[2] = i_width / 2;
     pic->param = NULL;
+    pic->i_pic_struct = PIC_STRUCT_AUTO;
     return 0;
 }
 
@@ -1149,6 +1167,7 @@ char *x264_param2string( x264_param_t *p, int b_res )
     {
         s += sprintf( s, "%dx%d ", p->i_width, p->i_height );
         s += sprintf( s, "fps=%d/%d ", p->i_fps_num, p->i_fps_den );
+        s += sprintf( s, "timebase=%d/%d ", p->i_timebase_num, p->i_timebase_den );
     }
 
     s += sprintf( s, "cabac=%d", p->b_cabac );
@@ -1180,7 +1199,8 @@ char *x264_param2string( x264_param_t *p, int b_res )
         s += sprintf( s, " slice_max_mbs=%d", p->i_slice_max_mbs );
     s += sprintf( s, " nr=%d", p->analyse.i_noise_reduction );
     s += sprintf( s, " decimate=%d", p->analyse.b_dct_decimate );
-    s += sprintf( s, " mbaff=%d", p->b_interlaced );
+    s += sprintf( s, " interlaced=%s", p->b_interlaced ? p->b_tff ? "tff" : "bff" : "0" );
+
     s += sprintf( s, " constrained_intra=%d", p->b_constrained_intra );
 
     s += sprintf( s, " bframes=%d", p->i_bframe );
@@ -1214,8 +1234,12 @@ char *x264_param2string( x264_param_t *p, int b_res )
             s += sprintf( s, " cplxblur=%.1f qblur=%.1f",
                           p->rc.f_complexity_blur, p->rc.f_qblur );
         if( p->rc.i_vbv_buffer_size )
+        {
             s += sprintf( s, " vbv_maxrate=%d vbv_bufsize=%d",
                           p->rc.i_vbv_max_bitrate, p->rc.i_vbv_buffer_size );
+            if( p->rc.i_rc_method == X264_RC_CRF )
+                s += sprintf( s, " crf-max=%f", p->rc.f_rf_constant_max );
+        }
     }
     else if( p->rc.i_rc_method == X264_RC_CQP )
         s += sprintf( s, " qp=%d", p->rc.i_qp_constant );
@@ -1233,6 +1257,8 @@ char *x264_param2string( x264_param_t *p, int b_res )
             s += sprintf( s, " zones" );
     }
 
+    if( p->rc.i_vbv_buffer_size )
+        s += sprintf( s, " nal_hrd=%s", x264_nal_hrd_names[p->i_nal_hrd] );
     return buf;
 }