Commit 03ca34de authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

distinguish mandatory and optional parameters

parent c9e198ea
Loading
Loading
Loading
Loading
+20 −8
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@
 *------------------------------------------------------------------------------------------*/
 *------------------------------------------------------------------------------------------*/


#define POST_REND_MAX_CLI_ARG_LENGTH ( FILENAME_MAX )
#define POST_REND_MAX_CLI_ARG_LENGTH ( FILENAME_MAX )
#define POST_REND_NUM_MANDATORY_CMD_LINE_PARAMS 3


#define ISAR_MAX16B_FLT 32767.0f
#define ISAR_MAX16B_FLT 32767.0f
#define ISAR_MIN16B_FLT ( -32768.0f )
#define ISAR_MIN16B_FLT ( -32768.0f )
@@ -120,6 +121,7 @@ typedef struct
    bool quietModeEnabled;
    bool quietModeEnabled;
    bool sceneDescriptionInput;
    bool sceneDescriptionInput;
    IVAS_RENDER_FRAMESIZE render_framesize;
    IVAS_RENDER_FRAMESIZE render_framesize;
    int16_t numMandatoryCmdLineParams;
} CmdlnArgs;
} CmdlnArgs;


typedef enum
typedef enum
@@ -155,18 +157,18 @@ static const CmdLnParser_Option cliOptions[] = {
        .matchShort = "if",
        .matchShort = "if",
        .description = "Audio format of input file (e.g. BINAURAL_SPLIT_PCM, use -l for a list)",
        .description = "Audio format of input file (e.g. BINAURAL_SPLIT_PCM, use -l for a list)",
    },
    },
    {
        .id = CmdLnOptionId_inputMetadata,
        .match = "input_metadata",
        .matchShort = "im",
        .description = "Space-separated list of paths to metadata files for BINAURAL_SPLIT_PCM input mode",
    },
    {
    {
        .id = CmdLnOptionId_outputFile,
        .id = CmdLnOptionId_outputFile,
        .match = "output_file",
        .match = "output_file",
        .matchShort = "o",
        .matchShort = "o",
        .description = "Path to the output file",
        .description = "Path to the output file",
    },
    },
    {
        .id = CmdLnOptionId_inputMetadata,
        .match = "input_metadata",
        .matchShort = "im",
        .description = "Space-separated list of paths to metadata files for BINAURAL_SPLIT_PCM input mode",
    },
    {
    {
        .id = CmdLnOptionId_sampleRate,
        .id = CmdLnOptionId_sampleRate,
        .match = "sample_rate",
        .match = "sample_rate",
@@ -453,15 +455,17 @@ static bool checkRequiredArgs(
        fprintf( stderr, "Missing mandatory parameter: --%s/-%s\n", tmpOption->match, tmpOption->matchShort );
        fprintf( stderr, "Missing mandatory parameter: --%s/-%s\n", tmpOption->match, tmpOption->matchShort );
        missingRequiredArg = true;
        missingRequiredArg = true;
    }
    }

    if ( isEmptyString( args.outputFilePath ) )
    if ( isEmptyString( args.outputFilePath ) )
    {
    {
        tmpOption = findOptionById( CmdLnOptionId_outputFile );
        tmpOption = findOptionById( CmdLnOptionId_outputFile );
        fprintf( stderr, "Missing mandatory parameter: --%s/-%s\n", tmpOption->match, tmpOption->matchShort );
        fprintf( stderr, "Missing mandatory parameter: --%s/-%s\n", tmpOption->match, tmpOption->matchShort );
        missingRequiredArg = true;
        missingRequiredArg = true;
    }
    }

    if ( missingRequiredArg )
    if ( missingRequiredArg )
    {
    {
        CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions );
        CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions, args.numMandatoryCmdLineParams );
    }
    }


    return !missingRequiredArg;
    return !missingRequiredArg;
@@ -481,6 +485,12 @@ static CmdlnArgs defaultArgs(
#endif
#endif
    args.sampleRate = 0;
    args.sampleRate = 0;


    args.inConfig.numBinBuses = 0;
    args.inConfig.binBuses[0].srRtp = false;
    args.inConfig.binBuses[0].audioConfig = IVAS_AUDIO_CONFIG_INVALID;
    args.inConfig.binBuses[0].inputChannelIndex = 0;
    args.inConfig.binBuses[0].gain_dB = 0;

    args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID;
    args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID;


    for ( int32_t i = 0; i < RENDERER_MAX_ISAR_MD_INPUTS; ++i )
    for ( int32_t i = 0; i < RENDERER_MAX_ISAR_MD_INPUTS; ++i )
@@ -492,11 +502,13 @@ static CmdlnArgs defaultArgs(
    clearString( args.headRotationFilePath );
    clearString( args.headRotationFilePath );
    clearString( args.splitRendBFIFilePath );
    clearString( args.splitRendBFIFilePath );


    args.complexityLevel = ISAR_POST_REND_COMPLEXITY_LEVEL_THREE;
    args.delayCompensationEnabled = true;
    args.delayCompensationEnabled = true;
    args.quietModeEnabled = false;
    args.quietModeEnabled = false;
    args.sceneDescriptionInput = false;
    args.sceneDescriptionInput = false;


    args.render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
    args.render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
    args.numMandatoryCmdLineParams = POST_REND_NUM_MANDATORY_CMD_LINE_PARAMS;


    return args;
    return args;
}
}
@@ -656,7 +668,7 @@ static CmdlnArgs parseCmdlnArgs(
{
{
    CmdlnArgs args = defaultArgs( argv[0] );
    CmdlnArgs args = defaultArgs( argv[0] );


    if ( CmdLnParser_parseArgs( argc, argv, cliOptions, numCliOptions, &args, parseOption ) != 0 )
    if ( CmdLnParser_parseArgs( argc, argv, cliOptions, numCliOptions, &args, parseOption, args.numMandatoryCmdLineParams ) != 0 )
    {
    {
        exit( -1 ); /* Error printout handled by failing function */
        exit( -1 ); /* Error printout handled by failing function */
    }
    }
+6 −3
Original line number Original line Diff line number Diff line
@@ -70,6 +70,7 @@
#define RENDERER_MAX_CLI_ARG_LENGTH       ( FILENAME_MAX )
#define RENDERER_MAX_CLI_ARG_LENGTH       ( FILENAME_MAX )
#define RENDERER_MAX_METADATA_LENGTH      8192
#define RENDERER_MAX_METADATA_LENGTH      8192
#define RENDERER_MAX_METADATA_LINE_LENGTH 1024
#define RENDERER_MAX_METADATA_LINE_LENGTH 1024
#define RENDERER_NUM_MANDATORY_CMD_LINE_PARAMS 1000


#define IVAS_MAX16B_FLT 32767.0f
#define IVAS_MAX16B_FLT 32767.0f
#define IVAS_MIN16B_FLT ( -32768.0f )
#define IVAS_MIN16B_FLT ( -32768.0f )
@@ -203,6 +204,7 @@ typedef struct
#ifdef FIX_1318_ROOM_SIZE_CMD_LINE
#ifdef FIX_1318_ROOM_SIZE_CMD_LINE
    IVAS_ROOM_SIZE_T reverbRoomSize;
    IVAS_ROOM_SIZE_T reverbRoomSize;
#endif
#endif
    int16_t numMandatoryCmdLineParams;
} CmdlnArgs;
} CmdlnArgs;


typedef enum
typedef enum
@@ -2663,7 +2665,7 @@ static bool checkRequiredArgs(
    }
    }
    if ( missingRequiredArg )
    if ( missingRequiredArg )
    {
    {
        CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions );
        CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions, 100 );
    }
    }


    return !missingRequiredArg;
    return !missingRequiredArg;
@@ -2743,10 +2745,11 @@ static CmdlnArgs defaultArgs(
    args.aeSequence.selected = 0;
    args.aeSequence.selected = 0;
    args.aeSequence.frameCounter = 0;
    args.aeSequence.frameCounter = 0;
#ifdef FIX_1318_ROOM_SIZE_CMD_LINE
#ifdef FIX_1318_ROOM_SIZE_CMD_LINE

    args.reverbRoomSize = IVAS_ROOM_SIZE_AUTO;
    args.reverbRoomSize = IVAS_ROOM_SIZE_AUTO;
#endif
#endif


    args.numMandatoryCmdLineParams = RENDERER_NUM_MANDATORY_CMD_LINE_PARAMS;

    return args;
    return args;
}
}


@@ -2955,7 +2958,7 @@ static CmdlnArgs parseCmdlnArgs(
{
{
    CmdlnArgs args = defaultArgs( argv[0] );
    CmdlnArgs args = defaultArgs( argv[0] );


    if ( CmdLnParser_parseArgs( argc, argv, cliOptions, numCliOptions, &args, parseOption ) != 0 )
    if ( CmdLnParser_parseArgs( argc, argv, cliOptions, numCliOptions, &args, parseOption, args.numMandatoryCmdLineParams ) != 0 )
    {
    {
        exit( -1 ); /* Error printout handled by failing function */
        exit( -1 ); /* Error printout handled by failing function */
    }
    }
+10 −8
Original line number Original line Diff line number Diff line
@@ -335,7 +335,8 @@ static void printOptDescriptionAligned(
static void printUsage(
static void printUsage(
    const char *argv0,
    const char *argv0,
    const OptionProps *optionProps,
    const OptionProps *optionProps,
    const int32_t numOptions )
    const int32_t numOptions,
    const int16_t numMandatoryCmdLineParams )
{
{
    int32_t optNameLength;
    int32_t optNameLength;


@@ -363,9 +364,9 @@ static void printUsage(
        OptionProps opt = optionProps[i];
        OptionProps opt = optionProps[i];
        optNameLength = totalOptionNameLength( optionProps[i] );
        optNameLength = totalOptionNameLength( optionProps[i] );


        if (i == 2)
        if ( i == numMandatoryCmdLineParams )
        {
        {
            fprintf( stderr, "\nOptional parameters:\n" );
            fprintf( stderr, "\nOptions:\n" );
        }
        }


        /* TODO(sgi): make matchShort optional */
        /* TODO(sgi): make matchShort optional */
@@ -384,8 +385,8 @@ int16_t CmdLnParser_parseArgs(
    const OptionProps *optionProps,
    const OptionProps *optionProps,
    const int32_t numOptions,
    const int32_t numOptions,
    void *pOutputStruct,
    void *pOutputStruct,
    CmdLnParser_FnPtr_ParseOption parseOption
    CmdLnParser_FnPtr_ParseOption parseOption,
)
    const int16_t numMandatoryCmdLineParams )
{
{
    assert( numOptions <= MAX_SUPPORTED_OPTS );
    assert( numOptions <= MAX_SUPPORTED_OPTS );


@@ -405,16 +406,17 @@ int16_t CmdLnParser_parseArgs(
    return 0;
    return 0;


fail:
fail:
    printUsage( argv[0], optionProps, numOptions );
    printUsage( argv[0], optionProps, numOptions, numMandatoryCmdLineParams );
    return -1;
    return -1;
}
}


void CmdLnParser_printUsage(
void CmdLnParser_printUsage(
    char *executableName,
    char *executableName,
    const CmdLnParser_Option *options,
    const CmdLnParser_Option *options,
    const int32_t numOptions )
    const int32_t numOptions,
    const int16_t numMandatoryCmdLineParams )
{
{
    printUsage( executableName, options, numOptions );
    printUsage( executableName, options, numOptions, numMandatoryCmdLineParams );


    return;
    return;
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -47,8 +47,8 @@ typedef struct
/* Function for parsing option values into an output struct, to be implemented by the user */
/* Function for parsing option values into an output struct, to be implemented by the user */
typedef int16_t ( *CmdLnParser_FnPtr_ParseOption )( int32_t optionId, char **optionValues, int16_t numOptionValues, void *pOutputStruct );
typedef int16_t ( *CmdLnParser_FnPtr_ParseOption )( int32_t optionId, char **optionValues, int16_t numOptionValues, void *pOutputStruct );


int16_t CmdLnParser_parseArgs( int32_t argc, char **argv, const CmdLnParser_Option *options, const int32_t numOptions, void *pOutputStruct, CmdLnParser_FnPtr_ParseOption parseOption );
int16_t CmdLnParser_parseArgs( int32_t argc, char **argv, const CmdLnParser_Option *options, const int32_t numOptions, void *pOutputStruct, CmdLnParser_FnPtr_ParseOption parseOption, const int16_t numMandatoryCmdLineParams );


void CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions );
void CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions, const int16_t numMandatoryCmdLineParams );


#endif /* CMDLN_PARSER_H */
#endif /* CMDLN_PARSER_H */