LCOV - code coverage report
Current view: top level - lib_enc - ivas_corecoder_enc_reconfig.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 172 182 94.5 %
Date: 2025-09-14 08:49:19 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #include "ivas_cnst.h"
      36             : #include "prot.h"
      37             : #include "ivas_prot.h"
      38             : #ifdef DEBUGGING
      39             : #include "debug.h"
      40             : #include <assert.h>
      41             : #endif
      42             : #include "wmc_auto.h"
      43             : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
      44             : #include <string.h>
      45             : #endif
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * ivas_corecoder_enc_reconfig()
      49             :  *
      50             :  * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching
      51             :  *-------------------------------------------------------------------*/
      52             : 
      53        5332 : ivas_error ivas_corecoder_enc_reconfig(
      54             :     Encoder_Struct *st_ivas,           /* i/o: IVAS encoder structure                */
      55             :     const int16_t nSCE_old,            /* i  : number of SCEs in previous frame      */
      56             :     const int16_t nCPE_old,            /* i  : number of CPEs in previous frame      */
      57             :     const int16_t nchan_transport_old, /* i  : number of TCs in previous frame       */
      58             :     const int32_t brate_SCE,           /* i  : bitrate to be set for the SCEs        */
      59             :     const int32_t brate_CPE,           /* i  : bitrate to be set for the CPEs        */
      60             :     const MC_MODE last_mc_mode         /* i  : switching between MC modes: last mode */
      61             : )
      62             : {
      63             :     int16_t n, sce_id, cpe_id;
      64             :     int16_t len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing;
      65             :     float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )];
      66             :     BSTR_ENC_HANDLE hBstr;
      67             :     int16_t i, nb_bits;
      68             :     Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST];
      69             :     int16_t nb_bits_tot;
      70             :     int16_t nchan_transport_real, nchan_transport_old_real;
      71             :     ENCODER_CONFIG_HANDLE hEncoderConfig;
      72             :     ivas_error error;
      73             : 
      74             :     /*-----------------------------------------------------------------*
      75             :      * Initialization
      76             :      *-----------------------------------------------------------------*/
      77             : 
      78        5332 :     hEncoderConfig = st_ivas->hEncoderConfig;
      79        5332 :     error = IVAS_ERR_OK;
      80             : 
      81        5332 :     len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
      82        5332 :     if ( hEncoderConfig->ivas_format == SBA_FORMAT )
      83             :     {
      84        1020 :         len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
      85             :     }
      86             : 
      87        5332 :     nchan_transport_old_real = nchan_transport_old;
      88        5332 :     nchan_transport_real = st_ivas->nchan_transport;
      89             : 
      90        5332 :     if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
      91             :     {
      92         255 :         nchan_transport_real += st_ivas->hEncoderConfig->nchan_ism;
      93             :     }
      94             : 
      95             :     /*-----------------------------------------------------------------*
      96             :      * Switching between SCE(s)/CPE(s)/MCT
      97             :      *-----------------------------------------------------------------*/
      98             : 
      99        5332 :     if ( nchan_transport_real == nchan_transport_old_real && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) /* in McMASA, nchan_transport may be the same, but nSCE/nCPE differs */
     100             :     {
     101        2538 :         for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
     102             :         {
     103        1412 :             copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
     104        1412 :             st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
     105        1412 :             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() */
     106             :         }
     107             : 
     108        2288 :         for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
     109             :         {
     110        1162 :             st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
     111             : 
     112             :             /* prepare bitstream buffers */
     113        3486 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     114             :             {
     115        2324 :                 copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
     116             : 
     117        2324 :                 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() */
     118             :             }
     119             :         }
     120             : 
     121        1126 :         if ( st_ivas->nCPE > 1 )
     122             :         {
     123         289 :             if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
     124             :             {
     125           0 :                 return error;
     126             :             }
     127             :         }
     128             :     }
     129             :     else
     130             :     {
     131             : 
     132             :         /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */
     133        4206 :         if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA )
     134             :         {
     135         273 :             nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old;
     136             :         }
     137             : 
     138        4206 :         if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
     139             :         {
     140         257 :             nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
     141             :         }
     142             : 
     143             :         /* something in transport changes */
     144        4206 :         hBstr = NULL;
     145             : 
     146             :         /* get the index list pointers */
     147        4206 :         if ( nSCE_old )
     148             :         {
     149        2291 :             hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
     150             :         }
     151        1915 :         else if ( nCPE_old )
     152             :         {
     153        1915 :             hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
     154             :         }
     155             : #ifdef DEBUGGING
     156             :         else
     157             :         {
     158             :             assert( 0 && "At least one SCE or one CPE should have existed before!\n" );
     159             :         }
     160             : #endif
     161             : 
     162             :         /* save bitstream information */
     163        4206 :         nb_bits_tot = hBstr->nb_bits_tot;
     164        4206 :         i = 0;
     165        4206 :         nb_bits = 0;
     166        7905 :         while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
     167             :         {
     168        3699 :             if ( hBstr->ind_list[i].nb_bits > 0 )
     169             :             {
     170        3699 :                 temp_ind_list[i].id = hBstr->ind_list[i].id;
     171        3699 :                 temp_ind_list[i].value = hBstr->ind_list[i].value;
     172        3699 :                 temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits;
     173             : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
     174             :                 strncpy( temp_ind_list[i].function_name, hBstr->ind_list[i].function_name, 100 );
     175             : #endif
     176             : 
     177        3699 :                 hBstr->ind_list[i].nb_bits = -1;
     178             :             }
     179             : 
     180        3699 :             hBstr->nb_bits_tot = 0;
     181        3699 :             hBstr->nb_ind_tot = 0;
     182             : 
     183        3699 :             nb_bits += temp_ind_list[i].nb_bits;
     184        3699 :             i++;
     185             :         }
     186             : 
     187       42567 :         for ( ; i < MAX_NUM_IND_TEMP_LIST; i++ )
     188             :         {
     189             :             /* reset nb_bits of all other indices to -1 */
     190       38361 :             temp_ind_list[i].nb_bits = -1;
     191             :         }
     192             : 
     193             : #ifdef DEBUGGING
     194             :         assert( ( nb_bits == nb_bits_tot ) && "Error saving bitstream information during core-coder reconfiguration!\n" );
     195             : #endif
     196             : 
     197        4206 :         if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
     198             :         {
     199             :             /* within McMASA we can modify the transport signals when switching */
     200             :             /* copy earlier dmx buffers */
     201          39 :             if ( nSCE_old > 0 )
     202             :             {
     203          29 :                 set_zero( input_buff[0], len_inp_memory );
     204          29 :                 mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory );
     205             :             }
     206             : 
     207         117 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     208             :             {
     209          78 :                 set_zero( input_buff[n + 1], len_inp_memory );
     210          78 :                 if ( nCPE_old > 0 )
     211             :                 {
     212          42 :                     mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory );
     213             :                 }
     214             :             }
     215             : 
     216          39 :             ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE );
     217             : 
     218          39 :             n_CoreCoder_existing = 0;
     219             :         }
     220             :         else
     221             :         {
     222        4167 :             n_CoreCoder_existing = min( nchan_transport_real, nchan_transport_old_real );
     223             :         }
     224             : 
     225             :         /* destroy superfluous core-coder elements */
     226        6804 :         for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
     227             :         {
     228             :             /* save input audio buffers */
     229        2598 :             if ( n_CoreCoder_existing > sce_id )
     230             :             {
     231        1543 :                 mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
     232             :             }
     233             : 
     234        2598 :             destroy_sce_enc( st_ivas->hSCE[sce_id] );
     235        2598 :             st_ivas->hSCE[sce_id] = NULL;
     236             :         }
     237             : 
     238        6338 :         for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
     239             :         {
     240             :             /* save input audio buffers */
     241        6396 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     242             :             {
     243        4264 :                 if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
     244             :                 {
     245         663 :                     mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
     246             :                 }
     247             :             }
     248             : 
     249        2132 :             destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
     250        2132 :             st_ivas->hCPE[cpe_id] = NULL;
     251             :         }
     252             : 
     253        4206 :         if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
     254             :         {
     255         477 :             ivas_mct_enc_close( &( st_ivas->hMCT ) );
     256             :         }
     257             : 
     258             :         /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */
     259        4206 :         if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
     260             :         {
     261         326 :             free( st_ivas->hCPE[0]->hStereoMdct );
     262         326 :             st_ivas->hCPE[0]->hStereoMdct = NULL;
     263             :         }
     264             : 
     265             :         /* create missing core coder elements and set element bitrates for already existing ones */
     266        4206 :         if ( st_ivas->nSCE > 0 )
     267             :         {
     268        2257 :             nSCE_existing = min( nSCE_old, st_ivas->nSCE );
     269             : 
     270        4004 :             for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
     271             :             {
     272        1747 :                 copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
     273        1747 :                 st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
     274        1747 :                 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() */
     275             : 
     276        1747 :                 ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) );
     277             :             }
     278             : 
     279        4836 :             for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
     280             :             {
     281        2579 :                 if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
     282             :                 {
     283           0 :                     return error;
     284             :                 }
     285             : 
     286             :                 /* propagate input audio buffers */
     287        2579 :                 if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT )
     288             :                 {
     289         663 :                     mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory );
     290             :                 }
     291             : 
     292             :                 /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
     293        2579 :                 if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
     294             :                 {
     295        1906 :                     reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_ind_tot );
     296             :                 }
     297             :             }
     298             : 
     299        2257 :             if ( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL )
     300             :             {
     301         576 :                 if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
     302             :                 {
     303           0 :                     return error;
     304             :                 }
     305             :             }
     306             :         }
     307             : 
     308        4206 :         if ( st_ivas->nCPE > 0 )
     309             :         {
     310        2929 :             nCPE_existing = min( nCPE_old, st_ivas->nCPE );
     311             : 
     312        5367 :             for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
     313             :             {
     314        2438 :                 st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
     315             : 
     316             :                 /* allocate buffer of indices */
     317        7314 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     318             :                 {
     319        4876 :                     copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
     320        4876 :                     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() */
     321             : 
     322        4876 :                     if ( ( cpe_id * CPE_CHANNELS + n > 0 ) ||
     323        2225 :                          ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ||
     324        2213 :                          ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) )
     325             :                     {
     326        3619 :                         reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
     327             :                     }
     328             :                 }
     329             :             }
     330             : 
     331        5171 :             for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
     332             :             {
     333        2242 :                 if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled )
     334             :                 {
     335          12 :                     st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
     336             :                 }
     337             : 
     338        2242 :                 if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
     339             :                 {
     340           0 :                     return error;
     341             :                 }
     342             : 
     343             :                 /* propagate input audio buffers */
     344        6726 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     345             :                 {
     346        4484 :                     if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
     347             :                     {
     348         699 :                         mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory );
     349             :                     }
     350             :                 }
     351             : 
     352        6726 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     353             :                 {
     354             :                     /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
     355        4484 :                     if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) )
     356             :                     {
     357        3792 :                         reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
     358             :                     }
     359             : 
     360        4484 :                     if ( hEncoderConfig->Opt_DTX_ON )
     361             :                     {
     362          48 :                         st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
     363             :                     }
     364             :                 }
     365             :             }
     366             :         }
     367             : 
     368             :         /* restore bitstream - IVAS format bits should be written in the first core channel of the first SCE/CPE */
     369        4206 :         i = 0;
     370        4206 :         nb_bits = 0;
     371        4206 :         if ( st_ivas->nSCE > 0 )
     372             :         {
     373        4294 :             while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
     374             :             {
     375        2037 :                 if ( temp_ind_list[i].nb_bits > 0 )
     376             :                 {
     377        2037 :                     st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
     378        2037 :                     st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
     379        2037 :                     st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
     380             : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
     381             :                     strncpy( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].function_name, temp_ind_list[i].function_name, 100 );
     382             : #endif
     383             :                 }
     384             : 
     385        2037 :                 nb_bits += temp_ind_list[i].nb_bits;
     386        2037 :                 i++;
     387             :             }
     388        2257 :             st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
     389        2257 :             st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
     390             :         }
     391        1949 :         else if ( st_ivas->nCPE > 0 )
     392             :         {
     393        3611 :             while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
     394             :             {
     395        1662 :                 if ( temp_ind_list[i].nb_bits > 0 )
     396             :                 {
     397        1662 :                     st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
     398        1662 :                     st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
     399        1662 :                     st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
     400             : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
     401             :                     strncpy( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].function_name, temp_ind_list[i].function_name, 100 );
     402             : #endif
     403             :                 }
     404             : 
     405        1662 :                 nb_bits += temp_ind_list[i].nb_bits;
     406        1662 :                 i++;
     407             :             }
     408        1949 :             st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
     409        1949 :             st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
     410             :         }
     411             : 
     412             : #ifdef DEBUGGING
     413             :         assert( ( nb_bits == nb_bits_tot ) && "Error restoring bitstream information during core-coder reconfiguration!\n" );
     414             : #endif
     415             : 
     416             : 
     417        4206 :         if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
     418             :         {
     419             :             /* restore modified transport signal */
     420          39 :             if ( st_ivas->nSCE )
     421             :             {
     422          29 :                 mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory );
     423             :             }
     424             : 
     425          39 :             if ( st_ivas->nCPE )
     426             :             {
     427          75 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     428             :                 {
     429          50 :                     mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory );
     430             :                 }
     431             :             }
     432             :         }
     433             : 
     434        4206 :         if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
     435             :         {
     436         804 :             if ( nCPE_old == 1 )
     437             :             {
     438             :                 /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
     439         978 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
     440             :                 {
     441         652 :                     st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
     442         652 :                     st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
     443        1304 :                     st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
     444         652 :                                                                           st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
     445         652 :                                                                           st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
     446         652 :                                                                           st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
     447             : 
     448         652 :                     if ( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK )
     449             :                     {
     450           0 :                         return error;
     451             :                     }
     452             :                 }
     453             :             }
     454             : 
     455         804 :             if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
     456             :             {
     457           0 :                 return error;
     458             :             }
     459             :         }
     460        3402 :         else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
     461             :         {
     462         157 :             if ( ( error = mct_enc_reconfigure( st_ivas, nchan_transport_old_real != nchan_transport_real ) ) != IVAS_ERR_OK )
     463             :             {
     464           0 :                 return error;
     465             :             }
     466             :         }
     467             : 
     468             :         /* alllocate buffer for metadata indices */
     469        4206 :         if ( st_ivas->nCPE > 0 )
     470             :         {
     471        2929 :             if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
     472             :             {
     473         369 :                 if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
     474             :                 {
     475           0 :                     return error;
     476             :                 }
     477             :             }
     478             : 
     479        2929 :             reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot );
     480             : 
     481        4680 :             for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
     482             :             {
     483        1751 :                 ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) );
     484             :             }
     485             :         }
     486             : 
     487             :         /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
     488        4206 :         if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
     489             :         {
     490         335 :             if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
     491             :             {
     492           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
     493             :             }
     494             : 
     495             :             /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */
     496        1005 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     497             :             {
     498         670 :                 st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
     499         670 :                 st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
     500        1340 :                 st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
     501         670 :                                                                       st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
     502         670 :                                                                       st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
     503         670 :                                                                       st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
     504             : 
     505         670 :                 if ( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK )
     506             :                 {
     507           0 :                     return error;
     508             :                 }
     509             : 
     510             :                 /* reset mct_chan_mode */
     511         670 :                 st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     512             :             }
     513             : 
     514             : #ifdef DEBUGGING
     515             :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl;
     516             : #endif
     517         335 :             initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 );
     518         335 :             st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT || hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
     519             :         }
     520             :     }
     521             : 
     522        5332 :     return error;
     523             : }

Generated by: LCOV version 1.14