From fd36eaba975f9999be19bcf97bcdb83853c5adfe Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 18 Sep 2023 18:04:09 +0200 Subject: [PATCH 1/4] issue 803: Resolve "MD handle needed only for one SCE"; under FIX_803_SCE_MD_HANDLE --- lib_com/ivas_prot.h | 11 ++++++ lib_com/options.h | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 25 ++++++++++++ lib_enc/ivas_cpe_enc.c | 13 +++++++ lib_enc/ivas_init_enc.c | 55 +++++++++++++++++++++++++++ lib_enc/ivas_sce_enc.c | 15 ++++++++ 6 files changed, 120 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 328f19c2c3..a3386c0e04 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 1a5f05080f..1ee862e92f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -173,7 +173,7 @@ #define FIX_764_HARM_CODE /* VA: issue 764: introduce new function for the same code block at four different places */ #define FIX_747_ISM_TODOS /* VA: issue 747 - address ISM ToDos */ #define FIX_ISMRENDERER_HANDLE_DEALLOC /* VA: issue 781: harmonize Deallocation of handle 'hIsmRendererData' */ - +#define FIX_803_SCE_MD_HANDLE /* VA: issue 803: Resolve "MD handle needed only for one SCE" */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index d6424bf959..52d9b77b31 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -279,6 +279,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++ ) @@ -305,6 +309,16 @@ ivas_error ivas_corecoder_enc_reconfig( { } } + +#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 ) @@ -490,6 +504,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" ) ); @@ -502,17 +522,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 e3362d816a..61b38701b1 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -882,11 +882,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" ) ); @@ -898,6 +906,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 } /*-----------------------------------------------------------------* @@ -1091,11 +1100,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 4a870d5977..06c963b24c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1222,3 +1222,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 e297d747a8..30fbcd8611 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 { @@ -409,11 +420,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 ); -- GitLab From df362eb77aab09c46172e0e144672c3b931566d5 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 19 Sep 2023 09:45:16 +0200 Subject: [PATCH 2/4] fix incorrect sequence of checks against a NULL pointer --- lib_enc/ivas_init_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 06c963b24c..29a422d5da 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1266,7 +1266,7 @@ void ivas_destroy_MD_bstr_enc( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ) { - if ( *hMetaData == NULL || hMetaData == NULL ) + if ( hMetaData == NULL || *hMetaData == NULL ) { return; } -- GitLab From b76fd485defa531d8dc46f16a25ccf287c12d339 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 19 Sep 2023 09:54:02 +0200 Subject: [PATCH 3/4] remove empty else block --- lib_enc/ivas_corecoder_enc_reconfig.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 52d9b77b31..1c4abd9568 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -305,9 +305,11 @@ 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 ); } +#ifndef FIX_803_SCE_MD_HANDLE else { } +#endif } #ifdef FIX_803_SCE_MD_HANDLE -- GitLab From 319fc4527cfdb978ff8f168d05a45fac955bd162 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 19 Sep 2023 09:56:40 +0200 Subject: [PATCH 4/4] remove more empty else blocks --- lib_enc/ivas_corecoder_enc_reconfig.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 1c4abd9568..7e4ef9ece3 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -344,9 +344,11 @@ ivas_error ivas_corecoder_enc_reconfig( reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); } +#ifndef FIX_803_SCE_MD_HANDLE else { } +#endif } } @@ -379,9 +381,11 @@ ivas_error ivas_corecoder_enc_reconfig( reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); } +#ifndef FIX_803_SCE_MD_HANDLE else { } +#endif if ( hEncoderConfig->Opt_DTX_ON ) { -- GitLab