From 94c829b20a864dd7404815c65c5ed249725ba1a6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 29 May 2023 11:54:37 +0200 Subject: [PATCH 1/2] add error codes to bitstream buffer functions --- lib_com/bitstream.c | 51 +++++++++++++++++++++++++++++++++++---------- lib_com/prot.h | 10 ++++++++- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index dcd1b71684..fde38e7533 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -899,16 +899,13 @@ int16_t get_ivas_max_num_indices_metadata( /* o * Move indices inside the buffer or among two buffers *-------------------------------------------------------------------*/ -ivas_error move_indices( +void move_indices( INDICE_HANDLE old_ind_list, /* i/o: old location of indices */ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */ const int16_t nb_indices /* i : number of moved indices */ ) { int16_t i; - ivas_error error; - - error = IVAS_ERR_OK; if ( new_ind_list < old_ind_list ) { @@ -933,7 +930,7 @@ ivas_error move_indices( } } - return error; + return; } #endif @@ -967,7 +964,10 @@ ivas_error check_ind_list_limits( #endif /* reallocate the buffer of indices with increased limit */ - ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ); + if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK ) + { + return error; + } } /* check, if we will not overwrite an existing indice */ @@ -994,7 +994,10 @@ ivas_error check_ind_list_limits( #endif /* no available empty slot -> need to re-allocate the buffer */ - ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ); + if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK ) + { + return error; + } } } else @@ -1072,7 +1075,10 @@ ivas_error push_indice( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ - error = check_ind_list_limits( hBstr ); + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice buffer writing failure (frame %d) !\n", frame ); + } #endif #ifdef IND_LIST_DYN @@ -1195,7 +1201,11 @@ ivas_error push_next_indice( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ - error = check_ind_list_limits( hBstr ); + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice buffer writing failure (frame %d) !\n", frame ); + } + #endif #ifdef IND_LIST_DYN @@ -1238,9 +1248,17 @@ ivas_error push_next_indice( *-------------------------------------------------------------------*/ #ifdef DEBUG_BS_READ_WRITE +#ifdef IND_LIST_DYN +ivas_error push_next_bits_( +#else void push_next_bits_( +#endif +#else +#ifdef IND_LIST_DYN +ivas_error push_next_bits( #else void push_next_bits( +#endif #endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const uint16_t bits[], /* i : bit buffer to pack, sequence of single bits */ @@ -1257,6 +1275,7 @@ void push_next_bits( Indice *ptr; #ifdef IND_LIST_DYN int16_t prev_id; + ivas_error error; #endif #ifdef DEBUG_BS_READ_WRITE printf( "%s: %d: %d\n", func, line, nb_bits ); @@ -1285,7 +1304,10 @@ void push_next_bits( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ - check_ind_list_limits( hBstr ); + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Indice buffer writing failure (frame %d) !\n", frame ); + } ptr = &hBstr->ind_list[hBstr->nb_ind_tot]; #endif @@ -1305,7 +1327,10 @@ void push_next_bits( { #ifdef IND_LIST_DYN /* check the limits of the list of indices */ - check_ind_list_limits( hBstr ); + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Indice buffer writing failure (frame %d) !\n", frame ); + } ptr = &hBstr->ind_list[hBstr->nb_ind_tot]; #endif @@ -1326,7 +1351,11 @@ void push_next_bits( #endif hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits; +#ifdef IND_LIST_DYN + return IVAS_ERR_OK; +#else return; +#endif } diff --git a/lib_com/prot.h b/lib_com/prot.h index e6f371c468..81c3d40857 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -505,9 +505,17 @@ ivas_error push_next_indice( #ifdef DEBUG_BS_READ_WRITE #define push_next_bits( ... ) push_next_bits_( __VA_ARGS__, __LINE__, __func__ ) +#ifdef IND_LIST_DYN +ivas)error push_next_bits_( +#else void push_next_bits_( +#endif +#else +#ifdef IND_LIST_DYN +ivas_error push_next_bits( #else void push_next_bits( +#endif #endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const uint16_t bits[], /* i : bit buffer to pack, sequence of single bits */ @@ -548,7 +556,7 @@ ivas_error check_ind_list_limits( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); -ivas_error move_indices( +void move_indices( INDICE_HANDLE old_ind_list, /* i/o: old location of indices */ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */ const int16_t nb_indices /* i : number of moved indices */ -- GitLab From 1d3f3e2c2629ca44d124577153db535c7267b5ff Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 29 May 2023 12:05:59 +0200 Subject: [PATCH 2/2] formatting --- lib_com/bitstream.c | 35 +++++++++++++++++-------------- lib_com/prot.h | 46 +++++++++++++++++++++++------------------ lib_enc/ivas_init_enc.c | 2 -- lib_enc/lib_enc.c | 17 +++++++-------- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index fde38e7533..b465efbe24 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -220,6 +220,7 @@ Word16 rate2EVSmode( return rate2AMRWB_IOmode( brate ); } + #ifdef IND_LIST_DYN /*-------------------------------------------------------------------* * ind_list_realloc() @@ -228,7 +229,7 @@ Word16 rate2EVSmode( *-------------------------------------------------------------------*/ ivas_error ind_list_realloc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t max_num_indices /* i : new maximum number of allowed indices in the list */ ) { @@ -281,9 +282,10 @@ ivas_error ind_list_realloc( * Get the maximum allowed number of indices in the encoder *-----------------------------------------------------------------------*/ -int16_t get_ivas_max_num_indices( /* o : maximum number of indices */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +/*! r: maximum number of indices */ +int16_t get_ivas_max_num_indices( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { if ( ivas_format == STEREO_FORMAT ) @@ -513,15 +515,17 @@ int16_t get_ivas_max_num_indices( /* o : maximum return 2450; } + /*-----------------------------------------------------------------------* * get_core_max_num_indices() * * Get the maximum allowed number of indices in the core coder *-----------------------------------------------------------------------*/ -int16_t get_core_max_num_indices( /* o : maximum number of indices */ - const int16_t core, /* i : core */ - const int32_t total_brate /* i : total bitrate */ +/*! r: maximum number of indices */ +int16_t get_core_max_num_indices( + const int16_t core, /* i : core */ + const int32_t total_brate /* i : total bitrate */ ) { /* set the maximum number of indices in the core coder */ @@ -694,8 +698,9 @@ int16_t get_core_max_num_indices( /* o : maximum numb * Get the maximum number of indices in the BWE *-----------------------------------------------------------------------*/ -int16_t get_BWE_max_num_indices( /* o : maximum number of indices */ - const int32_t extl_brate /* i : extensiona layer bitrate */ +/*! r: maximum number of indices */ +int16_t get_BWE_max_num_indices( + const int32_t extl_brate /* i : extensiona layer bitrate */ ) { /* set the maximum number of indices in the BWE */ @@ -716,9 +721,10 @@ int16_t get_BWE_max_num_indices( /* o : maximum number * Set the maximum allowed number of metadata indices in the list *-----------------------------------------------------------------------*/ -int16_t get_ivas_max_num_indices_metadata( /* o : maximum number of indices */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +/*! r: maximum number of indices */ +int16_t get_ivas_max_num_indices_metadata( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { /* set the maximum required number of metadata indices */ @@ -893,6 +899,7 @@ int16_t get_ivas_max_num_indices_metadata( /* o return 50; } + /*-------------------------------------------------------------------* * move_indices() * @@ -933,9 +940,7 @@ void move_indices( return; } -#endif -#ifdef IND_LIST_DYN /*-------------------------------------------------------------------* * check_ind_list_limits() * @@ -944,7 +949,7 @@ void move_indices( *-------------------------------------------------------------------*/ ivas_error check_ind_list_limits( - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { Indice *ivas_ind_list_zero, *ivas_ind_list_last; diff --git a/lib_com/prot.h b/lib_com/prot.h index 81c3d40857..124711393b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -528,27 +528,31 @@ void push_next_bits( ); #ifdef IND_LIST_DYN -int16_t get_ivas_max_num_indices( /* o : maximum number of indices */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +/*! r: maximum number of indices */ +int16_t get_ivas_max_num_indices( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); -int16_t get_core_max_num_indices( /* o : maximum number of indices */ - const int16_t core, /* i : core */ - const int32_t total_brate /* i : total bitrate */ +/*! r: maximum number of indices */ +int16_t get_core_max_num_indices( + const int16_t core, /* i : core */ + const int32_t total_brate /* i : total bitrate */ ); -int16_t get_BWE_max_num_indices( /* o : maximum number of indices */ - const int32_t extl_brate /* i : extensiona layer bitrate */ +/*! r: maximum number of indices */ +int16_t get_BWE_max_num_indices( + const int32_t extl_brate /* i : extensiona layer bitrate */ ); -int16_t get_ivas_max_num_indices_metadata( /* o : maximum number of indices for metadata */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +/*! r: maximum number of indices for metadata */ +int16_t get_ivas_max_num_indices_metadata( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); ivas_error ind_list_realloc( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t max_num_indices /* i : new maximum number of allowed indices in the list */ ); @@ -562,16 +566,18 @@ void move_indices( const int16_t nb_indices /* i : number of moved indices */ ); -int16_t find_indice( /* o : index of the indice in the list, -1 if not found */ - BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */ - int16_t id, /* i : ID of the indice */ - uint16_t *value, /* o : value of the quantized indice */ - int16_t *nb_bits /* o : number of bits used to quantize the indice */ +/*! r: index of the indice in the list, -1 if not found */ +int16_t find_indice( + BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */ + int16_t id, /* i : ID of the indice */ + uint16_t *value, /* o : value of the quantized indice */ + int16_t *nb_bits /* o : number of bits used to quantize the indice */ ); -uint16_t delete_indice( /* o : number of deleted indices */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - int16_t id /* i : ID of the indice */ +/*! r: number of deleted indices */ +uint16_t delete_indice( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + int16_t id /* i : ID of the indice */ ); #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index d964428352..845edfbe1f 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -329,8 +329,6 @@ ivas_error ivas_init_encoder( #ifndef IND_LIST_DYN , Indice ind_list[][MAX_NUM_INDICES] /* o : bitstream indices */ -#endif -#ifndef IND_LIST_DYN , Indice ind_list_metadata[][MAX_BITS_METADATA] /* o : bitstream indices metadata */ #endif diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 2e56f384ec..c2f03c38a7 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -51,9 +51,7 @@ struct IVAS_ENC { Encoder_Struct *st_ivas; #ifndef IND_LIST_DYN - Indice ind_list[MAX_NUM_DATA][MAX_NUM_INDICES]; /* list of indices */ -#endif -#ifndef IND_LIST_DYN + Indice ind_list[MAX_NUM_DATA][MAX_NUM_INDICES]; /* list of indices */ Indice ind_list_metadata[MAX_NUM_METADATA][MAX_BITS_METADATA]; /* list of indices for metadata */ #endif ENC_CORE_HANDLE hCoreCoder; @@ -139,11 +137,11 @@ ivas_error IVAS_ENC_Open( ( *phIvasEnc )->maxBandwidthUser = false; resetIsmMetadataProvidedFlags( *phIvasEnc ); +#ifndef IND_LIST_DYN /*-----------------------------------------------------------------* * Initialize indices *-----------------------------------------------------------------*/ -#ifndef IND_LIST_DYN for ( i = 0; i < MAX_NUM_DATA; ++i ) { for ( j = 0; j < MAX_NUM_INDICES; ++j ) @@ -152,9 +150,7 @@ ivas_error IVAS_ENC_Open( ( *phIvasEnc )->ind_list[i][j].value = 0; } } -#endif -#ifndef IND_LIST_DYN for ( i = 0; i < MAX_NUM_METADATA; ++i ) { for ( j = 0; j < MAX_BITS_METADATA; ++j ) @@ -928,10 +924,7 @@ static ivas_error configureEncoder( if ( ( error = ivas_init_encoder( st_ivas #ifndef IND_LIST_DYN , - hIvasEnc->ind_list -#endif -#ifndef IND_LIST_DYN - , + hIvasEnc->ind_list, hIvasEnc->ind_list_metadata #endif ) ) != IVAS_ERR_OK ) @@ -1226,6 +1219,10 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } } } + + /*-----------------------------------------------------------------* + * Encode one frame + *-----------------------------------------------------------------*/ #endif if ( hIvasEnc->switchingActive && hEncoderConfig->ivas_format == MONO_FORMAT ) -- GitLab