Commit a94f39dc authored by multrus's avatar multrus
Browse files

[cleanup] accept IND_LIST_DYN

parent 2f89ad8b
Loading
Loading
Loading
Loading
+0 −258
Original line number Diff line number Diff line
@@ -62,65 +62,8 @@
FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */
#endif

#ifdef IND_LIST_DYN
#define STEP_MAX_NUM_INDICES 100 /* increase the maximum number of allowed indices in the list by this amount */
#endif

#ifndef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * pack_bit()
 *
 * insert a bit into packed octet
 *-------------------------------------------------------------------*/

static void pack_bit(
    const Word16 bit, /* i  : bit to be packed */
    UWord8 **pt,      /* i/o: pointer to octet array into which bit will be placed */
    UWord8 *omask     /* i/o: output mask to indicate where in the octet the bit is to be written */
)
{
    if ( *omask == 0x80 )
    {
        **pt = 0;
    }
    if ( bit != 0 )
    {
        **pt = **pt | *omask;
    }
    *omask >>= 1;
    if ( *omask == 0 )
    {
        *omask = 0x80;
        ( *pt )++;
    }

    return;
}

/*-------------------------------------------------------------------*
 * unpack_bit()
 *
 * unpack a bit from packed octet
 *-------------------------------------------------------------------*/

static Word16 unpack_bit(
    UWord8 **pt, /* i/o: pointer to octet array from which bit will be read */
    UWord8 *mask /* i/o: mask to indicate the bit in the octet */
)
{
    Word16 bit;

    bit = ( **pt & *mask ) != 0;
    *mask >>= 1;
    if ( *mask == 0 )
    {
        *mask = 0x80;
        ( *pt )++;
    }

    return bit;
}
#endif

/*-------------------------------------------------------------------*
 * rate2AMRWB_IOmode()
@@ -220,7 +163,6 @@ Word16 rate2EVSmode(
    return rate2AMRWB_IOmode( brate );
}

#ifdef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * ind_list_realloc()
 *
@@ -910,9 +852,7 @@ ivas_error move_indices(
#endif
}

#endif

#ifdef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * check_ind_list_limits()
 *
@@ -1001,7 +941,6 @@ ivas_error check_ind_list_limits(

    return error;
}
#endif


/*-------------------------------------------------------------------*
@@ -1027,9 +966,7 @@ ivas_error push_indice(
)
{
    int16_t i;
#ifdef IND_LIST_DYN
    int16_t j;
#endif
    ivas_error error;

    error = IVAS_ERR_OK;
@@ -1043,30 +980,13 @@ ivas_error push_indice(
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice ID = %d with value %d exceeds the range of %d bits (frame %d) !\n", id, value, nb_bits, frame );
    }

#ifndef IND_LIST_DYN
#if 0
    /* mul, 2020-11-19: to be de-activated until proper solution found */
    if ( nb_bits < 1 )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, " Trying to push indice ID = %d with value %d that has %d bits (frame %d) !\n", id, value, nb_bits, frame );
    }
    else
#endif
#endif
    if ( nb_bits > 16 )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice ID = %d with value %d is trying to allocate %d bits which exceeds 16 bits (frame %d) !\n", id, value, nb_bits, frame );
    }

#ifndef IND_LIST_DYN
    if ( id >= MAX_NUM_INDICES )
    {
        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 the limits of the list of indices */
#ifdef FIX_545_ASSERT
    if ( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK )
@@ -1076,9 +996,7 @@ ivas_error push_indice(
#else
    error = check_ind_list_limits( hBstr );
#endif
#endif

#ifdef IND_LIST_DYN
    /* find the location in the list of indices based on ID */
    i = hBstr->nb_ind_tot;
    while ( i > 0 && id < hBstr->ind_list[i - 1].id )
@@ -1096,46 +1014,15 @@ ivas_error push_indice(
            hBstr->ind_list[j].value = hBstr->ind_list[j - 1].value;
        }
    }
#else
    if ( hBstr->last_ind == id )
    {
        /* indice with the same name as the previous one */
        i = hBstr->next_ind;
    }
    else
    {
        /* new indice - find an empty slot in the list */
        i = id;
        while ( hBstr->ind_list[i].nb_bits != -1 )
        {
            i++;
        }
    }
#endif

#ifndef IND_LIST_DYN
#ifdef DEBUGGING
    if ( hBstr->ind_list[i].nb_bits > 0 )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice ID = %d with value %d is trying to re-write an existing indice (frame %d) !\n", id, value, frame );
    }
#endif
#endif

    /* store the new indice in the list */
#ifdef IND_LIST_DYN
    hBstr->ind_list[i].id = id;
#endif
    hBstr->ind_list[i].value = value;
    hBstr->ind_list[i].nb_bits = nb_bits;

    /* updates */
#ifdef IND_LIST_DYN
    hBstr->nb_ind_tot++;
#else
    hBstr->next_ind = i + 1;
    hBstr->last_ind = id;
#endif
    hBstr->nb_bits_tot += nb_bits;

    return error;
@@ -1162,9 +1049,7 @@ ivas_error push_next_indice(
#endif
)
{
#ifdef IND_LIST_DYN
    int16_t prev_id;
#endif
    ivas_error error;

    error = IVAS_ERR_OK;
@@ -1183,20 +1068,8 @@ ivas_error push_next_indice(
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Indice with value %d is trying to allocate %d bits which exceeds 16 bits !\n", value, nb_bits );
    }

#ifndef IND_LIST_DYN
    if ( hBstr->next_ind >= MAX_NUM_INDICES )
    {
        return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Total number of indices exceeded: %d !\n", MAX_NUM_INDICES );
    }

    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 );
    }
#endif
#endif

#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 )
@@ -1206,9 +1079,7 @@ ivas_error push_next_indice(
#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 */
    if ( hBstr->nb_ind_tot > 0 )
    {
@@ -1218,24 +1089,14 @@ ivas_error push_next_indice(
    {
        prev_id = 0;
    }
#endif

    /* store the values in the list */
#ifdef IND_LIST_DYN
    hBstr->ind_list[hBstr->nb_ind_tot].id = prev_id;
    hBstr->ind_list[hBstr->nb_ind_tot].value = value;
    hBstr->ind_list[hBstr->nb_ind_tot].nb_bits = nb_bits;
#else
    hBstr->ind_list[hBstr->next_ind].value = value;
    hBstr->ind_list[hBstr->next_ind].nb_bits = nb_bits;
#endif

    /* updates */
#ifdef IND_LIST_DYN
    hBstr->nb_ind_tot++;
#else
    hBstr->next_ind++;
#endif
    hBstr->nb_bits_tot += nb_bits;

    return error;
@@ -1273,19 +1134,16 @@ void push_next_bits(
    uint16_t code;
    int16_t i, nb_bits_m15;
    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 );
#endif

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

    /* get the id of the previous indice -> will be re-used */
@@ -1297,16 +1155,12 @@ void push_next_bits(
    {
        prev_id = 0;
    }
#else
    ptr = &hBstr->ind_list[hBstr->next_ind];
#endif
    nb_bits_m15 = nb_bits - 15;

    for ( i = 0; i < nb_bits_m15; i += 16 )
    {
        code = (uint16_t) ( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) );

#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 )
@@ -1317,23 +1171,19 @@ void push_next_bits(
        check_ind_list_limits( hBstr );
#endif
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];
#endif

        ptr->value = code;
#ifdef DEBUG_BS_READ_WRITE
        printf( "code: %d\n", code );
#endif
        ptr->nb_bits = 16;
#ifdef IND_LIST_DYN
        ptr->id = prev_id;
        hBstr->nb_ind_tot++;
#endif
        ++ptr;
    }

    for ( ; i < nb_bits; ++i )
    {
#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 )
@@ -1344,23 +1194,17 @@ void push_next_bits(
        check_ind_list_limits( hBstr );
#endif
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];
#endif

        ptr->value = bits[i];
#ifdef DEBUG_BS_READ_WRITE
        printf( "value: %d\n", ptr->value );
#endif
        ptr->nb_bits = 1;
#ifdef IND_LIST_DYN
        ptr->id = prev_id;
        hBstr->nb_ind_tot++;
#endif
        ++ptr;
    }

#ifndef IND_LIST_DYN
    hBstr->next_ind = (int16_t) ( ptr - hBstr->ind_list );
#endif
    hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits;

#ifdef FIX_545_ASSERT
@@ -1371,7 +1215,6 @@ void push_next_bits(
}


#ifdef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * find_indice()
 *
@@ -1437,9 +1280,6 @@ uint16_t delete_indice(
    }

    hBstr->nb_ind_tot = j;
#ifndef IND_LIST_DYN
    hBstr->next_ind = j;
#endif

    for ( ; j < i; j++ )
    {
@@ -1449,7 +1289,6 @@ uint16_t delete_indice(

    return i - j;
}
#endif


/*-------------------------------------------------------------------*
@@ -1670,12 +1509,7 @@ void reset_indices_enc(
    int16_t i;

    hBstr->nb_bits_tot = 0;
#ifdef IND_LIST_DYN
    hBstr->nb_ind_tot = 0;
#else
    hBstr->next_ind = 0;
    hBstr->last_ind = -1;
#endif

    for ( i = 0; i < max_num_indices; i++ )
    {
@@ -1706,11 +1540,7 @@ void reset_indices_dec(
 *-------------------------------------------------------------------*/

static int16_t write_indices_to_stream(
#ifdef IND_LIST_DYN
    Indice *ind_list,
#else
    Indice *ind_list_metadata,
#endif
    uint16_t **pt_stream,
    const int16_t inc,
    const int16_t num_indices )
@@ -1724,13 +1554,8 @@ static int16_t write_indices_to_stream(

    for ( i = 0; i < num_indices; i++ )
    {
#ifdef IND_LIST_DYN
        value = ind_list[i].value;
        nb_bits = ind_list[i].nb_bits;
#else
        value = ind_list_metadata[i].value;
        nb_bits = ind_list_metadata[i].nb_bits;
#endif

        if ( nb_bits > 0 )
        {
@@ -1794,9 +1619,7 @@ 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;
@@ -1808,9 +1631,7 @@ 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 )
    {
@@ -1828,9 +1649,7 @@ 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 )
@@ -1841,9 +1660,7 @@ 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
@@ -1885,11 +1702,7 @@ static ivas_error write_indices_element(
            total_nb_bits =
#endif
                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
@@ -1905,11 +1718,7 @@ static ivas_error write_indices_element(
        total_nb_bits =
#endif
            write_indices_to_stream( sts[n]->hBstr->ind_list, &pt_stream_loc, 1,
#ifdef IND_LIST_DYN
                                     sts[n]->hBstr->nb_ind_tot
#else
                                 MAX_NUM_INDICES
#endif
            );

#ifdef ENABLE_BITRATE_VERIFICATION
@@ -1933,40 +1742,24 @@ static ivas_error write_indices_element(
    {
        if ( st_ivas->hSCE[element_id]->hMetaData != NULL )
        {
#ifdef IND_LIST_DYN
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot );
#else
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, MAX_BITS_METADATA );
#endif
        }

        reset_indices_enc( sts[0]->hBstr,
#ifdef IND_LIST_DYN
                           sts[0]->hBstr->nb_ind_tot
#else
                           MAX_NUM_INDICES
#endif
        );
    }
    else
    {
        if ( st_ivas->hCPE[element_id]->hMetaData != NULL )
        {
#ifdef IND_LIST_DYN
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot );
#else
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, MAX_BITS_METADATA );
#endif
        }

        for ( n = 0; n < n_channels; n++ )
        {
            reset_indices_enc( sts[n]->hBstr,
#ifdef IND_LIST_DYN
                               sts[n]->hBstr->nb_ind_tot
#else
                               MAX_NUM_INDICES
#endif
            );
        }
    }
@@ -2066,57 +1859,6 @@ ivas_error write_indices_ivas(
    return error;
}

#ifndef IND_LIST_DYN
/*-------------------------------------------------------------------*
 * indices_to_serial_generic()
 *
 * pack indices into serialized payload format
 *-------------------------------------------------------------------*/

void indices_to_serial_generic(
    const Indice *ind_list,   /* i  : indices list                                                  */
    const Word16 num_indices, /* i  : number of indices to write                                    */
    UWord8 *pFrame,           /* o  : byte array with bit packet and byte aligned coded speech data */
    Word16 *pFrame_size       /* i/o: number of bits in the binary encoded access unit [bits]       */
)
{
    Word16 i, k, j;
    Word32 mask;
    UWord8 omask;
    UWord8 *pt_pFrame = pFrame;
    Word16 nb_bits_tot = 0;

    omask = ( 0x80 >> ( *pFrame_size & 0x7 ) );
    pt_pFrame += *pFrame_size >> 3;

    /*----------------------------------------------------------------*
     * Bitstream packing (conversion of individual indices into a serial stream)
     *----------------------------------------------------------------*/

    j = 0;
    for ( i = 0; i < num_indices; i++ )
    {
        if ( ind_list[i].nb_bits > 0 )
        {
            /* mask from MSB to LSB */
            mask = 1 << ( ind_list[i].nb_bits - 1 );

            /* write bit by bit */
            for ( k = 0; k < ind_list[i].nb_bits; k++ )
            {
                pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask );
                j++;
                mask >>= 1;
            }
            nb_bits_tot += ind_list[i].nb_bits;
        }
    }

    *pFrame_size += nb_bits_tot;

    return;
}
#endif

/*---------------------------------------------------------------------*
 * convertSerialToBytestream( )
+0 −3
Original line number Diff line number Diff line
@@ -447,9 +447,6 @@ enum
    IND_STEREO_2ND_CODER_T,

    IND_UNUSED,
#ifndef IND_LIST_DYN
    MAX_NUM_INDICES = IND_UNUSED + 772 /* Total 2640 in line with MAX_BITS_METADATA */
#endif
};

/*----------------------------------------------------------------------------------*
+0 −5
Original line number Diff line number Diff line
@@ -181,15 +181,10 @@ 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 MIN_NUM_IND                             10                          /* minimum number of indices in the core coder */
#define MAX_NUM_IND_LFE                         100                         /* maximum number of indices in the LFE encoder */
#define MAX_NUM_IND_TEMP_LIST                   10                          /* maximum number of indices in the temporary list */
#define MAX_IND_TDM_TMP                         10                          /* maximum number of indices in the temporary list of TD stereo spatial parameters */
#endif

#define IVAS_ENC_DELAY_NS                       ACELP_LOOK_NS
#define IVAS_DEC_DELAY_NS                       3250000L                    /* 3.25 ms: IVAS decoder delay (without renderer delay) */
+0 −7
Original line number Diff line number Diff line
@@ -278,10 +278,6 @@ void ivas_initialize_handles_enc(

ivas_error ivas_init_encoder(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder structure                  */
#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
);

void destroy_core_enc(
@@ -3192,9 +3188,6 @@ 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
);

+0 −6
Original line number Diff line number Diff line
@@ -137,17 +137,11 @@
/* ################# Start DEVELOPMENT switches ######################## */

#define BASOP_NOGLOB                                    /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */
#define IND_LIST_DYN                                    /* VA: Issue 18: Dynamic allocation of ind_list[] and ind_list_metadata[] based on # of transport channels */

#ifndef IND_LIST_DYN
#define BITSTREAM_INDICES_MEMORY                        /* Don't count memory for bitstream Indice at the encoder - it is a temporary solution for development only */
#endif

/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */

#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_563_PARAMMC_LIMITER                         /* FhG: issue 563: fix ILD limiter when coming from silence w/o transient set             */

Loading