Commit 40f3499a authored by sagnowski's avatar sagnowski
Browse files

Update external renderer and corresponding tests

Includes:
    - Bug fixes
    - Improvements to tests
    - Fix for build issues with Make
    - Framework changes in preparation for MASA rendering
parent 7bec4a3b
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -242,6 +242,7 @@ external-renderer-cmake-asan-pytest:
  needs: [ "build-codec-linux-cmake" ]
  stage: test
  script:
    - python3 ci/disable_ram_counting.py
    - cmake -B cmake-build -G "Unix Makefiles" -DCLANG=asan
    - cmake --build cmake-build -- -j
    - python3 -m pytest scripts/tests/test_renderer.py --capture=no --tb=no -n auto
@@ -254,6 +255,7 @@ external-renderer-cmake-msan-pytest:
  needs: [ "build-codec-linux-cmake" ]
  stage: test
  script:
    - python3 ci/disable_ram_counting.py
    - cmake -B cmake-build -G "Unix Makefiles" -DCLANG=msan
    - cmake --build cmake-build -- -j
    - python3 -m pytest scripts/tests/test_renderer.py --capture=no --tb=no -n auto
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ $(CLI_APIDEC): $(OBJS_CLI_APIDEC) $(LIB_LIBDEC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(L
	$(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIDEC) -L. -livasdec -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIDEC)

$(CLI_APIREND): $(OBJS_CLI_APPREND) $(LIB_LIBREND) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG)
	$(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPREND) -L. -livasrend -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIREND)
	$(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPREND) -L. -livasrend -livasutil -livascom -livasdebug $(LDLIBS) -o $(CLI_APIREND)

$(CLI_UTESTS_CREND): $(OBJS_CLI_UTESTS_CREND) $(LIB_LIBDEC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG)
	$(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_UTESTS_CREND) -L. -livasdec -livascom -livasutil -livasdebug $(LDLIBS) -o $(UTESTS_CREND_DIR)/$(CLI_UTESTS_CREND)
+145 −16
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "lib_rend.h"
#include "ls_custom_file_reader.h"
#include "render_config_reader.h"
#include "masa_file_reader.h"
#include "ivas_stat_dec.h"
#include "prot.h"
#ifdef WMOPS
@@ -178,6 +179,9 @@ static IVAS_REND_Ambisonics ambisonicsOrderToEnum(
static IVAS_REND_Ambisonics audioCfgToAmbiEnum(
    AUDIO_CONFIG cfg );

static IVAS_REND_MasaTc audioCfgToMasaEnum(
    AUDIO_CONFIG cfg );

static IVAS_REND_SpeakerLayout speakerLayoutCicpToEnum(
    int32_t cicpIndex );

@@ -196,7 +200,8 @@ static void parseConfigFile(
    char *path,
    char *audioFilePath,
    IVAS_REND_InputConfig *inConfig,
    IsmPositionProvider *positionProvider );
    IsmPositionProvider *positionProvider,
    char *masaMetadataFilePath );

static void parseCustomLayoutFile(
    char *filePath,
@@ -271,11 +276,17 @@ static void parseMc(
    IVAS_REND_InputConfig *inConfig,
    int32_t idx );

static void parseMasa(
    char *line,
    IVAS_REND_InputConfig *inConfig,
    char *masaMetadataFilePath );

static void parseMetadata(
    char *metadataString,
    char *inDir,
    IVAS_REND_InputConfig *inConfig,
    IsmPositionProvider *positionProvider );
    IsmPositionProvider *positionProvider,
    char *masaMetadataFilePath );

static void convert_backslash(
    char *str );
@@ -294,6 +305,7 @@ int32_t main( int32_t argc, char **argv )
    IsmPositionProvider *positionProvider;
    RenderConfigReader *renderConfigReader = NULL;
    char audioFilePath[FILENAME_MAX];
    char masaMetadataFilePath[FILENAME_MAX];
    AudioFileReader *audioReader = NULL;
    int16_t numInChannels;
    AudioFileWriter *audioWriter;
@@ -332,6 +344,8 @@ int32_t main( int32_t argc, char **argv )
    hIvasRend = IVAS_REND_Open();
    positionProvider = IsmPositionProvider_open();

    masaMetadataFilePath[0] = '\0';

    convert_backslash( args.inputFilePath );
    convert_backslash( args.outputFilePath );
    convert_backslash( args.trajectoryFile );
@@ -355,7 +369,7 @@ int32_t main( int32_t argc, char **argv )
    if ( args.inputFormat == AUDIO_CONFIG_INVALID || args.inputFormat == AUDIO_CONFIG_META )
    {
        /* Only parse config file if input config is none */
        parseConfigFile( args.inputFilePath, audioFilePath, &args.inConfig, positionProvider );
        parseConfigFile( args.inputFilePath, audioFilePath, &args.inConfig, positionProvider, masaMetadataFilePath );
    }
    else
    {
@@ -415,6 +429,21 @@ int32_t main( int32_t argc, char **argv )
    }

    /* === Process === */
    MasaFileReader *masaReader = NULL;
    IVAS_MASA_METADATA_HANDLE hMasaMetadata = NULL;

    if ( masaMetadataFilePath[0] != '\0' )
    {
        masaReader = MasaFileReader_open( masaMetadataFilePath );
        if ( masaReader == NULL )
        {
            fprintf( stderr, "Could not open MASA metadata file %s\n", masaMetadataFilePath );
            exit( -1 );
        }

        hMasaMetadata = MasaFileReader_getMetadataHandle( masaReader );
    }

    if ( AudioFileWriter_open( &audioWriter, args.outputFilePath, args.sampleRate, IVAS_REND_GetOutChannels( hIvasRend ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "Failed to open file: %s\n", args.outputFilePath );
@@ -490,6 +519,17 @@ int32_t main( int32_t argc, char **argv )
            }
        }

        if ( masaReader != NULL )
        {
            MasaFileReader_readNextFrame( masaReader );

            if ( ( error = IVAS_REND_FeedMasaMetadata(hIvasRend, hMasaMetadata) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
        }

        IVAS_REND_AudioObjectMetadataBuffer mtdBuffer;
        IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer );

@@ -582,6 +622,7 @@ int32_t main( int32_t argc, char **argv )
    count_free( inFloatBuffer );
    count_free( outInt16Buffer );
    count_free( outFloatBuffer );
    MasaFileReader_close( &masaReader );
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );
    HeadRotationFileReader_close( &headRotReader );
@@ -611,6 +652,17 @@ static int8_t setInConfig( int16_t numChannels, AUDIO_CONFIG input_config, IVAS_

    success = 1;

    if ( input_config == AUDIO_CONFIG_META )
    {
        /* inConfig already set from metadata file, return early */
        return 0;
    }

    inConfig->numAudioObjects = 0;
    inConfig->numAmbisonicsBuses = 0;
    inConfig->numMultiChannelBuses = 0;
    inConfig->numMasaBuses = 0;

    switch ( input_config )
    {
        case AUDIO_CONFIG_MONO:
@@ -621,8 +673,6 @@ static int8_t setInConfig( int16_t numChannels, AUDIO_CONFIG input_config, IVAS_
        case AUDIO_CONFIG_5_1_4:
        case AUDIO_CONFIG_7_1_4:
        case AUDIO_CONFIG_LS_CUSTOM:
            inConfig->numAudioObjects = 0;
            inConfig->numAmbisonicsBuses = 0;
            inConfig->numMultiChannelBuses = 1;
            inConfig->multiChannelBuses[0].speakerLayout = audioCfgToMcEnum( input_config );
            inConfig->multiChannelBuses[0].inputChannelIndex = 0;
@@ -631,8 +681,6 @@ static int8_t setInConfig( int16_t numChannels, AUDIO_CONFIG input_config, IVAS_
        case AUDIO_CONFIG_FOA:
        case AUDIO_CONFIG_HOA2:
        case AUDIO_CONFIG_HOA3:
            inConfig->numAudioObjects = 0;
            inConfig->numMultiChannelBuses = 0;
            inConfig->numAmbisonicsBuses = 1;
            inConfig->ambisonicsBuses[0].ambisonicsConfig = audioCfgToAmbiEnum( input_config );
            inConfig->ambisonicsBuses[0].inputChannelIndex = 0;
@@ -642,8 +690,6 @@ static int8_t setInConfig( int16_t numChannels, AUDIO_CONFIG input_config, IVAS_
        case AUDIO_CONFIG_ISM2:
        case AUDIO_CONFIG_ISM3:
        case AUDIO_CONFIG_ISM4:
            inConfig->numAmbisonicsBuses = 0;
            inConfig->numMultiChannelBuses = 0;
            inConfig->numAudioObjects = numChannels;
            positionProvider->numObjects = numChannels;

@@ -665,7 +711,12 @@ static int8_t setInConfig( int16_t numChannels, AUDIO_CONFIG input_config, IVAS_
                positionProvider->positionDurations[i][0] = 1;
            }
            break;
        case AUDIO_CONFIG_META:
        case AUDIO_CONFIG_MASA1:
        case AUDIO_CONFIG_MASA2:
            inConfig->numMasaBuses = 1;
            inConfig->masaBus.numTc = audioCfgToMasaEnum( input_config );
            inConfig->masaBus.inputChannelIndex = 0;
            inConfig->masaBus.gain_dB = 0;
            break;
        default:
            success = 0;
@@ -714,6 +765,21 @@ static IVAS_REND_Ambisonics audioCfgToAmbiEnum( AUDIO_CONFIG cfg )
    return IVAS_REND_AMBISONICS_NONE;
}

static IVAS_REND_MasaTc audioCfgToMasaEnum( AUDIO_CONFIG cfg )
{
    switch ( cfg )
    {
        case AUDIO_CONFIG_MASA1:
            return IVAS_REND_MASA_TC_1;
        case AUDIO_CONFIG_MASA2:
            return IVAS_REND_MASA_TC_2;
        default:
            break;
    }

    return IVAS_REND_MASA_TC_NONE;
}

static IVAS_REND_SpeakerLayout speakerLayoutCicpToEnum( int32_t cicpIndex )
{
    switch ( cicpIndex )
@@ -833,8 +899,15 @@ static AUDIO_CONFIG parseStrToAudioCfg( char *config_str )
    }
    else if ( strncmp( format, "MASA", 4 ) == 0 )
    {
        parseUint8( &format[4], &numObjects );
        return AUDIO_CONFIG_MASA1 + numObjects - 1;
        switch ( format[4] )
        {
            case '1':
                return AUDIO_CONFIG_MASA1;
            case '2':
                return AUDIO_CONFIG_MASA2;
            default:
                return AUDIO_CONFIG_INVALID;
        }
    }
    else if ( strncmp( format, "META", 4 ) == 0 )
    {
@@ -900,6 +973,7 @@ static int8_t parseInFormat( char **optionValues, CmdlnArgs *args )
        case AUDIO_CONFIG_EXTERNAL:
            fprintf( stderr, "No rendering possible for EXT format!\n" );
            success = 0;
            break;
        default:
            args->numAudioObjects = 0;
    }
@@ -942,6 +1016,7 @@ static int8_t parseOutConfig( char *configString, IVAS_REND_OutputConfig *outCon
        case AUDIO_CONFIG_LS_CUSTOM:
            outConfig->speakerLayout = IVAS_REND_SPEAKER_LAYOUT_CUSTOM;
            parseCustomLayoutFile( configString, &outConfig->outSetupCustom );
            break;
        case AUDIO_CONFIG_FOA:
        case AUDIO_CONFIG_HOA2:
        case AUDIO_CONFIG_HOA3:
@@ -1546,7 +1621,7 @@ static void parseOptionalInputValues(
    parse_pos = readNextMetadataChunk( line, "\n" );

    /* Look for optional metadata until end of string or next input identifier is found */
    while ( parse_pos != NULL && strcmp( line, "MC" ) != 0 && strcmp( line, "SBA" ) != 0 && strcmp( line, "ISM" ) != 0 )
    while ( parse_pos != NULL && strcmp( line, "MC" ) != 0 && strcmp( line, "SBA" ) != 0 && strcmp( line, "ISM" ) != 0 && strcmp( line, "MASA" ) != 0 )
    {
        key = strtok( line, ":" );
        value = strtok( NULL, "\n" );
@@ -1692,6 +1767,36 @@ static void parseMc( char *line,
    parseOptionalInputValues( line, &inConfig->multiChannelBuses[idx].gain_dB );
}

static void parseMasa(
    char *line,
    IVAS_REND_InputConfig *inConfig,
    char *masaMetadataFilePath )
{
    AUDIO_CONFIG cfg;

    readNextMetadataChunk( line, "\n" );
    parseUint8( line, &inConfig->masaBus.inputChannelIndex );
    --inConfig->masaBus.inputChannelIndex; /* Convert from 1-indexing */

    readNextMetadataChunk( line, "\n" );

    /* Allow both just the number of TCs or MASAx. parseStrToAudioCfg() only accepts MASAx, so prepend if necessary. */
    if ( strncmp( line, "MASA", 4 ) != 0 )
    {
        char numTcs = *line;
        sprintf( line, "MASA%c", numTcs );
    }

    cfg = parseStrToAudioCfg( line );
    inConfig->masaBus.numTc = audioCfgToMasaEnum( cfg );

    readNextMetadataChunk( line, "\n" );
    strcpy( masaMetadataFilePath, line );

    /* Read optional values */
    parseOptionalInputValues( line, &inConfig->masaBus.gain_dB );
}

static void parseCustomLayoutFile(
    char *filePath,
    IVAS_LSSETUP_CUSTOM_HANDLE *hLsSetupCustom )
@@ -1735,7 +1840,8 @@ static void parseMetadata(
    char *metadataString,
    char *inDir,
    IVAS_REND_InputConfig *inConfig,
    IsmPositionProvider *positionProvider )
    IsmPositionProvider *positionProvider,
    char *masaMetadataFilePath )
{
    char line[RENDERER_MAX_METADATA_LINE_LENGTH];
    char *delimiter;
@@ -1744,6 +1850,7 @@ static void parseMetadata(
    uint8_t counterChannelAudioObjects;
    uint8_t counterAmbisonicsAudioObjects;
    uint8_t counterMonoAudioObjects;
    uint8_t counterMasaInputs;
    uint8_t num_parsed_inputs;

    delimiter = "\n";
@@ -1771,6 +1878,7 @@ static void parseMetadata(
    counterChannelAudioObjects = 0;
    counterAmbisonicsAudioObjects = 0;
    counterMonoAudioObjects = 0;
    counterMasaInputs = 0;

    readNextMetadataChunk( line, delimiter );

@@ -1807,6 +1915,16 @@ static void parseMetadata(
            }
            parseIsm( line, inDir, inConfig, positionProvider, counterMonoAudioObjects - 1 );
        }
        else if ( strcmp( line, "MASA" ) == 0 )
        {
            ++counterMasaInputs;
            if ( counterMasaInputs > RENDERER_MAX_MASA_INPUTS )
            {
                fprintf( stderr, "Metadata exceeds the supported number of MASA inputs\n" );
                exit( -1 );
            }
            parseMasa( line, inConfig, masaMetadataFilePath );
        }
        else if ( line[0] == '\0' )
        {
            fprintf( stderr, "Metadata string too short - expected %d inputs, found %d.\n", totalNumberOfAudioObjects, num_parsed_inputs );
@@ -1824,6 +1942,7 @@ static void parseMetadata(
    inConfig->numAudioObjects = counterMonoAudioObjects;
    inConfig->numAmbisonicsBuses = counterAmbisonicsAudioObjects;
    inConfig->numMultiChannelBuses = counterChannelAudioObjects;
    inConfig->numMasaBuses = counterMasaInputs;
    positionProvider->numObjects = counterMonoAudioObjects;

    /* check for trailing text */
@@ -1835,15 +1954,17 @@ static void parseMetadata(
    }
}

void parseConfigFile( char *path, char *audioFilePath, IVAS_REND_InputConfig *inConfig, IsmPositionProvider *positionProvider )
void parseConfigFile( char *path, char *audioFilePath, IVAS_REND_InputConfig *inConfig, IsmPositionProvider *positionProvider, char *masaMetadataFilePath )
{
    uint32_t inAudioFilePathLen;
    char inAudioFilePath[FILENAME_MAX];
    char inMasaFilePath[FILENAME_MAX];
    uint32_t mtdStrLen;
    char mtdStr[RENDERER_MAX_METADATA_LENGTH];
    char inDir[FILENAME_MAX];
    char *lastSlash = NULL;

    inMasaFilePath[0] = '\0';
    inAudioFilePathLen = FILENAME_MAX;
    mtdStrLen = RENDERER_MAX_METADATA_LENGTH;
    splitConfigFile( path,
@@ -1868,7 +1989,15 @@ void parseConfigFile( char *path, char *audioFilePath, IVAS_REND_InputConfig *in
    strcpy( audioFilePath, inDir );
    strncat( audioFilePath, inAudioFilePath, inAudioFilePathLen );

    parseMetadata( mtdStr, inDir, inConfig, positionProvider );
    parseMetadata( mtdStr, inDir, inConfig, positionProvider, inMasaFilePath );

    /* Append MASA file path (relative to config file location)
     * to config file location path to get full absolute path */
    if ( inMasaFilePath[0] != '\0' )
    {
        strcpy( masaMetadataFilePath, inDir );
        strcat( masaMetadataFilePath, inMasaFilePath );
    }
}

static void convert_backslash( char *str )
+20 −0
Original line number Diff line number Diff line
import re
import os

FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "lib_com", "options.h")
RE_TO_COMMENT_OUT = re.compile(r"#define\s+RAM_COUNTING_TOOL")


def main():
    with open(FILE_PATH, "r", encoding="utf-8") as file:
        lines = file.readlines()

    for i, line in enumerate(lines):
        lines[i] = RE_TO_COMMENT_OUT.sub(lambda x: f"/* {x.group(0)} */", line)

    with open(FILE_PATH, "w", encoding="utf-8") as file:
        file.writelines(lines)


if __name__ == "__main__":
    main()
+281 −53

File changed.

Preview size limit exceeded, changes collapsed.

Loading