From 1f4a2099fae2edee07ce4020c0db377955e03e06 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 17:56:33 +0200 Subject: [PATCH 01/10] FIX_1135_EXT_RENDERER_HANDLES --- apps/renderer.c | 26 +++++++++ lib_com/options.h | 1 + lib_dec/ivas_stat_dec.h | 2 +- lib_dec/lib_dec.c | 2 + lib_rend/lib_rend.c | 126 +++++++++++++++++++++++++++++++++++----- lib_rend/lib_rend.h | 4 ++ 6 files changed, 146 insertions(+), 15 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index cf97acf947..4f76ccb800 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -169,6 +169,10 @@ typedef struct char customHrtfFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char renderConfigFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; int8_t orientation_tracking; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + int16_t Opt_Headrotation; + int16_t Opt_ExternalOrientation; +#endif int16_t nonDiegeticPan; float nonDiegeticPanGain; IVAS_REND_COMPLEXITY_LEVEL complexityLevel; @@ -882,7 +886,11 @@ int main( const int16_t frameSize_smpls = (int16_t) ( ( args.render_framesize ) * args.sampleRate * 5 / ( 1000 ) ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, !isEmptyString( args.customHrtfFilePath ), args.nonDiegeticPan, args.nonDiegeticPanGain, args.Opt_Headrotation, args.Opt_ExternalOrientation, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, !isEmptyString( args.customHrtfFilePath ), args.nonDiegeticPan, args.nonDiegeticPanGain, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) ); exit( -1 ); @@ -2510,7 +2518,12 @@ static CmdlnArgs defaultArgs( clearString( args.renderConfigFilePath ); clearString( args.externalOrientationFilePath ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + args.Opt_Headrotation = 0; + args.Opt_ExternalOrientation = 0; +#endif args.orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; + args.nonDiegeticPan = 0; args.nonDiegeticPanGain = 0.f; @@ -2598,6 +2611,9 @@ static void parseOption( break; case CmdLnOptionId_trajFile: assert( numOptionValues == 1 ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + args->Opt_Headrotation = 1; +#endif strncpy( args->headRotationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_outputMetadata: @@ -2618,6 +2634,9 @@ static void parseOption( break; case CmdLnOptionId_exteriorOrientationFile: assert( numOptionValues == 1 ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + args->Opt_ExternalOrientation = 1; +#endif strncpy( args->externalOrientationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_customHrtfFile: @@ -2742,6 +2761,13 @@ static CmdlnArgs parseCmdlnArgs( exit( -1 ); /* Error printout handled by failing function */ } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + args.Opt_Headrotation = TRUE; + } +#endif + return args; } diff --git a/lib_com/options.h b/lib_com/options.h index 8d9fa9a11f..b16a8e83ff 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,7 @@ //#define FIX_CREND_FIX_POINT_HRTF_FILE_FORMAT /* Orange issue 1031 : new fix point hrtf binary file format */ //#define FIX_CREND_SIMPLIFY_CODE /* Ora : simplify line code in crend */ #define FLOAT_FIX_POINT_HRTF_FILE_FORMAT /* allows reading floation or fix point hrtf binary file format */ +#define FIX_1135_EXT_RENDERER_HANDLES /* VA: issue 1135: Memory usage reduction in external renderer: Allocate only handles that are really needed. */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 8f096dd705..3660868f27 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -990,7 +990,7 @@ typedef struct decoder_config_structure int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ float non_diegetic_pan_gain; /* non diegetic panning gain*/ int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ + int16_t Opt_ExternalOrientation; /* indicates whether external orientations are used */ int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ #ifdef DEBUGGING diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index c5654bd8ad..9ef281f1bd 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -489,11 +489,13 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->render_framesize = renderFramesize; } +#ifndef FIX_1135_EXT_RENDERER_HANDLES 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 ) { diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 6e3257b6c8..0ed0194088 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -204,7 +204,11 @@ struct IVAS_REND AUDIO_CONFIG outputConfig; EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + SPLIT_REND_WRAPPER *splitRendWrapper; +#else SPLIT_REND_WRAPPER splitRendWrapper; +#endif IVAS_REND_AudioBuffer splitRendEncBuffer; IVAS_REND_HeadRotData headRotData; @@ -1218,7 +1222,11 @@ static rendering_context getRendCtx( ctx.pHeadRotData = &hIvasRend->headRotData; ctx.hhRendererConfig = &hIvasRend->hRendererConfig; ctx.pSplitRendBFI = &hIvasRend->splitRendBFI; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ctx.pSplitRendWrapper = hIvasRend->splitRendWrapper; +#else ctx.pSplitRendWrapper = &hIvasRend->splitRendWrapper; +#endif ctx.pCombinedOrientationData = &hIvasRend->hCombinedOrientationData; return ctx; @@ -2754,13 +2762,18 @@ static void clearInputMasa( *------------------------------------------------------------------------*/ ivas_error IVAS_REND_Open( - IVAS_REND_HANDLE *phIvasRend, - const int32_t outputSampleRate, - const AUDIO_CONFIG outConfig, - const bool asHrtfBinary, - const int16_t nonDiegeticPan, - const float nonDiegeticPanGain, - const int16_t num_subframes ) + IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ + const int32_t outputSampleRate, /* i : output sampling rate */ + const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ + const bool asHrtfBinary, /* i : load hrtf binary file */ + const int16_t nonDiegeticPan, /* i : non-diegetic object flag */ + const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ +#ifdef FIX_1135_EXT_RENDERER_HANDLES + const int16_t Opt_Headrotation, /* i : indicates whether head-rotation is used */ + const int16_t Opt_ExternalOrientation, /* i : indicates whether external orientations are used */ +#endif + const int16_t num_subframes /* i : number of subframes */ +) { int16_t i; int16_t j; @@ -2814,22 +2827,46 @@ ivas_error IVAS_REND_Open( } /* Initialize headrotation data */ - if ( ( error = initHeadRotation( hIvasRend ) ) != IVAS_ERR_OK ) +#ifdef FIX_1135_EXT_RENDERER_HANDLES + hIvasRend->headRotData.headRotEnabled = 0; + if ( Opt_Headrotation ) { - return error; +#endif + if ( ( error = initHeadRotation( hIvasRend ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_1135_EXT_RENDERER_HANDLES } +#endif /* Initialize external orientation data */ - if ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) +#ifdef FIX_1135_EXT_RENDERER_HANDLES + hIvasRend->hExternalOrientationData = NULL; + if ( Opt_ExternalOrientation ) { - return error; +#endif + if ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_1135_EXT_RENDERER_HANDLES } +#endif /* Initilize combined orientation data */ - if ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) +#ifdef FIX_1135_EXT_RENDERER_HANDLESaa + hIvasRend->hCombinedOrientationData = NULL; + if ( Opt_Headrotation || Opt_ExternalOrientation ) { - return error; +#endif + if ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_1135_EXT_RENDERER_HANDLESaa } +#endif /* Initialize EFAP */ if ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) @@ -2838,9 +2875,28 @@ ivas_error IVAS_REND_Open( } /* Initialize inputs */ + +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + if ( ( hIvasRend->splitRendWrapper = (SPLIT_REND_WRAPPER *) malloc( sizeof( SPLIT_REND_WRAPPER ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); + } + + isar_init_split_rend_handles( hIvasRend->splitRendWrapper ); + hIvasRend->splitRendEncBuffer.data = NULL; + } + else + { + hIvasRend->splitRendWrapper = NULL; + } +#else isar_init_split_rend_handles( &hIvasRend->splitRendWrapper ); hIvasRend->splitRendEncBuffer.data = NULL; +#endif + for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); @@ -3445,7 +3501,11 @@ ivas_error IVAS_REND_AddInput( int16_t cldfb_in_flag; cldfb_in_flag = getCldfbRendFlag( hIvasRend, getAudioConfigType( inConfig ) ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ivas_pre_rend_init( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer, &hIvasRend->hRendererConfig->split_rend_config, hIvasRend->headRotData, hIvasRend->sampleRateOut, hIvasRend->outputConfig, cldfb_in_flag, hIvasRend->num_subframes ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_pre_rend_init( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer, &hIvasRend->hRendererConfig->split_rend_config, hIvasRend->headRotData, hIvasRend->sampleRateOut, hIvasRend->outputConfig, cldfb_in_flag, hIvasRend->num_subframes ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -3863,7 +3923,11 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->inputsSba[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( hIvasRend->splitRendWrapper->hBinHrSplitPreRend != NULL ) +#else if ( hIvasRend->splitRendWrapper.hBinHrSplitPreRend != NULL ) +#endif { if ( hIvasRend->hRendererConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) { @@ -4362,9 +4426,17 @@ int16_t IVAS_REND_FeedRenderConfig( { int16_t cldfb_in_flag; cldfb_in_flag = getCldfbRendFlag( hIvasRend, IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN ); +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); +#else ISAR_PRE_REND_close( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); +#endif +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ivas_pre_rend_init( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer, &hIvasRend->hRendererConfig->split_rend_config, hIvasRend->headRotData, hIvasRend->sampleRateOut, hIvasRend->outputConfig, cldfb_in_flag, hIvasRend->num_subframes ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_pre_rend_init( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer, &hIvasRend->hRendererConfig->split_rend_config, hIvasRend->headRotData, hIvasRend->sampleRateOut, hIvasRend->outputConfig, cldfb_in_flag, hIvasRend->num_subframes ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4521,6 +4593,13 @@ ivas_error IVAS_REND_SetOrientationTrackingMode( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking /* i : Head orientation tracking type */ ) { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( hIvasRend->headRotData.headRotEnabled == 0 ) + { + return IVAS_HEAD_ORIENT_TRK_NONE; + } +#endif + return ivas_orient_trk_SetTrackingType( hIvasRend->headRotData.hOrientationTracker, orientation_tracking ); } @@ -7371,10 +7450,19 @@ static ivas_error getSamplesInternal( ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { int16_t num_poses_orig; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + num_poses_orig = hIvasRend->splitRendWrapper->multiBinPoseData.num_poses; +#else num_poses_orig = hIvasRend->splitRendWrapper.multiBinPoseData.num_poses; +#endif outAudio = hIvasRend->splitRendEncBuffer; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ISAR_PRE_REND_GetMultiBinPoseData( &hIvasRend->hRendererConfig->split_rend_config, &hIvasRend->splitRendWrapper->multiBinPoseData, hIvasRend->headRotData.sr_pose_pred_axis ); + assert( num_poses_orig == hIvasRend->splitRendWrapper->multiBinPoseData.num_poses && "number of poses should not change dynamically" ); +#else ISAR_PRE_REND_GetMultiBinPoseData( &hIvasRend->hRendererConfig->split_rend_config, &hIvasRend->splitRendWrapper.multiBinPoseData, hIvasRend->headRotData.sr_pose_pred_axis ); assert( num_poses_orig == hIvasRend->splitRendWrapper.multiBinPoseData.num_poses && "number of poses should not change dynamically" ); +#endif /* Clear output buffer for split rendering bitstream */ set_zero( outAudio.data, outAudio.config.numChannels * outAudio.config.numSamplesPerChannel ); @@ -7439,7 +7527,11 @@ static ivas_error getSamplesInternal( } } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, +#else if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hIvasRend->splitRendWrapper, +#endif hIvasRend->headRotData.headPositions[0], hIvasRend->hRendererConfig->split_rend_config.splitRendBitRate, hIvasRend->hRendererConfig->split_rend_config.codec, @@ -7448,7 +7540,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, @@ -7611,7 +7703,13 @@ void IVAS_REND_Close( ivas_limiter_close( &hIvasRend->hLimiter ); /* Split binaural rendering */ +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); + free( hIvasRend->splitRendWrapper ); + hIvasRend->splitRendWrapper = NULL; +#else ISAR_PRE_REND_close( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); +#endif closeHeadRotation( hIvasRend ); diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 5cd2b07f61..94ff3ff3da 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -113,6 +113,10 @@ ivas_error IVAS_REND_Open( const bool asHrtfBinary, /* i : load hrtf binary file */ const int16_t nonDiegeticPan, /* i : non-diegetic object flag */ const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ +#ifdef FIX_1135_EXT_RENDERER_HANDLES + const int16_t Opt_Headrotation, /* i : indicates whether head-rotation is used */ + const int16_t Opt_ExternalOrientation, /* i : indicates whether external orientations are used */ +#endif const int16_t num_subframes /* i : number of subframes */ ); -- GitLab From 274445b535237db44dd1826a889b0c02655720c9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 18:05:27 +0200 Subject: [PATCH 02/10] build fix --- apps/renderer.c | 2 +- lib_rend/lib_rend.c | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 4f76ccb800..e734aeb8ab 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -2764,7 +2764,7 @@ static CmdlnArgs parseCmdlnArgs( #ifdef FIX_1135_EXT_RENDERER_HANDLES if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - args.Opt_Headrotation = TRUE; + args.Opt_Headrotation = 1; } #endif diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 0ed0194088..5b1b547eeb 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2855,7 +2855,7 @@ ivas_error IVAS_REND_Open( #endif /* Initilize combined orientation data */ -#ifdef FIX_1135_EXT_RENDERER_HANDLESaa +#ifdef FIX_1135_EXT_RENDERER_HANDLES hIvasRend->hCombinedOrientationData = NULL; if ( Opt_Headrotation || Opt_ExternalOrientation ) { @@ -2864,7 +2864,7 @@ ivas_error IVAS_REND_Open( { return error; } -#ifdef FIX_1135_EXT_RENDERER_HANDLESaa +#ifdef FIX_1135_EXT_RENDERER_HANDLES } #endif @@ -2877,6 +2877,7 @@ ivas_error IVAS_REND_Open( /* Initialize inputs */ #ifdef FIX_1135_EXT_RENDERER_HANDLES + hIvasRend->splitRendWrapper = NULL; if ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { if ( ( hIvasRend->splitRendWrapper = (SPLIT_REND_WRAPPER *) malloc( sizeof( SPLIT_REND_WRAPPER ) ) ) == NULL ) @@ -2887,14 +2888,9 @@ ivas_error IVAS_REND_Open( isar_init_split_rend_handles( hIvasRend->splitRendWrapper ); hIvasRend->splitRendEncBuffer.data = NULL; } - else - { - hIvasRend->splitRendWrapper = NULL; - } #else isar_init_split_rend_handles( &hIvasRend->splitRendWrapper ); hIvasRend->splitRendEncBuffer.data = NULL; - #endif for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) @@ -4596,7 +4592,7 @@ ivas_error IVAS_REND_SetOrientationTrackingMode( #ifdef FIX_1135_EXT_RENDERER_HANDLES if ( hIvasRend->headRotData.headRotEnabled == 0 ) { - return IVAS_HEAD_ORIENT_TRK_NONE; + return IVAS_ERR_OK; } #endif @@ -7540,7 +7536,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t ) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From 403e6da0ae7c40aacd8c8e8712c75d3b45cca3b6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 18:26:50 +0200 Subject: [PATCH 03/10] fix memory deallocation --- lib_rend/lib_rend.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 5b1b547eeb..bc4a944e91 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1113,7 +1113,11 @@ static ivas_error initHeadRotation( static void closeHeadRotation( IVAS_REND_HANDLE hIvasRend ) { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( hIvasRend != NULL && hIvasRend->headRotData.headRotEnabled && hIvasRend->headRotData.hOrientationTracker != NULL ) +#else if ( ( hIvasRend != NULL ) && ( hIvasRend->headRotData.hOrientationTracker != NULL ) ) +#endif { free( hIvasRend->headRotData.hOrientationTracker ); } @@ -1399,7 +1403,11 @@ static void clearInputIsm( initRendInputBase( &inputIsm->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); /* Free input's internal handles */ +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputIsm->crendWrapper, inputIsm->base.ctx.pSplitRendWrapper != NULL ? inputIsm->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputIsm->crendWrapper, inputIsm->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif ivas_reverb_close( &inputIsm->hReverb ); @@ -2374,7 +2382,11 @@ static void clearInputMc( efap_free_data( &inputMc->efapInWrapper.hEfap ); } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper != NULL ? inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif ivas_reverb_close( &inputMc->hReverb ); @@ -2670,7 +2682,11 @@ static void clearInputSba( initRendInputBase( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); /* Free input's internal handles */ +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputSba->crendWrapper, rendCtx.pSplitRendWrapper != NULL ? rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputSba->crendWrapper, rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif if ( inputSba->cldfbRendWrapper.hCldfbRend != NULL ) { @@ -7536,7 +7552,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - ( const int16_t ) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, @@ -7700,9 +7716,12 @@ void IVAS_REND_Close( /* Split binaural rendering */ #ifdef FIX_1135_EXT_RENDERER_HANDLES - ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); - free( hIvasRend->splitRendWrapper ); - hIvasRend->splitRendWrapper = NULL; + if ( hIvasRend->splitRendWrapper != NULL ) + { + ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); + free( hIvasRend->splitRendWrapper ); + hIvasRend->splitRendWrapper = NULL; + } #else ISAR_PRE_REND_close( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); #endif -- GitLab From f01f6b87ba436e1e3a242ef2256a7d934fcfffe0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 19:20:50 +0200 Subject: [PATCH 04/10] fix smoke test failures --- lib_rend/lib_rend.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index bc4a944e91..f04cfd8674 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2559,7 +2559,11 @@ static ivas_error updateSbaPanGains( } else { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, hMixconv, hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper != NULL ? rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, inConfig, outConfig, hRendCfg, hMixconv, hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -5244,7 +5248,11 @@ static ivas_error renderIsmToBinauralRoom( hCombinedOrientationData = ismInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -5858,7 +5866,11 @@ static ivas_error renderMcToBinaural( hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -5947,7 +5959,11 @@ static ivas_error renderMcToBinauralRoom( hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -6038,7 +6054,11 @@ static ivas_error renderMcCustomLsToBinauralRoom( hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -6644,7 +6664,11 @@ static ivas_error renderSbaToBinaural( hCombinedOrientationData = sbaInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -6721,7 +6745,11 @@ static ivas_error renderSbaToBinauralRoom( hCombinedOrientationData = sbaInput->base.ctx.pCombinedOrientationData; combinedOrientationEnabled = 0; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( *hCombinedOrientationData != NULL ) +#else if ( hCombinedOrientationData != NULL ) +#endif { for ( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { @@ -7552,7 +7580,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From 09b8e0b5afb47be8830388eade798d8e822a1945 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 19:24:37 +0200 Subject: [PATCH 05/10] memory optimization for ivas_HRTF_statistics_init() --- lib_rend/lib_rend.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f04cfd8674..68f53e4bbb 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3001,10 +3001,18 @@ ivas_error IVAS_REND_Open( return error; } } - if ( ( error = ivas_HRTF_statistics_init( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) + +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - return error; +#endif + if ( ( error = ivas_HRTF_statistics_init( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_1135_EXT_RENDERER_HANDLES } +#endif return IVAS_ERR_OK; } @@ -7580,7 +7588,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From b890dfb07b7d78cb52af7a152566bfbade044563 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 19:56:11 +0200 Subject: [PATCH 06/10] fixes --- lib_rend/lib_rend.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 68f53e4bbb..efd127562a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1380,7 +1380,11 @@ static ivas_error setRendInputActiveIsm( } else if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, hrtfs->hSetOfHRTF, hrtfs->hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper != NULL ? rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, hrtfs->hSetOfHRTF, hrtfs->hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2576,7 +2580,11 @@ static ivas_error updateSbaPanGains( return error; } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, hMixconv, hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper != NULL ? rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_rend_openCrend( &inputSba->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, hMixconv, hHrtfStatistics, *rendCtx.pOutSampleRate, rendCtx.pSplitRendWrapper->multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -4451,7 +4459,12 @@ int16_t IVAS_REND_FeedRenderConfig( int16_t cldfb_in_flag; cldfb_in_flag = getCldfbRendFlag( hIvasRend, IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN ); #ifdef FIX_1135_EXT_RENDERER_HANDLES - ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); + if ( hIvasRend->splitRendWrapper != NULL ) + { + ISAR_PRE_REND_close( hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); + free( hIvasRend->splitRendWrapper ); + hIvasRend->splitRendWrapper = NULL; + } #else ISAR_PRE_REND_close( &hIvasRend->splitRendWrapper, &hIvasRend->splitRendEncBuffer ); #endif -- GitLab From ee26668bc6dda9602dc35ebc9256b1206e77b59f Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 15 Jul 2024 20:07:38 +0200 Subject: [PATCH 07/10] fixes --- lib_rend/lib_rend.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index efd127562a..700e4a673d 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1276,7 +1276,11 @@ static ivas_error initIsmMasaRendering( ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputIsm->crendWrapper, inputIsm->base.ctx.pSplitRendWrapper != NULL ? inputIsm->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputIsm->crendWrapper, inputIsm->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif ivas_reverb_close( &inputIsm->hReverb ); @@ -2109,7 +2113,11 @@ static ivas_error initMcBinauralRendering( /* if we need to use TD renderer and CREND was open, close it */ if ( useTDRend ) { +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper != NULL ? inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif } if ( !reconfigureFlag || ( !useTDRend && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && inputMc->hReverb != NULL ) ) @@ -2201,7 +2209,11 @@ static ivas_error initMcMasaRendering( ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); } +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper != NULL ? inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif ivas_reverb_close( &inputMc->hReverb ); @@ -2616,7 +2628,11 @@ static ivas_error initSbaMasaRendering( { ivas_error error; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + ivas_rend_closeCrend( &inputSba->crendWrapper, inputSba->base.ctx.pSplitRendWrapper != NULL ? inputSba->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ); +#else ivas_rend_closeCrend( &inputSba->crendWrapper, inputSba->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses ); +#endif if ( ( error = ivas_dirac_ana_open( &inputSba->hDirAC, inSampleRate ) ) != IVAS_ERR_OK ) { -- GitLab From 87740adbf1fc1657008f2696074befc83cc35554 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 16 Jul 2024 08:08:19 +0200 Subject: [PATCH 08/10] fix --- lib_rend/lib_rend.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 700e4a673d..a7202af5b6 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -8437,6 +8437,9 @@ static ivas_error ivas_masa_ext_rend_parambin_init( int32_t output_Fs; RENDERER_TYPE renderer_type; int16_t j, k, bin; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + int16_t num_poses; +#endif float binCenterFreq, tmpFloat; ivas_error error; float frequency_axis[CLDFB_NO_CHANNELS_MAX]; @@ -8451,7 +8454,17 @@ static ivas_error ivas_masa_ext_rend_parambin_init( nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; renderer_type = inputMasa->hMasaExtRend->renderer_type; +#ifdef FIX_1135_EXT_RENDERER_HANDLES + num_poses = 1; + if ( inputMasa->base.ctx.pSplitRendWrapper != NULL ) + { + num_poses = inputMasa->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses; + } + + for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ ) +#else for ( pos_idx = 0; pos_idx < inputMasa->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses; pos_idx++ ) +#endif { hDiracDecBin = inputMasa->hMasaExtRend->hDiracDecBin[pos_idx]; -- GitLab From ed14d821e54aa33b80fe6a3f9713df12816fbf10 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 16 Jul 2024 08:31:38 +0200 Subject: [PATCH 09/10] fix MSAN error --- lib_rend/lib_rend.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a7202af5b6..57a6daea7a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2930,12 +2930,11 @@ ivas_error IVAS_REND_Open( } isar_init_split_rend_handles( hIvasRend->splitRendWrapper ); - hIvasRend->splitRendEncBuffer.data = NULL; } #else isar_init_split_rend_handles( &hIvasRend->splitRendWrapper ); - hIvasRend->splitRendEncBuffer.data = NULL; #endif + hIvasRend->splitRendEncBuffer.data = NULL; for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { @@ -7617,7 +7616,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From 6bc40b1d8df27e317b7dab759dde62d69494d67b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 16 Jul 2024 08:41:34 +0200 Subject: [PATCH 10/10] clang-format --- lib_rend/lib_rend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 57a6daea7a..eef12137ff 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7616,7 +7616,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab