30426
|
1 /*
|
|
2 * This file is part of MPlayer.
|
|
3 *
|
|
4 * MPlayer is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * MPlayer is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License along
|
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
17 */
|
|
18
|
7213
|
19 #include <stdio.h>
|
|
20 #include <stdlib.h>
|
|
21
|
7060
|
22 #include "config.h"
|
7091
2459fcc7baaf
Martin Olschewski <olschewski@zpr.uni-koeln.de>: [PATCH] ai_oss.c should check for USE_OSS_AUDIO
alex
diff
changeset
|
23
|
7213
|
24 #include <string.h> /* strerror */
|
|
25 #include <fcntl.h>
|
|
26 #include <errno.h>
|
|
27 #include <sys/ioctl.h>
|
|
28
|
7066
|
29 #ifdef HAVE_SYS_SOUNDCARD_H
|
|
30 #include <sys/soundcard.h>
|
|
31 #else
|
|
32 #ifdef HAVE_SOUNDCARD_H
|
|
33 #include <soundcard.h>
|
|
34 #else
|
7060
|
35 #include <linux/soundcard.h>
|
7066
|
36 #endif
|
|
37 #endif
|
7060
|
38
|
|
39 #include "audio_in.h"
|
|
40 #include "mp_msg.h"
|
16882
|
41 #include "help_mp.h"
|
7060
|
42
|
|
43 int ai_oss_set_samplerate(audio_in_t *ai)
|
|
44 {
|
|
45 int tmp = ai->req_samplerate;
|
|
46 if (ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &tmp) == -1) return -1;
|
11772
|
47 ai->samplerate = tmp;
|
7060
|
48 return 0;
|
|
49 }
|
|
50
|
|
51 int ai_oss_set_channels(audio_in_t *ai)
|
|
52 {
|
|
53 int err;
|
|
54 int ioctl_param;
|
|
55
|
|
56 if (ai->req_channels > 2)
|
|
57 {
|
|
58 ioctl_param = ai->req_channels;
|
|
59 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp channels: %d\n",
|
|
60 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param));
|
|
61 if (err < 0) {
|
16882
|
62 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetChanCount,
|
7060
|
63 ai->req_channels);
|
|
64 return -1;
|
|
65 }
|
11878
|
66 ai->channels = ioctl_param;
|
7060
|
67 }
|
|
68 else
|
|
69 {
|
|
70 ioctl_param = (ai->req_channels == 2);
|
|
71 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp stereo: %d (req: %d)\n",
|
|
72 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param),
|
|
73 ioctl_param);
|
|
74 if (err < 0) {
|
16882
|
75 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetStereo,
|
7060
|
76 ai->req_channels == 2);
|
|
77 return -1;
|
|
78 }
|
11878
|
79 ai->channels = ioctl_param ? 2 : 1;
|
7060
|
80 }
|
|
81 return 0;
|
|
82 }
|
|
83
|
|
84 int ai_oss_init(audio_in_t *ai)
|
|
85 {
|
|
86 int err;
|
|
87 int ioctl_param;
|
|
88
|
|
89 ai->oss.audio_fd = open(ai->oss.device, O_RDONLY);
|
|
90 if (ai->oss.audio_fd < 0)
|
|
91 {
|
16882
|
92 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2Open,
|
7060
|
93 ai->oss.device, strerror(errno));
|
|
94 return -1;
|
|
95 }
|
29263
|
96
|
7060
|
97 ioctl_param = 0 ;
|
|
98 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getfmt: %d\n",
|
|
99 ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param));
|
29263
|
100
|
7060
|
101 mp_msg(MSGT_TV, MSGL_V, "Supported formats: %x\n", ioctl_param);
|
|
102 if (!(ioctl_param & AFMT_S16_LE))
|
16882
|
103 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_UnsupportedFmt);
|
7060
|
104
|
|
105 ioctl_param = AFMT_S16_LE;
|
|
106 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp setfmt: %d\n",
|
|
107 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param));
|
|
108 if (err < 0) {
|
16882
|
109 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetAudioFmt);
|
7060
|
110 return -1;
|
|
111 }
|
|
112
|
|
113 if (ai_oss_set_channels(ai) < 0) return -1;
|
29263
|
114
|
7060
|
115 ioctl_param = ai->req_samplerate;
|
|
116 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp speed: %d\n",
|
|
117 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param));
|
|
118 if (err < 0) {
|
16882
|
119 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetSamplerate,
|
7060
|
120 ai->req_samplerate);
|
|
121 return -1;
|
|
122 }
|
11878
|
123 ai->samplerate = ioctl_param;
|
7060
|
124
|
|
125 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
|
|
126 ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param));
|
|
127 mp_msg(MSGT_TV, MSGL_V, "trigger: %x\n", ioctl_param);
|
|
128 ioctl_param = PCM_ENABLE_INPUT;
|
|
129 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n",
|
|
130 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param));
|
|
131 if (err < 0) {
|
16882
|
132 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2SetTrigger,
|
7060
|
133 PCM_ENABLE_INPUT);
|
|
134 }
|
|
135
|
|
136 ai->blocksize = 0;
|
|
137 mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getblocksize: %d\n",
|
|
138 err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize));
|
|
139 if (err < 0) {
|
16882
|
140 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_Unable2GetBlockSize);
|
7060
|
141 }
|
|
142 mp_msg(MSGT_TV, MSGL_V, "blocksize: %d\n", ai->blocksize);
|
|
143
|
|
144 // correct the blocksize to a reasonable value
|
|
145 if (ai->blocksize <= 0) {
|
|
146 ai->blocksize = 4096*ai->channels*2;
|
16882
|
147 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_AudioBlockSizeZero, ai->blocksize);
|
7060
|
148 } else if (ai->blocksize < 4096*ai->channels*2) {
|
|
149 ai->blocksize *= 4096*ai->channels*2/ai->blocksize;
|
16882
|
150 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIOSS_AudioBlockSize2Low, ai->blocksize);
|
7060
|
151 }
|
|
152
|
|
153 ai->samplesize = 16;
|
|
154 ai->bytes_per_sample = 2;
|
|
155
|
|
156 return 0;
|
|
157 }
|