Index: app_h324m.c =================================================================== --- app_h324m.c (révision 216) +++ app_h324m.c (copie de travail) @@ -46,6 +46,12 @@ #define AST_FRAME_DIGITAL 13 #endif +#ifndef i6net_config +#define DEFAULT_BOARDCODEC "both" +static char *config = "h324m.conf"; +static char boardcodec[20] = DEFAULT_BOARDCODEC; +#endif + static char *name_h324m_loopback = "h324m_loopback"; static char *syn_h324m_loopback = "H324m loopback mode"; static char *des_h324m_loopback = " h324m_loopback([options]): Establish H.324M connection and loopback media.\n" @@ -114,7 +120,91 @@ "to the Echo() application but only loops video (the Echo application loops\n" "audio and video). To use this function with H324M calls you first have to use\n" "the h324m_gw() function.\n"; + +#ifndef i6net_config +/* Configuration file */ +static int load_config(void) +{ + struct ast_config *cfg; + struct ast_variable *var; + char *tmp; + int level; + cfg = (void *)ast_config_load(config); + if (!cfg) + { + ast_log(LOG_WARNING, + "Unable to load config for h324m : %s\n", config); + return -1; + } + + var = (void *)ast_variable_browse(cfg, "general"); + if (!var) + { + ast_log(LOG_WARNING, "Nothing configured for h324m.\n"); + /* nothing configured */ + return 0; + } + + tmp = (void *)ast_variable_retrieve(cfg, "general", "debug"); + if (tmp) + { + if (sscanf(tmp, "%d", &level) < 0) + { + ast_log(LOG_WARNING, "Invalid debug.\n"); + level = 1; + } + if((level < 0) || (level > 9)) + { + ast_log(LOG_WARNING, "Invalid debug (>max).\n"); + level = 1; + } + else + { + H324MLoggerSetLevel(level); + } + } + else + { + level = 1; + } + + tmp = (void *)ast_variable_retrieve(cfg, "general", "boardcodec"); + if ((tmp) && (strlen(tmp) < 9)) + { + if (!strcmp(tmp, "alaw")) + strcpy(boardcodec, tmp); + else if (!strcmp(tmp, "ulaw")) + strcpy(boardcodec, tmp); + else if (!strcmp(tmp, "both")) + strcpy(boardcodec, tmp); + else + { + if (level > 0) + ast_verbose(VERBOSE_PREFIX_3 "Bad board law, set to %s.\n", + DEFAULT_BOARDCODEC); + strcpy(boardcodec, DEFAULT_BOARDCODEC); + } + + } + else + { + //if (debug) ast_verbose(VERBOSE_PREFIX_3 "Bad board codec, set to %s.\n",DEFAULT_BOARDCODEC); + strcpy(boardcodec, DEFAULT_BOARDCODEC); + } + + ast_config_destroy(cfg); + + if (level > 0) + { + ast_verbose(VERBOSE_PREFIX_3 "Debug level : %d\n", level); + ast_verbose(VERBOSE_PREFIX_3 "Board codec : %s\n", boardcodec); + } + + return 0; +} +#endif + /* Commands */ static int h324m_do_debug(int fd, int argc, char *argv[]) { @@ -160,6 +250,29 @@ "Set app_h324m debug log level", debug_usage }; +#ifndef i6net_config +/* Reload configuration */ +static int h324m_do_reload(int fd, int argc, char **argv) +{ + if (argc != 2) + return RESULT_SHOWUSAGE; + + ast_cli(fd, "Reloading h324 stack configuration\n"); + load_config(); + + return RESULT_SUCCESS; +} + +static char usage_reload[] = + "Usage: h324m reload \n" + " Reloads h324m stack configuration h324m.conf\n"; + +static struct ast_cli_entry cli_reload = { + {"h324m", "reload", NULL}, h324m_do_reload, + "Reload h324m stack configuration", usage_reload, NULL +}; +#endif + static short blockSize[16] = { 13, 14, 16, 18, 19, 21, 26, 31, 6, -1, -1, -1, -1, -1, -1, -1}; static short if2stuffing[16] = {5, 5, 6, 6, 0, 5, 0, 0, 5, 1, 6, 7, -1, -1, -1, 4}; @@ -217,18 +330,17 @@ unsigned char header = framedata[0]; /*Get mode*/ unsigned char mode = header & 0x0F; - - /* Check silence frames */ + if (mode==8 && framelength==6) { - /* save AMR-SID frame */ - memcpy( last_amr_sti, framedata, 6 ); - } else if (mode==15) { - /* AMR No-Data packet --> replace with last AMR-SID */ - mode = 8; - framelength = 6; - framedata = last_amr_sti; + /* save AMR-SID frame */ + memcpy( last_amr_sti, framedata, 6 ); + } else if (mode==15) { /* AMR No-Data packet --> replace with last AMR-SID */ + mode = 8; + framelength = 6; + framedata = last_amr_sti; } + /*Get number of stuffing bits*/ unsigned int stuf = if2stuffing[mode]; @@ -1029,8 +1141,23 @@ * Example for Austria(Europe): * pseudo = ast_request("Local", AST_FORMAT_ALAW , data, &reason); */ - pseudo = ast_request("Local", AST_FORMAT_ALAW , data, &reason); - + +#ifndef i6net_config + if (!strcmp(boardcodec, "alaw")) + { + ast_log(LOG_DEBUG, "h324m_call: forced request format: ALAW\n"); + pseudo = ast_request("Local", AST_FORMAT_ALAW , data, &reason); + } + else + if (!strcmp(boardcodec, "ulaw")) + { + ast_log(LOG_DEBUG, "h324m_call: forced request format: ALAW\n"); + pseudo = ast_request("Local", AST_FORMAT_ULAW , data, &reason); + } + else +#endif + pseudo = ast_request("Local", AST_FORMAT_ALAW | AST_FORMAT_ULAW, data, &reason); + /* If somthing has gone wrong */ if (!pseudo) /* goto end */ @@ -1396,6 +1523,11 @@ { int res; +#ifndef i6net_config + ast_cli_unregister(&cli_debug); + ast_cli_unregister(&cli_reload); +#endif + res = ast_unregister_application(name_h324m_loopback); res &= ast_unregister_application(name_h324m_gw); res &= ast_unregister_application(name_h324m_call); @@ -1404,8 +1536,6 @@ ast_module_user_hangup_all(); - ast_cli_unregister(&cli_debug); - return res; } @@ -1420,9 +1550,16 @@ res &= ast_register_application(name_video_loopback, app_video_loopback, syn_video_loopback, des_video_loopback); ast_cli_register(&cli_debug); - +#ifndef i6net_config + ast_cli_register(&cli_reload); +#endif + /* No loging by default */ H324MLoggerSetLevel(1); + +#ifndef i6net_config + load_config(); +#endif return 0; }