Mercurial > mplayer.hg
comparison libmpdemux/ai_oss.c @ 7060:b14880a6cccb
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
author | arpi |
---|---|
date | Wed, 21 Aug 2002 22:50:40 +0000 |
parents | |
children | e0255720a67c |
comparison
equal
deleted
inserted
replaced
7059:5285a81929a5 | 7060:b14880a6cccb |
---|---|
1 #include "config.h" | |
2 #include <linux/soundcard.h> | |
3 #include <fcntl.h> | |
4 #include <errno.h> | |
5 | |
6 #include "audio_in.h" | |
7 #include "mp_msg.h" | |
8 | |
9 int ai_oss_set_samplerate(audio_in_t *ai) | |
10 { | |
11 int tmp = ai->req_samplerate; | |
12 if (ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1) return -1; | |
13 ai->samplerate = ai->req_samplerate; | |
14 return 0; | |
15 } | |
16 | |
17 int ai_oss_set_channels(audio_in_t *ai) | |
18 { | |
19 int err; | |
20 int ioctl_param; | |
21 | |
22 if (ai->req_channels > 2) | |
23 { | |
24 ioctl_param = ai->req_channels; | |
25 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp channels: %d\n", | |
26 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param)); | |
27 if (err < 0) { | |
28 mp_msg(MSGT_TV, MSGL_ERR, "Unable to set channel count: %d\n", | |
29 ai->req_channels); | |
30 return -1; | |
31 } | |
32 } | |
33 else | |
34 { | |
35 ioctl_param = (ai->req_channels == 2); | |
36 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp stereo: %d (req: %d)\n", | |
37 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param), | |
38 ioctl_param); | |
39 if (err < 0) { | |
40 mp_msg(MSGT_TV, MSGL_ERR, "Unable to set stereo: %d\n", | |
41 ai->req_channels == 2); | |
42 return -1; | |
43 } | |
44 } | |
45 ai->channels = ai->req_channels; | |
46 return 0; | |
47 } | |
48 | |
49 int ai_oss_init(audio_in_t *ai) | |
50 { | |
51 int err; | |
52 int ioctl_param; | |
53 | |
54 ai->oss.audio_fd = open(ai->oss.device, O_RDONLY); | |
55 if (ai->oss.audio_fd < 0) | |
56 { | |
57 mp_msg(MSGT_TV, MSGL_ERR, "unable to open '%s': %s\n", | |
58 ai->oss.device, strerror(errno)); | |
59 return -1; | |
60 } | |
61 | |
62 ioctl_param = 0 ; | |
63 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getfmt: %d\n", | |
64 ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param)); | |
65 | |
66 mp_msg(MSGT_TV, MSGL_V, "Supported formats: %x\n", ioctl_param); | |
67 if (!(ioctl_param & AFMT_S16_LE)) | |
68 mp_msg(MSGT_TV, MSGL_ERR, "notsupported format\n"); | |
69 | |
70 ioctl_param = AFMT_S16_LE; | |
71 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp setfmt: %d\n", | |
72 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param)); | |
73 if (err < 0) { | |
74 mp_msg(MSGT_TV, MSGL_ERR, "Unable to set audio format."); | |
75 return -1; | |
76 } | |
77 | |
78 if (ai_oss_set_channels(ai) < 0) return -1; | |
79 | |
80 ioctl_param = ai->req_samplerate; | |
81 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp speed: %d\n", | |
82 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param)); | |
83 if (err < 0) { | |
84 mp_msg(MSGT_TV, MSGL_ERR, "Unable to set samplerate: %d\n", | |
85 ai->req_samplerate); | |
86 return -1; | |
87 } | |
88 ai->samplerate = ai->req_samplerate; | |
89 | |
90 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n", | |
91 ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param)); | |
92 mp_msg(MSGT_TV, MSGL_V, "trigger: %x\n", ioctl_param); | |
93 ioctl_param = PCM_ENABLE_INPUT; | |
94 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n", | |
95 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param)); | |
96 if (err < 0) { | |
97 mp_msg(MSGT_TV, MSGL_ERR, "Unable to set trigger: %d\n", | |
98 PCM_ENABLE_INPUT); | |
99 return -1; | |
100 } | |
101 | |
102 ai->blocksize = 0; | |
103 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getblocksize: %d\n", | |
104 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize)); | |
105 if (err < 0) { | |
106 mp_msg(MSGT_TV, MSGL_ERR, "Unable to get block size!\n"); | |
107 } | |
108 mp_msg(MSGT_TV, MSGL_V, "blocksize: %d\n", ai->blocksize); | |
109 | |
110 // correct the blocksize to a reasonable value | |
111 if (ai->blocksize <= 0) { | |
112 ai->blocksize = 4096*ai->channels*2; | |
113 mp_msg(MSGT_TV, MSGL_ERR, "audio block size is zero, setting to %d!\n", ai->blocksize); | |
114 } else if (ai->blocksize < 4096*ai->channels*2) { | |
115 ai->blocksize *= 4096*ai->channels*2/ai->blocksize; | |
116 mp_msg(MSGT_TV, MSGL_ERR, "audio block size too low, setting to %d!\n", ai->blocksize); | |
117 } | |
118 | |
119 ai->samplesize = 16; | |
120 ai->bytes_per_sample = 2; | |
121 | |
122 return 0; | |
123 } |