summaryrefslogtreecommitdiffstats
path: root/binding/radio_impl_rtlsdr.c
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-01-03 01:26:11 -0500
committerScott Murray <scott.murray@konsulko.com>2019-01-04 22:19:49 +0000
commit6e70d2b8b821622ae81796a6f1d3f7f3881610a2 (patch)
treead1bd2ee626608181d4dcb7adc6075b3efe97c1b /binding/radio_impl_rtlsdr.c
parent6098681d92e9087627d4ba2d90ae826a6f579d0b (diff)
Add audio role open/close support
Rework things so that the 4A audio role is only opened while playing, and closed when stopped. Further work will need to be done to handle the possibility of the output device changing on subsequent opens, both the RTL SDR and Kingfisher case have complications around doing so: - The RTL SDR helper application needs to be enhanced to add an output setting command. Killing it and starting it again would also work, but likely will add noticeable UI latency. - On the Kingfisher, the binding currently has no control over the output used for the loopback, as it is being set up down in the soft-mixer based on HAL values. Change-Id: I4aa83c937972ec5d91f7b78421a11148c7fe0afc Signed-off-by: Scott Murray <scott.murray@konsulko.com> (cherry picked from commit f1d5902c92eafd3aad62e29298502603a9b56d81)
Diffstat (limited to 'binding/radio_impl_rtlsdr.c')
-rw-r--r--binding/radio_impl_rtlsdr.c76
1 files changed, 56 insertions, 20 deletions
diff --git a/binding/radio_impl_rtlsdr.c b/binding/radio_impl_rtlsdr.c
index c6b0ea9..109d3f3 100644
--- a/binding/radio_impl_rtlsdr.c
+++ b/binding/radio_impl_rtlsdr.c
@@ -51,6 +51,7 @@ static fm_band_plan_t known_fm_band_plans[5] = {
};
static unsigned int bandplan;
+static char *helper_output;
static pid_t helper_pid;
static int helper_in;
static int helper_out;
@@ -127,7 +128,7 @@ static pid_t popen2(char *command, int *in_fd, int *out_fd)
return pid;
}
-static int rtlsdr_init(const char *output)
+static int rtlsdr_init(void)
{
GKeyFile *conf_file;
char *value_str;
@@ -185,31 +186,20 @@ static int rtlsdr_init(const char *output)
return -1;
}
- if(output) {
- // Indicate desired output to helper
- AFB_INFO("Setting RADIO_OUTPUT=%s", output);
- setenv("RADIO_OUTPUT", output, 1);
- }
-
- // Run helper
- if(snprintf(helper_path, PATH_MAX, "%s/bin/%s", rootdir, HELPER_NAME) == PATH_MAX) {
- AFB_ERROR("Could not create path to %s", HELPER_NAME);
- return -EINVAL;
- }
- helper_pid = popen2(helper_path, &helper_out, &helper_in);
- if(helper_pid < 0) {
- AFB_ERROR("Could not run %s!", HELPER_NAME);
- return -1;
- }
- AFB_DEBUG("%s started", HELPER_NAME);
- free(helper_path);
-
present = true;
rtlsdr_set_frequency(current_frequency);
return 0;
}
+static void rtlsdr_set_output(const char *output)
+{
+ // Save output for later use
+ if(helper_output)
+ free(helper_output);
+ helper_output = strdup(output);
+}
+
static uint32_t rtlsdr_get_frequency(void)
{
return current_frequency;
@@ -309,6 +299,48 @@ static uint32_t rtlsdr_get_frequency_step(radio_band_t band)
return ret;
}
+static int rtlsdr_start_helper(void)
+{
+ char *rootdir;
+ char *helper_path;
+ static bool helper_started = false;
+
+ if(!present)
+ return -1;
+
+ if(helper_started)
+ return 0;
+
+ rootdir = getenv("AFM_APP_INSTALL_DIR");
+ if(!rootdir)
+ return -1;
+
+ if(helper_output) {
+ // Indicate desired output to helper
+ AFB_INFO("Setting RADIO_OUTPUT=%s", helper_output);
+ setenv("RADIO_OUTPUT", helper_output, 1);
+ }
+
+ // Run helper
+ helper_path = malloc(HELPER_MAX);
+ if(!helper_path)
+ return -ENOMEM;
+ if(snprintf(helper_path, PATH_MAX, "%s/bin/%s", rootdir, HELPER_NAME) == PATH_MAX) {
+ AFB_ERROR("Could not create path to %s", HELPER_NAME);
+ return -EINVAL;
+ }
+ helper_pid = popen2(helper_path, &helper_out, &helper_in);
+ if(helper_pid < 0) {
+ AFB_ERROR("Could not run %s!", HELPER_NAME);
+ return -1;
+ }
+ AFB_DEBUG("%s started", HELPER_NAME);
+ helper_started = true;
+ free(helper_path);
+
+ return 0;
+}
+
static void rtlsdr_start(void)
{
if(!present)
@@ -317,6 +349,9 @@ static void rtlsdr_start(void)
if(active)
return;
+ if(rtlsdr_start_helper() < 0)
+ return;
+
ssize_t rc;
char cmd[HELPER_CMD_MAXLEN];
@@ -437,6 +472,7 @@ static void rtlsdr_set_stereo_mode(radio_stereo_mode_t mode)
radio_impl_ops_t rtlsdr_impl_ops = {
.name = "RTL-SDR USB adapter",
.init = rtlsdr_init,
+ .set_output = rtlsdr_set_output,
.get_frequency = rtlsdr_get_frequency,
.set_frequency = rtlsdr_set_frequency,
.set_frequency_callback = rtlsdr_set_frequency_callback,