Commit 5f3531bd authored by vaclav's avatar vaclav
Browse files

add sanitizeBitrateISM() to properly exit when the switched bitarte is not...

add sanitizeBitrateISM() to properly exit when the switched bitarte is not supported; under ISM_BITRATE_SWITCHING
parent 26340949
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas );
static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc );
static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc );
static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc );
#ifdef ISM_BITRATE_SWITCHING
static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig );
#endif
static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig );
static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc );
static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth );
@@ -761,6 +764,12 @@ static ivas_error configureEncoder(
        }
        else if ( hEncoderConfig->ivas_format == ISM_FORMAT )
        {
#ifdef ISM_BITRATE_SWITCHING
            if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK )
            {
                return error;
            }
#else
            if ( hEncoderConfig->ivas_total_brate > IVAS_256k )
            {
                return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
@@ -777,6 +786,7 @@ static ivas_error configureEncoder(
            {
                return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
            }
#endif
        }
        else if ( hEncoderConfig->ivas_format == SBA_FORMAT )
        {
@@ -1625,6 +1635,9 @@ static ivas_error setBitrate(
{
    Encoder_Struct *st_ivas;
    ENCODER_CONFIG_HANDLE hEncoderConfig;
#ifdef ISM_BITRATE_SWITCHING
    ivas_error error;
#endif

    st_ivas = hIvasEnc->st_ivas;
    hEncoderConfig = st_ivas->hEncoderConfig;
@@ -1671,6 +1684,16 @@ static ivas_error setBitrate(
        }
    }

#ifdef ISM_BITRATE_SWITCHING
    if ( hEncoderConfig->ivas_format == ISM_FORMAT )
    {
        if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
#endif

    st_ivas->codec_mode = MODE1;

    if ( hEncoderConfig->element_mode_init == EVS_MONO )
@@ -1897,6 +1920,41 @@ static ivas_error sanitizeBandwidth(
}


#ifdef ISM_BITRATE_SWITCHING
/*---------------------------------------------------------------------*
 * sanitizeBitrateISM()
 *
 *
 *---------------------------------------------------------------------*/

static ivas_error sanitizeBitrateISM(
    const ENCODER_CONFIG_HANDLE hEncoderConfig )
{
    if ( hEncoderConfig->ivas_total_brate > IVAS_256k )
    {
        return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
    }

    if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 )
    {
        return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
    }

    if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 )
    {
        return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
    }

    if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 )
    {
        return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
    }

    return IVAS_ERR_OK;
}
#endif


/*---------------------------------------------------------------------*
 * setBandwidth()
 *