[MPlayer-users] [PATCH] TV Audio for SAA7134 and other V4L2 drivers

Bernhard Rosenkraenzer bero at arklinux.org
Mon Jun 16 19:08:34 CEST 2003


It's a fairly well known problem: If used with a video4linux2 driver (such 
as the SAA7134 driver), analog TV doesn't have audio unless you launch 
xawtv or the likes just to enable audio.

The problem is that the video4linux1 compatibility layer in v4l2 doesn't 
support audio settings (it always returns there are no audio devices).

This patch makes mplayer use video4linux 2 for the audio settings parts 
(video is still done with the video4linux 1 compat layer - that works).

It's #ifdef'ed in stuff that v4l2 defines and v4l1 doesn't, so if you're 
using v4l1, the patch shouldn't change anything.

LLaP
bero

-- 
Ark Linux - Linux for the masses
http://www.arklinux.org/

Redistribution and processing of this message is subject to
http://www.arklinux.org/terms.php
-------------- next part --------------
--- mplayer/libmpdemux/tvi_v4l.c.ark	2003-05-29 20:17:31.000000000 +0200
+++ mplayer/libmpdemux/tvi_v4l.c	2003-05-29 20:48:22.000000000 +0200
@@ -12,6 +12,9 @@
   Mjpeg hardware encoding support by 
     Iv?n Sz?nt? <szivan at freemail.hu>
 
+  Basic video4linux2 support by
+    Bernhard Rosenkraenzer <bero at arklinux.org>
+
   CODE IS UNDER DEVELOPMENT, NO FEATURE REQUESTS PLEASE!
 */
 
@@ -433,6 +436,15 @@
 	mp_msg(MSGT_TV, MSGL_ERR, "ioctl get capabilites failed: %s\n", strerror(errno));
 	goto err;
     }
+#ifdef V4L2_CID_AUDIO_MUTE
+    /* V4L2's compat layer fails to report the correct number of audio devices */
+    struct v4l2_input input;
+    int index;
+    ioctl(priv->video_fd, VIDIOC_G_INPUT, &index);
+    input.index = index;
+    ioctl(priv->video_fd, VIDIOC_ENUMINPUT, &input);
+    priv->capability.audios = input.audioset;
+#endif
 
     fcntl(priv->video_fd, F_SETFD, FD_CLOEXEC);
 
@@ -670,6 +682,14 @@
 	priv->audio[priv->audio_id].flags |= VIDEO_AUDIO_MUTE;
 	ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
     }
+
+#ifdef V4L2_CID_AUDIO_MUTE
+    /* v4l2's v4l1 emulation doesn't get audio right --> work around it */
+    struct v4l2_control ctrl;
+    ctrl.id = V4L2_CID_AUDIO_MUTE;
+    ctrl.value = 1;
+    ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+#endif
     
     if ( tv_param_mjpeg )
       {
@@ -922,6 +942,36 @@
 	mp_msg(MSGT_TV, MSGL_V, " chan=%d\n", priv->audio_channels[priv->audio_id]);
 	ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
     }
+#ifdef V4L2_CID_AUDIO_MUTE
+    /* v4l2's v4l1 emulation doesn't get audio right --> work around it */
+    struct v4l2_control ctrl;
+    ctrl.id = V4L2_CID_AUDIO_MUTE;
+    ctrl.value = 0;
+    ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+    if(tv_param_volume >= 0) {
+      ctrl.id = V4L2_CID_AUDIO_VOLUME;
+      ctrl.value = tv_param_volume;
+      ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+    }
+
+    if(tv_param_bass >= 0) {
+      ctrl.id = V4L2_CID_AUDIO_BASS;
+      ctrl.value = tv_param_bass;
+      ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+    }
+
+    if(tv_param_treble >= 0) {
+      ctrl.id = V4L2_CID_AUDIO_TREBLE;
+      ctrl.value = tv_param_treble;
+      ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+    }
+
+    if(tv_param_balance >= 0) {
+      ctrl.id = V4L2_CID_AUDIO_BALANCE;
+      ctrl.value = tv_param_balance;
+      ioctl(priv->video_fd, VIDIOC_S_CTRL, &ctrl);
+    }
+#endif
     
     /* launch capture threads */
     priv->shutdown = 0;
--- mplayer/cfg-common.h.ark	2003-05-29 20:44:34.000000000 +0200
+++ mplayer/cfg-common.h	2003-05-29 20:44:54.000000000 +0200
@@ -277,7 +277,7 @@
 #ifdef USE_TV
 struct config tvopts_conf[]={
 	{"on", "-tv on is deprecated, use tv:// instead\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
-#ifdef HAVE_TV_BSDBT848
+#if defined(HAVE_TV_BSDBT848) || defined(HAVE_TV_V4L)
 	{"immediatemode", &tv_param_immediate, CONF_TYPE_FLAG, 0, 0, 0, NULL},
 #endif
 	{"noaudio", &tv_param_noaudio, CONF_TYPE_FLAG, 0, 0, 1, NULL},


More information about the MPlayer-users mailing list