summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-12-05 15:55:33 -0800
committerScott Murray <scott.murray@konsulko.com>2019-12-11 23:24:06 +0000
commit984dc822f8e32677be08a9061fb29d1609974307 (patch)
tree15a750b078bbed3285595dd69a5cb7fa6d973ee4
parentd864fe34f09249a29a4c63e7253b608a605b70ba (diff)
audiomixer: add steering wheel event processing supporthalibut_8.0.4halibut/8.0.48.0.4
Subscribe to volume events from the agl-service-signal-composer service, and enable up/down/mute event processing applied to the Master mixer control. Bug-AGL: SPEC-3024 Change-Id: I76bb66c7274875371a581568092c600dfd543e0f Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com> Signed-off-by: Scott Murray <scott.murray@konsulko.com>
-rw-r--r--binding/audiomixer-binding.c85
-rw-r--r--conf.d/wgt/config.xml.in3
2 files changed, 88 insertions, 0 deletions
diff --git a/binding/audiomixer-binding.c b/binding/audiomixer-binding.c
index 652df0a..80c4482 100644
--- a/binding/audiomixer-binding.c
+++ b/binding/audiomixer-binding.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2019 Collabora Ltd.
+ * Copyright © 2019 Konsulko Group
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
@@ -16,6 +17,13 @@ static afb_event_t controls_changed;
static afb_event_t volume_changed;
static afb_event_t mute_changed;
+static const char *signalcomposer_events[] = {
+ "event.volume.up",
+ "event.volume.down",
+ "event.volume.mute",
+ NULL,
+};
+
static void
audiomixer_controls_changed_deferred(int signum, void *arg)
{
@@ -96,6 +104,28 @@ cleanup(sd_event_source *s, void *data)
static int
init(afb_api_t api)
{
+ int ret;
+
+ ret = afb_daemon_require_api("signal-composer", 1);
+ if (ret) {
+ AFB_WARNING("unable to initialize signal-composer binding");
+ } else {
+ const char **tmp = signalcomposer_events;
+ json_object *args = json_object_new_object();
+ json_object *signals = json_object_new_array();
+
+ while (*tmp) {
+ json_object_array_add(signals, json_object_new_string(*tmp++));
+ }
+ json_object_object_add(args, "signal", signals);
+ if(json_object_array_length(signals)) {
+ afb_api_call_sync(api, "signal-composer", "subscribe",
+ args, NULL, NULL, NULL);
+ } else {
+ json_object_put(args);
+ }
+ }
+
sd_event *e = afb_daemon_get_event_loop();
controls_changed = afb_api_make_event(api, "controls_changed");
@@ -319,6 +349,60 @@ unsubscribe_cb(afb_req_t request)
afb_req_success(request, NULL, "Unsubscribed");
}
+static void
+onevent(afb_api_t api, const char *event, struct json_object *object)
+{
+ const struct mixer_control *ctl;
+ json_object *tmp = NULL;
+ const char *uid;
+ const char *value;
+
+ json_object_object_get_ex(object, "uid", &tmp);
+ if (tmp == NULL)
+ return;
+
+ uid = json_object_get_string(tmp);
+ if (strncmp(uid, "event.volume.", 13))
+ return;
+
+ json_object_object_get_ex(object, "value", &tmp);
+ if (tmp == NULL)
+ return;
+
+ value = json_object_get_string(tmp);
+ if (strncmp(value, "true", 4))
+ return;
+
+ audiomixer_lock(audiomixer);
+
+ ctl = audiomixer_find_control(audiomixer, "Master");
+ if (!ctl)
+ goto unlock;
+
+ if (!strcmp(uid, "event.volume.mute")) {
+ audiomixer_change_mute(audiomixer, ctl, !ctl->mute);
+ } else {
+ double volume = ctl->volume;
+
+ if (!strcmp(uid, "event.volume.up")) {
+ volume += 0.05; // up 5%
+ if (volume > 1.0)
+ volume = 1.0; // clamp to 100%
+ } else if (!strcmp(uid, "event.volume.down")) {
+ volume -= 0.05; // down 5%
+ if (volume < 0.0)
+ volume = 0.0; // clamp to 0%
+ } else {
+ AFB_WARNING("Unhandled signal-composer uid '%s'", uid);
+ goto unlock;
+ }
+ audiomixer_change_volume(audiomixer, ctl, volume);
+ }
+
+unlock:
+ audiomixer_unlock(audiomixer);
+}
+
static const afb_verb_t verbs[]= {
{ .verb = "list_controls", .callback = list_controls_cb, .info = "List the available controls" },
{ .verb = "volume", .callback = volume_cb, .info = "Get/Set volume" },
@@ -332,5 +416,6 @@ const afb_binding_t afbBindingV3 = {
.api = "audiomixer",
.specification = "AudioMixer API",
.verbs = verbs,
+ .onevent = onevent,
.init = init,
};
diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in
index 6d535ba..98c56bd 100644
--- a/conf.d/wgt/config.xml.in
+++ b/conf.d/wgt/config.xml.in
@@ -20,4 +20,7 @@
<param name="@WIDGET_ENTRY_POINT@" value="local" />
</feature>
+ <feature name="urn:AGL:widget:required-api">
+ <param name="signal-composer" value="ws" />
+ </feature>
</widget>