[MPlayer-dev-eng] [PATCH] frequency range check and keeping old volume for radio support

voroshil at gmail.com voroshil at gmail.com
Mon Nov 6 19:16:27 CET 2006


Hi, all.
Here is some abilities, which i want to suggest.

First is ability to check frequency range to disallow setting ivalid values for
frequency parameter.
Second is ability to restore old volume after mplayer exit.
Please review and comment.

P.S. Thanks to Vladimir Kushnir for idea.


-- 
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
Omsk State University
JID: voroshil at jabber.ru
ICQ: 95587719
-------------- next part --------------
Index: stream_radio.c
===================================================================
--- stream_radio.c	(revision 20736)
+++ stream_radio.c	(working copy)
@@ -69,6 +69,9 @@
 
 #endif
 
+#define FREQ_MIN 87.50
+#define FREQ_MAX 108.00
+
 #define RADIO_DRIVER_UNKNOWN    0
 #define RADIO_DRIVER_V4L        1
 #define RADIO_DRIVER_V4L2       2
@@ -185,7 +188,7 @@
 
             priv->radio_channel_current->freq=atof(tmp);
 
-            if (priv->radio_channel_current->freq == 0)
+            if ((priv->radio_channel_current->freq < FREQ_MIN) || (priv->radio_channel_current->freq > FREQ_MAX))
                 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreqForChannel,
                     priv->radio_channel_current->name);
 
@@ -523,6 +526,11 @@
     return STREAM_ERROR;
 }
 static inline int set_frequency(radio_priv_t* priv,float frequency){ 
+    if ((frequency < FREQ_MIN) || (frequency > FREQ_MAX)){
+        mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreq,frequency);
+	return STREAM_ERROR;
+    }
+
     switch(priv->driver){
 #ifdef HAVE_RADIO_V4L
         case RADIO_DRIVER_V4L:
@@ -1032,7 +1040,7 @@
         return STREAM_ERROR;
     }
 
-    if (frequency==0){
+    if ((frequency < FREQ_MIN) || (frequency > FREQ_MAX)){
         mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreq,frequency);
         close_s(stream);
         return STREAM_ERROR;
-------------- next part --------------
Index: stream_radio.c
===================================================================
--- stream_radio.c	(revision 20736)
+++ stream_radio.c	(working copy)
@@ -113,6 +113,7 @@
     radio_channels_t*   radio_channel_list;
     radio_channels_t*   radio_channel_current;
     int                 driver;
+    int                 old_snd_volume;
 #ifdef USE_RADIO_CAPTURE
     volatile int        do_capture;        ///< is capture enabled
     audio_in_t          audio_in;
@@ -1020,6 +1021,7 @@
     mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_RadioDevice, priv->radio_fd,radio_param_device);
     fcntl(priv->radio_fd, F_SETFD, FD_CLOEXEC);
 
+    get_volume(priv, &priv->old_snd_volume);
     set_volume(priv,0);
 
     if (init_frac(priv)!=STREAM_OK){
@@ -1093,6 +1095,7 @@
     priv->radio_channel_current=NULL;
     priv->radio_channel_list=NULL;
 
+    set_volume(priv, priv->old_snd_volume);
     if (priv->radio_fd>0){
         close(priv->radio_fd);
     }


More information about the MPlayer-dev-eng mailing list