Commit 27a7321e authored by vaclav's avatar vaclav
Browse files

updates within FIX_I98_HANDLES_TO_NULL: initialize handles right after their...

updates within FIX_I98_HANDLES_TO_NULL: initialize handles right after their allocation; introduce the same mechanism to the encoder -> ivas_initialize_handles_enc()
parent c7ccfb8d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -238,6 +238,12 @@ uint32_t ivas_syn_output(
    int16_t *synth_out                                          /* o  : integer 16 bits synthesis signal        */
);

#ifdef FIX_I98_HANDLES_TO_NULL
void ivas_initialize_handles_enc(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder structure                  */
);
#endif

ivas_error ivas_init_encoder(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                  */
    Indice ind_list[][MAX_NUM_INDICES],                         /* i  : indices list                            */
@@ -352,11 +358,10 @@ void ivas_destroy_dec(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
);

#ifndef FIX_I98_HANDLES_TO_NULL
void ivas_initialize_handles_dec(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
);
#endif

ivas_error ivas_core_enc(
    SCE_ENC_HANDLE hSCE,                                                     /* i/o: SCE encoder structure                   */
    CPE_ENC_HANDLE hCPE,                                                     /* i/o: CPE encoder structure                   */
+8 −4
Original line number Diff line number Diff line
@@ -1540,7 +1540,7 @@ void destroy_core_dec(
    return;
}

#ifndef FIX_I98_HANDLES_TO_NULL

/*-------------------------------------------------------------------------
 * ivas_initialize_handles_dec()
 *
@@ -1575,9 +1575,12 @@ void ivas_initialize_handles_dec(
        st_ivas->hCPE[i] = NULL;
    }

#ifndef FIX_I98_HANDLES_TO_NULL
    st_ivas->nSCE = 0;
    st_ivas->nCPE = 0;
#endif
    st_ivas->mem_hp20_out = NULL;
    st_ivas->hLimiter = NULL;

    /* ISM metadata handles */
    for ( i = 0; i < MAX_NUM_OBJECTS; i++ )
@@ -1586,7 +1589,9 @@ void ivas_initialize_handles_dec(
    }

    /* spatial coding handles */
#ifndef FIX_I98_HANDLES_TO_NULL
    st_ivas->hIsmRendererData = NULL;
#endif
    st_ivas->hDirAC = NULL;
    st_ivas->hSpar = NULL;
    st_ivas->hMasa = NULL;
@@ -1610,13 +1615,12 @@ void ivas_initialize_handles_dec(

    st_ivas->hHeadTrackData = NULL;
    st_ivas->hHrtfTD = NULL;
    st_ivas->hLimiter = NULL;
    st_ivas->hLsSetupCustom = NULL;
    st_ivas->hRenderConfig = NULL;

    return;
}
#endif


/*-------------------------------------------------------------------------
 * ivas_destroy_dec()
+48 −34
Original line number Diff line number Diff line
@@ -110,12 +110,17 @@ ivas_error IVAS_DEC_Open(
    float no_diegetic_pan )
{
    IVAS_DEC_HANDLE hIvasDec;
    Decoder_Struct *st_ivas;

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

    /*-----------------------------------------------------------------*
     * Allocate and initialize IVAS application decoder handle
     *-----------------------------------------------------------------*/

    if ( ( *phIvasDec = (IVAS_DEC_HANDLE) count_malloc( sizeof( struct IVAS_DEC ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
@@ -128,6 +133,16 @@ ivas_error IVAS_DEC_Open(

    hIvasDec->mode = mode;

    hIvasDec->bitstreamformat = G192;
    hIvasDec->Opt_VOIP = 0;
    hIvasDec->amrwb_rfc4867_flag = -1;
    hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
    hIvasDec->CNG = 0;            /* RXDTX handler CNG = 1, no CNG = 0*/

    /*-----------------------------------------------------------------*
     * Initialize IVAS-codec decoder state
     *-----------------------------------------------------------------*/

    if ( ( hIvasDec->st_ivas = (Decoder_Struct *) count_malloc( sizeof( Decoder_Struct ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" );
@@ -138,50 +153,49 @@ ivas_error IVAS_DEC_Open(
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" );
    }

    init_decoder_config( hIvasDec->st_ivas->hDecoderConfig, orientation_tracking, no_diegetic_pan );
    /*-----------------------------------------------------------------*
     * Initialize IVAS-codec decoder state
     *-----------------------------------------------------------------*/

    hIvasDec->bitstreamformat = G192;
    hIvasDec->Opt_VOIP = 0;
    hIvasDec->amrwb_rfc4867_flag = -1;
    hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
    hIvasDec->CNG = 0;            /* RXDTX handler CNG = 1, no CNG = 0*/
    st_ivas = hIvasDec->st_ivas;

#ifndef FIX_I98_HANDLES_TO_NULL
    /* initialize pointers to handles */
    ivas_initialize_handles_dec( hIvasDec->st_ivas );
#endif
    /* initialize Decoder Config. handle */
    init_decoder_config( hIvasDec->st_ivas->hDecoderConfig, orientation_tracking, no_diegetic_pan );

    /* high-level set parameters */
    /* initialize pointers to handles to NULL */
    ivas_initialize_handles_dec( st_ivas );

    /* set high-level parameters */
    if ( mode == IVAS_DEC_MODE_EVS )
    {
        hIvasDec->st_ivas->codec_mode = 0; /* unknown before first frame */
        hIvasDec->st_ivas->element_mode_init = EVS_MONO;
        hIvasDec->st_ivas->ivas_format = MONO_FORMAT;
        hIvasDec->st_ivas->transport_config = AUDIO_CONFIG_INVALID;
        hIvasDec->st_ivas->intern_config = AUDIO_CONFIG_INVALID;
        hIvasDec->st_ivas->writeFECoffset = 0;
        st_ivas->codec_mode = 0; /* unknown before first frame */
        st_ivas->element_mode_init = EVS_MONO;
        st_ivas->ivas_format = MONO_FORMAT;
        st_ivas->transport_config = AUDIO_CONFIG_INVALID;
        st_ivas->intern_config = AUDIO_CONFIG_INVALID;
        st_ivas->writeFECoffset = 0;

        return IVAS_ERR_OK;
    }
    else if ( mode == IVAS_DEC_MODE_IVAS )
    {
        hIvasDec->st_ivas->codec_mode = 0; /* unknown before first frame */
        hIvasDec->st_ivas->element_mode_init = -1;
        hIvasDec->st_ivas->ivas_format = UNDEFINED_FORMAT;
        hIvasDec->st_ivas->transport_config = AUDIO_CONFIG_INVALID;
        hIvasDec->st_ivas->intern_config = AUDIO_CONFIG_INVALID;
        hIvasDec->st_ivas->renderer_type = RENDERER_DISABLE;
        hIvasDec->st_ivas->ini_frame = 0;
        hIvasDec->st_ivas->ini_active_frame = 0;
        hIvasDec->st_ivas->writeFECoffset = 0;

        hIvasDec->st_ivas->ism_mode = ISM_MODE_NONE;
        hIvasDec->st_ivas->sba_mode = SBA_MODE_NONE;
        hIvasDec->st_ivas->mc_mode = MC_MODE_NONE;

        hIvasDec->st_ivas->sba_order = 0;
        hIvasDec->st_ivas->sba_planar = 0;
        hIvasDec->st_ivas->sba_analysis_order = 0;
        st_ivas->codec_mode = 0; /* unknown before first frame */
        st_ivas->element_mode_init = -1;
        st_ivas->ivas_format = UNDEFINED_FORMAT;
        st_ivas->transport_config = AUDIO_CONFIG_INVALID;
        st_ivas->intern_config = AUDIO_CONFIG_INVALID;
        st_ivas->renderer_type = RENDERER_DISABLE;
        st_ivas->ini_frame = 0;
        st_ivas->ini_active_frame = 0;
        st_ivas->writeFECoffset = 0;

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

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

        return IVAS_ERR_OK;
    }
+66 −0
Original line number Diff line number Diff line
@@ -237,6 +237,67 @@ void copy_encoder_config(
}


#ifdef FIX_I98_HANDLES_TO_NULL
/*-------------------------------------------------------------------------
 * ivas_initialize_handles_enc()
 *
 * NULL initialization of handles
 *-------------------------------------------------------------------------*/

void ivas_initialize_handles_enc(
    Encoder_Struct *st_ivas /* i/o: IVAS encoder structure                  */
)
{
    int16_t i;

    for ( i = 0; i < MAX_SCE; i++ )
    {
        st_ivas->hSCE[i] = NULL;
    }

    for ( i = 0; i < MAX_CPE; i++ )
    {
        st_ivas->hCPE[i] = NULL;
    }

    /* ISm metadata handles */
    for ( i = 0; i < MAX_NUM_OBJECTS; i++ )
    {
        st_ivas->hIsmMetaData[i] = NULL;
    }

    /* Q Metadata handle */
    st_ivas->hQMetaData = NULL;

    /* DirAC handle */
    st_ivas->hDirAC = NULL;

    /* SPAR handle */
    st_ivas->hSpar = NULL;

    /* MASA encoder handle */
    st_ivas->hMasa = NULL;

    /* MCT handle */
    st_ivas->hMCT = NULL;

    /* Parametric MC handle */
    st_ivas->hParamMC = NULL;

    /* Multi-channel MASA handle */
    st_ivas->hMcMasa = NULL;

    /* Stereo downmix for EVS encoder handle */
    st_ivas->hStereoDmxEVS = NULL;

    /* LFE  handle */
    st_ivas->hLFE = NULL;

    return;
}
#endif


/*-------------------------------------------------------------------*
 * ivas_init_encoder()
 *
@@ -275,6 +336,9 @@ ivas_error ivas_init_encoder(
    st_ivas->mc_mode = MC_MODE_NONE;
    st_ivas->sba_mode = SBA_MODE_NONE;

#ifdef FIX_I98_HANDLES_TO_NULL
    st_ivas->nchan_transport = -1;
#else
    /*-----------------------------------------------------------------*
     * Dummy pointers to max. number of SCEs and CPEs
     *-----------------------------------------------------------------*/
@@ -323,6 +387,7 @@ ivas_error ivas_init_encoder(

    /* LFE  handle */
    st_ivas->hLFE = NULL;
#endif

    /*-----------------------------------------------------------------*
     * Allocate and initialize SCE/CPE and other handles
@@ -986,3 +1051,4 @@ void ivas_destroy_enc(

    return;
}
+46 −24
Original line number Diff line number Diff line
@@ -105,6 +105,10 @@ ivas_error IVAS_ENC_Open(
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    /*-----------------------------------------------------------------*
     * Allocate and initialize IVAS application encoder handle
     *-----------------------------------------------------------------*/

#ifdef BITSTREAM_INDICES_MEMORY
    if ( ( *phIvasEnc = (IVAS_ENC_HANDLE) dynamic_malloc( sizeof( struct IVAS_ENC ) ) ) == NULL )
#else
@@ -114,15 +118,14 @@ ivas_error IVAS_ENC_Open(
        return IVAS_ERR_FAILED_ALLOC;
    }

    if ( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) count_malloc( sizeof( Encoder_Struct ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" );
    }

    if ( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) count_malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" );
    }
    ( *phIvasEnc )->hCoreCoder = NULL;
    ( *phIvasEnc )->isConfigured = false;
#ifdef DEBUGGING
    ( *phIvasEnc )->cmd_stereo = false;
#endif
    ( *phIvasEnc )->switchingActive = false;
    ( *phIvasEnc )->maxBandwidthUser = false;
    resetIsmMetadataProvidedFlags( *phIvasEnc );

    /*-----------------------------------------------------------------*
     * Initialize indices
@@ -147,31 +150,43 @@ ivas_error IVAS_ENC_Open(
    }

    /*-----------------------------------------------------------------*
     * Initialize encoder state
     * Allocate IVAS-codec encoder state
     *-----------------------------------------------------------------*/

    if ( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) count_malloc( sizeof( Encoder_Struct ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" );
    }

    if ( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) count_malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" );
    }

    /*-----------------------------------------------------------------*
     * Initialize IVAS-codec encoder state
     *-----------------------------------------------------------------*/

    st_ivas = ( *phIvasEnc )->st_ivas;

    /* initialize encoder Config. handle */
    init_encoder_config( st_ivas->hEncoderConfig );

#ifdef FIX_I98_HANDLES_TO_NULL
    /* initialize pointers to handles to NULL */
    ivas_initialize_handles_enc( st_ivas );
#else
    st_ivas->hEncoderConfig->ivas_total_brate = ACELP_12k65;
    st_ivas->hEncoderConfig->Opt_SC_VBR = 0;
    st_ivas->hEncoderConfig->last_Opt_SC_VBR = 0;
#endif

    /* set high-level parameters */
    st_ivas->mc_mode = MC_MODE_NONE;
    st_ivas->ism_mode = ISM_MODE_NONE;
    st_ivas->sba_mode = SBA_MODE_NONE;
    st_ivas->sba_analysis_order = 0;

    init_encoder_config( st_ivas->hEncoderConfig );

    ( *phIvasEnc )->hCoreCoder = NULL;
    ( *phIvasEnc )->isConfigured = false;
#ifdef DEBUGGING
    ( *phIvasEnc )->cmd_stereo = false;
#endif
    ( *phIvasEnc )->switchingActive = false;
    ( *phIvasEnc )->maxBandwidthUser = false;
    resetIsmMetadataProvidedFlags( *phIvasEnc );


    return IVAS_ERR_OK;
}

@@ -2033,11 +2048,18 @@ static void init_encoder_config(
    ENCODER_CONFIG_HANDLE hEncoderConfig /* o  : configuration structure */
)
{
#ifdef FIX_I98_HANDLES_TO_NULL
    hEncoderConfig->ivas_total_brate = ACELP_12k65;
#endif
    hEncoderConfig->max_bwidth = SWB;
    hEncoderConfig->input_Fs = 16000;
    hEncoderConfig->nchan_inp = 1;
    hEncoderConfig->element_mode_init = EVS_MONO;
    hEncoderConfig->ivas_format = UNDEFINED_FORMAT;
#ifdef FIX_I98_HANDLES_TO_NULL
    hEncoderConfig->Opt_SC_VBR = 0;
    hEncoderConfig->last_Opt_SC_VBR = 0;
#endif
    hEncoderConfig->Opt_AMR_WB = 0;
    hEncoderConfig->Opt_DTX_ON = 0;
    hEncoderConfig->Opt_RF_ON = 0;