diff options
-rw-r--r-- | modules/menu/menu.c | 96 |
1 files changed, 78 insertions, 18 deletions
diff --git a/modules/menu/menu.c b/modules/menu/menu.c index 3a34263..1ee4e73 100644 --- a/modules/menu/menu.c +++ b/modules/menu/menu.c @@ -47,6 +47,8 @@ static struct { static int menu_set_incall(bool incall); static void update_callstatus(void); static void alert_stop(void); +static int switch_audio_source(struct re_printf *pf, void *arg); +static int switch_audio_player(struct re_printf *pf, void *arg); static void redial_reset(void) @@ -419,6 +421,8 @@ static const struct cmd cmdv[] = { {NULL, KEYCODE_ESC,0, "Hangup call", cmd_hangup }, {"uanext", 'T', 0, "Toggle UAs", cmd_ua_next }, {"uanew", 0, CMD_PRM, "Create User-Agent", create_ua }, +{"ausrc", 0, CMD_IPRM, "Switch audio source", switch_audio_source }, +{"auplay", 0, CMD_IPRM, "Switch audio player", switch_audio_player }, }; @@ -525,7 +529,7 @@ static int hold_prev_call(struct re_printf *pf, void *arg) } -static int switch_audio_dev(struct re_printf *pf, void *arg) +static int switch_audio_player(struct re_printf *pf, void *arg) { const struct cmd_arg *carg = arg; struct pl pl_driver, pl_device; @@ -559,18 +563,27 @@ static int switch_audio_dev(struct re_printf *pf, void *arg) pl_strcpy(&pl_driver, driver, sizeof(driver)); pl_strcpy(&pl_device, device, sizeof(device)); - if (!ausrc_find(driver)) { - re_hprintf(pf, "no such audio-source: %s\n", driver); - return 0; - } if (!auplay_find(driver)) { re_hprintf(pf, "no such audio-player: %s\n", driver); return 0; } - re_hprintf(pf, "switch audio device: %s,%s\n", + re_hprintf(pf, "switch audio player: %s,%s\n", driver, device); + cfg = conf_config(); + if (!cfg) { + return re_hprintf(pf, "no config object\n"); + } + + aucfg = &cfg->audio; + + str_ncpy(aucfg->play_mod, driver, sizeof(aucfg->play_mod)); + str_ncpy(aucfg->play_dev, device, sizeof(aucfg->play_dev)); + + str_ncpy(aucfg->alert_mod, driver, sizeof(aucfg->alert_mod)); + str_ncpy(aucfg->alert_dev, device, sizeof(aucfg->alert_dev)); + for (le = list_tail(ua_calls(uag_cur())); le; le = le->prev) { struct call *call = le->data; @@ -583,15 +596,55 @@ static int switch_audio_dev(struct re_printf *pf, void *arg) " (%m)\n", err); break; } + } + } - err = audio_set_source(a, driver, device); - if (err) { - re_hprintf(pf, "failed to set audio-source" - " (%m)\n", err); - break; - } + return 0; +} + + +static int switch_audio_source(struct re_printf *pf, void *arg) +{ + const struct cmd_arg *carg = arg; + struct pl pl_driver, pl_device; + struct config_audio *aucfg; + struct config *cfg; + struct audio *a; + struct le *le; + char driver[16], device[128] = ""; + int err = 0; + + static bool switch_aud_inprogress; + + if (!switch_aud_inprogress && !carg->complete) { + re_hprintf(pf, + "\rPlease enter audio device (driver,device)\n"); + } + + switch_aud_inprogress = true; + + if (carg->complete) { + + switch_aud_inprogress = false; + + if (re_regex(carg->prm, str_len(carg->prm), "[^,]+,[~]*", + &pl_driver, &pl_device)) { + + return re_hprintf(pf, "\rFormat should be:" + " driver,device\n"); + } + + pl_strcpy(&pl_driver, driver, sizeof(driver)); + pl_strcpy(&pl_device, device, sizeof(device)); + + if (!ausrc_find(driver)) { + re_hprintf(pf, "no such audio-source: %s\n", driver); + return 0; } + re_hprintf(pf, "switch audio device: %s,%s\n", + driver, device); + cfg = conf_config(); if (!cfg) { return re_hprintf(pf, "no config object\n"); @@ -599,14 +652,22 @@ static int switch_audio_dev(struct re_printf *pf, void *arg) aucfg = &cfg->audio; - str_ncpy(aucfg->play_mod, driver, sizeof(aucfg->play_mod)); - str_ncpy(aucfg->play_dev, device, sizeof(aucfg->play_dev)); - str_ncpy(aucfg->src_mod, driver, sizeof(aucfg->src_mod)); str_ncpy(aucfg->src_dev, device, sizeof(aucfg->src_dev)); - str_ncpy(aucfg->alert_mod, driver, sizeof(aucfg->alert_mod)); - str_ncpy(aucfg->alert_dev, device, sizeof(aucfg->alert_dev)); + for (le = list_tail(ua_calls(uag_cur())); le; le = le->prev) { + + struct call *call = le->data; + + a = call_audio(call); + + err = audio_set_source(a, driver, device); + if (err) { + re_hprintf(pf, "failed to set audio-source" + " (%m)\n", err); + break; + } + } } return 0; @@ -692,7 +753,6 @@ static const struct cmd callcmdv[] = { {"hold", 'x', 0, "Call hold", cmd_call_hold }, {"", 'H', 0, "Hold previous call", hold_prev_call }, {"", 'L', 0, "Resume previous call",hold_prev_call }, -{"audev", 0, CMD_IPRM, "Switch audio device", switch_audio_dev }, #ifdef USE_VIDEO {"video_cycle", 'E', 0, "Cycle video encoder", call_videoenc_cycle }, |