Commit 46d77135 authored by vaclav's avatar vaclav
Browse files

introduce IVAS_DEC_Restart()

parent e5471e45
Loading
Loading
Loading
Loading
Loading
+29 −25
Original line number Diff line number Diff line
@@ -191,9 +191,7 @@ static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBs
static int16_t app_own_random( int16_t *seed );
#endif
static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader );
#ifdef FIX_FMSW_DEC
static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg );
#else
#ifndef FIX_FMSW_DEC
static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData );
#endif

@@ -2639,6 +2637,13 @@ static ivas_error decodeG192(

                if ( restartNeeded )
                {
#ifdef FIX_FMSW_DEC
                    if ( ( error = IVAS_DEC_Restart( hIvasDec, IVAS_DEC_MODE_IVAS ) ) != IVAS_ERR_OK ) /* note: only switching within IVAS formats is supported in G.192 */
                    {
                        fprintf( stderr, "\nIVAS_DEC_Restart failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }
#else
                    IVAS_DEC_BS_FORMAT tempFormat;
                    if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK )
                    {
@@ -2646,9 +2651,6 @@ static ivas_error decodeG192(
                        goto cleanup;
                    }
                    IVAS_DEC_MODE codecMode = ( tempFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS;
#ifdef FIX_FMSW_DEC
                    if ( ( error = restartDecoder( &hIvasDec, codecMode, &arg ) ) != IVAS_ERR_OK )
#else
                    error = restartDecoder(
                        &hIvasDec,
                        codecMode,
@@ -2661,8 +2663,8 @@ static ivas_error decodeG192(
                        fprintf( stderr, "\nFailed to restart decoder\n" );
                        goto cleanup;
                    }
#endif
                    *phIvasDec = hIvasDec; /* Update for main()' s free */
#endif
                }
#endif

@@ -3430,10 +3432,15 @@ static ivas_error decodeVoIP(
        /* restart decoder in case of format switching */
        if ( ivasRtp.restartNeeded )
        {
            IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS;
#ifdef FIX_FMSW_DEC
            if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, &arg ) ) != IVAS_ERR_OK )
            arg.decMode = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS;
            if ( ( error = IVAS_DEC_Restart( hIvasDec, arg.decMode ) ) != IVAS_ERR_OK ) /* note: switching between EVS and IVAS is supported in RTP */
            {
                fprintf( stderr, "\nIVAS_DEC_Restart failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
#else
            IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS;
            if ( ( error = restartDecoder(
                       &hIvasDec,
                       newDecModeInPacket,
@@ -3441,13 +3448,13 @@ static ivas_error decodeVoIP(
                       renderConfig,
                       NULL /* ToDo : Provide LS Custom Data */
                       ) ) != IVAS_ERR_OK )
#endif
            {
                fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket );
                goto cleanup;
            }

            *phIvasDec = hIvasDec; /* Update for main()' s free */
#endif
            ivasRtp.restartNeeded = false;
            bitstreamReadDone = false;
            parametersAvailableForEditing = false;
@@ -3679,6 +3686,13 @@ static ivas_error decodeVoIP(

                if ( restartNeeded )
                {
#ifdef FIX_FMSW_DEC
                    if ( ( error = IVAS_DEC_Restart( hIvasDec, IVAS_DEC_MODE_IVAS ) ) != IVAS_ERR_OK ) /* note: only switching within IVAS formats is supported in non-RTP VoIP */
                    {
                        fprintf( stderr, "\nIVAS_DEC_Restart failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }
#else
                    IVAS_DEC_BS_FORMAT tempBsFormat;
                    if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK )
                    {
@@ -3687,9 +3701,6 @@ static ivas_error decodeVoIP(
                    }

                    IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS;
#ifdef FIX_FMSW_DEC
                    if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, &arg ) ) != IVAS_ERR_OK )
#else
                    if ( ( error = restartDecoder(
                               &hIvasDec,
                               newDecModeInPacket,
@@ -3697,12 +3708,12 @@ static ivas_error decodeVoIP(
                               NULL, /* ToDo : Provide rendererConfig */
                               NULL  /* ToDo : Provide LS Custom Data */
                               ) ) != IVAS_ERR_OK )
#endif
                    {
                        fprintf( stderr, "\nFailed to restart decoder\n" );
                        goto cleanup;
                    }
                    *phIvasDec = hIvasDec; /* Update for main()' s free */
#endif
                    bitstreamReadDone = false;
                    parametersAvailableForEditing = false;
                }
@@ -4390,7 +4401,7 @@ static ivas_error load_hrtf_from_file(
    return IVAS_ERR_OK;
}


#ifndef FIX_FMSW_DEC
/*---------------------------------------------------------------------*
 * restartDecoder()
 *
@@ -4400,18 +4411,11 @@ static ivas_error load_hrtf_from_file(
static ivas_error restartDecoder(
    IVAS_DEC_HANDLE *phIvasDec,
    const IVAS_DEC_MODE decMode,
    DecArguments *arg
#ifndef FIX_FMSW_DEC
    ,
    DecArguments *arg,
    IVAS_RENDER_CONFIG_DATA *renderConfig,
    IVAS_CUSTOM_LS_DATA *hLsCustomData
#endif
)
    IVAS_CUSTOM_LS_DATA *hLsCustomData )
{
    ivas_error error = IVAS_ERR_OK;
#ifndef FIX_FMSW_DEC
    IVAS_DEC_HANDLE hIvasDec;
#endif

    if ( phIvasDec == NULL )
    {
@@ -4502,5 +4506,5 @@ cleanup:

    return error;
}

#endif
#undef WMC_TOOL_SKIP
+172 −81
Original line number Diff line number Diff line
@@ -129,6 +129,67 @@ static int16_t get_render_frame_size_samples( const DECODER_CONFIG_HANDLE hDecod
static int16_t ivas_dec_split_rend_cldfb_in( const RENDERER_TYPE renderer_type );
static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesRendered );

#ifdef FIX_FMSW_DEC

/*---------------------------------------------------------------------*
 * ivas_dec_handle_init()
 *
 * Set IVAS decoder handles to NULL + set high-level parameters
 *---------------------------------------------------------------------*/

static ivas_error ivas_dec_handle_init(
    Decoder_Struct *st_ivas,       /* i/o: IVAS decoder handle                                                             */
    const IVAS_DEC_MODE mode,      /* i  : compatibility mode (EVS or IVAS)                                                */
    bool *hasDecodedFirstGoodFrame /* o  : flag indicating if the decoder has decoded a good frame since it was configured */
)
{
    if ( st_ivas == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    /* initialize pointers to handles to NULL */
    ivas_initialize_handles_dec( st_ivas );

    st_ivas->restartNeeded = 0;

    /* set high-level parameters */

    st_ivas->codec_mode = 0; /* unknown before first frame */
    st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
    st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
    st_ivas->writeFECoffset = 0;
    st_ivas->sba_analysis_order = 0; /* not really used in EVS mode, but initialize here to fix MSAN complaint */

    if ( mode == IVAS_DEC_MODE_EVS )
    {
        st_ivas->element_mode_init = EVS_MONO;
        st_ivas->ivas_format = MONO_FORMAT;
        *hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */

        return IVAS_ERR_OK;
    }
    else if ( mode == IVAS_DEC_MODE_IVAS )
    {
        st_ivas->element_mode_init = -1;
        st_ivas->ivas_format = UNDEFINED_FORMAT;
        st_ivas->renderer_type = RENDERER_DISABLE;
        st_ivas->ini_frame = 0;
        st_ivas->ini_active_frame = 0;

        st_ivas->ism_mode = ISM_MODE_NONE;
        st_ivas->mc_mode = MC_MODE_NONE;

        st_ivas->sba_order = 0;
        st_ivas->sba_planar = 0;

        return IVAS_ERR_OK;
    }

    return IVAS_ERR_WRONG_PARAMS;
}

#endif

/*---------------------------------------------------------------------*
 * IVAS_DEC_Open()
@@ -145,21 +206,18 @@ ivas_error IVAS_DEC_Open(
    IVAS_DEC_HANDLE hIvasDec;
    Decoder_Struct *st_ivas;

    if ( phIvasDec == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

#ifdef FIX_FMSW_DEC
    if ( ( *phIvasDec ) != NULL && ( *phIvasDec )->st_ivas != NULL && ( *phIvasDec )->st_ivas->restartNeeded != 0 )
    if ( *phIvasDec != NULL )
    {
        hIvasDec = *phIvasDec;

        st_ivas = hIvasDec->st_ivas;
        return IVAS_ERR_WRONG_PARAMS;
    }
    else
#else
    if ( phIvasDec == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }
#endif

    /*-----------------------------------------------------------------*
     * Allocate and initialize IVAS application decoder handle
     *-----------------------------------------------------------------*/
@@ -220,14 +278,17 @@ ivas_error IVAS_DEC_Open(

    st_ivas = hIvasDec->st_ivas;

#ifdef FIX_FMSW_DEC
    st_ivas->restartNeeded = 0;
#endif

    /* initialize Decoder Config. handle */
    init_decoder_config( hIvasDec->st_ivas->hDecoderConfig );

#ifdef FIX_FMSW_DEC
        hIvasDec->st_ivas->restartNeeded = 0;
    }
#endif

    /* Set IVAS decoder handles to NULL + set high-level parameters */
    return ivas_dec_handle_init( st_ivas, mode, &( hIvasDec->hasDecodedFirstGoodFrame ) );
#else
    /* initialize pointers to handles to NULL */
    ivas_initialize_handles_dec( st_ivas );

@@ -267,8 +328,49 @@ ivas_error IVAS_DEC_Open(
    }

    return IVAS_ERR_WRONG_PARAMS;
#endif
}

#ifdef FIX_FMSW_DEC

/*---------------------------------------------------------------------*
 * IVAS_DEC_Restart()
 *
 * Restart IVAS decoder - used in case of format switching
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_Restart(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle               */
    const IVAS_DEC_MODE mode  /* i  : compatibility mode (EVS or IVAS)  */
)
{
    Decoder_Struct *st_ivas;

    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    st_ivas = hIvasDec->st_ivas;

    /* destroy Split binaural renderer (ISAR) handle */
    ivas_destroy_handle_isar( &st_ivas->hSplitBinRend );

    /* destroy IVAS decoder handles */
    ivas_destroy_dec( &st_ivas );

    /* Set IVAS decoder handles to NULL + set high-level parameters */
    if ( !st_ivas->restartNeeded )
    {
        return IVAS_ERR_WRONG_PARAMS;
    }
    else
    {
        return ivas_dec_handle_init( st_ivas, mode, &( hIvasDec->hasDecodedFirstGoodFrame ) );
    }
}

#endif

/*-------------------------------------------------------------------------*
 * isar_set_split_rend_setup()
@@ -351,11 +453,7 @@ void IVAS_DEC_Close(
        return;
    }

#ifdef FIX_FMSW_DEC
    if ( !( *phIvasDec )->st_ivas->restartNeeded && ( *phIvasDec )->hVoIP )
#else
    if ( ( *phIvasDec )->hVoIP )
#endif
    {
        ivas_destroy_handle_VoIP( ( *phIvasDec )->hVoIP );
        ( *phIvasDec )->hVoIP = NULL;
@@ -375,10 +473,6 @@ void IVAS_DEC_Close(
#endif
    }

#ifdef FIX_FMSW_DEC
    if ( ( *phIvasDec )->st_ivas == NULL || !( *phIvasDec )->st_ivas->restartNeeded )
    {
#endif
    apa_exit( &( *phIvasDec )->hTimeScaler );

    if ( ( *phIvasDec )->flushbuffer != NULL )
@@ -389,9 +483,6 @@ void IVAS_DEC_Close(
    free( *phIvasDec );
    *phIvasDec = NULL;
    phIvasDec = NULL;
#ifdef FIX_FMSW_DEC
    }
#endif

    return;
}
+23 −16
Original line number Diff line number Diff line
@@ -126,6 +126,13 @@ ivas_error IVAS_DEC_Configure(
    const bool delayCompensationEnabled                /* i  : enable delay compensation                                        */
);

#ifdef FIX_FMSW_DEC
ivas_error IVAS_DEC_Restart(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    const IVAS_DEC_MODE mode                    /* i  : compatibility mode (EVS or IVAS)                                        */
);

#endif
void IVAS_DEC_Close(
    IVAS_DEC_HANDLE *phIvasDec                  /* i/o: pointer to IVAS decoder handle                                          */
);