diff --git a/apps/decoder.c b/apps/decoder.c index f6b55ba00f5851cf9aa35d911047ba98f45b2059..40bc7d9df0759655c1bf5c2e9cd0a6f248a95ea4 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -448,7 +448,6 @@ int main( asked_frame_size = arg.renderFramesize; uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : IVAS_DEFAULT_AEID; - arg.enableHeadRotation = arg.enableHeadRotation || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM; if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.roomSize, arg.non_diegetic_pan_enabled, @@ -2235,6 +2234,7 @@ static ivas_error decodeG192( #endif #endif IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 } }; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; SplitFileReadWrite *splitRendWriter = NULL; @@ -2422,10 +2422,8 @@ static ivas_error decodeG192( } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -2463,7 +2461,6 @@ static ivas_error decodeG192( if ( arg.enableExternalOrientation ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -2850,16 +2847,28 @@ static ivas_error decodeG192( } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternion; - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternion, &Pos[0] ) ) != IVAS_ERR_OK ) + if ( headRotReader == NULL ) { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; + Quaternions[0].w = -3.0f; + Quaternions[0].x = 0.0f; + Quaternions[0].y = 0.0f; + Quaternions[0].z = 0.0f; + Pos[0].x = 0.0f; + Pos[0].y = 0.0f; + Pos[0].z = 0.0f; + } + else + { + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[0], &Pos[0] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; + } } - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[0], Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3182,6 +3191,7 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 } }; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; @@ -3384,10 +3394,8 @@ static ivas_error decodeVoIP( } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -3426,7 +3434,6 @@ static ivas_error decodeVoIP( if ( arg.enableExternalOrientation ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; diff --git a/apps/isar_post_rend.c b/apps/isar_post_rend.c index 47ffdfb70118bba7683dc6fa563bb30ed4afbb65..f792bfe07382c01a86b57a5ef42e81eb1f394a2d 100644 --- a/apps/isar_post_rend.c +++ b/apps/isar_post_rend.c @@ -105,14 +105,12 @@ typedef struct int32_t sampleRate; InputConfig inConfig; OutputConfig outConfig; - char inMetadataFilePaths[RENDERER_MAX_ISAR_MD_INPUTS][POST_REND_MAX_CLI_ARG_LENGTH]; - int16_t numInMetadataFiles; + char inMetadataFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; char headRotationFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; char splitRendBFIFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; ISAR_POST_REND_COMPLEXITY_LEVEL complexityLevel; bool delayCompensationEnabled; bool quietModeEnabled; - bool sceneDescriptionInput; IVAS_RENDER_FRAMESIZE render_framesize; } CmdlnArgs; @@ -123,7 +121,6 @@ typedef enum CmdLnOptionId_outputFile, CmdLnOptionId_sampleRate, CmdLnOptionId_trajFile, - CmdLnOptionId_orientationTracking, CmdLnOptionId_complexityLevel, CmdLnOptionId_noDelayCmp, CmdLnOptionId_quietModeEnabled, @@ -132,6 +129,7 @@ typedef enum CmdLnOptionId_SplitRendBFIFile, CmdLnOptionId_framing, CmdLnOptionId_srParamsFile, + CmdLnOptionId_help, } CmdLnOptionId; static const CmdLnParser_Option cliOptions[] = { @@ -139,80 +137,99 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputFile, .match = "input_file", .matchShort = "i", - .description = "Path to the input file (WAV, raw PCM or scene description file)", + .placeholder = "", + .description = "Path to the input file (WAV or raw PCM file with BINAURAL_SPLIT_PCM input format\nor ISAR bitstream file with BINAURAL_SPLIT_CODED input format)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputFormat, .match = "input_format", .matchShort = "if", - .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 path to metadata files for BINAURAL_SPLIT_PCM input mode", + .placeholder = "", + .description = "Audio format of input file (e.g. BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, ... Use -l for a list)", + .isMandatory = true, }, { .id = CmdLnOptionId_outputFile, .match = "output_file", .matchShort = "o", + .placeholder = "", .description = "Path to the output file", + .isMandatory = true, + }, + { + .id = CmdLnOptionId_inputMetadata, + .match = "input_metadata", + .matchShort = "im", + .placeholder = "", + .description = "Path to the input metadata file for BINAURAL_SPLIT_PCM input format", }, { .id = CmdLnOptionId_sampleRate, .match = "sample_rate", .matchShort = "fs", - .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw PCM inputs", + .placeholder = "", + .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw PCM input files", }, { .id = CmdLnOptionId_trajFile, .match = "trajectory_file", .matchShort = "T", + .placeholder = "", .description = "Head rotation trajectory file for simulation of head tracking", }, { .id = CmdLnOptionId_SplitRendBFIFile, .match = "post_rend_bfi_file", .matchShort = "prbfi", - .description = "Split rendering option: bfi file", + .placeholder = "", + .description = "Split rendering BFI (Bad Frame Indicator) file", }, { .id = CmdLnOptionId_noDelayCmp, .match = "no_delay_compensation", .matchShort = "no_delay_cmp", - .description = "[flag] Turn off delay compensation", + .description = "Turn off delay compensation", }, { .id = CmdLnOptionId_complexityLevel, .match = "complexity_level", .matchShort = "level", - .description = "Complexity level, level = (1, 2, 3), will be defined after characterisation.", + .placeholder = "", + .description = "Complexity level (1, 2, 3) - will be defined after characterisation", }, { .id = CmdLnOptionId_quietModeEnabled, .match = "quiet", .matchShort = "q", - .description = "[flag] Limit printouts to terminal", + .description = "Quiet mode - limit printouts to terminal", }, { .id = CmdLnOptionId_listFormats, .match = "list", .matchShort = "l", - .description = "List supported audio formats", + .description = "List supported audio formats of input file", }, { .id = CmdLnOptionId_framing, .match = "framing", .matchShort = "fr", - .description = "Set Render audio framing.", + .placeholder = "", + .description = "Set audio rendering frame size in ms (5, 10, 20)", }, { .id = CmdLnOptionId_srParamsFile, .match = "sr_params", .matchShort = "s", + .placeholder = "", .description = "Path to the split rendering init params file", }, + { + .id = CmdLnOptionId_help, + .match = "help", + .matchShort = "h", + .description = "Show this help message and exit", + }, }; @@ -291,26 +308,11 @@ static const CmdLnParser_Option *findOptionById( static bool parseInConfig( const char *inFormatStr, - InputConfig *inConfig, - bool *sceneDescriptionInput ) + InputConfig *inConfig ) { - char charBuf[FILENAME_MAX]; - /* Initialize input config struct */ inConfig->numBinBuses = 0; - /* First check if input is being set to scene description file - this is not covered by parseAudioConfig(). */ - strncpy( charBuf, inFormatStr, sizeof( charBuf ) - 1 ); - charBuf[sizeof( charBuf ) - 1] = '\0'; - to_upper( charBuf ); - if ( strcmp( charBuf, "META" ) == 0 ) - { - *sceneDescriptionInput = true; - /* Parsing the file will be done later. At this point the actual file path - * may not be known as command line parameters are still being parsed. */ - return true; - } - /* Check for single-format inputs. The given string should map to a member of AUDIO_CONFIG enum. */ bool srRtp = false; IVAS_AUDIO_CONFIG audioConfig = parseAudioConfig( inFormatStr, &srRtp ); @@ -329,7 +331,7 @@ static bool parseInConfig( /* Default case covers formats that are defined in the AUDIO_CONFIG enum, * but cannot be used at input, e.g. BINAURAL */ const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats ); - fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); + fprintf( stderr, "Error: Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); return false; } } @@ -403,50 +405,6 @@ static IVAS_AUDIO_CONFIG parseAudioConfig( } -static bool checkRequiredArgs( - CmdlnArgs args ) -{ - const CmdLnParser_Option *tmpOption; - - /* Check required arguments */ - bool missingRequiredArg = false; - if ( isEmptyString( args.inputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_inputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - - const bool singleInputSpecified = ( args.inConfig.numBinBuses != 0 ); - - if ( !args.sceneDescriptionInput && !singleInputSpecified ) - { - /* Neither scene description input nor single-type input was specified on command line */ - tmpOption = findOptionById( CmdLnOptionId_inputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( isEmptyString( args.outputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( args.sampleRate == 0 ) - { - tmpOption = findOptionById( CmdLnOptionId_sampleRate ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( missingRequiredArg ) - { - CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions ); - } - - return !missingRequiredArg; -} - - static CmdlnArgs defaultArgs( const char *executableName ) { @@ -459,20 +417,21 @@ static CmdlnArgs defaultArgs( args.sampleRate = 0; - args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID; + 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; - for ( int32_t i = 0; i < RENDERER_MAX_ISAR_MD_INPUTS; ++i ) - { - clearString( args.inMetadataFilePaths[i] ); - } - args.numInMetadataFiles = 0; + args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID; + clearString( args.inMetadataFilePath ); clearString( args.headRotationFilePath ); clearString( args.splitRendBFIFilePath ); + args.complexityLevel = ISAR_POST_REND_COMPLEXITY_LEVEL_THREE; args.delayCompensationEnabled = true; args.quietModeEnabled = false; - args.sceneDescriptionInput = false; args.render_framesize = IVAS_RENDER_FRAMESIZE_20MS; @@ -480,7 +439,7 @@ static CmdlnArgs defaultArgs( } -static void parseOption( +static int16_t parseOption( const int32_t optionId, char **optionValues, const int16_t numOptionValues, @@ -491,88 +450,182 @@ static void parseOption( switch ( optionId ) { case CmdLnOptionId_listFormats: - assert( numOptionValues == 0 ); printSupportedAudioConfigs(); exit( 0 ); case CmdLnOptionId_inputFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No input file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single input file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->inputFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_inputFormat: - assert( numOptionValues == 1 ); - if ( !parseInConfig( optionValues[0], &args->inConfig, &args->sceneDescriptionInput ) ) + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No input file format has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single input file format, but %d have been provided!\n", numOptionValues ); + return -1; + } + + if ( !parseInConfig( optionValues[0], &args->inConfig ) ) { - exit( -1 ); /* Error printout handled by failing function */ + /* Error printout handled by failing function */ + return -1; } break; case CmdLnOptionId_inputMetadata: - assert( numOptionValues <= RENDERER_MAX_ISAR_MD_INPUTS ); - for ( int16_t i = 0; i < numOptionValues; ++i ) + if ( numOptionValues == 0 ) { - strncpy( args->inMetadataFilePaths[i], optionValues[i], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); + fprintf( stderr, "Error: No input metadata file for BINAURAL_SPLIT_PCM mode has been provided!\n" ); + return -1; } - args->numInMetadataFiles = numOptionValues; + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single input metadata file, but %d have been provided!\n", numOptionValues ); + return -1; + } + strncpy( args->inMetadataFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_outputFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No output file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single output file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->outputFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_sampleRate: - assert( numOptionValues == 1 ); + if ( numOptionValues != 1 ) + { + fprintf( stderr, "Error: Incorrect sampling rate specification!\n" ); + return -1; + } args->sampleRate = (int32_t) ( strtol( optionValues[0], NULL, 10 ) * 1000 ); if ( args->sampleRate == 0 ) { - fprintf( stderr, "Invalid sampling rate specified\n" ); - exit( -1 ); + fprintf( stderr, "Error: Invalid sampling rate specified\n" ); + return -1; } break; case CmdLnOptionId_trajFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No head rotation trajectory file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single head rotation trajectory file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->headRotationFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_SplitRendBFIFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No BFI file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single BFI file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->splitRendBFIFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_complexityLevel: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No complexity level has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single complexity level, but %d have been provided!\n", numOptionValues ); + return -1; + } args->complexityLevel = (int32_t) ( strtol( optionValues[0], NULL, 10 ) ); if ( args->complexityLevel < ISAR_POST_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel > ISAR_POST_REND_COMPLEXITY_LEVEL_THREE ) { - fprintf( stdout, "Invalid complexity level specified.\n" ); - exit( -1 ); + fprintf( stderr, "Error: Invalid complexity level specified.\n" ); + return -1; } else if ( args->complexityLevel == ISAR_POST_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel == ISAR_POST_REND_COMPLEXITY_LEVEL_TWO ) { - fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" ); + fprintf( stderr, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" ); } break; case CmdLnOptionId_noDelayCmp: - assert( numOptionValues == 0 ); + if ( numOptionValues != 0 ) + { + fprintf( stderr, "Error: Incorrect specification of the `-%s/--%s` command-line option!\n", cliOptions[optionId].matchShort, cliOptions[optionId].match ); + return -1; + } args->delayCompensationEnabled = false; break; case CmdLnOptionId_quietModeEnabled: - assert( numOptionValues == 0 ); + if ( numOptionValues != 0 ) + { + fprintf( stderr, "Error: Incorrect specification of the `-%s/--%s` command-line option!\n", cliOptions[optionId].matchShort, cliOptions[optionId].match ); + return -1; + } args->quietModeEnabled = true; break; case CmdLnOptionId_framing: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: Incorrect audio rendering frame size!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a rendering frame size, but %d have been provided!\n", numOptionValues ); + return -1; + } if ( !parseRenderFramesize( optionValues[0], &args->render_framesize ) ) { - fprintf( stderr, "Unknown or invalid option for frame size: %s\n", optionValues[0] ); - exit( -1 ); + fprintf( stderr, "Error: Unknown or invalid option for audio rendring frame size: %s\n", optionValues[0] ); + return -1; } break; case CmdLnOptionId_srParamsFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No path to the parameter initialization file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single parameter initialization file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->srParamsFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; + case CmdLnOptionId_help: + CmdLnParser_printUsage( args->executableName, cliOptions, numCliOptions ); + exit( 0 ); default: - assert( 0 && "This should be unreachable - all command line options should be explicitly handled." ); + fprintf( stderr, "Error: Incorrect or invalid command-line usage!\n" ); + return -1; break; } - return; + return 0; } @@ -587,11 +640,6 @@ static CmdlnArgs parseCmdlnArgs( exit( -1 ); /* Error printout handled by failing function */ } - if ( !checkRequiredArgs( args ) ) - { - exit( -1 ); /* Error printout handled by failing function */ - } - return args; } @@ -606,7 +654,7 @@ static void printSupportedAudioConfigs( void ) "RTPDUMP", }; - fprintf( stdout, "Supported audio formats:\n" ); + fprintf( stdout, "Supported audio formats:\n\n" ); for ( i = 0; i < sizeof( supportedFormats ) / sizeof( *supportedFormats ); i++ ) { fprintf( stdout, "%s\n", supportedFormats[i] ); @@ -872,7 +920,6 @@ int main( convert_backslash( args.inputFilePath ); convert_backslash( args.outputFilePath ); - convert_backslash( args.headRotationFilePath ); convert_backslash( args.srParamsFilePath ); /*------------------------------------------------------------------------------------------* @@ -881,6 +928,7 @@ int main( if ( !isEmptyString( args.headRotationFilePath ) ) { + convert_backslash( args.headRotationFilePath ); if ( RotationFileReader_open( args.headRotationFilePath, &headRotReader ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError opening file: %s\n", args.headRotationFilePath ); @@ -895,7 +943,11 @@ int main( if ( !isEmptyString( args.splitRendBFIFilePath ) ) { convert_backslash( args.splitRendBFIFilePath ); - SplitRendBFIFileReader_open( args.splitRendBFIFilePath, &splitRendBFIReader ); + if ( SplitRendBFIFileReader_open( args.splitRendBFIFilePath, &splitRendBFIReader ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError opening file: %s\n", args.splitRendBFIFilePath ); + goto cleanup; + } } /*------------------------------------------------------------------------------------------* @@ -908,7 +960,7 @@ int main( if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { error = split_rend_reader_open( &hSplitRendFileReadWrite, - args.inMetadataFilePaths[0], + args.inMetadataFilePath, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, @@ -917,13 +969,21 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.inMetadataFilePaths[0] ); + if ( isEmptyString( args.inMetadataFilePath ) ) + { + const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_inputMetadata ); + fprintf( stderr, "\nError: Split rendering metadata file not specified, use option -%s/--%s.\n", listOption->matchShort, listOption->match ); + } + else + { + fprintf( stderr, "\nError: Could not open split rendering metadata file %s!\n", args.inMetadataFilePath ); + } goto cleanup; } if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError opening file: %s\n", audioFilePath ); + fprintf( stderr, "\nError: Could not open input file: %s!\n", audioFilePath ); goto cleanup; } } @@ -939,13 +999,13 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend params file %s\n", args.srParamsFilePath ); + fprintf( stderr, "\nError: Could not open split rendering init params file %s!\n", args.srParamsFilePath ); goto cleanup; } if ( ( error = IVAS_RTP_READER_Init( &srRTP, args.inputFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "error in IVAS_RTP_READER_Init(): %d\n", error ); + fprintf( stderr, "\nError in IVAS_RTP_READER_Init(), error code: %d!\n", error ); goto cleanup; } audioReader = NULL; @@ -965,7 +1025,7 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.inputFilePath ); + fprintf( stderr, "\nError reading input file %s, error code: %d!\n", args.inputFilePath, error ); goto cleanup; } audioReader = NULL; @@ -991,14 +1051,14 @@ int main( /* else if sampling rate given on command line, compare with wav file */ else if ( inFileSampleRate != args.sampleRate ) { - fprintf( stderr, "\nSampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n", args.sampleRate, inFileSampleRate, args.inputFilePath ); + fprintf( stderr, "\nError: Sampling rate mismatch: %d Hz requested, but %d Hz found in file %s!\n", args.sampleRate, inFileSampleRate, args.inputFilePath ); goto cleanup; } break; case IVAS_ERR_SAMPLING_RATE_UNKNOWN: /* Returned when input is raw PCM */ if ( args.sampleRate == 0 ) { - fprintf( stderr, "\nSampling rate must be specified on command line when using raw PCM input\n" ); + fprintf( stderr, "\nError: Sampling rate must be specified on command line in case of raw PCM input!\n" ); goto cleanup; } break; @@ -1013,7 +1073,7 @@ int main( error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels ); if ( error != IVAS_ERR_OK && error != IVAS_ERR_NUM_CHANNELS_UNKNOWN ) { - fprintf( stderr, "\nAudioFileReader_getNumChannels failed: %s\n", ivas_error_to_string( error ) ); + fprintf( stderr, "\nError: AudioFileReader_getNumChannels() failed: %s\n", ivas_error_to_string( error ) ); goto cleanup; } } @@ -1236,34 +1296,44 @@ int main( /* Convert from int to float and from interleaved to packed */ convertInputBuffer( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inFloatBuffer ); - int16_t num_subframes, sf_idx; + int16_t num_subframes; num_subframes = (int16_t) args.render_framesize; /* Read from head rotation trajectory file if specified */ + IVAS_QUATERNION headRot[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; if ( headRotReader != NULL ) { - for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ ) + for ( i = 0; i < num_subframes; i++ ) { - IVAS_QUATERNION headRot; - IVAS_VECTOR3 Pos; - - if ( ( error = HeadRotationFileReading( headRotReader, &headRot, &Pos ) ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReading( headRotReader, &headRot[i], &Pos[i] ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) ); goto cleanup; } - - if ( ( error = ISAR_POST_REND_SetHeadRotation( hIsarPostRend, headRot, Pos, DEFAULT_AXIS, sf_idx ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError setting Head Rotation: %s\n", ivas_error_to_string( error ) ); - goto cleanup; - } } } else { - fprintf( stderr, "\nHead Rotation should be enabled in post renderer\n" ); - goto cleanup; + for ( i = 0; i < num_subframes; i++ ) + { + headRot[i].w = -3.0f; + headRot[i].x = 0.0f; + headRot[i].y = 0.0f; + headRot[i].z = 0.0f; + Pos[i].x = 0.0f; + Pos[i].y = 0.0f; + Pos[i].z = 0.0f; + } + } + + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = ISAR_POST_REND_SetHeadRotation( hIsarPostRend, headRot[i], Pos[i], DEFAULT_AXIS, i ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError setting Head Rotation: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } } /* Read from split renderer bfi file if specified */ diff --git a/apps/renderer.c b/apps/renderer.c index 491433d645a25ba2da700da30c92c9187391f336..31693715601cd871c490384fbb8c8ddd7a65a3d9 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -234,96 +234,116 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputFile, .match = "input_file", .matchShort = "i", + .placeholder = "", .description = "Path to the input file (WAV, raw PCM or scene description file)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputFormat, .match = "input_format", .matchShort = "if", + .placeholder = "", .description = "Audio format of input file (e.g. 5_1 or HOA3 or META,\nuse -l for a list)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputMetadata, .match = "input_metadata", .matchShort = "im", + .placeholder = " [...]", .description = "Space-separated list of path to metadata files for ISM/MASA/OMASA/\nOSBA/BINAURAL_SPLIT_PCM inputs. \nFor OMASA, ISM files must be specified first.", }, { .id = CmdLnOptionId_outputFile, .match = "output_file", .matchShort = "o", + .placeholder = "", .description = "Path to the output file", + .isMandatory = true, }, { .id = CmdLnOptionId_outputFormat, .match = "output_format", .matchShort = "of", + .placeholder = "", .description = "Output format to render.\nAlternatively, can be a custom loudspeaker layout file", + .isMandatory = true, }, { .id = CmdLnOptionId_sampleRate, .match = "sample_rate", .matchShort = "fs", + .placeholder = "", .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw\nPCM inputs", }, { .id = CmdLnOptionId_trajFile, .match = "trajectory_file", .matchShort = "T", + .placeholder = "", .description = "Head rotation trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_outputMetadata, .match = "output_metadata", .matchShort = "om", + .placeholder = "", .description = "coded metadata file for BINAURAL_SPLIT_PCM output mode", }, { .id = CmdLnOptionId_SplitRendBFIFile, .match = "post_rend_bfi_file", .matchShort = "prbfi", + .placeholder = "", .description = "Split rendering option: bfi file", }, { .id = CmdLnOptionId_refRotFile, .match = "reference_rotation_file", .matchShort = "rf", + .placeholder = "", .description = "Reference rotation trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_customHrtfFile, .match = "custom_hrtf", .matchShort = "hrtf", + .placeholder = "", .description = "Custom HRTF file for binaural rendering\n(only for binaural outputs)", }, { .id = CmdLnOptionId_renderConfigFile, .match = "render_config_parameters", .matchShort = "render_config", + .placeholder = "", .description = "Binaural renderer configuration parameters in file\n(only for binaural outputs)", }, { .id = CmdLnOptionId_nonDiegeticPan, .match = "non_diegetic_panning", .matchShort = "non_diegetic_pan", + .placeholder = "", .description = "Panning mono non diegetic sound to stereo -90<= pan <= 90\nleft or l or 90->left, right or r or -90->right,\ncenter or c or 0 ->middle", }, { .id = CmdLnOptionId_orientationTracking, .match = "tracking_type", .matchShort = "otr", + .placeholder = "", .description = "Head orientation tracking type: 'none', 'ref', 'avg' or `ref_vec`\nor `ref_vec_lev` (only for binaural outputs)", }, { .id = CmdlnOptionId_lfePosition, .match = "lfe_position", .matchShort = "lp", + .placeholder = ",,", .description = "Output LFE position. Comma-delimited triplet of [gain, azimuth,\nelevation] where gain is linear (like --gain, -g) and azimuth,\nelevation are in degrees. If specified, overrides the default\nbehavior which attempts to map input to output LFE channel(s)", }, { .id = CmdlnOptionId_lfeMatrix, .match = "lfe_matrix", .matchShort = "lm", + .placeholder = "", .description = "LFE panning matrix. File (CSV table) containing a matrix of\ndimensions [ num_input_lfe x num_output_channels ] with elements\nspecifying linear routing gain (like --gain, -g). If specified,\noverrides the output LFE position option and the default\nbehavior which attempts to map input to output LFE channel(s)", }, { @@ -336,6 +356,7 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_complexityLevel, .match = "complexity_level", .matchShort = "level", + .placeholder = "", .description = "Complexity level, level = (1, 2, 3), will be defined after\ncharacterisation.", }, { @@ -348,6 +369,7 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputGain, .match = "gain", .matchShort = "g", + .placeholder = "", .description = "Input gain (linear, not in dB) to be applied to input audio file", }, { @@ -360,43 +382,50 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_referenceVectorFile, .match = "reference_vector_file", .matchShort = "rvf", + .placeholder = "", .description = "Reference vector trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_exteriorOrientationFile, .match = "exterior_orientation_file", .matchShort = "exof", + .placeholder = "", .description = "External orientation trajectory file for simulation of external\norientations", }, { .id = CmdLnOptionId_framing, .match = "framing", .matchShort = "fr", - .description = "Set Render audio framing.", + .placeholder = "", + .description = "Set render audio framing in ms", }, { .id = CmdLnOptionId_syncMdDelay, .match = "sync_md_delay", .matchShort = "smd", + .placeholder = "", .description = "Metadata Synchronization Delay in ms, Default is 0. Quantized by\n5ms subframes for TDRenderer (13ms -> 10ms -> 2subframes)", }, { .id = CmdLnOptionId_directivityPatternId, .match = "ism_directivity_pattern_id", .matchShort = "dpid", + .placeholder = " [...]", .description = "Directivity pattern ID(s) = [ID1, ID2, ID3, ID4]. Space-separated\nlist of up to 4 numbers (unsigned integers) can be specified for\nBINAURAL and BINAURAL_ROOM_REVERB output.\nID1, ID2, ID3, ID4 specify the directivity pattern IDs used for\nISMs 1,2,3 and 4 respectively. \nThis option needs to be accompanied by a render_config file,\notherwise a default directivity pattern is used.", }, { .id = CmdLnOptionId_acousticEnvironmentId, .match = "acoustic_environment_id", .matchShort = "aeid", + .placeholder = "", .description = "Acoustic environment ID (number > 0) alternatively, it can be\na text file where each line contains \"ID duration\" for\nBINAURAL_ROOM_REVERB output.", }, { .id = CmdLnOptionId_roomSize, .match = "room_size", .matchShort = "rsz", - .description = "Selects default reverb based on a room size (S - small | M - medium | L - large)", + .placeholder = "", + .description = "Selects default reverb based on a room size (S - small |\nM - medium | L - large)", } }; @@ -1447,7 +1476,7 @@ int main( if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, outFile, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms, bitsBuffer.config.isar_frame_size_ms, args.sampleRate, bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", outFile ); + fprintf( stderr, "\nError: Could not open split rend metadata file %s!\n", outFile ); goto cleanup; } } @@ -2595,53 +2624,6 @@ static bool parseReverbRoomSize( return true; } - -static bool checkRequiredArgs( - CmdlnArgs args ) -{ - const CmdLnParser_Option *tmpOption; - - /* Check required arguments */ - bool missingRequiredArg = false; - if ( isEmptyString( args.inputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_inputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - - const bool singleInputSpecified = args.inConfig.numAudioObjects != 0 || - args.inConfig.numAmbisonicsBuses != 0 || - args.inConfig.numMultiChannelBuses != 0 || - args.inConfig.numMasaBuses != 0; - - if ( !args.sceneDescriptionInput && !singleInputSpecified ) - { - /* Neither scene description input nor single-type input was specified on command line */ - tmpOption = findOptionById( CmdLnOptionId_inputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( isEmptyString( args.outputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_INVALID ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( missingRequiredArg ) - { - CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions ); - } - - return !missingRequiredArg; -} - static CmdlnArgs defaultArgs( const char *executableName ) { @@ -2721,7 +2703,7 @@ static CmdlnArgs defaultArgs( return args; } -static void parseOption( +static int16_t parseOption( const int32_t optionId, char **optionValues, const int16_t numOptionValues, @@ -2911,7 +2893,7 @@ static void parseOption( break; } - return; + return 0; } static CmdlnArgs parseCmdlnArgs( @@ -2925,11 +2907,6 @@ static CmdlnArgs parseCmdlnArgs( exit( -1 ); /* Error printout handled by failing function */ } - if ( !checkRequiredArgs( args ) ) - { - exit( -1 ); /* Error printout handled by failing function */ - } - if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { args.Opt_Headrotation = 1; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 17342a454a8dbd8c28acdf6ade2e3088f8eb1236..e532352e0b048495251ecc18d6dcac3a4630043c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -530,6 +530,11 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_aeid_on = acousticEnvironmentId != 65535 ? TRUE : FALSE; hDecoderConfig->Opt_ObjEdit_on = (int16_t) objEditEnabled; + if ( outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + hDecoderConfig->Opt_Headrotation = 1; + } + if ( renderFramesize == IVAS_RENDER_FRAMESIZE_UNKNOWN ) { return IVAS_ERR_WRONG_PARAMS; diff --git a/lib_isar/lib_isar_post_rend.h b/lib_isar/lib_isar_post_rend.h index e1f91a47690167ece73060b96a24329a4d4454d2..7d772205061c1903dded526253dab21cb867b888 100644 --- a/lib_isar/lib_isar_post_rend.h +++ b/lib_isar/lib_isar_post_rend.h @@ -41,8 +41,7 @@ * ISAR post-renderer constants *---------------------------------------------------------------------*/ -#define RENDERER_MAX_ISAR_MD_INPUTS 1 -#define RENDERER_MAX_BIN_INPUTS 1 +#define RENDERER_MAX_BIN_INPUTS 1 /*---------------------------------------------------------------------* * ISAR post-renderer structures diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 01e1d77231ff06fc84f35a4ca20448a53e8b2729..2faeca21d2145577b4714583e1e6f1daaec72e20 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -552,11 +552,11 @@ ivas_error get_channel_config( } else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { - strcpy( str, "BINAURAL_SPLIT_CODED" ); + strcpy( str, "Binaural: split-rendering mode using encoded data" ); } else if ( config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - strcpy( str, "Binaural_Split_PCM" ); + strcpy( str, "Binaural: split-rendering mode using PCM data" ); } else if ( config == IVAS_AUDIO_CONFIG_EXTERNAL ) { diff --git a/lib_util/cmdl_tools.c b/lib_util/cmdl_tools.c index 625db1273342f1b56eb20e12c5e31ffbf5ec7bc5..1f551f8917cab5791fd2129031e3cfdc4c6f98bd 100644 --- a/lib_util/cmdl_tools.c +++ b/lib_util/cmdl_tools.c @@ -225,3 +225,28 @@ bool isEmptyString( { return str[0] == '\0'; } + + +/*---------------------------------------------------------------------* + * strLength() + * + * Get the length of a string up to a maximum length. + * + * Equivalent to strnlen, which is not part of the C standard and only provided by POSIX. + * + *---------------------------------------------------------------------*/ + +int32_t strLength( + const char *str, + int32_t maxlen ) +{ + int32_t len; + + len = 0; + while ( len < maxlen && str[len] != '\0' ) + { + len++; + } + + return len; +} diff --git a/lib_util/cmdl_tools.h b/lib_util/cmdl_tools.h index 327acb93d0b1d528874de8ef018a36686379b778..b331dea03df0fea8a0b43c682f940c3773fd4b6e 100644 --- a/lib_util/cmdl_tools.h +++ b/lib_util/cmdl_tools.h @@ -50,4 +50,6 @@ void clearString( char *str ); bool isEmptyString( const char *str ); +int32_t strLength( const char *str, int32_t maxlen ); + #endif /* CMDL_TOOLS_H */ diff --git a/lib_util/cmdln_parser.c b/lib_util/cmdln_parser.c index 1b9eb7a92899f1b62df0e925fc7f3882c2512012..56164386493e40980c8a81b5022146fd1696a6c3 100644 --- a/lib_util/cmdln_parser.c +++ b/lib_util/cmdln_parser.c @@ -36,19 +36,30 @@ #include #include #include +#include +#include -#define MAX_SUPPORTED_OPTS ( 1024 ) -#define MAX_OPTION_LENGTH ( 1024 ) +#define MAX_SUPPORTED_OPTS ( 1024 ) +#define MAX_OPTION_MATCH_LENGTH ( 30 ) +#define MAX_OPTION_LENGTH ( MAX_OPTION_MATCH_LENGTH + 2 ) typedef CmdLnParser_Option OptionProps; typedef struct { OptionProps props; - int8_t hasBeenParsed; + bool hasBeenParsed; } Option; -static int16_t validateNoDuplicateIds( +/* Error enum for internal use */ +typedef enum +{ + CMDLN_PARSER_ERR_OK = 0, + CMDLN_PARSER_ERR_FAILED_PARSING = -1, + CMDLN_PARSER_ERR_MISCONFIGURED = -2, +} CmdLnParserError; + +static CmdLnParserError validateNoDuplicateIds( const OptionProps *props, int32_t numOpts ) { @@ -59,121 +70,136 @@ static int16_t validateNoDuplicateIds( if ( props[i].id == props[j].id ) { fprintf( stderr, "[dev] Duplicate ID == %d between options %s and %s\n", props[i].id, props[i].match, props[j].match ); - return -1; + return CMDLN_PARSER_ERR_MISCONFIGURED; } } } - return 0; + return CMDLN_PARSER_ERR_OK; } -static int16_t validateOptionProps( +static CmdLnParserError validateOptionProps( OptionProps props ) { /* Check required properties */ if ( props.match == NULL ) { - /* TODO(sgi): Don't print out usage after this - props.match is used there */ - fprintf( stderr, "[dev] Option with ID == %d - missing required property \"match\"\n", props.id ); - return -1; + fprintf( stderr, "[dev] Option with ID %d - missing required property \"match\"\n", props.id ); + return CMDLN_PARSER_ERR_MISCONFIGURED; } if ( props.id == 0 ) { fprintf( stderr, "[dev] Invalid ID for option %s. ID == %d is reserved.\n", props.match, props.id ); - return -1; + return CMDLN_PARSER_ERR_MISCONFIGURED; } - return 0; + /* Check match string length */ + if ( strLength( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) + { + fprintf( stderr, "[dev] Option with ID %d - match string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + if ( props.matchShort != NULL && strLength( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) + { + fprintf( stderr, "[dev] Option with ID %d - matchShort string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + + return CMDLN_PARSER_ERR_OK; } /* Validate given OptionProps and use them to initialize array of Options */ -static int16_t initOpts( +static CmdLnParserError initOpts( const OptionProps *options, const int32_t numOpts, Option *opts ) { + CmdLnParserError error; + + if ( numOpts > MAX_SUPPORTED_OPTS ) + { + fprintf( stderr, "[dev] Number of defined options (%d) exceeds limit (%d).\n", numOpts, MAX_SUPPORTED_OPTS ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + + /* Check for duplicate IDs */ + if ( ( error = validateNoDuplicateIds( options, numOpts ) ) != 0 ) + { + return error; + } + for ( int32_t i = 0; i < numOpts; ++i ) { - if ( validateOptionProps( options[i] ) != 0 ) + if ( ( error = validateOptionProps( options[i] ) ) != CMDLN_PARSER_ERR_OK ) { - return -1; + return error; } Option tmp = { - .hasBeenParsed = 0 + .hasBeenParsed = false }; tmp.props = options[i]; /* Cannot assign in aggregate initializer above - causes Visual Studio warning */ opts[i] = tmp; } - /* Check for duplicate IDs */ - if ( validateNoDuplicateIds( options, numOpts ) != 0 ) - { - return -1; - } - - return 0; -} - -static int8_t stringLooksLikeOption( - const char *str ) -{ - if ( ( str[0] == '-' ) && is_number( str ) == false ) - { - return 1; - } - return 0; } -static const char *stringToOptionName( +static bool stringLooksLikeOption( const char *str ) { - while ( ( *str == '-' ) && ( ( str[1] != '0' ) || ( str[1] != '1' ) ) ) + if ( ( str[0] == '-' ) && !is_number( str ) ) { - ++str; + return true; } - return str; + return false; } -static int8_t optionMatchesString( +static bool optionMatchesString( Option opt, const char *str ) { if ( !stringLooksLikeOption( str ) ) { - return 0; + return false; } - const char *optionName = stringToOptionName( str ); + if ( strLength( str, MAX_OPTION_LENGTH + 1 ) > MAX_OPTION_LENGTH ) + { + /* String longer than longest possible option - not a match */ + return false; + } - char optionName_to_upper[FILENAME_MAX]; - strncpy( optionName_to_upper, optionName, sizeof( optionName_to_upper ) - 1 ); - optionName_to_upper[sizeof( optionName_to_upper ) - 1] = '\0'; - to_upper( optionName_to_upper ); + char str_to_upper[MAX_OPTION_LENGTH + 1]; + snprintf( str_to_upper, sizeof( str_to_upper ), "%s", str ); + to_upper( str_to_upper ); - char match_to_upper[FILENAME_MAX]; - strncpy( match_to_upper, opt.props.match, sizeof( match_to_upper ) - 1 ); - optionName_to_upper[sizeof( match_to_upper ) - 1] = '\0'; + char match_to_upper[MAX_OPTION_LENGTH + 1]; + snprintf( match_to_upper, sizeof( match_to_upper ), "--%s", opt.props.match ); to_upper( match_to_upper ); + if ( strcmp( str_to_upper, match_to_upper ) == 0 ) + { + return true; + } - char matchShort_to_upper[FILENAME_MAX]; - strncpy( matchShort_to_upper, opt.props.matchShort, sizeof( matchShort_to_upper ) - 1 ); - optionName_to_upper[sizeof( matchShort_to_upper ) - 1] = '\0'; - to_upper( matchShort_to_upper ); - - if ( strncmp( optionName_to_upper, match_to_upper, MAX_OPTION_LENGTH ) == 0 || strncmp( optionName_to_upper, matchShort_to_upper, MAX_OPTION_LENGTH ) == 0 ) + if ( opt.props.matchShort != NULL ) { - return 1; + snprintf( match_to_upper, sizeof( match_to_upper ), "-%s", opt.props.matchShort ); + to_upper( match_to_upper ); + + if ( strcmp( str_to_upper, match_to_upper ) == 0 ) + { + return true; + } } - return 0; + return false; } -static int16_t parseOpts( +static CmdLnParserError parseOpts( int32_t argc, char **argv, Option *opts, @@ -202,8 +228,14 @@ static int16_t parseOpts( /* Check if already parsed */ if ( optToMatch->hasBeenParsed ) { - fprintf( stderr, "Duplicate option: %s (%s)\n", optToMatch->props.match, optToMatch->props.matchShort ); - return -1; + fprintf( stderr, "Duplicate option provided: --%s", optToMatch->props.match ); + if ( optToMatch->props.matchShort != NULL ) + { + fprintf( stderr, "/-%s", optToMatch->props.matchShort ); + } + fprintf( stderr, "\n" ); + + return CMDLN_PARSER_ERR_FAILED_PARSING; } break; @@ -216,8 +248,8 @@ static int16_t parseOpts( /* Invalid option */ if ( stringLooksLikeOption( argv[argIdx] ) ) { - fprintf( stderr, "Unknown option `%s`\n", stringToOptionName( argv[argIdx] ) ); - return -1; + fprintf( stderr, "Unknown option `%s`\n", argv[argIdx] ); + return CMDLN_PARSER_ERR_FAILED_PARSING; } /* Otherwise, value following current option. @@ -229,7 +261,7 @@ static int16_t parseOpts( else { fprintf( stderr, "Unexpected token `%s`\n", argv[argIdx] ); - return -1; + return CMDLN_PARSER_ERR_FAILED_PARSING; } } @@ -238,8 +270,11 @@ static int16_t parseOpts( { if ( currOpt != NULL ) { - parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ); - currOpt->hasBeenParsed = 1; + if ( parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ) != 0 ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + currOpt->hasBeenParsed = true; } currOpt = nextOpt; @@ -253,11 +288,37 @@ static int16_t parseOpts( /* Parse last option */ if ( currOpt != NULL ) { - parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ); - currOpt->hasBeenParsed = 1; + if ( parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ) != 0 ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + currOpt->hasBeenParsed = true; } - return 0; + /* Check mandatory options */ + bool missingMandatory = false; + for ( int32_t optIdx = 0; optIdx < numOpts; ++optIdx ) + { + Option opt = opts[optIdx]; + + if ( opt.props.isMandatory && !opt.hasBeenParsed ) + { + fprintf( stderr, "Missing mandatory parameter: --%s", opt.props.match ); + if ( opt.props.matchShort != NULL ) + { + fprintf( stderr, "/-%s", opt.props.matchShort ); + } + fprintf( stderr, "\n" ); + + missingMandatory = true; + } + } + if ( missingMandatory ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + + return CMDLN_PARSER_ERR_OK; } static const char *getBasename( @@ -281,19 +342,22 @@ static const char *getBasename( return path; } -static int32_t totalOptionNameLength( +static int32_t totalNumOptChars( const OptionProps opt ) { - return (int32_t) ( strlen( opt.match ) + strlen( opt.matchShort ) ); -} + int32_t len = (int32_t) strlen( opt.match ); -static void printWhitespace( - const int32_t n ) -{ - for ( int32_t i = 0; i < n; ++i ) + if ( opt.matchShort != NULL ) + { + len += (int32_t) strlen( opt.matchShort ); + } + + if ( opt.placeholder != NULL ) { - fprintf( stderr, " " ); + len += (int32_t) strlen( opt.placeholder ); } + + return len; } static void printOptDescriptionAligned( @@ -317,7 +381,7 @@ static void printOptDescriptionAligned( fprintf( stderr, "%c", *descPtr ); if ( *descPtr == '\n' ) { - printWhitespace( descriptionColumnIdx ); + fprintf( stderr, "%*s", descriptionColumnIdx, "" ); } ++descPtr; } @@ -325,41 +389,114 @@ static void printOptDescriptionAligned( return; } +static void printOptions( + const OptionProps *optionProps, + const int32_t numOptions, + const bool mandatory, + const int32_t maxNumOptChars ) +{ + const int32_t descriptionColumnIdx = maxNumOptChars + 11 /* Additional chars we will print in the options column */; + int32_t numOptChars; + + for ( int32_t i = 0; i < numOptions; ++i ) + { + OptionProps opt = optionProps[i]; + + if ( opt.isMandatory != mandatory ) + { + continue; + } + + numOptChars = totalNumOptChars( optionProps[i] ); + + fprintf( stderr, " --%s", opt.match ); + numOptChars += 4; + + if ( opt.matchShort != NULL ) + { + fprintf( stderr, ", -%s", opt.matchShort ); + numOptChars += 3; + } + + if ( opt.placeholder != NULL ) + { + fprintf( stderr, " %s", opt.placeholder ); + numOptChars += 1; + } + + if ( opt.description != NULL ) + { + /* Done printing options column, fill with whitespace until description column */ + fprintf( stderr, "%*s", descriptionColumnIdx - numOptChars, ": " ); + printOptDescriptionAligned( opt.description, descriptionColumnIdx ); + } + else + { + fprintf( stderr, "\n" ); + } + } +} + static void printUsage( const char *argv0, const OptionProps *optionProps, const int32_t numOptions ) { - fprintf( stderr, "\n" ); - fprintf( stderr, "Usage: %s [options]\n", getBasename( argv0 ) ); - fprintf( stderr, "\n" ); - fprintf( stderr, "Valid options:\n" ); - - /* Find option with longest name, used for pretty formatting */ - int32_t maxOptNameLength = 0; + int32_t numOptChars; + int32_t maxNumOptChars = 0; + bool hasMandatoryOptions = false; for ( int32_t i = 0; i < numOptions; ++i ) { - const int32_t optNameLength = totalOptionNameLength( optionProps[i] ); - if ( maxOptNameLength < optNameLength ) + /* Find option with most characters when printed, used for pretty formatting */ + numOptChars = totalNumOptChars( optionProps[i] ); + if ( maxNumOptChars < numOptChars ) { - maxOptNameLength = optNameLength; + maxNumOptChars = numOptChars; + } + + /* Check if mandatory parameters should be printed separately */ + if ( optionProps[i].isMandatory ) + { + hasMandatoryOptions = true; } } - const int32_t preDescriptionWhitespace = 8; - const int32_t leftColumnAdditionalChars = 7; + fprintf( stderr, "\n" ); + fprintf( stderr, "Usage: %s [options]", getBasename( argv0 ) ); for ( int32_t i = 0; i < numOptions; ++i ) { OptionProps opt = optionProps[i]; - const int32_t optNameLength = totalOptionNameLength( optionProps[i] ); - /* TODO(sgi): make matchShort optional */ - fprintf( stderr, " --%s, -%s", opt.match, opt.matchShort ); + if ( opt.isMandatory ) + { + if ( opt.matchShort != NULL ) + { + fprintf( stderr, " -%s", opt.matchShort ); + } + else + { + fprintf( stderr, " --%s", opt.match ); + } + + if ( opt.placeholder != NULL ) + { + fprintf( stderr, " %s", opt.placeholder ); + } + } + } - printWhitespace( maxOptNameLength - optNameLength + preDescriptionWhitespace ); - printOptDescriptionAligned( opt.description, maxOptNameLength + preDescriptionWhitespace + leftColumnAdditionalChars ); + fprintf( stderr, "\n\n" ); + + if ( hasMandatoryOptions ) + { + fprintf( stderr, "Mandatory parameters:\n---------------------\n" ); + printOptions( optionProps, numOptions, true, maxNumOptChars ); + fprintf( stderr, "\n" ); } + fprintf( stderr, "Options:\n--------\n" ); + printOptions( optionProps, numOptions, false, maxNumOptChars ); + return; } @@ -371,34 +508,64 @@ int16_t CmdLnParser_parseArgs( void *pOutputStruct, CmdLnParser_FnPtr_ParseOption parseOption ) { - assert( numOptions <= MAX_SUPPORTED_OPTS ); + CmdLnParserError error; /* Prepare option array */ Option opts[MAX_SUPPORTED_OPTS]; - if ( initOpts( optionProps, numOptions, opts ) != 0 ) + if ( ( error = initOpts( optionProps, numOptions, opts ) ) != CMDLN_PARSER_ERR_OK ) { goto fail; } /* Iterate over argv and parse */ - if ( parseOpts( argc, argv, opts, numOptions, pOutputStruct, parseOption ) != 0 ) + if ( ( error = parseOpts( argc, argv, opts, numOptions, pOutputStruct, parseOption ) ) != CMDLN_PARSER_ERR_OK ) { goto fail; } - return 0; - fail: - printUsage( argv[0], optionProps, numOptions ); - return -1; + switch ( error ) + { + case CMDLN_PARSER_ERR_OK: + break; + case CMDLN_PARSER_ERR_MISCONFIGURED: + fprintf( stderr, "CmdLnParser is misconfigured.\n" ); + break; + case CMDLN_PARSER_ERR_FAILED_PARSING: + printUsage( argv[0], optionProps, numOptions ); + break; + } + + return error; } -void CmdLnParser_printUsage( +int16_t CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ) { + CmdLnParserError error; + + /* Re-use initOpts for validation only */ + Option opts[MAX_SUPPORTED_OPTS]; + if ( ( error = initOpts( options, numOptions, opts ) ) != CMDLN_PARSER_ERR_OK ) + { + goto fail; + } + printUsage( executableName, options, numOptions ); - return; +fail: + switch ( error ) + { + case CMDLN_PARSER_ERR_OK: + break; + case CMDLN_PARSER_ERR_MISCONFIGURED: + fprintf( stderr, "CmdLnParser is misconfigured.\n" ); + break; + case CMDLN_PARSER_ERR_FAILED_PARSING: + break; + } + + return error; } diff --git a/lib_util/cmdln_parser.h b/lib_util/cmdln_parser.h index 2627d556624dc0de59ca01a5f342d684d066d277..c6848f79b81934854ecea336b3002b7d72b377c3 100644 --- a/lib_util/cmdln_parser.h +++ b/lib_util/cmdln_parser.h @@ -38,17 +38,21 @@ typedef struct { - int32_t id; - const char *match; - const char *matchShort; - const char *description; + int32_t id; /* Unique ID for the option */ + const char *match; /* String to match, e.g. "input" here will match "--input" on CLI */ + + /* Struct members below are optional and can be omitted in option definition. If omitted, C will implicitly set them to 0. */ + const char *matchShort; /* Short version of the string to match, e.g. "i" here will match "-i" on CLI */ + const char *placeholder; /* If not NULL, this will follow the match string in the usage printout, e.g. "" here will print "--input " on CLI */ + const char *description; /* Description of the option for the usage printout. May contain '\n' for line breaks. */ + bool isMandatory; /* Parsing will fail if an option with `isMandatory == true` is not given */ } CmdLnParser_Option; /* Function for parsing option values into an output struct, to be implemented by the user */ -typedef void ( *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 ); -void CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ); +int16_t CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ); #endif /* CMDLN_PARSER_H */ diff --git a/lib_util/split_render_file_read_write.c b/lib_util/split_render_file_read_write.c index 59dad090fab53c5d0e75de068e17c0e4c8fa6a46..26ea6d8c8131a0a28ce9de05588737769a927374 100644 --- a/lib_util/split_render_file_read_write.c +++ b/lib_util/split_render_file_read_write.c @@ -76,13 +76,13 @@ ivas_error split_rend_reader_open( if ( ( hSplitRendFileReadWrite = (SplitFileReadWrite *) malloc( sizeof( SplitFileReadWrite ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split rendering writer\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split rendering reader\n" ) ); } hSplitRendFileReadWrite->file = fopen( filename, "rb" ); if ( hSplitRendFileReadWrite->file == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nCould not open split rend metadata file %s\n", filename ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nCould not open file %s\n", filename ) ); } header_len = strlen( header ); @@ -98,7 +98,7 @@ ivas_error split_rend_reader_open( if ( strncmp( header_read, header, header_len ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nError split rend bitstream main header mismatch\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nSplit rendering bitstream main header mismatch\n" ) ); } fread( &hSplitRendFileReadWrite->delay_ns, sizeof( uint32_t ), 1, hSplitRendFileReadWrite->file ); diff --git a/readme.txt b/readme.txt index 129393976b0c84c780f7fb194fa45bdbb3407ebd..853fec87c3ec455ef62625f9b4994ed50790a65b 100644 --- a/readme.txt +++ b/readme.txt @@ -384,16 +384,27 @@ Options: The usage of the "ISAR_post_rend" program is as follows: -------------------------------------------------------- -Usage: ISAR_post_rend [options] +Usage: ISAR_post_rend [options] -i -if -o + +Mandatory parameters: +--------------------- +--input_file, -i : Path to the input file (WAV or raw PCM file with BINAURAL_SPLIT_PCM input format or ISAR bitstream file with BINAURAL_SPLIT_CODED input format) +--input_format, -if : Audio format of input file (e.g. BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, ... Use -l for a list) +--output_file, -o : Path to the output file Options: -------- --i File : Input File (input file is bitstream if format is BINAURAL_SPLIT_CODED, or PCM/WAV file if format is BINAURAL_SPLIT_PCM) --if Format : Input Format of input (BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM) --im File : Coded metadata File for BINAURAL_SPLIT_PCM input format --o File : Output Audio File in BINAURAL format --fs : Input sampling rate in kHz (48) --prbfi File : BFI File +--input_metadata, -im : Path to the input metadata file for BINAURAL_SPLIT_PCM input format +--sample_rate, -fs : Input sampling rate in kHz (16, 32, 48) - required only with raw PCM input files +--trajectory_file, -T : Head rotation trajectory file for simulation of head tracking +--post_rend_bfi_file, -prbfi : Split rendering BFI (Bad Frame Indicator) file +--no_delay_compensation, -no_delay_cmp : Turn off delay compensation +--complexity_level, -level : Complexity level (1, 2, 3) - will be defined after characterisation +--quiet, -q : Quiet mode - limit printouts to terminal +--list, -l : List supported audio formats of input file +--framing, -fr : Render frame size in ms (5, 10, 20), default is 20 +--sr_params, -s : Path to the split rendering init params file +--help, -h : Show this help message and exit The usage of the "ambi_converter" program is as follows: