Mercurial > mplayer.hg
annotate libao2/ao_alsa5.c @ 32061:dcdcbe7f6713
Move video_time_usage / vout_time_usage extern var declarations to mpcommon.h.
author | diego |
---|---|
date | Sat, 11 Sep 2010 11:33:07 +0000 |
parents | 02b9c1a452e1 |
children |
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 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
35 static const ao_info_t info = |
996 | 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; | |
30241
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
29401
diff
changeset
|
104 case AF_FORMAT_AC3_LE: |
14245 | 105 case AF_FORMAT_S16_LE: |
996 | 106 alsa_format.format = SND_PCM_SFMT_S16_LE; |
107 break; | |
30241
02b9c1a452e1
Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents:
29401
diff
changeset
|
108 case AF_FORMAT_AC3_BE: |
14245 | 109 case AF_FORMAT_S16_BE: |
996 | 110 alsa_format.format = SND_PCM_SFMT_S16_BE; |
111 break; | |
112 default: | |
113 alsa_format.format = SND_PCM_SFMT_MPEG; | |
114 break; | |
115 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
116 |
996 | 117 switch(alsa_format.format) |
118 { | |
119 case SND_PCM_SFMT_S16_LE: | |
120 case SND_PCM_SFMT_U16_LE: | |
3095 | 121 ao_data.bps *= 2; |
996 | 122 break; |
123 case -1: | |
14264 | 124 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
|
125 return 0; |
1111 | 126 default: |
127 break; | |
996 | 128 } |
129 | |
130 switch(rate_hz) | |
131 { | |
132 case 8000: | |
133 alsa_rate = SND_PCM_RATE_8000; | |
134 break; | |
135 case 11025: | |
136 alsa_rate = SND_PCM_RATE_11025; | |
137 break; | |
138 case 16000: | |
139 alsa_rate = SND_PCM_RATE_16000; | |
140 break; | |
141 case 22050: | |
142 alsa_rate = SND_PCM_RATE_22050; | |
143 break; | |
144 case 32000: | |
145 alsa_rate = SND_PCM_RATE_32000; | |
146 break; | |
147 case 44100: | |
148 alsa_rate = SND_PCM_RATE_44100; | |
149 break; | |
150 case 48000: | |
151 alsa_rate = SND_PCM_RATE_48000; | |
152 break; | |
153 case 88200: | |
154 alsa_rate = SND_PCM_RATE_88200; | |
155 break; | |
156 case 96000: | |
157 alsa_rate = SND_PCM_RATE_96000; | |
158 break; | |
159 case 176400: | |
160 alsa_rate = SND_PCM_RATE_176400; | |
161 break; | |
162 case 192000: | |
163 alsa_rate = SND_PCM_RATE_192000; | |
164 break; | |
165 default: | |
166 alsa_rate = SND_PCM_RATE_CONTINUOUS; | |
167 break; | |
168 } | |
169 | |
3095 | 170 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
|
171 alsa_format.voices = ao_data.channels; |
996 | 172 alsa_format.interleave = 1; |
173 | |
174 if ((err = snd_pcm_open(&alsa_handler, 0, 0, SND_PCM_OPEN_PLAYBACK)) < 0) | |
175 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
176 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
|
177 return 0; |
996 | 178 } |
179 | |
180 if ((err = snd_pcm_info(alsa_handler, &info)) < 0) | |
181 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
182 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
|
183 return 0; |
996 | 184 } |
185 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
186 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
|
187 cards, info.name); |
996 | 188 |
189 if (info.flags & SND_PCM_INFO_PLAYBACK) | |
190 { | |
3700 | 191 memset(&chninfo, 0, sizeof(chninfo)); |
996 | 192 chninfo.channel = SND_PCM_CHANNEL_PLAYBACK; |
193 if ((err = snd_pcm_channel_info(alsa_handler, &chninfo)) < 0) | |
194 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
195 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
|
196 return 0; |
996 | 197 } |
3095 | 198 |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
199 #ifndef __QNX__ |
996 | 200 if (chninfo.buffer_size) |
3095 | 201 ao_data.buffersize = chninfo.buffer_size; |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
202 #endif |
3095 | 203 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
204 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
|
205 ao_data.buffersize); |
996 | 206 } |
207 | |
208 memset(¶ms, 0, sizeof(params)); | |
209 params.channel = SND_PCM_CHANNEL_PLAYBACK; | |
210 params.mode = SND_PCM_MODE_STREAM; | |
211 params.format = alsa_format; | |
212 params.start_mode = SND_PCM_START_DATA; | |
213 params.stop_mode = SND_PCM_STOP_ROLLOVER; | |
3095 | 214 params.buf.stream.queue_size = ao_data.buffersize; |
996 | 215 params.buf.stream.fill = SND_PCM_FILL_NONE; |
216 | |
217 if ((err = snd_pcm_channel_params(alsa_handler, ¶ms)) < 0) | |
218 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
219 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
|
220 return 0; |
996 | 221 } |
222 | |
223 memset(&setup, 0, sizeof(setup)); | |
224 setup.channel = SND_PCM_CHANNEL_PLAYBACK; | |
225 setup.mode = SND_PCM_MODE_STREAM; | |
226 setup.format = alsa_format; | |
3095 | 227 setup.buf.stream.queue_size = ao_data.buffersize; |
228 setup.msbits_per_sample = ao_data.bps; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
229 |
996 | 230 if ((err = snd_pcm_channel_setup(alsa_handler, &setup)) < 0) |
231 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
232 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
|
233 return 0; |
996 | 234 } |
235 | |
236 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
237 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
238 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
|
239 return 0; |
996 | 240 } |
241 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
242 mp_msg(MSGT_AO, MSGL_INFO, "AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n", |
7659 | 243 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, |
996 | 244 snd_pcm_get_format_name(alsa_format.format)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
245 return 1; |
996 | 246 } |
247 | |
248 /* close audio device */ | |
12145 | 249 static void uninit(int immed) |
996 | 250 { |
1055 | 251 int err; |
252 | |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
253 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
254 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
255 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
|
256 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
257 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
258 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
259 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
|
260 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
261 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
|
262 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
263 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
264 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
265 if ((err = snd_pcm_close(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
266 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
267 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
|
268 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
269 } |
996 | 270 } |
271 | |
272 /* stop playing and empty buffers (for seeking/pause) */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
273 static void reset(void) |
996 | 274 { |
275 int err; | |
276 | |
277 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) | |
278 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
279 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetDrainError, snd_strerror(err)); |
996 | 280 return; |
281 } | |
282 | |
283 if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
284 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
285 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetFlushError, snd_strerror(err)); |
996 | 286 return; |
287 } | |
288 | |
289 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
290 { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
291 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetChanPrepareError, snd_strerror(err)); |
996 | 292 return; |
293 } | |
294 } | |
295 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
296 /* stop playing, keep buffers (for pause) */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
297 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
|
298 { |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
299 int err; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
300 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
301 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
302 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
303 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
|
304 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
305 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
306 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
307 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
|
308 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
309 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
|
310 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
311 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
312 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
313 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
314 /* resume playing, after audio_pause() */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
315 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
|
316 { |
1055 | 317 int err; |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
318 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
|
319 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
320 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
|
321 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
322 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
323 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
324 |
996 | 325 /* |
326 plays 'len' bytes of 'data' | |
327 returns: number of bytes played | |
328 */ | |
329 static int play(void* data, int len, int flags) | |
330 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
331 int got_len; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
332 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
333 if (!len) |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
334 return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
335 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
336 if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 337 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
338 if (got_len == -EPIPE) /* underrun? */ |
996 | 339 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
340 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
|
341 if ((got_len = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
996 | 342 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
343 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
|
344 return 0; |
996 | 345 } |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
346 if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 347 { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
348 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
|
349 snd_strerror(got_len)); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
350 return 0; |
996 | 351 } |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
352 return got_len; /* 2nd write was ok */ |
996 | 353 } |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
354 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
|
355 return 0; |
996 | 356 } |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
357 return got_len; |
996 | 358 } |
359 | |
360 /* how many byes are free in the buffer */ | |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
361 static int get_space(void) |
996 | 362 { |
363 snd_pcm_channel_status_t ch_stat; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
364 |
996 | 365 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; |
366 | |
367 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) | |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
368 return 0; /* error occurred */ |
996 | 369 else |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
370 return ch_stat.free; |
996 | 371 } |
372 | |
3095 | 373 /* delay in seconds between first and last sample in buffer */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
14264
diff
changeset
|
374 static float get_delay(void) |
996 | 375 { |
376 snd_pcm_channel_status_t ch_stat; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
377 |
996 | 378 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
379 |
996 | 380 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
381 return (float)ao_data.buffersize/(float)ao_data.bps; /* error occurred */ |
996 | 382 else |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
18915
diff
changeset
|
383 return (float)ch_stat.count/(float)ao_data.bps; |
996 | 384 } |