Commit cf08db10 authored by Ripinder Singh's avatar Ripinder Singh
Browse files

First draft of the RTP Pack API



 * Introduce RTP Packet and Payload API implementation
 * Introduce general handling of PI data and data type structures
 * Introduce the mutex encapsulation
 * Introduce a buffer pool manager
 * Example pack implementation in Encoder wrapper

Signed-off-by: default avatarSingh, Ripinder <ripinder.singh@dolby.com>
parent 1d0f51e9
Loading
Loading
Loading
Loading
+8 −71
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "bitstream_reader.h"
#include "evs_rtp_payload.h"
#include "ism_file_writer.h"
#undef IVAS_RTPDUMP
#ifdef IVAS_RTPDUMP
#include "ivas_rtp_payload.h"
#endif
@@ -1657,11 +1658,6 @@ static void usage_dec( void )
    fprintf( stdout, "                      EVS RTP Payload Format or rtpdump files containing TS26.253 Annex A\n" );
    fprintf( stdout, "                      IVAS RTP Payload Format. The SDP parameter hf_only is required.\n" );
    fprintf( stdout, "                      Reading RFC4867 AMR/AMR-WB RTP payload format is not supported.\n" );
#else
    fprintf( stdout, "-VOIP_hf_only=1     : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump\n" );
    fprintf( stdout, "                      The decoder may read rtpdump files containing TS26.445 Annex A.2.2\n" );
    fprintf( stdout, "                      EVS RTP Payload Format. The SDP parameter hf_only is required.\n" );
    fprintf( stdout, "                      Reading RFC4867 AMR/AMR-WB RTP payload format is not supported.\n" );
#endif
#ifdef SUPPORT_JBM_TRACEFILE
    fprintf( stdout, "-Tracefile TF       : VoIP mode: Generate trace file named TF\n" );
@@ -2885,9 +2881,6 @@ static ivas_error printBitstreamInfoVoip(
#ifdef IVAS_RTPDUMP
    IVAS_RTPDUMP_DEPACKER rtpdumpDepacker;
    IVAS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_NO_ERROR;
#else
    EVS_RTPDUMP_DEPACKER rtpdumpDepacker;
    EVS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_NO_ERROR;
#endif
    uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3];
    int16_t auSizeBits;
@@ -2897,10 +2890,6 @@ static ivas_error printBitstreamInfoVoip(
    uint16_t bitrateIndex;
    bool ivasIndicatorBit;
    bool isGoodFrame;
#else
    bool isAMRWB_IOmode;
    uint16_t frameTypeIndex;
    bool qBit;
#endif
    uint32_t nextPacketRcvTime_ms = 0;
    uint16_t rtpSequenceNumber;
@@ -2921,8 +2910,6 @@ static ivas_error printBitstreamInfoVoip(

#ifdef IVAS_RTPDUMP
            rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_open( &rtpdumpDepacker, f_rtpstream );
#else
            rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_open( &rtpdumpDepacker, f_rtpstream, arg.inputFormat == IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF );
#endif
            if ( rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
            {
@@ -2946,8 +2933,6 @@ static ivas_error printBitstreamInfoVoip(
            error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSizeBits, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms );
#ifdef IVAS_RTPDUMP
            isGoodFrame = 1; /* good frame for INPUT_FORMAT_G192 */
#else
            qBit = 1; /* good q_bit for INPUT_FORMAT_G192 */
#endif
        }
        else
@@ -2955,8 +2940,6 @@ static ivas_error printBitstreamInfoVoip(
            auPtr = au; /* might have been set to RTP packet in prev call */
#ifdef IVAS_RTPDUMP
            rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, &evsIvasModeBit, &bitrateIndex, &ivasIndicatorBit, &isGoodFrame, &auPtr, (uint16_t *) &auSizeBits );
#else
            rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, &isAMRWB_IOmode, &frameTypeIndex, &qBit, &auPtr, (uint16_t *) &auSizeBits );
#endif

            /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */
@@ -2969,8 +2952,6 @@ static ivas_error printBitstreamInfoVoip(
        }
#ifdef IVAS_RTPDUMP
    } while ( !isGoodFrame || auSizeBits < MIN_NUM_BITS_ACTIVE_FRAME || auSizeBits == NUM_BITS_SID_IVAS_5K2 );
#else
    } while ( !qBit || auSizeBits < MIN_NUM_BITS_ACTIVE_FRAME || auSizeBits == NUM_BITS_SID_IVAS_5K2 );
#endif

    BS_Reader_Rewind( hBsReader );
@@ -2987,8 +2968,6 @@ cleanup:

#ifdef IVAS_RTPDUMP
    IVAS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker );
#else
    EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker );
#endif

    if ( previewFailed && error == IVAS_ERR_OK )
@@ -3037,7 +3016,7 @@ static ivas_error decodeVoIP(
    uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3];
    int16_t auSize;
    uint16_t rtpSequenceNumber;
    uint32_t rtpTimeStamp;
    uint32_t rtpTimeStamp = 0;

    bool decodedGoodFrame = false;
    int16_t numInitialBadFrames = 0; /* Number of bad frames received until first good frame is decoded */
@@ -3055,24 +3034,15 @@ static ivas_error decodeVoIP(
    int16_t delayNumSamples = -1;
    int32_t delayTimeScale = -1;
    int16_t i;
    FILE *f_rtpstream = NULL;
#ifdef IVAS_RTPDUMP
    FILE *f_rtpstream = NULL;
    IVAS_RTPDUMP_DEPACKER rtpdumpDepacker;
    IVAS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_NO_ERROR;
#else
    EVS_RTPDUMP_DEPACKER rtpdumpDepacker;
    EVS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_NO_ERROR;
#endif
    uint8_t *auPtr = NULL;
#ifdef IVAS_RTPDUMP
    bool evsIvasModeBit;
    uint16_t bitrateIndex;
    bool ivasIndicatorBit;
    bool isGoodFrame;
#else
    bool isAMRWB_IOmode;
    uint16_t frameTypeIndex;
    bool qBit;
#endif

    IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN;
@@ -3110,41 +3080,31 @@ static ivas_error decodeVoIP(

    delayNumSamples_orig[0] = -1;

#ifdef IVAS_RTPDUMP
    rtpdumpDepacker.rtpdump = NULL;
#endif
    switch ( arg.inputFormat )
    {
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
#ifdef IVAS_RTPDUMP
            f_rtpstream = fopen( arg.inputBitstreamFilename, "rb" );
#else
            f_rtpstream = fopen( arg.inputBitstreamFilename, "r" );
#endif

            if ( f_rtpstream == NULL )
            {
                fprintf( stderr, "could not open: %s\n", arg.inputBitstreamFilename );
                goto cleanup;
            }

#ifdef IVAS_RTPDUMP
            rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_open( &rtpdumpDepacker, f_rtpstream );
            if ( rtpdumpDepackerError != IVAS_RTPDUMP_DEPACKER_NO_ERROR )
            {
                fprintf( stderr, "error in IVAS_RTPDUMP_DEPACKER_open(): %d\n", rtpdumpDepackerError );
                goto cleanup;
            }
#else
            rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_open( &rtpdumpDepacker, f_rtpstream, arg.inputFormat == IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF );
            if ( rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
            {
                fprintf( stderr, "error in EVS_RTPDUMP_DEPACKER_open(): %d\n", rtpdumpDepackerError );
                goto cleanup;
            }
#endif
            break;
        case IVAS_DEC_INPUT_FORMAT_G192:
            auPtr = au;
            //auPtr = au;
            break;
        default:
            fprintf( stderr, "Unsupported format of input bitstream" );
@@ -3180,17 +3140,13 @@ static ivas_error decodeVoIP(
        error = BS_Reader_ReadVoipFrame_compact( hBsReader, au, &auSize, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms );
#ifdef IVAS_RTPDUMP
        isGoodFrame = 1; /* good frame for INPUT_FORMAT_G192 */
#else
        qBit = 1; /* good q_bit for INPUT_FORMAT_G192 */
#endif
    }
    else
    {
        auPtr = au; /* might have been set to RTP packet in prev call */
#ifdef IVAS_RTPDUMP
        auPtr = au; /* might have been set to RTP packet in prev call */
        rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, &evsIvasModeBit, &bitrateIndex, &ivasIndicatorBit, &isGoodFrame, &auPtr, (uint16_t *) &auSize );
#else
        rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, &isAMRWB_IOmode, &frameTypeIndex, &qBit, &auPtr, (uint16_t *) &auSize );
#endif

        /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */
@@ -3198,8 +3154,6 @@ static ivas_error decodeVoIP(
    }
#ifdef IVAS_RTPDUMP
    if ( error != IVAS_ERR_OK || rtpdumpDepackerError != IVAS_RTPDUMP_DEPACKER_NO_ERROR )
#else
    if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
#endif
    {
        fprintf( stderr, "failed to read first RTP packet\n" );
@@ -3354,8 +3308,6 @@ static ivas_error decodeVoIP(
            /* feed the previous read packet into the receiver now */
#ifdef IVAS_RTPDUMP
            error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, isGoodFrame );
#else
            error = IVAS_DEC_VoIP_FeedFrame( hIvasDec, auPtr, auSize, rtpSequenceNumber, rtpTimeStamp, nextPacketRcvTime_ms, qBit );
#endif
            if ( error != IVAS_ERR_OK )
            {
@@ -3371,14 +3323,12 @@ static ivas_error decodeVoIP(

#ifdef IVAS_RTPDUMP
                isGoodFrame = 1; /* good frame for VOIP_G192_RTP */
#else
                qBit = 1; /* good q_bit for VOIP_G192_RTP */
#endif
            }
            else
            {
                auPtr = au; /* might have been set to RTP packet in prev call */
#ifdef IVAS_RTPDUMP
                auPtr = au; /* might have been set to RTP packet in prev call */
                rtpdumpDepackerError = IVAS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp,
                                                                            &nextPacketRcvTime_ms,
                                                                            &evsIvasModeBit, &bitrateIndex, &ivasIndicatorBit,
@@ -3393,19 +3343,10 @@ static ivas_error decodeVoIP(
                    fprintf( stderr, "\nError in IVAS_DEC_feedPIdata: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
#else
                rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp,
                                                                           &nextPacketRcvTime_ms,
                                                                           &isAMRWB_IOmode, &frameTypeIndex, &qBit,
                                                                           &auPtr, (uint16_t *) &auSize );
                /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */
                rtpTimeStamp = rtpTimeStamp / 16;
#endif
            }
#ifdef IVAS_RTPDUMP
            if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == IVAS_RTPDUMP_DEPACKER_EOF )
#else
            if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == EVS_RTPDUMP_DEPACKER_EOF )
#endif
            {
                /* finished reading */
@@ -3413,8 +3354,6 @@ static ivas_error decodeVoIP(
            }
#ifdef IVAS_RTPDUMP
            else if ( error != IVAS_ERR_OK )
#else
            else if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR )
#endif
            {
                fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error );
@@ -3771,8 +3710,6 @@ cleanup:

#ifdef IVAS_RTPDUMP
    IVAS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker );
#else
    EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker );
#endif
    AudioFileWriter_close( &afWriter );
    JbmOffsetFileWriter_close( &jbmOffsetWriter );
+112 −22
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@
#include "jbm_file_reader.h"
#include "masa_file_reader.h"
#ifdef IVAS_RTPDUMP
#include "evs_rtp_payload.h"
#include "ivas_rtp_payload.h"
#include "ivas_rtp_api.h"
#include "ivas_rtp_pi_data.h"
#include "rotation_file_reader.h"
#endif
#ifdef DEBUGGING
@@ -222,8 +222,8 @@ int main(

#ifdef IVAS_RTPDUMP
    FILE *f_rtpstream = NULL;
    IVAS_RTPDUMP_PACKER *rtpdumpPacker = NULL;
    IVAS_RTPDUMP_PACKER_ERROR rtpdumpPackerError = IVAS_RTPDUMP_PACKER_NO_ERROR;
    IVAS_RTP_PACK_HANDLE hPack = NULL;
    RTP_HEADER rtpHeader;
#endif

    /*------------------------------------------------------------------------------------------*
@@ -623,6 +623,14 @@ int main(

    if ( arg.rtpdumpOutput )
    {
        IVAS_RTP_PACK_CONFIG packCfg = {
            .maxFramesPerPacket = 4
        };

        uint32_t SSRC = (rand() & 0xFFFF) | ((uint32_t) rand() << 16);

        IVAS_RTP_InitRtpHeader(&rtpHeader, SSRC);

        /* Open the output file for RTPDump writing */
        f_rtpstream = fopen( arg.outputBitstreamFilename, "wb" );

@@ -632,10 +640,10 @@ int main(
            goto cleanup;
        }

        rtpdumpPackerError = IVAS_RTPDUMP_PACKER_open( &rtpdumpPacker, f_rtpstream );
        if ( rtpdumpPackerError != IVAS_RTPDUMP_PACKER_NO_ERROR )
        error = IVAS_RTP_PACK_Open( &hPack, &packCfg );
        if ( error != IVAS_ERR_OK )
        {
            fprintf( stderr, "error in IVAS_RTPDUMP_PACKER_open(): %d\n", rtpdumpPackerError );
            fprintf( stderr, "error in IVAS_RTP_PACK_Open(): %d\n", error );
            goto cleanup;
        }
    }
@@ -669,6 +677,7 @@ int main(

    int16_t numSamplesRead = 0;
    uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME];

    uint16_t numBits = 0;
#ifdef DEBUG_SBA
#ifdef DEBUG_AGC
@@ -838,43 +847,119 @@ int main(
        }

#ifdef IVAS_RTPDUMP
        if ( rtpdumpPacker && rtpdumpPacker->rtpdump )
        if ( hPack )
        {
            uint8_t au[(IVAS_MAX_BITS_PER_FRAME + 7) / 8];
            uint8_t packet[6144];
            uint32_t n = numBits/8, x = 0, numFramesInPayload = 0;;
            uint16_t *bitstrm = bitStream;

            IVAS_DATA_BUFFER frame = {
                .capacity = sizeof(au),
                .buffer = au,
                .length = 0
            };

            IVAS_DATA_BUFFER rtpPacket = {
                .capacity = sizeof(packet),
                .buffer = packet,
                .length = 0
            };

            /* Pack Encoded Stream */
            while (n)
            {
                x = ((bitstrm[0] << 7) | (bitstrm[1] << 6) | (bitstrm[2] << 5) | (bitstrm[3] << 4) |
                     (bitstrm[4] << 3) | (bitstrm[5] << 2) | (bitstrm[6] << 1) | (bitstrm[7] << 0));
                frame.buffer[frame.length++] = (uint8_t) x;
                bitstrm += 8;
                n--;
            }

            /* AMWWB-IO has non octet sized bitstream */
            if (numBits & 0x7)
            {
                x = 0;
                for (n = 0; n < (numBits & 0x7); n++)
                {
                    x |= (uint8_t) (bitstrm[n] << (7 - n));
                }
                frame.buffer[frame.length++] = (uint8_t) x;
            }

            /* Push Encoded Stream to */
            if ( ( error = IVAS_RTP_PACK_PushFrame(hPack,
                IVAS_isImmersiveFormat( hIvasEnc ) ? IVAS_RTP_IVAS : IVAS_RTP_EVS,
#ifdef RTP_S4_251135_CR26253_0016_REV1
                NULL,
#endif /* RTP_S4_251135_CR26253_0016_REV1 */
                &frame
            ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError %s while pushing audio frame to RTP pack\n", IVAS_ENC_GetErrorMessage( error ));
                goto cleanup;
            }

            /* scene orientation */
            if ( sceneOrientationFileReader )
            {
                if ( ( error = HeadRotationFileReading( sceneOrientationFileReader, &rtpdumpPacker->piDataPacker.sceneOrientationQuat, NULL ) ) != IVAS_ERR_OK )
                IVAS_PIDATA_ORIENTATION sceneOrientation = {
                    .size = sizeof(IVAS_PIDATA_ORIENTATION),
                    .piDataType = IVAS_PI_SCENE_ORIENTATION,
                    .orientation = {0.0f, 0.0f, 0.0f, 0.0f}
                };

                if ( ( error = HeadRotationFileReading( sceneOrientationFileReader, &sceneOrientation.orientation, NULL ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while reading scene orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( sceneOrientationFileReader ) );
                    goto cleanup;
                }
                rtpdumpPacker->piDataPacker.sceneOrientationPresent = true;

                if ( ( error = IVAS_RTP_PACK_PushPiData (hPack, (const IVAS_PIDATA_GENERIC *) &sceneOrientation) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while pushing scene orientation\n", IVAS_ENC_GetErrorMessage( error ));
                    goto cleanup;
                }
            }

            /* device orientation */
            if ( deviceOrientationFileReader )
            {
                if ( ( error = HeadRotationFileReading( deviceOrientationFileReader, &rtpdumpPacker->piDataPacker.deviceOrientationQuat, NULL ) ) != IVAS_ERR_OK )
                IVAS_PIDATA_ORIENTATION deviceOrientation = {
                    .size = sizeof(IVAS_PIDATA_ORIENTATION),
                    .piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED,
                    .orientation = {0.0f, 0.0f, 0.0f, 0.0f}
                };

                if ( ( error = HeadRotationFileReading( deviceOrientationFileReader, &deviceOrientation.orientation, NULL ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while reading device orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( deviceOrientationFileReader ) );
                    goto cleanup;
                }
                rtpdumpPacker->piDataPacker.deviceOrientationPresent = true;

                if ( ( error = IVAS_RTP_PACK_PushPiData (hPack, (const IVAS_PIDATA_GENERIC *) &deviceOrientation) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while pushing scene orientation\n", IVAS_ENC_GetErrorMessage( error ));
                    goto cleanup;
                }
            }

            /* PI presence */
            IVAS_RTPDUMP_PACKER_determinePIpresence( rtpdumpPacker );
            /* Generate RTP Packet Header */
            if ( ( error = IVAS_RTP_PackRtpHeader(&rtpHeader, &rtpPacket) ) != IVAS_ERR_OK ) {
                fprintf( stderr, "\nError %s while packing RTP Header\n", IVAS_ENC_GetErrorMessage( error ));
                goto cleanup;
            }

            /* write rtpdump */
            rtpdumpPackerError = IVAS_RTPDUMP_PACKER_writeNextFrame( rtpdumpPacker, bitStream, numBits,
                                                                     IVAS_isImmersiveFormat( hIvasEnc ), 0, false, NO_BANDWIDTH_REQUEST, NO_FORMAT_REQUEST );
            if ( rtpdumpPackerError != IVAS_RTPDUMP_PACKER_NO_ERROR )
            /* Generate RTP Packet Payload */
            if ( ( error = IVAS_RTP_PACK_GetPayload(hPack, &rtpPacket, &numFramesInPayload) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "IVAS_RTPDUMP_PACKER_writeNextFrame() failed, error code: %d\n", rtpdumpPackerError );
                fprintf( stderr, "\nError %s while packing RTP Payload\n", IVAS_ENC_GetErrorMessage( error ));
                goto cleanup;
            }

            IVAS_RTPDUMP_PACKER_resetPIdata( rtpdumpPacker );
            IVAS_RTP_UpdateRtpHeader(&rtpHeader, numFramesInPayload * 320); /* 20ms x 16KHz x nFrames */

            fwrite(rtpPacket.buffer, sizeof(uint8_t), rtpPacket.length, f_rtpstream);
        }
        else
        {
@@ -966,9 +1051,9 @@ cleanup:
    }

#ifdef IVAS_RTPDUMP
    if ( rtpdumpPacker )
    if ( hPack )
    {
        IVAS_RTPDUMP_PACKER_close( &rtpdumpPacker );
        IVAS_RTP_PACK_Close(&hPack);
    }

    if ( sceneOrientationFileReader )
@@ -980,6 +1065,11 @@ cleanup:
    {
        RotationFileReader_close( &deviceOrientationFileReader );
    }

    if (f_rtpstream)
    {
        fclose(f_rtpstream);
    }
#endif

    IVAS_ENC_Close( &hIvasEnc );
+9 −0
Original line number Diff line number Diff line
@@ -150,6 +150,15 @@ typedef enum
    IVAS_ERR_LC3PLUS_INVALID_BITRATE,
    IVAS_ERR_INVALID_SPLIT_REND_CONFIG,

    /*----------------------------------------*
     *               rtp errors               *
     *----------------------------------------*/
    IVAS_ERR_UNDERFLOW = 0x7000,
    IVAS_ERR_PI_DATA_WITH_NO_INPUT_FRAME,
    IVAS_ERR_INSUFFICIENT_INPUT,
    IVAS_ERR_INSUFFICIENT_OUTPUT_SIZE,
    IVAS_ERR_UNPACK_PI_DATA,

    /*----------------------------------------*
     *              unknown error             *
     *----------------------------------------*/

lib_util/ivas_bpool.c

0 → 100644
+154 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2024 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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "ivas_bpool.h"
#include "ivas_error_utils.h"
#include "mutex.h"

struct BPOOL
{
    mtx_t lock;
    uint32_t bufferSize;
    uint32_t numBuffers;
    uint32_t numFreeBuffers;
    void **freeBuffers;
};

ivas_error BPOOL_Create( BPOOL_HANDLE *pHandle, size_t bufferSize, uint32_t numBuffers )
{
    uint32_t n;
    uint8_t *base = NULL;
    BPOOL_HANDLE handle;
    size_t allocSize = sizeof( struct BPOOL );

    if ( pHandle == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer to Buffer Pool Handle" );
    }

    *pHandle = NULL;

    allocSize += bufferSize * numBuffers;       /* pool memory */
    allocSize += sizeof( void * ) * numBuffers; /* free buffers stack */

    base = calloc( allocSize, sizeof( uint8_t ) );
    if ( base == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Couldn't allocate Buffer pool" );
    }

    handle = (BPOOL_HANDLE) base;
    base += sizeof( struct BPOOL );

    mtx_init( &handle->lock, 0 );
    handle->bufferSize = bufferSize;
    handle->numBuffers = numBuffers;
    handle->numFreeBuffers = numBuffers;
    handle->freeBuffers = (void **) base;
    base += ( sizeof( void * ) * numBuffers );
    for ( n = 0; n < numBuffers; n++ )
    {
        handle->freeBuffers[n] = base;
        base += bufferSize;
    }

    *pHandle = handle;
    return IVAS_ERR_OK;
}

void BPOOL_Destroy( BPOOL_HANDLE *pHandle )
{
    if ( pHandle != NULL )
    {
        mtx_destroy( &( *pHandle )->lock );
        free( *pHandle );
        *pHandle = NULL;
    }
}

ivas_error BPOOL_GetBuffer( BPOOL_HANDLE handle, void **dataPtr )
{
    uint32_t idx = 0;
    bool isFree = false;

    if ( handle == NULL || dataPtr == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer args in GetBuffer" );
    }

    mtx_lock( &handle->lock );
    isFree = ( handle->numFreeBuffers > 0 );
    if ( isFree )
    {
        idx = --handle->numFreeBuffers;
    }
    mtx_unlock( &handle->lock );

    if ( !isFree )
    {
        return IVAS_ERROR( IVAS_ERR_UNDERFLOW, "Underflow, no free buffers in pool" );
    }

    *dataPtr = handle->freeBuffers[idx];
    return IVAS_ERR_OK;
}

/* return the buffer back to pool  */
ivas_error BPOOL_FreeBuffer( BPOOL_HANDLE handle, void *dataPtr )
{
    uint32_t idx;

    if ( handle == NULL || dataPtr == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer args in GetBuffer" );
    }

    mtx_lock( &handle->lock );
    idx = handle->numFreeBuffers++;
    mtx_unlock( &handle->lock );

    handle->freeBuffers[idx] = dataPtr;

    return IVAS_ERR_OK;
}

/* return the number of free buffers available atm in the pool */
uint32_t BPOOL_AvailableBuffers( BPOOL_HANDLE handle )
{
    uint32_t idx;
    mtx_lock( &handle->lock );
    idx = handle->numFreeBuffers;
    mtx_unlock( &handle->lock );
    return idx;
}

lib_util/ivas_bpool.h

0 → 100644
+58 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading