Skip to content

Instantly share code, notes, and snippets.

@alfredh
Created June 10, 2018 11:00
Show Gist options
  • Save alfredh/5ad83d7a3fe4cead3f7ac80a9e1435a9 to your computer and use it in GitHub Desktop.
Save alfredh/5ad83d7a3fe4cead3f7ac80a9e1435a9 to your computer and use it in GitHub Desktop.
diff --git a/include/baresip.h b/include/baresip.h
index f6d636e..2dd15f5 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -620,6 +620,8 @@ enum ua_event {
UA_EVENT_CALL_DTMF_END,
UA_EVENT_CALL_RTCP,
UA_EVENT_CALL_MENC,
+ UA_EVENT_VU_TX,
+ UA_EVENT_VU_RX,
UA_EVENT_MAX,
};
diff --git a/modules/menu/menu.c b/modules/menu/menu.c
index 184e84f..61ae9c9 100644
--- a/modules/menu/menu.c
+++ b/modules/menu/menu.c
@@ -963,7 +963,7 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
(void)prm;
(void)arg;
-#if 0
+#if 1
debug("menu: [ ua=%s call=%s ] event: %s (%s)\n",
ua_aor(ua), call_id(call), uag_event_str(ev), prm);
#endif
diff --git a/modules/vumeter/vumeter.c b/modules/vumeter/vumeter.c
index 952ce6b..fc41f51 100644
--- a/modules/vumeter/vumeter.c
+++ b/modules/vumeter/vumeter.c
@@ -23,6 +23,7 @@
struct vumeter_enc {
struct aufilt_enc_st af; /* inheritance */
struct tmr tmr;
+ const struct audio *au;
double avg_rec;
volatile bool started;
};
@@ -30,11 +31,31 @@ struct vumeter_enc {
struct vumeter_dec {
struct aufilt_dec_st af; /* inheritance */
struct tmr tmr;
+ const struct audio *au;
double avg_play;
volatile bool started;
};
+static void send_event(const struct audio *au, enum ua_event ev, double value)
+{
+ struct stream *strm;
+ struct call *call;
+ struct ua *ua;
+
+ /* get the stream from the audio object */
+ strm = audio_strm(au);
+
+ /* get the call from the stream object */
+ call = stream_call(strm);
+
+ /* get the useragent from the call object */
+ ua = call_get_ua(call);
+
+ ua_event(ua, ev, call, "%.2f", value);
+}
+
+
static void enc_destructor(void *arg)
{
struct vumeter_enc *st = arg;
@@ -86,10 +107,13 @@ static void enc_tmr_handler(void *arg)
{
struct vumeter_enc *st = arg;
- tmr_start(&st->tmr, 100, enc_tmr_handler, st);
+ tmr_start(&st->tmr, 500, enc_tmr_handler, st);
- if (st->started)
+ if (st->started) {
print_vumeter(60, 31, st->avg_rec);
+
+ send_event(st->au, UA_EVENT_VU_TX, st->avg_rec);
+ }
}
@@ -97,10 +121,13 @@ static void dec_tmr_handler(void *arg)
{
struct vumeter_dec *st = arg;
- tmr_start(&st->tmr, 100, dec_tmr_handler, st);
+ tmr_start(&st->tmr, 500, dec_tmr_handler, st);
- if (st->started)
+ if (st->started) {
print_vumeter(80, 32, st->avg_play);
+
+ send_event(st->au, UA_EVENT_VU_RX, st->avg_play);
+ }
}
@@ -122,6 +149,7 @@ static int encode_update(struct aufilt_enc_st **stp, void **ctx,
if (!st)
return ENOMEM;
+ st->au = au;
tmr_start(&st->tmr, 100, enc_tmr_handler, st);
*stp = (struct aufilt_enc_st *)st;
@@ -148,6 +176,7 @@ static int decode_update(struct aufilt_dec_st **stp, void **ctx,
if (!st)
return ENOMEM;
+ st->au = au;
tmr_start(&st->tmr, 100, dec_tmr_handler, st);
*stp = (struct aufilt_dec_st *)st;
diff --git a/src/event.c b/src/event.c
index 1de2dd4..11db376 100644
--- a/src/event.c
+++ b/src/event.c
@@ -34,6 +34,9 @@ static const char *event_class_name(enum ua_event ev)
case UA_EVENT_CALL_RTCP:
case UA_EVENT_CALL_MENC:
return "call";
+ case UA_EVENT_VU_RX:
+ case UA_EVENT_VU_TX:
+ return "VU_REPORT";
default:
return "other";
@@ -176,6 +179,8 @@ const char *uag_event_str(enum ua_event ev)
case UA_EVENT_CALL_DTMF_END: return "CALL_DTMF_END";
case UA_EVENT_CALL_RTCP: return "CALL_RTCP";
case UA_EVENT_CALL_MENC: return "CALL_MENC";
+ case UA_EVENT_VU_TX: return "VU_TX_REPORT";
+ case UA_EVENT_VU_RX: return "VU_RX_REPORT";
default: return "?";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment