Commit 26f87f05 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

move split post rend codec init to init time

parent c3148745
Loading
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ typedef struct
static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg );
static void usage_dec( void );
#ifdef SPLIT_REND_WITH_HEAD_ROT
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, uint8_t *splitRendBitsBuf, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#else
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#endif
@@ -181,9 +181,14 @@ int main(
    DecArguments arg;
    ivas_error error = IVAS_ERR_UNKNOWN;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_SPLIT_REND_BITS_DATA splitRendBits;
    uint8_t splitRendBitsBuf[IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES];
#endif

#ifdef SPLIT_REND_WITH_HEAD_ROT
    splitRendBits.bits_buf = splitRendBitsBuf;
#endif

    /* Any handles that require cleanup must be declared here and initialized to NULL */
    IVAS_DEC_HANDLE hIvasDec = NULL;
    BS_READER_HANDLE hBsReader = NULL;
@@ -864,7 +869,7 @@ int main(
    else
    {
#ifdef SPLIT_REND_WITH_HEAD_ROT
        error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, splitRendBitsBuf, hIvasDec, pcmBuf );
        error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf );
#else
        error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf );
#endif
@@ -1855,6 +1860,9 @@ static ivas_error initOnFirstGoodFrame(
        /* Open split rendering metadata writer */
        int16_t delayNumSamples_temp[3];
        int32_t delayTimeScale_temp;
        IVAS_SPLIT_REND_CODEC splitRendCodec;
        int16_t splitRendCodecFrameSizeMs;
        IVAS_SPLIT_REND_POSE_CORRECTION_MODE poseCorrection;

        if ( ( error = IVAS_DEC_GetDelay( hIvasDec, delayNumSamples_temp, &delayTimeScale_temp ) ) != IVAS_ERR_OK )
        {
@@ -1862,9 +1870,11 @@ static ivas_error initOnFirstGoodFrame(
            return error;
        }

        IVAS_DEC_GetSplitRendBitstreamHeader( hIvasDec, &splitRendCodec, &poseCorrection, &splitRendCodecFrameSizeMs );

        if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
        {
            if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK )
            if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename );
                return error;
@@ -1872,7 +1882,7 @@ static ivas_error initOnFirstGoodFrame(
        }
        else
        {
            if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK )
            if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename );
                return error;
@@ -1910,7 +1920,7 @@ static ivas_error initOnFirstGoodFrame(
            splitRendBitsZero.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
            splitRendBitsZero.codec_frame_size_ms = 20;

            if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written, -1, IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE, splitRendBitsZero.codec_frame_size_ms ) != IVAS_ERR_OK )
            if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nUnable to write to bitstream file!\n" );
                return error;
@@ -2078,7 +2088,7 @@ static ivas_error decodeG192(
    RotFileReader *refRotReader,
    Vector3PairFileReader *referenceVectorReader,
#ifdef SPLIT_REND_WITH_HEAD_ROT
    uint8_t *splitRendBitsBuf,
    IVAS_SPLIT_REND_BITS_DATA *splitRendBits,
#endif
    IVAS_DEC_HANDLE hIvasDec,
    int16_t *pcmBuf )
@@ -2384,7 +2394,7 @@ static ivas_error decodeG192(
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
            {
                if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBitsBuf, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBits, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
@@ -2467,15 +2477,7 @@ static ivas_error decodeG192(
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
            {
                IVAS_SPLIT_REND_BITS_DATA splitRendBits;

                if ( ( error = IVAS_DEC_GetSplitRendBits( hIvasDec, &splitRendBits ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_SplitRendBits: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }

                if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, splitRendBits.codec, splitRendBits.pose_correction, splitRendBits.codec_frame_size_ms ) != IVAS_ERR_OK )
                if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nUnable to write to bitstream file!\n" );
                    goto cleanup;
+34 −15
Original line number Diff line number Diff line
@@ -589,7 +589,9 @@ static void setupWithSingleFormatInput(
    IsmPositionProvider *positionProvider,
#ifdef SPLIT_REND_WITH_HEAD_ROT
    MasaFileReader **masaReaders,
    SplitFileReadWrite **hhSplitRendFileReadWrite
    SplitFileReadWrite **hhSplitRendFileReadWrite,
    IVAS_REND_BitstreamBuffer *hBitsBuffer

#else
    MasaFileReader **masaReaders
#endif
@@ -647,7 +649,7 @@ static void setupWithSingleFormatInput(
        if ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
        {
            ivas_error error;
            error = split_rend_reader_open( hhSplitRendFileReadWrite, args.inMetadataFilePaths[0] );
            error = split_rend_reader_open( hhSplitRendFileReadWrite, args.inMetadataFilePaths[0], &hBitsBuffer->config.codec, &hBitsBuffer->config.poseCorrection, &hBitsBuffer->config.codec_frame_size_ms );
            if ( error != IVAS_ERR_OK )
            {
                fprintf( stderr, "Could not open split rend metadata file %s\n", args.inMetadataFilePaths[0] );
@@ -802,6 +804,13 @@ int main(
    hSplitRendFileReadWrite = NULL;
    CLDFBframeSize_smpls = 0;
    cldfb_in_flag = 0;
    bitsBuffer.bits = NULL;
    bitsBuffer.config.bitsRead = 0;
    bitsBuffer.config.bitsWritten = 0;
    bitsBuffer.config.bufLenInBytes = 0;
    bitsBuffer.config.codec = IVAS_SPLIT_REND_CODEC_DEFAULT;
    bitsBuffer.config.poseCorrection = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
    bitsBuffer.config.codec_frame_size_ms = 20;
#endif
    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
@@ -895,7 +904,7 @@ int main(
    {
        /* With single-format input, all information is given on command line. */
#ifdef SPLIT_REND_WITH_HEAD_ROT
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders, &hSplitRendFileReadWrite );
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders, &hSplitRendFileReadWrite, &bitsBuffer );
#else
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders );
#endif
@@ -923,7 +932,8 @@ int main(
    /*if split renderer is running in post renderer mode*/
    if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) )
    {
        error = split_rend_reader_open( &hSplitRendFileReadWrite, args.inputFilePath );
        error = split_rend_reader_open( &hSplitRendFileReadWrite, args.inputFilePath, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection,
                                        &bitsBuffer.config.codec_frame_size_ms );
        if ( error != IVAS_ERR_OK )
        {
            fprintf( stderr, "Could not open split rend metadata file %s\n", args.inputFilePath );
@@ -1195,6 +1205,14 @@ int main(
#endif
    }

#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( args.inConfig.numBinBuses > 0 )
    {
        IVAS_REND_SetSplitRendBitstreamHeader( hIvasRend, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection,
                                               bitsBuffer.config.codec_frame_size_ms );
    }
#endif

    if ( ( error = IVAS_REND_SetOrientationTrackingMode( hIvasRend, args.orientation_tracking ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "Error in IVAS_REND_SetOrientationTrackingMode(): %s\n", ivas_error_to_string( error ) );
@@ -1468,13 +1486,16 @@ int main(

    if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
    {

        IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms );

        if ( IVAS_REND_GetDelay( hIvasRend, &delayNumSamples_temp, &delayTimeScale_temp ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nUnable to get delay of renderer!\n" );
            exit( -1 );
        }

        if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outputFilePath, delayNumSamples_temp, delayTimeScale_temp ) ) != IVAS_ERR_OK )
        if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outputFilePath, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Could not open split rend metadata file %s\n", args.outputFilePath );
            exit( -1 );
@@ -1485,13 +1506,16 @@ int main(
    {
        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
        {

            IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms );

            if ( IVAS_REND_GetDelay( hIvasRend, &delayNumSamples_temp, &delayTimeScale_temp ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nUnable to get delay of renderer!\n" );
                exit( -1 );
            }

            if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outMetadataFilePath, delayNumSamples_temp, delayTimeScale_temp ) ) != IVAS_ERR_OK )
            if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outMetadataFilePath, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Could not open split rend metadata file %s\n", args.outMetadataFilePath );
                exit( -1 );
@@ -1561,9 +1585,6 @@ int main(
    bitsBuffer.config.bitsRead = 0;
    bitsBuffer.config.bitsWritten = 0;
    bitsBuffer.config.bufLenInBytes = bitsBufferSize;
    bitsBuffer.config.codec = IVAS_SPLIT_REND_CODEC_DEFAULT;
    bitsBuffer.config.poseCorrection = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
    bitsBuffer.config.codec_frame_size_ms = 20;
#else
    inFloatBuffer = malloc( inBufferSize * sizeof( float ) );
    outInt16Buffer = malloc( outBufferSize * sizeof( int16_t ) );
@@ -1607,9 +1628,8 @@ int main(
        {
            ivas_error error_tmp;
            numSamplesRead = (int16_t) inBufferSize;
            error_tmp = split_rend_read_bits_from_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead, &bitsBuffer.config.bitsWritten,
                                                        &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection,
                                                        &bitsBuffer.config.codec_frame_size_ms );
            error_tmp = split_rend_read_bits_from_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead,
                                                        &bitsBuffer.config.bitsWritten );
            if ( error_tmp != IVAS_ERR_OK )
            {
                if ( error_tmp == IVAS_ERR_END_OF_FILE )
@@ -2010,9 +2030,8 @@ int main(
#ifdef SPLIT_REND_WITH_HEAD_ROT
        if ( is_split_pre_rend_mode( &args ) )
        {
            if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead, &bitsBuffer.config.bitsWritten,
                                                     bitsBuffer.config.codec, bitsBuffer.config.poseCorrection,
                                                     bitsBuffer.config.codec_frame_size_ms ) != IVAS_ERR_OK )
            if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead,
                                                     &bitsBuffer.config.bitsWritten ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nUnable to write to bitstream file!\n" );
                exit( -1 );
+0 −1
Original line number Diff line number Diff line
@@ -2550,7 +2550,6 @@ void ivas_initialize_handles_dec(

#ifdef SPLIT_REND_WITH_HEAD_ROT
    st_ivas->hSplitBinRend.hMultiBinCldfbData = NULL;
    st_ivas->hSplitBinRend.hSplitRendBits = NULL;
    st_ivas->hSplitBinRend.hCldfbDataOut = NULL;
#ifndef SPLIT_REND_LCLD_5MS
    st_ivas->hSplitBinRend.tdDataOut = NULL;
+0 −1
Original line number Diff line number Diff line
@@ -995,7 +995,6 @@ typedef struct
typedef struct
{
    IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE hMultiBinCldfbData; /*scratch buffer for frame by frame processing*/
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits;                         /*scratch buffer for frame by frame processing*/
    SPLIT_REND_WRAPPER splitrend;
    IVAS_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE hCldfbDataOut; /*buffer to store cldfb data before binauralization*/
#ifndef SPLIT_REND_LCLD_5MS
+17 −30
Original line number Diff line number Diff line
@@ -1029,7 +1029,7 @@ ivas_error IVAS_DEC_GetSamples(
ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    IVAS_DEC_HANDLE hIvasDec,                 /* i/o: IVAS decoder handle                                                     */
    void *pcmBuf_out,                         /* o  : output synthesis signal for BINAURAL_SPLIT_PCM                          */
    uint8_t *splitRendBitsBuf, /* o  : output split rendering bits                             */
    IVAS_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                                             */
    int16_t *nOutSamples,                     /* o  : number of samples per channel written to output buffer                  */
    bool *needNewFrame                        /* o  : indication that the decoder needs a new frame                           */
)
@@ -1073,7 +1073,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    *needNewFrame = false;
    hSplitBinRend = &st_ivas->hSplitBinRend;

    if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBitsBuf ) ) != IVAS_ERR_OK )
    if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK )
    {
        return error;
    }
@@ -1230,7 +1230,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
                                                       st_ivas->hRenderConfig->split_rend_config.splitRendBitRate,
                                                       st_ivas->hRenderConfig->split_rend_config.codec,
                                                       st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms,
                                                       hSplitBinRend->hSplitRendBits,
                                                       splitRendBits,
#ifdef SPLIT_REND_LCLD_5MS
                                                       Cldfb_RealBuffer_Binaural,
                                                       Cldfb_ImagBuffer_Binaural,
@@ -3735,37 +3735,24 @@ static ivas_error IVAS_DEC_VoIP_reconfigure(

#ifdef SPLIT_REND_WITH_HEAD_ROT
/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSplitRendBits()
 * IVAS_DEC_GetSplitRendBitstreamHeader()
 *
 *
 *---------------------------------------------------------------------*/

/*! r: decoder error code */
ivas_error IVAS_DEC_GetSplitRendBits(
ivas_error IVAS_DEC_GetSplitRendBitstreamHeader(
    IVAS_DEC_HANDLE hIvasDec,                             /* i/o: IVAS decoder handle                                                     */
    IVAS_SPLIT_REND_BITS_HANDLE splitRendBits /* o  : split rendering Bits structue    */
)
    IVAS_SPLIT_REND_CODEC *pCodec,                        /* o: pointer to codec setting                */
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o: pointer to pose correction mode                */
    int16_t *pCodec_frame_size_ms /* o: pointer to codec frame size setting     */ )
{
    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL /*|| hIvasDec->st_ivas->hSplitBinRend == NULL */ )
    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    splitRendBits->bits_buf = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->bits_buf;
    splitRendBits->bits_read = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->bits_read;
    splitRendBits->bits_written = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->bits_written;
    splitRendBits->buf_len = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->buf_len;
    splitRendBits->codec = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec;
    splitRendBits->pose_correction = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->pose_correction;
    splitRendBits->codec_frame_size_ms = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec_frame_size_ms;

#ifdef SPLIT_REND_LCLD_5MS
    /* data consumed, free it */
    free( hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits );
    hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits = NULL;
#endif


    *pCodec = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec;
    *pCodec_frame_size_ms = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms;
    *poseCorrection = hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode;
    return IVAS_ERR_OK;
}

Loading