summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-01-09 20:21:22 +0100
committerAlfred E. Heggestad <aeh@db.org>2016-01-09 20:21:22 +0100
commit4d8a30e750cfcbb6de91b1a4ee9c55411a146821 (patch)
treef95112383a8a5f2841ec41e953e5a53c9d09c608
parent856d3a5ac00d21d7892d2020a16b33bbd4aa829f (diff)
move playing of ringtones to the menu-module
-rw-r--r--docs/TODO2
-rw-r--r--include/baresip.h8
-rw-r--r--modules/menu/menu.c66
-rw-r--r--src/account.c6
-rw-r--r--src/core.h7
-rw-r--r--src/ua.c38
6 files changed, 80 insertions, 47 deletions
diff --git a/docs/TODO b/docs/TODO
index 9e518fa..04acb40 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -16,8 +16,6 @@ Version v0.x.y:
vumeter code is common for vumeter-module and gtk-module.
move to a common place ?
- move playing of ringtones from ua.c to menu.so ?
-
move password-prompt from ua (core) to module ?
add a FPS (framerate) throttler for fast vidsrc modules
diff --git a/include/baresip.h b/include/baresip.h
index 8574d35..2369915 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -31,6 +31,13 @@ struct vidsz;
* Account
*/
+/** Defines the answermodes */
+enum answermode {
+ ANSWERMODE_MANUAL = 0,
+ ANSWERMODE_EARLY,
+ ANSWERMODE_AUTO
+};
+
struct account;
int account_alloc(struct account **accp, const char *sipaddr);
@@ -43,6 +50,7 @@ struct list *account_vidcodecl(const struct account *acc);
struct sip_addr *account_laddr(const struct account *acc);
uint32_t account_regint(const struct account *acc);
uint32_t account_pubint(const struct account *acc);
+enum answermode account_answermode(const struct account *acc);
/*
diff --git a/modules/menu/menu.c b/modules/menu/menu.c
index b5f6354..0d0ca92 100644
--- a/modules/menu/menu.c
+++ b/modules/menu/menu.c
@@ -33,11 +33,27 @@ static enum statmode statmode; /**< Status mode */
static struct mbuf *dialbuf; /**< Buffer for dialled number */
static struct le *le_cur; /**< Current User-Agent (struct ua) */
+static struct {
+ struct play *play;
+} menu;
+
static void menu_set_incall(bool incall);
static void update_callstatus(void);
+static const char *translate_errorcode(uint16_t scode)
+{
+ switch (scode) {
+
+ case 404: return "notfound.wav";
+ case 486: return "busy.wav";
+ case 487: return NULL; /* ignore */
+ default: return "error.wav";
+ }
+}
+
+
static void check_registrations(void)
{
static bool ual_ready = false;
@@ -292,6 +308,9 @@ static int cmd_answer(struct re_printf *pf, void *unused)
(void)pf;
(void)unused;
+ /* Stop any ongoing ring-tones */
+ menu.play = mem_deref(menu.play);
+
ua_hold_answer(uag_cur(), NULL);
return 0;
@@ -303,6 +322,9 @@ static int cmd_hangup(struct re_printf *pf, void *unused)
(void)pf;
(void)unused;
+ /* Stop any ongoing ring-tones */
+ menu.play = mem_deref(menu.play);
+
ua_hangup(uag_cur(), NULL, 0, NULL);
/* note: must be called after ua_hangup() */
@@ -677,11 +699,53 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
info("%s: Incoming call from: %s %s -"
" (press ENTER to accept)\n",
ua_aor(ua), call_peername(call), call_peeruri(call));
+
+ /* stop any ringtones */
+ menu.play = mem_deref(menu.play);
+
+ /* Only play the ringtones if answermode is "Manual".
+ * If the answermode is "auto" then be silent.
+ */
+ if (ANSWERMODE_MANUAL == account_answermode(ua_account(ua))) {
+
+ if (list_count(ua_calls(ua)) > 1) {
+ (void)play_file(&menu.play,
+ "callwaiting.wav", 3);
+ }
+ else {
+ /* Alert user */
+ (void)play_file(&menu.play, "ring.wav", -1);
+ }
+
+ }
alert_start(0);
break;
+ case UA_EVENT_CALL_RINGING:
+ /* stop any ringtones */
+ menu.play = mem_deref(menu.play);
+
+ (void)play_file(&menu.play, "ringback.wav", -1);
+ break;
+
case UA_EVENT_CALL_ESTABLISHED:
+ /* stop any ringtones */
+ menu.play = mem_deref(menu.play);
+
+ alert_stop();
+ break;
+
case UA_EVENT_CALL_CLOSED:
+ /* stop any ringtones */
+ menu.play = mem_deref(menu.play);
+
+ if (call_scode(call)) {
+ const char *tone;
+ tone = translate_errorcode(call_scode(call));
+ if (tone)
+ (void)play_file(&menu.play, tone, 1);
+ }
+
alert_stop();
break;
@@ -749,6 +813,8 @@ static int module_close(void)
le_cur = NULL;
+ menu.play = mem_deref(menu.play);
+
return 0;
}
diff --git a/src/account.c b/src/account.c
index 7b32890..f870e2f 100644
--- a/src/account.c
+++ b/src/account.c
@@ -493,6 +493,12 @@ uint32_t account_pubint(const struct account *acc)
}
+enum answermode account_answermode(const struct account *acc)
+{
+ return acc ? acc->answermode : ANSWERMODE_MANUAL;
+}
+
+
static const char *answermode_str(enum answermode mode)
{
switch (mode) {
diff --git a/src/core.h b/src/core.h
index 43b720c..9d47582 100644
--- a/src/core.h
+++ b/src/core.h
@@ -31,13 +31,6 @@ enum {
*/
-/** Defines the answermodes */
-enum answermode {
- ANSWERMODE_MANUAL = 0,
- ANSWERMODE_EARLY,
- ANSWERMODE_AUTO
-};
-
struct account {
char *buf; /**< Buffer for the SIP address */
struct sip_addr laddr; /**< Decoded SIP address */
diff --git a/src/ua.c b/src/ua.c
index dc8073b..9fe4f0e 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -28,7 +28,6 @@ struct ua {
struct account *acc; /**< Account Parameters */
struct list regl; /**< List of Register clients */
struct list calls; /**< List of active calls (struct call) */
- struct play *play; /**< Playback of ringtones etc. */
struct pl extensionv[8]; /**< Vector of SIP extensions */
size_t extensionc; /**< Number of SIP extensions */
char *cuser; /**< SIP Contact username */
@@ -245,18 +244,6 @@ bool ua_isregistered(const struct ua *ua)
}
-static const char *translate_errorcode(uint16_t scode)
-{
- switch (scode) {
-
- case 404: return "notfound.wav";
- case 486: return "busy.wav";
- case 487: return NULL; /* ignore */
- default: return "error.wav";
- }
-}
-
-
static struct call *ua_find_call_onhold(const struct ua *ua)
{
struct le *le;
@@ -301,9 +288,6 @@ static void call_event_handler(struct call *call, enum call_event ev,
peeruri = call_peeruri(call);
- /* stop any ringtones */
- ua->play = mem_deref(ua->play);
-
switch (ev) {
case CALL_EVENT_INCOMING:
@@ -329,23 +313,12 @@ static void call_event_handler(struct call *call, enum call_event ev,
case ANSWERMODE_MANUAL:
default:
- if (list_count(&ua->calls) > 1) {
- (void)play_file(&ua->play,
- "callwaiting.wav", 3);
- }
- else {
- /* Alert user */
- (void)play_file(&ua->play, "ring.wav", -1);
- }
-
ua_event(ua, UA_EVENT_CALL_INCOMING, call, peeruri);
break;
}
break;
case CALL_EVENT_RINGING:
- (void)play_file(&ua->play, "ringback.wav", -1);
-
ua_event(ua, UA_EVENT_CALL_RINGING, call, peeruri);
break;
@@ -360,12 +333,6 @@ static void call_event_handler(struct call *call, enum call_event ev,
break;
case CALL_EVENT_CLOSED:
- if (call_scode(call)) {
- const char *tone;
- tone = translate_errorcode(call_scode(call));
- if (tone)
- (void)play_file(&ua->play, tone, 1);
- }
ua_event(ua, UA_EVENT_CALL_CLOSED, call, str);
mem_deref(call);
@@ -530,7 +497,6 @@ static void ua_destructor(void *arg)
list_flush(&ua->calls);
list_flush(&ua->regl);
- mem_deref(ua->play);
mem_deref(ua->cuser);
mem_deref(ua->pub_gruu);
mem_deref(ua->acc);
@@ -831,8 +797,6 @@ void ua_hangup(struct ua *ua, struct call *call,
return;
}
- ua->play = mem_deref(ua->play);
-
(void)call_hangup(call, scode, reason);
mem_deref(call);
@@ -860,8 +824,6 @@ int ua_answer(struct ua *ua, struct call *call)
return ENOENT;
}
- ua->play = mem_deref(ua->play);
-
return call_answer(call, 200);
}