Commit cde72ad2 authored by sbsarac's avatar sbsarac
Browse files

Merge branch '1066-orientation-output-functions' into...

Merge branch '1066-orientation-output-functions' into 1100-output-main-tracked-combined-orientation-decoder
parents f9fc23f9 9a1dbd49
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@
    <ClCompile Include="..\lib_util\evs_rtp_payload.c" />
    <ClCompile Include="..\lib_util\g192.c" />
    <ClCompile Include="..\lib_util\quaternion_file_writer.c" />
    <ClCompile Include="..\lib_util\rotation_file_writer.c" />
    <ClCompile Include="..\lib_util\vector3_pair_file_reader.c" />
    <ClCompile Include="..\lib_util\hrtf_file_reader.c" />
    <ClCompile Include="..\lib_util\ism_file_reader.c" />
@@ -138,6 +139,7 @@
    <ClInclude Include="..\lib_util\evs_rtp_payload.h" />
    <ClInclude Include="..\lib_util\g192.h" />
    <ClInclude Include="..\lib_util\quaternion_file_writer.h" />
    <ClInclude Include="..\lib_util\rotation_file_writer.h" />
    <ClInclude Include="..\lib_util\vector3_pair_file_reader.h" />
    <ClInclude Include="..\lib_util\hrtf_file_reader.h" />
    <ClInclude Include="..\lib_util\ism_file_reader.h" />
+157 −1
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@
#include "masa_file_writer.h"
#include "render_config_reader.h"
#include "rotation_file_reader.h"
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
#include "rotation_file_writer.h"
#endif
#ifdef FIX_1053_REVERB_RECONFIGURATION
#include "aeid_file_reader.h"
#endif
@@ -178,6 +181,11 @@ typedef struct
    char externalOrientationFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char customHrtfFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char renderConfigFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    char mainOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char trackedOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
    char combinedOrientationOutputFilePath[RENDERER_MAX_CLI_ARG_LENGTH];
#endif
    int8_t orientation_tracking;
    int16_t nonDiegeticPan;
    float nonDiegeticPanGain;
@@ -229,6 +237,11 @@ typedef enum
#endif
    CmdLnOptionId_referenceVectorFile,
    CmdLnOptionId_exteriorOrientationFile,
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    CmdLnOptionId_mainOrientationOutputFile,
    CmdLnOptionId_trackedRotationOutputFile,
    CmdLnOptionId_combinedOrientationOutputFile,
#endif
    CmdLnOptionId_framing,
    CmdLnOptionId_syncMdDelay,
    CmdLnOptionId_directivityPatternId,
@@ -380,6 +393,26 @@ static const CmdLnParser_Option cliOptions[] = {
        .matchShort = "exof",
        .description = "External orientation trajectory file for simulation of external orientations",
    },
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    {
        .id = CmdLnOptionId_mainOrientationOutputFile,
        .match = "main_orientation_output_file",
        .matchShort = "moof",
        .description = "Main orientation output file",
    },
    {
        .id = CmdLnOptionId_trackedRotationOutputFile,
        .match = "tracked_rotation_output_file",
        .matchShort = "trof",
        .description = "Tracked rotation output file",
    },
    {
        .id = CmdLnOptionId_combinedOrientationOutputFile,
        .match = "combined_orientation_output_file",
        .matchShort = "coof",
        .description = "Combined orientation output file",
    },
#endif
    {
        .id = CmdLnOptionId_framing,
        .match = "framing",
@@ -690,6 +723,11 @@ int main(
    RotFileReader *headRotReader = NULL;
    RotFileReader *externalOrientationFileReader = NULL;
    RotFileReader *referenceRotReader = NULL;
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    RotFileWriter *mainOrientationFileWriter = NULL;
    RotFileWriter *trackedRotationFileWriter = NULL;
    RotFileWriter *combinedOrientationFileWriter = NULL;
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_CLDFB_FILTER_BANK_HANDLE cldfbAna[IVAS_MAX_INPUT_CHANNELS];
    IVAS_CLDFB_FILTER_BANK_HANDLE cldfbSyn[IVAS_MAX_INPUT_CHANNELS];
@@ -803,6 +841,11 @@ int main(
    convert_backslash( args.referenceRotationFilePath );
    convert_backslash( args.inLfePanningMatrixFile );
    convert_backslash( args.externalOrientationFilePath );
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    convert_backslash( args.mainOrientationOutputFilePath );
    convert_backslash( args.trackedOrientationOutputFilePath );
    convert_backslash( args.combinedOrientationOutputFilePath );
#endif

        if ( !isEmptyString( args.headRotationFilePath ) )
    {
@@ -846,6 +889,34 @@ int main(
        }
    }

#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    if ( !isEmptyString( args.mainOrientationOutputFilePath ) )
    {
        if ( RotationFileWriter_open( args.mainOrientationOutputFilePath, &mainOrientationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.mainOrientationOutputFilePath );
            exit( -1 );
        }
    }

    if ( !isEmptyString( args.trackedOrientationOutputFilePath ) )
    {
        if ( RotationFileWriter_open( args.trackedOrientationOutputFilePath, &trackedRotationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.trackedOrientationOutputFilePath );
            exit( -1 );
        }
    }

    if ( !isEmptyString( args.combinedOrientationOutputFilePath ) )
    {
        if ( RotationFileWriter_open( args.combinedOrientationOutputFilePath, &combinedOrientationFileWriter ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Error opening file: %s\n", args.combinedOrientationOutputFilePath );
            exit( -1 );
        }
    }
#endif

    if ( !isEmptyString( args.renderConfigFilePath ) )
    {
@@ -1723,6 +1794,65 @@ int main(
            }
        }

#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
        if ( mainOrientationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION mainOrientation;

                if ( ( error = IVAS_REND_GetMainOrientation( hIvasRend, &mainOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( mainOrientationFileWriter, &mainOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }

        if ( trackedRotationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION trackedRotation;

                if ( ( error = IVAS_REND_GetTrackedRotation( hIvasRend, &trackedRotation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( trackedRotationFileWriter, &trackedRotation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }

        if ( combinedOrientationFileWriter != NULL )
        {
            for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ )
            {
                IVAS_QUATERNION combinedOrientation;

                if ( ( error = IVAS_REND_GetCombinedOrientation( hIvasRend, &combinedOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while getting main orientation: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
                if ( ( error = RotationFileWriter_write( combinedOrientationFileWriter, &combinedOrientation ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error while writing main orientation data: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
        }
#endif

        /* Combine external orientations and head rotation */

        if ( ( error = IVAS_REND_CombineHeadAndExternalOrientation( hIvasRend ) ) != IVAS_ERR_OK )
@@ -2126,9 +2256,15 @@ cleanup:
    MasaFileWriter_close( &masaWriter );
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );

    RotationFileReader_close( &headRotReader );
    RotationFileReader_close( &externalOrientationFileReader );
    RotationFileReader_close( &referenceRotReader );
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    RotationFileWriter_close( &mainOrientationFileWriter );
    RotationFileWriter_close( &trackedRotationFileWriter );
    RotationFileWriter_close( &combinedOrientationFileWriter );
#endif

    Vector3PairFileReader_close( &referenceVectorReader );
    destroy_td_hrtf( hHrtfTD );
@@ -2702,6 +2838,12 @@ static CmdlnArgs defaultArgs(
    clearString( args.renderConfigFilePath );
    clearString( args.externalOrientationFilePath );

#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
    clearString( args.mainOrientationOutputFilePath );
    clearString( args.trackedOrientationOutputFilePath );
    clearString( args.combinedOrientationOutputFilePath );
#endif

    args.orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
    args.nonDiegeticPan = 0;
    args.nonDiegeticPanGain = 0.f;
@@ -2818,6 +2960,20 @@ static void parseOption(
            assert( numOptionValues == 1 );
            strncpy( args->externalOrientationFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
        case CmdLnOptionId_mainOrientationOutputFile:
            assert( numOptionValues == 1 );
            strncpy( args->mainOrientationOutputFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
        case CmdLnOptionId_trackedRotationOutputFile:
            assert( numOptionValues == 1 );
            strncpy( args->trackedOrientationOutputFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
        case CmdLnOptionId_combinedOrientationOutputFile:
            assert( numOptionValues == 1 );
            strncpy( args->combinedOrientationOutputFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
            break;
#endif
        case CmdLnOptionId_customHrtfFile:
            assert( numOptionValues == 1 );
            strncpy( args->customHrtfFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 );
+1 −0
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@
#define FIX_1068_ASAN_IN_MC_2_BINAURAL_ROOM_IR          /* issue 1068 : Memory leak in MC to BINAURAL_ROOM decoding with bitrate switching*/
#define FIX_1050_EFAP_ALLOC                             /* FhG: issue 1050: reduction of memory allocated to EFAP handle */
#define NONBE_FIX_1100_OUTPUT_ORIENT                    /* Philips: issue 1100: Output for main/tracked/combined orientation for the decoder application */
#define FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS           /* Philips: issue 1066: orientation output functions support */

/* #################### End BE switches ################################## */

+6 −0
Original line number Diff line number Diff line
@@ -4818,7 +4818,9 @@ ivas_error IVAS_REND_SetReferenceRotation(
 *
 *
 *-------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetMainOrientation(
    IVAS_REND_HANDLE hIvasRend,   /* i/o: Renderer handle                           */
    IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer for main orientation   */
@@ -4845,7 +4847,9 @@ ivas_error IVAS_REND_GetMainOrientation(
 *
 *
 *-------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetTrackedRotation(
    IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle                             */
    IVAS_QUATERNION *pRotation  /* i/o: Quaternion pointer processed rotation       */
@@ -4953,7 +4957,9 @@ ivas_error IVAS_REND_CombineHeadAndExternalOrientation(
 *
 *
 *---------------------------------------------------------------------*/
#ifndef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS
// ToDo: not used
#endif
ivas_error IVAS_REND_GetCombinedOrientation(
    IVAS_REND_HANDLE hIvasRend,   /* i/o: Renderer handle                                */
    IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer processed orientation       */
+136 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/

#include "rotation_file_writer.h"
#ifdef FIX_1066_ORIENTATION_OUTPUT_FUNCTIONS

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "prot.h"


struct RotFileWriter
{
    FILE *pFile;
    char *filename;
};


/*-----------------------------------------------------------------------*
 * RotationFileWriter_open()
 *
 * Allocate and initialize rotation file writer
 *-----------------------------------------------------------------------*/

ivas_error RotationFileWriter_open(
    char *filename,         /* i  : output file name */
    RotFileWriter **pWriter /* o  : RotFileWriter handle          */
)
{
    RotFileWriter *self;
    FILE *pFile;

    /* Open trajectory file */
    if ( strlen( filename ) < 1 )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    pFile = fopen( filename, "wt" );

    if ( !pFile )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    self = calloc( sizeof( RotFileWriter ), 1 );
    self->pFile = pFile;
    self->filename = calloc( sizeof( char ), strlen( filename ) + 1 );
    strcpy( self->filename, filename );

    *pWriter = self;

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * RotationFileWriter_write()
 *
 * Reads values to the trajectory file
 *-----------------------------------------------------------------------*/

ivas_error RotationFileWriter_write(
    RotFileWriter *pWriter,
    IVAS_QUATERNION *pPose )
{
    int32_t bytes_written;

    if ( pWriter == NULL || pPose == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    if ( ( bytes_written = fprintf( pWriter->pFile, "%f,%f,%f,%f\n", pPose->w, pPose->x, pPose->y, pPose->z ) ) <= 0 )
    {
        return IVAS_ERR_FAILED_FILE_WRITE;
    }

    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * RotationFileWriter_close()
 *
 * Closes and deallocates the rotation file writer
 *-----------------------------------------------------------------------*/

void RotationFileWriter_close(
    RotFileWriter **pWriter /* i/o: RotFileWriter handle       */
)
{
    if ( pWriter == NULL || *pWriter == NULL )
    {
        return;
    }

    fclose( ( *pWriter )->pFile );
    free( ( *pWriter )->filename );
    free( *pWriter );
    *pWriter = NULL;

    return;
}

#endif
Loading