LCOV - code coverage report
Current view: top level - lib_com - parameter_bitmaping.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 68 68 100.0 %
Date: 2025-05-23 08:37:30 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     1705541 : static int16_t PutIntoBitstream( const int16_t **pStream, TEncodeValue EncodeValue, int16_t index, BSTR_ENC_HANDLE hBstr, const int16_t nBits )
      54             : {
      55     1705541 :     const int16_t value = *( *pStream )++;
      56     1705541 :     const int16_t codedValue = EncodeValue( value, index );
      57             : 
      58     1705541 :     push_next_indice( hBstr, codedValue, nBits );
      59             : 
      60     1705541 :     return value;
      61             : }
      62             : 
      63             : /** Get nBits long value from bitstream into *pStream. */
      64     5035500 : 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     5035500 :     int16_t value = 0;
      72     5035500 :     if ( DecodeValue != NULL )
      73             :     {
      74     2183310 :         DecodeValue( st, index, &value );
      75             :     }
      76             :     else
      77             :     {
      78     2852190 :         value = get_next_indice( st, nFixedBits );
      79             :     }
      80     5035500 :     *( *pStream )++ = value;
      81             : 
      82     5035500 :     return value;
      83             : }
      84             : 
      85             : 
      86      968386 : static int16_t FixedWidthEncoding( int16_t value, int16_t index )
      87             : {
      88             :     (void) index; /* suppress compiler warnings */
      89             : 
      90      968386 :     return value;
      91             : }
      92             : 
      93             : 
      94             : /********************************/
      95             : /*      Interface functions     */
      96             : /********************************/
      97             : 
      98     1750684 : 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     1750684 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( pnBits != NULL ) );
     112             : 
     113     1750684 :     nParams = paramsBitMap->nParams;
     114     4049544 :     for ( index = 0; index < nArrayLength; index++ )
     115             :     {
     116     4669428 :         for ( iParam = 0; iParam < nParams; iParam++ )
     117             :         {
     118     2370568 :             ParamBitMap const *const param = &paramsBitMap->params[iParam];
     119             : 
     120             : #define WMC_TOOL_SKIP
     121     2370568 :             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     2370568 :             if ( param->fZeroAllowed || ( param->EncodeValue != NULL ) )
     125             :             {
     126     2281541 :                 *( *pStream )++ = value;
     127             :             }
     128             :             else
     129             :             {
     130       89027 :                 *( *pStream )++ = value - 1;
     131             :             }
     132     2370568 :             ++*pnSize;
     133             : #define WMC_TOOL_SKIP
     134     2370568 :             *pnBits += ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( value, index );
     135             : #undef WMC_TOOL_SKIP
     136     2370568 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     137             :             {
     138      295864 :                 GetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits );
     139             :             }
     140             :         }
     141             :     }
     142             : 
     143     1750684 :     return;
     144             : }
     145             : 
     146             : 
     147     3274329 : 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     3274329 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pParameter != NULL ) && ( pStream != NULL ) && ( pnSize != NULL ) );
     160             : 
     161     3274329 :     nParams = paramsBitMap->nParams;
     162     8172342 :     for ( index = 0; index < nArrayLength; index++ )
     163             :     {
     164    10008789 :         for ( iParam = 0; iParam < nParams; iParam++ )
     165             :         {
     166     5110776 :             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     5110776 :             value = *( *pStream )++ + ( param->fZeroAllowed || ( param->EncodeValue != NULL ) ? 0 : 1 );
     170             : #define WMC_TOOL_SKIP
     171     5110776 :             pSubStruct = param->SetParamValue( pParameter, index, value );
     172             : #undef WMC_TOOL_SKIP
     173     5110776 :             ++*pnSize;
     174     5110776 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     175             :             {
     176      876261 :                 SetParameters( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize );
     177             :             }
     178             :         }
     179             :     }
     180             : 
     181     3274329 :     return;
     182             : }
     183             : 
     184             : 
     185     1100479 : 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     1100479 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) );
     197             : 
     198     1100479 :     nParams = paramsBitMap->nParams;
     199     2736830 :     for ( index = 0; index < nArrayLength; index++ )
     200             :     {
     201     3341892 :         for ( iParam = 0; iParam < nParams; iParam++ )
     202             :         {
     203     1705541 :             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     1705541 :             nBits = ( param->nBits != 0 ) ? param->nBits : param->GetNumberOfBits( **pStream, index );
     212             : #undef WMC_TOOL_SKIP
     213     1705541 :             fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
     214     1705541 :             EncodeValue = ( param->EncodeValue == NULL ) ? &FixedWidthEncoding : param->EncodeValue;
     215     1705541 :             value = PutIntoBitstream( pStream, EncodeValue, index, hBstr, nBits ) + ( fShiftValue ? 1 : 0 );
     216     1705541 :             ++*pnSize;
     217     1705541 :             *pnBits += nBits;
     218     1705541 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     219             :             {
     220      287792 :                 WriteToBitstream( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits );
     221             :             }
     222             :         }
     223             :     }
     224             : 
     225     1100479 :     return;
     226             : }
     227             : 
     228             : 
     229     3242904 : 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     3242904 :     assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
     242             : 
     243     3242904 :     nParams = paramsBitMap->nParams;
     244     8073081 :     for ( index = 0; index < nArrayLength; index++ )
     245             :     {
     246     9865677 :         for ( iParam = 0; iParam < nParams; iParam++ )
     247             :         {
     248     5035500 :             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     5035500 :             fShiftValue = !param->fZeroAllowed && ( param->EncodeValue == NULL );
     252     5035500 :             value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream ) + ( fShiftValue ? 1 : 0 );
     253     5035500 :             if ( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) )
     254             :             {
     255      852456 :                 ReadFromBitstream( param->pSubParamBitMap, value, st, pStream, pnSize );
     256             :             }
     257             :         }
     258             :     }
     259             : 
     260     3242904 :     *pnSize += nParams * nArrayLength;
     261             : 
     262     3242904 :     return;
     263             : }

Generated by: LCOV version 1.14