LCOV - code coverage report
Current view: top level - lib_com - parameter_bitmaping.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 68 68 100.0 %
Date: 2025-05-29 08:28:55 Functions: 7 7 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             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "stat_com.h"
      44             : #include "prot.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : 
      48             : /********************************/
      49             : /*      Helper functions        */
      50             : /********************************/
      51             : 
      52             : /** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */
      53    22550779 : static int16_t PutIntoBitstream( const int16_t **pStream, TEncodeValue EncodeValue, int16_t index, BSTR_ENC_HANDLE hBstr, const int16_t nBits )
      54             : {
      55    22550779 :     const int16_t value = *( *pStream )++;
      56    22550779 :     const int16_t codedValue = EncodeValue( value, index );
      57             : 
      58    22550779 :     push_next_indice( hBstr, codedValue, nBits );
      59             : 
      60    22550779 :     return value;
      61             : }
      62             : 
      63             : /** Get nBits long value from bitstream into *pStream. */
      64    47033413 : static int16_t GetFromBitstream(
      65             :     Decoder_State *st,
      66             :     TDecodeValue DecodeValue,
      67             :     uint16_t index,
      68             :     int16_t nFixedBits,
      69             :     int16_t **pStream )
      70             : {
      71    47033413 :     int16_t value = 0;
      72    47033413 :     if ( DecodeValue != NULL )
      73             :     {
      74    17449152 :         DecodeValue( st, index, &value );
      75             :     }
      76             :     else
      77             :     {
      78    29584261 :         value = get_next_indice( st, nFixedBits );
      79             :     }
      80    47033413 :     *( *pStream )++ = value;
      81             : 
      82    47033413 :     return value;
      83             : }
      84             : 
      85             : 
      86    13826885 : static int16_t FixedWidthEncoding( int16_t value, int16_t index )
      87             : {
      88             :     (void) index; /* suppress compiler warnings */
      89             : 
      90    13826885 :     return value;
      91             : }
      92             : 
      93             : 
      94             : /********************************/
      95             : /*      Interface functions     */
      96             : /********************************/
      97             : 
      98    25623768 : void GetParameters(
      99             :     ParamsBitMap const *paramsBitMap,
     100             :     const int16_t nArrayLength,
     101             :     void const *pParameter,
     102             :     int16_t **pStream,
     103             :     int16_t *pnSize,
     104             :     int16_t *pnBits )
     105             : {
     106             :     int16_t index;
     107             :     int16_t iParam, nParams;
     108             :     int16_t value;
     109             :     void const *pSubStruct;
     110             : 
     111    25623768 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
     112             : 
     113    25623768 :     nParams = paramsBitMap->nParams;
     114    57869451 :     for ( index = 0; index < nArrayLength; index++ )
     115             :     {
     116    65474829 :         for ( iParam = 0; iParam < nParams; iParam++ )
     117             :         {
     118    33229146 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
     119             : 
     120             : #define WMC_TOOL_SKIP
     121    33229146 :             pSubStruct = param->GetParamValue( pParameter, index, &value );
     122             : #undef WMC_TOOL_SKIP
     123             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     124    33229146 :             if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
     125             :             {
     126    32145185 :                 *( *pStream )++ = value;
     127             :             }
     128             :             else
     129             :             {
     130     1083961 :                 *( *pStream )++ = value - 1;
     131             :             }
     132    33229146 :             ++*pnSize;
     133             : #define WMC_TOOL_SKIP
     134    33229146 :             *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
     135             : #undef WMC_TOOL_SKIP
     136    33229146 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     137             :             {
     138     3640307 :                 GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
     139             :             }
     140             :         }
     141             :     }
     142             : 
     143    25623768 :     return;
     144             : }
     145             : 
     146             : 
     147    33024539 : void SetParameters(
     148             :     ParamsBitMap const *paramsBitMap,
     149             :     const int16_t nArrayLength,
     150             :     void *pParameter,
     151             :     const int16_t **pStream,
     152             :     int16_t *pnSize )
     153             : {
     154             :     int16_t index;
     155             :     int16_t iParam, nParams;
     156             :     int16_t value;
     157             :     void *pSubStruct;
     158             : 
     159    33024539 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
     160             : 
     161    33024539 :     nParams = paramsBitMap->nParams;
     162    79087697 :     for ( index = 0; index < nArrayLength; index++ )
     163             :     {
     164    93994041 :         for ( iParam = 0; iParam < nParams; iParam++ )
     165             :         {
     166    47930883 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
     167             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     168             : 
     169    47930883 :             value = *( *pStream )++ + ( param->fZeroAllowed || ( param->EncodeValue != NULL ) ? 0 : 1 );
     170             : #define WMC_TOOL_SKIP
     171    47930883 :             pSubStruct = param->SetParamValue( pParameter, index, value );
     172             : #undef WMC_TOOL_SKIP
     173    47930883 :             ++*pnSize;
     174    47930883 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     175             :             {
     176     7138139 :                 SetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize );
     177             :             }
     178             :         }
     179             :     }
     180             : 
     181    33024539 :     return;
     182             : }
     183             : 
     184             : 
     185    15324885 : void WriteToBitstream(
     186             :     ParamsBitMap const *paramsBitMap,
     187             :     const int16_t nArrayLength,
     188             :     const int16_t **pStream,
     189             :     int16_t *pnSize,
     190             :     BSTR_ENC_HANDLE hBstr,
     191             :     int16_t *pnBits )
     192             : {
     193             :     int16_t index;
     194             :     int16_t iParam, nParams;
     195             : 
     196    15324885 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
     197             : 
     198    15324885 :     nParams = paramsBitMap->nParams;
     199    36949285 :     for ( index = 0; index < nArrayLength; index++ )
     200             :     {
     201    44175179 :         for ( iParam = 0; iParam < nParams; iParam++ )
     202             :         {
     203    22550779 :             const ParamBitMap *param = &paramsBitMap->params[iParam];
     204             :             int16_t nBits;
     205             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     206             :             int16_t fShiftValue;
     207             :             TEncodeValue EncodeValue;
     208             :             int16_t value;
     209             : 
     210             : #define WMC_TOOL_SKIP
     211    22550779 :             nBits = ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( **pStream, index );
     212             : #undef WMC_TOOL_SKIP
     213    22550779 :             fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
     214    22550779 :             EncodeValue = ( param->EncodeValue == NULL ) ? &FixedWidthEncoding : param->EncodeValue;
     215    22550779 :             value = PutIntoBitstream( pStream, EncodeValue, index, hBstr, nBits ) + ( fShiftValue ? 1 : 0 );
     216    22550779 :             ++*pnSize;
     217    22550779 :             *pnBits += nBits;
     218    22550779 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     219             :             {
     220     3451256 :                 WriteToBitstream( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
     221             :             }
     222             :         }
     223             :     }
     224             : 
     225    15324885 :     return;
     226             : }
     227             : 
     228             : 
     229    32654772 : void ReadFromBitstream(
     230             :     ParamsBitMap const *paramsBitMap,
     231             :     const int16_t nArrayLength,
     232             :     Decoder_State *st,
     233             :     int16_t **pStream,
     234             :     int16_t *pnSize )
     235             : {
     236             :     int16_t index;
     237             :     int16_t iParam, nParams;
     238             :     int16_t fShiftValue;
     239             :     int16_t value;
     240             : 
     241    32654772 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
     242             : 
     243    32654772 :     nParams = paramsBitMap->nParams;
     244    77904978 :     for ( index = 0; index < nArrayLength; index++ )
     245             :     {
     246    92283619 :         for ( iParam = 0; iParam < nParams; iParam++ )
     247             :         {
     248    47033413 :             ParamBitMap const *param = &paramsBitMap->params[iParam];
     249             :             /* If a function for encoding/decoding value is defined than it should take care of 0 */
     250             : 
     251    47033413 :             fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
     252    47033413 :             value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream ) + ( fShiftValue ? 1 : 0 );
     253    47033413 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     254             :             {
     255     6854930 :                 ReadFromBitstream( param->pSubParamBitMap, value, st, pStream, pnSize );
     256             :             }
     257             :         }
     258             :     }
     259             : 
     260    32654772 :     *pnSize += nParams * nArrayLength;
     261             : 
     262    32654772 :     return;
     263             : }

Generated by: LCOV version 1.14