diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 624494d24a3f11147f03ecb7c75c0c530d82a77f..74b79ef9a9d6b46ff93d6e5eab1aeb18ed73dc4f 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -282,6 +282,17 @@ void ivas_destroy_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef FIX_803_SCE_MD_HANDLE +ivas_error ivas_initialize_MD_bstr_enc( + BSTR_ENC_HANDLE *hBstr, /* o : encoder MD bitstream handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_destroy_MD_bstr_enc( + BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ +); +#endif + ivas_error ivas_init_decoder_front( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 53b519f7c67153973da0eb565f45cdb0e917a673..db4ab9dcdd1a425595566c79423219d10053669a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,6 +179,7 @@ #define FIX_676_JBM_USAN /* FhG: Issue 676: USAN in JBM */ #define FIX_796_MCT_MODE_DIFF_JBM /* FhG: Issue 796: fix differences between JBM and non-JBM fOR MC */ #define LIB_REND_FIX_HRTFPARAMBIN_MEMLEAK /* fix 755 */ +#define FIX_803_SCE_MD_HANDLE /* VA: issue 803: Resolve "MD handle needed only for one SCE" */ /* #################### End BE switches ################################## */ @@ -208,9 +209,9 @@ #define NONBE_FIX_588_UPDATE_FASTCONV_SD /* FhG: issue 588: update FastConv SD HRTFs in CLDFB domain with new conversion method */ #define NONBE_FIX_778_TNS_UNFIED_STEREO_MSAN /* FhG: Issue 778: MSAN error due to uninitialized TNS configuration */ #define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* VA: issue 797: fix of crash when the separated object is inactive and the MASA metadata is using very few bits */ - #define NONBE_FIX_798_OSBA_MC_DEC_CRASH + /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index c80e463ebaca4e4d32814eb255761514a7322881..5d13ee6e4c0fd04a28a99aaedbeddb20d5211b6b 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -280,6 +280,10 @@ ivas_error ivas_corecoder_enc_reconfig( copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = brate_SCE; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + +#ifdef FIX_803_SCE_MD_HANDLE + ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) ); +#endif } for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) @@ -301,6 +305,16 @@ ivas_error ivas_corecoder_enc_reconfig( reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_ind_tot ); } } + +#ifdef FIX_803_SCE_MD_HANDLE + if ( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL ) + { + if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif } if ( st_ivas->nCPE > 0 ) @@ -413,6 +427,7 @@ ivas_error ivas_corecoder_enc_reconfig( { mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); } + if ( st_ivas->nCPE ) { for ( n = 0; n < CPE_CHANNELS; n++ ) @@ -472,6 +487,12 @@ ivas_error ivas_corecoder_enc_reconfig( { if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) { +#ifdef FIX_803_SCE_MD_HANDLE + if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); @@ -484,17 +505,22 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot = 0; st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_bits_tot = 0; st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->st_ivas = st_ivas; +#endif } reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot ); for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) { +#ifdef FIX_803_SCE_MD_HANDLE + ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) ); +#else if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL ) { free( st_ivas->hCPE[cpe_id]->hMetaData ); st_ivas->hCPE[cpe_id]->hMetaData = NULL; } +#endif } } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 18a609ccd69a5fae9289255316d43c64ef4f8a39..9f21dec4ce1bafda89e84e1e74800005235c6f4b 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -877,11 +877,19 @@ ivas_error create_cpe_enc( * Metadata: allocate and initialize *-----------------------------------------------------------------*/ +#ifndef FIX_803_SCE_MD_HANDLE /* we need the meta data handle also if we init as MC_FORMAT/MCT since it might be needed at a bit rate switch to ParamMC or McMASA and the metadata index list is only really reachable in the ivas_init_encoder() function and has to be connected to the MD handle there */ +#endif if ( cpe_id == ( st_ivas->nCPE - 1 ) ) { +#ifdef FIX_803_SCE_MD_HANDLE + if ( ( error = ivas_initialize_MD_bstr_enc( &( hCPE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( hCPE->hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); @@ -893,6 +901,7 @@ ivas_error create_cpe_enc( hCPE->hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; hCPE->hMetaData->st_ivas = st_ivas; reset_indices_enc( hCPE->hMetaData, st_ivas->ivas_max_num_indices_metadata ); +#endif } /*-----------------------------------------------------------------* @@ -1085,11 +1094,15 @@ void destroy_cpe_enc( } } +#ifdef FIX_803_SCE_MD_HANDLE + ivas_destroy_MD_bstr_enc( &( hCPE->hMetaData ) ); +#else if ( hCPE->hMetaData != NULL ) { free( hCPE->hMetaData ); hCPE->hMetaData = NULL; } +#endif for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index c954e89bc3ee37845849696b6bb4d8e4947df222..adbabd4061c73936fe59791ccc17a50d8609a893 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1229,3 +1229,58 @@ void ivas_destroy_enc( return; } + +#ifdef FIX_803_SCE_MD_HANDLE +/*------------------------------------------------------------------------- + * ivas_initialize_MD_bstr_enc() + * + * Allocate and initialize SCE/CPE MD bitstream handle + *-------------------------------------------------------------------------*/ + +ivas_error ivas_initialize_MD_bstr_enc( + BSTR_ENC_HANDLE *hMetaData_out, /* o : encoder MD bitstream handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + BSTR_ENC_HANDLE hMetaData; + + if ( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); + } + + /* set pointer to the buffer of metadata indices */ + hMetaData->ind_list = st_ivas->ind_list_metadata; + hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; + hMetaData->st_ivas = st_ivas; + + reset_indices_enc( hMetaData, st_ivas->ivas_max_num_indices_metadata ); + + *hMetaData_out = hMetaData; + + return IVAS_ERR_OK; +} + + +/*------------------------------------------------------------------------- + * ivas_destroy_MD_bstr_enc() + * + * Destroy SCE/CPE MD bistream handle + *-------------------------------------------------------------------------*/ + +void ivas_destroy_MD_bstr_enc( + BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ +) +{ + if ( hMetaData == NULL || *hMetaData == NULL ) + { + return; + } + + free( *hMetaData ); + *hMetaData = NULL; + + return; +} +#endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 8567693244da9fec85017a01bbcc1230b637d781..abf0745d60953b572a30028f14b4703300e63d87 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -333,8 +333,18 @@ ivas_error create_sce_enc( * Metadata: allocate and initialize *-----------------------------------------------------------------*/ +#ifdef FIX_803_SCE_MD_HANDLE + if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == ( st_ivas->nSCE - 1 ) ) +#else if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT ) +#endif { +#ifdef FIX_803_SCE_MD_HANDLE + if ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( hSCE->hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); @@ -346,6 +356,7 @@ ivas_error create_sce_enc( hSCE->hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; hSCE->hMetaData->st_ivas = st_ivas; reset_indices_enc( hSCE->hMetaData, st_ivas->ivas_max_num_indices_metadata ); +#endif } else { @@ -408,11 +419,15 @@ void destroy_sce_enc( st = NULL; } +#ifdef FIX_803_SCE_MD_HANDLE + ivas_destroy_MD_bstr_enc( &( hSCE->hMetaData ) ); +#else if ( hSCE->hMetaData != NULL ) { free( hSCE->hMetaData ); hSCE->hMetaData = NULL; } +#endif free( hSCE );