Commit fa7154d5 authored by sbsarac's avatar sbsarac
Browse files

Add quaternion file writer

parent 728f91d6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@
    <ClCompile Include="..\lib_util\cmdl_tools.c" />
    <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\vector3_pair_file_reader.c" />
    <ClCompile Include="..\lib_util\hrtf_file_reader.c" />
    <ClCompile Include="..\lib_util\ism_file_reader.c" />
@@ -134,6 +135,7 @@
    <ClInclude Include="..\lib_util\cmdl_tools.h" />
    <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\vector3_pair_file_reader.h" />
    <ClInclude Include="..\lib_util\hrtf_file_reader.h" />
    <ClInclude Include="..\lib_util\ism_file_reader.h" />
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@
#include "masa_file_writer.h"
#include "render_config_reader.h"
#include "rotation_file_reader.h"
#ifdef NONBE_FIX_1100_OUTPUT_ORIENT
#include "quaternion_file_writer.h"
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "split_render_file_read_write.h"
#endif
+160 −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 "quaternion_file_writer.h"
#ifdef NONBE_FIX_1100_OUTPUT_ORIENT
#include <stdlib.h>
#include <string.h>


#define META_LINE_LENGTH 200 /* max number of characters at one line of metadata input/output file */


struct QuaternionFileWriter
{
    FILE *file;
    char *file_path;
};

/*---------------------------------------------------------------------*
 * QuaternionFileWriter_open()
 *
 * Allocates memory for an QuaternionFileReader and opens the file at given path for writing.
 *---------------------------------------------------------------------*/

/*! r: error code */
ivas_error QuaternionFileWriter_open(
    const char *filePath,             /* i  : path to output file                     */
    QuaternionFileWriter **quatWriter /* o  : pointer to QuaternionFileWriter handle  */
)
{
    QuaternionFileWriter *self;
    FILE *file;

    if ( strlen( filePath ) < 1 )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    file = fopen( filePath, "w" );

    if ( !file )
    {
        return IVAS_ERR_FAILED_FILE_OPEN;
    }

    self = calloc( sizeof( QuaternionFileWriter ), 1 );
    self->file = file;
    self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 );
    strcpy( self->file_path, filePath );

    *quatWriter = self;

    return IVAS_ERR_OK;
}

/*---------------------------------------------------------------------*
 * QuaternionFileWriter_writeFrame()
 *
 * Writes quaternion data into a previously opened file
 *---------------------------------------------------------------------*/

/*! r: error code */
ivas_error QuaternionFileWriter_writeFrame(
    QuaternionFileWriter *quatWriter, /* o  : QuaternionFileWriter handle             */
    const IVAS_QUATERNION quatData    /* i  : Quaternion data                         */
)
{
    FILE *file;

    if ( quatWriter->file == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    file = quatWriter->file;

    if ( file )
    {
        fprintf( file, "%f,%f,%f,%f\n", quatData.w, quatData.x, quatData.y, quatData.z );
    }
    else
    {
        return IVAS_ERR_FAILED_FILE_WRITE;
    }

    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * QuaternionFileWriter_close()
 *
 * De-allocates all underlying memory of an QuaternionFileWriter.
 *---------------------------------------------------------------------*/

void QuaternionFileWriter_close(
    QuaternionFileWriter **quatWriter /* i/o: pointer to QuaternionFileWriter handle    */
)
{
    if ( quatWriter == NULL || *quatWriter == NULL )
    {
        return;
    }

    fclose( ( *quatWriter )->file );
    free( ( *quatWriter )->file_path );
    free( *quatWriter );
    *quatWriter = NULL;

    return;
}


/*---------------------------------------------------------------------*
 * IsmFileWriter_getFilePath()
 *
 *---------------------------------------------------------------------*/

/*! r: path to the currently opened file or NULL if `ismWriter` is NULL */
const char *QuaternionFileWriter_getFilePath(
    QuaternionFileWriter *quatWriter /* i  : QuaternionFileWriter handle                */
)
{
    if ( quatWriter == NULL )
    {
        return NULL;
    }

    return quatWriter->file_path;
}
#endif
+69 −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.

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

#ifndef IVAS_QUATERNION_WRITER_H
#define IVAS_QUATERNION_WRITER_H

#include "common_api_types.h"

#ifdef NONBE_FIX_1100_OUTPUT_ORIENT

typedef struct QuaternionFileWriter QuaternionFileWriter;

/* clang-format off */

/*! r: error code */
ivas_error QuaternionFileWriter_open(
    const char *filePath,                   /* i  : path to output file                     */
    QuaternionFileWriter **quatWriter       /* o  : pointer to QuaternionFileWriter handle  */
);

/*! r: error code */
ivas_error QuaternionFileWriter_writeFrame(
    QuaternionFileWriter *quatWriter,       /* o  : QuaternionFileWriter handle             */
    const IVAS_QUATERNION quatData          /* i  : Quaternion data                         */
);

void QuaternionFileWriter_close(
    QuaternionFileWriter **quatWriter       /* i/o: pointer to QuaternionFileWriter handle  */
);

/*! r: path to the currently opened file or NULL if `ismWriter` is NULL */
const char *QuaternionFileWriter_getFilePath(
    QuaternionFileWriter *quatWriter        /* i  : QuaternionFileWriter handle             */
);

/* clang-format on */

#endif

#endif /* IVAS_QUATERNION_WRITER_H */