Commit 3cd7d7a2 authored by Ripinder Singh's avatar Ripinder Singh
Browse files

Use SR framesize signalling in RTP ToC for post-renderer initialization



* Add a preview of the RTP stream to extract the codec, and framesize
  fields as reported in the RTP SR ToC byte
* Override the user provided renderer framesize to codec framesize in
  rtp cases to prevent bitstream read errors due to unparsed padding in
  the end of ISAR bitstream.
* Code formatting changes
* Eof early exit without throwing error in rtp for post renderer
* Remove the external SR CodecFrameSize from RTP API SR CodecFrameSize
  read from RTP stream, hence no need to be set externally.

Signed-off-by: default avatarRipinder Singh <ripinder.singh@dolby.com>
parent 6abbfbf3
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2074,12 +2074,16 @@ static ivas_error initOnFirstGoodFrame(
            fParamsSR = fopen( srParamsFile, "w" );
            if ( NULL != fParamsSR )
            {
#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
                fprintf( fParamsSR, "DOF = %d;\nLC3PLUS_HIGHRES = %d;\n", poseCorrection, lc3plusHighRes );
#else
                fprintf( fParamsSR, "CODEC = %s;\nDOF = %d;\nFRAMESIZE = %d;\nRENDERSIZE = %d;\nLC3PLUS_HIGHRES = %d;\n",
                         splitRendCodec == ISAR_SPLIT_REND_CODEC_LC3PLUS ? "LC3PLUS" : "LCLD",
                         poseCorrection,
                         splitRendCodecFrameSizeMs,
                         splitRendIsarFrameSizeMs,
                         lc3plusHighRes );
#endif
                fclose( fParamsSR );
                fParamsSR = NULL;
            }
@@ -3278,8 +3282,10 @@ static ivas_error printBitstreamInfoVoip(
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
#ifdef IVAS_RTPDUMP
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
#ifdef RTP_S4_251135_CR26253_0016_REV1
            if ( ( error = IVAS_RTP_READER_Init( &ivasRtp, 0, arg.inputBitstreamFilename, arg.piOutputFilename, arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL, arg.outputWavFilename ) ) != IVAS_ERR_OK )
#endif
#else
            if ( ( error = IVAS_RTP_READER_Init( &ivasRtp, arg.inputBitstreamFilename, arg.piOutputFilename, arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL, arg.outputWavFilename ) ) != IVAS_ERR_OK )
#endif
@@ -3526,8 +3532,10 @@ static ivas_error decodeVoIP(
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
        case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
#ifdef IVAS_RTPDUMP
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
#ifdef RTP_S4_251135_CR26253_0016_REV1
            if ( ( error = IVAS_RTP_READER_Init( &ivasRtp, 0, arg.inputBitstreamFilename, arg.piOutputFilename, arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL, arg.outputWavFilename ) ) != IVAS_ERR_OK )
#endif
#else
            if ( ( error = IVAS_RTP_READER_Init( &ivasRtp, arg.inputBitstreamFilename, arg.piOutputFilename, arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL, arg.outputWavFilename ) ) != IVAS_ERR_OK )
#endif
+77 −0
Original line number Diff line number Diff line
@@ -749,6 +749,9 @@ static void trim( char *str )

static ivas_error parseSRParamsFile(
    const char *srParamsFilePath,
#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
    const char *rtpFilePath,
#endif
    ISAR_SPLIT_REND_CODEC *codec,
    ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection,
    int16_t *codec_frame_size_ms,
@@ -775,6 +778,24 @@ static ivas_error parseSRParamsFile(
            trim( key );
            trim( value );

#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
            if ( 0 == strncmp( key, "DOF", 3 ) )
            {
                int val = atoi( value );
                if ( val == 0 || val == 1 )
                {
                    *poseCorrection = ( val == 0 ) ? ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE : ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB;
                }
            }
            else if ( 0 == strncmp( key, "LC3PLUS_HIGHRES", 15 ) )
            {
                int val = atoi( value );
                if ( val == 0 || val == 1 )
                {
                    *lc3plusHighRes = (int16_t) val;
                }
            }
#else
            if ( 0 == strncmp( key, "CODEC", 5 ) )
            {
                *codec = ( 0 == strncmp( value, "LCLD", 4 ) ) ? ISAR_SPLIT_REND_CODEC_LCLD : *codec;
@@ -812,10 +833,52 @@ static ivas_error parseSRParamsFile(
                    *lc3plusHighRes = (int16_t) val;
                }
            }
#endif
        }
    }

    fclose( fParamSR );

#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
    {
        /* Peek the RTP stream to ascertain the codec and codec_frame_size */
        ivas_error error = IVAS_ERR_OK;
        IVAS_RTP srRtp = { 0 };
        if ( ( error = IVAS_RTP_READER_Init( &srRtp, rtpFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "error in IVAS_RTP_READER_Init() for sr RTP peek: %d\n", error );
            return error;
        }

        /* read a frame */
        while ( 1 )
        {
            bool qBit = false;
            IVAS_RTP_SR_INFO srInfo = { 0 };
            uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3];
            int16_t auSize = 0;
            uint16_t rtpSequenceNumber = 0;
            uint32_t rtpTimeStamp = 0, nextPacketRcvTime_ms = 0;

            error = IVAS_RTP_ReadNextFrame( &srRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &srInfo, &qBit );
            if ( error != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError in IVAS_RTP_ReadNextFrame, error code: %d\n", error );
                return error;
            }

            if ( srInfo.valid )
            {
                *codec = ( srInfo.codec == IVAS_SR_TRANSPORT_LCLD ) ? ISAR_SPLIT_REND_CODEC_LCLD : ISAR_SPLIT_REND_CODEC_LC3PLUS;
                *codec_frame_size_ms = (int16_t) srInfo.codecFrameSizeMs;
                *isar_frame_size_ms = *codec_frame_size_ms; /* for rtp force codec framesize as isar renderer frame size */
                break;
            }
        }
        IVAS_RTP_Term( &srRtp );
    }
#endif

    return IVAS_ERR_OK;
}
#endif
@@ -949,6 +1012,9 @@ int main(
    if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].srRtp ) )
    {
        error = parseSRParamsFile( args.srParamsFilePath,
#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
                                   args.inputFilePath,
#endif
                                   &bitsBuffer.config.codec,
                                   &bitsBuffer.config.poseCorrection,
                                   &bitsBuffer.config.codec_frame_size_ms,
@@ -960,12 +1026,20 @@ int main(
            goto cleanup;
        }

#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
        if ( ( error = IVAS_RTP_READER_Init( &srRTP, (uint32_t) bitsBuffer.config.codec_frame_size_ms, args.inputFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK )
#else
        if ( ( error = IVAS_RTP_READER_Init( &srRTP, args.inputFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK )
#endif
        {
            fprintf( stderr, "error in IVAS_RTP_READER_Init(): %d\n", error );
            goto cleanup;
        }
        audioReader = NULL;
#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
        /* Force owerwrite of command line provided rendersize to align with codec frame size */
        args.render_framesize = bitsBuffer.config.isar_frame_size_ms / 5;
#endif
    }
    /*if split renderer is running in post renderer mode*/
    else if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) )
@@ -1195,6 +1269,9 @@ int main(
                    if ( error == IVAS_ERR_END_OF_FILE )
                    {
                        numSamplesRead = 0;
#ifdef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
                        break;
#endif
                    }
                    else
                    {
+2 −0
Original line number Diff line number Diff line
@@ -423,9 +423,11 @@ typedef struct IVAS_RTP_UNPACK *IVAS_RTP_UNPACK_HANDLE; /* rtp unpacker handle t
typedef struct
{
    uint32_t maxFramesPerPacket; /* maximum no of frame per packet expected during the session */
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
#ifdef RTP_S4_251135_CR26253_0016_REV1
    uint32_t srCodecFrameSizeMs; /* split rendering transport codec frame size in ms (5/10/20) set by sdp negotiation */
#endif
#endif
} IVAS_RTP_UNPACK_CONFIG;

/* Open an instance of the RTP unpacker and return a handle to rtp unpacker on success
+4 −0
Original line number Diff line number Diff line
@@ -871,8 +871,10 @@ ivas_error IVAS_RTP_WRITER_Init(

ivas_error IVAS_RTP_READER_Init(
    IVAS_RTP *rtp, /* i/o : IVAS RTP File reader handle  */
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
#ifdef RTP_S4_251135_CR26253_0016_REV1
    uint32_t srCodecFrameSizeMs, /* i   : SR Codec Framesize in ms */
#endif
#endif
    const char *inputBitstreamFilename, /* i   : Input rtpdump filename       */
    const char *piOutputFilename,       /* i   : Output PI data json filename */
@@ -885,7 +887,9 @@ ivas_error IVAS_RTP_READER_Init(
    memset( rtp, 0, sizeof( IVAS_RTP ) );

    rtp->unpackCfg.maxFramesPerPacket = IVAS_MAX_FRAMES_PER_RTP_PACKET;
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
    rtp->unpackCfg.srCodecFrameSizeMs = srCodecFrameSizeMs;
#endif
    rtp->rtpPacket.buffer = rtp->packet;
    rtp->rtpPacket.capacity = sizeof( rtp->packet );

+2 −0
Original line number Diff line number Diff line
@@ -75,8 +75,10 @@ ivas_error IVAS_RTP_WRITER_Init( IVAS_RTP *rtp, const char *outputBitstreamFilen
#else
ivas_error IVAS_RTP_WRITER_Init( IVAS_RTP *rtp, const char *outputBitstreamFilename, uint32_t numFramesPerPacket );
#endif
#ifndef RTP_SR_CODEC_FRAME_SIZE_IN_TOC_BYTE
#ifdef RTP_S4_251135_CR26253_0016_REV1
ivas_error IVAS_RTP_READER_Init( IVAS_RTP *rtp, uint32_t srCodecFrameSizeMs, const char *inputBitstreamFilename, const char *piOutputFilename, bool isExtOutput, const char *outputWavFilename );
#endif
#else
ivas_error IVAS_RTP_READER_Init( IVAS_RTP *rtp, const char *inputBitstreamFilename, const char *piOutputFilename, bool isExtOutput, const char *outputWavFilename );
#endif
Loading