From 352dad23c7847d234e11c1034e1354fbd9a8349a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 31 Dec 2011 17:50:06 +0100 Subject: initial import --- radio.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 radio.c (limited to 'radio.c') diff --git a/radio.c b/radio.c new file mode 100644 index 0000000..bc0d5ea --- /dev/null +++ b/radio.c @@ -0,0 +1,97 @@ +/* + * fmrxd - a daemon to enable and multiplex access to the N950/N9 radio tuner + * Copyright (C) 2011 Javier S. Pedro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include "fmrxd.h" + +static guint start_source_id = 0; +static guint stop_source_id = 0; +static bool active = false; + +bool radio_active() +{ + return active; +} + +void radio_start() +{ + g_return_if_fail(!active); + g_debug("Starting radio"); + + configure_bt_muxer(true); + configure_mixer(true); + configure_tuner(true); + configure_capture(true); + configure_rds(true); + + active = true; +} + +void radio_stop() +{ + g_return_if_fail(active); + g_debug("Stopping radio"); + + configure_rds(false); + configure_capture(false); + configure_tuner(false); + configure_mixer(false); + configure_bt_muxer(false); + + server_notify_stopped(); + + active = false; +} + +static gboolean radio_start_func(gpointer data) +{ + radio_start(); + start_source_id = 0; + return FALSE; +} + +static gboolean radio_stop_func(gpointer data) +{ + radio_stop(); + stop_source_id = 0; + return FALSE; +} + +void radio_queue_start() +{ + if (stop_source_id) { + /* If there was a queued stop pending, remove it. */ + g_source_remove(stop_source_id); + } + if (!start_source_id) { + start_source_id = g_idle_add(radio_start_func, NULL); + } +} + +void radio_queue_stop() +{ + if (start_source_id) { + /* If there is a queued start, remove it. */ + g_source_remove(start_source_id); + } + if (!stop_source_id) { + stop_source_id = g_timeout_add_seconds(RADIO_LINGER_TIME, + radio_stop_func, NULL); + } +} -- cgit v1.2.3