[Goodies-commits] r6312 - xfce4-radio-plugin/branches/newincludes/panel-plugin
Stefan Ott
cockroach at xfce.org
Sun Dec 14 07:46:34 CET 2008
Author: cockroach
Date: 2008-12-14 06:46:34 +0000 (Sun, 14 Dec 2008)
New Revision: 6312
Modified:
xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.c
xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.h
xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l1.c
xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l2.c
xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.c
xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.h
Log:
Got rid of last few ioctls, added some functionality to v4l/radio lib
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.c
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.c 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.c 2008-12-14 06:46:34 UTC (rev 6312)
@@ -122,6 +122,18 @@
else return -1;
}
+double radio_get_freq(void)
+{
+ if (dev) return dev->get_freq (dev);
+ return -1;
+}
+
+int radio_is_muted(void)
+{
+ if (dev) return dev->is_muted (dev);
+ return -1;
+}
+
int radio_check_station(float freq)
{
static int a, b;
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.h
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.h 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/radio.h 2008-12-14 06:46:34 UTC (rev 6312)
@@ -26,6 +26,8 @@
void (*mute) (RadioDev *dev, int mute);
int (*get_stereo) (RadioDev *dev);
int (*get_signal) (RadioDev *dev);
+ double(*get_freq) (RadioDev *dev);
+ int (*is_muted) (RadioDev *dev);
void (*finalize) (RadioDev *dev);
};
@@ -55,4 +57,8 @@
int radio_get_signal(void);
+double radio_get_freq(void);
+
+int radio_is_muted(void);
+
#endif
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l1.c
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l1.c 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l1.c 2008-12-14 06:46:34 UTC (rev 6312)
@@ -147,6 +147,41 @@
return signal;
}
+static double
+v4l1_radio_get_freq(RadioDev *radio_dev)
+{
+ V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
+ long freq;
+
+ if (dev->fd<0)
+ return -1;
+
+ if (ioctl (dev->fd, VIDIOCGFREQ, &freq))
+ {
+ perror ("VIDIOCGFREQ");
+ return -1;
+ }
+
+ return freq / (double) dev->freq_fact;
+}
+
+static int
+v4l1_radio_is_muted(RadioDev *radio_dev)
+{
+ V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
+ struct video_audio vid_aud;
+
+ if (dev->fd<0)
+ return -1;
+
+ if (ioctl (dev->fd, VIDIOCGAUDIO, &vid_aud)) {
+ perror ("VIDIOCGAUDIO");
+ return -1;
+ }
+
+ return (vid_aud.flags & VIDEO_AUDIO_MUTE);
+}
+
static void
v4l1_radio_finalize(RadioDev *radio_dev)
{
@@ -173,6 +208,8 @@
dev->mute = v4l1_radio_mute;
dev->get_stereo = v4l1_radio_get_stereo;
dev->get_signal = v4l1_radio_get_signal;
+ dev->get_freq = v4l1_radio_get_freq;
+ dev->is_muted = v4l1_radio_is_muted;
dev->finalize = v4l1_radio_finalize;
return dev;
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l2.c
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l2.c 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/v4l2.c 2008-12-14 06:46:34 UTC (rev 6312)
@@ -168,6 +168,46 @@
return tuner.signal >> 13;
}
+static double
+v4l2_radio_get_freq(RadioDev *radio_dev)
+{
+ V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
+ struct v4l2_frequency freq;
+
+ if (dev->fd<0)
+ return -1;
+
+ memset(&freq, 0, sizeof(freq));
+ freq.tuner = 0;
+ freq.type = V4L2_TUNER_RADIO;
+
+ if (ioctl (dev->fd, VIDIOC_G_FREQUENCY, &freq) < 0)
+ {
+ perror ("VIDIOC_G_FREQUENCY");
+ return -1;
+ }
+ return freq.frequency / (double) dev->freq_fact;
+}
+
+static int
+v4l2_radio_is_muted(RadioDev *radio_dev)
+{
+ V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
+ struct v4l2_control control;
+
+ if (dev->fd<0)
+ return -1;
+
+ memset(&control, 0, sizeof(control));
+ control.id = V4L2_CID_AUDIO_MUTE;
+
+ if (ioctl (dev->fd, VIDIOC_G_CTRL, &control) < 0) {
+ perror ("VIDIOC_S_CTRL");
+ return -1;
+ }
+ return control.value;
+}
+
static void
v4l2_radio_finalize(RadioDev *radio_dev)
{
@@ -194,7 +234,9 @@
dev->mute = v4l2_radio_mute;
dev->get_stereo = v4l2_radio_get_stereo;
dev->get_signal = v4l2_radio_get_signal;
+ dev->get_freq = v4l2_radio_get_freq;
dev->finalize = v4l2_radio_finalize;
+ dev->is_muted = v4l2_radio_is_muted;
return dev;
}
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.c
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.c 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.c 2008-12-14 06:46:34 UTC (rev 6312)
@@ -159,32 +159,11 @@
if (!data->auto_update_display)
return TRUE;
- struct video_audio vid_aud;
- long freq;
-
- if (!data->on)
+ if (radio_is_muted())
{
- data->fd = open (data->device, O_RDONLY);
-
- // We return TRUE to keep the timer alive, same reason as above
- if (data->fd == -1)
- return TRUE;
- }
-
- // TODO: This one seems to fail occasionally
- if (ioctl (data->fd, VIDIOCGAUDIO, &vid_aud)) {
- perror ("VIDIOCGAUDIO");
- return TRUE; // Abort if ioctl fails
- }
-
- if (vid_aud.flags & VIDEO_AUDIO_MUTE)
- {
- close (data->fd);
-
- // Radio is off. Did I think it was on?
if (data->on)
{
- // manually clean up; xfce4_radio_stop would call ioctl
+ // Radio is off, we thought it was on
if (data->show_signal)
gtk_widget_hide (data->signal_bar);
data->on = FALSE;
@@ -192,28 +171,14 @@
}
else
{
- // Radio is on. Did I think it was off?
if (!data->on)
{
- // manually clean up; xfce4_radio_start would tune the
- // radio
+ // Radio is on, we thought it was off
gtk_tooltips_enable (data->tooltips);
data->on = TRUE;
}
-
- if (ioctl (data->fd, VIDIOCGFREQ, &freq))
- {
- perror ("VIDIOCGFREQ");
- return TRUE; // should maybe be FALSE?
- }
-
- // this plugin deals with frequencies in hundredths of Mhz
- freq *= 100;
- freq /= data->freqfact;
-
- data->freq = freq;
+ data->freq = radio_get_freq () * 100;
}
-
update_label (data);
update_signal_bar (data);
@@ -223,9 +188,6 @@
static void
xfce4_radio_tune (radio_gui* data)
{
-// int freq = (data->freq * data->freqfact) / 100;
-// ioctl (data->fd, VIDIOCSFREQ, &freq);
-
double freq = data->freq / 100.0;
radio_set_freq (freq);
DBG ("Tuning to %f", freq);
@@ -251,31 +213,7 @@
gtk_widget_destroy (warn);
return FALSE;
}
-/*
- struct video_tuner tuner;
- struct video_audio vid_aud;
- if (-1 == (data->fd = open (data->device, O_RDONLY)))
- {
- GtkWindow* win = GTK_WINDOW (gtk_widget_get_toplevel(
- data->box));
- GtkWidget* warn = gtk_message_dialog_new (win, 0,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- _("Error opening radio device"));
- gtk_dialog_run (GTK_DIALOG (warn));
- gtk_widget_destroy (warn);
- return FALSE;
- }
-
- if (0 == ioctl (data->fd, VIDIOCGTUNER, &tuner) &&
- (tuner.flags & VIDEO_TUNER_LOW))
- data->freqfact = 16000;
-
- if (ioctl (data->fd, VIDIOCGAUDIO, &vid_aud)) perror("VIDIOCGAUDIO");
- if (vid_aud.volume == 0) vid_aud.volume = 65535;
- vid_aud.flags &= ~VIDEO_AUDIO_MUTE;
- if (ioctl (data->fd, VIDIOCSAUDIO, &vid_aud)) perror("VIDIOCSAUDIO");*/
-
if (strcmp(data->startup_command, "") != 0)
{
xfce_exec(data->startup_command, FALSE, FALSE, NULL);
@@ -290,16 +228,7 @@
{
radio_mute ();
gtk_tooltips_disable (data->tooltips);
- /*
- struct video_audio vid_aud;
- gtk_tooltips_disable (data->tooltips);
- if (ioctl (data->fd, VIDIOCGAUDIO, &vid_aud)) perror("VIDIOCGAUDIO");
- vid_aud.flags |= VIDEO_AUDIO_MUTE;
- if (ioctl (data->fd, VIDIOCSAUDIO, &vid_aud)) perror("VIDIOCSAUDIO");
-
- close (data->fd);*/
-
if (data->show_signal) gtk_widget_hide (data->signal_bar);
if (strcmp (data->shutdown_command, "") != 0)
@@ -424,6 +353,7 @@
const gchar* text = gtk_label_get_text (GTK_LABEL (label));
GtkTreeModel *presets = GTK_TREE_MODEL(data->presets);
GtkTreeIter iter;
+
if (find_preset_by_name (presets, text, &iter))
{
gtk_tree_model_get (presets, &iter, 1, &data->freq, -1);
@@ -605,8 +535,6 @@
static radio_gui *
plugin_control_new (XfcePanelPlugin *plugin)
{
- int fd;
- struct video_tuner tuner;
radio_gui* plugin_data = create_gui();
plugin_data->plugin = plugin;
@@ -615,28 +543,6 @@
plugin_data->freq = FREQ_INIT;
strcpy(plugin_data->device, "/dev/radio0");
- // have to get the freqfact here now because someone else might
- // turn on the radio
- fd = open(plugin_data->device, O_RDONLY);
- if (fd != -1)
- {
- if (ioctl(fd, VIDIOCGTUNER, &tuner) == 0)
- {
- if (tuner.flags & VIDEO_TUNER_LOW)
- plugin_data->freqfact = 16000;
- else
- plugin_data->freqfact = 16;
- }
- else
- {
- plugin_data->freqfact = 16;
- }
- close (fd);
- }
- else
- {
- plugin_data->freqfact = 16;
- }
plugin_data->show_signal = TRUE;
plugin_data->auto_update_display = TRUE;
plugin_data->presets = NULL;
Modified: xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.h
===================================================================
--- xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.h 2008-12-14 05:43:42 UTC (rev 6311)
+++ xfce4-radio-plugin/branches/newincludes/panel-plugin/xfce4-radio.h 2008-12-14 06:46:34 UTC (rev 6312)
@@ -15,7 +15,7 @@
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _XFCE4_RADIO_H
@@ -78,8 +78,6 @@
gboolean show_signal;
gboolean auto_update_display;
int freq;
- int fd;
- int freqfact;
char device [MAX_DEVICE_NAME_LENGTH];
char startup_command [MAX_COMMAND_LENGTH];
char shutdown_command [MAX_COMMAND_LENGTH];
More information about the Goodies-commits
mailing list