Commit 1e6cd422 authored by malenov's avatar malenov
Browse files

fix the I/O interface

parent 843b2278
Loading
Loading
Loading
Loading
Loading
+88 −36
Original line number Diff line number Diff line
@@ -147,6 +147,9 @@ typedef struct
#ifdef DEBUGGING
    IVAS_ENC_FORCED_MODE forcedMode;
    const char *forcedModeFile;
#ifdef DEBUG_FORCE_DIR
    const char *forcedModeDir;
#endif
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
    IVAS_ENC_AGC agc;
#endif
@@ -205,9 +208,6 @@ int main(
    int16_t *pcmBuf = NULL;
#ifdef DEBUGGING
    FILE *f_forcedModeProfile = NULL;
#ifdef DEBUG_FORCE_DIR
    bool f_forceModeDir = false;
#endif
#ifdef DEBUG_SBA
    int16_t numTransportChannels = 1;
#endif
@@ -562,26 +562,8 @@ int main(
#ifdef DEBUGGING
    IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode;
    int32_t force_profile_cnt = 0;
#ifdef DEBUG_FORCE_DIR
    struct stat path_stat;
#endif

    if ( arg.forcedModeFile )
    {
#ifdef DEBUG_FORCE_DIR
        if ( stat( arg.forcedModeFile, &path_stat ) != 0 )
        {
            fprintf( stderr, "\nError: The profile file/dir could not be opened: %s\n\n", arg.forcedModeFile );
            usage_enc();
            goto cleanup;
        }

        /* check if it is a directory */
        if ( S_ISDIR( path_stat.st_mode ) )
        {
            f_forceModeDir = true;
        }
        else
    {
        if ( ( f_forcedModeProfile = fopen( arg.forcedModeFile, "rb" ) ) == NULL )
        {
@@ -590,15 +572,11 @@ int main(
            goto cleanup;
        }
    }
#else
        if ( ( f_forcedModeProfile = fopen( arg.forcedModeFile, "rb" ) ) == NULL )
#ifdef DEBUG_FORCE_DIR
    else if ( arg.forcedModeDir )
    {
            fprintf( stderr, "\nError: Incorrect mode specification or the profile file could not be opened: %s\n\n", arg.forcedModeFile );
            usage_enc();
            goto cleanup;
    }
#endif
    }
#endif

    /*------------------------------------------------------------------------------------------*
@@ -751,16 +729,12 @@ int main(
        }

        /* Force mode not set when configuring, set in first frame even if not reading from file */
        if ( f_forcedModeProfile || 
#ifdef DEBUG_FORCE_DIR
             f_forceModeDir ||
#endif
             frame == 0 )
        if ( f_forcedModeProfile || frame == 0 )
        {
            if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode
#ifdef DEBUG_FORCE_DIR
                                                   ,
                                                   arg.forcedModeFile
                                                   arg.forcedModeDir
#endif
                                                   ) ) != IVAS_ERR_OK )
            {
@@ -951,6 +925,9 @@ static void initArgStruct( EncArguments *arg )
#ifdef DEBUGGING
    arg->forcedMode = IVAS_ENC_FORCE_UNFORCED;
    arg->forcedModeFile = NULL;
#ifdef DEBUG_FORCE_DIR
    arg->forcedModeDir = NULL;
#endif
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
    arg->agc = IVAS_ENC_AGC_UNDEFINED;
#endif
@@ -1101,6 +1078,28 @@ static bool parseCmdlIVAS_enc(

            arg->forcedMode = parseForcedMode( stmp );

#ifdef DEBUG_FORCE_DIR
            if ( arg->forcedMode < IVAS_ENC_FORCE_FILE )
            {
                fprintf( stdout, "Forcing codec to:       %s\n", argv[i + 1] );
            }
            else if ( arg->forcedMode == IVAS_ENC_FORCE_FILE )
            {
                arg->forcedModeFile = argv[i + 1];
                fprintf( stdout, "Force switching file:   %s\n", argv[i + 1] );
            }
            else if ( arg->forcedMode == IVAS_ENC_FORCE_DIR )
            {
                arg->forcedModeDir = argv[i + 1];
                fprintf( stdout, "Forcing switching directory:       %s\n", argv[i + 1] );
            }
            else
            {
                fprintf( stderr, "\nError: The force switching profile file/dir %s does not exist or could not be opened!\n\n", argv[i + 1] );
                usage_enc();
                return false;
            }
#else
            if ( arg->forcedMode == IVAS_ENC_FORCE_UNDEFINED )
            {
                arg->forcedModeFile = argv[i + 1];
@@ -1110,6 +1109,7 @@ static bool parseCmdlIVAS_enc(
            {
                fprintf( stdout, "Forcing codec to:       %s\n", argv[i + 1] );
            }
#endif

            i += 2;
        }
@@ -2069,8 +2069,59 @@ static bool readBitrate(
static IVAS_ENC_FORCED_MODE parseForcedMode(
    char *forcedModeChar )
{
#ifdef DEBUG_FORCE_DIR
    struct stat path_stat;
#endif

    to_upper( forcedModeChar );

#ifdef DEBUG_FORCE_DIR
    if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) ||
         ( strcmp( forcedModeChar, "0" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_SPEECH;
    }
    else if ( ( strcmp( forcedModeChar, "MUSIC" ) == 0 ) || ( strcmp( forcedModeChar, "'MUSIC'" ) == 0 ) || ( strcmp( forcedModeChar, "AUDIO" ) == 0 ) || ( strcmp( forcedModeChar, "'AUDIO'" ) == 0 ) || ( strcmp( forcedModeChar, "1" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_MUSIC;
    }
    else if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_ACELP;
    }
    else if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_GSC;
    }
    else if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_TCX;
    }
    else if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) )
    {
        return IVAS_ENC_FORCE_HQ;
    }
    else
    {
        if ( stat( forcedModeChar, &path_stat ) != 0 )
        {
            return IVAS_ENC_FORCE_UNDEFINED;
        }

        /* check if the argument represents an existing file or directory */
        if ( S_ISDIR( path_stat.st_mode ) )
        {
            /* it's a directory */
            return IVAS_ENC_FORCE_DIR;
        }
        else
        {
            /* it's a file */
            return IVAS_ENC_FORCE_FILE;
        }
    }

#else
    if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) ||
         ( strcmp( forcedModeChar, "0" ) == 0 ) )
    {
@@ -2098,6 +2149,7 @@ static IVAS_ENC_FORCED_MODE parseForcedMode(
    }

    return IVAS_ENC_FORCE_UNDEFINED;
#endif
}


+26 −0
Original line number Diff line number Diff line
@@ -284,6 +284,19 @@ void ivas_decision_matrix_enc(
                    }
                }
            }

#ifdef DEBUG_FORCE_DIR
            if ( st->force_dir[0] != '\0' )
            {
                dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) );
                dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) );
            }
            else
            {
                dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" );
                dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" );
            }
#endif
        }

        /* SWB and FB */
@@ -346,6 +359,19 @@ void ivas_decision_matrix_enc(
                st->extl_brate = 0;
            }

#ifdef DEBUG_FORCE_DIR
            if ( st->force_dir[0] != '\0' )
            {
                dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) );
                dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) );
            }
            else
            {
                dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" );
                dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" );
            }
#endif

            /* set IC-BWE bitrate */
            if ( st->element_mode == IVAS_CPE_TD && ( st->idchan == 0 ) && !st->tdm_LRTD_flag )
            {
+2 −2
Original line number Diff line number Diff line
@@ -1475,7 +1475,7 @@ ivas_error IVAS_ENC_SetForcedMode(
    }

#ifdef DEBUG_FORCE_DIR
    if ( forcedModeDir == NULL )
    if ( forcedMode < IVAS_ENC_FORCE_FILE )
    {
        hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0';

@@ -1490,7 +1490,7 @@ ivas_error IVAS_ENC_SetForcedMode(
            hIvasEnc->switchingActive = true;
        }
    }
    else
    else if ( forcedMode == IVAS_ENC_FORCE_DIR )
    {
        strcpy( hIvasEnc->st_ivas->hEncoderConfig->force_dir, forcedModeDir );
        hIvasEnc->st_ivas->hEncoderConfig->force = IVAS_ENC_FORCE_UNFORCED;
+4 −0
Original line number Diff line number Diff line
@@ -129,6 +129,10 @@ typedef enum _IVAS_ENC_FORCED_MODE
    IVAS_ENC_FORCE_GSC,
    IVAS_ENC_FORCE_TCX,
    IVAS_ENC_FORCE_HQ,
#ifdef DEBUG_FORCE_DIR
    IVAS_ENC_FORCE_FILE,
    IVAS_ENC_FORCE_DIR,
#endif
    IVAS_ENC_FORCE_UNFORCED,
    IVAS_ENC_FORCE_UNDEFINED = 0xffff
} IVAS_ENC_FORCED_MODE;