diff --git a/linphone/console/commands.c b/linphone/console/commands.c index 486202d03..248951df7 100644 --- a/linphone/console/commands.c +++ b/linphone/console/commands.c @@ -32,6 +32,7 @@ #include #include #include "linphonec.h" +#include "private.h" #ifndef WIN32 #include @@ -69,6 +70,7 @@ static int lpc_cmd_duration(LinphoneCore *lc, char *args); static int lpc_cmd_status(LinphoneCore *lc, char *args); static int lpc_cmd_ports(LinphoneCore *lc, char *args); static int lpc_cmd_speak(LinphoneCore *lc, char *args); +static int lpc_cmd_codec(LinphoneCore *lc, char *args); /* Command handler helpers */ static void linphonec_proxy_add(LinphoneCore *lc); @@ -85,6 +87,10 @@ static int linphonec_friend_call(LinphoneCore *lc, unsigned int num); static int linphonec_friend_add(LinphoneCore *lc, const char *name, const char *addr); #endif static int linphonec_friend_delete(LinphoneCore *lc, int num); +static int linphonec_friend_delete(LinphoneCore *lc, int num); +static void linphonec_codec_list(LinphoneCore *lc); +static void linphonec_codec_enable(LinphoneCore *lc, int index); +static void linphonec_codec_disable(LinphoneCore *lc, int index); @@ -107,7 +113,7 @@ void linphonec_out(const char *fmt,...); LPC_COMMAND commands[] = { { "help", lpc_cmd_help, "Print commands help", NULL }, { "call", lpc_cmd_call, "Call a SIP uri", - "'call ' or 'c ' " + "'call ' " ": initiate a call to the specified destination." }, { "terminate", lpc_cmd_terminate, "Terminate the current call", @@ -191,6 +197,11 @@ LPC_COMMAND commands[] = { "'speak ' : speak a text using the specified espeak voice.\n" "Example for english voice: 'speak default Hello my friend !'" }, + { "codec", lpc_cmd_codec, "Codec configuration", + "'codec list' : list codecs\n" + "'codec enable ' : enable available codec\n" + "'codec disable ' : disable codecs" }, + { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL } }; @@ -1341,6 +1352,7 @@ static int lpc_cmd_register(LinphoneCore *lc, char *args){ char passwd[512]; LinphoneProxyConfig *cfg; const MSList *elem; + if (!args) return 0; passwd[0]=proxy[0]=identity[0]='\0'; sscanf(args,"%s %s %s",identity,proxy,passwd); if (proxy[0]=='\0' || identity[0]=='\0'){ @@ -1488,6 +1500,7 @@ static int lpc_cmd_speak(LinphoneCore *lc, char *args){ char *wavfile; int status; FILE *file; + if (!args) return 0; memset(voice,0,sizeof(voice)); sscanf(args,"%s63",voice); sentence=args+strlen(voice); @@ -1511,6 +1524,92 @@ static int lpc_cmd_speak(LinphoneCore *lc, char *args){ return 1; } +static int lpc_cmd_codec(LinphoneCore *lc, char *args){ + char *arg1 = args; + char *arg2 = NULL; + char *ptr = args; + + if (!args) return 0; + + /* Isolate first and second arg */ + while(*ptr && !isspace(*ptr)) ++ptr; + if ( *ptr ) + { + *ptr='\0'; + arg2=ptr+1; + while(*arg2 && isspace(*arg2)) ++arg2; + } + + if (strcmp(arg1,"enable")==0) + { +#ifdef HAVE_READLINE + rl_inhibit_completion=1; +#endif + if (!strcmp(arg2,"all")) linphonec_codec_enable(lc,-1); + else linphonec_codec_enable(lc,atoi(arg2)); +#ifdef HAVE_READLINE + rl_inhibit_completion=0; +#endif + } + else if (strcmp(arg1,"list")==0) + { + linphonec_codec_list(lc); + } + else if (strcmp(arg1,"disable")==0) + { + if (!strcmp(arg2,"all")) linphonec_codec_disable(lc,-1); + else linphonec_codec_disable(lc,atoi(arg2)); + } + else + { + return 0; /* syntax error */ + } + + return 1; +} + +static void linphonec_codec_list(LinphoneCore *lc){ + PayloadType *pt; + codecs_config_t *config=&lc->codecs_conf; + int index=0; + MSList *node; + for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){ + pt=(PayloadType*)(node->data); + linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, payload_type_enabled(pt) ? "enabled" : "disabled"); + index++; + } +} + +static void linphonec_codec_enable(LinphoneCore *lc, int sel_index){ + PayloadType *pt; + codecs_config_t *config=&lc->codecs_conf; + int index=0; + MSList *node; + for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){ + if (index == sel_index || sel_index == -1) { + pt=(PayloadType*)(node->data); + pt->flags|=PAYLOAD_TYPE_ENABLED; + linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "enabled"); + } + index++; + } +} + +static void linphonec_codec_disable(LinphoneCore *lc, int sel_index){ + PayloadType *pt; + codecs_config_t *config=&lc->codecs_conf; + int index=0; + MSList *node; + for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){ + if (index == sel_index || sel_index == -1) { + pt=(PayloadType*)(node->data); + pt->flags&=~PAYLOAD_TYPE_ENABLED; + linphonec_out("%2d: %s (%d) %s\n", index, pt->mime_type, pt->clock_rate, "disabled"); + } + index++; + } +} + /*************************************************************************** * * Command table management funx