diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index dcd1b71684cdef22049e8a112685bb52dab24e4f..b465efbe24d7c83a2e6d321e8fd3209bbe0389ff 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,22 +899,20 @@ int16_t get_ivas_max_num_indices_metadata( /* o return 50; } + /*-------------------------------------------------------------------* * move_indices() * * 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,12 +937,10 @@ ivas_error move_indices( } } - return error; + return; } -#endif -#ifdef IND_LIST_DYN /*-------------------------------------------------------------------* * check_ind_list_limits() * @@ -947,7 +949,7 @@ ivas_error 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; @@ -967,7 +969,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 +999,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 +1080,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 +1206,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 +1253,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 +1280,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 +1309,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 +1332,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 +1356,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 e6f371c468148a17d0d23a7be80ee575ed20a52a..124711393b4cd2faf5d7a2730225d13226bc1013 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 */ @@ -520,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 */ ); @@ -548,22 +560,24 @@ 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 */ ); -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 d96442835275a54e21750d0efe088cfbc99c62a6..845edfbe1fae8347478bc6dd96da965267c38f7b 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 2e56f384ecdd454a487230261a65c53636a620ae..c2f03c38a716ef14902b1a88ff8faf926608efe4 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 )