diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index c9571d41c16a95edb92e88f5e6b4b06825b8abf4..2321d37334d7d3f3591b08425dcd17f4147754f5 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -907,16 +907,22 @@ int16_t get_ivas_max_num_indices_metadata( /* o * Move indices inside the buffer or among two buffers *-------------------------------------------------------------------*/ +#ifdef FIX_545_ASSERT +void move_indices( +#else ivas_error move_indices( +#endif 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; +#ifndef FIX_545_ASSERT ivas_error error; error = IVAS_ERR_OK; +#endif if ( new_ind_list < old_ind_list ) { @@ -941,7 +947,11 @@ ivas_error move_indices( } } +#ifdef FIX_545_ASSERT + return; +#else return error; +#endif } #endif @@ -969,13 +979,24 @@ ivas_error check_ind_list_limits( if ( ( &hBstr->ind_list[hBstr->nb_ind_tot] - ivas_ind_list_zero ) >= *( hBstr->ivas_max_num_indices ) ) { #ifdef DEBUGGING +#ifdef FIX_545_ASSERT + fprintf( stderr, "Warning: The maximum number of indices %d has been exceeded in frame %d! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata().\n", *( hBstr->ivas_max_num_indices ), frame ); +#else /* TODO: replace with the warning message below before the finalization of the IVAS codec */ /* fprintf( stderr, "Warning: The maximum number of indices %d has been exceeded in frame %d! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata().\n", *( hBstr->ivas_max_num_indices ), frame ); */ assert( 0 && "The maximum number of indices has been exceeded! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata()." ); +#endif #endif /* reallocate the buffer of indices with increased limit */ +#ifdef FIX_545_ASSERT + if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK ) + { + return error; + } +#else ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ); +#endif } /* check, if we will not overwrite an existing indice */ @@ -996,13 +1017,24 @@ ivas_error check_ind_list_limits( if ( hBstr->ind_list >= ivas_ind_list_last ) { #ifdef DEBUGGING +#ifdef FIX_545_ASSERT + fprintf( stderr, "Warning: The maximum number of indices %d has been exceeded in frame %d! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata().\n", *( hBstr->ivas_max_num_indices ), frame ); +#else /* TODO: replace with the warning message below before the finalization of the IVAS codec */ /* fprintf( stderr, "Warning: The maximum number of indices %d has been exceeded in frame %d! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata().\n", *( hBstr->ivas_max_num_indices ), frame ); */ assert( 0 && "The maximum number of indices has been exceeded! Increase the limits in get_ivas_max_num_indices() or get_max_num_indices_metadata()." ); +#endif #endif /* no available empty slot -> need to re-allocate the buffer */ +#ifdef FIX_545_ASSERT + if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK ) + { + return error; + } +#else ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ); +#endif } } else @@ -1080,8 +1112,15 @@ ivas_error push_indice( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ +#ifdef FIX_545_ASSERT + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n", frame ); + } +#else error = check_ind_list_limits( hBstr ); #endif +#endif #ifdef IND_LIST_DYN /* find the location in the list of indices based on ID */ @@ -1203,8 +1242,15 @@ ivas_error push_next_indice( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ +#ifdef FIX_545_ASSERT + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return error; + } +#else error = check_ind_list_limits( hBstr ); #endif +#endif #ifdef IND_LIST_DYN /* get the id of the previous indice -> it will be re-used */ @@ -1246,9 +1292,17 @@ ivas_error push_next_indice( *-------------------------------------------------------------------*/ #ifdef DEBUG_BS_READ_WRITE +#ifdef FIX_545_ASSERT +ivas_error push_next_bits_( +#else void push_next_bits_( +#endif +#else +#ifdef FIX_545_ASSERT +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 */ @@ -1265,6 +1319,11 @@ void push_next_bits( Indice *ptr; #ifdef IND_LIST_DYN int16_t prev_id; +#ifdef FIX_545_ASSERT + ivas_error error; + + error = IVAS_ERR_OK; +#endif #endif #ifdef DEBUG_BS_READ_WRITE printf( "%s: %d: %d\n", func, line, nb_bits ); @@ -1293,7 +1352,14 @@ void push_next_bits( #ifdef IND_LIST_DYN /* check the limits of the list of indices */ +#ifdef FIX_545_ASSERT + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame ); + } +#else check_ind_list_limits( hBstr ); +#endif ptr = &hBstr->ind_list[hBstr->nb_ind_tot]; #endif @@ -1313,7 +1379,14 @@ void push_next_bits( { #ifdef IND_LIST_DYN /* check the limits of the list of indices */ +#ifdef FIX_545_ASSERT + if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame ); + } +#else check_ind_list_limits( hBstr ); +#endif ptr = &hBstr->ind_list[hBstr->nb_ind_tot]; #endif @@ -1334,7 +1407,11 @@ void push_next_bits( #endif hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits; +#ifdef FIX_545_ASSERT + return error; +#else return; +#endif } @@ -1535,10 +1612,12 @@ uint16_t get_indice( { uint16_t value; int16_t i; + int32_t nbits_total; assert( nb_bits <= 16 ); - int32_t nbits_total; + nbits_total = st->total_brate / FRAMES_PER_SEC; + /* detect corrupted bitstream */ if ( pos + nb_bits > nbits_total ) { diff --git a/lib_com/options.h b/lib_com/options.h index 8a491e2499bd71b273c0b4360859c8629157da06..fabf8f14c3b2a543d3eca54aa44075a6997f2415 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -228,6 +228,9 @@ #define FIX_510 /* FhG: fix issue 510, misleading error message for invalid input format */ #define FIX_509 /* FhG: fix issue 509, too low number of bitsream indices in SBA */ #define FIX_519_JBM_ACCESS_NULL_TC_BUFFER /* FhG: fix issue 519, accessing a yet uninitialized TC Buffer in frame 0*/ +#ifdef IND_LIST_DYN +#define FIX_545_ASSERT /* VA: fix issue 545, replace assert() with warning message when hitting memory limit in the buffer of indices */ +#endif #define FIX_TODO_NON_DIEGETIC_PAN_NOT_IMPLELENTED_IN_RENDERER /* ..\apps\renderer.c(240): .... (todo: implementation)",*/ #define REMOVE_OBS_CODE /* FhG: Remove unnecessary assignement after LFE cleanup (Issue #451)*/ diff --git a/lib_com/prot.h b/lib_com/prot.h index e6f371c468148a17d0d23a7be80ee575ed20a52a..23c3b98756812ba7eefcb07b814ff6f85a35d448 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 FIX_545_ASSERT +ivas_error push_next_bits_( +#else void push_next_bits_( +#endif +#else +#ifdef FIX_545_ASSERT +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,11 @@ ivas_error check_ind_list_limits( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); +#ifdef FIX_545_ASSERT +void move_indices( +#else ivas_error move_indices( +#endif 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 */ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 006fb176fb401fbdfaaeb77f8cb0746d03983a4b..5591b12f40c96ff715a073209ec6f12f2dc16d77 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 37c3e57ab5c31a317b1223714d9b17e98e1b09b6..bc71f62ece8b92c4858537c20f7898c1fdf7cd8b 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; @@ -940,10 +938,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 )