Commit 064d3e8b authored by malenov's avatar malenov
Browse files

Removal of obsolete parameter hBstr->last_ind -> replaced by hBstr->nb_ind_tot

parent d1cadd34
Loading
Loading
Loading
Loading
+96 −90
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@
FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */
#endif

#ifdef IND_LIST_DYN
#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;
@@ -226,24 +230,17 @@ Word16 rate2EVSmode(
/*-------------------------------------------------------------------*
 * ind_list_realloc()
 *
 * Re-allocate list of indices if the maximum number of allowed indices has changed
 * Re-allocate the list of indices as the maximum number of allowed indices has changed
 *-------------------------------------------------------------------*/

ivas_error ind_list_realloc(
    BSTR_ENC_HANDLE hBstr,         /* i/o: encoder bitstream handle  */
    const IVAS_FORMAT ivas_format, /* i  : IVAS format               */
    const int32_t total_brate      /* i  : total bitrate             */
    int16_t max_num_indices        /* i  : new maximum number of allowed indices in the list */
)
{
    int16_t i, max_num_indices;
    int16_t i;
    INDICE_HANDLE new_ind_list;

    /* get the maximum allowed number of indices in the list */
    max_num_indices = get_max_num_indices( ivas_format, total_brate );

    /* check, if the maximum number of allowed indices has changed */
    if ( max_num_indices != hBstr->max_num_indices )
    {
    /* allocate new buffer of indices */
    if ( ( new_ind_list = (INDICE_HANDLE) malloc( max_num_indices * sizeof( Indice ) ) ) == NULL )
    {
@@ -274,7 +271,6 @@ ivas_error ind_list_realloc(

    /* set the new maximum for the allowed number of indices */
    hBstr->max_num_indices = max_num_indices;
    }

    return IVAS_ERR_OK;
}
@@ -285,58 +281,59 @@ ivas_error ind_list_realloc(
 * Re-allocate list of metadata indices if the IVAS total bitrate has changed
 *-------------------------------------------------------------------*/

ivas_error ind_list_metadata_realloc(
    BSTR_ENC_HANDLE hMetaData,          /* i/o: encoder bitstream handle  */
    const IVAS_FORMAT ivas_format,      /* i  : IVAS format               */
    const int32_t ivas_total_brate      /* i  : IVAS total bitrate        */
)
{
    int16_t i, max_num_indices_metadata;
    INDICE_HANDLE new_ind_list_metadata;

    if ( hMetaData != NULL && hMetaData->ind_list != NULL )
    {
        /* get the maximum allowed number of indices in the list */
        max_num_indices_metadata = get_max_num_indices_metadata( ivas_format, ivas_total_brate );

        /* check, if the maximum number of allowed indices has changed */
        if ( max_num_indices_metadata != hMetaData->max_num_indices )
        {
            /* allocate new buffer of metadata indices */
            if ( ( new_ind_list_metadata = (INDICE_HANDLE) malloc( max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
            }

            /* move indices from the old list to the new list */
            i = 0;
            while ( hMetaData->ind_list[i].nb_bits > 0 )
            {
                new_ind_list_metadata[i].id = hMetaData->ind_list[i].id;
                new_ind_list_metadata[i].value = hMetaData->ind_list[i].value;
                new_ind_list_metadata[i].nb_bits = hMetaData->ind_list[i].nb_bits;
                i++;
            }

            /* reset nb_bits of all other indices to -1 */
            for ( ; i < max_num_indices_metadata; i++ )
            {
                new_ind_list_metadata[i].nb_bits = -1;
            }

            /* free the old list */
            free( hMetaData->ind_list );

            /* set pointer to the new list */
            hMetaData->ind_list = new_ind_list_metadata;

            /* set the new maximum for the allowed number of indices */
            hMetaData->max_num_indices = max_num_indices_metadata;
        }
    }
//ivas_error ind_list_metadata_realloc(
//    BSTR_ENC_HANDLE hMetaData,          /* i/o: encoder bitstream handle  */
//    const IVAS_FORMAT ivas_format,      /* i  : IVAS format               */
//    const int32_t ivas_total_brate      /* i  : IVAS total bitrate        */
//)
//{
//    int16_t i, max_num_indices_metadata;
//    INDICE_HANDLE new_ind_list_metadata;
//
//    if ( hMetaData != NULL && hMetaData->ind_list != NULL )
//    {
//        /* get the maximum allowed number of indices in the list */
//        max_num_indices_metadata = get_max_num_indices_metadata( ivas_format, ivas_total_brate );
//
//        /* check, if the maximum number of allowed indices has changed */
//        if ( max_num_indices_metadata != hMetaData->max_num_indices )
//        {
//            /* allocate new buffer of metadata indices */
//            if ( ( new_ind_list_metadata = (INDICE_HANDLE) malloc( max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
//            {
//                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
//            }
//
//            /* move indices from the old list to the new list */
//            i = 0;
//            while ( hMetaData->ind_list[i].nb_bits > 0 )
//            {
//                new_ind_list_metadata[i].id = hMetaData->ind_list[i].id;
//                new_ind_list_metadata[i].value = hMetaData->ind_list[i].value;
//                new_ind_list_metadata[i].nb_bits = hMetaData->ind_list[i].nb_bits;
//                i++;
//            }
//
//            /* reset nb_bits of all other indices to -1 */
//            for ( ; i < max_num_indices_metadata; i++ )
//            {
//                new_ind_list_metadata[i].nb_bits = -1;
//            }
//
//            /* free the old list */
//            free( hMetaData->ind_list );
//
//            /* set pointer to the new list */
//            hMetaData->ind_list = new_ind_list_metadata;
//
//            /* set the new maximum for the allowed number of indices */
//            hMetaData->max_num_indices = max_num_indices_metadata;
//        }
//    }
//
//    return IVAS_ERR_OK;
//}

    return IVAS_ERR_OK;
}
/*-----------------------------------------------------------------------*
 * get_max_num_indices()
 *
@@ -577,14 +574,21 @@ ivas_error push_indice(
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice ID = %d exceeds the total number of indices: %d (frame %d) !\n", id, MAX_NUM_INDICES, frame );
    }
#endif
#endif

#ifdef IND_LIST_DYN
    /* check, if max number of indices has not been exceeded */
    /* 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 )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Maximum number of indices %d has been exceeded (frame %d) !\n", hBstr->max_num_indices, frame );
    }
#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
@@ -649,8 +653,8 @@ ivas_error push_indice(
#endif
#else
    hBstr->next_ind = i + 1;
#endif
    hBstr->last_ind = id;
#endif
    hBstr->nb_bits_tot += nb_bits;

    return error;
@@ -1146,7 +1150,9 @@ void reset_indices_enc(
#else
    hBstr->next_ind = 0;
#endif
#ifndef IND_LIST_DYN
    hBstr->last_ind = -1;
#endif

    for ( i = 0; i < max_num_indices; i++ )
    {
+2 −0
Original line number Diff line number Diff line
@@ -2944,7 +2944,9 @@ void ivas_qmetadata_close(
void restore_metadata_buffer(
    BSTR_ENC_HANDLE hMetaData,
    const int16_t next_ind_start,
#ifndef IND_LIST_DYN
    const int16_t last_ind_start,
#endif
    const int16_t bit_pos_start 
);

+13 −2
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@ ivas_error ivas_core_enc(
    int16_t last_element_mode, tdm_Pitch_reuse_flag;
    int32_t element_brate, last_element_brate, input_Fs;
    ivas_error error;
#ifdef IND_LIST_DYN
    int16_t max_num_indices;
#endif

    push_wmops( "ivas_core_enc" );

@@ -197,10 +200,18 @@ ivas_error ivas_core_enc(

#ifdef IND_LIST_DYN
        /*---------------------------------------------------------------------*
         * Re-allocate list of indices, if needed
         * Re-allocate the list of indices, if needed
         *---------------------------------------------------------------------*/

        ind_list_realloc( st->hBstr, ivas_format, st->total_brate );
        /* get the maximum allowed number of indices in the list */
        max_num_indices = get_max_num_indices( ivas_format, st->total_brate );

        /* check, if the maximum number of allowed indices has changed */
        if ( max_num_indices != st->hBstr->max_num_indices )
        {
            /* re-allocate the list of indices */
            ind_list_realloc( st->hBstr, max_num_indices );
        }
#endif

        /*---------------------------------------------------------------------*
+32 −13
Original line number Diff line number Diff line
@@ -70,11 +70,12 @@ ivas_error ivas_corecoder_enc_reconfig(
    BSTR_ENC_HANDLE hMetaData;
#endif
#ifdef IND_LIST_DYN
    int16_t i, nb_bits;
    int16_t i, nb_bits, max_num_indices_metadata;
    Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST];
#endif
    int16_t nb_bits_tot, last_ind;
    int16_t nb_bits_tot;
#ifndef IND_LIST_DYN
    int16_t last_ind;
    int16_t next_ind;
#endif
    ENCODER_CONFIG_HANDLE hEncoderConfig;
@@ -105,8 +106,18 @@ ivas_error ivas_corecoder_enc_reconfig(
            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 IND_LIST_DYN
            /* re-allocate list of metadata indices, if needed */
            ind_list_metadata_realloc( st_ivas->hSCE[sce_id]->hMetaData, hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );
            if ( st_ivas->hSCE[sce_id]->hMetaData != NULL )
            {
                /* get the maximum allowed number of indices in the list */
                max_num_indices_metadata = get_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );

                /* check, if the maximum number of allowed indices has changed */
                if ( max_num_indices_metadata != st_ivas->hSCE[sce_id]->hMetaData->max_num_indices )
                {
                    /* re-allocate the list of metadata indices */
                    ind_list_realloc( st_ivas->hSCE[sce_id]->hMetaData, max_num_indices_metadata );
                }
            }
#endif
        }

@@ -121,8 +132,18 @@ ivas_error ivas_corecoder_enc_reconfig(
                st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
            }
#ifdef IND_LIST_DYN
            /* re-allocate list of metadata indices, if needed */
            ind_list_metadata_realloc( st_ivas->hCPE[cpe_id]->hMetaData, hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );
            if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL )
            {
                /* get the maximum allowed number of indices in the list */
                max_num_indices_metadata = get_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );

                /* check, if the maximum number of allowed indices has changed */
                if ( max_num_indices_metadata != st_ivas->hCPE[cpe_id]->hMetaData->max_num_indices )
                {
                    /* re-allocate the list of metadata indices */
                    ind_list_realloc( st_ivas->hCPE[cpe_id]->hMetaData, max_num_indices_metadata );
                }
            }
#endif
        }

@@ -183,14 +204,12 @@ ivas_error ivas_corecoder_enc_reconfig(
#endif

        /* save bitstream information */
#ifndef IND_LIST_DYN
        ind_list = hBstr->ind_list; /* pointer to the beginning of the global list */
#endif
        nb_bits_tot = hBstr->nb_bits_tot;
#ifndef IND_LIST_DYN
        ind_list = hBstr->ind_list; /* pointer to the beginning of the global list */
        next_ind = hBstr->next_ind;
#endif
        last_ind = hBstr->last_ind;
#endif
#ifdef IND_LIST_DYN
        i = 0;
        nb_bits = 0;
@@ -333,9 +352,9 @@ ivas_error ivas_corecoder_enc_reconfig(
                }
                else
                {
                    st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind;
                    st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
#ifndef IND_LIST_DYN
                    st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind;
                    st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind;
#endif
#ifdef IND_LIST_DYN
@@ -397,9 +416,9 @@ ivas_error ivas_corecoder_enc_reconfig(
                    }
                    else
                    {
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot;
#ifndef IND_LIST_DYN
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind;
#endif
#ifdef IND_LIST_DYN
@@ -465,9 +484,9 @@ ivas_error ivas_corecoder_enc_reconfig(
                    }
                    else
                    {
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot;
#ifndef IND_LIST_DYN
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
                        st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind;
#endif
#ifdef IND_LIST_DYN
+27 −4
Original line number Diff line number Diff line
@@ -1678,6 +1678,9 @@ void ivas_masa_enc_reconfigure(
    int16_t n, tmp;
    int16_t sce_id, cpe_id;
    int32_t ivas_total_brate;
#ifdef IND_LIST_DYN
    int16_t max_num_indices_metadata;
#endif

    ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;

@@ -1690,8 +1693,18 @@ void ivas_masa_enc_reconfigure(
            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 IND_LIST_DYN
            /* re-allocate list of metadata indices, if needed */
            ind_list_metadata_realloc( st_ivas->hSCE[sce_id]->hMetaData, st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );
            if ( st_ivas->hSCE[sce_id]->hMetaData != NULL )
            {
                /* get the maximum allowed number of indices in the list */
                max_num_indices_metadata = get_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );

                /* check, if the maximum number of allowed indices has changed */
                if ( max_num_indices_metadata != st_ivas->hSCE[sce_id]->hMetaData->max_num_indices )
                {
                    /* re-allocate the list of metadata indices */
                    ind_list_realloc( st_ivas->hSCE[sce_id]->hMetaData, max_num_indices_metadata );
                }
            }
#endif
        }

@@ -1706,8 +1719,18 @@ void ivas_masa_enc_reconfigure(
                st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */

#ifdef IND_LIST_DYN
                /* re-allocate list of metadata indices, if needed */
                ind_list_metadata_realloc( st_ivas->hCPE[cpe_id]->hMetaData, st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );
                if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL )
                {
                    /* get the maximum allowed number of indices in the list */
                    max_num_indices_metadata = get_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );

                    /* check, if the maximum number of allowed indices has changed */
                    if ( max_num_indices_metadata != st_ivas->hCPE[cpe_id]->hMetaData->max_num_indices )
                    {
                        /* re-allocate the list of metadata indices */
                        ind_list_realloc( st_ivas->hCPE[cpe_id]->hMetaData, max_num_indices_metadata );
                    }
                }
#endif
            }

Loading