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

voroshil at gmail.com voroshil at gmail.com
Mon Nov 6 19:51:39 CET 2006


Vladimir Voroshilov wrote: 
> Hi Vladimir.
> >Sorry I'm not on the list presently. As far as patch for ranges/old volume 
> >for
> >Linux is concerned - would you pls correct them (if you don't mind)?
> >Sorry again, I'm not familiar with Linux enough to right anything at all 
> >for
> >it (like frequency ranges etc) :-(.
> Ok, i'll make a patch (just for keeping old volume, and range check)
> for a few days. I can also modify your patch (bsdbt848 support code),
> if you allow to do it.
I have made modified Vladimir Kushnir's bsd bt848 patch.
Restoring old volume, frequency range check and O_RDONLY in open()  
abilities were posted as separate patches. Here is just bsdbt848 support.

Can anybody review and test it (i haven't bt848) ?

Thanks.

> 
> -- 
> Regards,
> Vladimir Voroshilov     mailto:voroshil at gmail.com
> JID: voroshil at jabber.ru
> ICQ: 95587719

-- 
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 20736)
+++ stream/stream_radio.c	(working copy)
@@ -33,6 +33,22 @@
 #include <sys/ioctl.h>
 #include <errno.h>
 #include <unistd.h>
+
+#ifdef HAVE_RADIO_BSDBT848
+#include <sys/param.h>
+#if defined(__DragonFly__)
+#include <dev/video/meteor/ioctl_meteor.h>
+#include <dev/video/bktr/ioctl_bt848.h>
+#elif __FreeBSD_version >= 502100
+#include <dev/bktr/ioctl_meteor.h>
+#include <dev/bktr/ioctl_bt848.h>
+#else
+#include <machine/ioctl_meteor.h>
+#include <machine/ioctl_bt848.h>
+#endif
+
+#else // !BSDBT848
+
 #include <linux/types.h>
 
 #ifdef HAVE_RADIO_V4L2
@@ -44,6 +60,7 @@
 #warning  "V4L is deprecated and will be removed in future"
 #endif
 
+#endif //!BSDBT848
 
 
 #include "stream.h"
@@ -72,6 +89,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
@@ -81,6 +99,10 @@
     struct radio_channels_s * prev;
 } radio_channels_t;
 
+#ifdef HAVE_RADIO_BSDBT848
+#define BSD_MIXER_DEVICE "/dev/mixer"
+#endif
+
 /** (device,string, "/dev/radio0") name of radio device file */
 char*   radio_param_device="/dev/radio0";
 /** (driver,string, "v4l2") radio driver (v4l,v4l2) */
@@ -507,7 +529,119 @@
     return STREAM_ERROR;
 }
 #endif //HAVE_RADIO_V4L
+#ifdef HAVE_RADIO_BSDBT848
+/*****************************************************************
+ * \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*100;
+    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;
+    }
+#ifdef USE_RADIO_CAPTURE
+    if(clear_buffer(priv)!=STREAM_OK){
+        mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_ClearBufferFailed,
+							strerror(errno));
+        return  STREAM_ERROR;
+    }
+#endif
+    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)/100;
+    return STREAM_OK;
+}
+
+/*****************************************************************
+ * \brief set volume on radio card
+ * \param volume volume level (0..100)
+ * \return STREAM_OK if success, STREAM_ERROR otherwise
+ */
+static void set_volume_bsdbt848(radio_priv_t* priv,int volume){
+    int audio_flags, mixer_fd;
+
+    /*arg must be between 0 and 100*/
+    if (volume > 100) volume = 100;
+    if (volume < 0) volume = 0;
+
+    /* If volume = 0 mute radiodev, otherwise unmute and set volume */
+    if (volume == 0) {
+    	audio_flags = AUDIO_MUTE;
+    	if (ioctl(priv->radio_fd, BT848_SAUDIO, &audio_flags)<0){
+            mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,
+						strerror(errno));
+        }
+    }
+    else {
+    	audio_flags = AUDIO_UNMUTE;
+        if (ioctl(priv->radio_fd, BT848_SAUDIO, &audio_flags)<0){
+            mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetUnMuteFailed,
+							strerror(errno));
+        }
+
+        if ((mixer_fd = open(BSD_MIXER_DEVICE, O_RDWR)) < 0) {
+            mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_OpenMixerFailed,
+							strerror(errno));
+        }
+
+        volume += (volume << 8);
+        if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_LINE), &volume) < 0) {
+            mp_msg(MSGT_RADIO, MSGL_WARN,MSGTR_RADIO_SetVolumeFailed,
+							strerror(errno));
+        }
+        close(mixer_fd);
+    }
+}
+
+/*****************************************************************
+ * \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
+ */
+static int get_volume_bsdbt848(radio_priv_t* priv,int* volume){
+    int audio_flags, mixer_fd;
+
+    if ((mixer_fd = open(BSD_MIXER_DEVICE, O_RDWR)) < 0) {
+        mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_OpenMixerFailed,
+							strerror(errno));
+        return STREAM_ERROR;
+    }
+
+    if (ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_LINE), volume) < 0) {
+        mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_GetVolumeFailed,
+							strerror(errno));
+        return STREAM_ERROR;
+    }
+
+    *volume = *volume & 0x7f;
+
+    /*arg must be between 0 and 100*/
+    if (*volume > 100) *volume = 100;
+    if (*volume < 0) *volume = 0;
+
+    close(mixer_fd);
+    return STREAM_OK;
+}
+#endif //HAVE_RADIO_BSDBT848
+
 static inline int init_frac(radio_priv_t* priv){ 
     switch(priv->driver){
 #ifdef HAVE_RADIO_V4L
@@ -518,6 +652,10 @@
         case RADIO_DRIVER_V4L2:
             return init_frac_v4l2(priv);
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+        case RADIO_DRIVER_BSDBT848:
+	    return STREAM_OK;
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
     return STREAM_ERROR;
@@ -532,6 +670,10 @@
         case RADIO_DRIVER_V4L2:
             return set_frequency_v4l2(priv,frequency);
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+        case RADIO_DRIVER_BSDBT848:
+            return set_frequency_bsdbt848(priv,frequency);
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
     return STREAM_ERROR;
@@ -546,6 +688,10 @@
         case RADIO_DRIVER_V4L2:
             return get_frequency_v4l2(priv,frequency);
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+        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;
@@ -562,6 +708,11 @@
             set_volume_v4l2(priv,volume);
             return;
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+        case RADIO_DRIVER_BSDBT848:
+            set_volume_bsdbt848(priv,volume);
+            return;
+#endif
     }
     mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver);
 }
@@ -575,6 +726,10 @@
         case RADIO_DRIVER_V4L2:
             return get_volume_v4l2(priv,volume);
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+        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;
@@ -965,8 +1120,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(HAVE_RADIO_BSDBT848)
+        priv->driver=RADIO_DRIVER_BSDBT848;
 #else
         priv->driver=RADIO_DRIVER_V4L;
 #endif
@@ -981,6 +1138,11 @@
         priv->driver=RADIO_DRIVER_V4L;
     else
 #endif
+#ifdef HAVE_RADIO_BSDBT848
+    if (strncmp(radio_param_driver,"bsdbt848",8)==0)
+        priv->driver=RADIO_DRIVER_BSDBT848;
+    else
+#endif
     priv->driver=RADIO_DRIVER_UNKNOWN;
 
 
@@ -991,6 +1153,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 20736)
+++ configure	(working copy)
@@ -1647,6 +1647,7 @@
 _radio_capture=no
 _radio_v4l=auto
 _radio_v4l2=auto
+_radio_bsdbt848=auto
 _tv=yes
 _tv_v4l1=auto
 _tv_v4l2=auto
@@ -1902,6 +1903,8 @@
   --disable-radio-v4l)	_radio_v4l=no	;;
   --enable-radio-v4l2)	_radio_v4l2=yes	;;
   --disable-radio-v4l2)	_radio_v4l2=no	;;
+  --enable-radio-bsdbt848)	_radio_bsdbt848=yes	;;
+  --disable-radio-bsdbt848)	_radio_bsdbt848=no	;;
   --enable-pvr)  	_pvr=yes	;;
   --disable-pvr)	_pvr=no 	;;
   --enable-fastmemcpy)	_fastmemcpy=yes	;;
@@ -6756,10 +6759,41 @@
 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 bsd; then
+echocheck "*BSD BrookTree 848 Radio interface"
+if test "$_radio_bsdbt848" = auto ; then
+  _radio_bsdbt848=no
+  if test "$_radio" = yes ; then
+    cat > $TMPC <<EOF
+#include <sys/types.h>
+#include <sys/param.h>
+#if defined(__DragonFly__)
+#include <dev/video/meteor/ioctl_meteor.h>
+#include <dev/video/bktr/ioctl_bt848.h>
+#elif __FreeBSD_version >= 502100
+#include <dev/bktr/ioctl_meteor.h>
+#include <dev/bktr/ioctl_bt848.h>
+#else
+#include <machine/ioctl_meteor.h>
+#include <machine/ioctl_bt848.h>
+#endif
+int main(void) { return 0; }
+EOF
+    cc_check && _radio_bsdbt848=yes
+  fi
 fi
+if test "$_radio_bsdbt848" = yes ; then
+  _def_radio_bsdbt848='#define HAVE_RADIO_BSDBT848 1'
+else
+  _def_radio_bsdbt848='#undef HAVE_RADIO_BSDBT848'
+fi
+echores "$_radio_bsdbt848"
+fi #bsd
 
+if test "$_radio_v4l" = no && test "$_radio_v4l2" = no && test "$_radio_bsdbt848" = no && 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
@@ -7986,6 +8020,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: help/help_mp-en.h
===================================================================
--- help/help_mp-en.h	(revision 20736)
+++ help/help_mp-en.h	(working copy)
@@ -1863,9 +1863,11 @@
 #define MSGTR_RADIO_SetFreqFailed "[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n"
 #define MSGTR_RADIO_GetFreqFailed "[radio] ioctl get frequency failed: %s\n"
 #define MSGTR_RADIO_SetMuteFailed "[radio] ioctl set mute failed: %s\n"
+#define MSGTR_RADIO_SetUnMuteFailed "[radio] ioctl set unmute failed: %s\n"
 #define MSGTR_RADIO_QueryControlFailed "[radio] ioctl query control failed: %s\n"
 #define MSGTR_RADIO_GetVolumeFailed "[radio] ioctl get volume failed: %s\n"
 #define MSGTR_RADIO_SetVolumeFailed "[radio] ioctl set volume failed: %s\n"
+#define MSGTR_RADIO_OpenMixerFailed "[radio] Warning: open mixer failed: %s\n"
 #define MSGTR_RADIO_DroppingFrame "\n[radio] too bad - dropping audio frame (%d bytes)!\n"
 #define MSGTR_RADIO_BufferEmpty "[radio] grab_audio_frame: buffer empty, waiting for %d data bytes.\n"
 #define MSGTR_RADIO_AudioInitFailed "[radio] audio_in_init failed: %s\n"
@@ -1889,4 +1891,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