diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.com> | 2018-07-18 10:30:17 +0300 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.com> | 2018-08-28 12:14:08 +0300 |
commit | 30dc02f090dfb68e874297ea8b9c88e41a9d9428 (patch) | |
tree | a426ce25b6b95d4e1e1e9d24e00ef5d3982865eb /module-4a-client.c | |
parent | 699e0ab7dd2ff86192e92d038ca0d008ec0bfb34 (diff) |
switch to using a unix socket with afb-proto-ws
Change-Id: I58861247f7ca23be9cf05d2055d948713547e3d5
Signed-off-by: George Kiagiadakis <george.kiagiadakis@collabora.com>
Diffstat (limited to 'module-4a-client.c')
-rw-r--r-- | module-4a-client.c | 85 |
1 files changed, 27 insertions, 58 deletions
diff --git a/module-4a-client.c b/module-4a-client.c index 64502c8..9eda2fa 100644 --- a/module-4a-client.c +++ b/module-4a-client.c @@ -34,8 +34,7 @@ #include "m4a_afb_comm.h" -#define DEFAULT_URI "ws://localhost:1234/api?token=" -#define AHL_4A_API "ahl-4a" +#define DEFAULT_URI "sd:ahl-4a" PA_MODULE_AUTHOR("George Kiagiadakis"); PA_MODULE_DESCRIPTION("Makes PulseAudio work as a client of the AGL Advanced Audio Architecture"); @@ -78,13 +77,9 @@ typedef struct { /* operational data */ pa_mutex *lock; - bool null_sink_loaded; - uint32_t null_sink_id; - uint32_t null_sink_module_id; pa_dynarray *roles; /* element-type: char* */ PA_LLIST_HEAD(m4a_stream, streams); pa_hook_slot - *sink_input_new_slot, *sink_input_put_slot, *sink_input_unlink_post_slot; m4a_afb_comm *comm; @@ -146,21 +141,21 @@ static pa_sink *load_sink_module(pa_core *core, const char *module, char *params /* invoked in the afb communication thread */ static void got_roles_cb(enum m4a_afb_reply r, - const pa_json_object *response, + json_object *response, pa_module *self) { m4a_data *d = self->userdata; int length, i; - const pa_json_object *jr; + json_object *jr; char *role; pa_mutex_lock(d->lock); - if (r == M4A_AFB_REPLY_OK && pa_json_object_get_type(response) == PA_JSON_TYPE_ARRAY) { - length = pa_json_object_get_array_length(response); + if (r == M4A_AFB_REPLY_OK && json_object_get_type(response) == json_type_array) { + length = json_object_array_length(response); for (i = 0; i < length; i++) { - jr = pa_json_object_get_array_member(response, i); - if (pa_json_object_get_type(jr) == PA_JSON_TYPE_STRING) { - role = pa_xstrdup(pa_json_object_get_string(jr)); + jr = json_object_array_get_idx(response, i); + if (json_object_get_type(jr) == json_type_string) { + role = pa_xstrdup(json_object_get_string(jr)); pa_log_debug("Found 4a role: %s", role); pa_dynarray_append(d->roles, role); } @@ -201,35 +196,18 @@ static void m4a_stream_free(m4a_stream *stream) { pa_xfree(stream); } -static pa_hook_result_t sink_input_new_cb(pa_core *core, - pa_sink_input *i, - pa_module *self) { - m4a_data *d = self->userdata; - pa_sink *sink; - - pa_core_assert_ref(core); - - /* first, forcibly set the sink to be our null sink */ - sink = pa_idxset_get_by_index(core->sinks, d->null_sink_id); - if (sink) { - i->sink = sink; - i->sink_requested_by_application = false; - } - - return PA_HOOK_OK; -} - /* invoked in the afb communication thread */ static void device_open_cb(enum m4a_afb_reply r, - const pa_json_object *response, + json_object *response, m4a_stream *stream) { - const pa_json_object *jdu; + json_object *jdu; const char *device_uri = NULL; - if (r == M4A_AFB_REPLY_OK && pa_json_object_get_type(response) == PA_JSON_TYPE_OBJECT) { - jdu = pa_json_object_get_object_member(response, "device_uri"); - if (jdu && pa_json_object_get_type(jdu) == PA_JSON_TYPE_STRING) { - device_uri = pa_json_object_get_string(jdu); + if (r == M4A_AFB_REPLY_OK && json_object_get_type(response) == json_type_object) { + json_object_object_get_ex(response, "device_uri", &jdu); + if (json_object_object_get_ex(response, "device_uri", &jdu) && + json_object_get_type(jdu) == json_type_string) { + device_uri = json_object_get_string(jdu); } } @@ -245,6 +223,7 @@ static pa_hook_result_t sink_input_put_cb(pa_core *core, pa_sink_input *i, pa_module *self) { m4a_data *d = self->userdata; + json_object *jparams; char *role; pa_mutex_lock(d->lock); @@ -260,8 +239,10 @@ static pa_hook_result_t sink_input_put_cb(pa_core *core, pa_log_debug("Calling 4A to open the device"); - m4a_afb_call_async(d->comm, AHL_4A_API, role, - pa_xstrdup("{\"action\":\"open\"}"), + jparams = json_object_new_object(); + json_object_object_add(jparams, "action", json_object_new_string("open")); + + m4a_afb_call_async(d->comm, role, jparams, (m4a_afb_done_cb_t) device_open_cb, stream); pa_log_debug("waiting for 4A to reply"); @@ -298,7 +279,7 @@ static pa_hook_result_t sink_input_put_cb(pa_core *core, /* invoked in the afb communication thread */ static void device_close_cb(enum m4a_afb_reply r, - const pa_json_object *response, + json_object *response, m4a_stream *stream) { pa_log_debug("4A replied: %s", (r == M4A_AFB_REPLY_OK) ? "OK" : "ERROR"); @@ -310,6 +291,7 @@ static pa_hook_result_t sink_input_unlink_post_cb(pa_core *core, pa_module *self) { m4a_data *d = self->userdata; m4a_stream *stream = NULL; + json_object *jparams; PA_LLIST_FOREACH(stream, d->streams) { if (stream->sink_input == i) @@ -323,8 +305,10 @@ static pa_hook_result_t sink_input_unlink_post_cb(pa_core *core, stream->entity_module_id, false); stream->entity_loaded = false; - m4a_afb_call_async(d->comm, AHL_4A_API, stream->role, - pa_xstrdup("{\"action\":\"close\"}"), + jparams = json_object_new_object(); + json_object_object_add(jparams, "action", json_object_new_string("close")); + + m4a_afb_call_async(d->comm, stream->role, jparams, (m4a_afb_done_cb_t) device_close_cb, stream); } @@ -334,7 +318,6 @@ static pa_hook_result_t sink_input_unlink_post_cb(pa_core *core, int pa__init(pa_module *self) { m4a_data *d; const char *uri; - pa_sink *null_sink; pa_assert(self); @@ -352,20 +335,11 @@ int pa__init(pa_module *self) { goto fail; } - if (!m4a_afb_call_async(d->comm, AHL_4A_API, "get_roles", NULL, + if (!m4a_afb_call_async(d->comm, "get_roles", NULL, (m4a_afb_done_cb_t) got_roles_cb, self)) { goto fail; } - null_sink = load_sink_module(self->core, "module-null-sink", pa_sprintf_malloc( - "sink_name=aaaa_null_sink sink_properties='device.description=\"%s\"'", - _("4A Null Output"))); - d->null_sink_id = null_sink->index; - d->null_sink_module_id = null_sink->module->index; - d->null_sink_loaded = true; - - d->sink_input_new_slot = pa_hook_connect(&self->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], - PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_new_cb, self); d->sink_input_put_slot = pa_hook_connect(&self->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_put_cb, self); d->sink_input_unlink_post_slot = pa_hook_connect(&self->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], @@ -393,16 +367,11 @@ void pa__done(pa_module *self) { if (d->ma) pa_modargs_free(d->ma); - if (d->sink_input_new_slot) - pa_hook_slot_free(d->sink_input_new_slot); if (d->sink_input_put_slot) pa_hook_slot_free(d->sink_input_put_slot); if (d->sink_input_unlink_post_slot) pa_hook_slot_free(d->sink_input_unlink_post_slot); - if (d->null_sink_loaded) - pa_module_unload_request_by_index(self->core, d->null_sink_module_id, false); - if (d->comm) m4a_afb_comm_free(d->comm); } |