LCOV - code coverage report
Current view: top level - scripts/split_rendering/lc3plus_float - ivas_lc3plus_unit_test_payload_format.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 252 269 93.7 %
Date: 2025-11-01 08:50:45 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             : contributors to this repository. All Rights Reserved.
       8             : 
       9             : This software is protected by copyright law and by international treaties.
      10             : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             : contributors to this repository retain full ownership rights in their respective contributions in
      15             : the software. This notice grants no license of any kind, including but not limited to patent
      16             : license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             : contributions.
      20             : 
      21             : This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             : development stage. It is intended exclusively for experts who have experience with such software and
      23             : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             : and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             : Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             : the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdlib.h>
      35             : #include <string.h>
      36             : #include "isar_lc3plus_payload.h"
      37             : #include "ivas_error_utils.h"
      38             : #include "isar_lc3plus_common.h"
      39             : #include "options.h"
      40             : 
      41             : 
      42             : /* included by ivas_lc3plus_unit_test.c */
      43             : 
      44             : #define LC3PLUS_MAX_NUM_CODERS 16
      45             : #define LC3PLUS_MAX_BS_SIZE    LC3PLUS_MAX_NUM_CODERS *( 720 * LC3PLUS_RTP_PAYLOAD_MAX_NUM_MEDIA_TIMES )
      46             : #define SIZE_70                70
      47             : #define SIZE_160               160
      48             : #define SIZE_320               320
      49             : #define SIZE_600               600
      50             : 
      51           1 : static int pack_and_unpack_payload_config_2ch_10ms_lc3plus_20ms_ivas( void )
      52             : {
      53             :     LC3PLUS_RTP_FTD sender_ftds[LC3PLUS_MAX_NUM_CODERS];
      54           1 :     int32_t sender_ftds_num = 0;
      55           1 :     const LC3PLUS_RTP_FDL fdl_req = LC3PLUS_RTP_FDL_NO_REQ_OR_NO_DATA;
      56             : 
      57           1 :     LC3PLUS_RTP_FTD *ftd_L_01 = &sender_ftds[0];
      58           1 :     ftd_L_01->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
      59           1 :     ftd_L_01->fdi = LC3PLUS_RTP_FTD_FDI_10000_US;
      60           1 :     ftd_L_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
      61           1 :     ftd_L_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
      62           1 :     ftd_L_01->frame_data = NULL;
      63           1 :     ftd_L_01->frame_data_length = SIZE_160;
      64           1 :     sender_ftds_num++;
      65             : 
      66           1 :     LC3PLUS_RTP_FTD *ftd_R_01 = &sender_ftds[1];
      67           1 :     ftd_R_01->fc = LC3PLUS_RTP_FTD_FC_LAST_IN_MEDIATIME;
      68           1 :     ftd_R_01->fdi = LC3PLUS_RTP_FTD_FDI_10000_US;
      69           1 :     ftd_R_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
      70           1 :     ftd_R_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
      71           1 :     ftd_R_01->frame_data = NULL;
      72           1 :     ftd_R_01->frame_data_length = SIZE_600;
      73           1 :     sender_ftds_num++;
      74             : 
      75           1 :     LC3PLUS_RTP_FTD *ftd_L_02 = &sender_ftds[2];
      76           1 :     ftd_L_02->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
      77           1 :     ftd_L_02->fdi = LC3PLUS_RTP_FTD_FDI_10000_US;
      78           1 :     ftd_L_02->bwr = LC3PLUS_RTP_FTD_BWR_FB;
      79           1 :     ftd_L_02->h = LC3PLUS_RTP_FTD_H_PRIMARY;
      80           1 :     ftd_L_02->frame_data = NULL;
      81           1 :     ftd_L_02->frame_data_length = SIZE_320;
      82           1 :     sender_ftds_num++;
      83             : 
      84           1 :     LC3PLUS_RTP_FTD *ftd_R_02 = &sender_ftds[3];
      85           1 :     ftd_R_02->fc = LC3PLUS_RTP_FTD_FC_LAST_OVERALL;
      86           1 :     ftd_R_02->fdi = LC3PLUS_RTP_FTD_FDI_10000_US;
      87           1 :     ftd_R_02->bwr = LC3PLUS_RTP_FTD_BWR_FB;
      88           1 :     ftd_R_02->h = LC3PLUS_RTP_FTD_H_PRIMARY;
      89           1 :     ftd_R_02->frame_data = NULL;
      90           1 :     ftd_R_02->frame_data_length = SIZE_160;
      91           1 :     sender_ftds_num++;
      92             : 
      93           1 :     const size_t packed_buffer_capacity = LC3PLUS_MAX_BS_SIZE;
      94             :     size_t packed_buffer_actual_size;
      95             :     uint8_t packed_buffer[LC3PLUS_MAX_BS_SIZE];
      96           1 :     memset( packed_buffer, 0, packed_buffer_capacity );
      97             :     // prepare bitstream buffer headers & layout
      98           1 :     LC3PLUS_RTP_ERR error = LC3PLUS_RTP_payload_serialize( packed_buffer, packed_buffer_capacity, &packed_buffer_actual_size, fdl_req, sender_ftds, sender_ftds_num );
      99           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     100             :     {
     101           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_serialize failed\n" );
     102             :     }
     103             : 
     104             :     // copy encoded frames into their expected memory locations
     105             :     uint8_t frame_data_L_01[SIZE_160];
     106           1 :     memset( frame_data_L_01, 0x01, sizeof( frame_data_L_01 ) );
     107             :     uint8_t frame_data_R_01[SIZE_600];
     108           1 :     memset( frame_data_R_01, 0x02, sizeof( frame_data_R_01 ) );
     109             :     uint8_t frame_data_L_02[SIZE_320];
     110           1 :     memset( frame_data_L_02, 0x03, sizeof( frame_data_L_02 ) );
     111             :     uint8_t frame_data_R_02[SIZE_160];
     112           1 :     memset( frame_data_R_02, 0x04, sizeof( frame_data_R_02 ) );
     113           1 :     memcpy( sender_ftds[0].frame_data, frame_data_L_01, sender_ftds[0].frame_data_length );
     114           1 :     memcpy( sender_ftds[1].frame_data, frame_data_R_01, sender_ftds[1].frame_data_length );
     115           1 :     memcpy( sender_ftds[2].frame_data, frame_data_L_02, sender_ftds[2].frame_data_length );
     116           1 :     memcpy( sender_ftds[3].frame_data, frame_data_R_02, sender_ftds[3].frame_data_length );
     117             : 
     118           1 :     uint8_t *receiverBuffer = malloc( packed_buffer_actual_size );
     119           1 :     assert( NULL != receiverBuffer );
     120           1 :     memcpy( receiverBuffer, packed_buffer, packed_buffer_actual_size );
     121             : 
     122             :     LC3PLUS_RTP_PAYLOAD payload_config;
     123           1 :     error = LC3PLUS_RTP_payload_deserialize( &payload_config, receiverBuffer, packed_buffer_actual_size );
     124           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     125             :     {
     126           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_deserialize failed\n" );
     127             :     }
     128             : 
     129           1 :     assert( payload_config.fdl_request == fdl_req );
     130           1 :     assert( payload_config.frame_duration_us == 10000 );
     131           1 :     assert( payload_config.high_resolution_enabled == 0 );
     132           1 :     assert( payload_config.sampling_rate_hz == 48000 );
     133           1 :     assert( payload_config.num_ftds == 4 );
     134           1 :     assert( payload_config.num_media_times == 2 );
     135           1 :     assert( payload_config.num_channels == 2 );
     136           5 :     for ( int32_t i = 0; i < payload_config.num_ftds; ++i )
     137             :     {
     138           4 :         assert( payload_config.ftds[i].frame_data_length == sender_ftds[i].frame_data_length );
     139           4 :         assert( payload_config.ftds[i].h == sender_ftds[i].h );
     140           4 :         assert( payload_config.ftds[i].fdi == sender_ftds[i].fdi );
     141           4 :         assert( payload_config.ftds[i].bwr == sender_ftds[i].bwr );
     142           4 :         assert( payload_config.ftds[i].fc == sender_ftds[i].fc );
     143           4 :         assert( payload_config.ftds[i].frame_data_length == sender_ftds[i].frame_data_length );
     144           4 :         assert( payload_config.ftds[i].frame_data != sender_ftds[i].frame_data );
     145           4 :         assert( 0 == memcmp( payload_config.ftds[i].frame_data, sender_ftds[i].frame_data, sender_ftds[i].frame_data_length ) );
     146             :     }
     147             : 
     148           1 :     free( receiverBuffer );
     149           1 :     return 0;
     150             : }
     151             : 
     152           1 : static int pack_and_unpack_payload_config_2ch_5ms_lc3plus_20ms_ivas( void )
     153             : {
     154             :     LC3PLUS_RTP_FTD sender_ftds[LC3PLUS_MAX_NUM_CODERS];
     155           1 :     int32_t sender_ftds_num = 0;
     156           1 :     const LC3PLUS_RTP_FDL fdl_req = LC3PLUS_RTP_FDL_NO_REQ_OR_NO_DATA;
     157             : 
     158           1 :     LC3PLUS_RTP_FTD *ftd_L_01 = &sender_ftds[0];
     159           1 :     ftd_L_01->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
     160           1 :     ftd_L_01->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     161           1 :     ftd_L_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     162           1 :     ftd_L_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     163           1 :     ftd_L_01->frame_data = NULL;
     164           1 :     ftd_L_01->frame_data_length = SIZE_70;
     165           1 :     sender_ftds_num++;
     166             : 
     167           1 :     LC3PLUS_RTP_FTD *ftd_R_01 = &sender_ftds[1];
     168           1 :     ftd_R_01->fc = LC3PLUS_RTP_FTD_FC_LAST_IN_MEDIATIME;
     169           1 :     ftd_R_01->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     170           1 :     ftd_R_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     171           1 :     ftd_R_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     172           1 :     ftd_R_01->frame_data = NULL;
     173           1 :     ftd_R_01->frame_data_length = SIZE_320;
     174           1 :     sender_ftds_num++;
     175             : 
     176           1 :     LC3PLUS_RTP_FTD *ftd_L_02 = &sender_ftds[2];
     177           1 :     ftd_L_02->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
     178           1 :     ftd_L_02->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     179           1 :     ftd_L_02->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     180           1 :     ftd_L_02->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     181           1 :     ftd_L_02->frame_data = NULL;
     182           1 :     ftd_L_02->frame_data_length = SIZE_70;
     183           1 :     sender_ftds_num++;
     184             : 
     185           1 :     LC3PLUS_RTP_FTD *ftd_R_02 = &sender_ftds[3];
     186           1 :     ftd_R_02->fc = LC3PLUS_RTP_FTD_FC_LAST_IN_MEDIATIME;
     187           1 :     ftd_R_02->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     188           1 :     ftd_R_02->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     189           1 :     ftd_R_02->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     190           1 :     ftd_R_02->frame_data = NULL;
     191           1 :     ftd_R_02->frame_data_length = SIZE_160;
     192           1 :     sender_ftds_num++;
     193             : 
     194           1 :     LC3PLUS_RTP_FTD *ftd_L_03 = &sender_ftds[4];
     195           1 :     ftd_L_03->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
     196           1 :     ftd_L_03->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     197           1 :     ftd_L_03->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     198           1 :     ftd_L_03->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     199           1 :     ftd_L_03->frame_data = NULL;
     200           1 :     ftd_L_03->frame_data_length = SIZE_70;
     201           1 :     sender_ftds_num++;
     202             : 
     203           1 :     LC3PLUS_RTP_FTD *ftd_R_03 = &sender_ftds[5];
     204           1 :     ftd_R_03->fc = LC3PLUS_RTP_FTD_FC_LAST_IN_MEDIATIME;
     205           1 :     ftd_R_03->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     206           1 :     ftd_R_03->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     207           1 :     ftd_R_03->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     208           1 :     ftd_R_03->frame_data = NULL;
     209           1 :     ftd_R_03->frame_data_length = SIZE_320;
     210           1 :     sender_ftds_num++;
     211             : 
     212           1 :     LC3PLUS_RTP_FTD *ftd_L_04 = &sender_ftds[6];
     213           1 :     ftd_L_04->fc = LC3PLUS_RTP_FTD_FC_SUBSEQUENT_CHANNEL;
     214           1 :     ftd_L_04->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     215           1 :     ftd_L_04->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     216           1 :     ftd_L_04->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     217           1 :     ftd_L_04->frame_data = NULL;
     218           1 :     ftd_L_04->frame_data_length = SIZE_70;
     219           1 :     sender_ftds_num++;
     220             : 
     221           1 :     LC3PLUS_RTP_FTD *ftd_R_04 = &sender_ftds[7];
     222           1 :     ftd_R_04->fc = LC3PLUS_RTP_FTD_FC_LAST_OVERALL;
     223           1 :     ftd_R_04->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     224           1 :     ftd_R_04->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     225           1 :     ftd_R_04->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     226           1 :     ftd_R_04->frame_data = NULL;
     227           1 :     ftd_R_04->frame_data_length = SIZE_160;
     228           1 :     sender_ftds_num++;
     229             : 
     230           1 :     const size_t packed_buffer_capacity = LC3PLUS_MAX_BS_SIZE;
     231             :     size_t packed_buffer_actual_size;
     232             :     uint8_t packed_buffer[LC3PLUS_MAX_BS_SIZE];
     233           1 :     memset( packed_buffer, 0, packed_buffer_capacity );
     234             :     // prepare bitstream buffer headers & layout
     235           1 :     LC3PLUS_RTP_ERR error = LC3PLUS_RTP_payload_serialize( packed_buffer, packed_buffer_capacity, &packed_buffer_actual_size, fdl_req, sender_ftds, sender_ftds_num );
     236           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     237             :     {
     238           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_serialize failed\n" );
     239             :     }
     240             : 
     241             : 
     242             :     // copy encoded frames into their expected memory locations
     243             :     uint8_t frame_data_L_01[SIZE_70];
     244           1 :     assert( ftd_L_01->frame_data_length == sizeof( frame_data_L_01 ) );
     245           1 :     memset( frame_data_L_01, 0x01, sizeof( frame_data_L_01 ) );
     246             :     uint8_t frame_data_R_01[SIZE_320];
     247           1 :     assert( ftd_R_01->frame_data_length == sizeof( frame_data_R_01 ) );
     248           1 :     memset( frame_data_R_01, 0x02, sizeof( frame_data_R_01 ) );
     249             :     uint8_t frame_data_L_02[SIZE_70];
     250           1 :     assert( ftd_L_02->frame_data_length == sizeof( frame_data_L_02 ) );
     251           1 :     memset( frame_data_L_02, 0x03, sizeof( frame_data_L_02 ) );
     252             :     uint8_t frame_data_R_02[SIZE_160];
     253           1 :     assert( ftd_R_02->frame_data_length == sizeof( frame_data_R_02 ) );
     254           1 :     memset( frame_data_R_02, 0x04, sizeof( frame_data_R_02 ) );
     255             :     uint8_t frame_data_L_03[SIZE_70];
     256           1 :     assert( ftd_L_03->frame_data_length == sizeof( frame_data_L_03 ) );
     257           1 :     memset( frame_data_L_03, 0x05, sizeof( frame_data_L_03 ) );
     258             :     uint8_t frame_data_R_03[SIZE_320];
     259           1 :     assert( ftd_R_03->frame_data_length == sizeof( frame_data_R_03 ) );
     260           1 :     memset( frame_data_R_03, 0x06, sizeof( frame_data_R_03 ) );
     261             :     uint8_t frame_data_L_04[SIZE_70];
     262           1 :     assert( ftd_L_04->frame_data_length == sizeof( frame_data_L_04 ) );
     263           1 :     memset( frame_data_L_04, 0x07, sizeof( frame_data_L_04 ) );
     264             :     uint8_t frame_data_R_04[SIZE_160];
     265           1 :     assert( ftd_R_04->frame_data_length == sizeof( frame_data_R_04 ) );
     266           1 :     memset( frame_data_R_04, 0x08, sizeof( frame_data_R_04 ) );
     267           1 :     memcpy( sender_ftds[0].frame_data, frame_data_L_01, sender_ftds[0].frame_data_length );
     268           1 :     memcpy( sender_ftds[1].frame_data, frame_data_R_01, sender_ftds[1].frame_data_length );
     269           1 :     memcpy( sender_ftds[2].frame_data, frame_data_L_02, sender_ftds[2].frame_data_length );
     270           1 :     memcpy( sender_ftds[3].frame_data, frame_data_R_02, sender_ftds[3].frame_data_length );
     271           1 :     memcpy( sender_ftds[4].frame_data, frame_data_L_03, sender_ftds[4].frame_data_length );
     272           1 :     memcpy( sender_ftds[5].frame_data, frame_data_R_03, sender_ftds[5].frame_data_length );
     273           1 :     memcpy( sender_ftds[6].frame_data, frame_data_L_04, sender_ftds[6].frame_data_length );
     274           1 :     memcpy( sender_ftds[7].frame_data, frame_data_R_04, sender_ftds[7].frame_data_length );
     275             : 
     276           1 :     uint8_t *receiverBuffer = malloc( packed_buffer_actual_size );
     277           1 :     assert( NULL != receiverBuffer );
     278           1 :     memcpy( receiverBuffer, packed_buffer, packed_buffer_actual_size );
     279             : 
     280             :     LC3PLUS_RTP_PAYLOAD payload_config;
     281           1 :     error = LC3PLUS_RTP_payload_deserialize( &payload_config, receiverBuffer, packed_buffer_actual_size );
     282           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     283             :     {
     284           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_deserialize failed\n" );
     285             :     }
     286             : 
     287           1 :     assert( payload_config.fdl_request == fdl_req );
     288           1 :     assert( payload_config.frame_duration_us == 5000 );
     289           1 :     assert( payload_config.high_resolution_enabled == 0 );
     290           1 :     assert( payload_config.sampling_rate_hz == 48000 );
     291           1 :     assert( payload_config.num_ftds == 8 );
     292           1 :     assert( payload_config.num_media_times == 4 );
     293           1 :     assert( payload_config.num_channels == 2 );
     294           9 :     for ( int32_t i = 0; i < payload_config.num_ftds; ++i )
     295             :     {
     296           8 :         assert( payload_config.ftds[i].frame_data_length == sender_ftds[i].frame_data_length );
     297           8 :         assert( payload_config.ftds[i].h == sender_ftds[i].h );
     298           8 :         assert( payload_config.ftds[i].fdi == sender_ftds[i].fdi );
     299           8 :         assert( payload_config.ftds[i].bwr == sender_ftds[i].bwr );
     300           8 :         assert( payload_config.ftds[i].fc == sender_ftds[i].fc );
     301           8 :         assert( payload_config.ftds[i].frame_data_length == sender_ftds[i].frame_data_length );
     302           8 :         assert( payload_config.ftds[i].frame_data != sender_ftds[i].frame_data );
     303           8 :         assert( 0 == memcmp( payload_config.ftds[i].frame_data, sender_ftds[i].frame_data, sender_ftds[i].frame_data_length ) );
     304             :     }
     305             : 
     306           1 :     free( receiverBuffer );
     307           1 :     return 0;
     308             : }
     309             : 
     310           1 : static int try_unpack_invalid_values( void )
     311             : {
     312             :     LC3PLUS_RTP_FTD sender_ftds[LC3PLUS_MAX_NUM_CODERS];
     313           1 :     int32_t sender_ftds_num = 0;
     314           1 :     const LC3PLUS_RTP_FDL fdl_req = LC3PLUS_RTP_FDL_LENGTH_3_MAX;
     315             : 
     316           1 :     LC3PLUS_RTP_FTD *ftd_L_01 = &sender_ftds[0];
     317           1 :     ftd_L_01->fc = LC3PLUS_RTP_FTD_FC_LAST_OVERALL;
     318           1 :     ftd_L_01->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     319           1 :     ftd_L_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     320           1 :     ftd_L_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     321           1 :     ftd_L_01->frame_data = NULL;
     322           1 :     ftd_L_01->frame_data_length = SIZE_70;
     323           1 :     sender_ftds_num++;
     324             : 
     325           1 :     const size_t packed_buffer_capacity = LC3PLUS_MAX_BS_SIZE;
     326             :     size_t packed_buffer_actual_size;
     327             :     uint8_t packed_buffer[LC3PLUS_MAX_BS_SIZE];
     328           1 :     memset( packed_buffer, 0, packed_buffer_capacity );
     329             :     // prepare bitstream buffer headers & layout
     330           1 :     LC3PLUS_RTP_ERR error = LC3PLUS_RTP_payload_serialize( packed_buffer, packed_buffer_capacity, &packed_buffer_actual_size, fdl_req, sender_ftds, sender_ftds_num );
     331           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     332             :     {
     333           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_serialize failed\n" );
     334             :     }
     335             : 
     336             :     // copy encoded frames into their expected memory locations
     337             :     uint8_t frame_data_L_01[SIZE_70];
     338           1 :     assert( ftd_L_01->frame_data_length == sizeof( frame_data_L_01 ) );
     339           1 :     memset( frame_data_L_01, 0x01, sizeof( frame_data_L_01 ) );
     340             : 
     341           1 :     uint8_t *receiverBuffer = malloc( packed_buffer_actual_size );
     342           1 :     assert( NULL != receiverBuffer );
     343           1 :     memcpy( receiverBuffer, packed_buffer, packed_buffer_actual_size );
     344             : 
     345             :     int32_t fdl_req_length;
     346           1 :     error = LC3PLUS_RTP_frame_data_length_get_size( &fdl_req_length, fdl_req );
     347           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     348             :     {
     349           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_frame_data_length_get_size error\n" );
     350             :     }
     351          76 :     for ( int16_t packed_buffer_incorrect_size = 0; packed_buffer_incorrect_size < ( fdl_req_length + 2 + SIZE_70 ); ++packed_buffer_incorrect_size )
     352             :     {
     353             :         LC3PLUS_RTP_PAYLOAD payload_config;
     354          75 :         error = LC3PLUS_RTP_payload_deserialize( &payload_config, receiverBuffer, packed_buffer_incorrect_size );
     355          75 :         if ( error == LC3PLUS_RTP_ERR_NO_ERROR )
     356             :         {
     357           0 :             free( receiverBuffer );
     358           0 :             return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_deserialize failed to detect error\n" );
     359             :         }
     360             :     }
     361             : 
     362             :     LC3PLUS_RTP_PAYLOAD payload_config;
     363           1 :     error = LC3PLUS_RTP_payload_deserialize( &payload_config, receiverBuffer, packed_buffer_actual_size );
     364           1 :     if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     365             :     {
     366           0 :         free( receiverBuffer );
     367           0 :         return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_deserialize failed\n" );
     368             :     }
     369           1 :     free( receiverBuffer );
     370           1 :     return 0;
     371             : }
     372             : 
     373             : #define LC3PLUS_RTP_TEST_NUM_FTDS_UT 3
     374           1 : static int pack_and_unpack_different_fdl_sizes( void )
     375             : {
     376             :     int32_t iFtdUt;
     377             :     LC3PLUS_RTP_FDL fdl_requests_ut[LC3PLUS_RTP_TEST_NUM_FTDS_UT];
     378           1 :     fdl_requests_ut[0] = LC3PLUS_RTP_FDL_LENGTH_1_MIN;
     379           1 :     fdl_requests_ut[1] = LC3PLUS_RTP_FDL_LENGTH_2_MIN;
     380           1 :     fdl_requests_ut[2] = LC3PLUS_RTP_FDL_LENGTH_3_MIN;
     381             : 
     382           4 :     for ( iFtdUt = 0; iFtdUt < LC3PLUS_RTP_TEST_NUM_FTDS_UT; ++iFtdUt )
     383             :     {
     384             :         LC3PLUS_RTP_FTD sender_ftds[LC3PLUS_MAX_NUM_CODERS];
     385           3 :         int32_t sender_ftds_num = 0;
     386             : 
     387           3 :         LC3PLUS_RTP_FTD *ftd_L_01 = &sender_ftds[0];
     388           3 :         ftd_L_01->fc = LC3PLUS_RTP_FTD_FC_LAST_OVERALL;
     389           3 :         ftd_L_01->fdi = LC3PLUS_RTP_FTD_FDI_5000_US;
     390           3 :         ftd_L_01->bwr = LC3PLUS_RTP_FTD_BWR_FB;
     391           3 :         ftd_L_01->h = LC3PLUS_RTP_FTD_H_PRIMARY;
     392           3 :         ftd_L_01->frame_data = NULL;
     393           3 :         ftd_L_01->frame_data_length = fdl_requests_ut[iFtdUt];
     394           3 :         sender_ftds_num++;
     395             : 
     396           3 :         const size_t packed_buffer_capacity = LC3PLUS_MAX_BS_SIZE;
     397             :         size_t packed_buffer_actual_size;
     398             :         uint8_t packed_buffer[LC3PLUS_MAX_BS_SIZE];
     399           3 :         memset( packed_buffer, 0, packed_buffer_capacity );
     400             :         // prepare bitstream buffer headers & layout
     401           3 :         LC3PLUS_RTP_ERR error = LC3PLUS_RTP_payload_serialize( packed_buffer, packed_buffer_capacity, &packed_buffer_actual_size, fdl_requests_ut[iFtdUt], sender_ftds, sender_ftds_num );
     402           3 :         if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     403             :         {
     404           0 :             return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_serialize failed\n" );
     405             :         }
     406             : 
     407             :         // copy encoded frames into their expected memory locations
     408             :         uint8_t frame_data_L_01[SIZE_600];
     409           3 :         assert( ftd_L_01->frame_data_length <= sizeof( frame_data_L_01 ) );
     410           3 :         memset( frame_data_L_01, 0x01, ftd_L_01->frame_data_length );
     411             : 
     412           3 :         uint8_t *receiverBuffer = malloc( packed_buffer_actual_size );
     413           3 :         assert( NULL != receiverBuffer );
     414           3 :         memcpy( receiverBuffer, packed_buffer, packed_buffer_actual_size );
     415             : 
     416             :         LC3PLUS_RTP_PAYLOAD payload_config;
     417           3 :         error = LC3PLUS_RTP_payload_deserialize( &payload_config, receiverBuffer, packed_buffer_actual_size );
     418           3 :         if ( error != LC3PLUS_RTP_ERR_NO_ERROR )
     419             :         {
     420           0 :             free( receiverBuffer );
     421           0 :             return IVAS_ERROR( IVAS_LC3PLUS_LC3plusRtpErrToIvasErr( error ), "LC3PLUS_RTP_payload_deserialize failed\n" );
     422             :         }
     423           3 :         assert( payload_config.fdl_request == fdl_requests_ut[iFtdUt] );
     424           3 :         assert( payload_config.ftds[0].frame_data_length == fdl_requests_ut[iFtdUt] );
     425           3 :         free( receiverBuffer );
     426             :     }
     427           1 :     return 0;
     428             : }
     429             : 
     430           1 : static int run_all_payload_tests( void )
     431             : {
     432           1 :     if ( pack_and_unpack_payload_config_2ch_10ms_lc3plus_20ms_ivas() != 0 )
     433             :     {
     434           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL, "test failed\n" );
     435             :     }
     436           1 :     if ( pack_and_unpack_payload_config_2ch_5ms_lc3plus_20ms_ivas() != 0 )
     437             :     {
     438           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL, "test failed\n" );
     439             :     }
     440           1 :     if ( try_unpack_invalid_values() != 0 )
     441             :     {
     442           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL, "test failed\n" );
     443             :     }
     444           1 :     if ( pack_and_unpack_different_fdl_sizes() != 0 )
     445             :     {
     446           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL, "test failed\n" );
     447             :     }
     448           1 :     return 0;
     449             : }

Generated by: LCOV version 1.14