diff --git a/apps/decoder.c b/apps/decoder.c index 52c01979ab2b1822b171bddbbb3de8d64e9cf220..68b73151ce812a5ef2e84aaf38a407a71b836ae8 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -160,24 +160,22 @@ static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); -static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, #ifdef SPLIT_REND_WITH_HEAD_ROT - uint8_t *splitRendBitsBuf, +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 ); +#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 - IVAS_DEC_HANDLE hIvasDec, - int16_t *pcmBuf ); static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); + #ifdef DEBUGGING -#ifdef VARIABLE_SPEED_DECODING -static ivas_error decodeVariableSpeed( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); -#endif static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); + static int16_t app_own_random( int16_t *seed ); + static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( char *forcedRendModeChar ); #endif - /*------------------------------------------------------------------------------------------* * main() * @@ -432,67 +430,10 @@ int main( } } - /*-------------------------------------------------------------------* - * Load renderer configuration from file - *--------------------------------------------------------------------*/ - - IVAS_RENDER_CONFIG_DATA renderConfigSplit; - if ( ( error = IVAS_DEC_GetDefaultRenderConfig( &renderConfigSplit ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetDefaultRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - if ( arg.renderConfigEnabled ) - { - /* sanity check */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && - arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && - arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && - arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && - arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only when binaural output configurations is used as output OR when Split rendering mode is enabled. Exiting. \n" ); - exit( -1 ); - } -#else - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only for binaural output configurations. Exiting. \n\n" ); - goto cleanup; - } -#endif - if ( RenderConfigReader_read( renderConfigReader, - arg.renderConfigFilename, - &renderConfigSplit ) != IVAS_ERR_OK ) - { - fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); - goto cleanup; - } - } - /*------------------------------------------------------------------------------------------* * Configure the decoder *------------------------------------------------------------------------------------------*/ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - arg.enableHeadRotation = true; - if ( arg.enable5ms && - ( renderConfigSplit.split_rend_config.poseCorrectionMode == IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE || - renderConfigSplit.split_rend_config.dof == 0 ) ) - { - /*TODO : needs to be refined as this wont work with LCLD codec*/ - arg.enable5ms = true; - } - else - { - arg.enable5ms = false; - } - } -#endif - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.enable5ms, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, #ifdef FIX_708_DPID_COMMAND_LINE @@ -507,9 +448,8 @@ int main( goto cleanup; } - /*------------------------------------------------------------------------------------------* - * Configure VoIP mode + * Configure Split rendering *------------------------------------------------------------------------------------------*/ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -520,6 +460,8 @@ int main( fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + + arg.enableHeadRotation = true; } #endif @@ -671,6 +613,25 @@ int main( goto cleanup; } +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( arg.enable5ms && + ( renderConfig.split_rend_config.poseCorrectionMode == IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE || + renderConfig.split_rend_config.dof == 0 ) ) + { + /*TODO : needs to be refined as this wont work with LCLD codec*/ + arg.enable5ms = true; + } + else + { + arg.enable5ms = false; + } + + if ( ( error = IVAS_DEC_Set5msFlag( hIvasDec, arg.enable5ms ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + if ( RenderConfigReader_read( renderConfigReader, arg.renderConfigFilename, &renderConfig ) != IVAS_ERR_OK ) { fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); @@ -809,11 +770,11 @@ int main( } else { - error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, #ifdef SPLIT_REND_WITH_HEAD_ROT - splitRendBitsBuf, + error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, splitRendBitsBuf, hIvasDec, pcmBuf ); +#else + error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf ); #endif - hIvasDec, pcmBuf ); } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -884,7 +845,6 @@ cleanup: print_wmops(); print_mem( NULL ); #endif - if ( !arg.quietModeEnabled ) { printf( "\n" ); @@ -896,7 +856,6 @@ cleanup: #endif dbgclose(); #endif - return mainFailed ? -1 : 0; } @@ -1778,7 +1737,7 @@ static ivas_error initOnFirstGoodFrame( uint16_t *pNumObj /* o : */ #ifdef SPLIT_REND_WITH_HEAD_ROT , - SplitFileReadWrite **hSplitRendFileReadWrite + SplitFileReadWrite **splitRendWriter #endif ) { @@ -1833,7 +1792,7 @@ static ivas_error initOnFirstGoodFrame( if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { - if ( ( error = split_rend_writer_open( hSplitRendFileReadWrite, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1841,7 +1800,7 @@ static ivas_error initOnFirstGoodFrame( } else { - if ( ( error = split_rend_writer_open( hSplitRendFileReadWrite, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1868,7 +1827,7 @@ static ivas_error initOnFirstGoodFrame( for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( *hSplitRendFileReadWrite != NULL ) + if ( *splitRendWriter != NULL ) { IVAS_SPLIT_REND_BITS_DATA splitRendBitsZero; splitRendBitsZero.bits_buf = NULL; @@ -1878,12 +1837,11 @@ static ivas_error initOnFirstGoodFrame( splitRendBitsZero.codec = IVAS_SPLIT_REND_CODEC_DEFAULT; splitRendBitsZero.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; splitRendBitsZero.codec_frame_size_ms = 20; - if ( split_rend_write_bitstream_to_file( *hSplitRendFileReadWrite, 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, -1, IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE, splitRendBitsZero.codec_frame_size_ms ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - exit( -1 ); + return error; } } else @@ -1930,10 +1888,9 @@ static ivas_error initOnFirstGoodFrame( fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); return error; } - /* If outputting ISM, get number of objects, open output files and write zero metadata for initial bad frames */ - if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM - || *pBsFormat == IVAS_DEC_BS_SBA_ISM ) + /* If outputting ISM, get number of objects, open output files and write zero metadata for initial bad frames */ + if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM || *pBsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, pNumObj ) ) != IVAS_ERR_OK ) { @@ -2004,7 +1961,7 @@ static ivas_error initOnFirstGoodFrame( } #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( *hSplitRendFileReadWrite != NULL ) + if ( *splitRendWriter != NULL ) { int16_t enable5ms; @@ -2092,8 +2049,7 @@ static ivas_error decodeG192( IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; #ifdef SPLIT_REND_WITH_HEAD_ROT - IVAS_SPLIT_REND_BITS_DATA splitRendBits; - SplitFileReadWrite *hSplitRendFileReadWrite; + SplitFileReadWrite *splitRendWriter = NULL; #endif for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) @@ -2122,7 +2078,11 @@ static ivas_error decodeG192( } else { - IVAS_DEC_VoIP_SetScale( hIvasDec, arg.tsmScale, arg.tsmScale ); + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, arg.tsmScale, arg.tsmScale ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } } #endif @@ -2158,17 +2118,6 @@ static ivas_error decodeG192( vec_pos_len = 1; } -#ifdef SPLIT_REND_WITH_HEAD_ROT - splitRendBits.bits_buf = splitRendBitsBuf; - splitRendBits.bits_read = 0; - splitRendBits.bits_written = 0; - splitRendBits.buf_len = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES; - splitRendBits.codec = IVAS_SPLIT_REND_CODEC_DEFAULT; - splitRendBits.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; - splitRendBits.codec_frame_size_ms = 0; - hSplitRendFileReadWrite = NULL; -#endif - /*------------------------------------------------------------------------------------------* * Loop for every packet (frame) of bitstream data * - Read the bitstream packet @@ -2213,8 +2162,12 @@ static ivas_error decodeG192( goto cleanup; } } + int16_t enable5ms, num_subframes; - IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ); + if ( ( error = IVAS_DEC_Get5msFlag( hIvasDec, &enable5ms ) ) != IVAS_ERR_OK ) + { + return error; + } arg.enable5ms = enable5ms; num_subframes = ( arg.enable5ms ) ? 1 : IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; @@ -2277,11 +2230,9 @@ static ivas_error decodeG192( for ( i = 0; i < num_subframes; i++ ) { - if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), - RotationFileReader_getFilePath( externalOrientationFileReader ) ); + fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( externalOrientationFileReader ) ); goto cleanup; } } @@ -2311,11 +2262,14 @@ static ivas_error decodeG192( fprintf( stderr, "\nError: input bitstream file couldn't be read: %s \n\n", arg.inputBitstreamFilename ); goto cleanup; } - IVAS_DEC_VoIP_SetScale( hIvasDec, scale, scale ); + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, scale, scale ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } #endif #endif - if ( ( error = BS_Reader_ReadFrame_short( hBsReader, bit_stream, &num_bits, &bfi ) ) != IVAS_ERR_OK ) { if ( error == IVAS_ERR_END_OF_FILE ) @@ -2341,7 +2295,6 @@ static ivas_error decodeG192( } } #endif - /* Feed into decoder */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi ) ) != IVAS_ERR_OK ) { @@ -2353,7 +2306,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 ), &splitRendBits, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBitsBuf, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2365,7 +2318,6 @@ static ivas_error decodeG192( else { #endif - #ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) @@ -2402,31 +2354,11 @@ static ivas_error decodeG192( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { - error = initOnFirstGoodFrame( - hIvasDec, - arg, - numInitialBadFrames, #ifdef SPLIT_REND_WITH_HEAD_ROT - &nOutSamples, - &vec_pos_len, + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) #else - nOutSamples, -#endif - delayNumSamples_orig, - &delayNumSamples, - &delayTimeScale, - &bsFormat, - &afWriter, - &masaWriter, - ismWriters, - &nOutChannels, - &numObj -#ifdef SPLIT_REND_WITH_HEAD_ROT - , - &hSplitRendFileReadWrite + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) #endif - ); - if ( error != IVAS_ERR_OK ) { goto cleanup; } @@ -2441,26 +2373,25 @@ static ivas_error decodeG192( if ( decodedGoodFrame ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) + if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, - splitRendBits.codec, splitRendBits.pose_correction, splitRendBits.codec_frame_size_ms ) != IVAS_ERR_OK ) + 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 ) { fprintf( stderr, "\nUnable to write to bitstream file!\n" ); goto cleanup; } } - else + + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { - if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) - { - if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, - splitRendBits.codec, splitRendBits.pose_correction, splitRendBits.codec_frame_size_ms ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - goto cleanup; - } - } #endif if ( delayNumSamples < nOutSamples ) { @@ -2483,7 +2414,7 @@ static ivas_error decodeG192( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2508,7 +2439,8 @@ static ivas_error decodeG192( } } } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2542,6 +2474,7 @@ static ivas_error decodeG192( #ifdef WMOPS if ( vec_pos_update == 0 ) { + // update_mem(); TODO: verify this update_wmops(); #ifdef FIX_RAM_COUNTING_5MS_RENDERING update_mem(); @@ -2558,7 +2491,6 @@ static ivas_error decodeG192( #endif } - /*------------------------------------------------------------------------------------------* * Flush what is still left in the VoIP Buffers.... *------------------------------------------------------------------------------------------*/ @@ -2585,6 +2517,7 @@ static ivas_error decodeG192( goto cleanup; } } + /* Reference rotation */ if ( arg.enableReferenceRotation ) { @@ -2601,6 +2534,7 @@ static ivas_error decodeG192( goto cleanup; } } + /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -2623,7 +2557,6 @@ static ivas_error decodeG192( } /* decode and get samples */ - #ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) #else @@ -2644,7 +2577,7 @@ static ivas_error decodeG192( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2669,7 +2602,8 @@ static ivas_error decodeG192( } } } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { IVAS_MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) @@ -2717,21 +2651,25 @@ static ivas_error decodeG192( /* Print output metadata file name(s) */ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { - if ( bsFormat == IVAS_DEC_BS_OBJ ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { for ( i = 0; i < numObj; i++ ) { - fprintf( stdout, "\nOutput metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); } fprintf( stdout, "\n" ); } - else if ( bsFormat == IVAS_DEC_BS_MASA ) + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) { - fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } } - /* add zeros at the end to have equal length of synthesized signals */ + /*------------------------------------------------------------------------------------------* + * Add zeros at the end to have equal length of synthesized signals + *------------------------------------------------------------------------------------------*/ + memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); #ifdef SPLIT_REND_WITH_HEAD_ROT if ( afWriter != NULL ) @@ -2755,7 +2693,7 @@ static ivas_error decodeG192( cleanup: #ifdef SPLIT_REND_WITH_HEAD_ROT - split_rend_reader_writer_close( &hSplitRendFileReadWrite ); + split_rend_reader_writer_close( &splitRendWriter ); #endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); @@ -2905,7 +2843,6 @@ static ivas_error decodeVoIP( uint32_t systemTimeInc_ms = (uint32_t) JBM_FRONTEND_FETCH_FRAMESIZE_MS; int32_t nFramesFed = 0; - uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3]; int16_t auSize; uint16_t rtpSequenceNumber; @@ -2927,7 +2864,7 @@ static ivas_error decodeVoIP( int16_t delayNumSamples_orig[3]; /* stores: overall delay, dec+rend delay, and binauralization delay */ int16_t delayNumSamples = -1; int32_t delayTimeScale = -1; - + int16_t i; FILE *f_rtpstream = NULL; EVS_RTPDUMP_DEPACKER rtpdumpDepacker; EVS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_NO_ERROR; @@ -2939,7 +2876,7 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; - for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { ismWriters[i] = NULL; } @@ -3104,18 +3041,21 @@ static ivas_error decodeVoIP( /* decode and get samples */ - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, + #ifdef SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_INT16, (void *) + +#ifdef SUPPORT_JBM_TRACEFILE + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - pcmBuf, - systemTime_ms +#else #ifdef SUPPORT_JBM_TRACEFILE - , - writeJbmTraceFileFrameWrapper, - jbmTraceWriter + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) +#endif #endif - ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3152,34 +3092,14 @@ static ivas_error decodeVoIP( if ( decodedGoodFrame ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - SplitFileReadWrite *hSplitRendFileReadWrite = NULL; -#endif + SplitFileReadWrite *splitRendWriter = NULL; - error = initOnFirstGoodFrame( - hIvasDec, - arg, - numInitialBadFrames, -#ifdef SPLIT_REND_WITH_HEAD_ROT - &nOutSamples, - NULL, + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) #else - nOutSamples, -#endif - delayNumSamples_orig, - &delayNumSamples, - &delayTimeScale, - &bsFormat, - &afWriter, - &masaWriter, - ismWriters, - &nOutChannels, - &numObj -#ifdef SPLIT_REND_WITH_HEAD_ROT - , - &hSplitRendFileReadWrite + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) #endif - ); - if ( error != IVAS_ERR_OK ) { goto cleanup; } @@ -3214,9 +3134,7 @@ static ivas_error decodeVoIP( /* Write ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { - int16_t i; - - if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -3300,6 +3218,24 @@ static ivas_error decodeVoIP( } } + /* Print output metadata file name(s) */ + if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM || bsFormat == IVAS_DEC_BS_SBA_ISM ) + { + for ( i = 0; i < numObj; i++ ) + { + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + } + fprintf( stdout, "\n" ); + } + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + } + } + /*------------------------------------------------------------------------------------------* * Close files and deallocate resources *------------------------------------------------------------------------------------------*/ @@ -3315,7 +3251,7 @@ cleanup: JbmTraceFileWriter_close( &jbmTraceWriter ); #endif MasaFileWriter_close( &masaWriter ); - for ( int16_t i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) { IsmFileWriter_close( &ismWriters[i] ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index d44592c1c8c819c159218c372da660d903b8516b..4d7c9edf3dbefb3e1e42f1057a39a01893d38f18 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -105,30 +105,23 @@ static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_form static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static int16_t IVAS_DEC_VoIP_GetRenderGranularity( Decoder_Struct *st_ivas ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ); -static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, #ifdef SPLIT_REND_WITH_HEAD_ROT - const IVAS_DEC_PCM_TYPE pcmType, - void *data +static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data ); #else - int16_t *data +static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, int16_t *data ); #endif -); static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); -static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, #ifdef SPLIT_REND_WITH_HEAD_ROT - IVAS_DEC_PCM_TYPE pcmType, - void *pcmBuf +static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf ); #else - - int16_t *pcmBuf +static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, int16_t *pcmBuf ); #endif -); static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, int16_t *nSamplesBuffered ); #ifdef SPLIT_REND_WITH_HEAD_ROT static PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ); static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int32_t offset ); -static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int16_t nZeroSamples ); +static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int16_t nZeroSamples ); #endif @@ -371,11 +364,11 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Configure( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const uint32_t sampleRate, /* i : output sampling frequency */ - const AUDIO_CONFIG outputConfig, /* i : output configuration */ - const int16_t tsmEnabled, /* i : enable TSM */ - const int16_t enable5ms, + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const uint32_t sampleRate, /* i : output sampling frequency */ + const AUDIO_CONFIG outputConfig, /* i : output configuration */ + const int16_t tsmEnabled, /* i : enable TSM */ + const int16_t enable5ms, /* i : enable 5ms rendering path */ const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ const int16_t enableHeadRotation, /* i : enable head rotation for binaural output */ @@ -437,6 +430,8 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); } + hDecoderConfig->Opt_tsm = tsmEnabled; + hDecoderConfig->Opt_5ms = enable5ms; hDecoderConfig->Opt_LsCustom = customLsOutputEnabled; hDecoderConfig->Opt_Headrotation = enableHeadRotation; hDecoderConfig->orientation_tracking = orientation_tracking; @@ -453,6 +448,13 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_aeid_on = acousticEnvironmentId != 65535 ? TRUE : FALSE; #endif +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + hDecoderConfig->Opt_Headrotation = TRUE; + } +#endif + /* Set decoder parameters to initial values */ if ( ( error = ivas_init_decoder_front( st_ivas ) ) != IVAS_ERR_OK ) { @@ -464,8 +466,6 @@ ivas_error IVAS_DEC_Configure( hIvasDec->st_ivas->ivas_format = MONO_FORMAT; } - hDecoderConfig->Opt_tsm = tsmEnabled; - hDecoderConfig->Opt_5ms = enable5ms; hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; @@ -484,7 +484,7 @@ ivas_error IVAS_DEC_Configure( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_EnableSplitRendering( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ ) { DECODER_CONFIG_HANDLE hDecoderConfig; @@ -503,13 +503,34 @@ ivas_error IVAS_DEC_EnableSplitRendering( hDecoderConfig->Opt_Headrotation = 1; hDecoderConfig->Opt_5ms = false; - hDecoderConfig->Opt_Limiter = 0; return error; } #endif +/*---------------------------------------------------------------------* + * IVAS_DEC_Set5msFlag( ) + * + * Get the 5ms flag + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_Set5msFlag( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t enable5ms /* i : 5ms flag */ +) +{ + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIvasDec->st_ivas->hDecoderConfig->Opt_5ms = enable5ms; + + return IVAS_ERR_OK; +} + + /*---------------------------------------------------------------------* * IVAS_DEC_Get5msFlag( ) * @@ -517,8 +538,8 @@ ivas_error IVAS_DEC_EnableSplitRendering( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Get5msFlag( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t *enable5ms /* o : 5ms flag */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t *enable5ms /* o : 5ms flag */ ) { if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || enable5ms == NULL ) @@ -531,6 +552,7 @@ ivas_error IVAS_DEC_Get5msFlag( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_EnableVoIP( ) * @@ -573,13 +595,12 @@ ivas_error IVAS_DEC_EnableVoIP( } #endif - if ( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ) != IVAS_ERR_OK ) { return error; } - hIvasDec->hVoIP = malloc( sizeof( IVAS_DEC_VOIP ) ); - if ( hIvasDec->hVoIP == NULL ) + + if ( ( hIvasDec->hVoIP = malloc( sizeof( IVAS_DEC_VOIP ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } @@ -603,6 +624,7 @@ ivas_error IVAS_DEC_EnableVoIP( { return error; } + if ( JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) != 0 ) { return IVAS_ERR_FAILED_ALLOC; @@ -627,8 +649,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { ivas_error error; - error = IVAS_ERR_OK; - if ( !hIvasDec->isInitialized ) { /* Once first frame is fed, finish initialization in EVS Mono. @@ -681,7 +701,10 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } - error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ); + if ( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ) != IVAS_ERR_OK ) + { + return error; + } /* Update redundant frame information in EVS (post- read indices) */ if ( hIvasDec->mode == IVAS_DEC_MODE_EVS && @@ -699,7 +722,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesRendered = 0; hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; - return error; + return IVAS_ERR_OK; } @@ -723,8 +746,6 @@ static ivas_error _GetSamples( Decoder_Struct *st_ivas; ivas_error error; - error = IVAS_ERR_OK; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -739,12 +760,11 @@ static ivas_error _GetSamples( #if defined DEBUGGING && defined SPLIT_REND_WITH_HEAD_ROT assert( pcm_resolution == PCM_INT16 ); #endif - - if ( ( error = evs_dec_main( st_ivas, *nOutSamples, NULL, #ifdef SPLIT_REND_WITH_HEAD_ROT - (int16_t *) + if ( ( error = evs_dec_main( st_ivas, *nOutSamples, NULL, (int16_t *) pcmBuf ) ) != IVAS_ERR_OK ) +#else + if ( ( error = evs_dec_main( st_ivas, *nOutSamples, NULL, pcmBuf ) ) != IVAS_ERR_OK ) #endif - pcmBuf ) ) != IVAS_ERR_OK ) { return error; } @@ -752,11 +772,12 @@ static ivas_error _GetSamples( else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS ) { /* run the main IVAS decoding routine */ - if ( ( error = ivas_dec( st_ivas, + #ifdef SPLIT_REND_WITH_HEAD_ROT - pcm_resolution, + if ( ( error = ivas_dec( st_ivas, pcm_resolution, pcmBuf ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dec( st_ivas, pcmBuf ) ) != IVAS_ERR_OK ) #endif - pcmBuf ) ) != IVAS_ERR_OK ) { return error; } @@ -769,7 +790,7 @@ static ivas_error _GetSamples( hIvasDec->hasDecodedFirstGoodFrame = true; } - return error; + return IVAS_ERR_OK; } @@ -783,22 +804,20 @@ ivas_error IVAS_DEC_GetSamples( int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* indication that the decoder needs a new frame */ + bool *needNewFrame /* o :indication that the decoder needs a new frame */ ) { ivas_error error; int16_t nOutSamplesElse, result, nSamplesToRender; uint16_t nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels, nOutChannels; - error = IVAS_ERR_OK; + nSamplesRendered = 0; nOutChannels = 0; - nSamplesRendered_loop = 0; l_ts = 0; nTransportChannels = 0; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -810,7 +829,7 @@ ivas_error IVAS_DEC_GetSamples( *needNewFrame = true; *nOutSamples = 0; hIvasDec->needNewFrame = true; - return error; + return IVAS_ERR_OK; } /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */ @@ -835,15 +854,13 @@ ivas_error IVAS_DEC_GetSamples( if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { /* setup */ - if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, + #ifdef SPLIT_REND_WITH_HEAD_ROT - pcmType, - pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) #else - pcmBuf + nSamplesRendered * nOutChannels + if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif - ) ) != IVAS_ERR_OK ) { return error; } @@ -854,17 +871,18 @@ ivas_error IVAS_DEC_GetSamples( if ( !hIvasDec->st_ivas->hDecoderConfig->Opt_5ms ) { - if ( ( error = _GetSamples( hIvasDec, #ifdef SPLIT_REND_WITH_HEAD_ROT - pcm_type_API_to_internal( pcmType ), + if ( ( error = _GetSamples( hIvasDec, pcm_type_API_to_internal( pcmType ), pcmBuf, nOutSamples ) ) != IVAS_ERR_OK ) +#else + if ( ( error = _GetSamples( hIvasDec, pcmBuf, nOutSamples ) ) != IVAS_ERR_OK ) #endif - pcmBuf, nOutSamples ) ) != IVAS_ERR_OK ) { return error; } #ifdef DEBUGGING assert( *nOutSamples == nSamplesAsked ); #endif + hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = *nOutSamples; nSamplesRendered = *nOutSamples; @@ -932,18 +950,16 @@ ivas_error IVAS_DEC_GetSamples( /* render IVAS frames directly to the output buffer */ nSamplesToRender = nSamplesAsked - nSamplesRendered; - if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, + #ifdef SPLIT_REND_WITH_HEAD_ROT - pcmType, - pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) + if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) #else - pcmBuf + nSamplesRendered * nOutChannels + if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif - - ) ) != IVAS_ERR_OK ) { return error; } + nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; if ( hIvasDec->nSamplesAvailableNext == 0 ) @@ -960,7 +976,7 @@ ivas_error IVAS_DEC_GetSamples( *nOutSamples = nSamplesRendered; - return error; + return IVAS_ERR_OK; } @@ -972,11 +988,11 @@ 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 */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* o : indication that the decoder needs a new frame */ + 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 */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { Decoder_Struct *st_ivas; @@ -1004,10 +1020,10 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( output_Fs = st_ivas->hDecoderConfig->output_Fs; numSamplesPerChannelToDecode = (int16_t) ( output_Fs / FRAMES_PER_SEC ); - *needNewFrame = FALSE; + *needNewFrame = false; hSplitBinRend = &st_ivas->hSplitBinRend; - if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, hSplitRendBits ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBitsBuf ) ) != IVAS_ERR_OK ) { return error; } @@ -1107,11 +1123,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, - max_band, - pOutput, - 1, - !td_input, - pcm_out_flag ) ) != IVAS_ERR_OK ) + max_band, pOutput, 1, !td_input, pcm_out_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -1150,23 +1162,21 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( *---------------------------------------------------------------------*/ static ivas_error IVAS_DEC_Setup( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ - uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ - uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ - uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ + uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ + uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ #ifdef SPLIT_REND_WITH_HEAD_ROT - const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ - void *data /* o : output synthesis signal */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *data /* o : output synthesis signal */ #else - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ #endif ) { ivas_error error; - error = IVAS_ERR_OK; - *nSamplesRendered = 0; if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) @@ -1198,11 +1208,11 @@ static ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { - if ( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, #ifdef SPLIT_REND_WITH_HEAD_ROT - pcm_type_API_to_internal( pcmType ), + if ( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) #endif - data ) ) != IVAS_ERR_OK ) { return error; } @@ -1213,7 +1223,7 @@ static ivas_error IVAS_DEC_Setup( *nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; } - return error; + return IVAS_ERR_OK; } @@ -1232,8 +1242,6 @@ static ivas_error IVAS_DEC_GetTcSamples( Decoder_Struct *st_ivas; ivas_error error; - error = IVAS_ERR_OK; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1266,9 +1274,10 @@ static ivas_error IVAS_DEC_GetTcSamples( hIvasDec->hasDecodedFirstGoodFrame = true; } - return error; + return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_Rendered_FeedTcSamples( ) * @@ -1286,8 +1295,6 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( ivas_error error; - error = IVAS_ERR_OK; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1296,14 +1303,12 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( st_ivas = hIvasDec->st_ivas; /* feed the TCs to the IVAS renderer */ - if ( ( error = ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf ) ) != IVAS_ERR_OK ) - { - return error; - } + error = ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf ); return error; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderedSamples( ) * @@ -1326,8 +1331,6 @@ static ivas_error IVAS_DEC_GetRenderedSamples( Decoder_Struct *st_ivas; ivas_error error; - error = IVAS_ERR_OK; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1336,15 +1339,11 @@ static ivas_error IVAS_DEC_GetRenderedSamples( st_ivas = hIvasDec->st_ivas; /* run the main IVAS decoding routine */ - if ( ( error = ivas_jbm_dec_render( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, #ifdef SPLIT_REND_WITH_HEAD_ROT - pcm_type_API_to_internal( pcmType ), + error = ivas_jbm_dec_render( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcm_type_API_to_internal( pcmType ), pcmBuf ); +#else + error = ivas_jbm_dec_render( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); #endif - pcmBuf ) ) != IVAS_ERR_OK ) - { - return error; - } - return error; } @@ -1357,25 +1356,23 @@ static ivas_error IVAS_DEC_GetRenderedSamples( *---------------------------------------------------------------------*/ static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int16_t *nSamplesBuffered /* o : number of samples still buffered */ ) { - ivas_error error; - error = IVAS_ERR_OK; - *nSamplesBuffered = 0; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ if ( hIvasDec->st_ivas->hTcBuffer != NULL ) { *nSamplesBuffered = hIvasDec->st_ivas->hTcBuffer->n_samples_buffered - hIvasDec->st_ivas->hTcBuffer->n_samples_rendered; } - return error; + return IVAS_ERR_OK; } @@ -1524,9 +1521,9 @@ ivas_error IVAS_DEC_GetObjectMetadata( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetMasaMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ MASA_DECODER_EXT_OUT_META_HANDLE *hMasaExtOutMeta, /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ - uint8_t getFromJbmBuffer /* i : get metadata from a JBM buffer */ + uint8_t getFromJbmBuffer /* i : get metadata from a JBM buffer */ ) { if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -1568,6 +1565,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( ) { HEAD_TRACK_DATA_HANDLE hHeadTrackData; + ivas_error error; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1588,12 +1586,15 @@ ivas_error IVAS_DEC_FeedHeadTrackData( Euler2Quat( deg2rad( orientation.x ), deg2rad( orientation.y ), deg2rad( orientation.z ), &orientation ); } - ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[subframe_idx] ); + if ( ( error = ivas_orient_trk_Process( hHeadTrackData->OrientationTracker, orientation, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &hHeadTrackData->Quaternions[subframe_idx] ) ) != IVAS_ERR_OK ) + { + return error; + } + hHeadTrackData->Pos[subframe_idx].x = Pos.x; hHeadTrackData->Pos[subframe_idx].y = Pos.y; hHeadTrackData->Pos[subframe_idx].z = Pos.z; - #ifdef SPLIT_REND_WITH_HEAD_ROT hHeadTrackData->sr_pose_pred_axis = rot_axis; #endif @@ -1641,8 +1642,8 @@ ivas_error IVAS_DEC_FeedRefRotData( ivas_error IVAS_DEC_FeedRefVectorData( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_VECTOR3 listenerPos, /* i : Listener position */ - const IVAS_VECTOR3 refPos /* i : Reference position */ + const IVAS_VECTOR3 listenerPos, /* i : Listener position */ + const IVAS_VECTOR3 refPos /* i : Reference position */ ) { ivas_orient_trk_state_t *pOtr; @@ -1841,7 +1842,15 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( return IVAS_ERR_OK; } -static ivas_error copyRendererConfigStruct( RENDER_CONFIG_HANDLE hRCin, IVAS_RENDER_CONFIG_HANDLE hRCout ) +/*---------------------------------------------------------------------* + * copyRendererConfigStruct( ) + * + * + *---------------------------------------------------------------------*/ + +static ivas_error copyRendererConfigStruct( + RENDER_CONFIG_HANDLE hRCin, + IVAS_RENDER_CONFIG_HANDLE hRCout ) { if ( hRCin == NULL || hRCout == NULL ) { @@ -1887,6 +1896,7 @@ static ivas_error copyRendererConfigStruct( RENDER_CONFIG_HANDLE hRCin, IVAS_REN return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderConfig( ) * @@ -2298,13 +2308,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( int16_t nSamplesRendered; uint8_t nOutChannels; - error = IVAS_ERR_OK; - st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; hVoIP = hIvasDec->hVoIP; timeScalingDone = 0; - nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; nSamplesRendered = 0; @@ -2322,24 +2329,24 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesBuffered = 0; if ( hIvasDec->hasBeenFedFirstGoodFrame ) { - IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ); + if ( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ) != IVAS_ERR_OK ) + { + return error; + } } - extBufferedSamples = nSamplesRendered + nSamplesBuffered; + extBufferedSamples = nSamplesRendered + nSamplesBuffered; extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; - dataUnit = NULL; - /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); if ( result != 0 ) { return IVAS_ERR_UNKNOWN; } - - maxScaling = maxScaling * hDecoderConfig->output_Fs / 1000; + /* avoid time scaling multiple times in one sound card slot */ if ( scale != 100U ) { @@ -2363,7 +2370,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( scale = APA_MAX_SCALE; } - IVAS_DEC_VoIP_SetScale( hIvasDec, (int16_t) maxScaling, (int16_t) scale ); + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (int16_t) maxScaling, (int16_t) scale ) ) != IVAS_ERR_OK ) + { + return error; + } /* copy bitstream into decoder state */ if ( dataUnit ) @@ -2371,12 +2381,20 @@ ivas_error IVAS_DEC_VoIP_GetSamples( hIvasDec->hVoIP->hCurrentDataUnit = dataUnit; bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize ); - IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ); + + + if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( hIvasDec->hasDecodedFirstGoodFrame ) { /* Decoder has been initialized with first good frame - do PLC */ - IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ); + if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } } #ifdef SUPPORT_JBM_TRACEFILE @@ -2402,15 +2420,18 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator; } + /* data unit memory is no longer used */ JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; hIvasDec->nSamplesRendered = 0; } } + /* decode */ if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { @@ -2433,14 +2454,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesToRender = nSamplesPerChannel - nSamplesRendered; /* render IVAS frames directly to the output buffer */ - if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, #ifdef SPLIT_REND_WITH_HEAD_ROT - pcmType, - pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) #else - pcmBuf + nSamplesRendered * nOutChannels, + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nSamplesRendered * nOutChannels, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) #endif - &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -2449,7 +2467,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } - return error; + return IVAS_ERR_OK; } @@ -2480,16 +2498,14 @@ ivas_error IVAS_DEC_Flush( nSamplesToRender = (uint16_t) *nSamplesFlushed; /* render IVAS frames */ - if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, + #ifdef SPLIT_REND_WITH_HEAD_ROT - pcmType, + error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); +#else + error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); #endif - pcmBuf ) ) != IVAS_ERR_OK ) - { - return error; - } - return IVAS_ERR_OK; + return error; } @@ -2724,6 +2740,7 @@ static ivas_error get_channel_config( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * printConfigInfo_dec( ) * @@ -2904,20 +2921,25 @@ static ivas_error printConfigInfo_dec( /*-----------------------------------------------------------------* * Print TSM mode info *-----------------------------------------------------------------*/ + if ( st_ivas->hDecoderConfig->Opt_tsm ) { fprintf( stdout, "TSM mode: ON\n" ); } + /*-----------------------------------------------------------------* * Print 5ms API mode info *-----------------------------------------------------------------*/ + if ( st_ivas->hDecoderConfig->Opt_5ms ) { fprintf( stdout, "API 5ms mode: ON\n" ); } + return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_PrintConfig( ) * @@ -3023,8 +3045,6 @@ static ivas_error evs_dec_main( int16_t ch; ivas_error error; - error = IVAS_ERR_OK; - hCoreCoder = st_ivas->hSCE[0]->hCoreCoder; hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -3112,7 +3132,7 @@ static ivas_error evs_dec_main( ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); } - return error; + return IVAS_ERR_OK; } @@ -3328,16 +3348,14 @@ static int16_t IVAS_DEC_VoIP_GetRenderGranularity( * * *---------------------------------------------------------------------*/ + static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ) { - int16_t apa_buffer_size; - ivas_error error; - apa_buffer_size = hIvasDec->nSamplesFrame; if ( hIvasDec->apaExecBuffer == NULL ) @@ -3379,8 +3397,8 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( { return IVAS_ERR_INIT_ERROR; } - if ( apa_init( &hIvasDec->hTimeScaler, - nTransportChannels ) != IVAS_ERR_OK || + + if ( apa_init( &hIvasDec->hTimeScaler, nTransportChannels ) != IVAS_ERR_OK || apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ) != 0 || apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ) != 0 || apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ) != 0 || @@ -3389,7 +3407,6 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_INIT_ERROR; } - if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { if ( apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ) != 0 ) @@ -3397,8 +3414,8 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_INIT_ERROR; } } - if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) + if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } @@ -3427,9 +3444,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( hIvasDec->nTransportChannelsOld = nTransportChannels; - error = IVAS_ERR_OK; - - return error; + return IVAS_ERR_OK; } @@ -3457,6 +3472,7 @@ ivas_error IVAS_DEC_GetSplitRendBits( 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; return IVAS_ERR_OK; } @@ -3481,8 +3497,6 @@ ivas_error IVAS_DEC_GetCldfbSamples( ivas_error error; int16_t ch, b, slot_idx, num_chs, maxBand, num_samples; - error = IVAS_ERR_OK; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3520,7 +3534,7 @@ ivas_error IVAS_DEC_GetCldfbSamples( *nOutSamples = num_samples; - return error; + return IVAS_ERR_OK; } #endif @@ -3556,10 +3570,19 @@ static void *pcm_buffer_offset( } } -ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, int16_t nZeroSamples ) + +/*---------------------------------------------------------------------* + * set_pcm_buffer_to_zero() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error set_pcm_buffer_to_zero( + void *buffer, + const IVAS_DEC_PCM_TYPE pcmType, + const int16_t nZeroSamples ) { ivas_error error; - error = IVAS_ERR_OK; switch ( pcmType ) { @@ -3572,13 +3595,23 @@ ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType default: error = IVAS_ERR_INTERNAL; } - return error; + + return IVAS_ERR_OK; } -PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ) + +/*---------------------------------------------------------------------* + * pcm_type_API_to_internal() + * + * + *---------------------------------------------------------------------*/ + +PCM_RESOLUTION pcm_type_API_to_internal( + const IVAS_DEC_PCM_TYPE pcmType ) { PCM_RESOLUTION pcm_resolution; pcm_resolution = PCM_NOT_KNOW; + switch ( pcmType ) { case IVAS_DEC_PCM_FLOAT: @@ -3590,6 +3623,7 @@ PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ) default: pcm_resolution = PCM_NOT_KNOW; } + return pcm_resolution; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 22d39c9ed644c90e97dd6efa4784fe0be2e988e1..a1e6ea251419d046236a576d69482c3a8f7660cc 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -176,7 +176,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 */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o : bitstream output for split rendering mode */ + uint8_t *splitRendBitsBuf, /* 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 */ ); @@ -207,9 +207,9 @@ ivas_error IVAS_DEC_GetObjectMetadata( /*! r: error code */ ivas_error IVAS_DEC_GetMasaMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ IVAS_MASA_DECODER_EXT_OUT_META_HANDLE *hMasaExtOutMeta, /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */ - uint8_t getFromJbmBuffer /* i : get metadata from a JBM buffer */ + uint8_t getFromJbmBuffer /* i : get metadata from a JBM buffer */ ); /*! r: error code */ @@ -309,6 +309,11 @@ ivas_error IVAS_DEC_EnableSplitRendering( ); #endif +ivas_error IVAS_DEC_Set5msFlag( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t enable5ms /* i : 5ms flag */ +); + ivas_error IVAS_DEC_Get5msFlag( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int16_t *enable5ms /* o : 5ms flag */ diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index f3cada0ab30416c424974498fb235ede7c7e5461..b79319ed1f8730bacd62691413e307ad1ff65ace 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -601,10 +601,10 @@ void ivas_td_binaural_close( ); ivas_error TDREND_GetMix( - BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ float *output[], /* i/o: ISM object synth/rendered output in 0,1 */ - const int16_t subframe_length, /* i/o: subframe length */ - const int16_t subframe_idx, /* i : Subframe index to 5 ms subframe */ + const int16_t subframe_length, /* i/o: subframe length */ + const int16_t subframe_idx, /* i : Subframe index to 5 ms subframe */ const int16_t ism_md_subframe_update /* i : Number of subframes to delay metadata to sync with audio */ ); @@ -831,7 +831,7 @@ void ivas_rend_closeCrend( ); ivas_error ivas_hrtf_init( - HRTFS_DATA *hHrtf /* i/o: HRTF handle */ + HRTFS_DATA *hHrtf /* i/o: HRTF handle */ ); ivas_error ivas_rend_initCrendWrapper( @@ -1359,6 +1359,11 @@ ivas_error ivas_orient_trk_Process( ); #ifdef SPLIT_REND_WITH_HEAD_ROT +void ivas_set_split_rend_ht_setup( + IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData +); + /*----------------------------------------------------------------------------------* * Split binaural renderer prototypes *----------------------------------------------------------------------------------*/ @@ -1372,7 +1377,7 @@ ivas_error ivas_set_split_rend_setup( IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits + uint8_t *splitRendBitsBuf ); void ivas_init_split_rend_handles( @@ -1400,7 +1405,8 @@ ivas_error ivas_splitBinLCLDEncOpen( BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc, const int32_t iSampleRate, const int16_t iChannels, - const int32_t iDataRate ); + const int32_t iDataRate +); void ivas_splitBinLCLDEncClose( BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc @@ -1435,7 +1441,7 @@ void ivas_splitBinLCLDDecProcess( ivas_error ivas_splitBinPreRendOpen( BIN_HR_SPLIT_PRE_REND_HANDLE *hBinHrSplitPreRend, MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData -#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG +#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG , const int32_t output_Fs #endif @@ -1464,7 +1470,7 @@ void ivas_renderSplitUpdateNoCorrectionPoseData( ivas_error ivas_renderMultiBinToSplitBinaural( SPLIT_REND_WRAPPER *hSplitBin, - const IVAS_QUATERNION headPosition, + const IVAS_QUATERNION headPosition, const int32_t SplitRendBitRate, IVAS_SPLIT_REND_CODEC splitCodec, int16_t codec_frame_size_ms, @@ -1854,7 +1860,7 @@ void ivas_split_rend_get_quant_params( ivas_error ivas_split_rend_choose_default_codec( IVAS_SPLIT_REND_CODEC *pCodec, /* i/o: pointer to codec setting */ - int16_t *pCodec_frame_size_ms, /* i/o: pointer to codec frame size setting */ + int16_t *pCodec_frame_size_ms, /* i/o: pointer to codec frame size setting */ const int16_t cldfb_in_flag, /* i : flag indicating rendering in CLDFB */ const int16_t pcm_out_flag /* i : flag to indicate PCM output */ ); diff --git a/lib_rend/ivas_splitRendererPre.c b/lib_rend/ivas_splitRendererPre.c index 2be6e7429d61ccfec3fc575ab9b94cf5a9a6076c..6e97d70a5d13dec591e8c9444961ecca4b0dd4eb 100644 --- a/lib_rend/ivas_splitRendererPre.c +++ b/lib_rend/ivas_splitRendererPre.c @@ -1817,11 +1817,23 @@ ivas_error ivas_set_split_rend_setup( IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, - IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits ) + uint8_t *splitRendBitsBuf ) { int16_t sf, i, j; - hSplitBinRend->hSplitRendBits = hSplitRendBits; + if ( ( hSplitBinRend->hSplitRendBits = (IVAS_SPLIT_REND_BITS_HANDLE) malloc( sizeof( IVAS_SPLIT_REND_BITS_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split renderer Bits buffer\n" ) ); + } + + hSplitBinRend->hSplitRendBits->bits_buf = splitRendBitsBuf; + hSplitBinRend->hSplitRendBits->bits_read = 0; + hSplitBinRend->hSplitRendBits->bits_written = 0; + hSplitBinRend->hSplitRendBits->buf_len = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES; + hSplitBinRend->hSplitRendBits->codec = IVAS_SPLIT_REND_CODEC_DEFAULT; + hSplitBinRend->hSplitRendBits->pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE; + hSplitBinRend->hSplitRendBits->codec_frame_size_ms = 0; + if ( ( hSplitBinRend->hMultiBinCldfbData = (IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL ) {