Commit a2c05c47 authored by vaclav's avatar vaclav
Browse files

Merge branch 'float-1566-ext-output-in-format-switching' into 'main'

Fix EXT output in format switching

See merge request !2581
parents 8effb7ed 28acdd16
Loading
Loading
Loading
Loading
Loading
+113 −3
Original line number Diff line number Diff line
@@ -183,6 +183,9 @@ static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBs
static int16_t app_own_random( int16_t *seed );
#endif
static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader );
#ifdef FIX_FMSW_DEC_EXT
static ivas_error updateOnFormatSwitching( IVAS_DEC_HANDLE hIvasDec, IVAS_DEC_BS_FORMAT *pBsFormat, const char *outputWavFilename, MasaFileWriter **ppMasaWriter, IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], int16_t *pNumOutChannels, uint16_t *pNumObj, const bool delayCompensationEnabled );
#endif


/*------------------------------------------------------------------------------------------*
@@ -806,8 +809,8 @@ int main(
    {
        fprintf( stdout, "Clipping (saturation) detected: %d samples clipped!!!\n\n", noClipping );
    }
#endif

#endif
    /*------------------------------------------------------------------------------------------*
     * Close files and deallocate resources
     *------------------------------------------------------------------------------------------*/
@@ -840,7 +843,6 @@ cleanup:
    IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels );

#endif

    IVAS_DEC_Close( &hIvasDec );
    CustomLsReader_close( &hLsCustomReader );
    hrtfFileReader_close( &hrtfReader );
@@ -2263,7 +2265,11 @@ static ivas_error decodeG192(
    int16_t vec_pos_update, vec_pos_len;
    SplitFileReadWrite *splitRendWriter = NULL;
    int16_t isSplitRend, isSplitCoded;
#ifdef FIX_FMSW_DEC_EXT
    bool restartNeeded = false;
#else
    bool restartNeeded;
#endif

#ifdef VARIABLE_SPEED_DECODING
    if ( arg.tsmEnabled )
@@ -2396,9 +2402,9 @@ static ivas_error decodeG192(
            goto cleanup;
        }
    }

#endif
#endif

    /*------------------------------------------------------------------------------------------*
     * Loop for every packet (frame) of bitstream data
     * - Read the bitstream packet
@@ -2731,6 +2737,18 @@ static ivas_error decodeG192(
            }
        }

#ifdef FIX_FMSW_DEC_EXT
        /* Output writing update in case of format switching and EXTERNAL output */
        if ( restartNeeded && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
        {
            if ( ( error = updateOnFormatSwitching( hIvasDec, &bsFormat, arg.outputWavFilename, &masaWriter, ismWriters, &nOutChannels, &numObj, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Error in updateOnFormatSwitching(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
#endif

        /* Write current frame */
        if ( decodedGoodFrame )
        {
@@ -3212,7 +3230,11 @@ static ivas_error decodeVoIP(
    int16_t i;
    IVAS_DEC_HANDLE hIvasDec = *phIvasDec;

#ifdef FIX_FMSW_DEC_EXT
    bool restartNeeded = false;
#else
    bool restartNeeded;
#endif
    IVAS_RTP ivasRtp = { 0 };
    IVAS_RTP srRtp = { 0 };
    IVAS_RTP_SR_INFO srInfo = { true, false, 0, 20, IVAS_SR_TRANSPORT_LCLD };
@@ -3702,6 +3724,18 @@ static ivas_error decodeVoIP(
            }
        }

#ifdef FIX_FMSW_DEC_EXT
        /* Output writing update in case of format switching and EXTERNAL output */
        if ( restartNeeded && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL )
        {
            if ( ( error = updateOnFormatSwitching( hIvasDec, &bsFormat, arg.outputWavFilename, &masaWriter, ismWriters, &nOutChannels, &numObj, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "Error in updateOnFormatSwitching(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
#endif

        /* Write current frame */
        if ( !srRtp.hPack && decodedGoodFrame )
        {
@@ -4304,4 +4338,80 @@ static ivas_error load_hrtf_from_file(
    return IVAS_ERR_OK;
}

#ifdef FIX_FMSW_DEC_EXT

/*---------------------------------------------------------------------*
 * updateOnFormatSwitching()
 *
 * In case of IVAS format switching and EXTERNAL output,
 * update decoder wrt. output writing
 *---------------------------------------------------------------------*/

static ivas_error updateOnFormatSwitching(
    IVAS_DEC_HANDLE hIvasDec,                        /* i/o: IVAS decoder handle                             */
    IVAS_DEC_BS_FORMAT *pBsFormat,                   /* o  : format of currently decoded bitstream           */
    const char *outputWavFilename,                   /* i  : name of the output audio file                   */
    MasaFileWriter **ppMasaWriter,                   /* o  : MasaFileWriter handle                           */
    IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o  : 1-4 ismWriters handles                          */
    int16_t *pNumOutChannels,                        /* o  : number of output channels                       */
    uint16_t *pNumObj,                               /* o  : number of ISM objects                           */
    const bool delayCompensationEnabled              /* i  : is delay compensation enabled                   */
)
{
    ivas_error error;

    /* in case of EXT output, the number of output audio channels can change */
    if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_GetNumOutputChannels, code: %d\n", error );
        return error;
    }

    /* Get the format of currently decoded bitstream */
    if ( ( error = IVAS_DEC_GetFormat( hIvasDec, pBsFormat ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error );
        return error;
    }

    *pNumObj = 0;
    if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM || *pBsFormat == IVAS_DEC_BS_SBA_ISM )
    {
        if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, pNumObj ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) );
            return error;
        }

        /* If outputting ISM/OMASA/OSBA, ensure the output metadata files are opened */
        for ( int16_t i = 0; i < *pNumObj; ++i )
        {
            if ( ismWriters[i] == NULL )
            {
                if ( ( error = IsmFileWriter_open( outputWavFilename, i, &ismWriters[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError: Error opening ISM decoded metadata file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) );
                    return error;
                }
            }
        }
    }

    /* If outputting MASA, ensure the output file metadata is opened */
    if ( *pBsFormat == IVAS_DEC_BS_MASA || *pBsFormat == IVAS_DEC_BS_MASA_ISM )
    {
        if ( ppMasaWriter != NULL )
        {
            if ( ( error = MasaFileWriter_open( outputWavFilename, delayCompensationEnabled, ppMasaWriter ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError: Error opening MASA decoded metadata file %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) );
                return error;
            }
        }
    }

    return IVAS_ERR_OK;
}
#endif

#undef WMC_TOOL_SKIP
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@

#define FIX_1576_LCLD_CRASH_DIFFERENT_CODEC_ISAR_FRAME_SIZE  /* Dolby: float issue 1576: fix for crash in LCLD mode when codec frame size is less than isar frame size */
#define FIX_BASOP_2442_MASA2TC_TO_MONO_AND_AMBI         /* Nokia: BASOP issue 2442: Aligns float with identical diffuse gain limitation to minimize diff */
#define FIX_FMSW_DEC_EXT                                /* float issue 1566: fix EXT output in format switching */

/* ##################### End NON-BE switches ########################### */