From 28c0f2419db96278a14d126de3859a67d31d0a84 Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Sun, 1 Jan 2006 10:14:17 +0000 Subject: [PATCH] more error checking of input parameters git-svn-id: svn://svn.videolan.org/x264/trunk@394 df754926-b1dd-0310-bc7b-ec298dee348c --- encoder/encoder.c | 17 +++++++++++++++++ encoder/ratecontrol.c | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/encoder/encoder.c b/encoder/encoder.c index 68af6465..030d1526 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -352,6 +352,8 @@ static int x264_validate_parameters( x264_t *h ) } #endif + if( h->param.rc.b_cbr ) + h->param.rc.i_rf_constant = 0; if( h->param.rc.i_rf_constant > 0 ) h->param.rc.i_qp_constant = h->param.rc.i_rf_constant; h->param.rc.i_rf_constant = x264_clip3( h->param.rc.i_rf_constant, 0, 51 ); @@ -418,6 +420,7 @@ static int x264_validate_parameters( x264_t *h ) h->param.analyse.i_chroma_qp_offset = x264_clip3(h->param.analyse.i_chroma_qp_offset, -12, 12); if( !h->param.b_cabac ) h->param.analyse.i_trellis = 0; + h->param.analyse.i_trellis = x264_clip3( h->param.analyse.i_trellis, 0, 2 ); { const x264_level_t *l = x264_levels; @@ -439,6 +442,20 @@ static int x264_validate_parameters( x264_t *h ) if( h->param.rc.f_complexity_blur < 0 ) h->param.rc.f_complexity_blur = 0; + /* ensure the booleans are 0 or 1 so they can be used in math */ +#define BOOLIFY(x) h->param.x = !!h->param.x + BOOLIFY( b_cabac ); + BOOLIFY( b_deblocking_filter ); + BOOLIFY( analyse.b_transform_8x8 ); + BOOLIFY( analyse.b_weighted_bipred ); + BOOLIFY( analyse.b_bidir_me ); + BOOLIFY( analyse.b_chroma_me ); + BOOLIFY( analyse.b_fast_pskip ); + BOOLIFY( rc.b_cbr ); + BOOLIFY( rc.b_stat_write ); + BOOLIFY( rc.b_stat_read ); +#undef BOOLIFY + return 0; } diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index f7fc565c..9a07ed98 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -192,8 +192,14 @@ int x264_ratecontrol_new( x264_t *h ) if( rc->b_2pass && h->param.rc.i_rf_constant ) x264_log(h, X264_LOG_ERROR, "constant rate-factor is incompatible with 2pass.\n"); - if( h->param.rc.i_vbv_max_bitrate && !h->param.rc.b_cbr && !h->param.rc.i_rf_constant ) + if( h->param.rc.i_vbv_buffer_size && !h->param.rc.b_cbr && !h->param.rc.i_rf_constant ) x264_log(h, X264_LOG_ERROR, "VBV is incompatible with constant QP.\n"); + if( h->param.rc.i_vbv_buffer_size && h->param.rc.b_cbr + && h->param.rc.i_vbv_max_bitrate == 0 ) + { + x264_log( h, X264_LOG_DEBUG, "VBV maxrate unspecified, assuming CBR\n" ); + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate; + } if( h->param.rc.i_vbv_max_bitrate < h->param.rc.i_bitrate && h->param.rc.i_vbv_max_bitrate > 0) x264_log(h, X264_LOG_ERROR, "max bitrate less than average bitrate, ignored.\n"); -- 2.47.3