Commit d905319d authored by bayers's avatar bayers
Browse files

fix #899: fix build problem with VARIABLE_SPEED_DECODING enabled, fix general...

fix #899: fix build problem with VARIABLE_SPEED_DECODING enabled, fix general variable speed decoding issues, i.e. make sure TSM is applied as much as possible according to the chosen scaling
parent 332bc972
Loading
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
#endif
#ifdef VARIABLE_SPEED_DECODING
#include "tsm_scale_file_reader.h"
#include <math.h>
#endif
#include "vector3_pair_file_reader.h"
#ifdef DEBUGGING
@@ -1224,7 +1225,9 @@ static bool parseCmdlIVAS_dec(
            i++;
            int32_t tmp = 100;
            arg->tsmEnabled = true;
#ifndef NONBE_UNIFIED_DECODING_PATHS
            arg->enable5ms = true;
#endif
            if ( i < argc - 3 )
            {
                if ( !is_digits_only( argv[i] ) )
@@ -2120,6 +2123,7 @@ static ivas_error decodeG192(
    /* we always start with needing a new frame */
    needNewFrame = true;

#ifndef FIX_899_VARIABLE_SPEED_DECODING
#ifdef DEBUGGING
#ifdef VARIABLE_SPEED_DECODING
    /*------------------------------------------------------------------------------------------*
@@ -2146,6 +2150,7 @@ static ivas_error decodeG192(
        }
    }
#endif
#endif
#endif

    if ( !arg.quietModeEnabled )
@@ -2191,6 +2196,45 @@ static ivas_error decodeG192(
    }
#endif

#ifdef FIX_899_VARIABLE_SPEED_DECODING
#ifdef DEBUGGING
#ifdef VARIABLE_SPEED_DECODING
    /*------------------------------------------------------------------------------------------*
     * Open TSM scale file or set global TSM scale
     *------------------------------------------------------------------------------------------*/

    if ( arg.tsmEnabled )
    {
        if ( arg.tsmScaleFileEnabled )
        {
            if ( ( tsmScaleFileReader = TsmScaleFileReader_open( arg.tsmScaleFileName ) ) == NULL )
            {
                fprintf( stderr, "\nError: Can't open TSM scale file %s \n\n", arg.tsmScaleFileName );
                goto cleanup;
            }
        }
        else
        {
            int16_t maxScaling;
            /* max scaling as abs diff to the normal frame size in samples */
            maxScaling = (int16_t) ceilf( (float) abs( arg.tsmScale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) );
            if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
        /* set lowest possbile TSM quality to make sure it is applied as much as possible */
        if ( ( error = IVAS_DEC_TSM_SetQuality( hIvasDec, -2.0f ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nIVAS_DEC_TSM_SetQuality failed: %s \n", IVAS_DEC_GetErrorMessage( error ) );
            goto cleanup;
        }
    }
#endif
#endif
#endif

    /*------------------------------------------------------------------------------------------*
     * Loop for every packet (frame) of bitstream data
     * - Read the bitstream packet
@@ -2343,7 +2387,14 @@ static ivas_error decodeG192(
                        fprintf( stderr, "\nError: input bitstream file couldn't be read: %s \n\n", arg.inputBitstreamFilename );
                        goto cleanup;
                    }
#ifdef FIX_899_VARIABLE_SPEED_DECODING
                    int16_t maxScaling;
                    /* max scaling as abs diff to the normal frame size in samples */
                    maxScaling = (int16_t) ceilf( (float) abs( arg.tsmScale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) );
                    if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK )
#else
                    if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, scale, scale ) ) != IVAS_ERR_OK )
#endif
                    {
                        fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
@@ -2415,6 +2466,22 @@ static ivas_error decodeG192(
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif
#ifdef FIX_899_VARIABLE_SPEED_DECODING
            if ( needNewFrame )
            {
                frame++;
                if ( !arg.quietModeEnabled )
                {
                    fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
#ifdef DEBUGGING
                    if ( IVAS_DEC_GetBerDetectFlag( hIvasDec ) )
                    {
                        fprintf( stdout, "\n   Decoding error: BER detected in frame %d !!!!!\n", frame - 1 );
                    }
#endif
                }
            }
#endif

        } while ( nSamplesRendered < nOutSamples && error == IVAS_ERR_OK );

@@ -2538,6 +2605,7 @@ static ivas_error decodeG192(
            }
        }
        vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len;
#ifndef FIX_899_VARIABLE_SPEED_DECODING
        if ( needNewFrame )
        {
            frame++;
@@ -2552,6 +2620,7 @@ static ivas_error decodeG192(
#endif
            }
        }
#endif
#ifdef WMOPS
        if ( vec_pos_update == 0 )
        {
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@
#define FIX_643_PCA_OPTION                              /* VA: issue 643: rename PCA bypass command-line option */

/* #################### End BE switches ################################## */

#define FIX_899_VARIABLE_SPEED_DECODING                       /* FhG: Fix variable speed decoding                                    */

/* #################### Start NON-BE switches ############################ */
/* any switch which is non-be wrt selection floating point code */
+49 −3
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ struct IVAS_DEC
    bool Opt_VOIP;           /* flag indicating VOIP mode with JBM */
    int16_t tsm_scale;       /* scale for TSM operation */
    int16_t tsm_max_scaling;
#ifdef FIX_899_VARIABLE_SPEED_DECODING
    float tsm_quality;
#endif
    float *apaExecBuffer; /* Buffer for APA scaling */
    PCMDSP_APA_HANDLE hTimeScaler;
    bool needNewFrame;
@@ -163,6 +166,10 @@ ivas_error IVAS_DEC_Open(
    hIvasDec->apaExecBuffer = NULL;
    hIvasDec->hTimeScaler = NULL;
    hIvasDec->tsm_scale = 100;
#ifdef FIX_899_VARIABLE_SPEED_DECODING
    hIvasDec->tsm_max_scaling = 0;
    hIvasDec->tsm_quality = 1.0f;
#endif
    hIvasDec->needNewFrame = false;
    hIvasDec->nTransportChannelsOld = 0;
    hIvasDec->nSamplesAvailableNext = 0;
@@ -488,7 +495,12 @@ ivas_error IVAS_DEC_Configure(
    hIvasDec->nSamplesAvailableNext = 0;
    hIvasDec->nSamplesRendered = 0;
    hIvasDec->tsm_scale = 100;
#ifdef FIX_899_VARIABLE_SPEED_DECODING
    hIvasDec->tsm_max_scaling = 0;
    hIvasDec->tsm_quality = 1.0f;
#else
    hIvasDec->tsm_max_scaling = 100;
#endif

    return error;
}
@@ -2528,8 +2540,8 @@ ivas_error IVAS_DEC_VoIP_FeedFrame(

ivas_error IVAS_DEC_VoIP_SetScale(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                                         */
    const int16_t maxScaling,
    const int16_t scale /* i  : TSM scale to set                            */
    const int16_t maxScaling, /* i  : max allowed absolute difference in samples from the default 20ms frame size */
    const int16_t scale       /* i  : TSM scale to set in percent of the default frame size                       */
)
{
    ivas_error error;
@@ -2549,6 +2561,36 @@ ivas_error IVAS_DEC_VoIP_SetScale(
    return error;
}

#ifdef FIX_899_VARIABLE_SPEED_DECODING
/*---------------------------------------------------------------------*
 * IVAS_DEC_VoIP_SetScale( )
 *
 * Set the TSM scale
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_TSM_SetQuality(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                                         */
    const float quality       /* i  : target TSM quality                                                          */
)
{
    ivas_error error;

    error = IVAS_ERR_OK;

    if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false )
    {
        return IVAS_ERR_TSM_NOT_ENABLED;
    }
    else
    {
        hIvasDec->tsm_quality = quality;
    }

    return error;
}

#endif


/*---------------------------------------------------------------------*
 * IVAS_DEC_VoIP_GetSamples( )
@@ -3634,7 +3676,11 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(
            uint16_t wss, css;
            float startQuality;

#ifdef FIX_899_VARIABLE_SPEED_DECODING
            startQuality = hIvasDec->tsm_quality;
#else
            startQuality = 1.0f;
#endif
            apa_buffer_size = APA_BUF_PER_CHANNEL;

            /* get current renderer type*/
+7 −0
Original line number Diff line number Diff line
@@ -266,6 +266,13 @@ ivas_error IVAS_DEC_VoIP_SetScale(
    const int16_t scale                         /* i  : TSM scale to set                                                        */
);

#ifdef FIX_899_VARIABLE_SPEED_DECODING
ivas_error IVAS_DEC_TSM_SetQuality(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                                         */
	const float quality       /* i  : target TSM quality                                                          */
);
#endif

/*! r: error code */
ivas_error IVAS_DEC_VoIP_GetSamples(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */