diff options
author | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-07-11 17:42:22 +0200 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-07-17 10:50:07 +0200 |
commit | 9c519f325590fcf4dfcfe30798fddb5a102dc389 (patch) | |
tree | 79a7a47d282dd11a263c1c6458a9958fc2bed075 /binding/radio-binding.c | |
parent | 7db8c3df0b4abdb0bb643ca3220b3bfbc9a4db83 (diff) |
fixed the support for 4a framework
Changed the api call for getting an audio role.
Mapped the stop/start operations to mute/unmute
actions on role verb.
No longer uses a gstreamer pipeline for the sound
output, since it is 4a-softmixer that performs
the read/write loop instead.
Change-Id: I91e4f801a0da866c50b2218622e810d7350ab8a9
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'binding/radio-binding.c')
-rw-r--r-- | binding/radio-binding.c | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/binding/radio-binding.c b/binding/radio-binding.c index 3f34150..5f67567 100644 --- a/binding/radio-binding.c +++ b/binding/radio-binding.c @@ -30,8 +30,6 @@ #include "radio_impl_rtlsdr.h" #include "radio_impl_kingfisher.h" -#define RADIO_MODE_NAME_MAXLEN 8 - static radio_impl_ops_t *radio_impl_ops; static struct afb_event freq_event; @@ -103,7 +101,6 @@ static void rds(struct afb_req request) } ret_json = json_object_new_object(); - rds = radio_impl_ops->get_rds_info(); json_object_object_add(ret_json, "rds", json_object_new_string(rds?rds:"")); free(rds); @@ -391,7 +388,6 @@ static void stereo_mode(struct afb_req request) const char *value = afb_req_value(request, "value"); int valid = 0; radio_stereo_mode_t mode; - char mode_name[RADIO_MODE_NAME_MAXLEN]; if(value) { if(!strcasecmp(value, "mono")) { @@ -423,8 +419,8 @@ static void stereo_mode(struct afb_req request) } ret_json = json_object_new_object(); mode = radio_impl_ops->get_stereo_mode(); - snprintf(mode_name, RADIO_MODE_NAME_MAXLEN, "%s", mode == MONO ? "mono" : "stereo"); - json_object_object_add(ret_json, "mode", json_object_new_string(mode_name)); + + json_object_object_add(ret_json, "mode", json_object_new_string(mode == MONO ? "mono" : "stereo")); afb_req_success(request, ret_json, NULL); } @@ -495,32 +491,54 @@ static int init() char *output = NULL; #ifdef HAVE_4A_FRAMEWORK - json_object *response; - + json_object *response = NULL; json_object *jsonData = json_object_new_object(); - json_object_object_add(jsonData, "audio_role", json_object_new_string("Radio")); - json_object_object_add(jsonData, "endpoint_type", json_object_new_string("sink")); - rc = afb_service_call_sync("ahl-4a", "stream_open", jsonData, &response); - if(!rc) { - json_object *valJson = NULL; - json_object *val = NULL; - - rc = json_object_object_get_ex(response, "response", &valJson); - if(rc) { - rc = json_object_object_get_ex(valJson, "device_uri", &val); - if(rc) { - const char *jres_pcm = json_object_get_string(val); - char *p; - if((p = strchr(jres_pcm, ':'))) { - output = strdup(p + 1); - } - } - } - } else { - AFB_ERROR("afb_service_call_sync failed\n"); - return rc; + + json_object_object_add(jsonData, "action", json_object_new_string("open")); + rc = afb_service_call_sync("ahl-4a", "get_roles", NULL, &response); + if (rc < 0) { + AFB_ERROR("Failed to query 4A about roles"); + goto failed; + } + AFB_NOTICE("4A: available roles are '%s'", json_object_get_string(response)); + json_object_put(response); + + rc = afb_service_call_sync("ahl-4a", "radio", jsonData, &response); + if (rc < 0) { + AFB_ERROR("Failed to query 'radio' role to 4A"); + goto failed; + } + + json_object *valJson = NULL; + json_object *val = NULL; + + rc = json_object_object_get_ex(response, "response", &valJson); + if (rc == 0) { + AFB_ERROR("Reply from 4A is missing a 'response' field"); + goto failed_malformed; } -#endif + + rc = json_object_object_get_ex(valJson, "device_uri", &val); + if (rc == 0) { + AFB_ERROR("Reply from 4A is missing a 'device_uri' field"); + goto failed_malformed; + } + + const char *jres_pcm = json_object_get_string(val); + char * p = strchr(jres_pcm, ':'); + + if (p == NULL) { + AFB_ERROR("Unable to parse 'device_uri' value field"); + rc = -1; + goto failed_malformed; + } + + if (asprintf(&output, "hw:%s", p + 1) < 0) { + AFB_ERROR("Insufficient memory"); + rc = -1; + goto failed_malformed; + } +#endif /* HAVE_4A_FRAMEWORK */ // Initialize event structures freq_event = afb_daemon_make_event("frequency"); @@ -534,11 +552,23 @@ static int init() radio_impl_ops = &kf_impl_ops; rc = radio_impl_ops->init(output); } + if (rc != 0) { + AFB_ERROR("No radio device found, exiting"); + goto failed; + } + if(rc == 0) { - printf("%s found\n", radio_impl_ops->name); + AFB_NOTICE("%s found\n", radio_impl_ops->name); radio_impl_ops->set_frequency_callback(freq_callback, NULL); } free(output); + +#ifdef HAVE_4A_FRAMEWORK +failed_malformed: + json_object_put(response); +#endif /* HAVE_4A_FRAMEWORK */ + +failed: return rc; } |