Commit 502ba662 authored by vaclav's avatar vaclav
Browse files

- updates within SWITCHING_FORMAT_DEC

- DEBUG_FORMAT_SWITCHING_ENC replaces SWITCHING_FORMAT_ENC and SIMULATE_FORMAT_SWITCHING_ENC
parent bc4714a1
Loading
Loading
Loading
Loading
+72 −16
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ typedef struct

static void initArgStruct( EncArguments *arg );
static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg
#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
                               ,
                               const bool reconfig_flag
#endif
@@ -148,13 +148,13 @@ static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg
static void usage_enc( void );
static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter );
static bool readBitrate( FILE *file, int32_t *bitrate );
#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
static ivas_error configureEnc( const EncArguments arg, IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate, const IVAS_ENC_BANDWIDTH bandwidth, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig );
#endif
#ifdef DEBUGGING
static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter );
static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar );
#ifdef SIMULATE_FORMAT_SWITCHING_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
static void simulate_input_format_switching( int16_t *argc_new, char *p_argv_new[10], bool *reinit_flag );
#endif
#endif
@@ -190,6 +190,9 @@ int main(
    }
    int16_t *pcmBuf = NULL;
#ifdef DEBUGGING
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    int16_t pcmBufSize_orig;
#endif
    FILE *f_forcedModeProfile = NULL;
#ifdef DEBUG_SBA
    int16_t numTransportChannels = 1;
@@ -213,7 +216,7 @@ int main(
    IVAS_ENC_PrintDisclaimer();

    if ( !parseCmdlIVAS_enc( (int16_t) argc, argv, &arg
#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
                             ,
                             false
#endif
@@ -376,7 +379,7 @@ int main(
     * Configure and initialize (allocate memory for static variables) the encoder
     *------------------------------------------------------------------------------------------*/

#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    if ( ( error = configureEnc( arg, hIvasEnc, totalBitrate, bandwidth, caConfig ) ) != IVAS_ERR_OK )
    {
        goto cleanup;
@@ -574,6 +577,9 @@ int main(
        fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
        goto cleanup;
    }
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    pcmBufSize_orig = pcmBufSize;
#endif

    pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) );

@@ -634,19 +640,18 @@ int main(
     * - Write the parameters into output bitstream file
     *------------------------------------------------------------------------------------------*/

#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    bool reinit_flag = false;
    int16_t pcmBufSize_new = pcmBufSize;
    char *p_argv_new[10];
    int16_t argc_new = -1;
#endif

    while ( 1 )
    {
#ifdef SWITCHING_FORMAT_ENC
#ifdef SIMULATE_FORMAT_SWITCHING_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
        /* simulate input format switching */
        simulate_input_format_switching( &argc_new, p_argv_new, &reinit_flag );
#endif

        /* Reinitialization of the encoder in case of application parameter(s) change (e.g. change of IVAS input format) */
        if ( reinit_flag )
@@ -665,7 +670,6 @@ int main(
            }

            /* Allocate input data buffer */
            int16_t pcmBufSize_new;
            if ( ( error = IVAS_ENC_GetInputBufferSize( hIvasEnc, &pcmBufSize_new ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) );
@@ -675,10 +679,17 @@ int main(
            if ( pcmBufSize_new != pcmBufSize )
            {
                free( pcmBuf );
                pcmBuf = malloc( pcmBufSize_new * sizeof( int16_t ) );
                pcmBufSize = pcmBufSize_new;
                pcmBuf = malloc( max( pcmBufSize_new, pcmBufSize_orig ) * sizeof( int16_t ) );
            }
        }

        if ( pcmBufSize_new < pcmBufSize_orig )
        {
            free( pcmBuf );
            pcmBuf = malloc( max( pcmBufSize_new, pcmBufSize_orig ) * sizeof( int16_t ) );
        }

        pcmBufSize = pcmBufSize_orig;
#endif

        /* Read the input data */
@@ -688,6 +699,51 @@ int main(
            goto cleanup;
        }

#ifdef DEBUG_FORMAT_SWITCHING_ENC
        if ( pcmBufSize_new > pcmBufSize_orig )
        {
            /* keep only channels corresponding to input file channels and zero the others */
            int16_t tmp_buf[16 * 960];
            int16_t nchan = pcmBufSize_new / 960;
            int16_t nchan_orig = pcmBufSize / 960;
            memcpy( tmp_buf, pcmBuf, numSamplesRead * sizeof( int16_t ) );
            memset( pcmBuf, 0, pcmBufSize_new * sizeof( int16_t ) );
            int16_t k = 0;
            for ( i = 0; i < 960; i++ )
            {
                for ( int16_t j = 0; j < nchan_orig; j++ )
                {
                    pcmBuf[i * nchan + j] = tmp_buf[k++];
                }
            }

            pcmBufSize = pcmBufSize_new;
            numSamplesRead = pcmBufSize;
        }
        else if ( pcmBufSize_new < pcmBufSize_orig )
        {
            int16_t tmp_buf[16 * 960];

            /* skip channels corresponding to non-read input file channels */

            memcpy( tmp_buf, pcmBuf, pcmBufSize * sizeof( int16_t ) );
            free( pcmBuf );
            pcmBuf = malloc( pcmBufSize_new * sizeof( int16_t ) );

            int16_t fac = pcmBufSize / pcmBufSize_new;
            int16_t k = 0;
            for ( i = 0; i < pcmBufSize; i += fac )
            {
                for ( int16_t j = 0; j < pcmBufSize / pcmBufSize_orig; j++ )
                {
                    pcmBuf[k++] = tmp_buf[i + j];
                }
            }

            pcmBufSize = pcmBufSize_new;
        }
#endif

        if ( numSamplesRead == 0 )
        {
            /* end of input data */
@@ -981,7 +1037,7 @@ static bool parseCmdlIVAS_enc(
    int16_t argc,
    char *argv[],
    EncArguments *arg
#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    ,
    const bool reconfig_flag
#endif
@@ -1625,7 +1681,7 @@ static bool parseCmdlIVAS_enc(
        }
    } /* end of while  */

#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
    /*-----------------------------------------------------------------*
     * Return in case of reconfiguration
     *-----------------------------------------------------------------*/
@@ -1924,7 +1980,7 @@ static bool readBitrate(
}


#ifdef SWITCHING_FORMAT_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
/*---------------------------------------------------------------------*
 * configureEnc()
 *
@@ -2096,7 +2152,7 @@ static ivas_error readForcedMode(
}


#ifdef SIMULATE_FORMAT_SWITCHING_ENC
#ifdef DEBUG_FORMAT_SWITCHING_ENC
/*---------------------------------------------------------------------*
 * simulate_input_format_switching()
 *
+1 −2
Original line number Diff line number Diff line
@@ -228,8 +228,7 @@
#define FIX_DTX_428                                     /* FhG: fix for issue 428, crash with DTX and bitrate switching */

#define SWITCHING_FORMAT_DEC                            /* VA: issue 326: Bitstream Switching (Decoder side) */
#define SWITCHING_FORMAT_ENC                            /* VA: issue 325: Encoder Input format Switching */
/*#define SIMULATE_FORMAT_SWITCHING_ENC*/               /* VA: debugging: simulate Input format switching */
#define DEBUG_FORMAT_SWITCHING_ENC                  /* VA: debugging: simulate Input format switching */


/* ################## End DEVELOPMENT switches ######################### */
+5 −0
Original line number Diff line number Diff line
@@ -109,6 +109,11 @@ ivas_error ivas_dec_setup(

        /* set decoder high level parameters */
        ivas_decoder_init_highlevel_params( ivas_format_read, st_ivas );

        st_ivas->nSCE = 0;
        st_ivas->nCPE = 0;
        st_ivas->nchan_transport = -1;
        st_ivas->sba_dirac_stereo_flag = 0;
    }
#endif

+1 −1
Original line number Diff line number Diff line
@@ -1038,7 +1038,7 @@ void ivas_destroy_enc(
    /* Stereo downmix for EVS encoder handle */
    stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) );

#ifndef SWITCHING_FORMAT_ENC
#ifndef DEBUG_FORMAT_SWITCHING_ENC
    /* Encoder configuration handle */
    if ( st_ivas->hEncoderConfig != NULL )
    {
+8 −0
Original line number Diff line number Diff line
@@ -176,6 +176,14 @@ ivas_error ivas_ism_enc(
        {
            vad_flag[sce_id] = st->vad_flag;
        }

#ifdef DEBUG_MODE_INFO
        if ( sce_id == 0 )
        {
            dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" );
            dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
        }
#endif
    }

    /*------------------------------------------------------------------*
Loading