[x265] [PATCH] consolidate param functionality into param.cpp

Steve Borho steve at borho.org
Mon Feb 24 22:54:03 CET 2014


On Mon, Feb 24, 2014 at 7:43 AM,  <sagar at multicorewareinc.com> wrote:
> # HG changeset patch
> # User Sagar Kotecha <sagar at multicorewareinc.com>
> # Date 1393249400 -19800
> #      Mon Feb 24 19:13:20 2014 +0530
> # Node ID e7418fc7dbc61f11762a0adb634deaa2558241c2
> # Parent  80caa9f00d7c24da67d6b24e7bf339fe74752ced
> consolidate param functionality into param.cpp

This all looks ok except for the new param.h.  That header is
unnecessary, except perhaps for x265_param2string() and
x265_print_params() funcdefs.  Everything else in the header is a
duplicate of what is already defined in the public API x265.h; which
is wrong on many levels.

> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/common/CMakeLists.txt
> --- a/source/common/CMakeLists.txt      Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/common/CMakeLists.txt      Mon Feb 24 19:13:20 2014 +0530
> @@ -148,5 +148,6 @@
>      md5.cpp md5.h
>      TShortYUV.cpp TShortYUV.h mv.h
>      common.cpp common.h
> +    param.cpp param.h
>      lowres.cpp lowres.h
>      piclist.cpp piclist.h)
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/common/common.cpp
> --- a/source/common/common.cpp  Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/common/common.cpp  Mon Feb 24 19:13:20 2014 +0530
> @@ -135,122 +135,6 @@
>  }
>
>  extern "C"
> -void x265_param_default(x265_param *param)
> -{
> -    memset(param, 0, sizeof(x265_param));
> -
> -    /* Applying non-zero default values to all elements in the param structure */
> -    param->logLevel = X265_LOG_INFO;
> -    param->bEnableWavefront = 1;
> -    param->frameNumThreads = 0;
> -    param->poolNumThreads = 0;
> -    param->csvfn = NULL;
> -
> -    /* Source specifications */
> -    param->internalBitDepth = x265_max_bit_depth;
> -    param->internalCsp = X265_CSP_I420;
> -
> -    /* CU definitions */
> -    param->maxCUSize = 64;
> -    param->tuQTMaxInterDepth = 1;
> -    param->tuQTMaxIntraDepth = 1;
> -
> -    /* Coding Structure */
> -    param->keyframeMin = 0;
> -    param->keyframeMax = 250;
> -    param->bOpenGOP = 1;
> -    param->bframes = 4;
> -    param->lookaheadDepth = 20;
> -    param->bFrameAdaptive = X265_B_ADAPT_TRELLIS;
> -    param->bBPyramid = 1;
> -    param->scenecutThreshold = 40; /* Magic number pulled in from x264 */
> -
> -    /* Intra Coding Tools */
> -    param->bEnableConstrainedIntra = 0;
> -    param->bEnableStrongIntraSmoothing = 1;
> -
> -    /* Inter Coding tools */
> -    param->searchMethod = X265_HEX_SEARCH;
> -    param->subpelRefine = 2;
> -    param->searchRange = 57;
> -    param->maxNumMergeCand = 2;
> -    param->bEnableWeightedPred = 1;
> -    param->bEnableWeightedBiPred = 0;
> -    param->bEnableEarlySkip = 0;
> -    param->bEnableCbfFastMode = 0;
> -    param->bEnableAMP = 1;
> -    param->bEnableRectInter = 1;
> -    param->rdLevel = 3;
> -    param->bEnableSignHiding = 1;
> -    param->bEnableTransformSkip = 0;
> -    param->bEnableTSkipFast = 0;
> -    param->maxNumReferences = 3;
> -
> -    /* Loop Filter */
> -    param->bEnableLoopFilter = 1;
> -
> -    /* SAO Loop Filter */
> -    param->bEnableSAO = 1;
> -    param->saoLcuBoundary = 0;
> -    param->saoLcuBasedOptimization = 1;
> -
> -    /* Coding Quality */
> -    param->cbQpOffset = 0;
> -    param->crQpOffset = 0;
> -    param->rdPenalty = 0;
> -
> -    /* Rate control options */
> -    param->rc.vbvMaxBitrate = 0;
> -    param->rc.vbvBufferSize = 0;
> -    param->rc.vbvBufferInit = 0.9;
> -    param->rc.rfConstant = 28;
> -    param->rc.bitrate = 0;
> -    param->rc.rateTolerance = 1.0;
> -    param->rc.qCompress = 0.6;
> -    param->rc.ipFactor = 1.4f;
> -    param->rc.pbFactor = 1.3f;
> -    param->rc.qpStep = 4;
> -    param->rc.rateControlMode = X265_RC_CRF;
> -    param->rc.qp = 32;
> -    param->rc.aqMode = X265_AQ_VARIANCE;
> -    param->rc.aqStrength = 1.0;
> -    param->rc.cuTree = 1;
> -
> -    /* Quality Measurement Metrics */
> -    param->bEnablePsnr = 0;
> -    param->bEnableSsim = 0;
> -
> -    /* Video Usability Information (VUI) */
> -    param->bEnableVuiParametersPresentFlag = 0;
> -    param->bEnableAspectRatioIdc = 0;
> -    param->aspectRatioIdc = 0;
> -    param->sarWidth = 0;
> -    param->sarHeight = 0;
> -    param->bEnableOverscanAppropriateFlag = 0;
> -    param->bEnableVideoSignalTypePresentFlag = 0;
> -    param->videoFormat = 5;
> -    param->bEnableVideoFullRangeFlag = 0;
> -    param->bEnableColorDescriptionPresentFlag = 0;
> -    param->colorPrimaries = 2;
> -    param->transferCharacteristics = 2;
> -    param->matrixCoeffs = 2;
> -    param->bEnableChromaLocInfoPresentFlag = 0;
> -    param->chromaSampleLocTypeTopField = 0;
> -    param->chromaSampleLocTypeBottomField = 0;
> -    param->bEnableFieldSeqFlag = 0;
> -    param->bEnableFrameFieldInfoPresentFlag = 0;
> -    param->bEnableDefaultDisplayWindowFlag = 0;
> -    param->defDispWinLeftOffset = 0;
> -    param->defDispWinRightOffset = 0;
> -    param->defDispWinTopOffset = 0;
> -    param->defDispWinBottomOffset = 0;
> -    param->bEnableVuiTimingInfoPresentFlag = 0;
> -    param->bEnableVuiHrdParametersPresentFlag = 0;
> -    param->bEnableBitstreamRestrictionFlag = 0;
> -    param->bEnableSubPicHrdParamsPresentFlag = 0;
> -}
> -
> -extern "C"
>  void x265_picture_init(x265_param *param, x265_picture *pic)
>  {
>      memset(pic, 0, sizeof(x265_picture));
> @@ -259,924 +143,3 @@
>      pic->colorSpace = param->internalCsp;
>  }
>
> -extern "C"
> -int x265_param_apply_profile(x265_param *param, const char *profile)
> -{
> -    if (!profile)
> -        return 0;
> -    if (!strcmp(profile, "main"))
> -    {}
> -    else if (!strcmp(profile, "main10"))
> -    {
> -#if HIGH_BIT_DEPTH
> -        param->internalBitDepth = 10;
> -#else
> -        x265_log(param, X265_LOG_WARNING, "Main10 not supported, not compiled for 16bpp.\n");
> -        return -1;
> -#endif
> -    }
> -    else if (!strcmp(profile, "mainstillpicture"))
> -    {
> -        param->keyframeMax = 1;
> -        param->bOpenGOP = 0;
> -    }
> -    else
> -    {
> -        x265_log(param, X265_LOG_ERROR, "unknown profile <%s>\n", profile);
> -        return -1;
> -    }
> -
> -    return 0;
> -}
> -
> -extern "C"
> -int x265_param_default_preset(x265_param *param, const char *preset, const char *tune)
> -{
> -    x265_param_default(param);
> -
> -    if (preset)
> -    {
> -        char *end;
> -        int i = strtol(preset, &end, 10);
> -        if (*end == 0 && i >= 0 && i < (int)(sizeof(x265_preset_names) / sizeof(*x265_preset_names) - 1))
> -            preset = x265_preset_names[i];
> -
> -        if (!strcmp(preset, "ultrafast"))
> -        {
> -            param->lookaheadDepth = 10;
> -            param->scenecutThreshold = 0; // disable lookahead
> -            param->maxCUSize = 32;
> -            param->searchRange = 25;
> -            param->bFrameAdaptive = 0;
> -            param->subpelRefine = 0;
> -            param->searchMethod = X265_DIA_SEARCH;
> -            param->bEnableRectInter = 0;
> -            param->bEnableAMP = 0;
> -            param->bEnableEarlySkip = 1;
> -            param->bEnableCbfFastMode = 1;
> -            param->bEnableSAO = 0;
> -            param->bEnableSignHiding = 0;
> -            param->bEnableWeightedPred = 0;
> -            param->maxNumReferences = 1;
> -            param->rc.aqStrength = 0.0;
> -            param->rc.aqMode = X265_AQ_NONE;
> -            param->rc.cuTree = 0;
> -        }
> -        else if (!strcmp(preset, "superfast"))
> -        {
> -            param->lookaheadDepth = 10;
> -            param->maxCUSize = 32;
> -            param->searchRange = 44;
> -            param->bFrameAdaptive = 0;
> -            param->subpelRefine = 1;
> -            param->bEnableRectInter = 0;
> -            param->bEnableAMP = 0;
> -            param->bEnableEarlySkip = 1;
> -            param->bEnableCbfFastMode = 1;
> -            param->bEnableWeightedPred = 0;
> -            param->maxNumReferences = 1;
> -            param->rc.aqStrength = 0.0;
> -            param->rc.aqMode = X265_AQ_NONE;
> -            param->rc.cuTree = 0;
> -        }
> -        else if (!strcmp(preset, "veryfast"))
> -        {
> -            param->lookaheadDepth = 15;
> -            param->maxCUSize = 32;
> -            param->bFrameAdaptive = 0;
> -            param->subpelRefine = 1;
> -            param->bEnableRectInter = 0;
> -            param->bEnableAMP = 0;
> -            param->bEnableEarlySkip = 1;
> -            param->bEnableCbfFastMode = 1;
> -            param->maxNumReferences = 1;
> -            param->rc.cuTree = 0;
> -        }
> -        else if (!strcmp(preset, "faster"))
> -        {
> -            param->lookaheadDepth = 15;
> -            param->bFrameAdaptive = 0;
> -            param->bEnableRectInter = 0;
> -            param->bEnableAMP = 0;
> -            param->bEnableEarlySkip = 1;
> -            param->bEnableCbfFastMode = 1;
> -            param->maxNumReferences = 1;
> -            param->rc.cuTree = 0;
> -        }
> -        else if (!strcmp(preset, "fast"))
> -        {
> -            param->lookaheadDepth = 15;
> -            param->bEnableRectInter = 0;
> -            param->bEnableAMP = 0;
> -        }
> -        else if (!strcmp(preset, "medium"))
> -        {
> -            /* defaults */
> -        }
> -        else if (!strcmp(preset, "slow"))
> -        {
> -            param->lookaheadDepth = 25;
> -            param->rdLevel = 4;
> -            param->subpelRefine = 3;
> -            param->maxNumMergeCand = 3;
> -            param->searchMethod = X265_STAR_SEARCH;
> -        }
> -        else if (!strcmp(preset, "slower"))
> -        {
> -            param->lookaheadDepth = 30;
> -            param->bframes = 8;
> -            param->tuQTMaxInterDepth = 2;
> -            param->tuQTMaxIntraDepth = 2;
> -            param->rdLevel = 6;
> -            param->subpelRefine = 3;
> -            param->maxNumMergeCand = 3;
> -            param->searchMethod = X265_STAR_SEARCH;
> -        }
> -        else if (!strcmp(preset, "veryslow"))
> -        {
> -            param->lookaheadDepth = 40;
> -            param->bframes = 8;
> -            param->tuQTMaxInterDepth = 3;
> -            param->tuQTMaxIntraDepth = 3;
> -            param->rdLevel = 6;
> -            param->subpelRefine = 4;
> -            param->maxNumMergeCand = 4;
> -            param->searchMethod = X265_STAR_SEARCH;
> -            param->maxNumReferences = 5;
> -        }
> -        else if (!strcmp(preset, "placebo"))
> -        {
> -            param->lookaheadDepth = 60;
> -            param->searchRange = 92;
> -            param->bframes = 8;
> -            param->tuQTMaxInterDepth = 4;
> -            param->tuQTMaxIntraDepth = 4;
> -            param->rdLevel = 6;
> -            param->subpelRefine = 5;
> -            param->maxNumMergeCand = 5;
> -            param->searchMethod = X265_STAR_SEARCH;
> -            param->bEnableTransformSkip = 1;
> -            param->maxNumReferences = 5;
> -            // TODO: optimized esa
> -        }
> -        else
> -            return -1;
> -    }
> -    if (tune)
> -    {
> -        if (!strcmp(tune, "psnr"))
> -        {
> -            param->rc.aqStrength = 0.0;
> -        }
> -        else if (!strcmp(tune, "ssim"))
> -        {
> -            param->rc.aqMode = X265_AQ_AUTO_VARIANCE;
> -        }
> -        else if (!strcmp(tune, "zero-latency"))
> -        {
> -            param->bFrameAdaptive = 0;
> -            param->bframes = 0;
> -            param->lookaheadDepth = 0;
> -        }
> -        else
> -            return -1;
> -    }
> -
> -    return 0;
> -}
> -
> -static inline int _confirm(x265_param *param, bool bflag, const char* message)
> -{
> -    if (!bflag)
> -        return 0;
> -
> -    x265_log(param, X265_LOG_ERROR, "%s\n", message);
> -    return 1;
> -}
> -
> -int x265_check_params(x265_param *param)
> -{
> -#define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
> -    int check_failed = 0; /* abort if there is a fatal configuration problem */
> -
> -    CHECK(param->maxCUSize > 64,
> -          "max ctu size should be less than 64");
> -    CHECK(param->maxCUSize < 16,
> -          "Maximum partition width size should be larger than or equal to 16");
> -    if (check_failed == 1)
> -        return check_failed;
> -
> -    uint32_t maxCUDepth = (uint32_t)g_convertToBit[param->maxCUSize];
> -    uint32_t tuQTMaxLog2Size = maxCUDepth + 2 - 1;
> -    uint32_t tuQTMinLog2Size = 2; //log2(4)
> -
> -    CHECK((param->maxCUSize >> maxCUDepth) < 4,
> -          "Minimum partition width size should be larger than or equal to 8");
> -    CHECK(param->internalCsp != X265_CSP_I420 && param->internalCsp != X265_CSP_I444,
> -          "Only 4:2:0 and 4:4:4 color spaces is supported at this time");
> -
> -    /* These checks might be temporary */
> -#if HIGH_BIT_DEPTH
> -    CHECK(param->internalBitDepth != 10,
> -          "x265 was compiled for 10bit encodes, only 10bit inputs supported");
> -#endif
> -
> -    CHECK(param->internalBitDepth > x265_max_bit_depth,
> -          "internalBitDepth must be <= x265_max_bit_depth");
> -    CHECK(param->rc.qp < -6 * (param->internalBitDepth - 8) || param->rc.qp > 51,
> -          "QP exceeds supported range (-QpBDOffsety to 51)");
> -    CHECK(param->fpsNum == 0 || param->fpsDenom == 0,
> -          "Frame rate numerator and denominator must be specified");
> -    CHECK(param->searchMethod<0 || param->searchMethod> X265_FULL_SEARCH,
> -          "Search method is not supported value (0:DIA 1:HEX 2:UMH 3:HM 5:FULL)");
> -    CHECK(param->searchRange < 0,
> -          "Search Range must be more than 0");
> -    CHECK(param->searchRange >= 32768,
> -          "Search Range must be less than 32768");
> -    CHECK(param->subpelRefine > X265_MAX_SUBPEL_LEVEL,
> -          "subme must be less than or equal to X265_MAX_SUBPEL_LEVEL (7)");
> -    CHECK(param->subpelRefine < 0,
> -          "subme must be greater than or equal to 0");
> -    CHECK(param->frameNumThreads < 0,
> -          "frameNumThreads (--frame-threads) must be 0 or higher");
> -    CHECK(param->cbQpOffset < -12, "Min. Chroma Cb QP Offset is -12");
> -    CHECK(param->cbQpOffset >  12, "Max. Chroma Cb QP Offset is  12");
> -    CHECK(param->crQpOffset < -12, "Min. Chroma Cr QP Offset is -12");
> -    CHECK(param->crQpOffset >  12, "Max. Chroma Cr QP Offset is  12");
> -
> -    CHECK((1u << tuQTMaxLog2Size) > param->maxCUSize,
> -          "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
> -
> -    CHECK(param->tuQTMaxInterDepth < 1,
> -          "QuadtreeTUMaxDepthInter must be greater than or equal to 1");
> -    CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxInterDepth - 1)),
> -          "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
> -    CHECK(param->tuQTMaxIntraDepth < 1,
> -          "QuadtreeTUMaxDepthIntra must be greater than or equal to 1");
> -    CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxIntraDepth - 1)),
> -          "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
> -
> -    CHECK(param->maxNumMergeCand < 1, "MaxNumMergeCand must be 1 or greater.");
> -    CHECK(param->maxNumMergeCand > 5, "MaxNumMergeCand must be 5 or smaller.");
> -
> -    CHECK(param->maxNumReferences < 1, "maxNumReferences must be 1 or greater.");
> -    CHECK(param->maxNumReferences > MAX_NUM_REF, "maxNumReferences must be 16 or smaller.");
> -
> -    CHECK(param->sourceWidth  % TComSPS::getWinUnitX(param->internalCsp) != 0,
> -          "Picture width must be an integer multiple of the specified chroma subsampling");
> -    CHECK(param->sourceHeight % TComSPS::getWinUnitY(param->internalCsp) != 0,
> -          "Picture height must be an integer multiple of the specified chroma subsampling");
> -
> -    CHECK(param->rc.rateControlMode<X265_RC_ABR || param->rc.rateControlMode> X265_RC_CRF,
> -          "Rate control mode is out of range");
> -    CHECK(param->rdLevel < 0 || param->rdLevel > 6,
> -          "RD Level is out of range");
> -    CHECK(param->bframes > param->lookaheadDepth,
> -          "Lookahead depth must be greater than the max consecutive bframe count");
> -    CHECK(param->bframes < 0,
> -          "bframe count should be greater than zero");
> -    CHECK(param->bframes > X265_BFRAME_MAX,
> -          "max consecutive bframe count must be 16 or smaller");
> -    CHECK(param->lookaheadDepth > X265_LOOKAHEAD_MAX,
> -          "Lookahead depth must be less than 256");
> -    CHECK(param->rc.aqMode < X265_AQ_NONE || X265_AQ_AUTO_VARIANCE < param->rc.aqMode,
> -          "Aq-Mode is out of range");
> -    CHECK(param->rc.aqStrength < 0 || param->rc.aqStrength > 3,
> -          "Aq-Strength is out of range");
> -
> -    // max CU size should be power of 2
> -    uint32_t i = param->maxCUSize;
> -    while (i)
> -    {
> -        i >>= 1;
> -        if ((i & 1) == 1)
> -            CHECK(i != 1, "Max CU size should be 2^n");
> -    }
> -
> -    CHECK(param->bEnableWavefront < 0, "WaveFrontSynchro cannot be negative");
> -    CHECK((param->aspectRatioIdc < 0
> -           || param->aspectRatioIdc > 16)
> -          && param->aspectRatioIdc != X265_EXTENDED_SAR,
> -          "Sample Aspect Ratio must be 0-16 or 255");
> -    CHECK(param->aspectRatioIdc == X265_EXTENDED_SAR && param->sarWidth <= 0,
> -          "Sample Aspect Ratio width must be greater than 0");
> -    CHECK(param->aspectRatioIdc == X265_EXTENDED_SAR && param->sarHeight <= 0,
> -          "Sample Aspect Ratio height must be greater than 0");
> -    CHECK(param->videoFormat < 0 || param->videoFormat > 5,
> -          "Video Format must be Component component,"
> -          " pal, ntsc, secam, mac or undef");
> -    CHECK(param->colorPrimaries < 0
> -          || param->colorPrimaries > 9
> -          || param->colorPrimaries == 3,
> -          "Color Primaries must be undef, bt709, bt470m,"
> -          " bt470bg, smpte170m, smpte240m, film or bt2020");
> -    CHECK(param->transferCharacteristics < 0
> -          || param->transferCharacteristics > 15
> -          || param->transferCharacteristics == 3,
> -          "Transfer Characteristics must be undef, bt709, bt470m, bt470bg,"
> -          " smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e,"
> -          " iec61966-2-1, bt2020-10 or bt2020-12");
> -    CHECK(param->matrixCoeffs < 0
> -          || param->matrixCoeffs > 10
> -          || param->matrixCoeffs == 3,
> -          "Matrix Coefficients must be undef, bt709, fcc, bt470bg, smpte170m,"
> -          " smpte240m, GBR, YCgCo, bt2020nc or bt2020c");
> -    CHECK(param->chromaSampleLocTypeTopField < 0
> -          || param->chromaSampleLocTypeTopField > 5,
> -          "Chroma Sample Location Type Top Field must be 0-5");
> -    CHECK(param->chromaSampleLocTypeBottomField < 0
> -          || param->chromaSampleLocTypeBottomField > 5,
> -          "Chroma Sample Location Type Bottom Field must be 0-5");
> -    CHECK(param->defDispWinLeftOffset < 0,
> -          "Default Display Window Left Offset must be 0 or greater");
> -    CHECK(param->defDispWinRightOffset < 0,
> -          "Default Display Window Right Offset must be 0 or greater");
> -    CHECK(param->defDispWinTopOffset < 0,
> -          "Default Display Window Top Offset must be 0 or greater");
> -    CHECK(param->defDispWinBottomOffset < 0,
> -          "Default Display Window Bottom Offset must be 0 or greater");
> -    return check_failed;
> -}
> -
> -int x265_set_globals(x265_param *param)
> -{
> -    uint32_t maxCUDepth = (uint32_t)g_convertToBit[param->maxCUSize];
> -    uint32_t tuQTMinLog2Size = 2; //log2(4)
> -
> -    static int once /* = 0 */;
> -
> -    if (ATOMIC_CAS32(&once, 0, 1) == 1)
> -    {
> -        if (param->maxCUSize != g_maxCUWidth)
> -        {
> -            x265_log(param, X265_LOG_ERROR, "maxCUSize must be the same for all encoders in a single process");
> -            return -1;
> -        }
> -        if (param->internalBitDepth != g_bitDepth)
> -        {
> -            x265_log(param, X265_LOG_ERROR, "internalBitDepth must be the same for all encoders in a single process");
> -            return -1;
> -        }
> -    }
> -    else
> -    {
> -        // set max CU width & height
> -        g_maxCUWidth  = param->maxCUSize;
> -        g_maxCUHeight = param->maxCUSize;
> -        g_bitDepth = param->internalBitDepth;
> -
> -        // compute actual CU depth with respect to config depth and max transform size
> -        g_addCUDepth = 0;
> -        while ((param->maxCUSize >> maxCUDepth) > (1u << (tuQTMinLog2Size + g_addCUDepth)))
> -        {
> -            g_addCUDepth++;
> -        }
> -
> -        maxCUDepth += g_addCUDepth;
> -        g_addCUDepth++;
> -        g_maxCUDepth = maxCUDepth;
> -
> -        // initialize partition order
> -        uint32_t* tmp = &g_zscanToRaster[0];
> -        initZscanToRaster(g_maxCUDepth + 1, 1, 0, tmp);
> -        initRasterToZscan(g_maxCUWidth, g_maxCUHeight, g_maxCUDepth + 1);
> -
> -        // initialize conversion matrix from partition index to pel
> -        initRasterToPelXY(g_maxCUWidth, g_maxCUHeight, g_maxCUDepth + 1);
> -    }
> -    return 0;
> -}
> -
> -void x265_print_params(x265_param *param)
> -{
> -    if (param->logLevel < X265_LOG_INFO)
> -        return;
> -#if HIGH_BIT_DEPTH
> -    x265_log(param, X265_LOG_INFO, "Internal bit depth                  : %d\n", param->internalBitDepth);
> -#endif
> -    x265_log(param, X265_LOG_INFO, "CU size                             : %d\n", param->maxCUSize);
> -    x265_log(param, X265_LOG_INFO, "Max RQT depth inter / intra         : %d / %d\n", param->tuQTMaxInterDepth, param->tuQTMaxIntraDepth);
> -
> -    x265_log(param, X265_LOG_INFO, "ME / range / subpel / merge         : %s / %d / %d / %d\n",
> -             x265_motion_est_names[param->searchMethod], param->searchRange, param->subpelRefine, param->maxNumMergeCand);
> -    if (param->keyframeMax != INT_MAX || param->scenecutThreshold)
> -    {
> -        x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut       : %d / %d / %d\n", param->keyframeMin, param->keyframeMax, param->scenecutThreshold);
> -    }
> -    else
> -    {
> -        x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut       : disabled\n");
> -    }
> -    if (param->cbQpOffset || param->crQpOffset)
> -    {
> -        x265_log(param, X265_LOG_INFO, "Cb/Cr QP Offset              : %d / %d\n", param->cbQpOffset, param->crQpOffset);
> -    }
> -    if (param->rdPenalty)
> -    {
> -        x265_log(param, X265_LOG_INFO, "RDpenalty                    : %d\n", param->rdPenalty);
> -    }
> -    x265_log(param, X265_LOG_INFO, "Lookahead / bframes / badapt        : %d / %d / %d\n", param->lookaheadDepth, param->bframes, param->bFrameAdaptive);
> -    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / refs          : %d / %d / %d\n", param->bBPyramid, param->bEnableWeightedPred, param->maxNumReferences);
> -    switch (param->rc.rateControlMode)
> -    {
> -    case X265_RC_ABR:
> -        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : ABR-%d kbps / %0.1f / %d\n", param->rc.bitrate,
> -                 param->rc.aqStrength, param->rc.cuTree);
> -        break;
> -    case X265_RC_CQP:
> -        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : CQP-%d / %0.1f / %d\n", param->rc.qp, param->rc.aqStrength,
> -                 param->rc.cuTree);
> -        break;
> -    case X265_RC_CRF:
> -        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : CRF-%0.1f / %0.1f / %d\n", param->rc.rfConstant,
> -                 param->rc.aqStrength, param->rc.cuTree);
> -        break;
> -    }
> -
> -    x265_log(param, X265_LOG_INFO, "tools: ");
> -#define TOOLOPT(FLAG, STR) if (FLAG) fprintf(stderr, "%s ", STR)
> -    TOOLOPT(param->bEnableRectInter, "rect");
> -    TOOLOPT(param->bEnableAMP, "amp");
> -    TOOLOPT(param->bEnableCbfFastMode, "cfm");
> -    TOOLOPT(param->bEnableConstrainedIntra, "cip");
> -    TOOLOPT(param->bEnableEarlySkip, "esd");
> -    fprintf(stderr, "rd=%d ", param->rdLevel);
> -
> -    TOOLOPT(param->bEnableLoopFilter, "lft");
> -    if (param->bEnableSAO)
> -    {
> -        if (param->saoLcuBasedOptimization)
> -            fprintf(stderr, "sao-lcu ");
> -        else
> -            fprintf(stderr, "sao-frame ");
> -    }
> -    TOOLOPT(param->bEnableSignHiding, "sign-hide");
> -    if (param->bEnableTransformSkip)
> -    {
> -        if (param->bEnableTSkipFast)
> -            fprintf(stderr, "tskip(fast) ");
> -        else
> -            fprintf(stderr, "tskip ");
> -    }
> -    TOOLOPT(param->bEnableWeightedBiPred, "weightbp");
> -    fprintf(stderr, "\n");
> -    fflush(stderr);
> -}
> -
> -static int x265_atobool(const char *str, bool& bError)
> -{
> -    if (!strcmp(str, "1") ||
> -        !strcmp(str, "true") ||
> -        !strcmp(str, "yes"))
> -        return 1;
> -    if (!strcmp(str, "0") ||
> -        !strcmp(str, "false") ||
> -        !strcmp(str, "no"))
> -        return 0;
> -    bError = true;
> -    return 0;
> -}
> -
> -static int x265_atoi(const char *str, bool& bError)
> -{
> -    char *end;
> -    int v = strtol(str, &end, 0);
> -
> -    if (end == str || *end != '\0')
> -        bError = true;
> -    return v;
> -}
> -
> -static double x265_atof(const char *str, bool& bError)
> -{
> -    char *end;
> -    double v = strtod(str, &end);
> -
> -    if (end == str || *end != '\0')
> -        bError = true;
> -    return v;
> -}
> -
> -static int parseName(const char *arg, const char * const * names, bool& bError)
> -{
> -    for (int i = 0; names[i]; i++)
> -    {
> -        if (!strcmp(arg, names[i]))
> -        {
> -            return i;
> -        }
> -    }
> -
> -    return x265_atoi(arg, bError);
> -}
> -
> -/* internal versions of string-to-int with additional error checking */
> -#undef atoi
> -#undef atof
> -#define atoi(str) x265_atoi(str, bError)
> -#define atof(str) x265_atof(str, bError)
> -#define atobool(str) (bNameWasBool = true, x265_atobool(str, bError))
> -
> -extern "C"
> -int x265_param_parse(x265_param *p, const char *name, const char *value)
> -{
> -    bool bError = false;
> -    bool bNameWasBool = false;
> -    bool bValueWasNull = !value;
> -    char nameBuf[64];
> -
> -    if (!name)
> -        return X265_PARAM_BAD_NAME;
> -
> -    // s/_/-/g
> -    if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
> -    {
> -        char *c;
> -        strcpy(nameBuf, name);
> -        while ((c = strchr(nameBuf, '_')) != 0)
> -        {
> -            *c = '-';
> -        }
> -
> -        name = nameBuf;
> -    }
> -
> -    if (!strncmp(name, "no-", 3))
> -    {
> -        name += 3;
> -        value = !value || x265_atobool(value, bError) ? "false" : "true";
> -    }
> -    else if (!strncmp(name, "no", 2))
> -    {
> -        name += 2;
> -        value = !value || x265_atobool(value, bError) ? "false" : "true";
> -    }
> -    else if (!value)
> -        value = "true";
> -    else if (value[0] == '=')
> -        value++;
> -
> -#if defined(_MSC_VER)
> -#pragma warning(disable: 4127) // conditional expression is constant
> -#endif
> -#define OPT(STR) else if (!strcmp(name, STR))
> -    if (0) ;
> -    OPT("fps")
> -    {
> -        if (sscanf(value, "%u/%u", &p->fpsNum, &p->fpsDenom) == 2)
> -            ;
> -        else
> -        {
> -            float fps = (float)atof(value);
> -            if (fps > 0 && fps <= INT_MAX / 1000)
> -            {
> -                p->fpsNum = (int)(fps * 1000 + .5);
> -                p->fpsDenom = 1000;
> -            }
> -            else
> -            {
> -                p->fpsNum = atoi(value);
> -                p->fpsDenom = 1;
> -            }
> -        }
> -    }
> -    OPT("csv") p->csvfn = value;
> -    OPT("threads") p->poolNumThreads = atoi(value);
> -    OPT("frame-threads") p->frameNumThreads = atoi(value);
> -    OPT("log") p->logLevel = atoi(value);
> -    OPT("wpp") p->bEnableWavefront = atobool(value);
> -    OPT("ctu") p->maxCUSize = (uint32_t)atoi(value);
> -    OPT("tu-intra-depth") p->tuQTMaxIntraDepth = (uint32_t)atoi(value);
> -    OPT("tu-inter-depth") p->tuQTMaxInterDepth = (uint32_t)atoi(value);
> -    OPT("subme") p->subpelRefine = atoi(value);
> -    OPT("merange") p->searchRange = atoi(value);
> -    OPT("rect") p->bEnableRectInter = atobool(value);
> -    OPT("amp") p->bEnableAMP = atobool(value);
> -    OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value);
> -    OPT("early-skip") p->bEnableEarlySkip = atobool(value);
> -    OPT("fast-cbf") p->bEnableCbfFastMode = atobool(value);
> -    OPT("rdpenalty") p->rdPenalty = atoi(value);
> -    OPT("tskip") p->bEnableTransformSkip = atobool(value);
> -    OPT("no-tskip-fast") p->bEnableTSkipFast = atobool(value);
> -    OPT("tskip-fast") p->bEnableTSkipFast = atobool(value);
> -    OPT("strong-intra-smoothing") p->bEnableStrongIntraSmoothing = atobool(value);
> -    OPT("constrained-intra") p->bEnableConstrainedIntra = atobool(value);
> -    OPT("open-gop") p->bOpenGOP = atobool(value);
> -    OPT("scenecut") p->scenecutThreshold = atoi(value);
> -    OPT("keyint") p->keyframeMax = atoi(value);
> -    OPT("min-keyint") p->keyframeMin = atoi(value);
> -    OPT("rc-lookahead") p->lookaheadDepth = atoi(value);
> -    OPT("bframes") p->bframes = atoi(value);
> -    OPT("bframe-bias") p->bFrameBias = atoi(value);
> -    OPT("b-adapt") p->bFrameAdaptive = atoi(value);
> -    OPT("ref") p->maxNumReferences = atoi(value);
> -    OPT("weightp") p->bEnableWeightedPred = atobool(value);
> -    OPT("cbqpoffs") p->cbQpOffset = atoi(value);
> -    OPT("crqpoffs") p->crQpOffset = atoi(value);
> -    OPT("rd") p->rdLevel = atoi(value);
> -    OPT("signhide") p->bEnableSignHiding = atobool(value);
> -    OPT("lft") p->bEnableLoopFilter = atobool(value);
> -    OPT("sao") p->bEnableSAO = atobool(value);
> -    OPT("sao-lcu-bounds") p->saoLcuBoundary = atoi(value);
> -    OPT("sao-lcu-opt") p->saoLcuBasedOptimization = atoi(value);
> -    OPT("ssim") p->bEnableSsim = atobool(value);
> -    OPT("psnr") p->bEnablePsnr = atobool(value);
> -    OPT("hash") p->decodedPictureHashSEI = atoi(value);
> -    OPT("b-pyramid") p->bBPyramid = atobool(value);
> -    OPT("aq-mode") p->rc.aqMode = atoi(value);
> -    OPT("aq-strength") p->rc.aqStrength = atof(value);
> -    OPT("vbv-maxrate") p->rc.vbvMaxBitrate = atoi(value);
> -    OPT("vbv-bufsize") p->rc.vbvBufferSize = atoi(value);
> -    OPT("vbv-init")    p->rc.vbvBufferInit = atof(value);
> -    OPT("crf")
> -    {
> -        p->rc.rfConstant = atof(value);
> -        p->rc.rateControlMode = X265_RC_CRF;
> -    }
> -    OPT("bitrate")
> -    {
> -        p->rc.bitrate = atoi(value);
> -        p->rc.rateControlMode = X265_RC_ABR;
> -    }
> -    OPT("qp")
> -    {
> -        p->rc.qp = atoi(value);
> -        p->rc.rateControlMode = X265_RC_CQP;
> -    }
> -    OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, bError);
> -    OPT("me")        p->searchMethod = parseName(value, x265_motion_est_names, bError);
> -    OPT("cutree")    p->rc.cuTree = atobool(value);
> -    OPT("vui")
> -    {
> -        int bvalue = atobool(value);
> -
> -        p->bEnableVuiParametersPresentFlag = bvalue;
> -        p->bEnableAspectRatioIdc = bvalue;
> -        p->bEnableOverscanInfoPresentFlag = bvalue;
> -        p->bEnableVideoSignalTypePresentFlag = bvalue;
> -        p->bEnableColorDescriptionPresentFlag = bvalue;
> -        p->bEnableChromaLocInfoPresentFlag = bvalue;
> -        p->bEnableFieldSeqFlag = bvalue;
> -        p->bEnableFrameFieldInfoPresentFlag = bvalue;
> -        p->bEnableDefaultDisplayWindowFlag = bvalue;
> -        p->bEnableVuiTimingInfoPresentFlag = bvalue;
> -        p->bEnableVuiHrdParametersPresentFlag = bvalue;
> -        p->bEnableBitstreamRestrictionFlag = bvalue;
> -        p->bEnableSubPicHrdParamsPresentFlag = bvalue;
> -    }
> -    OPT("sar")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableAspectRatioIdc = atobool(value);
> -        p->aspectRatioIdc = atoi(value);
> -    }
> -    OPT("extended-sar")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableAspectRatioIdc = 1;
> -        p->aspectRatioIdc = X265_EXTENDED_SAR;
> -        bError |= sscanf(value, "%dx%d", &p->sarWidth, &p->sarHeight) != 2;
> -    }
> -    OPT("overscan")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        if (!strcmp(value, "show"))
> -            p->bEnableOverscanInfoPresentFlag = 1;
> -        else if (!strcmp(value, "crop"))
> -        {
> -            p->bEnableOverscanInfoPresentFlag = 1;
> -            p->bEnableOverscanAppropriateFlag = 1;
> -        }
> -        else
> -            p->bEnableOverscanInfoPresentFlag = -1;
> -    }
> -    OPT("videoformat")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVideoSignalTypePresentFlag = 1;
> -        if (!strcmp(value, "component"))
> -            p->videoFormat = 0;
> -        else if (!strcmp(value, "pal"))
> -            p->videoFormat = 1;
> -        else if (!strcmp(value, "ntsc"))
> -            p->videoFormat = 2;
> -        else if (!strcmp(value, "secam"))
> -            p->videoFormat = 3;
> -        else if (!strcmp(value, "mac"))
> -            p->videoFormat = 4;
> -        else if (!strcmp(value, "undef"))
> -            p->videoFormat = 5;
> -        else
> -            p->videoFormat = -1;
> -    }
> -    OPT("range")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVideoSignalTypePresentFlag = atobool(value);
> -        p->bEnableVideoFullRangeFlag = atobool(value);
> -    }
> -    OPT("colorprim")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVideoSignalTypePresentFlag = 1;
> -        p->bEnableColorDescriptionPresentFlag = 1;
> -        if (!strcmp(value, "bt709"))
> -            p->colorPrimaries = 1;
> -        else if (!strcmp(value, "undef"))
> -            p->colorPrimaries = 2;
> -        else if (!strcmp(value, "bt470m"))
> -            p->colorPrimaries = 4;
> -        else if (!strcmp(value, "bt470bg"))
> -            p->colorPrimaries = 5;
> -        else if (!strcmp(value, "smpte170m"))
> -            p->colorPrimaries = 6;
> -        else if (!strcmp(value, "smpte240m"))
> -            p->colorPrimaries = 7;
> -        else if (!strcmp(value, "film"))
> -            p->colorPrimaries = 8;
> -        else if (!strcmp(value, "bt2020"))
> -            p->colorPrimaries = 9;
> -        else
> -            p->colorPrimaries = -1;
> -    }
> -    OPT("transfer")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVideoSignalTypePresentFlag = 1;
> -        p->bEnableColorDescriptionPresentFlag = 1;
> -        if (!strcmp(value, "bt709"))
> -            p->transferCharacteristics = 1;
> -        else if (!strcmp(value, "undef"))
> -            p->transferCharacteristics = 2;
> -        else if (!strcmp(value, "bt470m"))
> -            p->transferCharacteristics = 4;
> -        else if (!strcmp(value, "bt470bg"))
> -            p->transferCharacteristics = 5;
> -        else if (!strcmp(value, "smpte170m"))
> -            p->transferCharacteristics = 6;
> -        else if (!strcmp(value, "smpte240m"))
> -            p->transferCharacteristics = 7;
> -        else if (!strcmp(value, "linear"))
> -            p->transferCharacteristics = 8;
> -        else if (!strcmp(value, "log100"))
> -            p->transferCharacteristics = 9;
> -        else if (!strcmp(value, "log316"))
> -            p->transferCharacteristics = 10;
> -        else if (!strcmp(value, "iec61966-2-4"))
> -            p->transferCharacteristics = 11;
> -        else if (!strcmp(value, "bt1361e"))
> -            p->transferCharacteristics = 12;
> -        else if (!strcmp(value, "iec61966-2-1"))
> -            p->transferCharacteristics = 13;
> -        else if (!strcmp(value, "bt2020-10"))
> -            p->transferCharacteristics = 14;
> -        else if (!strcmp(value, "bt2020-12"))
> -            p->transferCharacteristics = 15;
> -        else
> -            p->transferCharacteristics = -1;
> -    }
> -    OPT("colormatrix")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVideoSignalTypePresentFlag = 1;
> -        p->bEnableColorDescriptionPresentFlag = 1;
> -        if (!strcmp(value, "GBR"))
> -            p->matrixCoeffs = 0;
> -        else if (!strcmp(value, "bt709"))
> -            p->matrixCoeffs = 1;
> -        else if (!strcmp(value, "undef"))
> -            p->matrixCoeffs = 2;
> -        else if (!strcmp(value, "fcc"))
> -            p->matrixCoeffs = 4;
> -        else if (!strcmp(value, "bt470bg"))
> -            p->matrixCoeffs = 5;
> -        else if (!strcmp(value, "smpte170m"))
> -            p->matrixCoeffs = 6;
> -        else if (!strcmp(value, "smpte240m"))
> -            p->matrixCoeffs = 7;
> -        else if (!strcmp(value, "YCgCo"))
> -            p->matrixCoeffs = 8;
> -        else if (!strcmp(value, "bt2020nc"))
> -            p->matrixCoeffs = 9;
> -        else if (!strcmp(value, "bt2020c"))
> -            p->matrixCoeffs = 10;
> -        else
> -            p->matrixCoeffs = -1;
> -    }
> -    OPT("chromaloc")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableChromaLocInfoPresentFlag = 1;
> -        p->chromaSampleLocTypeTopField = atoi(value);
> -        p->chromaSampleLocTypeBottomField = p->chromaSampleLocTypeTopField;
> -    }
> -    OPT("fieldseq")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableFieldSeqFlag = atobool(value);
> -    }
> -    OPT("framefieldinfo")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableFrameFieldInfoPresentFlag = atobool(value);
> -    }
> -    OPT("crop-rect")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableDefaultDisplayWindowFlag = 1;
> -        bError |= sscanf(value, "%d,%d,%d,%d",
> -                         &p->defDispWinLeftOffset,
> -                         &p->defDispWinTopOffset,
> -                         &p->defDispWinRightOffset,
> -                         &p->defDispWinBottomOffset) != 4;
> -    }
> -    OPT("timinginfo")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVuiTimingInfoPresentFlag = atobool(value);
> -    }
> -    OPT("nal-hrd")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVuiTimingInfoPresentFlag = atobool(value);
> -        p->bEnableVuiHrdParametersPresentFlag = atobool(value);
> -    }
> -    OPT("bitstreamrestriction")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableBitstreamRestrictionFlag = atobool(value);
> -    }
> -    OPT("subpichrd")
> -    {
> -        p->bEnableVuiParametersPresentFlag = 1;
> -        p->bEnableVuiHrdParametersPresentFlag = atobool(value);
> -        p->bEnableSubPicHrdParamsPresentFlag = atobool(value);
> -    }
> -    else
> -        return X265_PARAM_BAD_NAME;
> -#undef OPT
> -#undef atobool
> -#undef atoi
> -#undef atof
> -
> -    bError |= bValueWasNull && !bNameWasBool;
> -    return bError ? X265_PARAM_BAD_VALUE : 0;
> -}
> -
> -char *x265_param2string(x265_param *p)
> -{
> -    char *buf, *s;
> -
> -    buf = s = X265_MALLOC(char, 2000);
> -    if (!buf)
> -        return NULL;
> -
> -#define BOOL(param, cliopt) \
> -    s += sprintf(s, " %s", (param) ? cliopt : "no-"cliopt);
> -
> -    BOOL(p->bEnableWavefront, "wpp");
> -    s += sprintf(s, " fps=%d/%d", p->fpsNum, p->fpsDenom);
> -    s += sprintf(s, " ctu=%d", p->maxCUSize);
> -    s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth);
> -    s += sprintf(s, " tu-inter-depth=%d", p->tuQTMaxInterDepth);
> -    s += sprintf(s, " me=%d", p->searchMethod);
> -    s += sprintf(s, " subme=%d", p->subpelRefine);
> -    s += sprintf(s, " merange=%d", p->searchRange);
> -    BOOL(p->bEnableRectInter, "rect");
> -    BOOL(p->bEnableAMP, "amp");
> -    s += sprintf(s, " max-merge=%d", p->maxNumMergeCand);
> -    BOOL(p->bEnableEarlySkip, "early-skip");
> -    BOOL(p->bEnableCbfFastMode, "fast-cbf");
> -    s += sprintf(s, " rdpenalty=%d", p->rdPenalty);
> -    BOOL(p->bEnableTransformSkip, "tskip");
> -    BOOL(p->bEnableTSkipFast, "tskip-fast");
> -    BOOL(p->bEnableStrongIntraSmoothing, "strong-intra-smoothing");
> -    BOOL(p->bEnableConstrainedIntra, "constrained-intra");
> -    BOOL(p->bOpenGOP, "open-gop");
> -    s += sprintf(s, " keyint=%d", p->keyframeMax);
> -    s += sprintf(s, " min-keyint=%d", p->keyframeMin);
> -    s += sprintf(s, " scenecut=%d", p->scenecutThreshold);
> -    s += sprintf(s, " rc-lookahead=%d", p->lookaheadDepth);
> -    s += sprintf(s, " bframes=%d", p->bframes);
> -    s += sprintf(s, " bframe-bias=%d", p->bFrameBias);
> -    s += sprintf(s, " b-adapt=%d", p->bFrameAdaptive);
> -    s += sprintf(s, " ref=%d", p->maxNumReferences);
> -    BOOL(p->bEnableWeightedPred, "weightp");
> -    s += sprintf(s, " bitrate=%d", p->rc.bitrate);
> -    s += sprintf(s, " qp=%d", p->rc.qp);
> -    s += sprintf(s, " aq-mode=%d", p->rc.aqMode);
> -    s += sprintf(s, " aq-strength=%.2f", p->rc.aqStrength);
> -    s += sprintf(s, " cbqpoffs=%d", p->cbQpOffset);
> -    s += sprintf(s, " crqpoffs=%d", p->crQpOffset);
> -    s += sprintf(s, " rd=%d", p->rdLevel);
> -    BOOL(p->bEnableSignHiding, "signhide");
> -    BOOL(p->bEnableLoopFilter, "lft");
> -    BOOL(p->bEnableSAO, "sao");
> -    s += sprintf(s, " sao-lcu-bounds=%d", p->saoLcuBoundary);
> -    s += sprintf(s, " sao-lcu-opt=%d", p->saoLcuBasedOptimization);
> -    s += sprintf(s, " b-pyramid=%d", p->bBPyramid);
> -    BOOL(p->rc.cuTree, "cutree");
> -#undef BOOL
> -
> -    return buf;
> -}
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/common/common.h
> --- a/source/common/common.h    Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/common/common.h    Mon Feb 24 19:13:20 2014 +0530
> @@ -112,11 +112,7 @@
>  /* defined in common.cpp */
>  int64_t x265_mdate(void);
>  void x265_log(x265_param *param, int level, const char *fmt, ...);
> -int  x265_check_params(x265_param *param);
> -void x265_print_params(x265_param *param);
> -int x265_set_globals(x265_param *param);
>  int x265_exp2fix8(double x);
> -char *x265_param2string(x265_param *p);
>  void *x265_malloc(size_t size);
>  void x265_free(void *ptr);
>
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/common/param.cpp
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/source/common/param.cpp   Mon Feb 24 19:13:20 2014 +0530
> @@ -0,0 +1,1084 @@
> +/*****************************************************************************
> + * Copyright (C) 2013 x265 project
> + *
> + * Authors: Deepthi Nandakumar <deepthi at multicorewareinc.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
> + *
> + * This program is also available under a commercial proprietary license.
> + * For more information, contact us at licensing at multicorewareinc.com.
> + *****************************************************************************/
> +
> +#include "TLibCommon/TComSlice.h"
> +#include "x265.h"
> +#include "threading.h"
> +#include "param.h"
> +
> +#include <climits>
> +#include <stdio.h>
> +#include <string.h>
> +#include <stdarg.h>
> +
> +using namespace x265;
> +
> +extern "C"
> +x265_param *x265_param_alloc()
> +{
> +    return (x265_param*)x265_malloc(sizeof(x265_param));
> +}
> +
> +extern "C"
> +void x265_param_free(x265_param *p)
> +{
> +    return x265_free(p);
> +}
> +
> +extern "C"
> +void x265_param_default(x265_param *param)
> +{
> +    memset(param, 0, sizeof(x265_param));
> +
> +    /* Applying non-zero default values to all elements in the param structure */
> +    param->logLevel = X265_LOG_INFO;
> +    param->bEnableWavefront = 1;
> +    param->frameNumThreads = 0;
> +    param->poolNumThreads = 0;
> +    param->csvfn = NULL;
> +
> +    /* Source specifications */
> +    param->internalBitDepth = x265_max_bit_depth;
> +    param->internalCsp = X265_CSP_I420;
> +
> +    /* CU definitions */
> +    param->maxCUSize = 64;
> +    param->tuQTMaxInterDepth = 1;
> +    param->tuQTMaxIntraDepth = 1;
> +
> +    /* Coding Structure */
> +    param->keyframeMin = 0;
> +    param->keyframeMax = 250;
> +    param->bOpenGOP = 1;
> +    param->bframes = 4;
> +    param->lookaheadDepth = 20;
> +    param->bFrameAdaptive = X265_B_ADAPT_TRELLIS;
> +    param->bBPyramid = 1;
> +    param->scenecutThreshold = 40; /* Magic number pulled in from x264 */
> +
> +    /* Intra Coding Tools */
> +    param->bEnableConstrainedIntra = 0;
> +    param->bEnableStrongIntraSmoothing = 1;
> +
> +    /* Inter Coding tools */
> +    param->searchMethod = X265_HEX_SEARCH;
> +    param->subpelRefine = 2;
> +    param->searchRange = 57;
> +    param->maxNumMergeCand = 2;
> +    param->bEnableWeightedPred = 1;
> +    param->bEnableWeightedBiPred = 0;
> +    param->bEnableEarlySkip = 0;
> +    param->bEnableCbfFastMode = 0;
> +    param->bEnableAMP = 1;
> +    param->bEnableRectInter = 1;
> +    param->rdLevel = 3;
> +    param->bEnableSignHiding = 1;
> +    param->bEnableTransformSkip = 0;
> +    param->bEnableTSkipFast = 0;
> +    param->maxNumReferences = 3;
> +
> +    /* Loop Filter */
> +    param->bEnableLoopFilter = 1;
> +
> +    /* SAO Loop Filter */
> +    param->bEnableSAO = 1;
> +    param->saoLcuBoundary = 0;
> +    param->saoLcuBasedOptimization = 1;
> +
> +    /* Coding Quality */
> +    param->cbQpOffset = 0;
> +    param->crQpOffset = 0;
> +    param->rdPenalty = 0;
> +
> +    /* Rate control options */
> +    param->rc.vbvMaxBitrate = 0;
> +    param->rc.vbvBufferSize = 0;
> +    param->rc.vbvBufferInit = 0.9;
> +    param->rc.rfConstant = 28;
> +    param->rc.bitrate = 0;
> +    param->rc.rateTolerance = 1.0;
> +    param->rc.qCompress = 0.6;
> +    param->rc.ipFactor = 1.4f;
> +    param->rc.pbFactor = 1.3f;
> +    param->rc.qpStep = 4;
> +    param->rc.rateControlMode = X265_RC_CRF;
> +    param->rc.qp = 32;
> +    param->rc.aqMode = X265_AQ_VARIANCE;
> +    param->rc.aqStrength = 1.0;
> +    param->rc.cuTree = 1;
> +
> +    /* Quality Measurement Metrics */
> +    param->bEnablePsnr = 0;
> +    param->bEnableSsim = 0;
> +
> +    /* Video Usability Information (VUI) */
> +    param->bEnableVuiParametersPresentFlag = 0;
> +    param->bEnableAspectRatioIdc = 0;
> +    param->aspectRatioIdc = 0;
> +    param->sarWidth = 0;
> +    param->sarHeight = 0;
> +    param->bEnableOverscanAppropriateFlag = 0;
> +    param->bEnableVideoSignalTypePresentFlag = 0;
> +    param->videoFormat = 5;
> +    param->bEnableVideoFullRangeFlag = 0;
> +    param->bEnableColorDescriptionPresentFlag = 0;
> +    param->colorPrimaries = 2;
> +    param->transferCharacteristics = 2;
> +    param->matrixCoeffs = 2;
> +    param->bEnableChromaLocInfoPresentFlag = 0;
> +    param->chromaSampleLocTypeTopField = 0;
> +    param->chromaSampleLocTypeBottomField = 0;
> +    param->bEnableFieldSeqFlag = 0;
> +    param->bEnableFrameFieldInfoPresentFlag = 0;
> +    param->bEnableDefaultDisplayWindowFlag = 0;
> +    param->defDispWinLeftOffset = 0;
> +    param->defDispWinRightOffset = 0;
> +    param->defDispWinTopOffset = 0;
> +    param->defDispWinBottomOffset = 0;
> +    param->bEnableVuiTimingInfoPresentFlag = 0;
> +    param->bEnableVuiHrdParametersPresentFlag = 0;
> +    param->bEnableBitstreamRestrictionFlag = 0;
> +    param->bEnableSubPicHrdParamsPresentFlag = 0;
> +}
> +
> +extern "C"
> +int x265_param_apply_profile(x265_param *param, const char *profile)
> +{
> +    if (!profile)
> +        return 0;
> +    if (!strcmp(profile, "main"))
> +    {}
> +    else if (!strcmp(profile, "main10"))
> +    {
> +#if HIGH_BIT_DEPTH
> +        param->internalBitDepth = 10;
> +#else
> +        x265_log(param, X265_LOG_WARNING, "Main10 not supported, not compiled for 16bpp.\n");
> +        return -1;
> +#endif
> +    }
> +    else if (!strcmp(profile, "mainstillpicture"))
> +    {
> +        param->keyframeMax = 1;
> +        param->bOpenGOP = 0;
> +    }
> +    else
> +    {
> +        x265_log(param, X265_LOG_ERROR, "unknown profile <%s>\n", profile);
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +extern "C"
> +int x265_param_default_preset(x265_param *param, const char *preset, const char *tune)
> +{
> +    x265_param_default(param);
> +
> +    if (preset)
> +    {
> +        char *end;
> +        int i = strtol(preset, &end, 10);
> +        if (*end == 0 && i >= 0 && i < (int)(sizeof(x265_preset_names) / sizeof(*x265_preset_names) - 1))
> +            preset = x265_preset_names[i];
> +
> +        if (!strcmp(preset, "ultrafast"))
> +        {
> +            param->lookaheadDepth = 10;
> +            param->scenecutThreshold = 0; // disable lookahead
> +            param->maxCUSize = 32;
> +            param->searchRange = 25;
> +            param->bFrameAdaptive = 0;
> +            param->subpelRefine = 0;
> +            param->searchMethod = X265_DIA_SEARCH;
> +            param->bEnableRectInter = 0;
> +            param->bEnableAMP = 0;
> +            param->bEnableEarlySkip = 1;
> +            param->bEnableCbfFastMode = 1;
> +            param->bEnableSAO = 0;
> +            param->bEnableSignHiding = 0;
> +            param->bEnableWeightedPred = 0;
> +            param->maxNumReferences = 1;
> +            param->rc.aqStrength = 0.0;
> +            param->rc.aqMode = X265_AQ_NONE;
> +            param->rc.cuTree = 0;
> +        }
> +        else if (!strcmp(preset, "superfast"))
> +        {
> +            param->lookaheadDepth = 10;
> +            param->maxCUSize = 32;
> +            param->searchRange = 44;
> +            param->bFrameAdaptive = 0;
> +            param->subpelRefine = 1;
> +            param->bEnableRectInter = 0;
> +            param->bEnableAMP = 0;
> +            param->bEnableEarlySkip = 1;
> +            param->bEnableCbfFastMode = 1;
> +            param->bEnableWeightedPred = 0;
> +            param->maxNumReferences = 1;
> +            param->rc.aqStrength = 0.0;
> +            param->rc.aqMode = X265_AQ_NONE;
> +            param->rc.cuTree = 0;
> +        }
> +        else if (!strcmp(preset, "veryfast"))
> +        {
> +            param->lookaheadDepth = 15;
> +            param->maxCUSize = 32;
> +            param->bFrameAdaptive = 0;
> +            param->subpelRefine = 1;
> +            param->bEnableRectInter = 0;
> +            param->bEnableAMP = 0;
> +            param->bEnableEarlySkip = 1;
> +            param->bEnableCbfFastMode = 1;
> +            param->maxNumReferences = 1;
> +            param->rc.cuTree = 0;
> +        }
> +        else if (!strcmp(preset, "faster"))
> +        {
> +            param->lookaheadDepth = 15;
> +            param->bFrameAdaptive = 0;
> +            param->bEnableRectInter = 0;
> +            param->bEnableAMP = 0;
> +            param->bEnableEarlySkip = 1;
> +            param->bEnableCbfFastMode = 1;
> +            param->maxNumReferences = 1;
> +            param->rc.cuTree = 0;
> +        }
> +        else if (!strcmp(preset, "fast"))
> +        {
> +            param->lookaheadDepth = 15;
> +            param->bEnableRectInter = 0;
> +            param->bEnableAMP = 0;
> +        }
> +        else if (!strcmp(preset, "medium"))
> +        {
> +            /* defaults */
> +        }
> +        else if (!strcmp(preset, "slow"))
> +        {
> +            param->lookaheadDepth = 25;
> +            param->rdLevel = 4;
> +            param->subpelRefine = 3;
> +            param->maxNumMergeCand = 3;
> +            param->searchMethod = X265_STAR_SEARCH;
> +        }
> +        else if (!strcmp(preset, "slower"))
> +        {
> +            param->lookaheadDepth = 30;
> +            param->bframes = 8;
> +            param->tuQTMaxInterDepth = 2;
> +            param->tuQTMaxIntraDepth = 2;
> +            param->rdLevel = 6;
> +            param->subpelRefine = 3;
> +            param->maxNumMergeCand = 3;
> +            param->searchMethod = X265_STAR_SEARCH;
> +        }
> +        else if (!strcmp(preset, "veryslow"))
> +        {
> +            param->lookaheadDepth = 40;
> +            param->bframes = 8;
> +            param->tuQTMaxInterDepth = 3;
> +            param->tuQTMaxIntraDepth = 3;
> +            param->rdLevel = 6;
> +            param->subpelRefine = 4;
> +            param->maxNumMergeCand = 4;
> +            param->searchMethod = X265_STAR_SEARCH;
> +            param->maxNumReferences = 5;
> +        }
> +        else if (!strcmp(preset, "placebo"))
> +        {
> +            param->lookaheadDepth = 60;
> +            param->searchRange = 92;
> +            param->bframes = 8;
> +            param->tuQTMaxInterDepth = 4;
> +            param->tuQTMaxIntraDepth = 4;
> +            param->rdLevel = 6;
> +            param->subpelRefine = 5;
> +            param->maxNumMergeCand = 5;
> +            param->searchMethod = X265_STAR_SEARCH;
> +            param->bEnableTransformSkip = 1;
> +            param->maxNumReferences = 5;
> +            // TODO: optimized esa
> +        }
> +        else
> +            return -1;
> +    }
> +    if (tune)
> +    {
> +        if (!strcmp(tune, "psnr"))
> +        {
> +            param->rc.aqStrength = 0.0;
> +        }
> +        else if (!strcmp(tune, "ssim"))
> +        {
> +            param->rc.aqMode = X265_AQ_AUTO_VARIANCE;
> +        }
> +        else if (!strcmp(tune, "zero-latency"))
> +        {
> +            param->bFrameAdaptive = 0;
> +            param->bframes = 0;
> +            param->lookaheadDepth = 0;
> +        }
> +        else
> +            return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +static inline int _confirm(x265_param *param, bool bflag, const char* message)
> +{
> +    if (!bflag)
> +        return 0;
> +
> +    x265_log(param, X265_LOG_ERROR, "%s\n", message);
> +    return 1;
> +}
> +
> +int x265_check_params(x265_param *param)
> +{
> +#define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
> +    int check_failed = 0; /* abort if there is a fatal configuration problem */
> +
> +    CHECK(param->maxCUSize > 64,
> +          "max ctu size should be less than 64");
> +    CHECK(param->maxCUSize < 16,
> +          "Maximum partition width size should be larger than or equal to 16");
> +    if (check_failed == 1)
> +        return check_failed;
> +
> +    uint32_t maxCUDepth = (uint32_t)g_convertToBit[param->maxCUSize];
> +    uint32_t tuQTMaxLog2Size = maxCUDepth + 2 - 1;
> +    uint32_t tuQTMinLog2Size = 2; //log2(4)
> +
> +    CHECK((param->maxCUSize >> maxCUDepth) < 4,
> +          "Minimum partition width size should be larger than or equal to 8");
> +    CHECK(param->internalCsp != X265_CSP_I420 && param->internalCsp != X265_CSP_I444,
> +          "Only 4:2:0 and 4:4:4 color spaces is supported at this time");
> +
> +    /* These checks might be temporary */
> +#if HIGH_BIT_DEPTH
> +    CHECK(param->internalBitDepth != 10,
> +          "x265 was compiled for 10bit encodes, only 10bit inputs supported");
> +#endif
> +
> +    CHECK(param->internalBitDepth > x265_max_bit_depth,
> +          "internalBitDepth must be <= x265_max_bit_depth");
> +    CHECK(param->rc.qp < -6 * (param->internalBitDepth - 8) || param->rc.qp > 51,
> +          "QP exceeds supported range (-QpBDOffsety to 51)");
> +    CHECK(param->fpsNum == 0 || param->fpsDenom == 0,
> +          "Frame rate numerator and denominator must be specified");
> +    CHECK(param->searchMethod<0 || param->searchMethod> X265_FULL_SEARCH,
> +          "Search method is not supported value (0:DIA 1:HEX 2:UMH 3:HM 5:FULL)");
> +    CHECK(param->searchRange < 0,
> +          "Search Range must be more than 0");
> +    CHECK(param->searchRange >= 32768,
> +          "Search Range must be less than 32768");
> +    CHECK(param->subpelRefine > X265_MAX_SUBPEL_LEVEL,
> +          "subme must be less than or equal to X265_MAX_SUBPEL_LEVEL (7)");
> +    CHECK(param->subpelRefine < 0,
> +          "subme must be greater than or equal to 0");
> +    CHECK(param->frameNumThreads < 0,
> +          "frameNumThreads (--frame-threads) must be 0 or higher");
> +    CHECK(param->cbQpOffset < -12, "Min. Chroma Cb QP Offset is -12");
> +    CHECK(param->cbQpOffset >  12, "Max. Chroma Cb QP Offset is  12");
> +    CHECK(param->crQpOffset < -12, "Min. Chroma Cr QP Offset is -12");
> +    CHECK(param->crQpOffset >  12, "Max. Chroma Cr QP Offset is  12");
> +
> +    CHECK((1u << tuQTMaxLog2Size) > param->maxCUSize,
> +          "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
> +
> +    CHECK(param->tuQTMaxInterDepth < 1,
> +          "QuadtreeTUMaxDepthInter must be greater than or equal to 1");
> +    CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxInterDepth - 1)),
> +          "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
> +    CHECK(param->tuQTMaxIntraDepth < 1,
> +          "QuadtreeTUMaxDepthIntra must be greater than or equal to 1");
> +    CHECK(param->maxCUSize < (1u << (tuQTMinLog2Size + param->tuQTMaxIntraDepth - 1)),
> +          "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
> +
> +    CHECK(param->maxNumMergeCand < 1, "MaxNumMergeCand must be 1 or greater.");
> +    CHECK(param->maxNumMergeCand > 5, "MaxNumMergeCand must be 5 or smaller.");
> +
> +    CHECK(param->maxNumReferences < 1, "maxNumReferences must be 1 or greater.");
> +    CHECK(param->maxNumReferences > MAX_NUM_REF, "maxNumReferences must be 16 or smaller.");
> +
> +    CHECK(param->sourceWidth  % TComSPS::getWinUnitX(param->internalCsp) != 0,
> +          "Picture width must be an integer multiple of the specified chroma subsampling");
> +    CHECK(param->sourceHeight % TComSPS::getWinUnitY(param->internalCsp) != 0,
> +          "Picture height must be an integer multiple of the specified chroma subsampling");
> +
> +    CHECK(param->rc.rateControlMode<X265_RC_ABR || param->rc.rateControlMode> X265_RC_CRF,
> +          "Rate control mode is out of range");
> +    CHECK(param->rdLevel < 0 || param->rdLevel > 6,
> +          "RD Level is out of range");
> +    CHECK(param->bframes > param->lookaheadDepth,
> +          "Lookahead depth must be greater than the max consecutive bframe count");
> +    CHECK(param->bframes < 0,
> +          "bframe count should be greater than zero");
> +    CHECK(param->bframes > X265_BFRAME_MAX,
> +          "max consecutive bframe count must be 16 or smaller");
> +    CHECK(param->lookaheadDepth > X265_LOOKAHEAD_MAX,
> +          "Lookahead depth must be less than 256");
> +    CHECK(param->rc.aqMode < X265_AQ_NONE || X265_AQ_AUTO_VARIANCE < param->rc.aqMode,
> +          "Aq-Mode is out of range");
> +    CHECK(param->rc.aqStrength < 0 || param->rc.aqStrength > 3,
> +          "Aq-Strength is out of range");
> +
> +    // max CU size should be power of 2
> +    uint32_t i = param->maxCUSize;
> +    while (i)
> +    {
> +        i >>= 1;
> +        if ((i & 1) == 1)
> +            CHECK(i != 1, "Max CU size should be 2^n");
> +    }
> +
> +    CHECK(param->bEnableWavefront < 0, "WaveFrontSynchro cannot be negative");
> +    CHECK((param->aspectRatioIdc < 0
> +           || param->aspectRatioIdc > 16)
> +          && param->aspectRatioIdc != X265_EXTENDED_SAR,
> +          "Sample Aspect Ratio must be 0-16 or 255");
> +    CHECK(param->aspectRatioIdc == X265_EXTENDED_SAR && param->sarWidth <= 0,
> +          "Sample Aspect Ratio width must be greater than 0");
> +    CHECK(param->aspectRatioIdc == X265_EXTENDED_SAR && param->sarHeight <= 0,
> +          "Sample Aspect Ratio height must be greater than 0");
> +    CHECK(param->videoFormat < 0 || param->videoFormat > 5,
> +          "Video Format must be Component component,"
> +          " pal, ntsc, secam, mac or undef");
> +    CHECK(param->colorPrimaries < 0
> +          || param->colorPrimaries > 9
> +          || param->colorPrimaries == 3,
> +          "Color Primaries must be undef, bt709, bt470m,"
> +          " bt470bg, smpte170m, smpte240m, film or bt2020");
> +    CHECK(param->transferCharacteristics < 0
> +          || param->transferCharacteristics > 15
> +          || param->transferCharacteristics == 3,
> +          "Transfer Characteristics must be undef, bt709, bt470m, bt470bg,"
> +          " smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e,"
> +          " iec61966-2-1, bt2020-10 or bt2020-12");
> +    CHECK(param->matrixCoeffs < 0
> +          || param->matrixCoeffs > 10
> +          || param->matrixCoeffs == 3,
> +          "Matrix Coefficients must be undef, bt709, fcc, bt470bg, smpte170m,"
> +          " smpte240m, GBR, YCgCo, bt2020nc or bt2020c");
> +    CHECK(param->chromaSampleLocTypeTopField < 0
> +          || param->chromaSampleLocTypeTopField > 5,
> +          "Chroma Sample Location Type Top Field must be 0-5");
> +    CHECK(param->chromaSampleLocTypeBottomField < 0
> +          || param->chromaSampleLocTypeBottomField > 5,
> +          "Chroma Sample Location Type Bottom Field must be 0-5");
> +    CHECK(param->defDispWinLeftOffset < 0,
> +          "Default Display Window Left Offset must be 0 or greater");
> +    CHECK(param->defDispWinRightOffset < 0,
> +          "Default Display Window Right Offset must be 0 or greater");
> +    CHECK(param->defDispWinTopOffset < 0,
> +          "Default Display Window Top Offset must be 0 or greater");
> +    CHECK(param->defDispWinBottomOffset < 0,
> +          "Default Display Window Bottom Offset must be 0 or greater");
> +    return check_failed;
> +}
> +
> +int x265_set_globals(x265_param *param)
> +{
> +    uint32_t maxCUDepth = (uint32_t)g_convertToBit[param->maxCUSize];
> +    uint32_t tuQTMinLog2Size = 2; //log2(4)
> +
> +    static int once /* = 0 */;
> +
> +    if (ATOMIC_CAS32(&once, 0, 1) == 1)
> +    {
> +        if (param->maxCUSize != g_maxCUWidth)
> +        {
> +            x265_log(param, X265_LOG_ERROR, "maxCUSize must be the same for all encoders in a single process");
> +            return -1;
> +        }
> +        if (param->internalBitDepth != g_bitDepth)
> +        {
> +            x265_log(param, X265_LOG_ERROR, "internalBitDepth must be the same for all encoders in a single process");
> +            return -1;
> +        }
> +    }
> +    else
> +    {
> +        // set max CU width & height
> +        g_maxCUWidth  = param->maxCUSize;
> +        g_maxCUHeight = param->maxCUSize;
> +        g_bitDepth = param->internalBitDepth;
> +
> +        // compute actual CU depth with respect to config depth and max transform size
> +        g_addCUDepth = 0;
> +        while ((param->maxCUSize >> maxCUDepth) > (1u << (tuQTMinLog2Size + g_addCUDepth)))
> +        {
> +            g_addCUDepth++;
> +        }
> +
> +        maxCUDepth += g_addCUDepth;
> +        g_addCUDepth++;
> +        g_maxCUDepth = maxCUDepth;
> +
> +        // initialize partition order
> +        uint32_t* tmp = &g_zscanToRaster[0];
> +        initZscanToRaster(g_maxCUDepth + 1, 1, 0, tmp);
> +        initRasterToZscan(g_maxCUWidth, g_maxCUHeight, g_maxCUDepth + 1);
> +
> +        // initialize conversion matrix from partition index to pel
> +        initRasterToPelXY(g_maxCUWidth, g_maxCUHeight, g_maxCUDepth + 1);
> +    }
> +    return 0;
> +}
> +
> +void x265_print_params(x265_param *param)
> +{
> +    if (param->logLevel < X265_LOG_INFO)
> +        return;
> +#if HIGH_BIT_DEPTH
> +    x265_log(param, X265_LOG_INFO, "Internal bit depth                  : %d\n", param->internalBitDepth);
> +#endif
> +    x265_log(param, X265_LOG_INFO, "CU size                             : %d\n", param->maxCUSize);
> +    x265_log(param, X265_LOG_INFO, "Max RQT depth inter / intra         : %d / %d\n", param->tuQTMaxInterDepth, param->tuQTMaxIntraDepth);
> +
> +    x265_log(param, X265_LOG_INFO, "ME / range / subpel / merge         : %s / %d / %d / %d\n",
> +             x265_motion_est_names[param->searchMethod], param->searchRange, param->subpelRefine, param->maxNumMergeCand);
> +    if (param->keyframeMax != INT_MAX || param->scenecutThreshold)
> +    {
> +        x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut       : %d / %d / %d\n", param->keyframeMin, param->keyframeMax, param->scenecutThreshold);
> +    }
> +    else
> +    {
> +        x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut       : disabled\n");
> +    }
> +    if (param->cbQpOffset || param->crQpOffset)
> +    {
> +        x265_log(param, X265_LOG_INFO, "Cb/Cr QP Offset              : %d / %d\n", param->cbQpOffset, param->crQpOffset);
> +    }
> +    if (param->rdPenalty)
> +    {
> +        x265_log(param, X265_LOG_INFO, "RDpenalty                    : %d\n", param->rdPenalty);
> +    }
> +    x265_log(param, X265_LOG_INFO, "Lookahead / bframes / badapt        : %d / %d / %d\n", param->lookaheadDepth, param->bframes, param->bFrameAdaptive);
> +    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / refs          : %d / %d / %d\n", param->bBPyramid, param->bEnableWeightedPred, param->maxNumReferences);
> +    switch (param->rc.rateControlMode)
> +    {
> +    case X265_RC_ABR:
> +        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : ABR-%d kbps / %0.1f / %d\n", param->rc.bitrate,
> +                 param->rc.aqStrength, param->rc.cuTree);
> +        break;
> +    case X265_RC_CQP:
> +        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : CQP-%d / %0.1f / %d\n", param->rc.qp, param->rc.aqStrength,
> +                 param->rc.cuTree);
> +        break;
> +    case X265_RC_CRF:
> +        x265_log(param, X265_LOG_INFO, "Rate Control / AQ-Strength / CUTree : CRF-%0.1f / %0.1f / %d\n", param->rc.rfConstant,
> +                 param->rc.aqStrength, param->rc.cuTree);
> +        break;
> +    }
> +
> +    x265_log(param, X265_LOG_INFO, "tools: ");
> +#define TOOLOPT(FLAG, STR) if (FLAG) fprintf(stderr, "%s ", STR)
> +    TOOLOPT(param->bEnableRectInter, "rect");
> +    TOOLOPT(param->bEnableAMP, "amp");
> +    TOOLOPT(param->bEnableCbfFastMode, "cfm");
> +    TOOLOPT(param->bEnableConstrainedIntra, "cip");
> +    TOOLOPT(param->bEnableEarlySkip, "esd");
> +    fprintf(stderr, "rd=%d ", param->rdLevel);
> +
> +    TOOLOPT(param->bEnableLoopFilter, "lft");
> +    if (param->bEnableSAO)
> +    {
> +        if (param->saoLcuBasedOptimization)
> +            fprintf(stderr, "sao-lcu ");
> +        else
> +            fprintf(stderr, "sao-frame ");
> +    }
> +    TOOLOPT(param->bEnableSignHiding, "sign-hide");
> +    if (param->bEnableTransformSkip)
> +    {
> +        if (param->bEnableTSkipFast)
> +            fprintf(stderr, "tskip(fast) ");
> +        else
> +            fprintf(stderr, "tskip ");
> +    }
> +    TOOLOPT(param->bEnableWeightedBiPred, "weightbp");
> +    fprintf(stderr, "\n");
> +    fflush(stderr);
> +}
> +
> +static int x265_atobool(const char *str, bool& bError)
> +{
> +    if (!strcmp(str, "1") ||
> +        !strcmp(str, "true") ||
> +        !strcmp(str, "yes"))
> +        return 1;
> +    if (!strcmp(str, "0") ||
> +        !strcmp(str, "false") ||
> +        !strcmp(str, "no"))
> +        return 0;
> +    bError = true;
> +    return 0;
> +}
> +
> +static int x265_atoi(const char *str, bool& bError)
> +{
> +    char *end;
> +    int v = strtol(str, &end, 0);
> +
> +    if (end == str || *end != '\0')
> +        bError = true;
> +    return v;
> +}
> +
> +static double x265_atof(const char *str, bool& bError)
> +{
> +    char *end;
> +    double v = strtod(str, &end);
> +
> +    if (end == str || *end != '\0')
> +        bError = true;
> +    return v;
> +}
> +
> +static int parseName(const char *arg, const char * const * names, bool& bError)
> +{
> +    for (int i = 0; names[i]; i++)
> +    {
> +        if (!strcmp(arg, names[i]))
> +        {
> +            return i;
> +        }
> +    }
> +
> +    return x265_atoi(arg, bError);
> +}
> +
> +/* internal versions of string-to-int with additional error checking */
> +#undef atoi
> +#undef atof
> +#define atoi(str) x265_atoi(str, bError)
> +#define atof(str) x265_atof(str, bError)
> +#define atobool(str) (bNameWasBool = true, x265_atobool(str, bError))
> +
> +extern "C"
> +int x265_param_parse(x265_param *p, const char *name, const char *value)
> +{
> +    bool bError = false;
> +    bool bNameWasBool = false;
> +    bool bValueWasNull = !value;
> +    char nameBuf[64];
> +
> +    if (!name)
> +        return X265_PARAM_BAD_NAME;
> +
> +    // s/_/-/g
> +    if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
> +    {
> +        char *c;
> +        strcpy(nameBuf, name);
> +        while ((c = strchr(nameBuf, '_')) != 0)
> +        {
> +            *c = '-';
> +        }
> +
> +        name = nameBuf;
> +    }
> +
> +    if (!strncmp(name, "no-", 3))
> +    {
> +        name += 3;
> +        value = !value || x265_atobool(value, bError) ? "false" : "true";
> +    }
> +    else if (!strncmp(name, "no", 2))
> +    {
> +        name += 2;
> +        value = !value || x265_atobool(value, bError) ? "false" : "true";
> +    }
> +    else if (!value)
> +        value = "true";
> +    else if (value[0] == '=')
> +        value++;
> +
> +#if defined(_MSC_VER)
> +#pragma warning(disable: 4127) // conditional expression is constant
> +#endif
> +#define OPT(STR) else if (!strcmp(name, STR))
> +    if (0) ;
> +    OPT("fps")
> +    {
> +        if (sscanf(value, "%u/%u", &p->fpsNum, &p->fpsDenom) == 2)
> +            ;
> +        else
> +        {
> +            float fps = (float)atof(value);
> +            if (fps > 0 && fps <= INT_MAX / 1000)
> +            {
> +                p->fpsNum = (int)(fps * 1000 + .5);
> +                p->fpsDenom = 1000;
> +            }
> +            else
> +            {
> +                p->fpsNum = atoi(value);
> +                p->fpsDenom = 1;
> +            }
> +        }
> +    }
> +    OPT("csv") p->csvfn = value;
> +    OPT("threads") p->poolNumThreads = atoi(value);
> +    OPT("frame-threads") p->frameNumThreads = atoi(value);
> +    OPT("log") p->logLevel = atoi(value);
> +    OPT("wpp") p->bEnableWavefront = atobool(value);
> +    OPT("ctu") p->maxCUSize = (uint32_t)atoi(value);
> +    OPT("tu-intra-depth") p->tuQTMaxIntraDepth = (uint32_t)atoi(value);
> +    OPT("tu-inter-depth") p->tuQTMaxInterDepth = (uint32_t)atoi(value);
> +    OPT("subme") p->subpelRefine = atoi(value);
> +    OPT("merange") p->searchRange = atoi(value);
> +    OPT("rect") p->bEnableRectInter = atobool(value);
> +    OPT("amp") p->bEnableAMP = atobool(value);
> +    OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value);
> +    OPT("early-skip") p->bEnableEarlySkip = atobool(value);
> +    OPT("fast-cbf") p->bEnableCbfFastMode = atobool(value);
> +    OPT("rdpenalty") p->rdPenalty = atoi(value);
> +    OPT("tskip") p->bEnableTransformSkip = atobool(value);
> +    OPT("no-tskip-fast") p->bEnableTSkipFast = atobool(value);
> +    OPT("tskip-fast") p->bEnableTSkipFast = atobool(value);
> +    OPT("strong-intra-smoothing") p->bEnableStrongIntraSmoothing = atobool(value);
> +    OPT("constrained-intra") p->bEnableConstrainedIntra = atobool(value);
> +    OPT("open-gop") p->bOpenGOP = atobool(value);
> +    OPT("scenecut") p->scenecutThreshold = atoi(value);
> +    OPT("keyint") p->keyframeMax = atoi(value);
> +    OPT("min-keyint") p->keyframeMin = atoi(value);
> +    OPT("rc-lookahead") p->lookaheadDepth = atoi(value);
> +    OPT("bframes") p->bframes = atoi(value);
> +    OPT("bframe-bias") p->bFrameBias = atoi(value);
> +    OPT("b-adapt") p->bFrameAdaptive = atoi(value);
> +    OPT("ref") p->maxNumReferences = atoi(value);
> +    OPT("weightp") p->bEnableWeightedPred = atobool(value);
> +    OPT("cbqpoffs") p->cbQpOffset = atoi(value);
> +    OPT("crqpoffs") p->crQpOffset = atoi(value);
> +    OPT("rd") p->rdLevel = atoi(value);
> +    OPT("signhide") p->bEnableSignHiding = atobool(value);
> +    OPT("lft") p->bEnableLoopFilter = atobool(value);
> +    OPT("sao") p->bEnableSAO = atobool(value);
> +    OPT("sao-lcu-bounds") p->saoLcuBoundary = atoi(value);
> +    OPT("sao-lcu-opt") p->saoLcuBasedOptimization = atoi(value);
> +    OPT("ssim") p->bEnableSsim = atobool(value);
> +    OPT("psnr") p->bEnablePsnr = atobool(value);
> +    OPT("hash") p->decodedPictureHashSEI = atoi(value);
> +    OPT("b-pyramid") p->bBPyramid = atobool(value);
> +    OPT("aq-mode") p->rc.aqMode = atoi(value);
> +    OPT("aq-strength") p->rc.aqStrength = atof(value);
> +    OPT("vbv-maxrate") p->rc.vbvMaxBitrate = atoi(value);
> +    OPT("vbv-bufsize") p->rc.vbvBufferSize = atoi(value);
> +    OPT("vbv-init")    p->rc.vbvBufferInit = atof(value);
> +    OPT("crf")
> +    {
> +        p->rc.rfConstant = atof(value);
> +        p->rc.rateControlMode = X265_RC_CRF;
> +    }
> +    OPT("bitrate")
> +    {
> +        p->rc.bitrate = atoi(value);
> +        p->rc.rateControlMode = X265_RC_ABR;
> +    }
> +    OPT("qp")
> +    {
> +        p->rc.qp = atoi(value);
> +        p->rc.rateControlMode = X265_RC_CQP;
> +    }
> +    OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, bError);
> +    OPT("me")        p->searchMethod = parseName(value, x265_motion_est_names, bError);
> +    OPT("cutree")    p->rc.cuTree = atobool(value);
> +    OPT("vui")
> +    {
> +        int bvalue = atobool(value);
> +
> +        p->bEnableVuiParametersPresentFlag = bvalue;
> +        p->bEnableAspectRatioIdc = bvalue;
> +        p->bEnableOverscanInfoPresentFlag = bvalue;
> +        p->bEnableVideoSignalTypePresentFlag = bvalue;
> +        p->bEnableColorDescriptionPresentFlag = bvalue;
> +        p->bEnableChromaLocInfoPresentFlag = bvalue;
> +        p->bEnableFieldSeqFlag = bvalue;
> +        p->bEnableFrameFieldInfoPresentFlag = bvalue;
> +        p->bEnableDefaultDisplayWindowFlag = bvalue;
> +        p->bEnableVuiTimingInfoPresentFlag = bvalue;
> +        p->bEnableVuiHrdParametersPresentFlag = bvalue;
> +        p->bEnableBitstreamRestrictionFlag = bvalue;
> +        p->bEnableSubPicHrdParamsPresentFlag = bvalue;
> +    }
> +    OPT("sar")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableAspectRatioIdc = atobool(value);
> +        p->aspectRatioIdc = atoi(value);
> +    }
> +    OPT("extended-sar")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableAspectRatioIdc = 1;
> +        p->aspectRatioIdc = X265_EXTENDED_SAR;
> +        bError |= sscanf(value, "%dx%d", &p->sarWidth, &p->sarHeight) != 2;
> +    }
> +    OPT("overscan")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        if (!strcmp(value, "show"))
> +            p->bEnableOverscanInfoPresentFlag = 1;
> +        else if (!strcmp(value, "crop"))
> +        {
> +            p->bEnableOverscanInfoPresentFlag = 1;
> +            p->bEnableOverscanAppropriateFlag = 1;
> +        }
> +        else
> +            p->bEnableOverscanInfoPresentFlag = -1;
> +    }
> +    OPT("videoformat")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVideoSignalTypePresentFlag = 1;
> +        if (!strcmp(value, "component"))
> +            p->videoFormat = 0;
> +        else if (!strcmp(value, "pal"))
> +            p->videoFormat = 1;
> +        else if (!strcmp(value, "ntsc"))
> +            p->videoFormat = 2;
> +        else if (!strcmp(value, "secam"))
> +            p->videoFormat = 3;
> +        else if (!strcmp(value, "mac"))
> +            p->videoFormat = 4;
> +        else if (!strcmp(value, "undef"))
> +            p->videoFormat = 5;
> +        else
> +            p->videoFormat = -1;
> +    }
> +    OPT("range")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVideoSignalTypePresentFlag = atobool(value);
> +        p->bEnableVideoFullRangeFlag = atobool(value);
> +    }
> +    OPT("colorprim")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVideoSignalTypePresentFlag = 1;
> +        p->bEnableColorDescriptionPresentFlag = 1;
> +        if (!strcmp(value, "bt709"))
> +            p->colorPrimaries = 1;
> +        else if (!strcmp(value, "undef"))
> +            p->colorPrimaries = 2;
> +        else if (!strcmp(value, "bt470m"))
> +            p->colorPrimaries = 4;
> +        else if (!strcmp(value, "bt470bg"))
> +            p->colorPrimaries = 5;
> +        else if (!strcmp(value, "smpte170m"))
> +            p->colorPrimaries = 6;
> +        else if (!strcmp(value, "smpte240m"))
> +            p->colorPrimaries = 7;
> +        else if (!strcmp(value, "film"))
> +            p->colorPrimaries = 8;
> +        else if (!strcmp(value, "bt2020"))
> +            p->colorPrimaries = 9;
> +        else
> +            p->colorPrimaries = -1;
> +    }
> +    OPT("transfer")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVideoSignalTypePresentFlag = 1;
> +        p->bEnableColorDescriptionPresentFlag = 1;
> +        if (!strcmp(value, "bt709"))
> +            p->transferCharacteristics = 1;
> +        else if (!strcmp(value, "undef"))
> +            p->transferCharacteristics = 2;
> +        else if (!strcmp(value, "bt470m"))
> +            p->transferCharacteristics = 4;
> +        else if (!strcmp(value, "bt470bg"))
> +            p->transferCharacteristics = 5;
> +        else if (!strcmp(value, "smpte170m"))
> +            p->transferCharacteristics = 6;
> +        else if (!strcmp(value, "smpte240m"))
> +            p->transferCharacteristics = 7;
> +        else if (!strcmp(value, "linear"))
> +            p->transferCharacteristics = 8;
> +        else if (!strcmp(value, "log100"))
> +            p->transferCharacteristics = 9;
> +        else if (!strcmp(value, "log316"))
> +            p->transferCharacteristics = 10;
> +        else if (!strcmp(value, "iec61966-2-4"))
> +            p->transferCharacteristics = 11;
> +        else if (!strcmp(value, "bt1361e"))
> +            p->transferCharacteristics = 12;
> +        else if (!strcmp(value, "iec61966-2-1"))
> +            p->transferCharacteristics = 13;
> +        else if (!strcmp(value, "bt2020-10"))
> +            p->transferCharacteristics = 14;
> +        else if (!strcmp(value, "bt2020-12"))
> +            p->transferCharacteristics = 15;
> +        else
> +            p->transferCharacteristics = -1;
> +    }
> +    OPT("colormatrix")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVideoSignalTypePresentFlag = 1;
> +        p->bEnableColorDescriptionPresentFlag = 1;
> +        if (!strcmp(value, "GBR"))
> +            p->matrixCoeffs = 0;
> +        else if (!strcmp(value, "bt709"))
> +            p->matrixCoeffs = 1;
> +        else if (!strcmp(value, "undef"))
> +            p->matrixCoeffs = 2;
> +        else if (!strcmp(value, "fcc"))
> +            p->matrixCoeffs = 4;
> +        else if (!strcmp(value, "bt470bg"))
> +            p->matrixCoeffs = 5;
> +        else if (!strcmp(value, "smpte170m"))
> +            p->matrixCoeffs = 6;
> +        else if (!strcmp(value, "smpte240m"))
> +            p->matrixCoeffs = 7;
> +        else if (!strcmp(value, "YCgCo"))
> +            p->matrixCoeffs = 8;
> +        else if (!strcmp(value, "bt2020nc"))
> +            p->matrixCoeffs = 9;
> +        else if (!strcmp(value, "bt2020c"))
> +            p->matrixCoeffs = 10;
> +        else
> +            p->matrixCoeffs = -1;
> +    }
> +    OPT("chromaloc")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableChromaLocInfoPresentFlag = 1;
> +        p->chromaSampleLocTypeTopField = atoi(value);
> +        p->chromaSampleLocTypeBottomField = p->chromaSampleLocTypeTopField;
> +    }
> +    OPT("fieldseq")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableFieldSeqFlag = atobool(value);
> +    }
> +    OPT("framefieldinfo")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableFrameFieldInfoPresentFlag = atobool(value);
> +    }
> +    OPT("crop-rect")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableDefaultDisplayWindowFlag = 1;
> +        bError |= sscanf(value, "%d,%d,%d,%d",
> +                         &p->defDispWinLeftOffset,
> +                         &p->defDispWinTopOffset,
> +                         &p->defDispWinRightOffset,
> +                         &p->defDispWinBottomOffset) != 4;
> +    }
> +    OPT("timinginfo")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVuiTimingInfoPresentFlag = atobool(value);
> +    }
> +    OPT("nal-hrd")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVuiTimingInfoPresentFlag = atobool(value);
> +        p->bEnableVuiHrdParametersPresentFlag = atobool(value);
> +    }
> +    OPT("bitstreamrestriction")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableBitstreamRestrictionFlag = atobool(value);
> +    }
> +    OPT("subpichrd")
> +    {
> +        p->bEnableVuiParametersPresentFlag = 1;
> +        p->bEnableVuiHrdParametersPresentFlag = atobool(value);
> +        p->bEnableSubPicHrdParamsPresentFlag = atobool(value);
> +    }
> +    else
> +        return X265_PARAM_BAD_NAME;
> +#undef OPT
> +#undef atobool
> +#undef atoi
> +#undef atof
> +
> +    bError |= bValueWasNull && !bNameWasBool;
> +    return bError ? X265_PARAM_BAD_VALUE : 0;
> +}
> +
> +char *x265_param2string(x265_param *p)
> +{
> +    char *buf, *s;
> +
> +    buf = s = X265_MALLOC(char, 2000);
> +    if (!buf)
> +        return NULL;
> +
> +#define BOOL(param, cliopt) \
> +    s += sprintf(s, " %s", (param) ? cliopt : "no-"cliopt);
> +
> +    BOOL(p->bEnableWavefront, "wpp");
> +    s += sprintf(s, " fps=%d/%d", p->fpsNum, p->fpsDenom);
> +    s += sprintf(s, " ctu=%d", p->maxCUSize);
> +    s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth);
> +    s += sprintf(s, " tu-inter-depth=%d", p->tuQTMaxInterDepth);
> +    s += sprintf(s, " me=%d", p->searchMethod);
> +    s += sprintf(s, " subme=%d", p->subpelRefine);
> +    s += sprintf(s, " merange=%d", p->searchRange);
> +    BOOL(p->bEnableRectInter, "rect");
> +    BOOL(p->bEnableAMP, "amp");
> +    s += sprintf(s, " max-merge=%d", p->maxNumMergeCand);
> +    BOOL(p->bEnableEarlySkip, "early-skip");
> +    BOOL(p->bEnableCbfFastMode, "fast-cbf");
> +    s += sprintf(s, " rdpenalty=%d", p->rdPenalty);
> +    BOOL(p->bEnableTransformSkip, "tskip");
> +    BOOL(p->bEnableTSkipFast, "tskip-fast");
> +    BOOL(p->bEnableStrongIntraSmoothing, "strong-intra-smoothing");
> +    BOOL(p->bEnableConstrainedIntra, "constrained-intra");
> +    BOOL(p->bOpenGOP, "open-gop");
> +    s += sprintf(s, " keyint=%d", p->keyframeMax);
> +    s += sprintf(s, " min-keyint=%d", p->keyframeMin);
> +    s += sprintf(s, " scenecut=%d", p->scenecutThreshold);
> +    s += sprintf(s, " rc-lookahead=%d", p->lookaheadDepth);
> +    s += sprintf(s, " bframes=%d", p->bframes);
> +    s += sprintf(s, " bframe-bias=%d", p->bFrameBias);
> +    s += sprintf(s, " b-adapt=%d", p->bFrameAdaptive);
> +    s += sprintf(s, " ref=%d", p->maxNumReferences);
> +    BOOL(p->bEnableWeightedPred, "weightp");
> +    s += sprintf(s, " bitrate=%d", p->rc.bitrate);
> +    s += sprintf(s, " qp=%d", p->rc.qp);
> +    s += sprintf(s, " aq-mode=%d", p->rc.aqMode);
> +    s += sprintf(s, " aq-strength=%.2f", p->rc.aqStrength);
> +    s += sprintf(s, " cbqpoffs=%d", p->cbQpOffset);
> +    s += sprintf(s, " crqpoffs=%d", p->crQpOffset);
> +    s += sprintf(s, " rd=%d", p->rdLevel);
> +    BOOL(p->bEnableSignHiding, "signhide");
> +    BOOL(p->bEnableLoopFilter, "lft");
> +    BOOL(p->bEnableSAO, "sao");
> +    s += sprintf(s, " sao-lcu-bounds=%d", p->saoLcuBoundary);
> +    s += sprintf(s, " sao-lcu-opt=%d", p->saoLcuBasedOptimization);
> +    s += sprintf(s, " b-pyramid=%d", p->bBPyramid);
> +    BOOL(p->rc.cuTree, "cutree");
> +#undef BOOL
> +
> +    return buf;
> +}
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/common/param.h
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/source/common/param.h     Mon Feb 24 19:13:20 2014 +0530
> @@ -0,0 +1,628 @@
> +/*****************************************************************************
> + * Copyright (C) 2013 x265 project
> + *
> + * Authors: Deepthi Nandakumar <deepthi at multicorewareinc.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
> + *
> + * This program is also available under a commercial proprietary license.
> + * For more information, contact us at licensing at multicorewareinc.com.
> + *****************************************************************************/
> +
> +#ifndef X265_PARAM_H
> +#define X265_PARAM_H
> +
> +/* x265 input parameters
> + *
> + * For version safety you may use x265_param_alloc/free() to manage the
> + * allocation of x265_param instances, and x265_param_parse() to assign values
> + * by name.  By never dereferencing param fields in your own code you can treat
> + * x265_param as an opaque data structure */
> +typedef struct x265_param
> +{
> +    /*== Encoder Environment ==*/
> +
> +    /* Enable wavefront parallel processing, greatly increases parallelism for
> +     * less than 1% compression efficiency loss */
> +    int       bEnableWavefront;
> +
> +    /* Number of threads to allocate for the process global thread pool, if no
> +     * thread pool has yet been created. 0 implies auto-detection. By default
> +     * x265 will try to allocate one worker thread per CPU core */
> +    int       poolNumThreads;
> +
> +    /* Number of concurrently encoded frames, 0 implies auto-detection. By
> +     * default x265 will use a number of frame threads emperically determined to
> +     * be optimal for your CPU core count, between 2 and 6.  Using more than one
> +     * frame thread causes motion search in the down direction to be clamped but
> +     * otherwise encode behavior is unaffected. With CQP rate control the output
> +     * bitstream is deterministic for all values of frameNumThreads greater than
> +     * 1.  All other forms of rate-control can be negatively impacted by
> +     * increases to the number of frame threads because the extra concurrency
> +     * adds uncertainty to the bitrate estimations.  There is no limit to the
> +     * number of frame threads you use for each encoder, but frame parallelism
> +     * is generally limited by the the number of CU rows */
> +    int       frameNumThreads;
> +
> +    /* The level of logging detail emitted by the encoder. X265_LOG_NONE to
> +     * X265_LOG_DEBUG, default is X265_LOG_INFO */
> +    int       logLevel;
> +
> +    /* Enable the measurement and reporting of PSNR. Default is enabled */
> +    int       bEnablePsnr;
> +
> +    /* Enable the measurement and reporting of SSIM. Default is disabled */
> +    int       bEnableSsim;
> +
> +    /* filename of CSV log. If logLevel is X265_LOG_DEBUG, the encoder will emit
> +     * per-slice statistics to this log file in encode order. Otherwise the
> +     * encoder will emit per-stream statistics into the log file when
> +     * x265_encoder_log is called (presumably at the end of the encode) */
> +    const char *csvfn;
> +
> +    /* Enable the generation of SEI messages for each encoded frame containing
> +     * the hashes of the three reconstructed picture planes. Most decoders will
> +     * validate those hashes against the reconstructed images it generates and
> +     * report any mismatches. This is essentially a debugging feature.  Hash
> +     * types are MD5(1), CRC(2), Checksum(3).  Default is 0, none */
> +    int       decodedPictureHashSEI;
> +
> +    /*== Video Usability Information ==*/
> +
> +    /* Enable the generation of a VUI with all fields in the SPS.  VUI fields
> +     * that are not specified on the command line will have default values. */
> +    int       bEnableVuiParametersPresentFlag;
> +
> +    /* Enable aspect ratio in VUI.  Causes the aspect_ratio_idc to be added
> +     * to the VUI.  The default is false. */
> +    int bEnableAspectRatioIdc;
> +
> +    /* Aspect ratio idc to be added to the VUI.  The default is 0 indicating
> +     * the apsect ratio is unspecified.  If set to X265_EXTENDED_SAR then
> +     * sarWidth and sarHeight must also be set. */
> +    int       aspectRatioIdc;
> +
> +    /* Sample Aspect Ratio width in arbitrary units to be added to the VUI
> +     * only if aspectRatioIdc is set to X265_EXTENDED_SAR.  This is the width
> +     * of an individual pixel.  If this is set then sarHeight must also be set.
> +     */
> +    int       sarWidth;
> +
> +    /* Sample Aspect Ratio height in arbitrary units to be added to the VUI.
> +     * only if aspectRatioIdc is set to X265_EXTENDED_SAR.  This is the width
> +     * of an individual pixel.  If this is set then sarWidth must also be set.
> +     */
> +    int       sarHeight;
> +
> +    /* Enable overscan info present flag in the VUI.  If this is set then
> +     * bEnabledOverscanAppropriateFlag will be added to the VUI. The default
> +     * is false. */
> +    int       bEnableOverscanInfoPresentFlag;
> +
> +    /* Enable overscan appropriate flag.  The status of this flag is added to
> +     * the VUI only if bEnableOverscanInfoPresentFlag is set.  If this flag is
> +     * set then cropped decoded pictures may be output for display. The default
> +     * is false. */
> +    int       bEnableOverscanAppropriateFlag;
> +
> +    /* Video signal type present flag of the VUI.  If this is set then
> +     * videoFormat, bEnableVideoFullRangeFlag and
> +     * bEnableColorDescriptionPresentFlag will be added to the VUI.  The default
> +     * is false. */
> +    int       bEnableVideoSignalTypePresentFlag;
> +
> +    /* Video format of the source video.  0 = component, 1 = PAL, 2 = NTSC,
> +     * 3 = SECAM, 4 = MAC, 5 = unspecified video format is the default. */
> +    int       videoFormat;
> +
> +    /* Video full range flag indicates the black level and range of the luma
> +     * and chroma signals as derived from E′Y, E′PB, and E′PR or E′R, E′G, and
> +     * E′B real-valued component signals.  False is the default. */
> +    int       bEnableVideoFullRangeFlag;
> +
> +    /* Color description present flag in the VUI.  If this is set then
> +     * color_primaries, transfer_characteristics and matrix_coeffs are to be added
> +     * to the VUI.  The default is false. */
> +    int       bEnableColorDescriptionPresentFlag;
> +
> +    /* Color primaries holds the chromacity coordinates of the source primaries.
> +     * The default is 2. */
> +    int       colorPrimaries;
> +
> +    /* Transfer characteristics indicates the opto-electronic transfer characteristic
> +     * of the source picture.  The default is 2. */
> +    int       transferCharacteristics;
> +
> +    /* Matrix coefficients used to derive the luma and chroma signals from the red,
> +     * blue and green primaries.  The default is 2. */
> +    int       matrixCoeffs;
> +
> +    /* Chroma location info present flag adds chroma_sample_loc_type_top_field and
> +     * chroma_sample_loc_type_bottom_field to the VUI.  The default is false. */
> +    int       bEnableChromaLocInfoPresentFlag;
> +
> +    /* Chroma sample location type top field holds the chroma location in the top
> +     * field.  The default is 0. */
> +    int       chromaSampleLocTypeTopField;
> +
> +    /* Chroma sample location type bottom field holds the chroma location in the bottom
> +     * field.  The default is 0. */
> +    int       chromaSampleLocTypeBottomField;
> +
> +    /* Field seq flag specifies that the pictures are fields and each one has a
> +     * timing SEI message.  The default is false */
> +    int       bEnableFieldSeqFlag;
> +
> +    /* Frame field info present flag indicates that each picture has a timing SEI
> +     * message wich includes a pic_struct, source_scan_type and duplicate_flag
> +     * elements.  If not set then the pic_struct element is not included.  The
> +     * default is false. */
> +    int       bEnableFrameFieldInfoPresentFlag;
> +
> +    /* Default display window flag adds def_disp_win_left_offset ,
> +     * def_disp_win_right_offset, def_disp_win_top_offset and
> +     * def_disp_win_bottom_offset to the VUI.  The default is false. */
> +    int       bEnableDefaultDisplayWindowFlag;
> +
> +    /* Default display window left offset holds the left offset with the
> +     * conformance cropping window to further crop the displayed window. */
> +    int       defDispWinLeftOffset;
> +
> +    /* Default display window right offset holds the right offset with the
> +     * conformance cropping window to further crop the displayed window. */
> +    int       defDispWinRightOffset;
> +
> +    /* Default display window top offset holds the top offset with the
> +     * conformance cropping window to further crop the displayed window. */
> +    int       defDispWinTopOffset;
> +
> +    /* Default display window bottom offset holds the bottom offset with the
> +     * conformance cropping window to further crop the displayed window. */
> +    int       defDispWinBottomOffset;
> +
> +    /* VUI timing info present flag adds vui_num_units_in_tick, vui_time_scale,
> +     * vui_poc_proportional_to_timing_flag and vui_hrd_parameters_present_flag
> +     * to the VUI.  vui_num_units_in_tick, vui_time_scale and
> +     * vui_poc_proportional_to_timing_flag are derived from processing the input
> +     * video.  The default is false. */
> +    int       bEnableVuiTimingInfoPresentFlag;
> +
> +    /* VUI hrd parameters present flag adds the HRD to the VUI */
> +    int       bEnableVuiHrdParametersPresentFlag;
> +
> +    /* Bitstream restriction flag adds tiles_fixed_structure_flag,
> +     * motion_vectors_over_pic_boundaries_flag, restricted_ref_pic_lists_flag,
> +     * min_spatial_segmentation_idc, max_bytes_per_pic_denom,
> +     * max_bit_per_min_cu_denom, log2_max_mv_length_horizontal and
> +     * log2_max_mv_length_vertical to the VUI. All values are derived from
> +     * processing the input video.  The default is false.  */
> +    int       bEnableBitstreamRestrictionFlag;
> +
> +    /*== Hypothetical Reference Decoder Parameters ==*/
> +
> +    /* Sub pic HRD params present flag determines if tic_divisor_minus2,
> +     * du_cpb_removal_delay_increment_length_minus1,
> +     * sub_pic_cpb_params_in_pic_timing_sei_flag,
> +     * dpb_output_delay_du_length_minus1 and cpb_size_du_scale
> +     * are added to the HRD.  All are derived from processing the input video.
> +     * The default is false. */
> +    int       bEnableSubPicHrdParamsPresentFlag;
> +
> +    /*== Internal Picture Specification ==*/
> +
> +    /* Internal encoder bit depth. If x265 was compiled to use 8bit pixels
> +     * (HIGH_BIT_DEPTH=0), this field must be 8, else this field must be 10.
> +     * Future builds may support 12bit pixels. */
> +    int       internalBitDepth;
> +
> +    /* Color space of internal pictures. Only X265_CSP_I420 and X265_CSP_I444
> +     * are supported.  Eventually, i422 will also be supported as an internal
> +     * color space and other packed formats will be supported in
> +     * x265_picture.colorSpace */
> +    int       internalCsp;
> +
> +    /* Numerator and denominator of frame rate */
> +    uint32_t  fpsNum;
> +    uint32_t  fpsDenom;
> +
> +    /* Width (in pixels) of the source pictures. If this width is not an even
> +     * multiple of 4, the encoder will pad the pictures internally to meet this
> +     * minimum requirement. All valid HEVC widths are supported */
> +    int       sourceWidth;
> +
> +    /* Height (in pixels) of the source pictures. If this height is not an even
> +     * multiple of 4, the encoder will pad the pictures internally to meet this
> +     * minimum requirement. All valid HEVC heights are supported */
> +    int       sourceHeight;
> +
> +    /*== Coding Unit (CU) definitions ==*/
> +
> +    /* Maxiumum CU width and height in pixels.  The size must be 64, 32, or 16.
> +     * The higher the size, the more efficiently x265 can encode areas of low
> +     * complexity, greatly improving compression efficiency at large
> +     * resolutions.  The smaller the size, the more effective wavefront and
> +     * frame parallelism will become because of the increase in rows. default 64 */
> +    uint32_t  maxCUSize;
> +
> +    /* The additional depth the residual quadtree is allowed to recurse beyond
> +     * the coding quadtree, for inter coded blocks. This must be between 1 and
> +     * 3. The higher the value the more efficiently the residual can be
> +     * compressed by the DCT transforms, at the expense of much more compute */
> +    uint32_t  tuQTMaxInterDepth;
> +
> +    /* The additional depth the residual quadtree is allowed to recurse beyond
> +     * the coding quadtree, for intra coded blocks. This must be between 1 and
> +     * 3. The higher the value the more efficiently the residual can be
> +     * compressed by the DCT transforms, at the expense of much more compute */
> +    uint32_t  tuQTMaxIntraDepth;
> +
> +    /*== GOP Structure and Lokoahead ==*/
> +
> +    /* Enable open GOP - meaning I slices are not necessariy IDR and thus frames
> +     * encoded after an I slice may reference frames encoded prior to the I
> +     * frame which have remained in the decoded picture buffer.  Open GOP
> +     * generally has better compression efficiency and negligable encoder
> +     * performance impact, but the use case may preclude it.  Default true */
> +    int       bOpenGOP;
> +
> +    /* Scenecuts closer together than this are coded as I, not IDR. */
> +    int       keyframeMin;
> +
> +    /* Maximum keyframe distance or intra period in number of frames. If 0 or 1,
> +     * all frames are I frames. A negative value is casted to MAX_INT internally
> +     * which effectively makes frame 0 the only I frame. Default is 250 */
> +    int       keyframeMax;
> +
> +    /* The maximum number of L0 references a P or B slice may use. This
> +     * influences the size of the decoded picture buffer. The higher this
> +     * number, the more reference frames there will be available for motion
> +     * search, improving compression efficiency of most video at a cost of
> +     * performance. Value must be between 1 and 16, default is 3 */
> +    int       maxNumReferences;
> +
> +    /* Sets the operating mode of the lookahead.  With b-adapt 0, the GOP
> +     * structure is fixed based on the values of keyframeMax and bframes.
> +     * With b-adapt 1 a light lookahead is used to chose B frame placement.
> +     * With b-adapt 2 (trellis) a viterbi B path selection is performed */
> +    int       bFrameAdaptive;
> +
> +    /* Maximum consecutive B frames that can be emitted by the lookehead. When
> +     * b-adapt is 0 and keyframMax is greater than bframes, the lookahead emits
> +     * a fixed pattern of `bframes` B frames between each P.  With b-adapt 1 the
> +     * lookahead ignores the value of bframes for the most part.  With b-adapt 2
> +     * the value of bframes determines the search (POC) distance performeed in
> +     * both directions, quadradically increasing the compute load of the
> +     * lookahead.  The higher the value, the more B frames the lookahead may
> +     * possibly use consecutively, usually improving compression. Default is 3,
> +     * maximum is 16 */
> +    int       bframes;
> +
> +    /* When enabled, the encoder will use the B frame in the middle of each
> +     * mini-GOP larger than 2 B frames as a motion reference for the surrounding
> +     * B frames.  This improves compression efficiency for a small performance
> +     * penalty.  Referenced B frames are treated somewhere between a B and a P
> +     * frame by rate control.  Default is enabled. */
> +    int       bBPyramid;
> +
> +    /* The number of frames that must be queued in the lookahead before it may
> +     * make slice decisions. Increasing this value directly increases the encode
> +     * latency. The longer the queue the more optimally the lookahead may make
> +     * slice decisions, particularly with b-adapt 2. When mb-tree is enabled,
> +     * the length of the queue linearly increases the effectiveness of the
> +     * mb-tree analysis. Default is 40 frames, maximum is 250 */
> +    int       lookaheadDepth;
> +
> +    /* A value which is added to the cost estimate of B frames in the lookahead.
> +     * It may be a positive value (making B frames appear more expensive, which
> +     * causes the lookahead to chose more P frames) or negative, which makes the
> +     * lookahead chose more B frames. Default is 0, there are no limits */
> +    int       bFrameBias;
> +
> +    /* An arbitrary threshold which determines how agressively the lookahead
> +     * should detect scene cuts. The default (40) is recommended. */
> +    int       scenecutThreshold;
> +
> +    /*== Intra Coding Tools ==*/
> +
> +    /* Enable constrained intra prediction. This causes intra prediction to
> +     * input samples that were inter predicted. For some use cases this is
> +     * believed to me more robust to stream errors, but it has a compression
> +     * penalty on P and (particularly) B slices. Defaults to diabled */
> +    int       bEnableConstrainedIntra;
> +
> +    /* Enable strong intra smoothing for 32x32 blocks where the reference
> +     * samples are flat. It may or may not improve compression efficiency,
> +     * depending on your source material. Defaults to disabled */
> +    int       bEnableStrongIntraSmoothing;
> +
> +    /*== Inter Coding Tools ==*/
> +
> +    /* ME search method (DIA, HEX, UMH, STAR, FULL). The search patterns
> +     * (methods) are sorted in increasing complexity, with diamond being the
> +     * simplest and fastest and full being the slowest.  DIA, HEX, and UMH were
> +     * adapted from x264 directly. STAR is an adaption of the HEVC reference
> +     * encoder's three step search, while full is a naive exhaustive search. The
> +     * default is the star search, it has a good balance of performance and
> +     * compression efficiecy */
> +    int       searchMethod;
> +
> +    /* A value between 0 and X265_MAX_SUBPEL_LEVEL which adjusts the amount of
> +     * effort performed during subpel refine. Default is 5 */
> +    int       subpelRefine;
> +
> +    /* The maximum distance from the motion prediction that the full pel motion
> +     * search is allowed to progress before terminating. This value can have an
> +     * effect on frame parallelism, as referenced frames must be at least this
> +     * many rows of reconstructed pixels ahead of the referencee at all times.
> +     * (When considering reference lag, the motion prediction must be ignored
> +     * because it cannot be known ahead of time).  Default is 60, which is the
> +     * default max CU size (64) minus the luma HPEL half-filter length (4). If a
> +     * smaller CU size is used, the search range should be similarly reduced */
> +    int       searchRange;
> +
> +    /* The maximum number of merge candidates that are considered during inter
> +     * analysis.  This number (between 1 and 5) is signaled in the stream
> +     * headers and determines the number of bits required to signal a merge so
> +     * it can have significant trade-offs. The smaller this number the higher
> +     * the performance but the less compression efficiency. Default is 3 */
> +    uint32_t  maxNumMergeCand;
> +
> +    /* Enable weighted prediction in P slices.  This enables weighting analysis
> +     * in the lookahead, which influences slice decitions, and enables weighting
> +     * analysis in the main encoder which allows P reference samples to have a
> +     * weight function applied to them prior to using them for motion
> +     * compensation.  In video which has lighting changes, it can give a large
> +     * improvement in compression efficiency. Default is enabled */
> +    int       bEnableWeightedPred;
> +
> +    /* Enable weighted bi-prediction in B slices. This option currently has no
> +     * effect */
> +    int       bEnableWeightedBiPred;
> +
> +    /*== Analysis tools ==*/
> +
> +    /* Enable asymmetrical motion predictions.  At CU depths 64, 32, and 16, it
> +     * is possible to use 25%/75% split partitions in the up, down, right, left
> +     * directions. For some material this can improve compression efficiency at
> +     * the cost of extra analysis. bEnableRectInter must be enabled for this
> +     * feature to be used. Default enabled */
> +    int       bEnableAMP;
> +
> +    /* Enable rectangular motion prediction partitions (vertical and
> +     * horizontal), available at all CU depths from 64x64 to 8x8. Default is
> +     * enabled */
> +    int       bEnableRectInter;
> +
> +    /* Enable the use of `coded block flags` (flags set to true when a residual
> +     * has been coded for a given block) to avoid intra analysis in likely skip
> +     * blocks. Default is disabled */
> +    int       bEnableCbfFastMode;
> +
> +    /* Enable early skip decisions to avoid intra and inter analysis in likely
> +     * skip blocks. Default is disabled */
> +    int       bEnableEarlySkip;
> +
> +    /* Apply an optional penalty to the estimated cost of 32x32 intra blocks in
> +     * non-intra slices. 0 is disabled, 1 enables a small penalty, and 2 enables
> +     * a full penalty. This favors inter-coding and its low bitrate over
> +     * potential increases in distortion, but usually improves performance.
> +     * Default is 0 */
> +    int       rdPenalty;
> +
> +    /* A value betwen X265_NO_RDO_NO_RDOQ and X265_RDO_LEVEL which determines
> +     * the level of rate distortion optimizations to perform during mode
> +     * decisions and quantization. The more RDO the better the compression
> +     * efficiency at a major cost of performance. Default is no RDO (0) */
> +    int       rdLevel;
> +
> +    /*== Coding tools ==*/
> +
> +    /* Enable the implicit signaling of the sign bit of the last coefficient of
> +     * each transform unit. This saves one bit per TU at the expense of figuring
> +     * out which coefficient can be toggled with the least distortion.
> +     * Default is enabled */
> +    int       bEnableSignHiding;
> +
> +    /* Allow intra coded blocks to be encoded directly as residual without the
> +     * DCT transform, when this improves efficiency. Checking whether the block
> +     * will benefit from this option incurs a performance penalty. Default is
> +     * enabled */
> +    int       bEnableTransformSkip;
> +
> +    /* Enable a faster determination of whether skippig the DCT transform will
> +     * be beneficial. Slight performance gain for some compression loss. Default
> +     * is enabled */
> +    int       bEnableTSkipFast;
> +
> +    /* Enable the deblocking loop filter, which improves visual quality by
> +     * reducing blocking effects at block edges, particularly at lower bitrates
> +     * or higher QP. When enabled it adds another CU row of reference lag,
> +     * reducing frame parallelism effectiveness.  Default is enabled */
> +    int       bEnableLoopFilter;
> +
> +    /* Enable the Sample Adaptive Offset loop filter, which reduces distortion
> +     * effects by adjusting reconstructed sample values based on histogram
> +     * analysis to better approximate the original samples. When enabled it adds
> +     * a CU row of reference lag, reducing frame parallelism effectiveness.
> +     * Default is enabled */
> +    int       bEnableSAO;
> +
> +    /* Note: when deblocking and SAO are both enabled, the loop filter CU lag is
> +     * only one row, as they operate in series o the same row. */
> +
> +    /* Select the method in which SAO deals with deblocking boundary pixels.  If
> +     * 0 the right and bottom boundary areas are skipped. If 1, non-deblocked
> +     * pixels are used entirely. Default is 0 */
> +    int       saoLcuBoundary;
> +
> +    /* Select the scope of the SAO optimization. If 0 SAO is performed over the
> +     * entire output picture at once, this can severly restrict frame
> +     * parallelism so it is not recommended for many-core machines.  If 1 SAO is
> +     * performed on LCUs in series. Default is 1 */
> +    int       saoLcuBasedOptimization;
> +
> +    /* Generally a small signed integer which offsets the QP used to quantize
> +     * the Cb chroma residual (delta from luma QP specified by rate-control).
> +     * Default is 0, which is recommended */
> +    int       cbQpOffset;
> +
> +    /* Generally a small signed integer which offsets the QP used to quantize
> +     * the Cr chroma residual (delta from luma QP specified by rate-control).
> +     * Default is 0, which is recommended */
> +    int       crQpOffset;
> +
> +    /*== Rate Control ==*/
> +
> +    struct
> +    {
> +        /* Explicit mode of rate-control, necessary for API users. It must
> +         * be one of the X265_RC_METHODS enum values. */
> +        int       rateControlMode;
> +
> +        /* Base QP to use for Constant QP rate control. Adaptive QP may alter
> +         * the QP used for each block. If a QP is specified on the command line
> +         * CQP rate control is implied. Default: 32 */
> +        int       qp;
> +
> +        /* target bitrate for Average BitRate (ABR) rate control. If a non- zero
> +         * bitrate is specified on the command line, ABR is implied. Default 0 */
> +        int       bitrate;
> +
> +        /* The degree of rate fluctuation that x265 tolerates. Rate tolerance is used
> +         * alongwith overflow (difference between actual and target bitrate), to adjust
> +           qp. Default is 1.0 */
> +        double    rateTolerance;
> +
> +        /* qComp sets the quantizer curve compression factor. It weights the frame
> +         * quantizer based on the complexity of residual (measured by lookahead).
> +         * Default value is 0.6. Increasing it to 1 will effectively generate CQP */
> +        double    qCompress;
> +
> +        /* QP offset between I/P and P/B frames. Default ipfactor: 1.4
> +         *  Default pbFactor: 1.3 */
> +        double    ipFactor;
> +        double    pbFactor;
> +
> +        /* Max QP difference between frames. Default: 4 */
> +        int       qpStep;
> +
> +        /* Ratefactor constant: targets a certain constant "quality".
> +         * Acceptable values between 0 and 51. Default value: 28 */
> +        double    rfConstant;
> +
> +        /* Enable adaptive quantization. This mode distributes available bits between all
> +         * macroblocks of a frame, assigning more bits to low complexity areas. Turning
> +         * this ON will usually affect PSNR negatively, however SSIM and visual quality
> +         * generally improves. Default: OFF (0) */
> +        int       aqMode;
> +
> +        /* Sets the strength of AQ bias towards low detail macroblocks. Valid only if
> +         * AQ is enabled. Default value: 1.0. Acceptable values between 0.0 and 3.0 */
> +        double    aqStrength;
> +
> +        /* Sets the maximum rate the VBV buffer should be assumed to refill at
> +         * Default is zero */
> +        int       vbvMaxBitrate;
> +
> +        /* Sets the size of the VBV buffer in kilobits. Default is zero */
> +        int       vbvBufferSize;
> +
> +        /* Sets how full the VBV buffer must be before playback starts. If it is less than
> +         * 1, then the initial fill is vbv-init * vbvBufferSize. Otherwise, it is
> +         * interpreted as the initial fill in kbits. Default is 0.9 */
> +        double    vbvBufferInit;
> +
> +        /* Enable CUTree ratecontrol. This keeps track of the CUs that propagate temporally
> +         * across frames and assigns more bits to these CUs. Improves encode efficiency.
> +         * Default: OFF (0) */
> +        int       cuTree;
> +        /* In CRF mode, maximum CRF as caused by VBV */
> +        double    rfConstantMax;
> +    } rc;
> +} x265_param;
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/* x265_param_alloc:
> + *  Allocates an x265_param instance. The returned param structure is not
> + *  special in any way, but using this method together with x265_param_free()
> + *  and x265_param_parse() to set values by name allows the application to treat
> + *  x265_param as an opaque data struct for version safety */
> +x265_param *x265_param_alloc();
> +
> +/* x265_param_free:
> + *  Use x265_param_free() to release storage for an x265_param instance
> + *  allocated by x26_param_alloc() */
> +void x265_param_free(x265_param *);
> +
> +/***
> + * Initialize an x265_param_t structure to default values
> + */
> +void x265_param_default(x265_param *param);
> +
> +/* x265_param_parse:
> + *  set one parameter by name.
> + *  returns 0 on success, or returns one of the following errors.
> + *  note: BAD_VALUE occurs only if it can't even parse the value,
> + *  numerical range is not checked until x265_encoder_open() or
> + *  x265_encoder_reconfig().
> + *  value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */
> +#define X265_PARAM_BAD_NAME  (-1)
> +#define X265_PARAM_BAD_VALUE (-2)
> +int x265_param_parse(x265_param *p, const char *name, const char *value);
> +
> +/* x265_param_apply_profile:
> + *      Applies the restrictions of the given profile. (one of below) */
> +static const char * const x265_profile_names[] = { "main", "main10", "mainstillpicture", 0 };
> +
> +/*      (can be NULL, in which case the function will do nothing)
> + *      returns 0 on success, negative on failure (e.g. invalid profile name). */
> +int x265_param_apply_profile(x265_param *, const char *profile);
> +
> +/* x265_param_default_preset:
> + *      The same as x265_param_default, but also use the passed preset and tune
> + *      to modify the default settings.
> + *      (either can be NULL, which implies no preset or no tune, respectively)
> + *
> + *      Currently available presets are, ordered from fastest to slowest: */
> +static const char * const x265_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };
> +
> +/*      The presets can also be indexed numerically, as in:
> + *      x265_param_default_preset( &param, "3", ... )
> + *      with ultrafast mapping to "0" and placebo mapping to "9".  This mapping may
> + *      of course change if new presets are added in between, but will always be
> + *      ordered from fastest to slowest.
> + *
> + *      Warning: the speed of these presets scales dramatically.  Ultrafast is a full
> + *      100 times faster than placebo!
> + *
> + *      Currently available tunings are: */
> +static const char * const x265_tune_names[] = { "psnr", "ssim", "zero-latency", 0 };
> +
> +/*      returns 0 on success, negative on failure (e.g. invalid preset/tune name). */
> +int x265_param_default_preset(x265_param *, const char *preset, const char *tune);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +int  x265_check_params(x265_param *param);
> +int x265_set_globals(x265_param *param);
> +void x265_print_params(x265_param *param);
> +char *x265_param2string(x265_param *p);
> +
> +#endif // ifndef X265_COMMON_H
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/dllmain.cpp
> --- a/source/dllmain.cpp        Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/dllmain.cpp        Mon Feb 24 19:13:20 2014 +0530
> @@ -22,6 +22,7 @@
>   *****************************************************************************/
>
>  #include "x265.h"
> +#include "param.h"
>
>  /* this unreachable function forces the MSVC linker to include the encoder
>   * and common libraries into the DLL */
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/encoder/encoder.cpp        Mon Feb 24 19:13:20 2014 +0530
> @@ -29,6 +29,7 @@
>  #include "primitives.h"
>  #include "threadpool.h"
>  #include "common.h"
> +#include "param.h"
>
>  #include "TLibEncoder/NALwrite.h"
>  #include "bitcost.h"
> @@ -1587,18 +1588,6 @@
>  }
>
>  extern "C"
> -x265_param *x265_param_alloc()
> -{
> -    return (x265_param*)x265_malloc(sizeof(x265_param));
> -}
> -
> -extern "C"
> -void x265_param_free(x265_param *p)
> -{
> -    return x265_free(p);
> -}
> -
> -extern "C"
>  x265_picture *x265_picture_alloc()
>  {
>      return (x265_picture*)x265_malloc(sizeof(x265_picture));
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/x265.cpp
> --- a/source/x265.cpp   Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/x265.cpp   Mon Feb 24 19:13:20 2014 +0530
> @@ -29,6 +29,7 @@
>  #include "output/output.h"
>  #include "common.h"
>  #include "x265.h"
> +#include "param.h"
>
>  #if HAVE_VLD
>  /* Visual Leak Detector */
> diff -r 80caa9f00d7c -r e7418fc7dbc6 source/x265.h
> --- a/source/x265.h     Sun Feb 23 21:25:22 2014 +0530
> +++ b/source/x265.h     Mon Feb 24 19:13:20 2014 +0530
> @@ -26,6 +26,7 @@
>
>  #include <stdint.h>
>  #include "x265_config.h"
> +#include "param.h"
>
>  #ifdef __cplusplus
>  extern "C" {
> @@ -279,599 +280,11 @@
>      /* new statistic member variables must be added below this line */
>  } x265_stats;
>
> -/* x265 input parameters
> - *
> - * For version safety you may use x265_param_alloc/free() to manage the
> - * allocation of x265_param instances, and x265_param_parse() to assign values
> - * by name.  By never dereferencing param fields in your own code you can treat
> - * x265_param as an opaque data structure */
> -typedef struct x265_param
> -{
> -    /*== Encoder Environment ==*/
> -
> -    /* Enable wavefront parallel processing, greatly increases parallelism for
> -     * less than 1% compression efficiency loss */
> -    int       bEnableWavefront;
> -
> -    /* Number of threads to allocate for the process global thread pool, if no
> -     * thread pool has yet been created. 0 implies auto-detection. By default
> -     * x265 will try to allocate one worker thread per CPU core */
> -    int       poolNumThreads;
> -
> -    /* Number of concurrently encoded frames, 0 implies auto-detection. By
> -     * default x265 will use a number of frame threads emperically determined to
> -     * be optimal for your CPU core count, between 2 and 6.  Using more than one
> -     * frame thread causes motion search in the down direction to be clamped but
> -     * otherwise encode behavior is unaffected. With CQP rate control the output
> -     * bitstream is deterministic for all values of frameNumThreads greater than
> -     * 1.  All other forms of rate-control can be negatively impacted by
> -     * increases to the number of frame threads because the extra concurrency
> -     * adds uncertainty to the bitrate estimations.  There is no limit to the
> -     * number of frame threads you use for each encoder, but frame parallelism
> -     * is generally limited by the the number of CU rows */
> -    int       frameNumThreads;
> -
> -    /* The level of logging detail emitted by the encoder. X265_LOG_NONE to
> -     * X265_LOG_DEBUG, default is X265_LOG_INFO */
> -    int       logLevel;
> -
> -    /* Enable the measurement and reporting of PSNR. Default is enabled */
> -    int       bEnablePsnr;
> -
> -    /* Enable the measurement and reporting of SSIM. Default is disabled */
> -    int       bEnableSsim;
> -
> -    /* filename of CSV log. If logLevel is X265_LOG_DEBUG, the encoder will emit
> -     * per-slice statistics to this log file in encode order. Otherwise the
> -     * encoder will emit per-stream statistics into the log file when
> -     * x265_encoder_log is called (presumably at the end of the encode) */
> -    const char *csvfn;
> -
> -    /* Enable the generation of SEI messages for each encoded frame containing
> -     * the hashes of the three reconstructed picture planes. Most decoders will
> -     * validate those hashes against the reconstructed images it generates and
> -     * report any mismatches. This is essentially a debugging feature.  Hash
> -     * types are MD5(1), CRC(2), Checksum(3).  Default is 0, none */
> -    int       decodedPictureHashSEI;
> -
> -    /*== Video Usability Information ==*/
> -
> -    /* Enable the generation of a VUI with all fields in the SPS.  VUI fields
> -     * that are not specified on the command line will have default values. */
> -    int       bEnableVuiParametersPresentFlag;
> -
> -    /* Enable aspect ratio in VUI.  Causes the aspect_ratio_idc to be added
> -     * to the VUI.  The default is false. */
> -    int bEnableAspectRatioIdc;
> -
> -    /* Aspect ratio idc to be added to the VUI.  The default is 0 indicating
> -     * the apsect ratio is unspecified.  If set to X265_EXTENDED_SAR then
> -     * sarWidth and sarHeight must also be set. */
> -    int       aspectRatioIdc;
> -
> -    /* Sample Aspect Ratio width in arbitrary units to be added to the VUI
> -     * only if aspectRatioIdc is set to X265_EXTENDED_SAR.  This is the width
> -     * of an individual pixel.  If this is set then sarHeight must also be set.
> -     */
> -    int       sarWidth;
> -
> -    /* Sample Aspect Ratio height in arbitrary units to be added to the VUI.
> -     * only if aspectRatioIdc is set to X265_EXTENDED_SAR.  This is the width
> -     * of an individual pixel.  If this is set then sarWidth must also be set.
> -     */
> -    int       sarHeight;
> -
> -    /* Enable overscan info present flag in the VUI.  If this is set then
> -     * bEnabledOverscanAppropriateFlag will be added to the VUI. The default
> -     * is false. */
> -    int       bEnableOverscanInfoPresentFlag;
> -
> -    /* Enable overscan appropriate flag.  The status of this flag is added to
> -     * the VUI only if bEnableOverscanInfoPresentFlag is set.  If this flag is
> -     * set then cropped decoded pictures may be output for display. The default
> -     * is false. */
> -    int       bEnableOverscanAppropriateFlag;
> -
> -    /* Video signal type present flag of the VUI.  If this is set then
> -     * videoFormat, bEnableVideoFullRangeFlag and
> -     * bEnableColorDescriptionPresentFlag will be added to the VUI.  The default
> -     * is false. */
> -    int       bEnableVideoSignalTypePresentFlag;
> -
> -    /* Video format of the source video.  0 = component, 1 = PAL, 2 = NTSC,
> -     * 3 = SECAM, 4 = MAC, 5 = unspecified video format is the default. */
> -    int       videoFormat;
> -
> -    /* Video full range flag indicates the black level and range of the luma
> -     * and chroma signals as derived from E′Y, E′PB, and E′PR or E′R, E′G, and
> -     * E′B real-valued component signals.  False is the default. */
> -    int       bEnableVideoFullRangeFlag;
> -
> -    /* Color description present flag in the VUI.  If this is set then
> -     * color_primaries, transfer_characteristics and matrix_coeffs are to be added
> -     * to the VUI.  The default is false. */
> -    int       bEnableColorDescriptionPresentFlag;
> -
> -    /* Color primaries holds the chromacity coordinates of the source primaries.
> -     * The default is 2. */
> -    int       colorPrimaries;
> -
> -    /* Transfer characteristics indicates the opto-electronic transfer characteristic
> -     * of the source picture.  The default is 2. */
> -    int       transferCharacteristics;
> -
> -    /* Matrix coefficients used to derive the luma and chroma signals from the red,
> -     * blue and green primaries.  The default is 2. */
> -    int       matrixCoeffs;
> -
> -    /* Chroma location info present flag adds chroma_sample_loc_type_top_field and
> -     * chroma_sample_loc_type_bottom_field to the VUI.  The default is false. */
> -    int       bEnableChromaLocInfoPresentFlag;
> -
> -    /* Chroma sample location type top field holds the chroma location in the top
> -     * field.  The default is 0. */
> -    int       chromaSampleLocTypeTopField;
> -
> -    /* Chroma sample location type bottom field holds the chroma location in the bottom
> -     * field.  The default is 0. */
> -    int       chromaSampleLocTypeBottomField;
> -
> -    /* Field seq flag specifies that the pictures are fields and each one has a
> -     * timing SEI message.  The default is false */
> -    int       bEnableFieldSeqFlag;
> -
> -    /* Frame field info present flag indicates that each picture has a timing SEI
> -     * message wich includes a pic_struct, source_scan_type and duplicate_flag
> -     * elements.  If not set then the pic_struct element is not included.  The
> -     * default is false. */
> -    int       bEnableFrameFieldInfoPresentFlag;
> -
> -    /* Default display window flag adds def_disp_win_left_offset ,
> -     * def_disp_win_right_offset, def_disp_win_top_offset and
> -     * def_disp_win_bottom_offset to the VUI.  The default is false. */
> -    int       bEnableDefaultDisplayWindowFlag;
> -
> -    /* Default display window left offset holds the left offset with the
> -     * conformance cropping window to further crop the displayed window. */
> -    int       defDispWinLeftOffset;
> -
> -    /* Default display window right offset holds the right offset with the
> -     * conformance cropping window to further crop the displayed window. */
> -    int       defDispWinRightOffset;
> -
> -    /* Default display window top offset holds the top offset with the
> -     * conformance cropping window to further crop the displayed window. */
> -    int       defDispWinTopOffset;
> -
> -    /* Default display window bottom offset holds the bottom offset with the
> -     * conformance cropping window to further crop the displayed window. */
> -    int       defDispWinBottomOffset;
> -
> -    /* VUI timing info present flag adds vui_num_units_in_tick, vui_time_scale,
> -     * vui_poc_proportional_to_timing_flag and vui_hrd_parameters_present_flag
> -     * to the VUI.  vui_num_units_in_tick, vui_time_scale and
> -     * vui_poc_proportional_to_timing_flag are derived from processing the input
> -     * video.  The default is false. */
> -    int       bEnableVuiTimingInfoPresentFlag;
> -
> -    /* VUI hrd parameters present flag adds the HRD to the VUI */
> -    int       bEnableVuiHrdParametersPresentFlag;
> -
> -    /* Bitstream restriction flag adds tiles_fixed_structure_flag,
> -     * motion_vectors_over_pic_boundaries_flag, restricted_ref_pic_lists_flag,
> -     * min_spatial_segmentation_idc, max_bytes_per_pic_denom,
> -     * max_bit_per_min_cu_denom, log2_max_mv_length_horizontal and
> -     * log2_max_mv_length_vertical to the VUI. All values are derived from
> -     * processing the input video.  The default is false.  */
> -    int       bEnableBitstreamRestrictionFlag;
> -
> -    /*== Hypothetical Reference Decoder Parameters ==*/
> -
> -    /* Sub pic HRD params present flag determines if tic_divisor_minus2,
> -     * du_cpb_removal_delay_increment_length_minus1,
> -     * sub_pic_cpb_params_in_pic_timing_sei_flag,
> -     * dpb_output_delay_du_length_minus1 and cpb_size_du_scale
> -     * are added to the HRD.  All are derived from processing the input video.
> -     * The default is false. */
> -    int       bEnableSubPicHrdParamsPresentFlag;
> -
> -    /*== Internal Picture Specification ==*/
> -
> -    /* Internal encoder bit depth. If x265 was compiled to use 8bit pixels
> -     * (HIGH_BIT_DEPTH=0), this field must be 8, else this field must be 10.
> -     * Future builds may support 12bit pixels. */
> -    int       internalBitDepth;
> -
> -    /* Color space of internal pictures. Only X265_CSP_I420 and X265_CSP_I444
> -     * are supported.  Eventually, i422 will also be supported as an internal
> -     * color space and other packed formats will be supported in
> -     * x265_picture.colorSpace */
> -    int       internalCsp;
> -
> -    /* Numerator and denominator of frame rate */
> -    uint32_t  fpsNum;
> -    uint32_t  fpsDenom;
> -
> -    /* Width (in pixels) of the source pictures. If this width is not an even
> -     * multiple of 4, the encoder will pad the pictures internally to meet this
> -     * minimum requirement. All valid HEVC widths are supported */
> -    int       sourceWidth;
> -
> -    /* Height (in pixels) of the source pictures. If this height is not an even
> -     * multiple of 4, the encoder will pad the pictures internally to meet this
> -     * minimum requirement. All valid HEVC heights are supported */
> -    int       sourceHeight;
> -
> -    /*== Coding Unit (CU) definitions ==*/
> -
> -    /* Maxiumum CU width and height in pixels.  The size must be 64, 32, or 16.
> -     * The higher the size, the more efficiently x265 can encode areas of low
> -     * complexity, greatly improving compression efficiency at large
> -     * resolutions.  The smaller the size, the more effective wavefront and
> -     * frame parallelism will become because of the increase in rows. default 64 */
> -    uint32_t  maxCUSize;
> -
> -    /* The additional depth the residual quadtree is allowed to recurse beyond
> -     * the coding quadtree, for inter coded blocks. This must be between 1 and
> -     * 3. The higher the value the more efficiently the residual can be
> -     * compressed by the DCT transforms, at the expense of much more compute */
> -    uint32_t  tuQTMaxInterDepth;
> -
> -    /* The additional depth the residual quadtree is allowed to recurse beyond
> -     * the coding quadtree, for intra coded blocks. This must be between 1 and
> -     * 3. The higher the value the more efficiently the residual can be
> -     * compressed by the DCT transforms, at the expense of much more compute */
> -    uint32_t  tuQTMaxIntraDepth;
> -
> -    /*== GOP Structure and Lokoahead ==*/
> -
> -    /* Enable open GOP - meaning I slices are not necessariy IDR and thus frames
> -     * encoded after an I slice may reference frames encoded prior to the I
> -     * frame which have remained in the decoded picture buffer.  Open GOP
> -     * generally has better compression efficiency and negligable encoder
> -     * performance impact, but the use case may preclude it.  Default true */
> -    int       bOpenGOP;
> -
> -    /* Scenecuts closer together than this are coded as I, not IDR. */
> -    int       keyframeMin;
> -
> -    /* Maximum keyframe distance or intra period in number of frames. If 0 or 1,
> -     * all frames are I frames. A negative value is casted to MAX_INT internally
> -     * which effectively makes frame 0 the only I frame. Default is 250 */
> -    int       keyframeMax;
> -
> -    /* The maximum number of L0 references a P or B slice may use. This
> -     * influences the size of the decoded picture buffer. The higher this
> -     * number, the more reference frames there will be available for motion
> -     * search, improving compression efficiency of most video at a cost of
> -     * performance. Value must be between 1 and 16, default is 3 */
> -    int       maxNumReferences;
> -
> -    /* Sets the operating mode of the lookahead.  With b-adapt 0, the GOP
> -     * structure is fixed based on the values of keyframeMax and bframes.
> -     * With b-adapt 1 a light lookahead is used to chose B frame placement.
> -     * With b-adapt 2 (trellis) a viterbi B path selection is performed */
> -    int       bFrameAdaptive;
> -
> -    /* Maximum consecutive B frames that can be emitted by the lookehead. When
> -     * b-adapt is 0 and keyframMax is greater than bframes, the lookahead emits
> -     * a fixed pattern of `bframes` B frames between each P.  With b-adapt 1 the
> -     * lookahead ignores the value of bframes for the most part.  With b-adapt 2
> -     * the value of bframes determines the search (POC) distance performeed in
> -     * both directions, quadradically increasing the compute load of the
> -     * lookahead.  The higher the value, the more B frames the lookahead may
> -     * possibly use consecutively, usually improving compression. Default is 3,
> -     * maximum is 16 */
> -    int       bframes;
> -
> -    /* When enabled, the encoder will use the B frame in the middle of each
> -     * mini-GOP larger than 2 B frames as a motion reference for the surrounding
> -     * B frames.  This improves compression efficiency for a small performance
> -     * penalty.  Referenced B frames are treated somewhere between a B and a P
> -     * frame by rate control.  Default is enabled. */
> -    int       bBPyramid;
> -
> -    /* The number of frames that must be queued in the lookahead before it may
> -     * make slice decisions. Increasing this value directly increases the encode
> -     * latency. The longer the queue the more optimally the lookahead may make
> -     * slice decisions, particularly with b-adapt 2. When mb-tree is enabled,
> -     * the length of the queue linearly increases the effectiveness of the
> -     * mb-tree analysis. Default is 40 frames, maximum is 250 */
> -    int       lookaheadDepth;
> -
> -    /* A value which is added to the cost estimate of B frames in the lookahead.
> -     * It may be a positive value (making B frames appear more expensive, which
> -     * causes the lookahead to chose more P frames) or negative, which makes the
> -     * lookahead chose more B frames. Default is 0, there are no limits */
> -    int       bFrameBias;
> -
> -    /* An arbitrary threshold which determines how agressively the lookahead
> -     * should detect scene cuts. The default (40) is recommended. */
> -    int       scenecutThreshold;
> -
> -    /*== Intra Coding Tools ==*/
> -
> -    /* Enable constrained intra prediction. This causes intra prediction to
> -     * input samples that were inter predicted. For some use cases this is
> -     * believed to me more robust to stream errors, but it has a compression
> -     * penalty on P and (particularly) B slices. Defaults to diabled */
> -    int       bEnableConstrainedIntra;
> -
> -    /* Enable strong intra smoothing for 32x32 blocks where the reference
> -     * samples are flat. It may or may not improve compression efficiency,
> -     * depending on your source material. Defaults to disabled */
> -    int       bEnableStrongIntraSmoothing;
> -
> -    /*== Inter Coding Tools ==*/
> -
> -    /* ME search method (DIA, HEX, UMH, STAR, FULL). The search patterns
> -     * (methods) are sorted in increasing complexity, with diamond being the
> -     * simplest and fastest and full being the slowest.  DIA, HEX, and UMH were
> -     * adapted from x264 directly. STAR is an adaption of the HEVC reference
> -     * encoder's three step search, while full is a naive exhaustive search. The
> -     * default is the star search, it has a good balance of performance and
> -     * compression efficiecy */
> -    int       searchMethod;
> -
> -    /* A value between 0 and X265_MAX_SUBPEL_LEVEL which adjusts the amount of
> -     * effort performed during subpel refine. Default is 5 */
> -    int       subpelRefine;
> -
> -    /* The maximum distance from the motion prediction that the full pel motion
> -     * search is allowed to progress before terminating. This value can have an
> -     * effect on frame parallelism, as referenced frames must be at least this
> -     * many rows of reconstructed pixels ahead of the referencee at all times.
> -     * (When considering reference lag, the motion prediction must be ignored
> -     * because it cannot be known ahead of time).  Default is 60, which is the
> -     * default max CU size (64) minus the luma HPEL half-filter length (4). If a
> -     * smaller CU size is used, the search range should be similarly reduced */
> -    int       searchRange;
> -
> -    /* The maximum number of merge candidates that are considered during inter
> -     * analysis.  This number (between 1 and 5) is signaled in the stream
> -     * headers and determines the number of bits required to signal a merge so
> -     * it can have significant trade-offs. The smaller this number the higher
> -     * the performance but the less compression efficiency. Default is 3 */
> -    uint32_t  maxNumMergeCand;
> -
> -    /* Enable weighted prediction in P slices.  This enables weighting analysis
> -     * in the lookahead, which influences slice decitions, and enables weighting
> -     * analysis in the main encoder which allows P reference samples to have a
> -     * weight function applied to them prior to using them for motion
> -     * compensation.  In video which has lighting changes, it can give a large
> -     * improvement in compression efficiency. Default is enabled */
> -    int       bEnableWeightedPred;
> -
> -    /* Enable weighted bi-prediction in B slices. This option currently has no
> -     * effect */
> -    int       bEnableWeightedBiPred;
> -
> -    /*== Analysis tools ==*/
> -
> -    /* Enable asymmetrical motion predictions.  At CU depths 64, 32, and 16, it
> -     * is possible to use 25%/75% split partitions in the up, down, right, left
> -     * directions. For some material this can improve compression efficiency at
> -     * the cost of extra analysis. bEnableRectInter must be enabled for this
> -     * feature to be used. Default enabled */
> -    int       bEnableAMP;
> -
> -    /* Enable rectangular motion prediction partitions (vertical and
> -     * horizontal), available at all CU depths from 64x64 to 8x8. Default is
> -     * enabled */
> -    int       bEnableRectInter;
> -
> -    /* Enable the use of `coded block flags` (flags set to true when a residual
> -     * has been coded for a given block) to avoid intra analysis in likely skip
> -     * blocks. Default is disabled */
> -    int       bEnableCbfFastMode;
> -
> -    /* Enable early skip decisions to avoid intra and inter analysis in likely
> -     * skip blocks. Default is disabled */
> -    int       bEnableEarlySkip;
> -
> -    /* Apply an optional penalty to the estimated cost of 32x32 intra blocks in
> -     * non-intra slices. 0 is disabled, 1 enables a small penalty, and 2 enables
> -     * a full penalty. This favors inter-coding and its low bitrate over
> -     * potential increases in distortion, but usually improves performance.
> -     * Default is 0 */
> -    int       rdPenalty;
> -
> -    /* A value betwen X265_NO_RDO_NO_RDOQ and X265_RDO_LEVEL which determines
> -     * the level of rate distortion optimizations to perform during mode
> -     * decisions and quantization. The more RDO the better the compression
> -     * efficiency at a major cost of performance. Default is no RDO (0) */
> -    int       rdLevel;
> -
> -    /*== Coding tools ==*/
> -
> -    /* Enable the implicit signaling of the sign bit of the last coefficient of
> -     * each transform unit. This saves one bit per TU at the expense of figuring
> -     * out which coefficient can be toggled with the least distortion.
> -     * Default is enabled */
> -    int       bEnableSignHiding;
> -
> -    /* Allow intra coded blocks to be encoded directly as residual without the
> -     * DCT transform, when this improves efficiency. Checking whether the block
> -     * will benefit from this option incurs a performance penalty. Default is
> -     * enabled */
> -    int       bEnableTransformSkip;
> -
> -    /* Enable a faster determination of whether skippig the DCT transform will
> -     * be beneficial. Slight performance gain for some compression loss. Default
> -     * is enabled */
> -    int       bEnableTSkipFast;
> -
> -    /* Enable the deblocking loop filter, which improves visual quality by
> -     * reducing blocking effects at block edges, particularly at lower bitrates
> -     * or higher QP. When enabled it adds another CU row of reference lag,
> -     * reducing frame parallelism effectiveness.  Default is enabled */
> -    int       bEnableLoopFilter;
> -
> -    /* Enable the Sample Adaptive Offset loop filter, which reduces distortion
> -     * effects by adjusting reconstructed sample values based on histogram
> -     * analysis to better approximate the original samples. When enabled it adds
> -     * a CU row of reference lag, reducing frame parallelism effectiveness.
> -     * Default is enabled */
> -    int       bEnableSAO;
> -
> -    /* Note: when deblocking and SAO are both enabled, the loop filter CU lag is
> -     * only one row, as they operate in series o the same row. */
> -
> -    /* Select the method in which SAO deals with deblocking boundary pixels.  If
> -     * 0 the right and bottom boundary areas are skipped. If 1, non-deblocked
> -     * pixels are used entirely. Default is 0 */
> -    int       saoLcuBoundary;
> -
> -    /* Select the scope of the SAO optimization. If 0 SAO is performed over the
> -     * entire output picture at once, this can severly restrict frame
> -     * parallelism so it is not recommended for many-core machines.  If 1 SAO is
> -     * performed on LCUs in series. Default is 1 */
> -    int       saoLcuBasedOptimization;
> -
> -    /* Generally a small signed integer which offsets the QP used to quantize
> -     * the Cb chroma residual (delta from luma QP specified by rate-control).
> -     * Default is 0, which is recommended */
> -    int       cbQpOffset;
> -
> -    /* Generally a small signed integer which offsets the QP used to quantize
> -     * the Cr chroma residual (delta from luma QP specified by rate-control).
> -     * Default is 0, which is recommended */
> -    int       crQpOffset;
> -
> -    /*== Rate Control ==*/
> -
> -    struct
> -    {
> -        /* Explicit mode of rate-control, necessary for API users. It must
> -         * be one of the X265_RC_METHODS enum values. */
> -        int       rateControlMode;
> -
> -        /* Base QP to use for Constant QP rate control. Adaptive QP may alter
> -         * the QP used for each block. If a QP is specified on the command line
> -         * CQP rate control is implied. Default: 32 */
> -        int       qp;
> -
> -        /* target bitrate for Average BitRate (ABR) rate control. If a non- zero
> -         * bitrate is specified on the command line, ABR is implied. Default 0 */
> -        int       bitrate;
> -
> -        /* The degree of rate fluctuation that x265 tolerates. Rate tolerance is used
> -         * alongwith overflow (difference between actual and target bitrate), to adjust
> -           qp. Default is 1.0 */
> -        double    rateTolerance;
> -
> -        /* qComp sets the quantizer curve compression factor. It weights the frame
> -         * quantizer based on the complexity of residual (measured by lookahead).
> -         * Default value is 0.6. Increasing it to 1 will effectively generate CQP */
> -        double    qCompress;
> -
> -        /* QP offset between I/P and P/B frames. Default ipfactor: 1.4
> -         *  Default pbFactor: 1.3 */
> -        double    ipFactor;
> -        double    pbFactor;
> -
> -        /* Max QP difference between frames. Default: 4 */
> -        int       qpStep;
> -
> -        /* Ratefactor constant: targets a certain constant "quality".
> -         * Acceptable values between 0 and 51. Default value: 28 */
> -        double    rfConstant;
> -
> -        /* Enable adaptive quantization. This mode distributes available bits between all
> -         * macroblocks of a frame, assigning more bits to low complexity areas. Turning
> -         * this ON will usually affect PSNR negatively, however SSIM and visual quality
> -         * generally improves. Default: OFF (0) */
> -        int       aqMode;
> -
> -        /* Sets the strength of AQ bias towards low detail macroblocks. Valid only if
> -         * AQ is enabled. Default value: 1.0. Acceptable values between 0.0 and 3.0 */
> -        double    aqStrength;
> -
> -        /* Sets the maximum rate the VBV buffer should be assumed to refill at
> -         * Default is zero */
> -        int       vbvMaxBitrate;
> -
> -        /* Sets the size of the VBV buffer in kilobits. Default is zero */
> -        int       vbvBufferSize;
> -
> -        /* Sets how full the VBV buffer must be before playback starts. If it is less than
> -         * 1, then the initial fill is vbv-init * vbvBufferSize. Otherwise, it is
> -         * interpreted as the initial fill in kbits. Default is 0.9 */
> -        double    vbvBufferInit;
> -
> -        /* Enable CUTree ratecontrol. This keeps track of the CUs that propagate temporally
> -         * across frames and assigns more bits to these CUs. Improves encode efficiency.
> -         * Default: OFF (0) */
> -        int       cuTree;
> -        /* In CRF mode, maximum CRF as caused by VBV */
> -        double    rfConstantMax;
> -    } rc;
> -} x265_param;
> -
>  /***
>   * If not called, first encoder allocated will auto-detect the CPU and
>   * initialize performance primitives, which are process global */
>  void x265_setup_primitives(x265_param *param, int cpu);
>
> -/* x265_param_alloc:
> - *  Allocates an x265_param instance. The returned param structure is not
> - *  special in any way, but using this method together with x265_param_free()
> - *  and x265_param_parse() to set values by name allows the application to treat
> - *  x265_param as an opaque data struct for version safety */
> -x265_param *x265_param_alloc();
> -
> -/* x265_param_free:
> - *  Use x265_param_free() to release storage for an x265_param instance
> - *  allocated by x26_param_alloc() */
> -void x265_param_free(x265_param *);
> -
> -/***
> - * Initialize an x265_param_t structure to default values
> - */
> -void x265_param_default(x265_param *param);
> -
> -/* x265_param_parse:
> - *  set one parameter by name.
> - *  returns 0 on success, or returns one of the following errors.
> - *  note: BAD_VALUE occurs only if it can't even parse the value,
> - *  numerical range is not checked until x265_encoder_open() or
> - *  x265_encoder_reconfig().
> - *  value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */
> -#define X265_PARAM_BAD_NAME  (-1)
> -#define X265_PARAM_BAD_VALUE (-2)
> -int x265_param_parse(x265_param *p, const char *name, const char *value);
> -
> -/* x265_param_apply_profile:
> - *      Applies the restrictions of the given profile. (one of below) */
> -static const char * const x265_profile_names[] = { "main", "main10", "mainstillpicture", 0 };
> -
> -/*      (can be NULL, in which case the function will do nothing)
> - *      returns 0 on success, negative on failure (e.g. invalid profile name). */
> -int x265_param_apply_profile(x265_param *, const char *profile);
> -
> -/* x265_param_default_preset:
> - *      The same as x265_param_default, but also use the passed preset and tune
> - *      to modify the default settings.
> - *      (either can be NULL, which implies no preset or no tune, respectively)
> - *
> - *      Currently available presets are, ordered from fastest to slowest: */
> -static const char * const x265_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };
> -
> -/*      The presets can also be indexed numerically, as in:
> - *      x265_param_default_preset( &param, "3", ... )
> - *      with ultrafast mapping to "0" and placebo mapping to "9".  This mapping may
> - *      of course change if new presets are added in between, but will always be
> - *      ordered from fastest to slowest.
> - *
> - *      Warning: the speed of these presets scales dramatically.  Ultrafast is a full
> - *      100 times faster than placebo!
> - *
> - *      Currently available tunings are: */
> -static const char * const x265_tune_names[] = { "psnr", "ssim", "zero-latency", 0 };
> -
> -/*      returns 0 on success, negative on failure (e.g. invalid preset/tune name). */
> -int x265_param_default_preset(x265_param *, const char *preset, const char *tune);
> -
>  /* x265_picture_alloc:
>   *  Allocates an x265_picture instance. The returned picture structure is not
>   *  special in any way, but using this method together with x265_picture_free()
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel



-- 
Steve Borho


More information about the x265-devel mailing list