Fix the reading of .linpohne.ecstate

This commit is contained in:
François Grisez 2014-12-12 12:11:51 +01:00
parent 84e3d60838
commit db5fc6ea89
3 changed files with 26 additions and 21 deletions

View file

@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mssndcard.h"
static const char EC_STATE_STORE[] = ".linphone.ecstate";
static const size_t EC_STATE_MAX_LEN = 1048576; // 1Mo
static void linphone_call_stats_uninit(LinphoneCallStats *stats);
@ -1581,14 +1582,15 @@ void linphone_call_init_audio_stream(LinphoneCall *call){
audio_stream_enable_gain_control(audiostream,TRUE);
if (linphone_core_echo_cancellation_enabled(lc)){
int len,delay,framesize;
char *statestr=lp_config_read_relative_file(lc->config, EC_STATE_STORE);
char statestr[EC_STATE_MAX_LEN];
len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize);
if (statestr && audiostream->ec){
ms_filter_call_method(audiostream->ec,MS_ECHO_CANCELLER_SET_STATE_STRING,(void*)statestr);
ms_free(statestr);
if (audiostream->ec) {
if (lp_config_read_relative_file(lc->config, EC_STATE_STORE, statestr, EC_STATE_MAX_LEN) == 0) {
ms_filter_call_method(audiostream->ec, MS_ECHO_CANCELLER_SET_STATE_STRING, statestr);
}
}
}
audio_stream_enable_automatic_gain_control(audiostream,linphone_core_agc_enabled(lc));

View file

@ -734,25 +734,26 @@ void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filenam
}
}
char *lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename) {
int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length) {
char *dir = _lp_config_dirname(lpconfig->filename);
char *filepath = ms_strdup_printf("%s/%s", dir, filename);
char *result = NULL;
if(ortp_file_exist(filepath) == 0) {
FILE *file = fopen(filepath, "r");
if(file != NULL) {
result = ms_new0(char, MAX_LEN);
if(fgets(result, MAX_LEN, file) == NULL) {
ms_error("%s could not be loaded", filepath);
}
fclose(file);
} else {
ms_error("Could not open %s for read", filepath);
FILE *file = fopen(filepath, "r");
if(file != NULL) {
if(fgets(data, max_length, file) == NULL) {
ms_error("%s could not be loaded. %s", filepath, strerror(errno));
goto err;
}
fclose(file);
} else {
ms_message("%s does not exist", filepath);
ms_error("Could not open %s for read. %s", filepath, strerror(errno));
goto err;
}
ms_free(dir);
ms_free(filepath);
return result;
return 0;
err:
ms_free(dir);
ms_free(filepath);
return -1;
}

View file

@ -281,12 +281,14 @@ LINPHONE_PUBLIC void lp_config_unref(LpConfig *lpconfig);
LINPHONE_PUBLIC void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filename, const char *data);
/**
* @brief Read a string from a file placed relatively with the Linphone configuration file
* @brief Read a string from a file placed beside the Linphone configuration file
* @param lpconfig LpConfig instance used as a reference
* @param filename Name of the file where data will be read from. The name is relative to the place of the config file
* @return The read string
* @param data Buffer where read string will be stored
* @param max_length Length of the buffer
* @return 0 on success, -1 on failure
*/
LINPHONE_PUBLIC char *lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename);
LINPHONE_PUBLIC int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length);
#ifdef __cplusplus
}