Commit 388c180c authored by malenov's avatar malenov
Browse files

Allocate ind_list_metadata[] dynamically

parent 2aaf10bc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@

#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

@@ -745,6 +746,7 @@ int main(

#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


+184 −9
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */

#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

@@ -238,7 +239,7 @@ ivas_error ind_list_realloc(
    INDICE_HANDLE new_ind_list;

    /* get the maximum allowed number of indices in the list */
    max_num_indices = set_max_num_indices( ivas_format, total_brate );
    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 )
@@ -278,14 +279,71 @@ ivas_error ind_list_realloc(
    return IVAS_ERR_OK;
}

#ifdef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * ind_list_metadata_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;
        }
    }

    return IVAS_ERR_OK;
}
/*-----------------------------------------------------------------------*
 * set_max_num_indices()
 * get_max_num_indices()
 *
 * Set the maximum allowed number of indices in the list
 *-----------------------------------------------------------------------*/

int16_t set_max_num_indices(       /* o  : maximum number of indices */
int16_t get_max_num_indices(       /* o  : maximum number of indices */
    const IVAS_FORMAT ivas_format, /* i  : IVAS format               */
    const int32_t total_brate      /* i  : total bitrate             */
)
@@ -376,6 +434,88 @@ int16_t set_max_num_indices( /* o : maximum number of indices */

    return 1050;
}

#ifdef IND_LIST_DYN
/*-----------------------------------------------------------------------*
 * set_max_set_max_num_indices_metadatanum_indices()
 *
 * Set the maximum allowed number of metadata indices in the list
 *-----------------------------------------------------------------------*/

int16_t get_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       */
)
{
    /* set the maximum required number of metadata indices */
    if ( ivas_format == MONO_FORMAT )
    {
        return 0;
    }
    else if ( ivas_format == STEREO_FORMAT )
    {
        return 80;
    }
    else if ( ivas_format == ISM_FORMAT )
    {
        return 60;
    }
    else if ( ivas_format == SBA_FORMAT )
    {
        if ( ivas_total_brate < IVAS_24k4 )
        {
            return 80;
        }
        else if ( ivas_total_brate < IVAS_48k )
        {
            return 670;
        }
        else
        {
            return 1060;
        }
    }
    else if ( ivas_format == MASA_FORMAT )
    {
        if ( ivas_total_brate < IVAS_32k )
        {
            return 80;
        }
        else if ( ivas_total_brate < IVAS_48k )
        {
            return 110;
        }
        else if ( ivas_total_brate < IVAS_192k )
        {
            return 330;
        }
        else if ( ivas_total_brate < IVAS_384k )
        {
            return 1000;
        }
        else
        {
            return 1950;
        }
    }
    else if ( ivas_format == MC_FORMAT )
    {
        if ( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_48k || ivas_total_brate == IVAS_64k )
        {
            return 300;
        }
        if ( ivas_total_brate == IVAS_80k || ivas_total_brate == IVAS_96k )
        {
            return 170;
        }
        else
        {
            return 90;
        }
    }

    return 1050;
}
#endif
#endif

@@ -1119,6 +1259,10 @@ static ivas_error write_indices_element(
    uint16_t *pt_stream_backup;
    uint16_t *pt_stream_end;
    int16_t nb_bits_tot_metadata;
#ifdef IND_LIST_DYN
    int16_t nb_ind_tot_metadata;
#endif

    Indice *ind_list_metadata;
    int16_t n, n_channels;
#ifdef ENABLE_BITRATE_VERIFICATION
@@ -1129,6 +1273,9 @@ static ivas_error write_indices_element(
    error = IVAS_ERR_OK;

    ind_list_metadata = NULL;
#ifdef IND_LIST_DYN
    nb_ind_tot_metadata = 0;
#endif

    if ( st_ivas->hEncoderConfig->ivas_format == MONO_FORMAT )
    {
@@ -1146,6 +1293,9 @@ static ivas_error write_indices_element(
            {
                nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot;
                ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list;
#ifdef IND_LIST_DYN
                nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot;
#endif
            }
        }
        else if ( !is_SCE && st_ivas->hCPE[element_id] != NULL )
@@ -1156,6 +1306,9 @@ static ivas_error write_indices_element(
            {
                nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot;
                ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list;
#ifdef IND_LIST_DYN
                nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot;
#endif
            }
        }
#ifdef DEBUGGING
@@ -1196,7 +1349,13 @@ static ivas_error write_indices_element(
#ifdef ENABLE_BITRATE_VERIFICATION
            total_nb_bits =
#endif
                write_indices_to_stream( ind_list_metadata, &pt_stream_loc, -1, MAX_BITS_METADATA );
                write_indices_to_stream( ind_list_metadata, &pt_stream_loc, -1,
#ifdef IND_LIST_DYN
                    nb_ind_tot_metadata
#else
                    MAX_BITS_METADATA 
#endif                
                );

#ifdef ENABLE_BITRATE_VERIFICATION
            if ( total_nb_bits != nb_bits_tot_metadata )
@@ -1245,9 +1404,17 @@ static ivas_error write_indices_element(
    {
        if ( st_ivas->hSCE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, MAX_BITS_METADATA );
#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
            st_ivas->hSCE[element_id]->hMetaData->max_num_indices = MAX_BITS_METADATA;
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->max_num_indices );
#else
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, MAX_BITS_METADATA );
#endif
        }

@@ -1272,9 +1439,17 @@ static ivas_error write_indices_element(
    {
        if ( st_ivas->hCPE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, MAX_BITS_METADATA );
#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
            st_ivas->hCPE[element_id]->hMetaData->max_num_indices = MAX_BITS_METADATA;
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->max_num_indices );
#else
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, MAX_BITS_METADATA );
#endif
        }

+2 −0
Original line number Diff line number Diff line
@@ -177,7 +177,9 @@ typedef enum
#define MAX_CPE                                 ( MAX_TRANSPORT_CHANNELS / CPE_CHANNELS )    /* max. number of CPEs */

#define MAX_BITS_METADATA                       2640                        /* max. bit-budget of metadata, one channel */ /* IVAS_fmToDo: to be confirmed for final value once mature */
#ifndef IND_LIST_DYN
#define MAX_NUM_METADATA                        max( 2, MAX_NUM_OBJECTS )   /* number of max. metadata (now only 2 for DirAC) */
#endif

#ifdef IND_LIST_DYN
#define MAX_NUM_IND_TEMP_LIST                   10                          /* maximum number of indices in the temporary list */
+5 −3
Original line number Diff line number Diff line
@@ -284,11 +284,13 @@ void ivas_initialize_handles_enc(
);

ivas_error ivas_init_encoder(
    Encoder_Struct *st_ivas,                                    /* i/o: IVAS encoder structure                  */
    Encoder_Struct *st_ivas                                    /* i/o: IVAS encoder structure                  */
#ifndef IND_LIST_DYN
    ,Indice ind_list[][MAX_NUM_INDICES]                         /* i  : indices list                            */
#endif
#ifndef IND_LIST_DYN
    Indice ind_list[][MAX_NUM_INDICES],                         /* i  : indices list                            */
    ,Indice ind_list_metadata[][MAX_BITS_METADATA]               /* i  : indices list metadata                   */
#endif
    Indice ind_list_metadata[][MAX_BITS_METADATA]               /* i  : indices list metadata                   */
);

void destroy_core_enc(
+2 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@

/*#define BITSTREAM_INDICES_MEMORY*/            /* Don't count memory for bitstream Indice at the encoder - it is a temporary solution for development only */
#define IND_LIST_DYN                            /* dynamic allocation of ind_list based on transport channels */
#define DEBUG_IND_LIST
/*#define DEBUG_IND_LIST*/

#ifdef DEBUGGING

Loading