LCOV - code coverage report
Current view: top level - home/magsoft/trunks/SVT-AV1/Source/App/EncApp - EbAppConfig.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 225 588 38.3 %
Date: 2019-11-25 17:38:06 Functions: 15 107 14.0 %

          Line data    Source code
       1             : /*
       2             : * Copyright(c) 2019 Intel Corporation
       3             : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
       4             : */
       5             : 
       6             : #include <stdio.h>
       7             : #include <stdlib.h>
       8             : #include <string.h>
       9             : #include <sys/stat.h>
      10             : 
      11             : #include "EbAppString.h"
      12             : #include "EbAppConfig.h"
      13             : #include "EbAppInputy4m.h"
      14             : 
      15             : #ifdef _WIN32
      16             : #include <windows.h>
      17             : #else
      18             : #include <unistd.h>
      19             : #endif
      20             : 
      21             : /**********************************
      22             :  * Defines
      23             :  **********************************/
      24             : #define HELP_TOKEN                      "-help"
      25             : #define CHANNEL_NUMBER_TOKEN            "-nch"
      26             : #define COMMAND_LINE_MAX_SIZE           2048
      27             : #define CONFIG_FILE_TOKEN               "-c"
      28             : #define INPUT_FILE_TOKEN                "-i"
      29             : #define OUTPUT_BITSTREAM_TOKEN          "-b"
      30             : #define OUTPUT_RECON_TOKEN              "-o"
      31             : #define ERROR_FILE_TOKEN                "-errlog"
      32             : #define QP_FILE_TOKEN                   "-qp-file"
      33             : #if TWO_PASS
      34             : #define INPUT_STAT_FILE_TOKEN           "-input-stat-file"
      35             : #define OUTPUT_STAT_FILE_TOKEN          "-output-stat-file"
      36             : #endif
      37             : #define STAT_FILE_TOKEN                 "-stat-file"
      38             : #define WIDTH_TOKEN                     "-w"
      39             : #define HEIGHT_TOKEN                    "-h"
      40             : #define NUMBER_OF_PICTURES_TOKEN        "-n"
      41             : #define BUFFERED_INPUT_TOKEN            "-nb"
      42             : #define BASE_LAYER_SWITCH_MODE_TOKEN    "-base-layer-switch-mode" // no Eval
      43             : #define QP_TOKEN                        "-q"
      44             : #define USE_QP_FILE_TOKEN               "-use-q-file"
      45             : #define STAT_REPORT_TOKEN               "-stat-report"
      46             : #define FRAME_RATE_TOKEN                "-fps"
      47             : #define FRAME_RATE_NUMERATOR_TOKEN      "-fps-num"
      48             : #define FRAME_RATE_DENOMINATOR_TOKEN    "-fps-denom"
      49             : #define ENCODER_BIT_DEPTH               "-bit-depth"
      50             : #define ENCODER_COLOR_FORMAT            "-color-format"
      51             : #define INPUT_COMPRESSED_TEN_BIT_FORMAT "-compressed-ten-bit-format"
      52             : #define ENCMODE_TOKEN                   "-enc-mode"
      53             : #if TWO_PASS_USE_2NDP_ME_IN_1STP
      54             : #define ENCMODE2P_TOKEN                 "-enc-mode-2p"
      55             : #endif
      56             : #define HIERARCHICAL_LEVELS_TOKEN       "-hierarchical-levels" // no Eval
      57             : #define PRED_STRUCT_TOKEN               "-pred-struct"
      58             : #define INTRA_PERIOD_TOKEN              "-intra-period"
      59             : #define PROFILE_TOKEN                   "-profile"
      60             : #define TIER_TOKEN                      "-tier"
      61             : #define LEVEL_TOKEN                     "-level"
      62             : #define LATENCY_MODE                    "-latency-mode" // no Eval
      63             : #define FILM_GRAIN_TOKEN                "-film-grain"
      64             : #define INTERLACED_VIDEO_TOKEN          "-interlaced-video"
      65             : #define SEPERATE_FILDS_TOKEN            "-separate-fields"
      66             : #define INTRA_REFRESH_TYPE_TOKEN        "-irefresh-type" // no Eval
      67             : #define LOOP_FILTER_DISABLE_TOKEN       "-dlf"
      68             : #define LOCAL_WARPED_ENABLE_TOKEN       "-local-warp"
      69             : #define GLOBAL_MOTION_ENABLE_TOKEN      "-global-motion"
      70             : #define OBMC_TOKEN                      "-obmc"
      71             : #define RDOQ_TOKEN                      "-rdoq"
      72             : #define FILTER_INTRA_TOKEN              "-filter-intra"
      73             : #define USE_DEFAULT_ME_HME_TOKEN        "-use-default-me-hme"
      74             : #define HME_ENABLE_TOKEN                "-hme"
      75             : #define HME_L0_ENABLE_TOKEN             "-hme-l0"
      76             : #define HME_L1_ENABLE_TOKEN             "-hme-l1"
      77             : #define HME_L2_ENABLE_TOKEN             "-hme-l2"
      78             : #define EXT_BLOCK                       "-ext-block"
      79             : #define IN_LOOP_ME                      "-in-loop-me"
      80             : #define SEARCH_AREA_WIDTH_TOKEN         "-search-w"
      81             : #define SEARCH_AREA_HEIGHT_TOKEN        "-search-h"
      82             : #define NUM_HME_SEARCH_WIDTH_TOKEN      "-num-hme-w"
      83             : #define NUM_HME_SEARCH_HEIGHT_TOKEN     "-num-hme-h"
      84             : #define HME_SRCH_T_L0_WIDTH_TOKEN       "-hme-tot-l0-w"
      85             : #define HME_SRCH_T_L0_HEIGHT_TOKEN      "-hme-tot-l0-h"
      86             : #define HME_LEVEL0_WIDTH                "-hme-l0-w"
      87             : #define HME_LEVEL0_HEIGHT               "-hme-l0-h"
      88             : #define HME_LEVEL1_WIDTH                "-hme-l1-w"
      89             : #define HME_LEVEL1_HEIGHT               "-hme-l1-h"
      90             : #define HME_LEVEL2_WIDTH                "-hme-l2-w"
      91             : #define HME_LEVEL2_HEIGHT               "-hme-l2-h"
      92             : #define SCREEN_CONTENT_TOKEN            "-scm"
      93             : // --- start: ALTREF_FILTERING_SUPPORT
      94             : #define ENABLE_ALTREFS                  "-enable-altrefs"
      95             : #define ALTREF_STRENGTH                 "-altref-strength"
      96             : #define ALTREF_NFRAMES                  "-altref-nframes"
      97             : #define ENABLE_OVERLAYS                 "-enable-overlays"
      98             : // --- end: ALTREF_FILTERING_SUPPORT
      99             : #define HBD_MD_ENABLE_TOKEN             "-hbd-md"
     100             : #define PALETTE_TOKEN                   "-palette"
     101             : #define OLPD_REFINEMENT_TOKEN           "-olpd-refinement"
     102             : #define CONSTRAINED_INTRA_ENABLE_TOKEN  "-constrd-intra"
     103             : #define HDR_INPUT_TOKEN                 "-hdr"
     104             : #define RATE_CONTROL_ENABLE_TOKEN       "-rc"
     105             : #define TARGET_BIT_RATE_TOKEN           "-tbr"
     106             : #define MAX_QP_TOKEN                    "-max-qp"
     107             : #define MIN_QP_TOKEN                    "-min-qp"
     108             : #define ADAPTIVE_QP_ENABLE_TOKEN        "-adaptive-quantization"
     109             : #define LOOK_AHEAD_DIST_TOKEN           "-lad"
     110             : #define SUPER_BLOCK_SIZE_TOKEN          "-sb-size"
     111             : #define TILE_ROW_TOKEN                   "-tile-rows"
     112             : #define TILE_COL_TOKEN                   "-tile-columns"
     113             : 
     114             : #define SQ_WEIGHT_TOKEN                 "-sqw"
     115             : 
     116             : #define SCENE_CHANGE_DETECTION_TOKEN    "-scd"
     117             : #define INJECTOR_TOKEN                  "-inj"  // no Eval
     118             : #define INJECTOR_FRAMERATE_TOKEN        "-inj-frm-rt" // no Eval
     119             : #define SPEED_CONTROL_TOKEN             "-speed-ctrl"
     120             : #define ASM_TYPE_TOKEN                  "-asm"
     121             : #define THREAD_MGMNT                    "-lp"
     122             : #define TARGET_SOCKET                   "-ss"
     123             : #define UNRESTRICTED_MOTION_VECTOR      "-umv"
     124             : #define CONFIG_FILE_COMMENT_CHAR    '#'
     125             : #define CONFIG_FILE_NEWLINE_CHAR    '\n'
     126             : #define CONFIG_FILE_RETURN_CHAR     '\r'
     127             : #define CONFIG_FILE_VALUE_SPLIT     ':'
     128             : #define CONFIG_FILE_SPACE_CHAR      ' '
     129             : #define CONFIG_FILE_ARRAY_SEP_CHAR  CONFIG_FILE_SPACE_CHAR
     130             : #define CONFIG_FILE_TAB_CHAR        '\t'
     131             : #define CONFIG_FILE_NULL_CHAR       '\0'
     132             : #define CONFIG_FILE_MAX_ARG_COUNT   256
     133             : #define CONFIG_FILE_MAX_VAR_LEN     128
     134             : #define EVENT_FILE_MAX_ARG_COUNT    20
     135             : #define EVENT_FILE_MAX_VAR_LEN      256
     136             : #define BUFFER_FILE_MAX_ARG_COUNT   320
     137             : #define BUFFER_FILE_MAX_VAR_LEN     128
     138             : 
     139             : #define MDS1_PRUNE_C_TH             "-mds1p-class-th"
     140             : #define MDS1_PRUNE_S_TH             "-mds1p-cand-th"
     141             : #define MDS2_PRUNE_C_TH             "-mds2p-class-th"
     142             : #define MDS2_PRUNE_S_TH             "-mds2p-cand-th"
     143             : 
     144             : /**********************************
     145             :  * Set Cfg Functions
     146             :  **********************************/
     147           2 : static void SetCfgInputFile(const char *filename, EbConfig *cfg)
     148             : {
     149           2 :     if (cfg->input_file && !cfg->input_file_is_fifo)
     150           0 :         fclose(cfg->input_file);
     151             : 
     152           2 :     if (!filename) {
     153           0 :         cfg->input_file = NULL;
     154           0 :         return;
     155             :     }
     156             : 
     157           2 :     if (!strcmp(filename, "stdin"))
     158           0 :         cfg->input_file = stdin;
     159             :     else
     160           2 :         FOPEN(cfg->input_file, filename, "rb");
     161             : 
     162           2 :     if (cfg->input_file == NULL) {
     163           0 :         return;
     164             :     }
     165             : 
     166             : #ifdef _WIN32
     167             :     cfg->input_file_is_fifo =
     168             :     GetFileType(cfg->input_file) == FILE_TYPE_PIPE;
     169             : #else
     170           2 :     int fd = fileno(cfg->input_file);
     171             :     struct stat statbuf;
     172           2 :     fstat(fd, &statbuf);
     173           2 :     cfg->input_file_is_fifo = S_ISFIFO(statbuf.st_mode);
     174             : #endif
     175             : 
     176           2 :     cfg->y4m_input = check_if_y4m(cfg);
     177             : };
     178             : 
     179           2 : static void SetCfgStreamFile                    (const char *value, EbConfig *cfg)
     180             : {
     181           2 :     if (cfg->bitstream_file) { fclose(cfg->bitstream_file); }
     182           2 :     FOPEN(cfg->bitstream_file,value, "wb");
     183           2 : };
     184           0 : static void SetCfgErrorFile                     (const char *value, EbConfig *cfg)
     185             : {
     186           0 :     if (cfg->error_log_file) { fclose(cfg->error_log_file); }
     187           0 :     FOPEN(cfg->error_log_file,value, "w+");
     188           0 : };
     189           0 : static void SetCfgReconFile                     (const char *value, EbConfig *cfg)
     190             : {
     191           0 :     if (cfg->recon_file) { fclose(cfg->recon_file); }
     192           0 :     FOPEN(cfg->recon_file,value, "wb");
     193           0 : };
     194           0 : static void SetCfgQpFile                        (const char *value, EbConfig *cfg)
     195             : {
     196           0 :     if (cfg->qp_file) { fclose(cfg->qp_file); }
     197           0 :     FOPEN(cfg->qp_file,value, "r");
     198           0 : };
     199             : #if TWO_PASS
     200           0 : static void set_input_stat_file(const char *value, EbConfig *cfg)
     201             : {
     202           0 :     if (cfg->input_stat_file) { fclose(cfg->input_stat_file); }
     203           0 :     FOPEN(cfg->input_stat_file, value, "rb");
     204           0 : };
     205           0 : static void set_output_stat_file(const char *value, EbConfig *cfg)
     206             : {
     207           0 :     if (cfg->output_stat_file) { fclose(cfg->output_stat_file); }
     208           0 :     FOPEN(cfg->output_stat_file, value, "wb");
     209           0 : };
     210             : #if TWO_PASS_USE_2NDP_ME_IN_1STP
     211           0 : static void set_snd_pass_enc_mode(const char *value, EbConfig *cfg) { cfg->snd_pass_enc_mode = (uint8_t)strtoul(value, NULL, 0); };
     212             : #endif
     213             : #endif
     214           0 : static void SetCfgStatFile(const char *value, EbConfig *cfg)
     215             : {
     216           0 :     if (cfg->stat_file) { fclose(cfg->stat_file); }
     217           0 :     FOPEN(cfg->stat_file, value, "wb");
     218           0 : };
     219           0 : static void SetStatReport                       (const char *value, EbConfig *cfg) {cfg->stat_report = (uint8_t) strtoul(value, NULL, 0);};
     220           0 : static void SetCfgSourceWidth                   (const char *value, EbConfig *cfg) {cfg->source_width = strtoul(value, NULL, 0);};
     221           0 : static void SetInterlacedVideo                  (const char *value, EbConfig *cfg) {cfg->interlaced_video  = (EbBool) strtoul(value, NULL, 0);};
     222           0 : static void SetSeperateFields                   (const char *value, EbConfig *cfg) {cfg->separate_fields = (EbBool) strtoul(value, NULL, 0);};
     223           0 : static void SetCfgSourceHeight                  (const char *value, EbConfig *cfg) {cfg->source_height = strtoul(value, NULL, 0) >> cfg->separate_fields;};
     224           0 : static void SetCfgFramesToBeEncoded             (const char *value, EbConfig *cfg) {cfg->frames_to_be_encoded = strtol(value,  NULL, 0) << cfg->separate_fields;};
     225           0 : static void SetBufferedInput                    (const char *value, EbConfig *cfg) {cfg->buffered_input = (strtol(value, NULL, 0) != -1 && cfg->separate_fields) ? strtol(value, NULL, 0) << cfg->separate_fields : strtol(value, NULL, 0);};
     226           0 : static void SetFrameRate                        (const char *value, EbConfig *cfg) {
     227           0 :     cfg->frame_rate = strtoul(value, NULL, 0);
     228           0 :     if (cfg->frame_rate > 1000 )
     229           0 :         cfg->frame_rate = cfg->frame_rate;
     230             :     else
     231           0 :         cfg->frame_rate = cfg->frame_rate << 16;
     232           0 : }
     233             : 
     234           0 : static void SetFrameRateNumerator               (const char *value, EbConfig *cfg) { cfg->frame_rate_numerator = strtoul(value, NULL, 0);};
     235           0 : static void SetFrameRateDenominator             (const char *value, EbConfig *cfg) { cfg->frame_rate_denominator = strtoul(value, NULL, 0);};
     236           0 : static void SetEncoderBitDepth                  (const char *value, EbConfig *cfg) {cfg->encoder_bit_depth = strtoul(value, NULL, 0);}
     237           0 : static void SetEncoderColorFormat               (const char *value, EbConfig *cfg) {cfg->encoder_color_format = strtoul(value, NULL, 0);}
     238           0 : static void SetcompressedTenBitFormat           (const char *value, EbConfig *cfg) {cfg->compressed_ten_bit_format = strtoul(value, NULL, 0);}
     239           0 : static void SetBaseLayerSwitchMode              (const char *value, EbConfig *cfg) {cfg->base_layer_switch_mode = (EbBool) strtoul(value, NULL, 0);};
     240           2 : static void SetencMode                          (const char *value, EbConfig *cfg) {cfg->enc_mode = (uint8_t)strtoul(value, NULL, 0);};
     241           0 : static void SetCfgIntraPeriod                   (const char *value, EbConfig *cfg) {cfg->intra_period = strtol(value,  NULL, 0);};
     242           0 : static void SetCfgIntraRefreshType              (const char *value, EbConfig *cfg) {cfg->intra_refresh_type = strtol(value,  NULL, 0);};
     243           0 : static void SetHierarchicalLevels               (const char *value, EbConfig *cfg) { cfg->hierarchical_levels = strtol(value, NULL, 0); };
     244           0 : static void SetCfgPredStructure                 (const char *value, EbConfig *cfg) { cfg->pred_structure = strtol(value, NULL, 0); };
     245           2 : static void SetCfgQp                            (const char *value, EbConfig *cfg) {cfg->qp = strtoul(value, NULL, 0);};
     246           0 : static void SetCfgUseQpFile                     (const char *value, EbConfig *cfg) {cfg->use_qp_file = (EbBool)strtol(value, NULL, 0); };
     247           0 : static void SetCfgFilmGrain                     (const char *value, EbConfig *cfg) { cfg->film_grain_denoise_strength = strtol(value, NULL, 0); };  //not bool to enable possible algorithm extension in the future
     248           0 : static void SetDisableDlfFlag                   (const char *value, EbConfig *cfg) {cfg->disable_dlf_flag = (EbBool)strtoul(value, NULL, 0);};
     249           0 : static void SetEnableLocalWarpedMotionFlag      (const char *value, EbConfig *cfg) {cfg->enable_warped_motion = (EbBool)strtoul(value, NULL, 0);};
     250           0 : static void SetEnableGlobalMotionFlag           (const char *value, EbConfig *cfg) {cfg->enable_global_motion = (EbBool)strtoul(value, NULL, 0);};
     251           0 : static void SetEnableObmcFlag                   (const char *value, EbConfig *cfg) {cfg->enable_obmc = (EbBool)strtoul(value, NULL, 0);};
     252           0 : static void SetEnableRdoqFlag                   (const char *value, EbConfig *cfg) {cfg->enable_rdoq = (int8_t)strtol(value, NULL, 0);};
     253             : 
     254           0 : static void SetEnableFilterIntraFlag            (const char *value, EbConfig *cfg) {cfg->enable_filter_intra = (EbBool)strtoul(value, NULL, 0);};
     255           0 : static void SetEnableHmeFlag                    (const char *value, EbConfig *cfg) {cfg->enable_hme_flag = (EbBool)strtoul(value, NULL, 0);};
     256           0 : static void SetEnableHmeLevel0Flag              (const char *value, EbConfig *cfg) {cfg->enable_hme_level0_flag = (EbBool)strtoul(value, NULL, 0);};
     257           0 : static void SetTileRow                          (const char *value, EbConfig *cfg) { cfg->tile_rows = strtoul(value, NULL, 0); };
     258           0 : static void SetTileCol                          (const char *value, EbConfig *cfg) { cfg->tile_columns = strtoul(value, NULL, 0); };
     259             : 
     260           0 : static void SetSceneChangeDetection             (const char *value, EbConfig *cfg) {cfg->scene_change_detection = strtoul(value, NULL, 0);};
     261           0 : static void SetLookAheadDistance                (const char *value, EbConfig *cfg) {cfg->look_ahead_distance = strtoul(value, NULL, 0);};
     262           0 : static void SetRateControlMode                  (const char *value, EbConfig *cfg) {cfg->rate_control_mode = strtoul(value, NULL, 0);};
     263           0 : static void SetTargetBitRate                    (const char *value, EbConfig *cfg) {cfg->target_bit_rate = strtoul(value, NULL, 0);};
     264           0 : static void SetMaxQpAllowed                     (const char *value, EbConfig *cfg) {cfg->max_qp_allowed = strtoul(value, NULL, 0);};
     265           0 : static void SetMinQpAllowed                     (const char *value, EbConfig *cfg) {cfg->min_qp_allowed = strtoul(value, NULL, 0);};
     266           0 : static void SetAdaptiveQuantization             (const char *value, EbConfig *cfg) {cfg->enable_adaptive_quantization = (EbBool)strtol(value,  NULL, 0);};
     267           0 : static void SetEnableHmeLevel1Flag              (const char *value, EbConfig *cfg) {cfg->enable_hme_level1_flag  = (EbBool)strtoul(value, NULL, 0);};
     268           0 : static void SetEnableHmeLevel2Flag              (const char *value, EbConfig *cfg) {cfg->enable_hme_level2_flag  = (EbBool)strtoul(value, NULL, 0);};
     269           0 : static void SetCfgSearchAreaWidth               (const char *value, EbConfig *cfg) {cfg->search_area_width = strtoul(value, NULL, 0);};
     270           0 : static void SetCfgSearchAreaHeight              (const char *value, EbConfig *cfg) {cfg->search_area_height = strtoul(value, NULL, 0);};
     271           0 : static void SetCfgNumberHmeSearchRegionInWidth  (const char *value, EbConfig *cfg) {cfg->number_hme_search_region_in_width = strtoul(value, NULL, 0);};
     272           0 : static void SetCfgNumberHmeSearchRegionInHeight (const char *value, EbConfig *cfg) {cfg->number_hme_search_region_in_height = strtoul(value, NULL, 0);};
     273           0 : static void SetCfgHmeLevel0TotalSearchAreaWidth (const char *value, EbConfig *cfg) {cfg->hme_level0_total_search_area_width = strtoul(value, NULL, 0);};
     274           0 : static void SetCfgHmeLevel0TotalSearchAreaHeight(const char *value, EbConfig *cfg) {cfg->hme_level0_total_search_area_height = strtoul(value, NULL, 0);};
     275           0 : static void SetCfgUseDefaultMeHme               (const char *value, EbConfig *cfg) {cfg->use_default_me_hme = (EbBool)strtol(value, NULL, 0); };
     276           0 : static void SetEnableExtBlockFlag(const char *value, EbConfig *cfg) { cfg->ext_block_flag = (EbBool)strtoul(value, NULL, 0); };
     277           0 : static void SetEnableInLoopMeFlag(const char *value, EbConfig *cfg) { cfg->in_loop_me_flag = (EbBool)strtoul(value, NULL, 0); };
     278           0 : static void SetHmeLevel0SearchAreaInWidthArray  (const char *value, EbConfig *cfg) {cfg->hme_level0_search_area_in_width_array[cfg->hme_level0_column_index++] = strtoul(value, NULL, 0);};
     279           0 : static void SetHmeLevel0SearchAreaInHeightArray (const char *value, EbConfig *cfg) {cfg->hme_level0_search_area_in_height_array[cfg->hme_level0_row_index++] = strtoul(value, NULL, 0);};
     280           0 : static void SetHmeLevel1SearchAreaInWidthArray  (const char *value, EbConfig *cfg) {cfg->hme_level1_search_area_in_width_array[cfg->hme_level1_column_index++] = strtoul(value, NULL, 0);};
     281           0 : static void SetHmeLevel1SearchAreaInHeightArray (const char *value, EbConfig *cfg) {cfg->hme_level1_search_area_in_height_array[cfg->hme_level1_row_index++] = strtoul(value, NULL, 0);};
     282           0 : static void SetHmeLevel2SearchAreaInWidthArray  (const char *value, EbConfig *cfg) {cfg->hme_level2_search_area_in_width_array[cfg->hme_level2_column_index++] = strtoul(value, NULL, 0);};
     283           0 : static void SetHmeLevel2SearchAreaInHeightArray (const char *value, EbConfig *cfg) {cfg->hme_level2_search_area_in_height_array[cfg->hme_level2_row_index++] = strtoul(value, NULL, 0);};
     284           0 : static void SetScreenContentMode                (const char *value, EbConfig *cfg) {cfg->screen_content_mode                                                 = strtoul(value, NULL, 0);};
     285             : // --- start: ALTREF_FILTERING_SUPPORT
     286           0 : static void SetEnableAltRefs                    (const char *value, EbConfig *cfg) {cfg->enable_altrefs = (EbBool)strtoul(value, NULL, 0);};
     287           0 : static void SetAltRefStrength                   (const char *value, EbConfig *cfg) {cfg->altref_strength = (uint8_t)strtoul(value, NULL, 0);};
     288           0 : static void SetAltRefNFrames                    (const char *value, EbConfig *cfg) {cfg->altref_nframes = (uint8_t)strtoul(value, NULL, 0);};
     289           0 : static void SetEnableOverlays                   (const char *value, EbConfig *cfg) { cfg->enable_overlays = (EbBool)strtoul(value, NULL, 0); };
     290             : // --- end: ALTREF_FILTERING_SUPPORT
     291           0 : static void SetEnableHBDModeDecision            (const char *value, EbConfig *cfg) {cfg->enable_hbd_mode_decision = (uint8_t)strtoul(value, NULL, 0);};
     292           0 : static void SetEnablePalette                    (const char *value, EbConfig *cfg) { cfg->enable_palette = (int32_t)strtoul(value, NULL, 0); };
     293           0 : static void SetEnableOlpdRefinement              (const char *value, EbConfig *cfg) { cfg->olpd_refinement = (int32_t)strtoul(value, NULL, 0); };
     294           0 : static void SetEnableConstrainedIntra           (const char *value, EbConfig *cfg) {cfg->constrained_intra                                             = (EbBool)strtoul(value, NULL, 0);};
     295           0 : static void SetHighDynamicRangeInput            (const char *value, EbConfig *cfg) {cfg->high_dynamic_range_input            = strtol(value,  NULL, 0);};
     296           0 : static void SetProfile                          (const char *value, EbConfig *cfg) {cfg->profile                          = strtol(value,  NULL, 0);};
     297           0 : static void SetTier                             (const char *value, EbConfig *cfg) {cfg->tier                             = strtol(value,  NULL, 0);};
     298           0 : static void SetLevel                            (const char *value, EbConfig *cfg) {
     299             : 
     300           0 :     if (strtoul( value, NULL,0) != 0 || EB_STRCMP(value, "0") == 0 )
     301           0 :         cfg->level = (uint32_t)(10*strtod(value,  NULL));
     302             :     else
     303           0 :         cfg->level = 9999999;
     304           0 : };
     305           0 : static void SetInjector                         (const char *value, EbConfig *cfg) {cfg->injector                         = strtol(value,  NULL, 0);};
     306           0 : static void SpeedControlFlag                    (const char *value, EbConfig *cfg) { cfg->speed_control_flag = strtol(value, NULL, 0); };
     307           0 : static void SetInjectorFrameRate                (const char *value, EbConfig *cfg) {
     308           0 :     cfg->injector_frame_rate = strtoul(value, NULL, 0);
     309           0 :     if (cfg->injector_frame_rate > 1000 )
     310           0 :         cfg->injector_frame_rate = cfg->injector_frame_rate;
     311             :     else
     312           0 :         cfg->injector_frame_rate = cfg->injector_frame_rate << 16;
     313           0 : }
     314           0 : static void SetLatencyMode                      (const char *value, EbConfig *cfg)  {cfg->latency_mode               = (uint8_t)strtol(value, NULL, 0);};
     315           0 : static void SetAsmType                          (const char *value, EbConfig *cfg)  {cfg->asm_type                   = (uint32_t)strtoul(value, NULL, 0);};
     316           0 : static void SetLogicalProcessors                (const char *value, EbConfig *cfg)  {cfg->logical_processors         = (uint32_t)strtoul(value, NULL, 0);};
     317           0 : static void SetTargetSocket                     (const char *value, EbConfig *cfg)  {cfg->target_socket              = (int32_t)strtol(value, NULL, 0);};
     318           0 : static void SetUnrestrictedMotionVector         (const char *value, EbConfig *cfg)  {cfg->unrestricted_motion_vector = (EbBool)strtol(value, NULL, 0);};
     319             : 
     320           0 : static void SetSquareWeight                     (const char *value, EbConfig *cfg)  {cfg->sq_weight                  = (uint64_t)strtoul(value, NULL, 0);
     321           0 :         if (cfg->sq_weight == 0)
     322           0 :             cfg->sq_weight = (uint32_t)~0;
     323           0 : }
     324             : 
     325           0 : static void SetMDS1_PRUNE_C_TH(const char *value, EbConfig *cfg) {
     326           0 :     cfg->md_stage_1_class_prune_th = (uint64_t)strtoul(value, NULL, 0);
     327           0 :     if (cfg->md_stage_1_class_prune_th == 0)
     328           0 :         cfg->md_stage_1_class_prune_th = (uint64_t)~0;
     329           0 : }
     330           0 : static void SetMDS1_PRUNE_S_TH(const char *value, EbConfig *cfg) {
     331           0 :     cfg->md_stage_1_cand_prune_th = (uint64_t)strtoul(value, NULL, 0);
     332           0 :     if (cfg->md_stage_1_cand_prune_th == 0)
     333           0 :         cfg->md_stage_1_cand_prune_th = (uint64_t)~0;
     334           0 : }
     335           0 : static void SetMDS2_PRUNE_C_TH(const char *value, EbConfig *cfg) {
     336           0 :     cfg->md_stage_2_class_prune_th = (uint64_t)strtoul(value, NULL, 0);
     337           0 :     if (cfg->md_stage_2_class_prune_th == 0)
     338           0 :         cfg->md_stage_2_class_prune_th = (uint64_t)~0;
     339           0 : }
     340           0 : static void SetMDS2_PRUNE_S_TH(const char *value, EbConfig *cfg) {
     341           0 :     cfg->md_stage_2_cand_prune_th = (uint64_t)strtoul(value, NULL, 0);
     342           0 :     if (cfg->md_stage_2_cand_prune_th == 0)
     343           0 :         cfg->md_stage_2_cand_prune_th = (uint64_t)~0;
     344           0 : }
     345             : 
     346             : enum cfg_type{
     347             :     SINGLE_INPUT,   // Configuration parameters that have only 1 value input
     348             :     ARRAY_INPUT     // Configuration parameters that have multiple values as input
     349             : };
     350             : 
     351             : /**********************************
     352             :  * Config Entry Struct
     353             :  **********************************/
     354             : typedef struct config_entry_s {
     355             :     enum  cfg_type type;
     356             :     const char *token;
     357             :     const char *name;
     358             :     void (*scf)(const char *, EbConfig *);
     359             : } config_entry_t;
     360             : 
     361             : /**********************************
     362             :  * Config Entry Array
     363             :  **********************************/
     364             : config_entry_t config_entry[] = {
     365             :     // File I/O
     366             :     { SINGLE_INPUT, INPUT_FILE_TOKEN, "InputFile", SetCfgInputFile },
     367             :     { SINGLE_INPUT, OUTPUT_BITSTREAM_TOKEN,   "StreamFile",       SetCfgStreamFile },
     368             :     { SINGLE_INPUT, ERROR_FILE_TOKEN, "ErrorFile", SetCfgErrorFile },
     369             :     { SINGLE_INPUT, OUTPUT_RECON_TOKEN, "ReconFile", SetCfgReconFile },
     370             :     { SINGLE_INPUT, QP_FILE_TOKEN, "QpFile", SetCfgQpFile },
     371             :     { SINGLE_INPUT, STAT_FILE_TOKEN, "StatFile", SetCfgStatFile },
     372             : #if TWO_PASS
     373             :     { SINGLE_INPUT, INPUT_STAT_FILE_TOKEN, "input_stat_file", set_input_stat_file },
     374             :     { SINGLE_INPUT, OUTPUT_STAT_FILE_TOKEN, "output_stat_file", set_output_stat_file },
     375             : #endif
     376             : 
     377             :     // Interlaced Video
     378             :     { SINGLE_INPUT, INTERLACED_VIDEO_TOKEN , "InterlacedVideo" , SetInterlacedVideo },
     379             :     { SINGLE_INPUT, SEPERATE_FILDS_TOKEN, "SeperateFields", SetSeperateFields },
     380             :     // Picture Dimensions
     381             :     { SINGLE_INPUT, WIDTH_TOKEN, "SourceWidth", SetCfgSourceWidth },
     382             :     { SINGLE_INPUT, HEIGHT_TOKEN, "SourceHeight", SetCfgSourceHeight },
     383             :     // Prediction Structure
     384             :     { SINGLE_INPUT, NUMBER_OF_PICTURES_TOKEN, "FrameToBeEncoded", SetCfgFramesToBeEncoded },
     385             :     { SINGLE_INPUT, BUFFERED_INPUT_TOKEN, "BufferedInput", SetBufferedInput },
     386             :     { SINGLE_INPUT, BASE_LAYER_SWITCH_MODE_TOKEN, "BaseLayerSwitchMode", SetBaseLayerSwitchMode },
     387             :     { SINGLE_INPUT, ENCMODE_TOKEN, "EncoderMode", SetencMode},
     388             : #if TWO_PASS_USE_2NDP_ME_IN_1STP
     389             :     { SINGLE_INPUT, ENCMODE2P_TOKEN, "EncoderMode2p", set_snd_pass_enc_mode},
     390             : #endif
     391             :     { SINGLE_INPUT, INTRA_PERIOD_TOKEN, "IntraPeriod", SetCfgIntraPeriod },
     392             :     { SINGLE_INPUT, INTRA_REFRESH_TYPE_TOKEN, "IntraRefreshType", SetCfgIntraRefreshType },
     393             :     { SINGLE_INPUT, FRAME_RATE_TOKEN, "FrameRate", SetFrameRate },
     394             :     { SINGLE_INPUT, FRAME_RATE_NUMERATOR_TOKEN, "FrameRateNumerator", SetFrameRateNumerator },
     395             :     { SINGLE_INPUT, FRAME_RATE_DENOMINATOR_TOKEN, "FrameRateDenominator", SetFrameRateDenominator },
     396             :     { SINGLE_INPUT, ENCODER_BIT_DEPTH, "EncoderBitDepth", SetEncoderBitDepth },
     397             :     { SINGLE_INPUT, ENCODER_COLOR_FORMAT, "EncoderColorFormat", SetEncoderColorFormat},
     398             :     { SINGLE_INPUT, INPUT_COMPRESSED_TEN_BIT_FORMAT, "CompressedTenBitFormat", SetcompressedTenBitFormat },
     399             :     { SINGLE_INPUT, HIERARCHICAL_LEVELS_TOKEN, "HierarchicalLevels", SetHierarchicalLevels },
     400             :     { SINGLE_INPUT, PRED_STRUCT_TOKEN, "PredStructure", SetCfgPredStructure },
     401             :      { SINGLE_INPUT, TILE_ROW_TOKEN, "TileRow", SetTileRow},
     402             :      { SINGLE_INPUT, TILE_COL_TOKEN, "TileCol", SetTileCol},
     403             :     // Rate Control
     404             :     { SINGLE_INPUT, SCENE_CHANGE_DETECTION_TOKEN, "SceneChangeDetection", SetSceneChangeDetection},
     405             :     { SINGLE_INPUT, QP_TOKEN, "QP", SetCfgQp },
     406             :     { SINGLE_INPUT, USE_QP_FILE_TOKEN, "UseQpFile", SetCfgUseQpFile },
     407             :     { SINGLE_INPUT, STAT_REPORT_TOKEN, "StatReport", SetStatReport },
     408             :     { SINGLE_INPUT, RATE_CONTROL_ENABLE_TOKEN, "RateControlMode", SetRateControlMode },
     409             :     { SINGLE_INPUT, LOOK_AHEAD_DIST_TOKEN, "LookAheadDistance",                             SetLookAheadDistance},
     410             :     { SINGLE_INPUT, TARGET_BIT_RATE_TOKEN, "TargetBitRate", SetTargetBitRate },
     411             :     { SINGLE_INPUT, MAX_QP_TOKEN, "MaxQpAllowed", SetMaxQpAllowed },
     412             :     { SINGLE_INPUT, MIN_QP_TOKEN, "MinQpAllowed", SetMinQpAllowed },
     413             :     { SINGLE_INPUT, ADAPTIVE_QP_ENABLE_TOKEN, "AdaptiveQuantization", SetAdaptiveQuantization },
     414             : 
     415             :     // DLF
     416             :     { SINGLE_INPUT, LOOP_FILTER_DISABLE_TOKEN, "LoopFilterDisable", SetDisableDlfFlag },
     417             :     // LOCAL WARPED MOTION
     418             :     { SINGLE_INPUT, LOCAL_WARPED_ENABLE_TOKEN, "LocalWarpedMotion", SetEnableLocalWarpedMotionFlag },
     419             :     // GLOBAL MOTION
     420             :     { SINGLE_INPUT, GLOBAL_MOTION_ENABLE_TOKEN, "GlobalMotion", SetEnableGlobalMotionFlag },
     421             :     // OBMC
     422             :     { SINGLE_INPUT, OBMC_TOKEN, "Obmc", SetEnableObmcFlag },
     423             :     // RDOQ
     424             :     { SINGLE_INPUT, RDOQ_TOKEN, "RDOQ", SetEnableRdoqFlag },
     425             :     // Filter Intra
     426             :     { SINGLE_INPUT, FILTER_INTRA_TOKEN, "FilterIntra", SetEnableFilterIntraFlag },
     427             :     // ME Tools
     428             :     { SINGLE_INPUT, USE_DEFAULT_ME_HME_TOKEN, "UseDefaultMeHme", SetCfgUseDefaultMeHme },
     429             :     { SINGLE_INPUT, HME_ENABLE_TOKEN, "HME", SetEnableHmeFlag },
     430             :     { SINGLE_INPUT, HME_L0_ENABLE_TOKEN, "HMELevel0", SetEnableHmeLevel0Flag },
     431             :     { SINGLE_INPUT, HME_L1_ENABLE_TOKEN, "HMELevel1", SetEnableHmeLevel1Flag },
     432             :     { SINGLE_INPUT, HME_L2_ENABLE_TOKEN, "HMELevel2", SetEnableHmeLevel2Flag },
     433             :     { SINGLE_INPUT, EXT_BLOCK, "ExtBlockFlag", SetEnableExtBlockFlag },
     434             :     { SINGLE_INPUT, IN_LOOP_ME, "InLoopMeFlag", SetEnableInLoopMeFlag },
     435             :     // ME Parameters
     436             :     { SINGLE_INPUT, SEARCH_AREA_WIDTH_TOKEN, "SearchAreaWidth", SetCfgSearchAreaWidth },
     437             :     { SINGLE_INPUT, SEARCH_AREA_HEIGHT_TOKEN, "SearchAreaHeight", SetCfgSearchAreaHeight },
     438             :     // HME Parameters
     439             :     { SINGLE_INPUT, NUM_HME_SEARCH_WIDTH_TOKEN, "NumberHmeSearchRegionInWidth", SetCfgNumberHmeSearchRegionInWidth },
     440             :     { SINGLE_INPUT, NUM_HME_SEARCH_HEIGHT_TOKEN, "NumberHmeSearchRegionInHeight", SetCfgNumberHmeSearchRegionInHeight },
     441             :     { SINGLE_INPUT, HME_SRCH_T_L0_WIDTH_TOKEN, "HmeLevel0TotalSearchAreaWidth", SetCfgHmeLevel0TotalSearchAreaWidth },
     442             :     { SINGLE_INPUT, HME_SRCH_T_L0_HEIGHT_TOKEN, "HmeLevel0TotalSearchAreaHeight", SetCfgHmeLevel0TotalSearchAreaHeight },
     443             :     // MD Parameters
     444             :     { SINGLE_INPUT, SCREEN_CONTENT_TOKEN, "ScreenContentMode", SetScreenContentMode},
     445             :     { SINGLE_INPUT, HBD_MD_ENABLE_TOKEN, "HighBitDepthModeDecision", SetEnableHBDModeDecision },
     446             :     { SINGLE_INPUT, PALETTE_TOKEN, "PaletteMode", SetEnablePalette },
     447             :     { SINGLE_INPUT, OLPD_REFINEMENT_TOKEN, "OlpdRefinement", SetEnableOlpdRefinement },
     448             :     { SINGLE_INPUT, CONSTRAINED_INTRA_ENABLE_TOKEN, "ConstrainedIntra", SetEnableConstrainedIntra},
     449             :     // Thread Management
     450             :     { SINGLE_INPUT, THREAD_MGMNT, "logicalProcessors", SetLogicalProcessors },
     451             :     { SINGLE_INPUT, TARGET_SOCKET, "TargetSocket", SetTargetSocket },
     452             :     // Optional Features
     453             :     { SINGLE_INPUT, UNRESTRICTED_MOTION_VECTOR, "UnrestrictedMotionVector", SetUnrestrictedMotionVector },
     454             : 
     455             : //    { SINGLE_INPUT, BITRATE_REDUCTION_TOKEN, "bit_rate_reduction", SetBitRateReduction },
     456             :     { SINGLE_INPUT, HDR_INPUT_TOKEN, "HighDynamicRangeInput", SetHighDynamicRangeInput },
     457             :     // Latency
     458             :     { SINGLE_INPUT, INJECTOR_TOKEN, "Injector", SetInjector },
     459             :     { SINGLE_INPUT, INJECTOR_FRAMERATE_TOKEN, "InjectorFrameRate", SetInjectorFrameRate },
     460             :     { SINGLE_INPUT, SPEED_CONTROL_TOKEN, "SpeedControlFlag", SpeedControlFlag },
     461             :     // Annex A parameters
     462             :     { SINGLE_INPUT, PROFILE_TOKEN, "Profile", SetProfile },
     463             :     { SINGLE_INPUT, TIER_TOKEN, "Tier", SetTier },
     464             :     { SINGLE_INPUT, LEVEL_TOKEN, "Level", SetLevel },
     465             :     { SINGLE_INPUT, LATENCY_MODE, "LatencyMode", SetLatencyMode },
     466             :     { SINGLE_INPUT, FILM_GRAIN_TOKEN, "FilmGrain", SetCfgFilmGrain },
     467             :     // Asm Type
     468             :     { SINGLE_INPUT, ASM_TYPE_TOKEN, "AsmType", SetAsmType },
     469             :     // HME
     470             :     { ARRAY_INPUT,HME_LEVEL0_WIDTH, "HmeLevel0SearchAreaInWidth", SetHmeLevel0SearchAreaInWidthArray },
     471             :     { ARRAY_INPUT,HME_LEVEL0_HEIGHT, "HmeLevel0SearchAreaInHeight", SetHmeLevel0SearchAreaInHeightArray },
     472             :     { ARRAY_INPUT,HME_LEVEL1_WIDTH, "HmeLevel1SearchAreaInWidth", SetHmeLevel1SearchAreaInWidthArray },
     473             :     { ARRAY_INPUT,HME_LEVEL1_HEIGHT, "HmeLevel1SearchAreaInHeight", SetHmeLevel1SearchAreaInHeightArray },
     474             :     { ARRAY_INPUT,HME_LEVEL2_WIDTH, "HmeLevel2SearchAreaInWidth", SetHmeLevel2SearchAreaInWidthArray },
     475             :     { ARRAY_INPUT,HME_LEVEL2_HEIGHT, "HmeLevel2SearchAreaInHeight", SetHmeLevel2SearchAreaInHeightArray },
     476             :     // --- start: ALTREF_FILTERING_SUPPORT
     477             :     { SINGLE_INPUT, ENABLE_ALTREFS, "EnableAltRefs", SetEnableAltRefs },
     478             :     { SINGLE_INPUT, ALTREF_STRENGTH, "AltRefStrength", SetAltRefStrength },
     479             :     { SINGLE_INPUT, ALTREF_NFRAMES, "AltRefNframes", SetAltRefNFrames },
     480             :     { SINGLE_INPUT, ENABLE_OVERLAYS, "EnableOverlays", SetEnableOverlays },
     481             :     // --- end: ALTREF_FILTERING_SUPPORT
     482             : 
     483             :     { SINGLE_INPUT, SQ_WEIGHT_TOKEN, "SquareWeight", SetSquareWeight },
     484             : 
     485             :     { SINGLE_INPUT, MDS1_PRUNE_C_TH, "MDStage1PruneClassThreshold", SetMDS1_PRUNE_C_TH },
     486             :     { SINGLE_INPUT, MDS1_PRUNE_S_TH, "MDStage1PruneCandThreshold", SetMDS1_PRUNE_S_TH },
     487             :     { SINGLE_INPUT, MDS2_PRUNE_C_TH, "MDStage2PruneClassThreshold", SetMDS2_PRUNE_C_TH },
     488             :     { SINGLE_INPUT, MDS2_PRUNE_S_TH, "MDStage2PruneCandThreshold", SetMDS2_PRUNE_S_TH },
     489             : 
     490             :     // Termination
     491             :     {SINGLE_INPUT,NULL,  NULL,                                NULL}
     492             : };
     493             : 
     494             : /**********************************
     495             :  * Constructor
     496             :  **********************************/
     497           2 : void eb_config_ctor(EbConfig *config_ptr)
     498             : {
     499           2 :     memset(config_ptr, 0, sizeof(*config_ptr));
     500           2 :     config_ptr->error_log_file                         = stderr;
     501           2 :     config_ptr->frame_rate                            = 30 << 16;
     502           2 :     config_ptr->encoder_bit_depth                      = 8;
     503           2 :     config_ptr->encoder_color_format                   = 1; //EB_YUV420
     504           2 :     config_ptr->buffered_input                        = -1;
     505             : 
     506           2 :     config_ptr->qp                                   = 50;
     507           2 :     config_ptr->use_qp_file                          = EB_FALSE;
     508           2 :     config_ptr->look_ahead_distance                  = (uint32_t)~0;
     509           2 :     config_ptr->target_bit_rate                        = 7000000;
     510           2 :     config_ptr->max_qp_allowed                       = 63;
     511           2 :     config_ptr->min_qp_allowed                       = 10;
     512             : 
     513           2 :     config_ptr->enable_adaptive_quantization         = 2;
     514           2 :     config_ptr->enc_mode                              = MAX_ENC_PRESET;
     515             : #if TWO_PASS_USE_2NDP_ME_IN_1STP
     516           2 :     config_ptr->snd_pass_enc_mode                     = MAX_ENC_PRESET + 1;
     517             : #endif
     518           2 :     config_ptr->intra_period                          = -2;
     519           2 :     config_ptr->intra_refresh_type                     = 1;
     520           2 :     config_ptr->hierarchical_levels                   = 4;
     521           2 :     config_ptr->pred_structure                        = 2;
     522           2 :     config_ptr->enable_global_motion                 = EB_TRUE;
     523           2 :     config_ptr->enable_obmc                          = EB_TRUE;
     524           2 :     config_ptr->enable_rdoq                          = -1;
     525           2 :     config_ptr->enable_filter_intra                  = EB_TRUE;
     526           2 :     config_ptr->in_loop_me_flag                      = EB_TRUE;
     527           2 :     config_ptr->use_default_me_hme                   = EB_TRUE;
     528           2 :     config_ptr->enable_hme_flag                        = EB_TRUE;
     529           2 :     config_ptr->enable_hme_level0_flag                  = EB_TRUE;
     530           2 :     config_ptr->search_area_width                      = 16;
     531           2 :     config_ptr->search_area_height                     = 7;
     532           2 :     config_ptr->number_hme_search_region_in_width         = 2;
     533           2 :     config_ptr->number_hme_search_region_in_height        = 2;
     534           2 :     config_ptr->hme_level0_total_search_area_width        = 64;
     535           2 :     config_ptr->hme_level0_total_search_area_height       = 25;
     536           2 :     config_ptr->hme_level0_search_area_in_width_array[0]   = 32;
     537           2 :     config_ptr->hme_level0_search_area_in_width_array[1]   = 32;
     538           2 :     config_ptr->hme_level0_search_area_in_height_array[0]  = 12;
     539           2 :     config_ptr->hme_level0_search_area_in_height_array[1]  = 13;
     540           2 :     config_ptr->hme_level1_search_area_in_width_array[0]   = 1;
     541           2 :     config_ptr->hme_level1_search_area_in_width_array[1]   = 1;
     542           2 :     config_ptr->hme_level1_search_area_in_height_array[0]  = 1;
     543           2 :     config_ptr->hme_level1_search_area_in_height_array[1]  = 1;
     544           2 :     config_ptr->hme_level2_search_area_in_width_array[0]   = 1;
     545           2 :     config_ptr->hme_level2_search_area_in_width_array[1]   = 1;
     546           2 :     config_ptr->hme_level2_search_area_in_height_array[0]  = 1;
     547           2 :     config_ptr->hme_level2_search_area_in_height_array[1]  = 1;
     548           2 :     config_ptr->screen_content_mode                  = 2;
     549           2 :     config_ptr->enable_hbd_mode_decision             = 1;
     550           2 :     config_ptr->enable_palette                       = -1;
     551           2 :     config_ptr->olpd_refinement                      = -1;
     552           2 :     config_ptr->injector_frame_rate                    = 60 << 16;
     553             : 
     554             :     // ASM Type
     555           2 :     config_ptr->asm_type                              = 1;
     556             : 
     557           2 :     config_ptr->target_socket                         = -1;
     558             : 
     559           2 :     config_ptr->unrestricted_motion_vector           = EB_TRUE;
     560             : 
     561             :     // --- start: ALTREF_FILTERING_SUPPORT
     562           2 :     config_ptr->enable_altrefs                       = EB_TRUE;
     563           2 :     config_ptr->altref_strength                      = 5;
     564           2 :     config_ptr->altref_nframes                       = 7;
     565             :     // --- end: ALTREF_FILTERING_SUPPORT
     566             : 
     567           2 :     config_ptr->sq_weight                            = 100;
     568             : 
     569           2 :     config_ptr->md_stage_1_cand_prune_th                = 75;
     570           2 :     config_ptr->md_stage_1_class_prune_th                = 100;
     571           2 :     config_ptr->md_stage_2_cand_prune_th                = 15;
     572           2 :     config_ptr->md_stage_2_class_prune_th                = 25;
     573             : 
     574           2 :     return;
     575             : }
     576             : 
     577             : /**********************************
     578             :  * Destructor
     579             :  **********************************/
     580           2 : void eb_config_dtor(EbConfig *config_ptr)
     581             : {
     582             :     // Close any files that are open
     583           2 :     if (config_ptr->config_file) {
     584           0 :         fclose(config_ptr->config_file);
     585           0 :         config_ptr->config_file = (FILE *) NULL;
     586             :     }
     587             : 
     588           2 :     if (config_ptr->input_file) {
     589           2 :         if (!config_ptr->input_file_is_fifo)
     590           2 :             fclose(config_ptr->input_file);
     591           2 :         config_ptr->input_file = (FILE *) NULL;
     592             :     }
     593             : 
     594           2 :     if (config_ptr->bitstream_file) {
     595           2 :         fclose(config_ptr->bitstream_file);
     596           2 :         config_ptr->bitstream_file = (FILE *) NULL;
     597             :     }
     598             : 
     599           2 :     if (config_ptr->recon_file) {
     600           0 :         fclose(config_ptr->recon_file);
     601           0 :         config_ptr->recon_file = (FILE *)NULL;
     602             :     }
     603             : 
     604           2 :     if (config_ptr->error_log_file) {
     605           2 :         fclose(config_ptr->error_log_file);
     606           2 :         config_ptr->error_log_file = (FILE *) NULL;
     607             :     }
     608             : 
     609           2 :     if (config_ptr->qp_file) {
     610           0 :         fclose(config_ptr->qp_file);
     611           0 :         config_ptr->qp_file = (FILE *)NULL;
     612             :     }
     613             : 
     614           2 :     if (config_ptr->stat_file) {
     615           0 :         fclose(config_ptr->stat_file);
     616           0 :         config_ptr->stat_file = (FILE *) NULL;
     617             :     }
     618             : #if TWO_PASS
     619           2 :     if (config_ptr->input_stat_file) {
     620           0 :         fclose(config_ptr->input_stat_file);
     621           0 :         config_ptr->input_stat_file = (FILE *)NULL;
     622             :     }
     623           2 :     if (config_ptr->output_stat_file) {
     624           0 :         fclose(config_ptr->output_stat_file);
     625           0 :         config_ptr->output_stat_file = (FILE *)NULL;
     626             :     }
     627             : #endif
     628           2 :     return;
     629             : }
     630             : 
     631             : /**********************************
     632             :  * File Size
     633             :  **********************************/
     634           0 : static int32_t findFileSize(
     635             :     FILE * const pFile)
     636             : {
     637             :     int32_t fileSize;
     638             : 
     639           0 :     fseek(pFile, 0, SEEK_END);
     640           0 :     fileSize = ftell(pFile);
     641           0 :     rewind(pFile);
     642             : 
     643           0 :     return fileSize;
     644             : }
     645             : 
     646             : /**********************************
     647             :  * Line Split
     648             :  **********************************/
     649           0 : static void lineSplit(
     650             :     uint32_t       *argc,
     651             :     char           *argv  [CONFIG_FILE_MAX_ARG_COUNT],
     652             :     uint32_t        argLen[CONFIG_FILE_MAX_ARG_COUNT],
     653             :     char           *linePtr)
     654             : {
     655           0 :     uint32_t i=0;
     656           0 :     *argc = 0;
     657             : 
     658           0 :     while((*linePtr != CONFIG_FILE_NEWLINE_CHAR) &&
     659           0 :             (*linePtr != CONFIG_FILE_RETURN_CHAR) &&
     660           0 :             (*linePtr != CONFIG_FILE_COMMENT_CHAR) &&
     661           0 :             (*argc < CONFIG_FILE_MAX_ARG_COUNT)) {
     662             :         // Increment past whitespace
     663           0 :         while((*linePtr == CONFIG_FILE_SPACE_CHAR || *linePtr == CONFIG_FILE_TAB_CHAR) && (*linePtr != CONFIG_FILE_NEWLINE_CHAR))
     664           0 :             ++linePtr;
     665             :         // Set arg
     666           0 :         if ((*linePtr != CONFIG_FILE_NEWLINE_CHAR) &&
     667           0 :                 (*linePtr != CONFIG_FILE_RETURN_CHAR) &&
     668           0 :                 (*linePtr != CONFIG_FILE_COMMENT_CHAR) &&
     669           0 :                 (*argc < CONFIG_FILE_MAX_ARG_COUNT)) {
     670           0 :             argv[*argc] = linePtr;
     671             : 
     672             :             // Increment to next whitespace
     673           0 :             while(*linePtr != CONFIG_FILE_SPACE_CHAR &&
     674           0 :                     *linePtr != CONFIG_FILE_TAB_CHAR &&
     675           0 :                     *linePtr != CONFIG_FILE_NEWLINE_CHAR &&
     676           0 :                     *linePtr != CONFIG_FILE_RETURN_CHAR) {
     677           0 :                 ++linePtr;
     678           0 :                 ++i;
     679             :             }
     680             : 
     681             :             // Set arg length
     682           0 :             argLen[(*argc)++] = i;
     683             : 
     684           0 :             i=0;
     685             :         }
     686             :     }
     687             : 
     688           0 :     return;
     689             : }
     690             : 
     691             : /**********************************
     692             : * Set Config value
     693             : **********************************/
     694           0 : static void SetConfigValue(EbConfig *config, const char *name,
     695             :                            const char *value) {
     696           0 :     int32_t i=0;
     697             : 
     698           0 :     while(config_entry[i].name != NULL) {
     699           0 :         if(EB_STRCMP(config_entry[i].name, name) == 0)
     700           0 :             (*config_entry[i].scf)((const char *) value, config);
     701           0 :         ++i;
     702             :     }
     703             : 
     704           0 :     return;
     705             : }
     706             : 
     707             : /**********************************
     708             : * Parse Config File
     709             : **********************************/
     710           0 : static void ParseConfigFile(
     711             :     EbConfig *config,
     712             :     char       *buffer,
     713             :     int32_t         size)
     714             : {
     715             :     uint32_t argc;
     716             :     char *argv[CONFIG_FILE_MAX_ARG_COUNT];
     717             :     uint32_t argLen[CONFIG_FILE_MAX_ARG_COUNT];
     718             : 
     719             :     char varName[CONFIG_FILE_MAX_VAR_LEN];
     720             :     char varValue[CONFIG_FILE_MAX_ARG_COUNT][CONFIG_FILE_MAX_VAR_LEN];
     721             : 
     722             :     uint32_t valueIndex;
     723             : 
     724           0 :     uint32_t commentSectionFlag = 0;
     725           0 :     uint32_t newLineFlag = 0;
     726             : 
     727             :     // Keep looping until we process the entire file
     728           0 :     while(size--) {
     729           0 :         commentSectionFlag = ((*buffer == CONFIG_FILE_COMMENT_CHAR) || (commentSectionFlag != 0)) ? 1 : commentSectionFlag;
     730             : 
     731             :         // At the beginning of each line
     732           0 :         if ((newLineFlag == 1) && (commentSectionFlag == 0)) {
     733             :             // Do an argc/argv split for the line
     734           0 :             lineSplit(&argc, argv, argLen, buffer);
     735             : 
     736           0 :             if ((argc > 2) && (*argv[1] == CONFIG_FILE_VALUE_SPLIT)) {
     737             :                 // ***NOTE - We're assuming that the variable name is the first arg and
     738             :                 // the variable value is the third arg.
     739             : 
     740             :                 // Cap the length of the variable name
     741           0 :                 argLen[0] = (argLen[0] > CONFIG_FILE_MAX_VAR_LEN - 1) ? CONFIG_FILE_MAX_VAR_LEN - 1 : argLen[0];
     742             :                 // Copy the variable name
     743           0 :                 EB_STRNCPY(varName, CONFIG_FILE_MAX_VAR_LEN, argv[0], argLen[0]);
     744             :                 // Null terminate the variable name
     745           0 :                 varName[argLen[0]] = CONFIG_FILE_NULL_CHAR;
     746             : 
     747           0 :                 for(valueIndex=0; (valueIndex < CONFIG_FILE_MAX_ARG_COUNT - 2) && (valueIndex < (argc - 2)); ++valueIndex) {
     748             :                     // Cap the length of the variable
     749           0 :                     argLen[valueIndex+2] = (argLen[valueIndex+2] > CONFIG_FILE_MAX_VAR_LEN - 1) ? CONFIG_FILE_MAX_VAR_LEN - 1 : argLen[valueIndex+2];
     750             :                     // Copy the variable name
     751           0 :                     EB_STRNCPY(varValue[valueIndex], CONFIG_FILE_MAX_VAR_LEN, argv[valueIndex+2], argLen[valueIndex+2]);
     752             :                     // Null terminate the variable name
     753           0 :                     varValue[valueIndex][argLen[valueIndex+2]] = CONFIG_FILE_NULL_CHAR;
     754             : 
     755           0 :                     SetConfigValue(config, varName, varValue[valueIndex]);
     756             :                 }
     757             :             }
     758             :         }
     759             : 
     760           0 :         commentSectionFlag = (*buffer == CONFIG_FILE_NEWLINE_CHAR) ? 0 : commentSectionFlag;
     761           0 :         newLineFlag = (*buffer == CONFIG_FILE_NEWLINE_CHAR) ? 1 : 0;
     762           0 :         ++buffer;
     763             :     }
     764             : 
     765           0 :     return;
     766             : }
     767             : 
     768             : /******************************************
     769             : * Find Token
     770             : ******************************************/
     771           6 : static int32_t FindToken(
     772             :     int32_t         argc,
     773             :     char * const    argv[],
     774             :     char const *    token,
     775             :     char*           configStr)
     776             : {
     777           6 :     int32_t return_error = -1;
     778             : 
     779          60 :     while((argc > 0) && (return_error != 0)) {
     780          54 :         return_error = EB_STRCMP(argv[--argc], token);
     781          54 :         if (return_error == 0) {
     782           0 :             EB_STRCPY(configStr, COMMAND_LINE_MAX_SIZE, argv[argc + 1]);
     783             :         }
     784             :     }
     785             : 
     786           6 :     return return_error;
     787             : }
     788             : 
     789             : /**********************************
     790             : * Read Config File
     791             : **********************************/
     792           0 : static int32_t ReadConfigFile(
     793             :     EbConfig  *config,
     794             :     char        *configPath,
     795             :     uint32_t     instance_idx)
     796             : {
     797           0 :     int32_t return_error = 0;
     798             : 
     799             :     // Open the config file
     800           0 :     FOPEN(config->config_file, configPath, "rb");
     801             : 
     802           0 :     if (config->config_file != (FILE*) NULL) {
     803           0 :         int32_t configFileSize = findFileSize(config->config_file);
     804           0 :         char *configFileBuffer = (char*) malloc(configFileSize);
     805             : 
     806           0 :         if (configFileBuffer != (char *) NULL) {
     807           0 :             int32_t resultSize = (int32_t) fread(configFileBuffer, 1, configFileSize, config->config_file);
     808             : 
     809           0 :             if (resultSize == configFileSize) {
     810           0 :                 ParseConfigFile(config, configFileBuffer, configFileSize);
     811             :             } else {
     812           0 :                 printf("Error channel %u: File Read Failed\n",instance_idx+1);
     813           0 :                 return_error = -1;
     814             :             }
     815             :         } else {
     816           0 :             printf("Error channel %u: Memory Allocation Failed\n",instance_idx+1);
     817           0 :             return_error = -1;
     818             :         }
     819             : 
     820           0 :         free(configFileBuffer);
     821           0 :         fclose(config->config_file);
     822           0 :         config->config_file = (FILE*) NULL;
     823             :     } else {
     824           0 :         printf("Error channel %u: Couldn't open Config File: %s\n", instance_idx+1,configPath);
     825           0 :         return_error = -1;
     826             :     }
     827             : 
     828           0 :     return return_error;
     829             : }
     830             : 
     831             : /******************************************
     832             : * Verify Settings
     833             : ******************************************/
     834           2 : static EbErrorType VerifySettings(EbConfig *config, uint32_t channelNumber)
     835             : {
     836           2 :     EbErrorType return_error = EB_ErrorNone;
     837             : 
     838             :     // Check Input File
     839           2 :     if(config->input_file == (FILE*) NULL) {
     840           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid Input File\n",channelNumber+1);
     841           0 :         return_error = EB_ErrorBadParameter;
     842             :     }
     843             : 
     844           2 :     if (config->frames_to_be_encoded <= -1) {
     845           0 :         fprintf(config->error_log_file, "Error instance %u: FrameToBeEncoded must be greater than 0\n",channelNumber+1);
     846           0 :         return_error = EB_ErrorBadParameter;
     847             :     }
     848             : 
     849           2 :     if (config->buffered_input < -1) {
     850           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid buffered_input. buffered_input must greater or equal to -1\n", channelNumber + 1);
     851           0 :         return_error = EB_ErrorBadParameter;
     852             :     }
     853             : 
     854           2 :     if (config->buffered_input > config->frames_to_be_encoded) {
     855           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid buffered_input. buffered_input must be less or equal to the number of frames to be encoded\n",channelNumber+1);
     856           0 :         return_error = EB_ErrorBadParameter;
     857             :     }
     858             : 
     859           2 :     if (config->use_qp_file == EB_TRUE && config->qp_file == NULL) {
     860           0 :         fprintf(config->error_log_file, "Error instance %u: Could not find QP file, UseQpFile is set to 1\n", channelNumber + 1);
     861           0 :         return_error = EB_ErrorBadParameter;
     862             :     }
     863           2 :     if (config->separate_fields > 1) {
     864           0 :         fprintf(config->error_log_file, "Error Instance %u: Invalid SeperateFields Input\n", channelNumber + 1);
     865           0 :         return_error = EB_ErrorBadParameter;
     866             :     }
     867             : 
     868           2 :     if (config->encoder_bit_depth == 10 && config->separate_fields == 1)
     869             :     {
     870           0 :         fprintf(config->error_log_file, "Error instance %u: Separate fields is not supported for 10 bit input \n", channelNumber + 1);
     871           0 :         return_error = EB_ErrorBadParameter;
     872             :     }
     873             : 
     874           2 :     if (config->encoder_color_format != 1) {
     875           0 :         fprintf(config->error_log_file, "Error instance %u: Only support 420 now \n", channelNumber + 1);
     876           0 :         return_error = EB_ErrorBadParameter;
     877             :     }
     878           2 :     if (config->injector > 1 ){
     879           0 :         fprintf(config->error_log_file, "Error Instance %u: Invalid injector [0 - 1]\n",channelNumber+1);
     880           0 :         return_error = EB_ErrorBadParameter;
     881             :     }
     882             : 
     883           2 :     if(config->injector_frame_rate > (240<<16) && config->injector){
     884           0 :         fprintf(config->error_log_file, "Error Instance %u: The maximum allowed injector_frame_rate is 240 fps\n",channelNumber+1);
     885           0 :         return_error = EB_ErrorBadParameter;
     886             :     }
     887             :     // Check that the injector frame_rate is non-zero
     888           2 :     if(config->injector_frame_rate <= 0 && config->injector) {
     889           0 :         fprintf(config->error_log_file, "Error Instance %u: The injector frame rate should be greater than 0 fps \n",channelNumber+1);
     890           0 :         return_error = EB_ErrorBadParameter;
     891             :     }
     892             : 
     893             :     // target_socket
     894           2 :     if (config->target_socket != -1 && config->target_socket != 0 && config->target_socket != 1) {
     895           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid target_socket [-1 - 1], your input: %d\n", channelNumber + 1, config->target_socket);
     896           0 :         return_error = EB_ErrorBadParameter;
     897             :     }
     898             : 
     899             :     // Local Warped Motion
     900           2 :     if (config->enable_warped_motion != 0 && config->enable_warped_motion != 1) {
     901           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid warped motion flag [0 - 1], your input: %d\n", channelNumber + 1, config->target_socket);
     902           0 :         return_error = EB_ErrorBadParameter;
     903             :     }
     904             : 
     905             :     // Global Motion
     906           2 :     if (config->enable_global_motion != 0 && config->enable_global_motion != 1) {
     907           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid global motion flag [0 - 1], your input: %d\n", channelNumber + 1, config->target_socket);
     908           0 :         return_error = EB_ErrorBadParameter;
     909             :     }
     910             : 
     911             :     // OBMC
     912           2 :     if (config->enable_obmc != 0 && config->enable_obmc != 1) {
     913           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid OBMC flag [0 - 1], your input: %d\n", channelNumber + 1, config->target_socket);
     914           0 :         return_error = EB_ErrorBadParameter;
     915             :     }
     916             : 
     917             :     // Filter Intra prediction
     918           2 :     if (config->enable_filter_intra != 0 && config->enable_filter_intra != 1) {
     919           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid Filter Intra flag [0 - 1], your input: %d\n", channelNumber + 1, config->target_socket);
     920           0 :         return_error = EB_ErrorBadParameter;
     921             :     }
     922             : 
     923             :     // HBD mode decision
     924           2 :     if (config->enable_hbd_mode_decision != 0 && config->enable_hbd_mode_decision != 1 && config->enable_hbd_mode_decision != 2) {
     925           0 :         fprintf(config->error_log_file, "Error instance %u: Invalid HBD mode decision flag [0 - 2], your input: %d\n", channelNumber + 1, config->target_socket);
     926           0 :         return_error = EB_ErrorBadParameter;
     927             :     }
     928             : 
     929             : 
     930             : 
     931           2 :     return return_error;
     932             : }
     933             : 
     934             : /******************************************
     935             :  * Find Token for multiple inputs
     936             :  ******************************************/
     937         184 : int32_t FindTokenMultipleInputs(
     938             :     int32_t         argc,
     939             :     char* const     argv[],
     940             :     const char*     token,
     941             :     char**          configStr)
     942             : {
     943         184 :     int32_t return_error = -1;
     944         184 :     int32_t done = 0;
     945        1808 :     while((argc > 0) && (return_error != 0)) {
     946        1624 :         return_error = EB_STRCMP(argv[--argc], token);
     947        1624 :         if (return_error == 0) {
     948             :             int32_t count;
     949          56 :             for (count=0; count < MAX_CHANNEL_NUMBER  ; ++count){
     950          48 :                 if (done ==0){
     951          16 :                     if (argv[argc + count + 1] ){
     952          14 :                         if (strtoul(argv[argc + count + 1], NULL,0) != 0 || EB_STRCMP(argv[argc + count + 1], "0") == 0 ){
     953           4 :                             EB_STRCPY(configStr[count], COMMAND_LINE_MAX_SIZE, argv[argc + count + 1]);
     954          10 :                         }else if (argv[argc + count + 1][0] != '-'){
     955           4 :                             EB_STRCPY(configStr[count], COMMAND_LINE_MAX_SIZE, argv[argc + count + 1]);
     956             :                         }else {
     957           6 :                             EB_STRCPY(configStr[count], COMMAND_LINE_MAX_SIZE," ");
     958           6 :                             done = 1;
     959             :                         }
     960             :                     }else{
     961           2 :                         EB_STRCPY(configStr[count], COMMAND_LINE_MAX_SIZE, " ");
     962           2 :                         done =1;
     963             :                         //return return_error;
     964             :                     }
     965             :                 }else
     966          32 :                     EB_STRCPY(configStr[count], COMMAND_LINE_MAX_SIZE, " ");
     967             :             }
     968             :         }
     969             :     }
     970             : 
     971         184 :     return return_error;
     972             : }
     973             : 
     974           2 : uint32_t get_help(
     975             :     int32_t     argc,
     976             :     char *const argv[])
     977             : {
     978             :     char config_string[COMMAND_LINE_MAX_SIZE];
     979           2 :     if (FindToken(argc, argv, HELP_TOKEN, config_string) == 0) {
     980           0 :         int32_t token_index = -1;
     981             : 
     982           0 :         printf("\n%-25s\t%-25s\t%s\n\n" ,"TOKEN", "DESCRIPTION", "INPUT TYPE");
     983           0 :         printf("%-25s\t%-25s\t%s\n" ,"-nch", "NumberOfChannels", "Single input");
     984           0 :         while (config_entry[++token_index].token != NULL)
     985           0 :             printf("%-25s\t%-25s\t%s\n", config_entry[token_index].token, config_entry[token_index].name, config_entry[token_index].type ? "Array input": "Single input");
     986           0 :         return 1;
     987             :     }
     988             :     else
     989           2 :         return 0;
     990             : }
     991             : 
     992             : /******************************************************
     993             : * Get the number of channels and validate it with input
     994             : ******************************************************/
     995           2 : uint32_t get_number_of_channels(
     996             :     int32_t     argc,
     997             :     char *const argv[])
     998             : {
     999             :     char config_string[COMMAND_LINE_MAX_SIZE];
    1000             :     uint32_t channelNumber;
    1001           2 :     if (FindToken(argc, argv, CHANNEL_NUMBER_TOKEN, config_string) == 0) {
    1002             :         // Set the input file
    1003           0 :         channelNumber = strtol(config_string,  NULL, 0);
    1004           0 :         if ((channelNumber > (uint32_t) MAX_CHANNEL_NUMBER) || channelNumber == 0){
    1005           0 :             printf("Error: The number of channels has to be within the range [1,%u]\n",(uint32_t) MAX_CHANNEL_NUMBER);
    1006           0 :             return 0;
    1007             :         }else{
    1008           0 :             return channelNumber;
    1009             :         }
    1010             :     }
    1011           2 :     return 1;
    1012             : }
    1013             : 
    1014           8 : void mark_token_as_read(
    1015             :     const char  * token,
    1016             :     char        * cmd_copy[],
    1017             :     int32_t     * cmd_token_cnt
    1018             :     )
    1019             : {
    1020             :     int32_t cmd_copy_index;
    1021          22 :     for (cmd_copy_index = 0; cmd_copy_index < *(cmd_token_cnt); ++cmd_copy_index) {
    1022          14 :         if (!EB_STRCMP(cmd_copy[cmd_copy_index], token))
    1023           8 :             cmd_copy[cmd_copy_index] = cmd_copy[--(*cmd_token_cnt)];
    1024             :     }
    1025           8 : }
    1026             : 
    1027           8 : EbBool is_negative_number(
    1028             :     const char* string) {
    1029           8 :     int32_t length = (int32_t)strlen(string);
    1030           8 :     int32_t index = 0;
    1031           8 :     if (string[0] != '-') return EB_FALSE;
    1032           8 :     for (index = 1; index < length; index++)
    1033             :     {
    1034           8 :         if (string[index] < '0' || string[index] > '9')
    1035           8 :             return EB_FALSE;
    1036             :     }
    1037           0 :     return EB_TRUE;
    1038             : }
    1039             : 
    1040             : // Computes the number of frames in the input file
    1041           2 : int32_t ComputeFramesToBeEncoded(
    1042             :     EbConfig   *config)
    1043             : {
    1044           2 :     uint64_t fileSize   = 0;
    1045           2 :     int32_t  frame_count = 0;
    1046             :     uint32_t frameSize;
    1047             :     uint64_t currLoc;
    1048             : 
    1049           2 :     if (config->input_file) {
    1050           2 :         currLoc = ftello(config->input_file); // get current fp location
    1051           2 :         fseeko(config->input_file, 0L, SEEK_END);
    1052           2 :         fileSize = ftello(config->input_file);
    1053           2 :         fseeko(config->input_file, currLoc, SEEK_SET); // seek back to that location
    1054             :     }
    1055             : 
    1056           2 :     frameSize = config->input_padded_width * config->input_padded_height; // Luma
    1057           2 :     frameSize += 2 * (frameSize >> (3 - config->encoder_color_format)); // Add Chroma
    1058           2 :     frameSize = frameSize << ((config->encoder_bit_depth == 10) ? 1 : 0);
    1059             : 
    1060           2 :     if (frameSize == 0)
    1061           0 :         return -1;
    1062             : 
    1063           2 :     if (config->encoder_bit_depth == 10 && config->compressed_ten_bit_format == 1)
    1064           0 :         frame_count = (int32_t)(2 * ((double)fileSize / frameSize) / 1.25);
    1065             :     else
    1066           2 :         frame_count = (int32_t)(fileSize / frameSize);
    1067             : 
    1068           2 :     if (frame_count == 0)
    1069           0 :         return -1;
    1070             : 
    1071           2 :     return frame_count;
    1072             : }
    1073             : 
    1074             : /******************************************
    1075             : * Read Command Line
    1076             : ******************************************/
    1077           2 : EbErrorType read_command_line(
    1078             :     int32_t        argc,
    1079             :     char *const    argv[],
    1080             :     EbConfig   **configs,
    1081             :     uint32_t       num_channels,
    1082             :     EbErrorType  *return_errors)
    1083             : {
    1084           2 :     EbErrorType return_error = EB_ErrorBadParameter;
    1085             :     char            config_string[COMMAND_LINE_MAX_SIZE];        // for one input options
    1086             :     char           *config_strings[MAX_CHANNEL_NUMBER]; // for multiple input options
    1087             :     char           *cmd_copy[MAX_NUM_TOKENS];                 // keep track of extra tokens
    1088           2 :     uint32_t    index           = 0;
    1089           2 :     int32_t             cmd_token_cnt   = 0;                        // total number of tokens
    1090           2 :     int32_t             token_index     = -1;
    1091             :     int32_t ret_y4m;
    1092             : 
    1093          14 :     for (index = 0; index < MAX_CHANNEL_NUMBER; ++index)
    1094          12 :         config_strings[index] = (char*)malloc(sizeof(char)*COMMAND_LINE_MAX_SIZE);
    1095             :     // Copy tokens (except for CHANNEL_NUMBER_TOKEN ) into a temp token buffer hosting all tokens that are passed through the command line
    1096           2 :     size_t len = EB_STRLEN(CHANNEL_NUMBER_TOKEN, COMMAND_LINE_MAX_SIZE);
    1097          20 :     for (token_index = 0; token_index < argc; ++token_index) {
    1098          18 :         if ((argv[token_index][0] == '-') && strncmp(argv[token_index], CHANNEL_NUMBER_TOKEN, len) && !is_negative_number(argv[token_index]))
    1099           8 :                 cmd_copy[cmd_token_cnt++] = argv[token_index];
    1100             :     }
    1101             : 
    1102             :     /***************************************************************************************************/
    1103             :     /****************  Find configuration files tokens and call respective functions  ******************/
    1104             :     /***************************************************************************************************/
    1105             : 
    1106             :     // Find the Config File Path in the command line
    1107           2 :     if (FindTokenMultipleInputs(argc, argv, CONFIG_FILE_TOKEN, config_strings) == 0) {
    1108           0 :         mark_token_as_read(CONFIG_FILE_TOKEN, cmd_copy, &cmd_token_cnt);
    1109             :         // Parse the config file
    1110           0 :         for (index = 0; index < num_channels; ++index){
    1111           0 :             return_errors[index] = (EbErrorType)ReadConfigFile(configs[index], config_strings[index], index);
    1112           0 :             return_error = (EbErrorType)(return_error &  return_errors[index]);
    1113             :         }
    1114             :     }
    1115             :     else {
    1116           2 :         if (FindToken(argc, argv, CONFIG_FILE_TOKEN, config_string) == 0) {
    1117           0 :             printf("Error: Config File Token Not Found\n");
    1118           0 :             return EB_ErrorBadParameter;
    1119             :         }
    1120             :         else
    1121           2 :             return_error = EB_ErrorNone;
    1122             :     }
    1123             : 
    1124             :     /***************************************************************************************************/
    1125             :     /***********   Find SINGLE_INPUT configuration parameter tokens and call respective functions  **********/
    1126             :     /***************************************************************************************************/
    1127           2 :     token_index = -1;
    1128             :     // Parse command line for tokens
    1129         184 :     while (config_entry[++token_index].name != NULL){
    1130         182 :         if (config_entry[token_index].type == SINGLE_INPUT){
    1131         170 :             if (FindTokenMultipleInputs(argc, argv, config_entry[token_index].token, config_strings) == 0) {
    1132             :                 // When a token is found mark it as found in the temp token buffer
    1133           8 :                 mark_token_as_read(config_entry[token_index].token, cmd_copy, &cmd_token_cnt);
    1134             : 
    1135             :                 // Fill up the values corresponding to each channel
    1136          16 :                 for (index = 0; index < num_channels; ++index) {
    1137           8 :                     if (EB_STRCMP(config_strings[index], " "))
    1138           8 :                         (*config_entry[token_index].scf)(config_strings[index], configs[index]);
    1139             :                     else
    1140           0 :                         break;
    1141             :                 }
    1142             :             }
    1143             :         }
    1144             :     }
    1145             : 
    1146             :     /***************************************************************************************************/
    1147             :     /********************** Parse parameters from input file if in y4m format **************************/
    1148             :     /********************** overriding config file and command line inputs    **************************/
    1149             :     /***************************************************************************************************/
    1150             : 
    1151           4 :     for (index = 0; index < num_channels; ++index) {
    1152           2 :         if ((configs[index])->y4m_input == EB_TRUE){
    1153           2 :             ret_y4m = read_y4m_header(configs[index]);
    1154           2 :             if(ret_y4m == EB_ErrorBadParameter){
    1155           0 :                 printf("Error found when reading the y4m file parameters.\n");
    1156           0 :                 return EB_ErrorBadParameter;
    1157             :             }
    1158             :         }
    1159             :     }
    1160             : 
    1161             :     /***************************************************************************************************/
    1162             :     /***********   Find SPECIAL configuration parameter tokens and call respective functions  **********/
    1163             :     /***************************************************************************************************/
    1164             :     // Parse command line for search region at level 0 width token
    1165           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL0_WIDTH, config_strings) == 0) {
    1166           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1167           0 :         uint32_t done = 1;
    1168             : 
    1169           0 :         mark_token_as_read(HME_LEVEL0_WIDTH, cmd_copy, &cmd_token_cnt);
    1170             : 
    1171           0 :         for (index = 0; done && (index < num_channels); ++index){
    1172           0 :             configs[index]->hme_level0_column_index = 0;
    1173           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_width + lastIndex; ++inputIndex){
    1174           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1175           0 :                     SetHmeLevel0SearchAreaInWidthArray(config_strings[inputIndex], configs[index]);
    1176             :                 else{
    1177           0 :                     done = 0;
    1178           0 :                     break;
    1179             :                 }
    1180             :             }
    1181           0 :             lastIndex += configs[index]->number_hme_search_region_in_width;
    1182             :         }
    1183             :     }
    1184             : 
    1185             :     //// Parse command line for search region at level 0 height token
    1186           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL0_HEIGHT, config_strings) == 0) {
    1187           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1188           0 :         uint32_t done = 1;
    1189             : 
    1190           0 :         mark_token_as_read(HME_LEVEL0_HEIGHT, cmd_copy, &cmd_token_cnt);
    1191             : 
    1192           0 :         for (index = 0; done && (index < num_channels); ++index){
    1193           0 :             configs[index]->hme_level0_row_index = 0;
    1194           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_height + lastIndex; ++inputIndex){
    1195           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1196           0 :                     SetHmeLevel0SearchAreaInHeightArray(config_strings[inputIndex], configs[index]);
    1197             :                 else{
    1198           0 :                     done = 0;
    1199           0 :                     break;
    1200             :                 }
    1201             :             }
    1202           0 :             lastIndex += configs[index]->number_hme_search_region_in_height;
    1203             :         }
    1204             :     }
    1205             : 
    1206             :     // Parse command line for search region at level 1 Height token
    1207           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL1_HEIGHT, config_strings) == 0) {
    1208           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1209           0 :         uint32_t done = 1;
    1210             : 
    1211           0 :         mark_token_as_read(HME_LEVEL1_HEIGHT, cmd_copy, &cmd_token_cnt);
    1212             : 
    1213           0 :         for (index = 0; done && (index < num_channels); ++index){
    1214           0 :             configs[index]->hme_level1_row_index = 0;
    1215           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_height + lastIndex; ++inputIndex){
    1216           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1217           0 :                     SetHmeLevel1SearchAreaInHeightArray(config_strings[inputIndex], configs[index]);
    1218             :                 else{
    1219           0 :                     done = 0;
    1220           0 :                     break;
    1221             :                 }
    1222             :             }
    1223           0 :             lastIndex += configs[index]->number_hme_search_region_in_height;
    1224             :         }
    1225             :     }
    1226             : 
    1227             :     // Parse command line for search region at level 1 width token
    1228           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL1_WIDTH, config_strings) == 0) {
    1229           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1230           0 :         uint32_t done = 1;
    1231             : 
    1232           0 :         mark_token_as_read(HME_LEVEL1_WIDTH, cmd_copy, &cmd_token_cnt);
    1233             : 
    1234           0 :         for (index = 0; done && (index < num_channels); ++index){
    1235           0 :             configs[index]->hme_level1_column_index = 0;
    1236           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_width + lastIndex; ++inputIndex){
    1237           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1238           0 :                     SetHmeLevel1SearchAreaInWidthArray(config_strings[inputIndex], configs[index]);
    1239             :                 else{
    1240           0 :                     done = 0;
    1241           0 :                     break;
    1242             :                 }
    1243             :             }
    1244           0 :             lastIndex += configs[index]->number_hme_search_region_in_width;
    1245             :         }
    1246             :     }
    1247             : 
    1248             :     // Parse command line for search region at level 2 width token
    1249           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL2_WIDTH, config_strings) == 0) {
    1250           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1251           0 :         uint32_t done = 1;
    1252             : 
    1253           0 :         mark_token_as_read(HME_LEVEL2_WIDTH, cmd_copy, &cmd_token_cnt);
    1254             : 
    1255           0 :         for (index = 0; done && (index < num_channels); ++index){
    1256           0 :             configs[index]->hme_level2_column_index = 0;
    1257           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_width + lastIndex; ++inputIndex){
    1258           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1259           0 :                     SetHmeLevel2SearchAreaInWidthArray(config_strings[inputIndex], configs[index]);
    1260             :                 else{
    1261           0 :                     done = 0;
    1262           0 :                     break;
    1263             :                 }
    1264             :             }
    1265           0 :             lastIndex += configs[index]->number_hme_search_region_in_width;
    1266             :         }
    1267             :     }
    1268             : 
    1269             :     // Parse command line for search region at level 2 height token
    1270           2 :     if (FindTokenMultipleInputs(argc, argv, HME_LEVEL2_HEIGHT, config_strings) == 0) {
    1271           0 :         uint32_t inputIndex = 0, lastIndex = 0;
    1272           0 :         uint32_t done = 1;
    1273             : 
    1274           0 :         mark_token_as_read(HME_LEVEL2_HEIGHT, cmd_copy, &cmd_token_cnt);
    1275             : 
    1276           0 :         for (index = 0; done && (index < num_channels); ++index){
    1277           0 :             configs[index]->hme_level2_row_index = 0;
    1278           0 :             for (inputIndex = lastIndex; inputIndex < configs[index]->number_hme_search_region_in_height + lastIndex; ++inputIndex){
    1279           0 :                 if (EB_STRCMP(config_strings[inputIndex], " "))
    1280           0 :                     SetHmeLevel2SearchAreaInHeightArray(config_strings[inputIndex], configs[index]);
    1281             :                 else{
    1282           0 :                     done = 0;
    1283           0 :                     break;
    1284             :                 }
    1285             :             }
    1286           0 :             lastIndex += configs[index]->number_hme_search_region_in_height;
    1287             :         }
    1288             :     }
    1289             : 
    1290             :     /***************************************************************************************************/
    1291             :     /**************************************   Verify configuration parameters   ************************/
    1292             :     /***************************************************************************************************/
    1293             :     // Verify the config values
    1294           2 :     if (return_error == 0) {
    1295           2 :         return_error = EB_ErrorBadParameter;
    1296           4 :         for (index = 0; index < num_channels; ++index){
    1297           2 :             if (return_errors[index] == EB_ErrorNone){
    1298           2 :                 return_errors[index] = VerifySettings(configs[index], index);
    1299             : 
    1300             :                 // Assuming no errors, add padding to width and height
    1301           2 :                 if (return_errors[index] == EB_ErrorNone) {
    1302           2 :                     configs[index]->input_padded_width = configs[index]->source_width + configs[index]->source_width % 8;
    1303           2 :                     configs[index]->input_padded_height = configs[index]->source_height + configs[index]->source_width % 8;
    1304             :                 }
    1305             : 
    1306             :                 // Assuming no errors, set the frames to be encoded to the number of frames in the input yuv
    1307           2 :                 if (return_errors[index] == EB_ErrorNone && configs[index]->frames_to_be_encoded == 0)
    1308           2 :                     configs[index]->frames_to_be_encoded = ComputeFramesToBeEncoded(configs[index]);
    1309             : 
    1310           2 :                 if (configs[index]->frames_to_be_encoded == -1) {
    1311           0 :                     fprintf(configs[index]->error_log_file, "Error instance %u: Input yuv does not contain enough frames \n", index + 1);
    1312           0 :                     return_errors[index] = EB_ErrorBadParameter;
    1313             :                 }
    1314             : 
    1315             :                 // Force the injector latency mode, and injector frame rate when speed control is on
    1316           2 :                 if (return_errors[index] == EB_ErrorNone && configs[index]->speed_control_flag == 1)
    1317           0 :                     configs[index]->injector    = 1;
    1318             :             }
    1319           2 :             return_error = (EbErrorType)(return_error & return_errors[index]);
    1320             :         }
    1321             :     }
    1322             : 
    1323             :     // Print message for unprocessed tokens
    1324           2 :     if (cmd_token_cnt > 0) {
    1325             :         int32_t cmd_copy_index;
    1326           0 :         printf("Unprocessed tokens: ");
    1327           0 :         for (cmd_copy_index = 0; cmd_copy_index < cmd_token_cnt; ++cmd_copy_index)
    1328           0 :             printf(" %s ", cmd_copy[cmd_copy_index]);
    1329           0 :         printf("\n\n");
    1330           0 :         return_error = EB_ErrorBadParameter;
    1331             :     }
    1332             : 
    1333          14 :     for (index = 0; index < MAX_CHANNEL_NUMBER; ++index)
    1334          12 :         free(config_strings[index]);
    1335           2 :     return return_error;
    1336             : }

Generated by: LCOV version 1.14