From 51bfe505878081563e66496b55fb043699f443f4 Mon Sep 17 00:00:00 2001 From: Ripinder Singh Date: Fri, 27 Mar 2026 12:02:23 +1100 Subject: [PATCH] 1527: Add tests for incorrect bitrate idx reported in CMR requests * Add support for passing a requests file from command line to set CMR and other requests at frame boundary * Add test for iterating through valid bandwidth/codec/bitrate combinations and comparing bitstream with expected values Signed-off-by: Ripinder Singh --- Workspace_msvc/lib_util.vcxproj | 2 + apps/encoder.c | 62 ++++++++++++ lib_util/ivas_rtp_file.c | 14 +++ lib_util/ivas_rtp_file.h | 3 + lib_util/requests_file_reader.c | 167 ++++++++++++++++++++++++++++++++ lib_util/requests_file_reader.h | 85 ++++++++++++++++ 6 files changed, 333 insertions(+) create mode 100644 lib_util/requests_file_reader.c create mode 100644 lib_util/requests_file_reader.h diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index bfbfa8d4c..b0c380c38 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -129,6 +129,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/apps/encoder.c b/apps/encoder.c index 31d9b448c..01064681d 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -45,6 +45,9 @@ #include "masa_file_reader.h" #include "rotation_file_reader.h" #include "ivas_rtp_file.h" +#ifdef FIX_1527_CMR_BITRATE_IDX +#include "requests_file_reader.h" +#endif #include "wmc_auto.h" @@ -165,6 +168,9 @@ typedef struct char *sceneOrientationTrajFileName; char *deviceOrientationTrajFileName; +#ifdef FIX_1527_CMR_BITRATE_IDX + char *requestsFileName; +#endif } EncArguments; @@ -221,6 +227,9 @@ int main( uint8_t au[IVAS_MAX_BITS_PER_FRAME / 8]; IVAS_RTP ivasRtp = { 0 }; +#ifdef FIX_1527_CMR_BITRATE_IDX + ReqFileReader *requestsFileReader = NULL; +#endif /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we use fixed seed for random num generator for regression based tests. Any realtime application should implement this initialization seperately */ @@ -651,6 +660,20 @@ int main( } } +#ifdef FIX_1527_CMR_BITRATE_IDX + /*------------------------------------------------------------------------------------------* + * Open remote requests file for rtp packing (E-bytes) + *------------------------------------------------------------------------------------------*/ + if ( arg.requestsFileName != NULL ) + { + if ( ( error = RequestsFileReader_open( arg.requestsFileName, &requestsFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open requests file %s \n\n", arg.requestsFileName ); + goto cleanup; + } + } +#endif + /*------------------------------------------------------------------------------------------* * Run the encoder *------------------------------------------------------------------------------------------*/ @@ -860,6 +883,17 @@ int main( } } +#ifdef FIX_1527_CMR_BITRATE_IDX + if ( requestsFileReader ) + { + if ( ( error = ReadNextRequests( requestsFileReader, ivasRtp.remoteRequests, &ivasRtp.remoteRequestBitmap ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading requests from %s\n", IVAS_ENC_GetErrorMessage( error ), RequestsFileReader_getFilePath( requestsFileReader ) ); + goto cleanup; + } + } +#endif + if ( ( error = IVAS_ENC_EncodeFrameToCompact( hIvasEnc, pcmBuf, pcmBufSize, au, &numBits ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); @@ -955,6 +989,13 @@ cleanup: fclose( f_bitrateProfile ); } +#ifdef FIX_1527_CMR_BITRATE_IDX + if ( requestsFileReader ) + { + RequestsFileReader_close( &requestsFileReader ); + } +#endif + if ( sceneOrientationFileReader ) { RotationFileReader_close( &sceneOrientationFileReader ); @@ -1001,6 +1042,9 @@ static bool parseCmdlIVAS_enc( /*-----------------------------------------------------------------* * Set default values *-----------------------------------------------------------------*/ +#ifdef FIX_1527_CMR_BITRATE_IDX + memset( arg, 0, sizeof( *arg ) ); +#endif arg->inputWavFilename = NULL; arg->outputBitstreamFilename = NULL; @@ -1867,6 +1911,20 @@ static bool parseCmdlIVAS_enc( arg->deviceOrientationTrajFileName = argv[i]; i++; } +#ifdef FIX_1527_CMR_BITRATE_IDX + else if ( strcmp( argv_to_upper, "-REQUESTS" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Remote requests file name not specified!\n\n" ); + usage_enc(); + return false; + } + arg->requestsFileName = argv[i]; + i++; + } +#endif /*-----------------------------------------------------------------* * Option not recognized @@ -2086,6 +2144,10 @@ static void usage_enc( void ) fprintf( stdout, " EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet\n" ); fprintf( stdout, "-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output.\n" ); fprintf( stdout, "-device_orientation : Device orientation trajectory file. Only used with rtpdump output.\n" ); +#ifdef FIX_1527_CMR_BITRATE_IDX + fprintf( stdout, "-requests : Remote requests file, Only used with rtpdump output.\n" ); +#endif + fprintf( stdout, "\n" ); return; diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c index 37d03a385..1eafa9bf8 100644 --- a/lib_util/ivas_rtp_file.c +++ b/lib_util/ivas_rtp_file.c @@ -1001,6 +1001,20 @@ ivas_error IVAS_RTP_WriteNextFrame( rtp->nWrittenPiData--; } +#ifdef FIX_1527_CMR_BITRATE_IDX + for ( IVAS_RTP_REQUEST_TYPE req = 0; req < IVAS_REQUEST_MAX; req++ ) + { + if ( rtp->remoteRequestBitmap & ( 1u << req ) ) + { + if ( ( error = IVAS_RTP_PACK_PushRemoteRequest( rtp->hPack, req, rtp->remoteRequests[req] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while pushing requests\n", ivas_error_to_string( error ) ); + return error; + } + } + } +#endif + if ( forcePacket || IVAS_RTP_PACK_GetNumFrames( rtp->hPack ) == rtp->packCfg.maxFramesPerPacket ) { uint32_t numFramesInPayload = 0; diff --git a/lib_util/ivas_rtp_file.h b/lib_util/ivas_rtp_file.h index a3742c6c8..9e0c2906a 100644 --- a/lib_util/ivas_rtp_file.h +++ b/lib_util/ivas_rtp_file.h @@ -44,6 +44,9 @@ typedef struct uint8_t packet[NOMINAL_BUFFER_SIZE( IVAS_MAX_FRAMES_PER_RTP_PACKET )]; IVAS_PIDATA_TS piData[IVAS_PI_MAX_ID * IVAS_MAX_FRAMES_PER_RTP_PACKET]; +#ifdef FIX_1527_CMR_BITRATE_IDX + IVAS_RTP_REQUEST_VALUE remoteRequests[IVAS_REQUEST_MAX]; +#endif IVAS_RTP_FILE_HANDLE hRtpFile; FILE *f_piDataOut; FILE *f_piExtOut; diff --git a/lib_util/requests_file_reader.c b/lib_util/requests_file_reader.c new file mode 100644 index 000000000..894b07568 --- /dev/null +++ b/lib_util/requests_file_reader.c @@ -0,0 +1,167 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "requests_file_reader.h" +#include +#include +#include + + +struct ReqFileReader +{ + FILE *requestsFile; + int32_t frameCounter; + char *file_path; + bool fileRewind; +}; + + +/*-----------------------------------------------------------------------* + * RequestsFileReader_open() + * + * Allocate and initialize requests reader + *-----------------------------------------------------------------------*/ + +ivas_error RequestsFileReader_open( + char *requestsFilePath, /* i : requests file name */ + ReqFileReader **reqReader /* o : ReqFileReader handle */ +) +{ + ReqFileReader *self; + FILE *requestsFile; + + /* Open trajectory file */ + if ( strlen( requestsFilePath ) < 1 ) + { + return IVAS_ERR_FAILED_FILE_OPEN; + } + + requestsFile = fopen( requestsFilePath, "r" ); + + if ( !requestsFile ) + { + return IVAS_ERR_FAILED_FILE_OPEN; + } + + self = calloc( 1, sizeof( ReqFileReader ) ); + self->requestsFile = requestsFile; + self->frameCounter = 0; + self->file_path = calloc( strlen( requestsFilePath ) + 1, sizeof( char ) ); + strcpy( self->file_path, requestsFilePath ); + self->fileRewind = false; + + *reqReader = self; + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------* + * RequestsFileReader_close() + * + * Deallocates memory for the requests reader + *-----------------------------------------------------------------------*/ + +void RequestsFileReader_close( + ReqFileReader **reqReader /* i/o: ReqFileReader handle */ +) +{ + if ( reqReader == NULL || *reqReader == NULL ) + { + return; + } + + fclose( ( *reqReader )->requestsFile ); + free( ( *reqReader )->file_path ); + free( *reqReader ); + *reqReader = NULL; + + return; +} + +/*-----------------------------------------------------------------------* + * ReadNextRequests() + * + * Read request for next frame from the requests file + *-----------------------------------------------------------------------*/ + +ivas_error ReadNextRequests( + ReqFileReader *reqReader, /* i/o: ReqFileReader handle */ + IVAS_RTP_REQUEST_VALUE reqs[IVAS_REQUEST_MAX], /* o : Requests buffer buffer */ + uint32_t *remoteRequestBitmap /* o : Bitmap of available request */ +) +{ + *remoteRequestBitmap = 0u; + if ( !feof( reqReader->requestsFile ) ) + { + if ( IVAS_REQUEST_MAX != fscanf( reqReader->requestsFile, "%d,%d,%d,%d,%d,%d,%d\n", + (int32_t *) &reqs[IVAS_REQUEST_CODEC].codec, + (int32_t *) &reqs[IVAS_REQUEST_BITRATE].bitrate, + (int32_t *) &reqs[IVAS_REQUEST_BANDWIDTH].bandwidth, + (int32_t *) &reqs[IVAS_REQUEST_FORMAT].formatType, + (int32_t *) &reqs[IVAS_REQUEST_CA_MODE].caMode, + (int32_t *) &reqs[IVAS_REQUEST_SUBFORMAT].subFormatType, + (int32_t *) &reqs[IVAS_REQUEST_SR_CONFIG].srConfig ) ) + { + return IVAS_ERR_FAILED_FILE_PARSE; + } + + /* Indicate Request present if not equal to -1 */ + for ( IVAS_RTP_REQUEST_TYPE req = 0; req < IVAS_REQUEST_MAX; req++ ) + { + if ( reqs[req].bitrate != ( ~0u ) ) + { + *remoteRequestBitmap |= ( 1u << req ); + } + } + } + + return IVAS_ERR_OK; +} + + +/*-----------------------------------------------------------------------* + * HeadRequestsFileReader_getFilePath() + * + * + *-----------------------------------------------------------------------*/ + +const char *RequestsFileReader_getFilePath( + ReqFileReader *reqReader /* i/o: ReqFileReader handle */ +) +{ + if ( reqReader == NULL ) + { + return NULL; + } + + return reqReader->file_path; +} diff --git a/lib_util/requests_file_reader.h b/lib_util/requests_file_reader.h new file mode 100644 index 000000000..0918dd344 --- /dev/null +++ b/lib_util/requests_file_reader.h @@ -0,0 +1,85 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_REQUESTS_FILE_READER_H +#define IVAS_REQUESTS_FILE_READER_H + +#include "common_api_types.h" +#include "ivas_rtp_api.h" + +typedef struct ReqFileReader ReqFileReader; + +/*-----------------------------------------------------------------------* + * RequestsFileReader_open() + * + * Allocate and initialize requests handle + *-----------------------------------------------------------------------*/ + +ivas_error RequestsFileReader_open( + char *requestsFilePath, /* i : requests file name */ + ReqFileReader **reqReader /* o : ReqFileReader handle */ +); + +/*-----------------------------------------------------------------------* + * RequestsFileReading() + * + * Read values from the trajectory file + *-----------------------------------------------------------------------*/ + +ivas_error ReadNextRequests( + ReqFileReader *reqReader, /* i/o: ReqFileReader handle */ + IVAS_RTP_REQUEST_VALUE reqs[IVAS_REQUEST_MAX], /* o : Requests buffer buffer */ + uint32_t *remoteRequestBitmap /* o : Bitmap of available request */ +); + +/*-----------------------------------------------------------------------* + * RequestsFileReader_close() + * + * Deallocates memory for the requests handle + *-----------------------------------------------------------------------*/ + +void RequestsFileReader_close( + ReqFileReader **reqReader /* i/o: ReqFileReader handle */ +); + +/*-----------------------------------------------------------------------* + * RequestsFileReader_getFilePath() + * + * + *-----------------------------------------------------------------------*/ + +const char *RequestsFileReader_getFilePath( + ReqFileReader *reqReader /* i/o: ReqFileReader handle */ +); + + +#endif /* IVAS_REQUESTS_FILE_READER_H */ -- GitLab