Commit 939dc7fc authored by Jouni Paulus's avatar Jouni Paulus
Browse files

- removed cldfb analysis/synthesis reset after MC reconfig

- removed special handling of McMASA in corecoder bitrate switching and merged the operations more in the common flow
parent 0b60f877
Loading
Loading
Loading
Loading
Loading
+31 −204
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ ivas_error ivas_corecoder_dec_reconfig(
    const int16_t nCPE_old,                  /* i  : number of CPEs in previous frame                          */
    const int16_t nchan_transport_old,       /* i  : number of TCs in previous frame                           */
    const int16_t sba_dirac_stereo_flag_old, /* i  : signal stereo rendering using DFT upmix in previous frame */
    const int32_t brate_SCE,                 /* i  : bitrate to be set for the SCEs                            */
    const int32_t brate_SCE,                 /* i  : bitrate to be set for the SCEs                            */
    const int32_t brate_CPE                  /* i  : bitrate to be set for the CPEs                            */
#else
    Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure                               */
@@ -93,8 +93,8 @@ ivas_error ivas_corecoder_dec_reconfig(

    /* remove dummy CPE element for DFT stereo-like upmix */
#ifdef MCMASA_BITRATE_SWITCHING
    if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ||
         ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && sba_dirac_stereo_flag_old ) )
    if ( ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ||
         ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) )
#else
    if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag )
#endif
@@ -115,215 +115,28 @@ ivas_error ivas_corecoder_dec_reconfig(
    }

#ifdef MCMASA_BITRATE_SWITCHING
    if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) )
    {
        float *save_synth, *save_hb_synth;
        save_synth = NULL;
        save_hb_synth = NULL;

        /* McMASA specific handling: delete anything old and create completely new ones.
         * sba_dirac_stereo_flag: STEREO rendering from 1 transport channel with low delay using DFT stereo */
        if ( ( nSCE_old > 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag )
        {
            /* save the old buffers, if they exist */
            save_synth = st_ivas->hSCE[0]->save_synth;
            save_hb_synth = st_ivas->hSCE[0]->save_hb_synth;
            st_ivas->hSCE[0]->save_synth = NULL;
            st_ivas->hSCE[0]->save_hb_synth = NULL;
        }

        for ( sce_id = 0; sce_id < nSCE_old; sce_id++ )
        {
            destroy_sce_dec( st_ivas->hSCE[sce_id] );
            st_ivas->hSCE[sce_id] = NULL;
        }
        for ( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ )
        {
            destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
            st_ivas->hCPE[cpe_id] = NULL;
        }
        for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
        {
            if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
            {
                return error;
            }
            if ( ( sce_id == 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag )
            {
                /* replace the newly created buffers with the old ones */
                if ( st_ivas->hSCE[0]->save_synth != NULL )
                {
                    count_free( st_ivas->hSCE[0]->save_synth );
                    st_ivas->hSCE[0]->save_synth = NULL;
                }
                if ( st_ivas->hSCE[0]->save_hb_synth != NULL )
                {
                    count_free( st_ivas->hSCE[0]->save_hb_synth );
                    st_ivas->hSCE[0]->save_hb_synth = NULL;
                }
                st_ivas->hSCE[0]->save_synth = save_synth;
                st_ivas->hSCE[0]->save_hb_synth = save_hb_synth;
            }
        }
        for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
            if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }
    else
    {
        /* non-McMASA */
        if ( ( st_ivas->nSCE == nSCE_old ) && ( st_ivas->nCPE == nCPE_old ) )
        {
            for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
            {
                st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
                st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
            }

            for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
            {
                st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;

                /* prepare bitstream buffers */
                for ( n = 0; n < CPE_CHANNELS; n++ )
                {
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
                }
            }

            if ( st_ivas->nCPE > 1 )
            {
                if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
        }
        else
        {
            nSCE_existing = min( nSCE_old, st_ivas->nSCE );
            nCPE_existing = min( nCPE_old, st_ivas->nCPE );

            // VE: TBV - try to reuse the CoreCoder
            /* destroy superfluous core coder elements */
            for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
            {
                destroy_sce_dec( st_ivas->hSCE[sce_id] );
                st_ivas->hSCE[sce_id] = NULL;
            }

            for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
            {
                destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
                st_ivas->hCPE[cpe_id] = NULL;
            }

            if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
            {
                ivas_mct_dec_close( &st_ivas->hMCT );
            }

            /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/
            if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
            {
                count_free( st_ivas->hCPE[0]->hStereoMdct );
                st_ivas->hCPE[0]->hStereoMdct = NULL;
            }

            for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
            {
                st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
                st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
            }
            for ( ; sce_id < st_ivas->nSCE; sce_id++ )
            {
                if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }

            for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
            {
                st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;

                /* prepare bitstream buffers */
                for ( n = 0; n < CPE_CHANNELS; n++ )
                {
                    st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
                }
            }
            for ( ; cpe_id < st_ivas->nCPE; cpe_id++ )
            {
                if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }

            if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
            {
                if ( nCPE_old == 1 )
                {
                    /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
                    for ( n = 0; n < CPE_CHANNELS; n++ )
                    {
                        st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
                        st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
                        st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0;
                    }
                }

                if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
            {
                if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }

            /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
            if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
            {
                if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
                {
                    return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
                }

                st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0;
                st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0;
                st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f;

                for ( n = 0; n < CPE_CHANNELS; n++ )
                {
                    /* reset mct_chan_mode */
                    st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
                }
            }
        }
    }
    if ( st_ivas->nchan_transport == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old )
#else
    if ( st_ivas->nchan_transport == nchan_transport_old )
#endif
    {
        for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
#else
            st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
#endif
            st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
        }

        for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
#else
            st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;

#endif
            /* prepare bitstream buffers */
            for ( n = 0; n < CPE_CHANNELS; n++ )
            {
@@ -372,12 +185,20 @@ ivas_error ivas_corecoder_dec_reconfig(

        for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
#else
            st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
#endif
            st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
        }
        for ( ; sce_id < st_ivas->nSCE; sce_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
#else
            if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
@@ -385,8 +206,11 @@ ivas_error ivas_corecoder_dec_reconfig(

        for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
#else
            st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;

#endif
            /* prepare bitstream buffers */
            for ( n = 0; n < CPE_CHANNELS; n++ )
            {
@@ -395,7 +219,11 @@ ivas_error ivas_corecoder_dec_reconfig(
        }
        for ( ; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
#ifdef MCMASA_BITRATE_SWITCHING
            if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
#else
            if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
@@ -446,12 +274,11 @@ ivas_error ivas_corecoder_dec_reconfig(
            }
        }
    }
#endif

    /* create dummy CPE element for DFT stereo-like upmix */
#ifdef MCMASA_BITRATE_SWITCHING
    if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ||
         ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag ) )
    if ( ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ||
         ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) )
#else
    if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
#endif
+2 −11
Original line number Diff line number Diff line
@@ -681,6 +681,7 @@ ivas_error ivas_mc_dec_reconfig(
    {
        nchan_hp20_old = nchan_transport_old;
    }
    st_ivas->sba_dirac_stereo_flag = 0; /* needs to be after getNumChanSynthesis() */
#endif
    /* renderer might have changed, reselect */
    renderer_type_old = st_ivas->renderer_type;
@@ -777,8 +778,8 @@ ivas_error ivas_mc_dec_reconfig(
    {
#ifdef MCMASA_BITRATE_SWITCHING
        ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), st_ivas->hDecoderConfig->ivas_total_brate );

#endif

        if ( last_mc_mode != MC_MODE_MCMASA )
        {
            if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
@@ -957,10 +958,6 @@ ivas_error ivas_mc_dec_reconfig(
            }
        }
    }
    for ( i = 0; i < numCldfbAnalyses; i++ )
    {
        cldfb_reset_memory( st_ivas->cldfbAnaDec[i] );
    }
#endif
    /* Synthesis */
    if ( numCldfbSyntheses_old > numCldfbSyntheses )
@@ -983,12 +980,6 @@ ivas_error ivas_mc_dec_reconfig(
            }
        }
    }
#ifdef MCMASA_BITRATE_SWITCHING
    for ( i = 0; i < numCldfbSyntheses; i++ )
    {
        cldfb_reset_memory( st_ivas->cldfbSynDec[i] );
    }
#endif

    /* Allocate the LFE handle that is coded separately after the allocation of the core coders */
    if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL )
+99 −358

File changed.

Preview size limit exceeded, changes collapsed.