Commit 7b16a271 authored by sagnowski's avatar sagnowski
Browse files

lib_rend: check validity of I/O config

parent 01c1860e
Loading
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ typedef enum
    IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT,
    IVAS_ERR_ISM_INVALID_METADATA_VALUE,
    IVAS_ERR_INVALID_MASA_FORMAT_METADATA_FILE,
#ifdef FIX_372_LIB_REND_VALIDATE_IO
    IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED,
#endif
#ifdef DEBUGGING
    IVAS_ERR_INVALID_FORCE_MODE,
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
@@ -145,18 +148,7 @@ typedef enum

static inline const char *ivas_error_to_string( ivas_error error_code )
{
    /* For error categories that are likely to still have many changes to
     * specific error codes, return one string per category */
    if ( ( error_code & 0xF000 ) == 0x1000 )
    {
        return "API error";
    }
    if ( ( error_code & 0xF000 ) == 0x2000 )
    {
        return "data error";
    }

    /* For categories that are unlikely to change, use more specific strings */
    /* Try to match to a specific string */
    switch ( error_code )
    {
        case IVAS_ERR_OK:
@@ -179,6 +171,10 @@ static inline const char *ivas_error_to_string( ivas_error error_code )
            return "Wrong number of channels";
        case IVAS_ERR_INVALID_BUFFER_SIZE:
            return "Invalid buffer size";
#ifdef FIX_372_LIB_REND_VALIDATE_IO
        case IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED:
            return "Unsupported input/output config pair";
#endif
        case IVAS_ERR_FAILED_FILE_OPEN:
            return "File open error";
        case IVAS_ERR_FAILED_FILE_WRITE:
@@ -193,6 +189,17 @@ static inline const char *ivas_error_to_string( ivas_error error_code )
            break;
    }

    /* For error categories that are likely to still have many changes to
     * specific error codes, return one string per category */
    if ( ( error_code & 0xF000 ) == 0x1000 )
    {
        return "API error";
    }
    if ( ( error_code & 0xF000 ) == 0x2000 )
    {
        return "data error";
    }

    return "Unknown error";
}

+1 −0
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@
#define ISM_HIGHEST_BITRATE                             /* VA: Issue 284: Update highest bitrate limit in ISM format */
#define TUNE_360_OBJECT_WITH_NOISE                      /* VA: issue 360: consider objects being speech+noise for active speech coding */
#define FIX_350_MASA_DELAY_COMP                         /* Nokia: Issue 350: MASA audio/meta delay compensation */
#define FIX_372_LIB_REND_VALIDATE_IO                    /* FhG: Issue 372: IVAS_rend segfaults with unsupported I/O configs - add validation checks of I/O config */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+43 −0
Original line number Diff line number Diff line
@@ -1050,6 +1050,21 @@ static CREND_WRAPPER defaultCrendWrapper(
    return w;
}

#ifdef FIX_372_LIB_REND_VALIDATE_IO
static bool isIoConfigPairSupported( IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig )
{
    /* Rendering mono or stereo to binaural is not supported */
    if ( ( inConfig == IVAS_REND_AUDIO_CONFIG_MONO || inConfig == IVAS_REND_AUDIO_CONFIG_STEREO ) &&
         getAudioConfigType( outConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL )
    {
        return false;
    }

    /* If not returned so far, config pair is supported */
    return true;
}
#endif

static ivas_error setRendInputActiveIsm(
    void *input,
    const IVAS_REND_AudioConfig inConfig,
@@ -1065,6 +1080,13 @@ static ivas_error setRendInputActiveIsm(
    rendCtx = inputIsm->base.ctx;
    outConfig = *rendCtx.pOutConfig;

#ifdef FIX_372_LIB_REND_VALIDATE_IO
    if ( !isIoConfigPairSupported( inConfig, outConfig ) )
    {
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }
#endif

    initRendInputBase( &inputIsm->base, inConfig, id, rendCtx );

    inputIsm->currentPos = defaultObjectPosition();
@@ -1956,6 +1978,13 @@ static ivas_error setRendInputActiveMc(
    rendCtx = inputMc->base.ctx;
    outConfig = *rendCtx.pOutConfig;

#ifdef FIX_372_LIB_REND_VALIDATE_IO
    if ( !isIoConfigPairSupported( inConfig, outConfig ) )
    {
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }
#endif

    initRendInputBase( &inputMc->base, inConfig, id, rendCtx );
    setZeroPanMatrix( inputMc->panGains );
    inputMc->customLsInput = defaultCustomLs();
@@ -2216,6 +2245,13 @@ static ivas_error setRendInputActiveSba(
    rendCtx = inputSba->base.ctx;
    outConfig = *rendCtx.pOutConfig;

#ifdef FIX_372_LIB_REND_VALIDATE_IO
    if ( !isIoConfigPairSupported( inConfig, outConfig ) )
    {
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }
#endif

    initRendInputBase( &inputSba->base, inConfig, id, rendCtx );
    setZeroPanMatrix( inputSba->hoaDecMtx );
#ifdef FIX_197_CREND_INTERFACE
@@ -2618,6 +2654,13 @@ static ivas_error setRendInputActiveMasa(
    outConfig = *rendCtx.pOutConfig;
    (void) hRendCfg; /* Suppress warning */

#ifdef FIX_372_LIB_REND_VALIDATE_IO
    if ( !isIoConfigPairSupported( inConfig, outConfig ) )
    {
        return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED;
    }
#endif

    initRendInputBase( &inputMasa->base, inConfig, id, rendCtx );

    if ( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ) != IVAS_ERR_OK )