Commit f2fe22b1 authored by malenov's avatar malenov
Browse files

cleanup (removal of DEBUG_IND_LIST)

insert safety mechanism for ind_list reallocation also in push_next_indice() and push_next_bits()
parent f8fafc17
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -47,12 +47,6 @@

#define WMC_TOOL_SKIP

#ifdef DEBUG_IND_LIST
extern int16_t max_total_num_ind;
extern int16_t max_total_num_ind_metadata;
extern int32_t max_at_brate;
#endif

/*------------------------------------------------------------------------------------------*
 * Local constants, enums, structures
 *------------------------------------------------------------------------------------------*/
@@ -804,12 +798,6 @@ int main(
    print_snr();
#endif

#ifdef DEBUG_IND_LIST
    printf( "\nMaximum total number of indices: %d at bitrate: %d\n", max_total_num_ind, max_at_brate );
    printf( "\nMaximum total number of indices for metadata: %d\n", max_total_num_ind_metadata );
#endif


    /*------------------------------------------------------------------------------------------*
     * Close files and deallocate resources
     *------------------------------------------------------------------------------------------*/
+47 −57
Original line number Diff line number Diff line
@@ -66,12 +66,6 @@ FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */
#define STEP_MAX_NUM_INDICES 20     /* increase the maximum number of allowed indices in the list by this amount */
#endif

#ifdef DEBUG_IND_LIST
int16_t max_total_num_ind = 0;
int16_t max_total_num_ind_metadata = 0;
int32_t max_at_brate;
#endif

#ifndef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * pack_bit()
@@ -602,9 +596,6 @@ ivas_error push_indice(
    /* shift indices, if the new id is to be written somewhere inside the list */
    if ( i < hBstr->nb_ind_tot )
    {
#ifdef DEBUG_IND_LIST_OUT_OF_ORDER
        printf( "Indice ID=%d is written before the last indice with ID=%d!\n", id, hBstr->ind_list[hBstr->nb_ind_tot - 1].id );
#endif
        for ( j = hBstr->nb_ind_tot; j > i; j-- )
        {
            hBstr->ind_list[j].id = hBstr->ind_list[j - 1].id;
@@ -648,9 +639,6 @@ ivas_error push_indice(
    /* updates */
#ifdef IND_LIST_DYN
    hBstr->nb_ind_tot++;
#ifdef DEBUG_IND_LIST
    assert( (hBstr->nb_ind_tot < hBstr->max_num_indices) && "Maximum number of indices has been exceeded!" );
#endif
#else
    hBstr->next_ind = i + 1;
    hBstr->last_ind = id;
@@ -707,9 +695,7 @@ ivas_error push_next_indice(
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Total number of indices exceeded: %d !\n", MAX_NUM_INDICES );
    }
#endif

#ifndef IND_LIST_DYN
    if ( hBstr->ind_list[hBstr->next_ind].nb_bits > 0 )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice with value %d is trying to re-write an existing indice (frame %d) !\n", value, frame );
@@ -717,6 +703,22 @@ ivas_error push_next_indice(
#endif
#endif

#ifdef IND_LIST_DYN
    /* check, if the maximum number of indices has been reached and re-allocate the buffer */
    /* the re-allocation can be avoided by increasing the limits in get_max_num_indices() and get_max_num_indices_metadata() */
    if ( hBstr->nb_ind_tot >= hBstr->max_num_indices )
    {
#ifdef DEBUGGING
        DEBUG_LINE( 1 )
        printf( "Warning: Maximum number of indices %d has been exceeded (frame %d)! Increase the limits in get_max_num_indices() or get_max_num_indices_metadata().\n", hBstr->max_num_indices, frame );
#endif

        /* reallocate the buffer of indices with increased limit */
        ind_list_realloc( hBstr, hBstr->nb_ind_tot + STEP_MAX_NUM_INDICES );
    }
#endif


#ifdef IND_LIST_DYN
    /* get the id of the previous indice -> it will be re-used */
    if ( hBstr->nb_ind_tot > 0 )
@@ -742,14 +744,9 @@ ivas_error push_next_indice(
    /* updates */
#ifdef IND_LIST_DYN
    hBstr->nb_ind_tot++;
#ifdef DEBUG_IND_LIST
    assert( ( hBstr->nb_ind_tot < hBstr->max_num_indices ) && "Maximum number of indices has been exceeded!" );
#endif

#else
    hBstr->next_ind++;
#endif

    hBstr->nb_bits_tot += nb_bits;

    return error;
@@ -785,6 +782,7 @@ void push_next_bits(
#ifdef DEBUG_BS_READ_WRITE
    printf( "%s: %d: %d\n", func, line, nb_bits );
#endif

#ifdef IND_LIST_DYN
    ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

@@ -814,12 +812,24 @@ void push_next_bits(
#ifdef IND_LIST_DYN
        ptr->id = prev_id;
        hBstr->nb_ind_tot++;
#ifdef DEBUG_IND_LIST
        assert( ( hBstr->nb_ind_tot < hBstr->max_num_indices ) && "Maximum number of indices has been exceeded!" );
#endif

#ifdef IND_LIST_DYN
        /* check, if the maximum number of indices has been reached and re-allocate the buffer */
        /* the re-allocation can be avoided by increasing the limits in get_max_num_indices() and get_max_num_indices_metadata() */
        if ( hBstr->nb_ind_tot >= hBstr->max_num_indices )
        {
#ifdef DEBUGGING
            DEBUG_LINE( 1 )
            printf( "Warning: Maximum number of indices %d has been exceeded (frame %d)! Increase the limits in get_max_num_indices() or get_max_num_indices_metadata().\n", hBstr->max_num_indices, frame );
#endif
        ++ptr;

            /* reallocate the buffer of indices with increased limit */
            ind_list_realloc( hBstr, hBstr->nb_ind_tot + STEP_MAX_NUM_INDICES );
        }
#endif

        ++ptr;
    }

    for ( ; i < nb_bits; ++i )
@@ -832,12 +842,24 @@ void push_next_bits(
#ifdef IND_LIST_DYN
        ptr->id = prev_id;
        hBstr->nb_ind_tot++;
#ifdef DEBUG_IND_LIST
        assert( ( hBstr->nb_ind_tot < hBstr->max_num_indices ) && "Maximum number of indices has been exceeded!" );
#endif

#ifdef IND_LIST_DYN
        /* check, if the maximum number of indices has been reached and re-allocate the buffer */
        /* the re-allocation can be avoided by increasing the limits in get_max_num_indices() and get_max_num_indices_metadata() */
        if ( hBstr->nb_ind_tot >= hBstr->max_num_indices )
        {
#ifdef DEBUGGING
            DEBUG_LINE( 1 )
            printf( "Warning: Maximum number of indices %d has been exceeded (frame %d)! Increase the limits in get_max_num_indices() or get_max_num_indices_metadata().\n", hBstr->max_num_indices, frame );
#endif

            /* reallocate the buffer of indices with increased limit */
            ind_list_realloc( hBstr, hBstr->nb_ind_tot + STEP_MAX_NUM_INDICES );
        }
#endif
        ++ptr;

        ++ptr;
    }

#ifndef IND_LIST_DYN
@@ -1416,13 +1438,6 @@ static ivas_error write_indices_element(
    {
        if ( st_ivas->hSCE[element_id]->hMetaData != NULL )
        {
#ifdef DEBUG_IND_LIST
            /* find the maximum number of metadata indices */
            if ( st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot > max_total_num_ind_metadata )
            {
                max_total_num_ind_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot;
            }
#endif
#ifdef IND_LIST_DYN
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->max_num_indices );
#else
@@ -1430,15 +1445,6 @@ static ivas_error write_indices_element(
#endif
        }

#ifdef DEBUG_IND_LIST
        /* find the maximum number of core-coder indices */
        if ( sts[0]->hBstr->nb_ind_tot > max_total_num_ind )
        {
            max_total_num_ind = sts[0]->hBstr->nb_ind_tot;
            max_at_brate = sts[0]->total_brate;
        }
#endif

        reset_indices_enc( sts[0]->hBstr,
#ifdef IND_LIST_DYN
            sts[0]->hBstr->max_num_indices
@@ -1451,13 +1457,6 @@ static ivas_error write_indices_element(
    {
        if ( st_ivas->hCPE[element_id]->hMetaData != NULL )
        {
#ifdef DEBUG_IND_LIST
            /* find the maximum number of metadata indices */
            if ( st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot > max_total_num_ind_metadata )
            {
                max_total_num_ind_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot;
            }
#endif
#ifdef IND_LIST_DYN
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->max_num_indices );
#else
@@ -1467,15 +1466,6 @@ static ivas_error write_indices_element(

        for ( n = 0; n < n_channels; n++ )
        {
#ifdef DEBUG_IND_LIST
            /* find the maximum number of core-coder indices */
            if ( sts[n]->hBstr->nb_ind_tot > max_total_num_ind )
            {
                max_total_num_ind = sts[n]->hBstr->nb_ind_tot;
                max_at_brate = sts[0]->total_brate;
            }
#endif

            reset_indices_enc( sts[n]->hBstr, 
#ifdef IND_LIST_DYN
                               sts[n]->hBstr->max_num_indices