make the 'name' and 'value' fields in ast_variable const char *
[asterisk/asterisk.git] / codecs / codec_speex.c
index 182b33e..bbb6be2 100644 (file)
@@ -375,37 +375,37 @@ static struct ast_translator lintospeex = {
        .buf_size = BUFFER_SAMPLES * 2, /* XXX maybe a lot less ? */
 };
 
-static void parse_config(void) 
+static int parse_config(int reload) 
 {
-       struct ast_config *cfg = ast_config_load("codecs.conf");
+       struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+       struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
        struct ast_variable *var;
        int res;
        float res_f;
 
-       if (cfg == NULL)
-               return;
+       if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
+               return -1;
+       if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+               return 0;
 
        for (var = ast_variable_browse(cfg, "speex"); var; var = var->next) {
                if (!strcasecmp(var->name, "quality")) {
                        res = abs(atoi(var->value));
                        if (res > -1 && res < 11) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Quality to %d\n",res);
+                               ast_verb(3, "CODEC SPEEX: Setting Quality to %d\n",res);
                                quality = res;
                        } else 
                                ast_log(LOG_ERROR,"Error Quality must be 0-10\n");
                } else if (!strcasecmp(var->name, "complexity")) {
                        res = abs(atoi(var->value));
                        if (res > -1 && res < 11) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Complexity to %d\n",res);
+                               ast_verb(3, "CODEC SPEEX: Setting Complexity to %d\n",res);
                                complexity = res;
                        } else 
                                ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n");
                } else if (!strcasecmp(var->name, "vbr_quality")) {
                        if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0 && res_f <= 10) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
+                               ast_verb(3, "CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
                                vbr_quality = res_f;
                        } else
                                ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n");
@@ -413,83 +413,70 @@ static void parse_config(void)
                        ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n");
                } else if (!strcasecmp(var->name, "enhancement")) {
                        enhancement = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off");
                } else if (!strcasecmp(var->name, "vbr")) {
                        vbr = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off");
                } else if (!strcasecmp(var->name, "abr")) {
                        res = abs(atoi(var->value));
                        if (res >= 0) {
-                               if (option_verbose > 2) {
                                        if (res > 0)
-                                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
+                                       ast_verb(3, "CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
                                        else
-                                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Disabling ABR\n");
-                               }
+                                       ast_verb(3, "CODEC SPEEX: Disabling ABR\n");
                                abr = res;
                        } else 
                                ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n");
                } else if (!strcasecmp(var->name, "vad")) {
                        vad = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off");
                } else if (!strcasecmp(var->name, "dtx")) {
                        dtx = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off");
                } else if (!strcasecmp(var->name, "preprocess")) {
                        preproc = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off");
                } else if (!strcasecmp(var->name, "pp_vad")) {
                        pp_vad = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off");
                } else if (!strcasecmp(var->name, "pp_agc")) {
                        pp_agc = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off");
                } else if (!strcasecmp(var->name, "pp_agc_level")) {
                        if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
+                               ast_verb(3, "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
                                pp_agc_level = res_f;
                        } else
                                ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n");
                } else if (!strcasecmp(var->name, "pp_denoise")) {
                        pp_denoise = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off");
                } else if (!strcasecmp(var->name, "pp_dereverb")) {
                        pp_dereverb = ast_true(var->value) ? 1 : 0;
-                       if (option_verbose > 2)
-                               ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off");
+                       ast_verb(3, "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off");
                } else if (!strcasecmp(var->name, "pp_dereverb_decay")) {
                        if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
+                               ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
                                pp_dereverb_decay = res_f;
                        } else
                                ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n");
                } else if (!strcasecmp(var->name, "pp_dereverb_level")) {
                        if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
-                               if (option_verbose > 2)
-                                       ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
+                               ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
                                pp_dereverb_level = res_f;
                        } else
                                ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n");
                }
        }
        ast_config_destroy(cfg);
+       return 0;
 }
 
 static int reload(void) 
 {
-       parse_config();
-
-       return 0;
+       if (parse_config(1))
+               return AST_MODULE_LOAD_DECLINE;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)
@@ -506,14 +493,16 @@ static int load_module(void)
 {
        int res;
 
-       parse_config();
+       if (parse_config(0))
+               return AST_MODULE_LOAD_DECLINE;
        res=ast_register_translator(&speextolin);
        if (!res) 
                res=ast_register_translator(&lintospeex);
        else
                ast_unregister_translator(&speextolin);
-
-       return res;
+       if (res)
+               return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Speex Coder/Decoder",