LCOV - code coverage report
Current view: top level - lib_isar - isar_lc3plus_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 119 194 61.3 %
Date: 2025-11-01 05:07:43 Functions: 6 7 85.7 %

          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 "prot.h"
      36             : #include "ivas_prot.h"
      37             : #include "isar_lc3plus_dec.h"
      38             : #include "isar_lc3plus_common.h"
      39             : #include "lc3plus.h"
      40             : #include "ivas_error_utils.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : 
      44             : /*-------------------------------------------------------------------------
      45             :  * ISAR_LC3PLUS_DEC_Open()
      46             :  *
      47             :  *
      48             :  *------------------------------------------------------------------------*/
      49             : 
      50         358 : ivas_error ISAR_LC3PLUS_DEC_Open(
      51             :     const LC3PLUS_CONFIG config,    /* i  : LC3plus decoder configuration   */
      52             :     ISAR_LC3PLUS_DEC_HANDLE *handle /* o  : decoder handle                  */
      53             : )
      54             : {
      55             :     LC3PLUS_Error err;
      56             :     int32_t decoder_size;
      57             :     int16_t i;
      58             : 
      59         358 :     if ( 0 == config.lc3plus_frame_duration_us )
      60             :     {
      61           0 :         return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid lc3plus_frame_duration_us (0)\n" );
      62             :     }
      63             : 
      64         358 :     if ( ( *handle = malloc( sizeof( struct ISAR_LC3PLUS_DEC_HANDLE ) ) ) == NULL )
      65             :     {
      66           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus wrapper handle\n" );
      67             :     }
      68             : 
      69         358 :     if ( config.channels > ISAR_LC3PLUS_MAX_NUM_DECODERS )
      70             :     {
      71           0 :         return IVAS_ERROR( IVAS_ERR_INIT_ERROR, "Maximum number of channels exceeds ISAR_LC3PLUS_MAX_NUM_DECODERS\n" );
      72             :     }
      73             : 
      74         358 :     ( *handle )->num_decs = 0;
      75         358 :     ( *handle )->pcm_conversion_buffer = NULL;
      76         358 :     ( *handle )->handles = NULL;
      77         358 :     ( *handle )->selective_decoding_states = NULL;
      78         358 :     ( *handle )->bitstream_caches = NULL;
      79             : 
      80         358 :     if ( ( ( *handle )->handles = malloc( config.channels * sizeof( ISAR_LC3PLUS_DEC_HANDLE ) ) ) == NULL )
      81             :     {
      82           0 :         ISAR_LC3PLUS_DEC_Close( handle );
      83           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus wrapper handle\n" );
      84             :     }
      85             : 
      86         358 :     if ( ( ( *handle )->selective_decoding_states = malloc( config.channels * sizeof( ISAR_LC3PLUS_DEC_SELECTIVE_DECODING_STATE * ) ) ) == NULL )
      87             :     {
      88           0 :         ISAR_LC3PLUS_DEC_Close( handle );
      89           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus wrapper handle\n" );
      90             :     }
      91             : 
      92        1074 :     for ( i = 0; i < config.channels; ++i )
      93             :     {
      94         716 :         ( *handle )->handles[i] = NULL;
      95         716 :         ( *handle )->selective_decoding_states[i] = NULL;
      96             :     }
      97             : 
      98         358 :     if ( ( ( *handle )->bitstream_caches = malloc( config.channels * sizeof( ISAR_LC3PLUS_DEC_BITSTREAM_CACHE * ) ) ) == NULL )
      99             :     {
     100           0 :         ISAR_LC3PLUS_DEC_Close( handle );
     101           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus wrapper handle\n" );
     102             :     }
     103        1074 :     for ( i = 0; i < config.channels; ++i )
     104             :     {
     105         716 :         ( *handle )->bitstream_caches[i] = NULL;
     106             :     }
     107             : 
     108         358 :     ( *handle )->num_decs = config.channels;
     109        1074 :     for ( int32_t iCh = 0; iCh < config.channels; iCh++ )
     110             :     {
     111         716 :         ( *handle )->selective_decoding_states[iCh] = NULL;
     112         716 :         if ( NULL != ( *handle )->bitstream_caches )
     113             :         {
     114         716 :             ( *handle )->bitstream_caches[iCh] = NULL;
     115             :         }
     116             :         /* allocate and configure LC3plus decoder */
     117         716 :         decoder_size = lc3plus_dec_get_size( config.samplerate, 1 );
     118         716 :         if ( 0 == decoder_size )
     119             :         {
     120           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     121           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "lc3plus_dec_get_size failed\n" );
     122             :         }
     123             : 
     124         716 :         if ( ( ( *handle )->handles[iCh] = malloc( decoder_size ) ) == NULL )
     125             :         {
     126           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     127           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus decoder\n" );
     128             :         }
     129             : 
     130         716 :         err = lc3plus_dec_init( ( *handle )->handles[iCh], config.samplerate, 1, LC3PLUS_PLC_ADVANCED, config.high_res_mode_enabled );
     131             : 
     132         716 :         if ( LC3PLUS_OK != err )
     133             :         {
     134           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     135           0 :             return IVAS_ERROR( ISAR_LC3PLUS_LC3plusErrToIvasErr( err ), "lc3plus_dec_init failed\n" );
     136             :         }
     137             : 
     138         716 :         err = lc3plus_dec_set_frame_dms( ( *handle )->handles[iCh], IVAS_LC3PLUS_UsToLC3plusFrameDuration( config.lc3plus_frame_duration_us ) );
     139         716 :         if ( LC3PLUS_OK != err )
     140             :         {
     141           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     142           0 :             return IVAS_ERROR( ISAR_LC3PLUS_LC3plusErrToIvasErr( err ), "lc3plus_dec_set_frame_dms failed\n" );
     143             :         }
     144             : 
     145             :         /* allocate and configure per LC3plus decoder skip state  */
     146         716 :         if ( ( ( *handle )->selective_decoding_states[iCh] = malloc( sizeof( ISAR_LC3PLUS_DEC_SELECTIVE_DECODING_STATE ) ) ) == NULL )
     147             :         {
     148           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     149           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus decoder\n" );
     150             :         }
     151             : 
     152         716 :         ( *handle )->selective_decoding_states[iCh]->has_skipped_a_frame = 0;
     153         716 :         ( *handle )->selective_decoding_states[iCh]->shall_decode_cached_frame = 0;
     154         716 :         ( *handle )->selective_decoding_states[iCh]->frame_action = DEC_ACTION_DECODE_AND_USE;
     155             : 
     156             :         /* allocate and configure per LC3plus decoder bitstream cache */
     157         716 :         if ( ( ( *handle )->bitstream_caches[iCh] = malloc( sizeof( ISAR_LC3PLUS_DEC_BITSTREAM_CACHE ) ) ) == NULL )
     158             :         {
     159           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     160           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus decoder\n" );
     161             :         }
     162             : 
     163         716 :         ( *handle )->bitstream_caches[iCh]->bitstream_cache_capacity = 400 /*LC3plus max non-HR octet count*/;
     164             : 
     165         716 :         if ( ( ( *handle )->bitstream_caches[iCh]->bitstream_cache = malloc( ( *handle )->bitstream_caches[iCh]->bitstream_cache_capacity ) ) == NULL )
     166             :         {
     167           0 :             ISAR_LC3PLUS_DEC_Close( handle );
     168           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus decoder\n" );
     169             :         }
     170         716 :         ( *handle )->bitstream_caches[iCh]->bitstream_cache_size = 0;
     171             :     }
     172             : 
     173         358 :     ( *handle )->config = config;
     174         358 :     if ( config.isar_frame_duration_us < config.lc3plus_frame_duration_us || config.isar_frame_duration_us % config.lc3plus_frame_duration_us != 0 )
     175             :     {
     176           0 :         ISAR_LC3PLUS_DEC_Close( handle );
     177           0 :         return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "Current pcm_conversion_buffer sizing requires that lc3plus uses a shorter or equal frame duration than ivas\n" );
     178             :     }
     179             : 
     180         358 :     if ( ( ( *handle )->pcm_conversion_buffer = malloc( sizeof( int16_t ) * config.samplerate * config.lc3plus_frame_duration_us / 1000000 ) ) == NULL )
     181             :     {
     182           0 :         ISAR_LC3PLUS_DEC_Close( handle );
     183           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LC3plus decoder wrapper pcm_conversion_buffer\n" );
     184             :     }
     185             : 
     186         358 :     return IVAS_ERR_OK;
     187             : }
     188             : 
     189             : 
     190             : /*-------------------------------------------------------------------------
     191             :  * ISAR_LC3PLUS_DEC_GetDelay()
     192             :  *
     193             :  *
     194             :  *------------------------------------------------------------------------*/
     195             : 
     196         358 : ivas_error ISAR_LC3PLUS_DEC_GetDelay(
     197             :     ISAR_LC3PLUS_DEC_HANDLE handle, /* i  : LC3plus decoder handle                          */
     198             :     int32_t *delayInSamples         /* o  : decoder delay in number of samples per channel  */
     199             : )
     200             : {
     201             :     int32_t tmpDelayInSamples;
     202             : 
     203         358 :     if ( NULL == handle )
     204             :     {
     205           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "ISAR_LC3PLUS_DEC_HANDLE is NULL\n" );
     206             :     }
     207             : 
     208         358 :     if ( NULL == delayInSamples )
     209             :     {
     210           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "delayInSamples is NULL\n" );
     211             :     }
     212             : 
     213         358 :     *delayInSamples = 0;
     214             :     /* sanity check whether all encoders are actually configured identically */
     215        1074 :     for ( uint32_t iDec = 0; iDec < handle->num_decs; iDec++ )
     216             :     {
     217         716 :         if ( NULL == handle->handles[iDec] )
     218             :         {
     219           0 :             return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3plus decoder handle is NULL\n" );
     220             :         }
     221             : 
     222         716 :         tmpDelayInSamples = lc3plus_dec_get_delay( handle->handles[iDec] );
     223         716 :         if ( 0 != *delayInSamples && tmpDelayInSamples != *delayInSamples )
     224             :         {
     225           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "Not all mono LC3plus decoders are configured identically\n" );
     226             :         }
     227             : 
     228         716 :         *delayInSamples = tmpDelayInSamples;
     229             :     }
     230             : 
     231         358 :     return IVAS_ERR_OK;
     232             : }
     233             : 
     234             : 
     235             : /*-------------------------------------------------------------------------
     236             :  * ISAR_LC3PLUS_DEC_Close()
     237             :  *
     238             :  *
     239             :  *------------------------------------------------------------------------*/
     240             : 
     241         358 : void ISAR_LC3PLUS_DEC_Close(
     242             :     ISAR_LC3PLUS_DEC_HANDLE *handle /* i/o: Pointer to LC3plus decoder handle   */
     243             : )
     244             : {
     245         358 :     if ( NULL == handle || NULL == *handle )
     246             :     {
     247           0 :         return;
     248             :     }
     249        1074 :     for ( uint32_t iDec = 0; iDec < ( *handle )->num_decs; iDec++ )
     250             :     {
     251         716 :         if ( NULL != ( *handle )->handles && NULL != ( *handle )->handles[iDec] )
     252             :         {
     253         716 :             lc3plus_free_decoder_structs( ( *handle )->handles[iDec] );
     254         716 :             free( ( *handle )->handles[iDec] );
     255             :         }
     256             : 
     257         716 :         if ( NULL != ( *handle )->selective_decoding_states && NULL != ( *handle )->selective_decoding_states[iDec] )
     258             :         {
     259         716 :             free( ( *handle )->selective_decoding_states[iDec] );
     260             :         }
     261             : 
     262         716 :         if ( NULL != ( *handle )->bitstream_caches && NULL != ( *handle )->bitstream_caches[iDec] )
     263             :         {
     264         716 :             free( ( *handle )->bitstream_caches[iDec]->bitstream_cache );
     265         716 :             free( ( *handle )->bitstream_caches[iDec] );
     266             :         }
     267             :     }
     268             : 
     269         358 :     if ( NULL != ( *handle )->pcm_conversion_buffer )
     270             :     {
     271         358 :         free( ( *handle )->pcm_conversion_buffer );
     272             :     }
     273         358 :     free( ( *handle )->handles );
     274             : 
     275         358 :     if ( NULL != ( *handle )->bitstream_caches )
     276             :     {
     277         358 :         free( ( *handle )->bitstream_caches );
     278             :     }
     279         358 :     free( ( *handle )->selective_decoding_states );
     280             : 
     281         358 :     free( *handle );
     282         358 :     *handle = NULL;
     283             : 
     284         358 :     return;
     285             : }
     286             : 
     287             : 
     288             : /*-------------------------------------------------------------------------
     289             :  * decode_or_conceal_one_lc3plus_frame()
     290             :  *
     291             :  *
     292             :  *------------------------------------------------------------------------*/
     293             : 
     294      590506 : static ivas_error decode_or_conceal_one_lc3plus_frame(
     295             :     LC3PLUS_Dec *dec,
     296             :     uint8_t *bitstream_in,
     297             :     const int32_t bitstream_in_length,
     298             :     int16_t **pcm_out_buffer,
     299             :     const int32_t badFrameIndicator )
     300             : {
     301             :     LC3PLUS_Error err;
     302             : 
     303      590506 :     push_wmops( "lc3plus_dec16" );
     304      590506 :     err = lc3plus_dec16( dec, bitstream_in, bitstream_in_length, pcm_out_buffer, NULL, badFrameIndicator );
     305      590506 :     pop_wmops();
     306             : 
     307      590506 :     if ( err == LC3PLUS_DECODE_ERROR && 1 == badFrameIndicator )
     308             :     {
     309             :         /* LC3PLUS_DECODE_ERROR && badFrameIndicator means that the decoder has successfully concealed, which is actually OK. */
     310           0 :         err = LC3PLUS_OK;
     311             :     }
     312             : 
     313      590506 :     if ( err != LC3PLUS_OK )
     314             :     {
     315           0 :         return IVAS_ERROR( ISAR_LC3PLUS_LC3plusErrToIvasErr( err ), "lc3plus_dec16 failed\n" );
     316             :     }
     317             : 
     318      590506 :     return IVAS_ERR_OK;
     319             : }
     320             : 
     321             : 
     322             : /*-------------------------------------------------------------------------
     323             :  * isar_LC3PLUS_DEC_Decode_or_Conceal_internal()
     324             :  *
     325             :  *
     326             :  *------------------------------------------------------------------------*/
     327             : 
     328       84880 : static ivas_error isar_LC3PLUS_DEC_Decode_or_Conceal_internal(
     329             :     ISAR_LC3PLUS_DEC_HANDLE handle,  /* i  : LC3plus decoder configuration                          */
     330             :     uint8_t *bitstream_in,           /* i  : pointer to input bitstream                             */
     331             :     int32_t bitstream_in_size,       /* i  : size of bitstream_in                                   */
     332             :     const int16_t badFrameIndicator, /* i  : bad frame indicator. If set to 1, triggers concealment */
     333             :     float **pcm_out                  /* o  : decoded samples                                        */
     334             : )
     335             : {
     336             :     uint32_t iDec;
     337             :     int32_t config_num_media_times;
     338             :     int32_t iMediaTime;
     339             :     int32_t iFtd;
     340             :     LC3PLUS_RTP_PAYLOAD payload;
     341             :     int32_t ivasSampleIndex;
     342             :     int16_t numSamplesPerLC3plusChannel;
     343             :     ivas_error err;
     344             : 
     345       84880 :     if ( NULL == handle )
     346             :     {
     347           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     348             :     }
     349       84880 :     if ( NULL == bitstream_in )
     350             :     {
     351           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "bitstream_in is NULL\n" );
     352             :     }
     353       84880 :     if ( NULL == pcm_out )
     354             :     {
     355           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pcm_out is NULL\n" );
     356             :     }
     357       84880 :     if ( badFrameIndicator != 0 && badFrameIndicator != 1 )
     358             :     {
     359           0 :         return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "badFrameIndicator must be 1 or 0\n" );
     360             :     }
     361       84880 :     if ( badFrameIndicator == 0 && bitstream_in_size <= 0 )
     362             :     {
     363           0 :         return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "bitstream_in_size must be positive\n" );
     364             :     }
     365             : 
     366       84880 :     if ( handle->config.isar_frame_duration_us % handle->config.lc3plus_frame_duration_us != 0 )
     367             :     {
     368           0 :         return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "isar_frame_duration_us must be equal or multiple of lc3plus_frame_duration_us \n" );
     369             :     }
     370             : 
     371       84880 :     config_num_media_times = handle->config.isar_frame_duration_us / handle->config.lc3plus_frame_duration_us;
     372       84880 :     if ( !badFrameIndicator )
     373             :     {
     374       84880 :         if ( LC3PLUS_RTP_payload_deserialize( &payload, bitstream_in, bitstream_in_size ) != LC3PLUS_RTP_ERR_NO_ERROR )
     375             :         {
     376           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "LC3PLUS_RTP_payload_deserialize failed\n" );
     377             :         }
     378       84880 :         if ( payload.sampling_rate_hz != handle->config.samplerate )
     379             :         {
     380           0 :             return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "LC3plus config change (samplerate) in bitstream is not supported\n" );
     381             :         }
     382       84880 :         if ( payload.num_channels != handle->config.channels )
     383             :         {
     384           0 :             return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "LC3plus config change (number of channels) in bitstream is not supported\n" );
     385             :         }
     386       84880 :         if ( payload.frame_duration_us != handle->config.lc3plus_frame_duration_us )
     387             :         {
     388           0 :             return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "LC3plus config change (frame duration) in bitstream is not supported\n" );
     389             :         }
     390       84880 :         if ( payload.high_resolution_enabled != handle->config.high_res_mode_enabled )
     391             :         {
     392           0 :             return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "LC3plus config change (high resolution mode) in bitstream is not supported\n" );
     393             :         }
     394       84880 :         if ( payload.num_media_times != config_num_media_times )
     395             :         {
     396           0 :             return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "LC3plus config change (number of media times per frame data block) in bitstream is not supported\n" );
     397             :         }
     398             :     }
     399             : 
     400       84880 :     numSamplesPerLC3plusChannel = (int16_t) ( handle->config.samplerate / ( 1000000 / handle->config.isar_frame_duration_us ) / config_num_media_times );
     401      254640 :     for ( iDec = 0; iDec < handle->num_decs; iDec++ )
     402             :     {
     403      760266 :         for ( iMediaTime = 0; iMediaTime < config_num_media_times; iMediaTime++ )
     404             :         {
     405      590506 :             iFtd = iDec + iMediaTime * handle->num_decs;
     406      590506 :             if ( handle->selective_decoding_states[iDec]->shall_decode_cached_frame )
     407             :             {
     408           0 :                 if ( 0 == handle->bitstream_caches[iDec]->bitstream_cache_size )
     409             :                 {
     410           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "LC3plus cache is empty\n" );
     411             :                 }
     412             : 
     413           0 :                 err = decode_or_conceal_one_lc3plus_frame( handle->handles[iDec], handle->bitstream_caches[iDec]->bitstream_cache, handle->bitstream_caches[iDec]->bitstream_cache_size, &handle->pcm_conversion_buffer, badFrameIndicator );
     414           0 :                 if ( err != IVAS_ERR_OK )
     415             :                 {
     416           0 :                     return IVAS_ERROR( err, "lc3plus decoding failed\n" );
     417             :                 }
     418           0 :                 handle->selective_decoding_states[iDec]->shall_decode_cached_frame = 0;
     419           0 :                 handle->selective_decoding_states[iDec]->has_skipped_a_frame = 0;
     420             :             }
     421             : 
     422             :             /* reset cache if caching is enabled - it has either been decoded or is not needed */
     423      590506 :             if ( NULL != handle->bitstream_caches )
     424             :             {
     425      590506 :                 handle->bitstream_caches[iDec]->bitstream_cache_size = 0;
     426             :             }
     427             : 
     428      590506 :             switch ( handle->selective_decoding_states[iDec]->frame_action )
     429             :             {
     430      590506 :                 case DEC_ACTION_DECODE_AND_USE:
     431             :                 {
     432      590506 :                     if ( badFrameIndicator )
     433             :                     {
     434           0 :                         err = decode_or_conceal_one_lc3plus_frame( handle->handles[iDec], bitstream_in, bitstream_in_size, &handle->pcm_conversion_buffer, badFrameIndicator );
     435             :                     }
     436      590506 :                     else if ( payload.ftds[iFtd].frame_data_length == LC3PLUS_RTP_FDL_SPEECH_BAD )
     437             :                     {
     438           0 :                         return IVAS_ERR_NOT_IMPLEMENTED;
     439             :                         /* Untested therefore disabled. Would probably only need to call concealment,
     440             :                          * but the LC3plus API requires a non-NULL ptr for this which is not available here */
     441             :                     }
     442             :                     else
     443             :                     {
     444      590506 :                         err = decode_or_conceal_one_lc3plus_frame( handle->handles[iDec], payload.ftds[iFtd].frame_data, payload.ftds[iFtd].frame_data_length, &handle->pcm_conversion_buffer, badFrameIndicator );
     445             :                     }
     446      590506 :                     if ( err != IVAS_ERR_OK )
     447             :                     {
     448           0 :                         return IVAS_ERROR( err, "lc3plus decoding failed\n" );
     449             :                     }
     450             : 
     451   150038026 :                     for ( int16_t iSampleInt16 = 0; iSampleInt16 < numSamplesPerLC3plusChannel; iSampleInt16++ )
     452             :                     {
     453   149447520 :                         ivasSampleIndex = iSampleInt16 + iMediaTime * numSamplesPerLC3plusChannel;
     454   149447520 :                         pcm_out[iDec][ivasSampleIndex] = (float) handle->pcm_conversion_buffer[iSampleInt16];
     455             :                     }
     456      590506 :                     handle->selective_decoding_states[iDec]->has_skipped_a_frame = 0;
     457      590506 :                     break;
     458             :                 }
     459           0 :                 case DEC_ACTION_CACHE:
     460             :                 {
     461           0 :                     if ( handle->bitstream_caches[iDec]->bitstream_cache_capacity < (int32_t) payload.ftds[iFtd].frame_data_length )
     462             :                     {
     463           0 :                         return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "bitstream_cache_capacity is too low for LC3plus frame size\n" );
     464             :                     }
     465             :                     /* store bit rate of cached frame */
     466           0 :                     mvc2c( payload.ftds[iFtd].frame_data, handle->bitstream_caches[iDec]->bitstream_cache, (int16_t) payload.ftds[iFtd].frame_data_length );
     467           0 :                     handle->bitstream_caches[iDec]->bitstream_cache_size = payload.ftds[iFtd].frame_data_length;
     468             :                     /* log that this instance has skipped a frame and must decode twice once reactivated */
     469           0 :                     handle->selective_decoding_states[iDec]->has_skipped_a_frame = 1;
     470           0 :                     break;
     471             :                 }
     472           0 :                 case DEC_ACTION_NUM_ENUMS:
     473             :                 default:
     474           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid LC3plus decoder state\n" );
     475             :             }
     476             :         } /* for each media time */
     477             :         /* reset skipping state, must be set by the user before each decode call*/
     478      169760 :         handle->selective_decoding_states[iDec]->frame_action = DEC_ACTION_DECODE_AND_USE;
     479             :     } /* for each dec/channel */
     480             : 
     481       84880 :     return IVAS_ERR_OK;
     482             : }
     483             : 
     484             : 
     485             : /*-------------------------------------------------------------------------
     486             :  * ISAR_LC3PLUS_DEC_Decode()
     487             :  *
     488             :  *
     489             :  *------------------------------------------------------------------------*/
     490             : 
     491       84880 : ivas_error ISAR_LC3PLUS_DEC_Decode(
     492             :     ISAR_LC3PLUS_DEC_HANDLE handle,  /* i  : LC3plus decoder configuration  */
     493             :     uint8_t *bitstream_in,           /* i  : pointer to input bitstream     */
     494             :     const int32_t bitstream_in_size, /* i  : size of bitstream_in           */
     495             :     float **pcm_out                  /* o  : decoded samples                */
     496             : )
     497             : {
     498             :     int16_t badFrameIndicator;
     499             : 
     500       84880 :     if ( NULL == handle )
     501             :     {
     502           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     503             :     }
     504       84880 :     if ( NULL == bitstream_in )
     505             :     {
     506           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "bitstream_in is NULL\n" );
     507             :     }
     508       84880 :     if ( NULL == pcm_out )
     509             :     {
     510           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pcm_out is NULL\n" );
     511             :     }
     512       84880 :     badFrameIndicator = 0;
     513             : 
     514       84880 :     return isar_LC3PLUS_DEC_Decode_or_Conceal_internal( handle, bitstream_in, bitstream_in_size, badFrameIndicator, pcm_out );
     515             : }
     516             : 
     517             : 
     518             : /*-------------------------------------------------------------------------
     519             :  * ISAR_LC3PLUS_DEC_Conceal()
     520             :  *
     521             :  *
     522             :  *------------------------------------------------------------------------*/
     523             : 
     524           0 : ivas_error ISAR_LC3PLUS_DEC_Conceal(
     525             :     ISAR_LC3PLUS_DEC_HANDLE handle, /* i  : LC3plus decoder handle      */
     526             :     float **pcm_out                 /* o  : concealed samples           */
     527             : )
     528             : {
     529             :     uint8_t bitstream_in[LC3PLUS_MAX_BYTES];
     530             :     int16_t badFrameIndicator;
     531             : 
     532           0 :     if ( NULL == handle )
     533             :     {
     534           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     535             :     }
     536             : 
     537           0 :     if ( NULL == pcm_out )
     538             :     {
     539           0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pcm_out is NULL\n" );
     540             :     }
     541             : 
     542             :     /* LC3plus API requires a non-NULL bitstream pointer, even when triggering concealment  */
     543           0 :     badFrameIndicator = 1;
     544             : 
     545           0 :     return isar_LC3PLUS_DEC_Decode_or_Conceal_internal( handle, bitstream_in, 0, badFrameIndicator, pcm_out );
     546             : }

Generated by: LCOV version 1.14