[MPlayer-dev-eng] [PATCH] setting the audio source for recording tv-audio through the soundcard

Ivan Szanto szivan at duticai.TWI.TUDelft.NL
Wed Mar 19 01:52:35 CET 2003


Hi,


to show how happy I am that Michael actually tried to apply
my previous patch, and just to generate some more traffic on the
list, here's a next patch.

** Problem description:

My tv capture card (Matrox Marvel) is outside of my computer in
a break-out box. To get audio data from it I need to connect it
to the soundcard. I like to connect it to the line-in jack of
the soundcard, because that has a better quality than the microphone jack.

This configuration is currently not supported by mencoder, that is,
it records no sound for me, probably for the following two reasons

 - the default audio source is probably the microphone jack
 - I think my tv capture card does not report the audio capability

** Solution:

The attached patch overcomes the first problem by defining the
audiosource parameter that enables the user to choose from the
possible audio sources. I implemented this only for OSS, don't know
how to do it for alsa. However, this should not be a problem, since
I use alsa oss emulation myself.

The second problem is overcome by setting the forceaudio parameter,
but the patch also makes sure that it forces audio even if the card
reports no audio capability.

I tried to make the first change by respecting the audio_in encapsulation,
this is why I defined there a new "member" (oss.source) and
a new "method" (audio_in_set_source).

How to set the audio source I learned from mjpegtools/liblavrec.c.
The rest should be self-explanatory.

** command line

Just to make sure it is clear what I mean, here's a command line:

mencoder -tv on:driver=v4l:input=2:width=352:height=288:forceaudio:audiosource=l
-aspect 4:3 -oac mp3lame -vop dint -ovc lavc -lameopts abr:br=128 -o o.avi

This works fine for my config, otherwise I get no sound.

Ivan
-------------- next part --------------
diff -Naur main/libmpdemux/ai_oss.c main-mjpeg/libmpdemux/ai_oss.c
--- main/libmpdemux/ai_oss.c	Sat Sep 28 18:42:17 2002
+++ main-mjpeg/libmpdemux/ai_oss.c	Wed Mar 19 00:49:09 2003
@@ -132,6 +132,30 @@
 	mp_msg(MSGT_TV, MSGL_ERR, "audio block size too low, setting to %d!\n", ai->blocksize);
     }
 
+    if ( ai->oss.source )
+    {
+      switch ( *(ai->oss.source) )
+      {
+        case 'm':
+          ioctl_param = SOUND_MASK_MIC;
+          mp_msg(MSGT_TV, MSGL_V, "about to set audio source to microphone\n");
+                      break;
+        case 'l':
+          ioctl_param = SOUND_MASK_LINE;
+          mp_msg(MSGT_TV, MSGL_V, "about to set audio source to line-in\n");
+                      break;
+        case 'c':
+          ioctl_param = SOUND_MASK_CD;
+          mp_msg(MSGT_TV, MSGL_V, "about to set audio source to cd-rom\n");
+                      break;
+      }
+      mp_msg(MSGT_TV, MSGL_V, "ioctl  SOUND_MIXER_WRITE_RECSRC: %d\n", ioctl_param);
+      err = ioctl(ai->oss.audio_fd, SOUND_MIXER_WRITE_RECSRC, &ioctl_param);
+      if (err < 0) {
+	mp_msg(MSGT_TV, MSGL_ERR, "Unable to set SOUND_MIXER_WRITE_RECSRC\n");
+      }
+    }
+
     ai->samplesize = 16;
     ai->bytes_per_sample = 2;
 
diff -Naur main/libmpdemux/audio_in.c main-mjpeg/libmpdemux/audio_in.c
--- main/libmpdemux/audio_in.c	Sat Nov 23 10:58:08 2002
+++ main-mjpeg/libmpdemux/audio_in.c	Wed Mar 19 00:30:14 2003
@@ -35,6 +35,7 @@
     case AUDIO_IN_OSS:
 	ai->oss.audio_fd = -1;
 	ai->oss.device = strdup("/dev/dsp");
+	ai->oss.source = 0;
 	return 0;
 #endif
     default:
@@ -133,6 +134,15 @@
     default:
 	return -1;
     }
+}
+
+int audio_in_set_source(audio_in_t *ai, char *source)
+{
+#ifdef USE_OSS_AUDIO
+  if (ai->setup) return -1;
+  if ( source )
+	ai->oss.source = strdup(source);
+#endif
 }
 
 int audio_in_uninit(audio_in_t *ai)
diff -Naur main/libmpdemux/audio_in.h main-mjpeg/libmpdemux/audio_in.h
--- main/libmpdemux/audio_in.h	Sat Dec 28 13:39:51 2002
+++ main-mjpeg/libmpdemux/audio_in.h	Wed Mar 19 00:30:24 2003
@@ -22,6 +22,7 @@
 #ifdef USE_OSS_AUDIO
 typedef struct {
     char *device;
+    char *source;
 
     int audio_fd;
 } ai_oss_t;
@@ -54,6 +55,7 @@
 int audio_in_init(audio_in_t *ai, int type);
 int audio_in_setup(audio_in_t *ai);
 int audio_in_set_device(audio_in_t *ai, char *device);
+int audio_in_set_source(audio_in_t *ai, char *source);
 int audio_in_set_samplerate(audio_in_t *ai, int rate);
 int audio_in_set_channels(audio_in_t *ai, int channels);
 int audio_in_uninit(audio_in_t *ai);
diff -Naur main/libmpdemux/tv.c main-mjpeg/libmpdemux/tv.c
--- main/libmpdemux/tv.c	Wed Mar 19 00:35:52 2003
+++ main-mjpeg/libmpdemux/tv.c	Wed Mar 19 00:28:57 2003
@@ -62,6 +62,7 @@
 int tv_param_balance = -1;
 int tv_param_forcechan = -1;
 int tv_param_force_audio = 0;
+int tv_param_audio_source = 0;
 int tv_param_buffer_size = -1;
 int tv_param_mjpeg = 0;
 int tv_param_decimation = 2;
diff -Naur main/libmpdemux/tv.h main-mjpeg/libmpdemux/tv.h
--- main/libmpdemux/tv.h	Wed Mar 19 00:35:52 2003
+++ main-mjpeg/libmpdemux/tv.h	Wed Mar 19 00:29:03 2003
@@ -33,6 +33,7 @@
 extern int tv_param_balance;
 extern int tv_param_forcechan;
 extern int tv_param_force_audio;
+extern int tv_param_audio_source;
 extern int tv_param_buffer_size;
 extern int tv_param_mjpeg;
 extern int tv_param_decimation;
diff -Naur main/libmpdemux/tvi_v4l.c main-mjpeg/libmpdemux/tvi_v4l.c
--- main/libmpdemux/tvi_v4l.c	Wed Mar 19 00:35:52 2003
+++ main-mjpeg/libmpdemux/tvi_v4l.c	Wed Mar 19 00:29:49 2003
@@ -618,6 +618,7 @@
 	if (priv->audio_device) {
 	    audio_in_set_device(&priv->audio_in, priv->audio_device);
 	}
+        audio_in_set_source(&priv->audio_in, tv_param_audio_source);
 
 	if (tv_param_audio_id < priv->capability.audios)
 	    priv->audio_id = tv_param_audio_id;
@@ -943,6 +944,8 @@
 	    return(TVI_CONTROL_FALSE);
 	}
 	case TVI_CONTROL_IS_AUDIO:
+	    if (tv_param_force_audio)
+		return(TVI_CONTROL_TRUE);
 	    if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
 	    {
 		return(TVI_CONTROL_TRUE);
--- main/cfg-common.h	Wed Mar 19 00:35:52 2003
+++ main-mjpeg/cfg-common.h	Wed Mar 19 00:28:25 2003
@@ -285,6 +285,7 @@
 	{"balance", &tv_param_balance, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
 	{"forcechan", &tv_param_forcechan, CONF_TYPE_INT, CONF_RANGE, 1, 2, NULL},
 	{"forceaudio", &tv_param_force_audio, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"audiosource", &tv_param_audio_source, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"buffersize", &tv_param_buffer_size, CONF_TYPE_INT, CONF_RANGE, 16, 1024, NULL},
 	{"mjpeg", &tv_param_mjpeg, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"decimation", &tv_param_decimation, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
diff -Naur main/DOCS/en/mplayer.1 main-mjpeg/DOCS/en/mplayer.1
--- main/DOCS/en/mplayer.1	Wed Mar 19 00:35:52 2003
+++ main-mjpeg/DOCS/en/mplayer.1	Wed Mar 19 00:43:58 2003
@@ -777,6 +777,15 @@
 .br
 hardware ID for ALSA
 .REss
+.IPs audiosource=<l,m,c>
+set the audio capture source (OSS only)
+.RSss
+l: line-in
+.br
+m: microphone
+.br
+c: cd-rom
+.REss
 .IPs audioid=<value>
 choose an audio output of the capture card, if it has more of them
 .IPs "[volume|bass|treble|balance]=<0\-65535>"


More information about the MPlayer-dev-eng mailing list