LCOV - code coverage report
Current view: top level - lib_isar/lib_isar - isar_lc3plus_dec.c (source / functions) Coverage Total Hit
Test: Coverage on main -- merged total coverage @ aa956cc5e85ad1343482c43368edd0b56b2bceb5 Lines: 72.5 % 218 158
Test Date: 2026-04-17 05:05:34 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /******************************************************************************************************
       2              : 
       3              :    (C) 2022-2026 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         1645 : 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         1645 :     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         1645 :     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         1645 :     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         1645 :     ( *handle )->num_decs = 0;
      75         1645 :     ( *handle )->pcm_conversion_buffer = NULL;
      76         1645 :     ( *handle )->handles = NULL;
      77         1645 :     ( *handle )->selective_decoding_states = NULL;
      78         1645 :     ( *handle )->bitstream_caches = NULL;
      79              : 
      80         1645 :     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         1645 :     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         4924 :     for ( i = 0; i < config.channels; ++i )
      93              :     {
      94         3279 :         ( *handle )->handles[i] = NULL;
      95         3279 :         ( *handle )->selective_decoding_states[i] = NULL;
      96         3279 :     }
      97              : 
      98         1645 :     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         4924 :     for ( i = 0; i < config.channels; ++i )
     104              :     {
     105         3279 :         ( *handle )->bitstream_caches[i] = NULL;
     106         3279 :     }
     107              : 
     108         1645 :     ( *handle )->num_decs = config.channels;
     109         4922 :     for ( int32_t iCh = 0; iCh < config.channels; iCh++ )
     110              :     {
     111         3279 :         ( *handle )->selective_decoding_states[iCh] = NULL;
     112         3279 :         if ( NULL != ( *handle )->bitstream_caches )
     113              :         {
     114         3279 :             ( *handle )->bitstream_caches[iCh] = NULL;
     115         3279 :         }
     116              :         /* allocate and configure LC3plus decoder */
     117         3279 :         decoder_size = lc3plus_dec_get_size( config.samplerate, 1 );
     118         3279 :         if ( 0 == decoder_size )
     119              :         {
     120            1 :             ISAR_LC3PLUS_DEC_Close( handle );
     121            1 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "lc3plus_dec_get_size failed\n" );
     122              :         }
     123              : 
     124         3278 :         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         3278 :         err = lc3plus_dec_init( ( *handle )->handles[iCh], config.samplerate, 1, LC3PLUS_PLC_ADVANCED, config.high_res_mode_enabled );
     131              : 
     132         3278 :         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         3278 :         err = lc3plus_dec_set_frame_dms( ( *handle )->handles[iCh], IVAS_LC3PLUS_UsToLC3plusFrameDuration( config.lc3plus_frame_duration_us ) );
     139         3278 :         if ( LC3PLUS_OK != err )
     140              :         {
     141            1 :             ISAR_LC3PLUS_DEC_Close( handle );
     142            1 :             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         3277 :         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         3277 :         ( *handle )->selective_decoding_states[iCh]->has_skipped_a_frame = 0;
     153         3277 :         ( *handle )->selective_decoding_states[iCh]->shall_decode_cached_frame = 0;
     154         3277 :         ( *handle )->selective_decoding_states[iCh]->frame_action = DEC_ACTION_DECODE_AND_USE;
     155              : 
     156              :         /* allocate and configure per LC3plus decoder bitstream cache */
     157         3277 :         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         3277 :         ( *handle )->bitstream_caches[iCh]->bitstream_cache_capacity = 400 /*LC3plus max non-HR octet count*/;
     164              : 
     165         3277 :         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         3277 :         ( *handle )->bitstream_caches[iCh]->bitstream_cache_size = 0;
     171         3277 :     }
     172              : 
     173         1643 :     ( *handle )->config = config;
     174         1643 :     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         1643 :     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         1643 :     return IVAS_ERR_OK;
     187         1645 : }
     188              : 
     189              : 
     190              : /*-------------------------------------------------------------------------
     191              :  * ISAR_LC3PLUS_DEC_GetDelay()
     192              :  *
     193              :  *
     194              :  *------------------------------------------------------------------------*/
     195              : 
     196         1642 : 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         1642 :     if ( NULL == handle )
     204              :     {
     205            2 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "ISAR_LC3PLUS_DEC_HANDLE is NULL\n" );
     206              :     }
     207              : 
     208         1640 :     if ( NULL == delayInSamples )
     209              :     {
     210            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "delayInSamples is NULL\n" );
     211              :     }
     212              : 
     213         1640 :     *delayInSamples = 0;
     214              :     /* sanity check whether all encoders are actually configured identically */
     215         4914 :     for ( uint32_t iDec = 0; iDec < handle->num_decs; iDec++ )
     216              :     {
     217         3274 :         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         3274 :         tmpDelayInSamples = lc3plus_dec_get_delay( handle->handles[iDec] );
     223         3274 :         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         3274 :         *delayInSamples = tmpDelayInSamples;
     229         3274 :     }
     230              : 
     231         1640 :     return IVAS_ERR_OK;
     232         1642 : }
     233              : 
     234              : 
     235              : /*-------------------------------------------------------------------------
     236              :  * ISAR_LC3PLUS_DEC_Close()
     237              :  *
     238              :  *
     239              :  *------------------------------------------------------------------------*/
     240              : 
     241         1646 : void ISAR_LC3PLUS_DEC_Close(
     242              :     ISAR_LC3PLUS_DEC_HANDLE *handle /* i/o: Pointer to LC3plus decoder handle   */
     243              : )
     244              : {
     245         1646 :     if ( NULL == handle || NULL == *handle )
     246              :     {
     247            1 :         return;
     248              :     }
     249         4924 :     for ( uint32_t iDec = 0; iDec < ( *handle )->num_decs; iDec++ )
     250              :     {
     251         3279 :         if ( NULL != ( *handle )->handles && NULL != ( *handle )->handles[iDec] )
     252              :         {
     253         3278 :             lc3plus_free_decoder_structs( ( *handle )->handles[iDec] );
     254         3278 :             free( ( *handle )->handles[iDec] );
     255         3278 :         }
     256              : 
     257         3279 :         if ( NULL != ( *handle )->selective_decoding_states && NULL != ( *handle )->selective_decoding_states[iDec] )
     258              :         {
     259         3277 :             free( ( *handle )->selective_decoding_states[iDec] );
     260         3277 :         }
     261              : 
     262         3279 :         if ( NULL != ( *handle )->bitstream_caches && NULL != ( *handle )->bitstream_caches[iDec] )
     263              :         {
     264         3277 :             free( ( *handle )->bitstream_caches[iDec]->bitstream_cache );
     265         3277 :             free( ( *handle )->bitstream_caches[iDec] );
     266         3277 :         }
     267         3279 :     }
     268              : 
     269         1645 :     if ( NULL != ( *handle )->pcm_conversion_buffer )
     270              :     {
     271         1643 :         free( ( *handle )->pcm_conversion_buffer );
     272         1643 :     }
     273         1645 :     free( ( *handle )->handles );
     274              : 
     275         1645 :     if ( NULL != ( *handle )->bitstream_caches )
     276              :     {
     277         1645 :         free( ( *handle )->bitstream_caches );
     278         1645 :     }
     279         1645 :     free( ( *handle )->selective_decoding_states );
     280              : 
     281         1645 :     free( *handle );
     282         1645 :     *handle = NULL;
     283              : 
     284         1645 :     return;
     285         1646 : }
     286              : 
     287              : 
     288              : /*-------------------------------------------------------------------------
     289              :  * decode_or_conceal_one_lc3plus_frame()
     290              :  *
     291              :  *
     292              :  *------------------------------------------------------------------------*/
     293              : 
     294      2089003 : 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      2089003 :     push_wmops( "lc3plus_dec16" );
     304      2089003 :     err = lc3plus_dec16( dec, bitstream_in, bitstream_in_length, pcm_out_buffer, NULL, badFrameIndicator );
     305      2089003 :     pop_wmops();
     306              : 
     307      2089003 :     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        14911 :         err = LC3PLUS_OK;
     311        14911 :     }
     312              : 
     313      2089003 :     if ( err != LC3PLUS_OK )
     314              :     {
     315            0 :         return IVAS_ERROR( ISAR_LC3PLUS_LC3plusErrToIvasErr( err ), "lc3plus_dec16 failed\n" );
     316              :     }
     317              : 
     318      2089003 :     return IVAS_ERR_OK;
     319      2089003 : }
     320              : 
     321              : 
     322              : /*-------------------------------------------------------------------------
     323              :  * isar_LC3PLUS_DEC_Decode_or_Conceal_internal()
     324              :  *
     325              :  *
     326              :  *------------------------------------------------------------------------*/
     327              : 
     328       292124 : 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       292124 :     if ( NULL == handle )
     346              :     {
     347            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     348              :     }
     349       292124 :     if ( NULL == bitstream_in )
     350              :     {
     351            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "bitstream_in is NULL\n" );
     352              :     }
     353       292124 :     if ( NULL == pcm_out )
     354              :     {
     355            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pcm_out is NULL\n" );
     356              :     }
     357       292124 :     if ( badFrameIndicator != 0 && badFrameIndicator != 1 )
     358              :     {
     359            0 :         return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "badFrameIndicator must be 1 or 0\n" );
     360              :     }
     361       292124 :     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       292124 :     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       292124 :     config_num_media_times = handle->config.isar_frame_duration_us / handle->config.lc3plus_frame_duration_us;
     372       292124 :     if ( !badFrameIndicator )
     373              :     {
     374       290239 :         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       290239 :         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       290239 :         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       290239 :         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       290239 :         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       290239 :         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       290239 :     }
     399              : 
     400       292124 :     numSamplesPerLC3plusChannel = (int16_t) ( handle->config.samplerate / ( 1000000 / handle->config.isar_frame_duration_us ) / config_num_media_times );
     401       876352 :     for ( iDec = 0; iDec < handle->num_decs; iDec++ )
     402              :     {
     403      2673231 :         for ( iMediaTime = 0; iMediaTime < config_num_media_times; iMediaTime++ )
     404              :         {
     405      2089003 :             iFtd = iDec + iMediaTime * handle->num_decs;
     406      2089003 :             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            0 :             }
     421              : 
     422              :             /* reset cache if caching is enabled - it has either been decoded or is not needed */
     423      2089003 :             if ( NULL != handle->bitstream_caches )
     424              :             {
     425      2089003 :                 handle->bitstream_caches[iDec]->bitstream_cache_size = 0;
     426      2089003 :             }
     427              : 
     428      2089003 :             switch ( handle->selective_decoding_states[iDec]->frame_action )
     429              :             {
     430              :                 case DEC_ACTION_DECODE_AND_USE:
     431              :                 {
     432      2089003 :                     if ( badFrameIndicator )
     433              :                     {
     434        14911 :                         err = decode_or_conceal_one_lc3plus_frame( handle->handles[iDec], bitstream_in, bitstream_in_size, &handle->pcm_conversion_buffer, badFrameIndicator );
     435        14911 :                     }
     436      2074092 :                     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      2074092 :                         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      2089003 :                     if ( err != IVAS_ERR_OK )
     447              :                     {
     448            0 :                         return IVAS_ERROR( err, "lc3plus decoding failed\n" );
     449              :                     }
     450              : 
     451    525077563 :                     for ( int16_t iSampleInt16 = 0; iSampleInt16 < numSamplesPerLC3plusChannel; iSampleInt16++ )
     452              :                     {
     453    522988560 :                         ivasSampleIndex = iSampleInt16 + iMediaTime * numSamplesPerLC3plusChannel;
     454    522988560 :                         pcm_out[iDec][ivasSampleIndex] = (float) handle->pcm_conversion_buffer[iSampleInt16];
     455    522988560 :                     }
     456      2089003 :                     handle->selective_decoding_states[iDec]->has_skipped_a_frame = 0;
     457      2089003 :                     break;
     458              :                 }
     459              :                 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      2089003 :         } /* for each media time */
     477              :         /* reset skipping state, must be set by the user before each decode call*/
     478       584228 :         handle->selective_decoding_states[iDec]->frame_action = DEC_ACTION_DECODE_AND_USE;
     479       584228 :     } /* for each dec/channel */
     480              : 
     481       292124 :     return IVAS_ERR_OK;
     482       292124 : }
     483              : 
     484              : 
     485              : /*-------------------------------------------------------------------------
     486              :  * ISAR_LC3PLUS_DEC_Decode()
     487              :  *
     488              :  *
     489              :  *------------------------------------------------------------------------*/
     490              : 
     491       290246 : 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       290246 :     if ( NULL == handle )
     501              :     {
     502            7 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     503              :     }
     504       290239 :     if ( NULL == bitstream_in )
     505              :     {
     506            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "bitstream_in is NULL\n" );
     507              :     }
     508       290239 :     if ( NULL == pcm_out )
     509              :     {
     510            0 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pcm_out is NULL\n" );
     511              :     }
     512       290239 :     badFrameIndicator = 0;
     513              : 
     514       290239 :     return isar_LC3PLUS_DEC_Decode_or_Conceal_internal( handle, bitstream_in, bitstream_in_size, badFrameIndicator, pcm_out );
     515       290246 : }
     516              : 
     517              : 
     518              : /*-------------------------------------------------------------------------
     519              :  * ISAR_LC3PLUS_DEC_Conceal()
     520              :  *
     521              :  *
     522              :  *------------------------------------------------------------------------*/
     523              : 
     524         1887 : 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         1887 :     if ( NULL == handle )
     533              :     {
     534            2 :         return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "LC3PLUS_Dec_Wrap_Handle is NULL\n" );
     535              :     }
     536              : 
     537         1885 :     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         1885 :     badFrameIndicator = 1;
     544              : 
     545         1885 :     return isar_LC3PLUS_DEC_Decode_or_Conceal_internal( handle, bitstream_in, 0, badFrameIndicator, pcm_out );
     546         1887 : }
        

Generated by: LCOV version 2.0-1