Loading lib_util/head_rotation_file_writer.c 0 → 100644 +177 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2023 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 "head_rotation_file_writer.h" #include <stdlib.h> #include <string.h> #include <stdint.h> #include "prot.h" struct HeadRotFileWriter { FILE *trajFile; int32_t frameCounter; char *file_path; bool fileRewind; }; /*-----------------------------------------------------------------------* * HeadRotationFileWriter_open() * * Allocate and initialize Head-Tracking reader *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriter_open( char *trajFilePath, /* i : head rotation trajectory file name */ HeadRotFileWriter **headRotWriter /* o : HeadRotFileReader handle */ ) { HeadRotFileWriter *self; FILE *trajFile; /* Open trajectory file */ if ( strlen( trajFilePath ) < 1 ) { return IVAS_ERR_FAILED_FILE_OPEN; } trajFile = fopen( trajFilePath, "r" ); if ( !trajFile ) { return IVAS_ERR_FAILED_FILE_OPEN; } self = calloc( sizeof( HeadRotFileWriter ), 1 ); self->trajFile = trajFile; self->frameCounter = 0; self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); strcpy( self->file_path, trajFilePath ); self->fileRewind = false; *headRotWriter = self; return IVAS_ERR_OK; } /*-----------------------------------------------------------------------* * HeadRotationFileWriting() * * Write values to the trajectory file *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriting( HeadRotFileWriter *headRotWriter, /* i/o: HeadRotFileReader handle */ IVAS_QUATERNION *pQuaternion, /* o : head-tracking data */ IVAS_POSITION *pPos /* o : listener position */ ) { float w, x, y, z; float posx, posy, posz; int32_t read_values; posx = 0.0f; posy = 0.0f; posz = 0.0f; read_values = fscanf( headRotWriter->trajFile, "%f,%f,%f,%f,%f,%f,%f", &w, &x, &y, &z, &posx, &posy, &posz ); if ( ( read_values != 4 ) && ( read_values != 7 ) ) /* Allow either orientation (4) or orientation+position (4+3) */ { if ( feof( headRotWriter->trajFile ) ) { rewind( headRotWriter->trajFile ); headRotWriter->fileRewind = true; return HeadRotationFileWriting( headRotWriter, pQuaternion, pPos ); } return IVAS_ERR_FAILED_FILE_PARSE; } ( headRotWriter->frameCounter )++; pQuaternion->w = w; pQuaternion->x = x; pQuaternion->y = y; pQuaternion->z = z; if ( pPos != NULL ) { pPos->x = posx; pPos->y = posy; pPos->z = posz; } return IVAS_ERR_OK; } /*-----------------------------------------------------------------------* * HeadRotationFileWriter_close() * * Deallocates memory for the Head-Tracking writer *-----------------------------------------------------------------------*/ void HeadRotationFileWriter_close( HeadRotFileWriter **headRotWriter /* i/o: HeadRotFileReader handle */ ) { if ( headRotWriter == NULL || *headRotWriter == NULL ) { return; } fclose( ( *headRotWriter )->trajFile ); free( ( *headRotWriter )->file_path ); free( *headRotWriter ); *headRotWriter = NULL; return; } /*-----------------------------------------------------------------------* * HeadRotationFileWriter_getFilePath() * * *-----------------------------------------------------------------------*/ const char *HeadRotationFileWriter_getFilePath( HeadRotFileWriter *headRotWriter /* i/o: HeadRotFileReader handle */ ) { if ( headRotWriter == NULL ) { return NULL; } return headRotWriter->file_path; } lib_util/head_rotation_file_writer.h 0 → 100644 +85 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2023 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_HR_FILE_WRITER_H #define IVAS_HR_FILE_WRITER_H #include "common_api_types.h" #include "head_rotation_file_reader.h" typedef struct HeadRotFileWriter HeadRotFileWriter; /*-----------------------------------------------------------------------* * HeadRotationFileWriter_open() * * Allocate and initialize Head-Tracking handle *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriter_open( char *trajFilePath, /* i : head rotation trajectory file name */ HeadRotFileWriter **headRotWRiter /* o : HeadRotFileReader handle */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriting() * * Writes values to the trajectory file *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriting( HeadRotFileWriter *headRotWriter, /* i/o: HeadRotFileReader handle */ IVAS_QUATERNION *pQuaternion, /* o : head-tracking data */ IVAS_POSITION *pPos /* o : listener position */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriter_close() * * Deallocates memory for the Head-Tracking handle *-----------------------------------------------------------------------*/ void HeadRotationFileWriter_close( HeadRotFileWriter **headRotWriter /* i/o: HeadRotFileReader handle */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriter_getFilePath() * * *-----------------------------------------------------------------------*/ const char *HeadRotationFileWriter_getFilePath( HeadRotFileWriter *headRotWriter /* i/o: HeadRotFileReader handle */ ); #endif /* IVAS_HR_FILE_WRITER_H */ Loading
lib_util/head_rotation_file_writer.c 0 → 100644 +177 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2023 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 "head_rotation_file_writer.h" #include <stdlib.h> #include <string.h> #include <stdint.h> #include "prot.h" struct HeadRotFileWriter { FILE *trajFile; int32_t frameCounter; char *file_path; bool fileRewind; }; /*-----------------------------------------------------------------------* * HeadRotationFileWriter_open() * * Allocate and initialize Head-Tracking reader *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriter_open( char *trajFilePath, /* i : head rotation trajectory file name */ HeadRotFileWriter **headRotWriter /* o : HeadRotFileReader handle */ ) { HeadRotFileWriter *self; FILE *trajFile; /* Open trajectory file */ if ( strlen( trajFilePath ) < 1 ) { return IVAS_ERR_FAILED_FILE_OPEN; } trajFile = fopen( trajFilePath, "r" ); if ( !trajFile ) { return IVAS_ERR_FAILED_FILE_OPEN; } self = calloc( sizeof( HeadRotFileWriter ), 1 ); self->trajFile = trajFile; self->frameCounter = 0; self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); strcpy( self->file_path, trajFilePath ); self->fileRewind = false; *headRotWriter = self; return IVAS_ERR_OK; } /*-----------------------------------------------------------------------* * HeadRotationFileWriting() * * Write values to the trajectory file *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriting( HeadRotFileWriter *headRotWriter, /* i/o: HeadRotFileReader handle */ IVAS_QUATERNION *pQuaternion, /* o : head-tracking data */ IVAS_POSITION *pPos /* o : listener position */ ) { float w, x, y, z; float posx, posy, posz; int32_t read_values; posx = 0.0f; posy = 0.0f; posz = 0.0f; read_values = fscanf( headRotWriter->trajFile, "%f,%f,%f,%f,%f,%f,%f", &w, &x, &y, &z, &posx, &posy, &posz ); if ( ( read_values != 4 ) && ( read_values != 7 ) ) /* Allow either orientation (4) or orientation+position (4+3) */ { if ( feof( headRotWriter->trajFile ) ) { rewind( headRotWriter->trajFile ); headRotWriter->fileRewind = true; return HeadRotationFileWriting( headRotWriter, pQuaternion, pPos ); } return IVAS_ERR_FAILED_FILE_PARSE; } ( headRotWriter->frameCounter )++; pQuaternion->w = w; pQuaternion->x = x; pQuaternion->y = y; pQuaternion->z = z; if ( pPos != NULL ) { pPos->x = posx; pPos->y = posy; pPos->z = posz; } return IVAS_ERR_OK; } /*-----------------------------------------------------------------------* * HeadRotationFileWriter_close() * * Deallocates memory for the Head-Tracking writer *-----------------------------------------------------------------------*/ void HeadRotationFileWriter_close( HeadRotFileWriter **headRotWriter /* i/o: HeadRotFileReader handle */ ) { if ( headRotWriter == NULL || *headRotWriter == NULL ) { return; } fclose( ( *headRotWriter )->trajFile ); free( ( *headRotWriter )->file_path ); free( *headRotWriter ); *headRotWriter = NULL; return; } /*-----------------------------------------------------------------------* * HeadRotationFileWriter_getFilePath() * * *-----------------------------------------------------------------------*/ const char *HeadRotationFileWriter_getFilePath( HeadRotFileWriter *headRotWriter /* i/o: HeadRotFileReader handle */ ) { if ( headRotWriter == NULL ) { return NULL; } return headRotWriter->file_path; }
lib_util/head_rotation_file_writer.h 0 → 100644 +85 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2023 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_HR_FILE_WRITER_H #define IVAS_HR_FILE_WRITER_H #include "common_api_types.h" #include "head_rotation_file_reader.h" typedef struct HeadRotFileWriter HeadRotFileWriter; /*-----------------------------------------------------------------------* * HeadRotationFileWriter_open() * * Allocate and initialize Head-Tracking handle *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriter_open( char *trajFilePath, /* i : head rotation trajectory file name */ HeadRotFileWriter **headRotWRiter /* o : HeadRotFileReader handle */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriting() * * Writes values to the trajectory file *-----------------------------------------------------------------------*/ ivas_error HeadRotationFileWriting( HeadRotFileWriter *headRotWriter, /* i/o: HeadRotFileReader handle */ IVAS_QUATERNION *pQuaternion, /* o : head-tracking data */ IVAS_POSITION *pPos /* o : listener position */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriter_close() * * Deallocates memory for the Head-Tracking handle *-----------------------------------------------------------------------*/ void HeadRotationFileWriter_close( HeadRotFileWriter **headRotWriter /* i/o: HeadRotFileReader handle */ ); /*-----------------------------------------------------------------------* * HeadRotationFileWriter_getFilePath() * * *-----------------------------------------------------------------------*/ const char *HeadRotationFileWriter_getFilePath( HeadRotFileWriter *headRotWriter /* i/o: HeadRotFileReader handle */ ); #endif /* IVAS_HR_FILE_WRITER_H */