summaryrefslogtreecommitdiffstats
path: root/libmpdemux/ai_oss.c
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-08-21 22:50:40 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-08-21 22:50:40 +0000
commit6c724895d6e36eaa749798efdeb826061ed03022 (patch)
tree7d61d28a4af232ed3ecd401efe3c349c9119a8d5 /libmpdemux/ai_oss.c
parent5a92702245bfbcaec3c013ff6512aa2e5641cbd7 (diff)
downloadmpv-6c724895d6e36eaa749798efdeb826061ed03022.tar.bz2
mpv-6c724895d6e36eaa749798efdeb826061ed03022.tar.xz
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
- multithreaded audio/video buffering (I know mplayer crew hates threads but it seems to me as the only way of doing reliable a/v capture) - a/v timebase synchronization (sample count vs. gettimeofday) - "immediate" mode support for mplayer - fixed colorspace stuff - RGB?? and YUY2 modes now work as expected - native ALSA audio capture - separated audio input layer git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7061 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux/ai_oss.c')
-rw-r--r--libmpdemux/ai_oss.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/libmpdemux/ai_oss.c b/libmpdemux/ai_oss.c
new file mode 100644
index 0000000000..54cf50b643
--- /dev/null
+++ b/libmpdemux/ai_oss.c
@@ -0,0 +1,123 @@
+#include "config.h"
+#include <linux/soundcard.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "audio_in.h"
+#include "mp_msg.h"
+
+int ai_oss_set_samplerate(audio_in_t *ai)
+{
+ int tmp = ai->req_samplerate;
+ if (ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1) return -1;
+ ai->samplerate = ai->req_samplerate;
+ return 0;
+}
+
+int ai_oss_set_channels(audio_in_t *ai)
+{
+ int err;
+ int ioctl_param;
+
+ if (ai->req_channels > 2)
+ {
+ ioctl_param = ai->req_channels;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp channels: %d\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to set channel count: %d\n",
+ ai->req_channels);
+ return -1;
+ }
+ }
+ else
+ {
+ ioctl_param = (ai->req_channels == 2);
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp stereo: %d (req: %d)\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
+ ioctl_param);
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to set stereo: %d\n",
+ ai->req_channels == 2);
+ return -1;
+ }
+ }
+ ai->channels = ai->req_channels;
+ return 0;
+}
+
+int ai_oss_init(audio_in_t *ai)
+{
+ int err;
+ int ioctl_param;
+
+ ai->oss.audio_fd = open(ai->oss.device, O_RDONLY);
+ if (ai->oss.audio_fd < 0)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n",
+ ai->oss.device, strerror(errno));
+ return -1;
+ }
+
+ ioctl_param = 0 ;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getfmt: %d\n",
+ ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
+
+ mp_msg(MSGT_TV, MSGL_V, "Supported formats: %x\n", ioctl_param);
+ if (!(ioctl_param & AFMT_S16_LE))
+ mp_msg(MSGT_TV, MSGL_ERR, "notsupported format\n");
+
+ ioctl_param = AFMT_S16_LE;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp setfmt: %d\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to set audio format.");
+ return -1;
+ }
+
+ if (ai_oss_set_channels(ai) < 0) return -1;
+
+ ioctl_param = ai->req_samplerate;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp speed: %d\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to set samplerate: %d\n",
+ ai->req_samplerate);
+ return -1;
+ }
+ ai->samplerate = ai->req_samplerate;
+
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
+ ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
+ mp_msg(MSGT_TV, MSGL_V, "trigger: %x\n", ioctl_param);
+ ioctl_param = PCM_ENABLE_INPUT;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to set trigger: %d\n",
+ PCM_ENABLE_INPUT);
+ return -1;
+ }
+
+ ai->blocksize = 0;
+ mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getblocksize: %d\n",
+ err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize));
+ if (err < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to get block size!\n");
+ }
+ mp_msg(MSGT_TV, MSGL_V, "blocksize: %d\n", ai->blocksize);
+
+ // correct the blocksize to a reasonable value
+ if (ai->blocksize <= 0) {
+ ai->blocksize = 4096*ai->channels*2;
+ mp_msg(MSGT_TV, MSGL_ERR, "audio block size is zero, setting to %d!\n", ai->blocksize);
+ } else if (ai->blocksize < 4096*ai->channels*2) {
+ ai->blocksize *= 4096*ai->channels*2/ai->blocksize;
+ mp_msg(MSGT_TV, MSGL_ERR, "audio block size too low, setting to %d!\n", ai->blocksize);
+ }
+
+ ai->samplesize = 16;
+ ai->bytes_per_sample = 2;
+
+ return 0;
+}