Commit 67e4ff90 authored by sagnowski's avatar sagnowski
Browse files

Merge branch '293-external-renderer-cli-problems' into 'main'

Resolve "External renderer CLI problems"

See merge request !387
parents 605ee559 951bdab9
Loading
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -1041,6 +1041,22 @@ static IVAS_REND_AudioConfig ambisonicsOrderToEnum(
    return IVAS_REND_AUDIO_CONFIG_UNKNOWN;
}

#ifdef FIX_293_EXT_RENDERER_CLI
static const CmdLnParser_Option *findOptionById(
    const int32_t id )
{
    for ( int32_t i = 0; i < numCliOptions; ++i )
    {
        if ( cliOptions[i].id == id )
        {
            return &cliOptions[i];
        }
    }

    return NULL;
}
#endif

static bool parseInConfig(
    const char *inFormatStr,
    InputConfig *inConfig,
@@ -1128,8 +1144,13 @@ static bool parseInConfig(

                if ( error == IVAS_ERR_FAILED_FILE_OPEN )
                {
#ifdef FIX_293_EXT_RENDERER_CLI
                    /* Failed to open with given string - most likely wasn't a file path */
                    const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats );
                    fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match );
#else
                    fprintf( stderr, "Unsupported input format: %s\n", inFormatStr );
#endif
                    return false;
                }
                if ( error != IVAS_ERR_OK )
@@ -1144,10 +1165,20 @@ static bool parseInConfig(
            }
            break;
        default:
#ifdef FIX_293_EXT_RENDERER_CLI
        {
            /* Default case covers formats that are defined in the IVAS_REND_AudioConfig 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 );
            return false;
        }
#else
            /* Default case covers formats that are defined in the IVAS_REND_AudioConfig enum,
             * but cannot be used at input, e.g. BINAURAL */
            fprintf( stderr, "Unsupported input format: %s\n", inFormatStr );
            return false;
#endif
    }

    return true;
@@ -1285,7 +1316,20 @@ static IVAS_REND_AudioConfig parseAudioConfig(
    }
    if ( strncmp( charBuf, "ISM", 3 ) == 0 )
    {
#ifdef FIX_293_EXT_RENDERER_CLI
        /* Accept input config as ISM only if the 4th character is a number from 1 to 4.
         * Otherwise, do nothing. Unknown audio config will be returned. */
        switch ( charBuf[3] )
        {
            case '1':
            case '2':
            case '3':
            case '4':
                return IVAS_REND_AUDIO_CONFIG_OBJECT;
        }
#else
        return IVAS_REND_AUDIO_CONFIG_OBJECT;
#endif
    }
    if ( strncmp( charBuf, "MASA", 4 ) == 0 )
    {
@@ -1313,6 +1357,7 @@ static IVAS_REND_AudioConfig parseAudioConfig(
    return IVAS_REND_AUDIO_CONFIG_UNKNOWN;
}

#ifndef FIX_293_EXT_RENDERER_CLI
static const CmdLnParser_Option *findOptionById(
    const int32_t id )
{
@@ -1326,6 +1371,7 @@ static const CmdLnParser_Option *findOptionById(

    return NULL;
}
#endif

static bool checkRequiredArgs(
    CmdlnArgs args )
@@ -1619,6 +1665,24 @@ void IsmPositionProvider_getNextFrame(

    for ( objIdx = 0; objIdx < positionProvider->numObjects; ++objIdx )
    {
#ifdef FIX_293_EXT_RENDERER_CLI
        /* If ISM metadata reader is open, read from metadata file */
        if ( positionProvider->ismReaders[objIdx] != NULL )
        {
            getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx );
        }
        /* Otherwise, if positions were provided in a scene description file, use them */
        else if ( positionProvider->positions[objIdx] != NULL )
        {
            readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx );
        }
        /* Otherwise fall back to default position */
        else
        {
            objectMetadataBuffer->positions[objIdx].azimuth = 0.0f;
            objectMetadataBuffer->positions[objIdx].elevation = 0.0f;
        }
#else
        if ( positionProvider->ismReaders[objIdx] != NULL )
        {
            getMetadataFromFileReader( positionProvider->ismReaders[objIdx], objectMetadataBuffer, objIdx );
@@ -1627,6 +1691,7 @@ void IsmPositionProvider_getNextFrame(
        {
            readFromShorthandMetadata( positionProvider, objectMetadataBuffer, objIdx );
        }
#endif

        /* Wrap azimuth to lie within (-180, 180] range */
        while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f )
@@ -2014,7 +2079,11 @@ static void parseMasa(
    if ( strncmp( line, "MASA", 4 ) != 0 )
    {
        char numTcs = *line;
#ifdef FIX_293_EXT_RENDERER_CLI
        snprintf( line, 6 /* write at most 6 characters: MASAx + null termination */, "MASA%c", numTcs );
#else
        sprintf( line, "MASA%c", numTcs );
#endif
    }

    inConfig->masaBuses[idx].audioConfig = parseAudioConfig( line );
+1 −0
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@
#define ENV_STAB_FIX                                    /* Contribution 23: HQ envelope stability memory fix */
#define STABILIZE_GIPD                                  /* FhG: Contribution 22: gIPD stabilization */
#define FIX_292_VBAP_CALLOC_REMOVAL                     /* Nokia: Fixes issue 292 by removing the remnant callocs */
#define FIX_293_EXT_RENDERER_CLI                        /* FhG: Fix bugs in external renderer CLI */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+4 −0
Original line number Diff line number Diff line
@@ -2563,7 +2563,11 @@ static IVAS_REND_InputId makeInputId(
    /* Put config type in second byte (from LSB), put index + 1 in first byte
     *
     * Index is incremented here so that a valid ID can never be 0. */
#ifdef FIX_293_EXT_RENDERER_CLI
    return (IVAS_REND_InputId) ( ( ( (uint32_t) getAudioConfigType( config ) ) << 8 ) | ( inputIndex + 1 ) );
#else
    return (IVAS_REND_InputId) ( ( getAudioConfigType( config ) << 8 ) | ( inputIndex + 1 ) );
#endif
}

static ivas_error getInputById(
+8 −0
Original line number Diff line number Diff line
@@ -64,7 +64,11 @@ ivas_error IsmFileWriter_open(
    FILE *file;

    strncpy( metadata_filename_loc, filePathWav, sizeof( metadata_filename_loc ) - 1 );
#ifdef FIX_293_EXT_RENDERER_CLI
    snprintf( ext_meta, sizeof( ext_meta ), ".%d.csv", obj_num );
#else
    sprintf( ext_meta, ".%d.csv", obj_num );
#endif
    const int32_t maxNumCharactersToAppend = (int32_t) sizeof( metadata_filename_loc ) - strlen( metadata_filename_loc ) - 1;
    strncat( metadata_filename_loc, ext_meta, maxNumCharactersToAppend );

@@ -116,7 +120,11 @@ ivas_error IsmFileWriter_writeFrame(
    file = ismWriter->file;

    /* IVAS_fmToDo: work in progress; currently position_azimuth, position_elevation, position_radius, spread, gain_factor */
#ifdef FIX_293_EXT_RENDERER_CLI
    snprintf( char_buff, sizeof( char_buff ), "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor );
#else
    sprintf( char_buff, "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor );
#endif

    if ( file )
    {
+4 −0
Original line number Diff line number Diff line
@@ -66,7 +66,11 @@ static void getExtMasaMetadataFileName(
    /* sizeof( ext_meta ) accounts for terminating NULL, don't subtract extra 1 */
    const int32_t maxNameLenWithoutExt = sizeof( metadata_filename[0] ) - sizeof( ext_meta );
    strncpy( metadata_filename[0], outputWavFilename, maxNameLenWithoutExt );
#ifdef FIX_293_EXT_RENDERER_CLI
    snprintf( ext_meta, sizeof( ext_meta ), ".met" );
#else
    sprintf( ext_meta, ".met" );
#endif

    /* strlen( metadata_filename[0] ) doesn't account for terminating NULL, subtract extra 1 */
    const int32_t maxNumCharactersToAppend = (int32_t) ( sizeof( metadata_filename[0] ) - strlen( metadata_filename[0] ) - 1 );