Loading lib_util/jbm_file_reader.c 0 → 100644 +181 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022 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 "jbm_file_reader.h" #include "cmdl_tools.h" #include <stdio.h> #include <stdlib.h> #include <string.h> struct JbmFileReader { FILE *file; char *file_path; }; /*---------------------------------------------------------------------* * JbmFileReader_open() * * Allocates memory for an JbmFileReader and opens the file at given path for reading. *---------------------------------------------------------------------*/ /*! r: JbmFileReader handle */ JbmFileReader *JbmFileReader_open( const char *filePath /* i : path to CA config file */ ) { JbmFileReader *self; FILE *file; if ( !filePath ) { return NULL; } file = fopen( filePath, "rb" ); if ( !file ) { return NULL; } self = calloc( sizeof( JbmFileReader ), 1 ); self->file = file; self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); strcpy( self->file_path, filePath ); return self; } /*---------------------------------------------------------------------* * JbmFileReader_readCAconfig() * * Read Chanel-aware config. entry *---------------------------------------------------------------------*/ ivas_error JbmFileReader_readCAconfig( JbmFileReader* self, /* i/o: JbmFileReader handle */ IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ ) { char rline[10], str[4]; int16_t tmp; /* Initialize */ caConfig->fec_offset = 0; caConfig->fec_indicator = IVAS_ENC_FEC_HI; while ( fgets( rline, 10, self->file ) == NULL && feof( self->file ) ) { rewind( self->file ); } if ( sscanf( rline, "%s %hd", str, &tmp ) != 2 ) { fprintf( stderr, "Error in the RF configuration file. There is no proper configuration line.\n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } /* Read RF FEC indicator */ to_upper( str ); if ( strcmp( str, "HI" ) == 0 ) { caConfig->fec_indicator = IVAS_ENC_FEC_HI; } else if ( strcmp( str, "LO" ) == 0 ) { caConfig->fec_indicator = IVAS_ENC_FEC_LO; } else { fprintf( stderr, "Error: Incorrect FEC indicator string. Exiting the encoder.\n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } /* Read RF FEC offset */ if ( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) { caConfig->fec_offset = tmp; } else { fprintf( stderr, "Error: incorrect FEC offset specified in the RF configuration file; RF offset can be 2, 3, 5, or 7. \n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } return IVAS_ERR_OK; } /*---------------------------------------------------------------------* * JbmFileReader_close() * * De-allocates all underlying memory of an JbmFileReader. *---------------------------------------------------------------------*/ void JbmFileReader_close( JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ ) { if ( selfPtr == NULL || *selfPtr == NULL ) { return; } fclose( ( *selfPtr )->file ); free( ( *selfPtr )->file_path ); free( *selfPtr ); *selfPtr = NULL; return; } /*---------------------------------------------------------------------* * JbmFileReader_getFilePath() * *---------------------------------------------------------------------*/ const char *JbmFileReader_getFilePath( JbmFileReader *self /* i/o: JbmFileReader handle */ ) { if ( self == NULL ) { return NULL; } return self->file_path; } lib_util/jbm_file_reader.h 0 → 100644 +67 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022 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_JBM_FILE_READER_H #define IVAS_JBM_FILE_READER_H #include <stdint.h> #include "common_api_types.h" #include "ivas_error.h" /* clang-format off */ typedef struct JbmFileReader JbmFileReader; /*! r: JbmFileReader handle */ JbmFileReader *JbmFileReader_open( const char *filePath /* i : path to CA config file */ ); ivas_error JbmFileReader_readCAconfig( JbmFileReader* self, /* i/o: JbmFileReader handle */ IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ ); void JbmFileReader_close( JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ ); /*! r: path to the currently opened file or NULL if `self` is NULL */ const char *JbmFileReader_getFilePath( JbmFileReader* self /* i/o: JbmFileReader handle */ ); /* clang-format on */ #endif /* IVAS_JBM_FILE_READER_H */ Loading
lib_util/jbm_file_reader.c 0 → 100644 +181 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022 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 "jbm_file_reader.h" #include "cmdl_tools.h" #include <stdio.h> #include <stdlib.h> #include <string.h> struct JbmFileReader { FILE *file; char *file_path; }; /*---------------------------------------------------------------------* * JbmFileReader_open() * * Allocates memory for an JbmFileReader and opens the file at given path for reading. *---------------------------------------------------------------------*/ /*! r: JbmFileReader handle */ JbmFileReader *JbmFileReader_open( const char *filePath /* i : path to CA config file */ ) { JbmFileReader *self; FILE *file; if ( !filePath ) { return NULL; } file = fopen( filePath, "rb" ); if ( !file ) { return NULL; } self = calloc( sizeof( JbmFileReader ), 1 ); self->file = file; self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); strcpy( self->file_path, filePath ); return self; } /*---------------------------------------------------------------------* * JbmFileReader_readCAconfig() * * Read Chanel-aware config. entry *---------------------------------------------------------------------*/ ivas_error JbmFileReader_readCAconfig( JbmFileReader* self, /* i/o: JbmFileReader handle */ IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ ) { char rline[10], str[4]; int16_t tmp; /* Initialize */ caConfig->fec_offset = 0; caConfig->fec_indicator = IVAS_ENC_FEC_HI; while ( fgets( rline, 10, self->file ) == NULL && feof( self->file ) ) { rewind( self->file ); } if ( sscanf( rline, "%s %hd", str, &tmp ) != 2 ) { fprintf( stderr, "Error in the RF configuration file. There is no proper configuration line.\n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } /* Read RF FEC indicator */ to_upper( str ); if ( strcmp( str, "HI" ) == 0 ) { caConfig->fec_indicator = IVAS_ENC_FEC_HI; } else if ( strcmp( str, "LO" ) == 0 ) { caConfig->fec_indicator = IVAS_ENC_FEC_LO; } else { fprintf( stderr, "Error: Incorrect FEC indicator string. Exiting the encoder.\n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } /* Read RF FEC offset */ if ( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) { caConfig->fec_offset = tmp; } else { fprintf( stderr, "Error: incorrect FEC offset specified in the RF configuration file; RF offset can be 2, 3, 5, or 7. \n" ); return IVAS_ERR_INVALID_FEC_CONFIG; } return IVAS_ERR_OK; } /*---------------------------------------------------------------------* * JbmFileReader_close() * * De-allocates all underlying memory of an JbmFileReader. *---------------------------------------------------------------------*/ void JbmFileReader_close( JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ ) { if ( selfPtr == NULL || *selfPtr == NULL ) { return; } fclose( ( *selfPtr )->file ); free( ( *selfPtr )->file_path ); free( *selfPtr ); *selfPtr = NULL; return; } /*---------------------------------------------------------------------* * JbmFileReader_getFilePath() * *---------------------------------------------------------------------*/ const char *JbmFileReader_getFilePath( JbmFileReader *self /* i/o: JbmFileReader handle */ ) { if ( self == NULL ) { return NULL; } return self->file_path; }
lib_util/jbm_file_reader.h 0 → 100644 +67 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022 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_JBM_FILE_READER_H #define IVAS_JBM_FILE_READER_H #include <stdint.h> #include "common_api_types.h" #include "ivas_error.h" /* clang-format off */ typedef struct JbmFileReader JbmFileReader; /*! r: JbmFileReader handle */ JbmFileReader *JbmFileReader_open( const char *filePath /* i : path to CA config file */ ); ivas_error JbmFileReader_readCAconfig( JbmFileReader* self, /* i/o: JbmFileReader handle */ IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ ); void JbmFileReader_close( JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ ); /*! r: path to the currently opened file or NULL if `self` is NULL */ const char *JbmFileReader_getFilePath( JbmFileReader* self /* i/o: JbmFileReader handle */ ); /* clang-format on */ #endif /* IVAS_JBM_FILE_READER_H */