1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
/**
* @file dynamic_menu.c dynamic menu related functions
*
* Copyright (C) 2010 Alfred E. Heggestad
*/
#include <stdlib.h>
#include <re.h>
#include <baresip.h>
#include "menu.h"
static int set_audio_bitrate(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct call *call;
uint32_t bitrate = str_isset(carg->prm) ? atoi(carg->prm) : 0;
call = ua_call(ua);
if (call) {
(void)re_hprintf(pf, "setting audio bitrate: %u bps\n",
bitrate);
audio_set_bitrate(call_audio(call), bitrate);
}
else {
(void)re_hprintf(pf, "call not found\n");
return EINVAL;
}
return 0;
}
static int call_audio_debug(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
return audio_debug(pf, call_audio(ua_call(ua)));
}
static int cmd_find_call(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
const char *id = carg->prm;
struct call *call = uag_call_find(id);
if (call) {
(void)re_hprintf(pf, "setting current call: %s\n", id);
menu_selcall(call);
}
else {
(void)re_hprintf(pf, "call not found (id=%s)\n", id);
return EINVAL;
}
return 0;
}
/**
* Put the active call on-hold
*
* @param pf Print handler
* @param arg Command arguments (carg)
* carg->data is an optional pointer to a User-Agent
* carg->prm is an optional call-id string
*
* @return 0 if success, otherwise errorcode
*/
static int cmd_call_hold(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct call *call = ua_call(ua);
(void)pf;
if (carg->prm) {
call = uag_call_find(carg->prm);
if (!call) {
re_hprintf(pf, "call %s not found\n", carg->prm);
return EINVAL;
}
}
if (!call) {
re_hprintf(pf, "no active call\n");
return ENOENT;
}
return call_hold(call, true);
}
static int set_current_call(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct call *call;
uint32_t linenum = atoi(carg->prm);
call = call_find_linenum(ua_calls(ua), linenum);
if (call) {
(void)re_hprintf(pf, "setting current call: line %u\n",
linenum);
menu_selcall(call);
}
else {
(void)re_hprintf(pf, "call not found (ua=%s, line=%u)\n",
account_aor(ua_account(ua)), linenum);
return EINVAL;
}
return 0;
}
static int call_mute(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct audio *audio = call_audio(ua_call(ua));
bool muted = !audio_ismuted(audio);
(void)re_hprintf(pf, "\ncall %smuted\n", muted ? "" : "un-");
audio_mute(audio, muted);
return 0;
}
static int call_reinvite(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
(void)pf;
return call_modify(ua_call(ua));
}
/**
* Resume the active call
*
* @param pf Print handler
* @param arg Command arguments (carg)
* carg->data is an optional pointer to a User-Agent
* carg->prm is an optional call-id string
*
* @return 0 if success, otherwise errorcode
*/
static int cmd_call_resume(struct re_printf *pf, void *arg)
{
struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct call *call = ua_call(ua);
(void)pf;
if (carg->prm) {
call = uag_call_find(carg->prm);
if (!call) {
re_hprintf(pf, "call %s not found\n", carg->prm);
return EINVAL;
}
}
if (!call) {
re_hprintf(pf, "no active call\n");
return ENOENT;
}
return uag_hold_resume(call);
}
static int send_code(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
struct call *call;
size_t i;
int err = 0;
(void)pf;
call = ua_call(ua);
if (call) {
for (i = 0; i < str_len(carg->prm) && !err; i++) {
err = call_send_digit(call, carg->prm[i]);
}
if (!err) {
err = call_send_digit(call, KEYCODE_REL);
}
}
return err;
}
static int toggle_statmode(struct re_printf *pf, void *arg)
{
struct menu *menu = menu_get();
(void)pf;
(void)arg;
if (menu->statmode == STATMODE_OFF)
menu->statmode = STATMODE_CALL;
else
menu->statmode = STATMODE_OFF;
return 0;
}
static int call_xfer(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
(void)pf;
return call_transfer(ua_call(ua), carg->prm);
}
static int call_video_debug(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
struct ua *ua = carg->data ? carg->data : menu_uacur();
return video_debug(pf, call_video(ua_call(ua)));
}
static int set_video_dir(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
struct call *call = menu_callcur();
int err = 0;
if (!call)
return EINVAL;
if (0 == str_cmp(carg->prm, sdp_dir_name(SDP_INACTIVE))) {
err = call_set_video_dir(call, SDP_INACTIVE);
}
else if (0 == str_cmp(carg->prm, sdp_dir_name(SDP_SENDONLY))) {
err = call_set_video_dir(call, SDP_SENDONLY);
}
else if (0 == str_cmp(carg->prm, sdp_dir_name(SDP_RECVONLY))) {
err = call_set_video_dir(call, SDP_RECVONLY);
}
else if (0 == str_cmp(carg->prm, sdp_dir_name(SDP_SENDRECV))) {
err = call_set_video_dir(call, SDP_SENDRECV);
}
else {
(void)re_hprintf(pf, "invalid video direction %s"
" (inactive, sendonly, recvonly, sendrecv)\n",
carg->prm);
return EINVAL;
}
return err;
}
static int digit_handler(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
(void) pf;
return call_send_digit(menu_callcur(), carg->key);
}
/*Dynamic call menu*/
static const struct cmd callcmdv[] = {
{"aubitrate", 0, CMD_PRM, "Set audio bitrate", set_audio_bitrate },
{"audio_debug", 'A', 0, "Audio stream", call_audio_debug },
{"callfind", 0, CMD_PRM, "Find call <callid>", cmd_find_call },
{"hold", 'x', 0, "Call hold", cmd_call_hold },
{"line", '@', CMD_PRM, "Set current call <line>", set_current_call },
{"mute", 'm', 0, "Call mute/un-mute", call_mute },
{"reinvite", 'I', 0, "Send re-INVITE", call_reinvite },
{"resume", 'X', 0, "Call resume", cmd_call_resume },
{"sndcode", 0, CMD_PRM, "Send Code", send_code },
{"statmode", 'S', 0, "Statusmode toggle", toggle_statmode },
{"transfer", 't', CMD_PRM, "Transfer call", call_xfer },
{"video_debug", 'V', 0, "Video stream", call_video_debug },
{"videodir", 0, CMD_PRM, "Set video direction", set_video_dir },
/* Numeric keypad for DTMF events: */
{NULL, '#', 0, NULL, digit_handler },
{NULL, '*', 0, NULL, digit_handler },
{NULL, '0', 0, NULL, digit_handler },
{NULL, '1', 0, NULL, digit_handler },
{NULL, '2', 0, NULL, digit_handler },
{NULL, '3', 0, NULL, digit_handler },
{NULL, '4', 0, NULL, digit_handler },
{NULL, '5', 0, NULL, digit_handler },
{NULL, '6', 0, NULL, digit_handler },
{NULL, '7', 0, NULL, digit_handler },
{NULL, '8', 0, NULL, digit_handler },
{NULL, '9', 0, NULL, digit_handler },
{NULL, KEYCODE_REL, 0, NULL, digit_handler },
};
/**
* Register call commands
*
* @return int 0 if success, errorcode otherwise
*/
int dynamic_menu_register(void)
{
struct commands *baresip_cmd = baresip_commands();
if (!cmds_find(baresip_cmd, callcmdv))
return cmd_register(baresip_cmd,
callcmdv, ARRAY_SIZE(callcmdv));
return 0;
}
/**
* Unregister call commands
*/
void dynamic_menu_unregister(void)
{
cmd_unregister(baresip_commands(), callcmdv);
}
|