[MPlayer-dev-eng] BSD BT848 Radio interface (patch)

voroshil at gmail.com voroshil at gmail.com
Wed Nov 15 18:54:24 CET 2006


RC wrote: 
> 
> If I tune it below 66MHz, then back to a normal station, I get static
> instead of sound...  This can be corrected by tuning to any frequency in
> tv:// mode.  It's unable to pick-up any signals below (precisely) 66MHz,
> despite a couple channels there, which I can tune to in tv:// mode.
> 
> I don't have the same tuning problem with higher frequencies... 
> However, the highest frequency I was able to recieve with radio://
> mode was 192MHz, despite numerous higher-frequency channels in tv://
> mode.
> 
> I guess 66 - 192 is approximately the limit, at least for my card.

I suggest to keep 87.5-108.0 frequency range for *BSD BT848, because 
*BSD kernel have such limit by default. If anybody wants to change it,
he needs at least to recompile kernel, so changing range in source code and
recompilation of MPlayer will not be so hard thing, i think.

It is also possible to add freq_min,freq_max parameters for using with bt848.
If such parameters need, i suggest to add them as separate patch.

According to above i have two questions:
1. Can i apply attached patch with 87.5-108.0 range limit (i also have changeed default
radio device for bt848 to /dev/tuner0)?
2. Does freq_min and freq_max parameters need for bt848? 


-- 
Regards,
Vladimir Voroshilov mailto:voroshil at gmail.com
Omsk State University
JID: voroshil at jabber.ru
ICQ: 95587719
-------------- next part --------------
Index: stream/stream_radio.c
===================================================================
--- stream/stream_radio.c	(revision 20942)
+++ stream/stream_radio.c	(working copy)
@@ -33,6 +33,16 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 #include <unistd.h>
+
+#ifdef RADIO_BSDBT848_HDR
+#include <sys/param.h>
+#include RADIO_BSDBT848_HDR
+
+/* see comment to init_frac_bsdbt848 below */
+#define BSDBT848_FREQ_MIN 87.50
+#define BSDBT848_FREQ_MAX 108.0
+#else // !BSDBT848
+
 #include <linux/types.h>
 
 #ifdef HAVE_RADIO_V4L2
@@ -44,6 +54,7 @@
 #warning  "V4L is deprecated and will be removed in future"
 #endif
 
+#endif //!BSDBT848
 
 
 #include "stream.h"
@@ -72,6 +83,7 @@
 #define RADIO_DRIVER_UNKNOWN    0
 #define RADIO_DRIVER_V4L        1
 #define RADIO_DRIVER_V4L2       2
+#define RADIO_DRIVER_BSDBT848   3
 
 typedef struct radio_channels_s {
     int index;     ///< channel index in channels list
@@ -82,7 +94,11 @@
 } radio_channels_t;
 
 /** (device,string, "/dev/radio0") name of radio device file */
+#ifdef RADIO_BSDBT848_HDR
+char*   radio_param_device="/dev/tuner0";
+#else
 char*   radio_param_device="/dev/radio0";
+#endif
 /** (driver,string, "v4l2") radio driver (v4l,v4l2) */
 char*   radio_param_driver="default";
 /** radio_param_channels (channels,string,NULL) channels list (see man page) */
@@ -507,7 +523,106 @@
     return STREAM_ERROR;
 }
 #endif //HAVE_RADIO_V4L
+#ifdef RADIO_BSDBT848_HDR
+/*****************************************************************
+ * \brief get fraction value for using in set_frequency and get_frequency
+ * \return STREAM_OK if success, STREAM_ERROR otherwise
+ *
+ * For *BSD BT848 frac=100
+ *
+ * Here is a coment from FreeBSD 5.2-RELEASE source code:
+ *
+ * * Tuner Notes:
+ * * Programming the tuner properly is quite complicated.
+ * * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner.
+ * * The tuner (front end) covers 45.75 MHz - 855.25 MHz and an FM band of
+ * * 87.5 MHz to 108.0 MHz.
+ *
+ * Thus, frequency range is limited to 87.5-108.0 
+*/
+static int init_frac_bsdbt848(radio_priv_t* priv){
+    priv->frac=100;
+    priv->rangelow=BSDBT848_FREQ_MIN;
+    priv->rangehigh=BSDBT848_FREQ_MAX;
+    return STREAM_OK;
+}
 
+/*****************************************************************
+ * \brief tune card to given frequency
+ * \param frequency frequency in MHz
+ * \return STREAM_OK if success, STREAM_ERROR otherwise
+ */
+static int set_frequency_bsdbt848(radio_priv_t* priv,float frequency){
+    unsigned int freq;
+    freq=frequency*priv->frac;
+    if(ioctl(priv->radio_fd,RADIO_SETFREQ,&freq)<0){
+        mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetFreqFailed,freq, frequency, strerror(errno));
+        return  STREAM_ERROR;
+    }
+    return STREAM_OK;
+}
+
+/*****************************************************************
+ * \brief get current tuned frequency from card
+ * \param frequency where to store frequency in MHz
+ * \return STREAM_OK if success, STREAM_ERROR otherwise
+ */
+static int get_frequency_bsdbt848(radio_priv_t* priv,float* frequency){
+    unsigned int freq;
+    if (ioctl(priv->radio_fd, RADIO_GETFREQ, &freq) < 0) {
+        mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetFreqFailed,strerror(errno));
+        return  STREAM_ERROR;
+    }
+    *frequency=((float)freq)/priv->frac;
+    return STREAM_OK;
+}
+
+/*****************************************************************
+ * \brief set volume on radio card
+ * \param volume volume level (0..100)
+ * \return STREAM_OK if success, STREAM_ERROR otherwise
+ *
+ * *BSD BT848 does not have volume changing abilities, so
+ * we will just mute sound if volume=0 and unmute it otherwise.
+ */
+static void set_volume_bsdbt848(radio_priv_t* priv,int volume){
+    int audio_flags;
+
+    /*arg must be between 0 and 100*/
+    if (volume > 100) volume = 100;
+    if (volume < 0) volume = 0;
+
+    audio_flags = (volume==0?AUDIO_MUTE:AUDIO_UNMUTE);
+    if (ioctl(priv->radio_fd, BT848_SAUDIO, &audio_flags)<0){
+            mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,strerror(errno));
+    }
+}
+
+/*****************************************************************
+ * \brief get current volume from radio card
+ * \param volume where to store volume level (0..100)
+ * \return previous STREAM_OK if success, STREAM_ERROR otherwise
+ *
+ * *BSD BT848 does not have volume changing abilities, so
+ * we will return 0 if sound is muted and 100 otherwise.
+ */
+static int get_volume_bsdbt848(radio_priv_t* priv,int* volume){
+    int audio_flags;
+
+    if (ioctl(priv->radio_fd, BT848_GAUDIO, &audio_flags)<0){
+        mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetVolumeFailed,strerror(errno));
+        return STREAM_ERROR;
+    }
+
+    if (audio_flags & AUDIO_MUTE)
+        *volume=0;
+    else
+        *volume=100;
+
+    return STREAM_OK;
+}
+#endif //RADIO_BSDBT848_HDR
+
 static inline int init_frac(radio_priv_t* priv){ 
     switch(priv->driver){
 #ifdef HAVE_RADIO_V4L
@@ -518,6 +633,10 @@
         case RADIO_DRIVER_V4L2:
             return init_frac_v4l2(priv);
 #endif
+#ifdef RADIO_BSDBT848_HDR
+        case RADIO_DRIVER_BSDBT848:
+            return init_frac_bsdbt848(priv);
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
     return STREAM_ERROR;
@@ -540,6 +659,12 @@
                 return STREAM_ERROR;
             break;     
 #endif
+#ifdef RADIO_BSDBT848_HDR
+        case RADIO_DRIVER_BSDBT848:
+            if(set_frequency_bsdbt848(priv,frequency)!=STREAM_OK)
+                return STREAM_ERROR;
+            break;     
+#endif
         default:
             mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
             return STREAM_ERROR;
@@ -562,6 +687,10 @@
         case RADIO_DRIVER_V4L2:
             return get_frequency_v4l2(priv,frequency);
 #endif
+#ifdef RADIO_BSDBT848_HDR
+        case RADIO_DRIVER_BSDBT848:
+            return get_frequency_bsdbt848(priv,frequency);
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
     return STREAM_ERROR;
@@ -578,6 +707,11 @@
             set_volume_v4l2(priv,volume);
             return;
 #endif
+#ifdef RADIO_BSDBT848_HDR
+        case RADIO_DRIVER_BSDBT848:
+            set_volume_bsdbt848(priv,volume);
+            return;
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
 }
@@ -591,6 +725,10 @@
         case RADIO_DRIVER_V4L2:
             return get_volume_v4l2(priv,volume);
 #endif
+#ifdef RADIO_BSDBT848_HDR
+        case RADIO_DRIVER_BSDBT848:
+            return get_volume_bsdbt848(priv,volume);
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
     return STREAM_ERROR;
@@ -981,8 +1119,10 @@
 
 
     if (strncmp(radio_param_driver,"default",7)==0)
-#ifdef HAVE_RADIO_V4L2
+#if defined(HAVE_RADIO_V4L2)
         priv->driver=RADIO_DRIVER_V4L2;
+#elif defined(RADIO_BSDBT848_HDR)
+        priv->driver=RADIO_DRIVER_BSDBT848;
 #else
         priv->driver=RADIO_DRIVER_V4L;
 #endif
@@ -997,6 +1137,11 @@
         priv->driver=RADIO_DRIVER_V4L;
     else
 #endif
+#ifdef RADIO_BSDBT848_HDR
+    if (strncmp(radio_param_driver,"bsdbt848",8)==0)
+        priv->driver=RADIO_DRIVER_BSDBT848;
+    else
+#endif
     priv->driver=RADIO_DRIVER_UNKNOWN;
 
 
@@ -1007,6 +1152,9 @@
         case RADIO_DRIVER_V4L2:
             mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverV4L2);
             break;
+        case RADIO_DRIVER_BSDBT848:
+            mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverBSDBT848);
+            break;
         default:
             mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverUnknownStr,radio_param_driver);
             close_s(stream);
Index: configure
===================================================================
--- configure	(revision 20942)
+++ configure	(working copy)
@@ -228,6 +228,7 @@
   --enable-radio         enable radio interface [disable]
   --enable-radio-capture enable radio capture (through PCI/line-in) [disable]
   --disable-radio-v4l2   disable Video4Linux2 radio interface [autodetect]
+  --disable-radio-bsdbt848   disable BSD BT848 radio interface [autodetect]
   --disable-tv           disable TV interface (TV/DVB grabbers) [enable]
   --disable-tv-v4l1      disable Video4Linux TV interface [autodetect]
   --disable-tv-v4l2      disable Video4Linux2 TV interface [autodetect]
@@ -1648,6 +1649,7 @@
 _radio_capture=no
 _radio_v4l=auto
 _radio_v4l2=auto
+_radio_bsdbt848=auto 
 _tv=yes
 _tv_v4l1=auto
 _tv_v4l2=auto
@@ -1906,6 +1908,7 @@
   --disable-radio-v4l)	_radio_v4l=no	;;
   --enable-radio-v4l2)	_radio_v4l2=yes	;;
   --disable-radio-v4l2)	_radio_v4l2=no	;;
+  --disable-radio-bsdbt848)	_radio_bsdbt848=no	;;
   --enable-pvr)  	_pvr=yes	;;
   --disable-pvr)	_pvr=no 	;;
   --enable-fastmemcpy)	_fastmemcpy=yes	;;
@@ -6749,10 +6752,32 @@
 fi
 echores "$_radio_v4l"
 
-if test "$_radio_v4l" = no && test "$_radio_v4l2" = no && test "$_radio" = yes ; then
-    die "Radio driver requires V4L or V4L2!"
+if test "$_radio_bsdbt848" = auto -a "$_radio" = yes && bsd; then
+ echocheck "*BSD BrookTree 848 Radio interface header"
+ _radio_bsdbt848_hdr=
+ for file in "dev/ic/bt8xx.h" "machine/ioctl_bt848.h" "dev/bktr/ioctl_bt848.h" "dev/video/bktr/ioctl_bt848.h" ; do
+    cat > $TMPC <<EOF
+#include <sys/types.h>
+#include <$file>
+int main(void) { return 0; }
+EOF
+    cc_check && _radio_bsdbt848_hdr=$file
+ done
+ echores "$_radio_bsdbt848_hdr"
+else
+  _radio_bsdbt848_hdr=
+fi #if bsd && radio && radio_bsdbt848
+
+if test -n "$_radio_bsdbt848_hdr"  ; then
+  _def_radio_bsdbt848="#define RADIO_BSDBT848_HDR <$_radio_bsdbt848_hdr>"
+else
+  _def_radio_bsdbt848='#undef RADIO_BSDBT848_HDR '
 fi
 
+if test "$_radio_v4l" = no && test "$_radio_v4l2" = no && test -z "$_radio_bsdbt848_hdr" && test "$_radio" = yes ; then
+    die "Radio driver requires BSD BT848,  V4L or V4L2!"
+fi
+
 echocheck "Video 4 Linux 2 MPEG PVR interface"
 if test "$_pvr" = auto ; then
  _pvr=no
@@ -7982,6 +8007,9 @@
 /* Enable Video 4 Linux 2 Radio interface support */
 $_def_radio_v4l2
 
+/* Enable *BSD BrookTree Radio interface support */
+$_def_radio_bsdbt848
+
 /* Enable Video 4 Linux 2 MPEG PVR support */
 $_def_pvr
 
Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1	(revision 20942)
+++ DOCS/man/en/mplayer.1	(working copy)
@@ -1614,7 +1614,7 @@
 Available options are:
 .RSs
 .IPs device=<value>
-Radio device to use (default: /dev/radio0).
+Radio device to use (default: /dev/radio0 for Linux and /dev/tuner0 for *BSD).
 .IPs driver=<value>
 Radio driver to use (default: v4l2 if available, otherwise v4l).
 Currently, v4l and v4l2 drivers are supported.
Index: help/help_mp-en.h
===================================================================
--- help/help_mp-en.h	(revision 20942)
+++ help/help_mp-en.h	(working copy)
@@ -1959,4 +1959,5 @@
 #define MSGTR_RADIO_DriverUnknownStr "[radio] Unknown driver name: %s\n"
 #define MSGTR_RADIO_DriverV4L2 "[radio] Using V4Lv2 radio interface.\n"
 #define MSGTR_RADIO_DriverV4L "[radio] Using V4Lv1 radio interface.\n"
+#define MSGTR_RADIO_DriverBSDBT848 "[radio] Using *BSD BT848 radio interface.\n"
 


More information about the MPlayer-dev-eng mailing list