Mercurial > mplayer.hg
annotate libao2/ao_alsa5.c @ 28664:68542628747d
Make alpha arch detection more lenient. Taken from the Debian patchset.
author | diego |
---|---|
date | Sat, 21 Feb 2009 22:08:50 +0000 |
parents | e45b08f2f5d3 |
children | 9a5b8c2ed6de |
rev | line source |
---|---|
996 | 1 /* |
28343 | 2 * ALSA 0.5.x audio output driver |
3 * | |
4 * Copyright (C) 2001 Alex Beregszaszi | |
5 * | |
6 * Thanks to Arpi for helping me ;) | |
7 * | |
8 * MPlayer is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * MPlayer is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License along | |
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 */ | |
996 | 22 |
23 #include <errno.h> | |
24 #include <sys/asoundlib.h> | |
25 | |
14123 | 26 #include "config.h" |
996 | 27 |
28 #include "audio_out.h" | |
29 #include "audio_out_internal.h" | |
14245 | 30 #include "libaf/af_format.h" |
996 | 31 |
14123 | 32 #include "mp_msg.h" |
33 #include "help_mp.h" | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
34 |
996 | 35 static ao_info_t info = |
36 { | |
37 "ALSA-0.5.x audio output", | |
38 "alsa5", | |
10366 | 39 "Alex Beregszaszi", |
996 | 40 "" |
41 }; | |
42 | |
43 LIBAO_EXTERN(alsa5) | |
44 | |
45 static snd_pcm_t *alsa_handler; | |
46 static snd_pcm_format_t alsa_format; | |
47 static int alsa_rate = SND_PCM_RATE_CONTINUOUS; | |
48 | |
49 /* to set/get/query special features/parameters */ | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8027
diff
changeset
|
50 static int control(int cmd, void *arg) |
996 | 51 { |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
52 return CONTROL_UNKNOWN; |
996 | 53 } |
54 | |
55 /* | |
56 open & setup audio device | |
57 return: 1=success 0=fail | |
58 */ | |
59 static int init(int rate_hz, int channels, int format, int flags) | |
60 { | |
61 int err; | |
62 int cards = -1; | |
63 snd_pcm_channel_params_t params; | |
64 snd_pcm_channel_setup_t setup; | |
65 snd_pcm_info_t info; | |
66 snd_pcm_channel_info_t chninfo; | |
67 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
68 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ALSA5_InitInfo, rate_hz, |
14264 | 69 channels, af_fmt2str_short(format)); |
996 | 70 |
71 alsa_handler = NULL; | |
72 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
73 mp_msg(MSGT_AO, MSGL_V, "alsa-init: compiled for ALSA-%s (%d)\n", SND_LIB_VERSION_STR, |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
74 SND_LIB_VERSION); |
996 | 75 |
76 if ((cards = snd_cards()) < 0) | |
77 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
78 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_SoundCardNotFound); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
79 return 0; |
996 | 80 } |
81 | |
3095 | 82 ao_data.format = format; |
7659 | 83 ao_data.channels = channels; |
3095 | 84 ao_data.samplerate = rate_hz; |
7659 | 85 ao_data.bps = ao_data.samplerate*ao_data.channels; |
3095 | 86 ao_data.outburst = OUTBURST; |
87 ao_data.buffersize = 16384; | |
996 | 88 |
89 memset(&alsa_format, 0, sizeof(alsa_format)); | |
90 switch (format) | |
91 { | |
14245 | 92 case AF_FORMAT_S8: |
996 | 93 alsa_format.format = SND_PCM_SFMT_S8; |
94 break; | |
14245 | 95 case AF_FORMAT_U8: |
996 | 96 alsa_format.format = SND_PCM_SFMT_U8; |
97 break; | |
14245 | 98 case AF_FORMAT_U16_LE: |
996 | 99 alsa_format.format = SND_PCM_SFMT_U16_LE; |
100 break; | |
14245 | 101 case AF_FORMAT_U16_BE: |
996 | 102 alsa_format.format = SND_PCM_SFMT_U16_BE; |
103 break; | |
5790 | 104 #ifndef WORDS_BIGENDIAN |
14245 | 105 case AF_FORMAT_AC3: |
5790 | 106 #endif |
14245 | 107 case AF_FORMAT_S16_LE: |
996 | 108 alsa_format.format = SND_PCM_SFMT_S16_LE; |
109 break; | |
5790 | 110 #ifdef WORDS_BIGENDIAN |
14245 | 111 case AF_FORMAT_AC3: |
5790 | 112 #endif |
14245 | 113 case AF_FORMAT_S16_BE: |
996 | 114 alsa_format.format = SND_PCM_SFMT_S16_BE; |
115 break; | |
116 default: | |
117 alsa_format.format = SND_PCM_SFMT_MPEG; | |
118 break; | |
119 } | |
120 | |
121 switch(alsa_format.format) | |
122 { | |
123 case SND_PCM_SFMT_S16_LE: | |
124 case SND_PCM_SFMT_U16_LE: | |
3095 | 125 ao_data.bps *= 2; |
996 | 126 break; |
127 case -1: | |
14264 | 128 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_InvalidFormatReq,af_fmt2str_short(format)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
129 return 0; |
1111 | 130 default: |
131 break; | |
996 | 132 } |
133 | |
134 switch(rate_hz) | |
135 { | |
136 case 8000: | |
137 alsa_rate = SND_PCM_RATE_8000; | |
138 break; | |
139 case 11025: | |
140 alsa_rate = SND_PCM_RATE_11025; | |
141 break; | |
142 case 16000: | |
143 alsa_rate = SND_PCM_RATE_16000; | |
144 break; | |
145 case 22050: | |
146 alsa_rate = SND_PCM_RATE_22050; | |
147 break; | |
148 case 32000: | |
149 alsa_rate = SND_PCM_RATE_32000; | |
150 break; | |
151 case 44100: | |
152 alsa_rate = SND_PCM_RATE_44100; | |
153 break; | |
154 case 48000: | |
155 alsa_rate = SND_PCM_RATE_48000; | |
156 break; | |
157 case 88200: | |
158 alsa_rate = SND_PCM_RATE_88200; | |
159 break; | |
160 case 96000: | |
161 alsa_rate = SND_PCM_RATE_96000; | |
162 break; | |
163 case 176400: | |
164 alsa_rate = SND_PCM_RATE_176400; | |
165 break; | |
166 case 192000: | |
167 alsa_rate = SND_PCM_RATE_192000; | |
168 break; | |
169 default: | |
170 alsa_rate = SND_PCM_RATE_CONTINUOUS; | |
171 break; | |
172 } | |
173 | |
3095 | 174 alsa_format.rate = ao_data.samplerate; |
9670
88e4f274df48
10l to arpi with commit r1.12, noticed by Daniel Mario Vega <dv5a@dc.uba.ar>
alex
parents:
9633
diff
changeset
|
175 alsa_format.voices = ao_data.channels; |
996 | 176 alsa_format.interleave = 1; |
177 | |
178 if ((err = snd_pcm_open(&alsa_handler, 0, 0, SND_PCM_OPEN_PLAYBACK)) < 0) | |
179 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
180 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PlayBackError, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
181 return 0; |
996 | 182 } |
183 | |
184 if ((err = snd_pcm_info(alsa_handler, &info)) < 0) | |
185 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
186 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmInfoError, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
187 return 0; |
996 | 188 } |
189 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
190 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ALSA5_SoundcardsFound, |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
191 cards, info.name); |
996 | 192 |
193 if (info.flags & SND_PCM_INFO_PLAYBACK) | |
194 { | |
3700 | 195 memset(&chninfo, 0, sizeof(chninfo)); |
996 | 196 chninfo.channel = SND_PCM_CHANNEL_PLAYBACK; |
197 if ((err = snd_pcm_channel_info(alsa_handler, &chninfo)) < 0) | |
198 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
199 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmChanInfoError, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
200 return 0; |
996 | 201 } |
3095 | 202 |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
203 #ifndef __QNX__ |
996 | 204 if (chninfo.buffer_size) |
3095 | 205 ao_data.buffersize = chninfo.buffer_size; |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
206 #endif |
3095 | 207 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
208 mp_msg(MSGT_AO, MSGL_V, "alsa-init: setting preferred buffer size from driver: %d bytes\n", |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
209 ao_data.buffersize); |
996 | 210 } |
211 | |
212 memset(¶ms, 0, sizeof(params)); | |
213 params.channel = SND_PCM_CHANNEL_PLAYBACK; | |
214 params.mode = SND_PCM_MODE_STREAM; | |
215 params.format = alsa_format; | |
216 params.start_mode = SND_PCM_START_DATA; | |
217 params.stop_mode = SND_PCM_STOP_ROLLOVER; | |
3095 | 218 params.buf.stream.queue_size = ao_data.buffersize; |
996 | 219 params.buf.stream.fill = SND_PCM_FILL_NONE; |
220 | |
221 if ((err = snd_pcm_channel_params(alsa_handler, ¶ms)) < 0) | |
222 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
223 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_CantSetParms, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
224 return 0; |
996 | 225 } |
226 | |
227 memset(&setup, 0, sizeof(setup)); | |
228 setup.channel = SND_PCM_CHANNEL_PLAYBACK; | |
229 setup.mode = SND_PCM_MODE_STREAM; | |
230 setup.format = alsa_format; | |
3095 | 231 setup.buf.stream.queue_size = ao_data.buffersize; |
232 setup.msbits_per_sample = ao_data.bps; | |
996 | 233 |
234 if ((err = snd_pcm_channel_setup(alsa_handler, &setup)) < 0) | |
235 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
236 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_CantSetChan, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
237 return 0; |
996 | 238 } |
239 | |
240 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
241 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
242 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ChanPrepareError, snd_strerror(err)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
243 return 0; |
996 | 244 } |
245 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
246 mp_msg(MSGT_AO, MSGL_INFO, "AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n", |
7659 | 247 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, |
996 | 248 snd_pcm_get_format_name(alsa_format.format)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
249 return 1; |
996 | 250 } |
251 | |
252 /* close audio device */ | |
12145 | 253 static void uninit(int immed) |
996 | 254 { |
1055 | 255 int err; |
256 | |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
257 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
258 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
259 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_DrainError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
260 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
261 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
262 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
263 if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
264 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
265 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_FlushError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
266 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
267 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
268 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
269 if ((err = snd_pcm_close(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
270 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
271 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmCloseError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
272 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
273 } |
996 | 274 } |
275 | |
276 /* stop playing and empty buffers (for seeking/pause) */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
277 static void reset(void) |
996 | 278 { |
279 int err; | |
280 | |
281 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) | |
282 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
283 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetDrainError, snd_strerror(err)); |
996 | 284 return; |
285 } | |
286 | |
287 if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
288 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
289 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetFlushError, snd_strerror(err)); |
996 | 290 return; |
291 } | |
292 | |
293 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
294 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
295 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetChanPrepareError, snd_strerror(err)); |
996 | 296 return; |
297 } | |
298 } | |
299 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
300 /* stop playing, keep buffers (for pause) */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
301 static void audio_pause(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
302 { |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
303 int err; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
304 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
305 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
306 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
307 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PauseDrainError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
308 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
309 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
310 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
311 if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
312 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
313 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PauseFlushError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
314 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
315 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
316 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
317 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
318 /* resume playing, after audio_pause() */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
319 static void audio_resume(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
320 { |
1055 | 321 int err; |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
322 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
323 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
324 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResumePrepareError, snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
325 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
326 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
327 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
328 |
996 | 329 /* |
330 plays 'len' bytes of 'data' | |
331 returns: number of bytes played | |
332 */ | |
333 static int play(void* data, int len, int flags) | |
334 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
335 int got_len; |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
336 |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
337 if (!len) |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
338 return 0; |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
339 |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
340 if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 341 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
342 if (got_len == -EPIPE) /* underrun? */ |
996 | 343 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
344 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_Underrun); |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
345 if ((got_len = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
996 | 346 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
347 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PlaybackPrepareError, snd_strerror(got_len)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
348 return 0; |
996 | 349 } |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
350 if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 351 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
352 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_WriteErrorAfterReset, |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
353 snd_strerror(got_len)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
354 return 0; |
996 | 355 } |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
356 return got_len; /* 2nd write was ok */ |
996 | 357 } |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
358 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_OutPutError, snd_strerror(got_len)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
359 return 0; |
996 | 360 } |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
361 return got_len; |
996 | 362 } |
363 | |
364 /* how many byes are free in the buffer */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
365 static int get_space(void) |
996 | 366 { |
367 snd_pcm_channel_status_t ch_stat; | |
368 | |
369 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; | |
370 | |
371 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) | |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
372 return 0; /* error occurred */ |
996 | 373 else |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
374 return ch_stat.free; |
996 | 375 } |
376 | |
3095 | 377 /* delay in seconds between first and last sample in buffer */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
378 static float get_delay(void) |
996 | 379 { |
380 snd_pcm_channel_status_t ch_stat; | |
381 | |
382 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; | |
383 | |
384 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) | |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
385 return (float)ao_data.buffersize/(float)ao_data.bps; /* error occurred */ |
996 | 386 else |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
387 return (float)ch_stat.count/(float)ao_data.bps; |
996 | 388 } |