Commit 21e1a6bd authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

Merge branch '1527_fix_bitrate_idx_in_CMR_tests_Basop' into 'main'

1527: Tests for incorrect bitrate idx in CMR Fix

See merge request !2908
parents c7039f3b 0b3a5d78
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@
    <ClCompile Include="..\lib_util\obj_edit_file_reader.c" />
    <ClCompile Include="..\lib_util\render_config_reader.c" />
    <ClCompile Include="..\lib_util\rotation_file_reader.c" />
    <ClCompile Include="..\lib_util\requests_file_reader.c" />
    <ClCompile Include="..\lib_util\rtpdump.c" />
    <ClCompile Include="..\lib_util\split_render_file_read_write.c" />
    <ClCompile Include="..\lib_util\split_rend_bfi_file_reader.c" />
@@ -164,6 +165,7 @@
    <ClInclude Include="..\lib_util\masa_file_writer.h" />
    <ClInclude Include="..\lib_util\render_config_reader.h" />
    <ClInclude Include="..\lib_util\rotation_file_reader.h" />
    <ClInclude Include="..\lib_util\requests_file_reader.h" />
    <ClInclude Include="..\lib_util\rtpdump.h" />
    <ClInclude Include="..\lib_util\tinywavein_c.h" />
    <ClInclude Include="..\lib_util\tinywaveout_c.h" />
+62 −0
Original line number Diff line number Diff line
@@ -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 */
@@ -658,6 +667,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
     *------------------------------------------------------------------------------------------*/
@@ -867,6 +890,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 ) );
@@ -962,6 +996,13 @@ cleanup:
        fclose( f_bitrateProfile );
    }

#ifdef FIX_1527_CMR_BITRATE_IDX
    if ( requestsFileReader )
    {
        RequestsFileReader_close( &requestsFileReader );
    }
#endif

    if ( sceneOrientationFileReader )
    {
        RotationFileReader_close( &sceneOrientationFileReader );
@@ -1008,6 +1049,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;
@@ -1874,6 +1918,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
@@ -2093,6 +2151,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;
+14 −0
Original line number Diff line number Diff line
@@ -1016,6 +1016,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;
+3 −0
Original line number Diff line number Diff line
@@ -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;
+167 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (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 <stdlib.h>
#include <string.h>
#include <stdbool.h>


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;
}
Loading