Mercurial > mplayer.hg
annotate libao2/ao_alsa5.c @ 7874:4c832590e18e
yeah, test.c works now!
author | arpi |
---|---|
date | Wed, 23 Oct 2002 18:20:13 +0000 |
parents | b10df387019c |
children | b9da278e4c92 |
rev | line source |
---|---|
996 | 1 /* |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
2 ao_alsa5 - ALSA-0.5.x output plugin for MPlayer |
996 | 3 |
4 (C) Alex Beregszaszi <alex@naxine.org> | |
5 | |
6 Thanks to Arpi for helping me ;) | |
7 */ | |
8 | |
9 #include <errno.h> | |
10 #include <sys/asoundlib.h> | |
11 | |
12 #include "../config.h" | |
13 | |
14 #include "audio_out.h" | |
15 #include "audio_out_internal.h" | |
1058 | 16 #include "afmt.h" |
996 | 17 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
18 #include "../mp_msg.h" |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
19 |
996 | 20 extern int verbose; |
21 | |
22 static ao_info_t info = | |
23 { | |
24 "ALSA-0.5.x audio output", | |
25 "alsa5", | |
26 "Alex Beregszaszi <alex@naxine.org>", | |
27 "" | |
28 }; | |
29 | |
30 LIBAO_EXTERN(alsa5) | |
31 | |
32 static snd_pcm_t *alsa_handler; | |
33 static snd_pcm_format_t alsa_format; | |
34 static int alsa_rate = SND_PCM_RATE_CONTINUOUS; | |
35 | |
36 /* to set/get/query special features/parameters */ | |
37 static int control(int cmd, int arg) | |
38 { | |
39 return(CONTROL_UNKNOWN); | |
40 } | |
41 | |
42 /* | |
43 open & setup audio device | |
44 return: 1=success 0=fail | |
45 */ | |
46 static int init(int rate_hz, int channels, int format, int flags) | |
47 { | |
48 int err; | |
49 int cards = -1; | |
50 snd_pcm_channel_params_t params; | |
51 snd_pcm_channel_setup_t setup; | |
52 snd_pcm_info_t info; | |
53 snd_pcm_channel_info_t chninfo; | |
54 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
55 mp_msg(MSGT_AO, MSGL_INFO, "alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
996 | 56 channels, audio_out_format_name(format)); |
57 | |
58 alsa_handler = NULL; | |
59 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
60 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
|
61 SND_LIB_VERSION); |
996 | 62 |
63 if ((cards = snd_cards()) < 0) | |
64 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
65 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: no soundcards found\n"); |
996 | 66 return(0); |
67 } | |
68 | |
3095 | 69 ao_data.format = format; |
7659 | 70 ao_data.channels = channels; |
3095 | 71 ao_data.samplerate = rate_hz; |
7659 | 72 ao_data.bps = ao_data.samplerate*ao_data.channels; |
3095 | 73 ao_data.outburst = OUTBURST; |
74 ao_data.buffersize = 16384; | |
996 | 75 |
76 memset(&alsa_format, 0, sizeof(alsa_format)); | |
77 switch (format) | |
78 { | |
79 case AFMT_S8: | |
80 alsa_format.format = SND_PCM_SFMT_S8; | |
81 break; | |
82 case AFMT_U8: | |
83 alsa_format.format = SND_PCM_SFMT_U8; | |
84 break; | |
85 case AFMT_U16_LE: | |
86 alsa_format.format = SND_PCM_SFMT_U16_LE; | |
87 break; | |
88 case AFMT_U16_BE: | |
89 alsa_format.format = SND_PCM_SFMT_U16_BE; | |
90 break; | |
5790 | 91 #ifndef WORDS_BIGENDIAN |
92 case AFMT_AC3: | |
93 #endif | |
996 | 94 case AFMT_S16_LE: |
95 alsa_format.format = SND_PCM_SFMT_S16_LE; | |
96 break; | |
5790 | 97 #ifdef WORDS_BIGENDIAN |
98 case AFMT_AC3: | |
99 #endif | |
996 | 100 case AFMT_S16_BE: |
101 alsa_format.format = SND_PCM_SFMT_S16_BE; | |
102 break; | |
103 default: | |
104 alsa_format.format = SND_PCM_SFMT_MPEG; | |
105 break; | |
106 } | |
107 | |
108 switch(alsa_format.format) | |
109 { | |
110 case SND_PCM_SFMT_S16_LE: | |
111 case SND_PCM_SFMT_U16_LE: | |
3095 | 112 ao_data.bps *= 2; |
996 | 113 break; |
114 case -1: | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
115 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: invalid format (%s) requested - output disabled\n", |
996 | 116 audio_out_format_name(format)); |
117 return(0); | |
1111 | 118 default: |
119 break; | |
996 | 120 } |
121 | |
122 switch(rate_hz) | |
123 { | |
124 case 8000: | |
125 alsa_rate = SND_PCM_RATE_8000; | |
126 break; | |
127 case 11025: | |
128 alsa_rate = SND_PCM_RATE_11025; | |
129 break; | |
130 case 16000: | |
131 alsa_rate = SND_PCM_RATE_16000; | |
132 break; | |
133 case 22050: | |
134 alsa_rate = SND_PCM_RATE_22050; | |
135 break; | |
136 case 32000: | |
137 alsa_rate = SND_PCM_RATE_32000; | |
138 break; | |
139 case 44100: | |
140 alsa_rate = SND_PCM_RATE_44100; | |
141 break; | |
142 case 48000: | |
143 alsa_rate = SND_PCM_RATE_48000; | |
144 break; | |
145 case 88200: | |
146 alsa_rate = SND_PCM_RATE_88200; | |
147 break; | |
148 case 96000: | |
149 alsa_rate = SND_PCM_RATE_96000; | |
150 break; | |
151 case 176400: | |
152 alsa_rate = SND_PCM_RATE_176400; | |
153 break; | |
154 case 192000: | |
155 alsa_rate = SND_PCM_RATE_192000; | |
156 break; | |
157 default: | |
158 alsa_rate = SND_PCM_RATE_CONTINUOUS; | |
159 break; | |
160 } | |
161 | |
3095 | 162 alsa_format.rate = ao_data.samplerate; |
163 alsa_format.voices = ao_data.channels*2; | |
996 | 164 alsa_format.interleave = 1; |
165 | |
166 if ((err = snd_pcm_open(&alsa_handler, 0, 0, SND_PCM_OPEN_PLAYBACK)) < 0) | |
167 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
168 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: playback open error: %s\n", snd_strerror(err)); |
996 | 169 return(0); |
170 } | |
171 | |
172 if ((err = snd_pcm_info(alsa_handler, &info)) < 0) | |
173 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
174 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: pcm info error: %s\n", snd_strerror(err)); |
996 | 175 return(0); |
176 } | |
177 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
178 mp_msg(MSGT_AO, MSGL_INFO, "alsa-init: %d soundcard(s) found, using: %s\n", |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
179 cards, info.name); |
996 | 180 |
181 if (info.flags & SND_PCM_INFO_PLAYBACK) | |
182 { | |
3700 | 183 memset(&chninfo, 0, sizeof(chninfo)); |
996 | 184 chninfo.channel = SND_PCM_CHANNEL_PLAYBACK; |
185 if ((err = snd_pcm_channel_info(alsa_handler, &chninfo)) < 0) | |
186 { | |
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 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: pcm channel info error: %s\n", snd_strerror(err)); |
996 | 188 return(0); |
189 } | |
3095 | 190 |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
191 #ifndef __QNX__ |
996 | 192 if (chninfo.buffer_size) |
3095 | 193 ao_data.buffersize = chninfo.buffer_size; |
3087
08947e067d80
compiling under qnx, hope it works on all qnx release :)
alex
parents:
1111
diff
changeset
|
194 #endif |
3095 | 195 |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
196 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
|
197 ao_data.buffersize); |
996 | 198 } |
199 | |
200 memset(¶ms, 0, sizeof(params)); | |
201 params.channel = SND_PCM_CHANNEL_PLAYBACK; | |
202 params.mode = SND_PCM_MODE_STREAM; | |
203 params.format = alsa_format; | |
204 params.start_mode = SND_PCM_START_DATA; | |
205 params.stop_mode = SND_PCM_STOP_ROLLOVER; | |
3095 | 206 params.buf.stream.queue_size = ao_data.buffersize; |
996 | 207 params.buf.stream.fill = SND_PCM_FILL_NONE; |
208 | |
209 if ((err = snd_pcm_channel_params(alsa_handler, ¶ms)) < 0) | |
210 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
211 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: error setting parameters: %s\n", snd_strerror(err)); |
996 | 212 return(0); |
213 } | |
214 | |
215 memset(&setup, 0, sizeof(setup)); | |
216 setup.channel = SND_PCM_CHANNEL_PLAYBACK; | |
217 setup.mode = SND_PCM_MODE_STREAM; | |
218 setup.format = alsa_format; | |
3095 | 219 setup.buf.stream.queue_size = ao_data.buffersize; |
220 setup.msbits_per_sample = ao_data.bps; | |
996 | 221 |
222 if ((err = snd_pcm_channel_setup(alsa_handler, &setup)) < 0) | |
223 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
224 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: error setting up channel: %s\n", snd_strerror(err)); |
996 | 225 return(0); |
226 } | |
227 | |
228 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
229 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
230 mp_msg(MSGT_AO, MSGL_ERR, "alsa-init: channel prepare error: %s\n", snd_strerror(err)); |
996 | 231 return(0); |
232 } | |
233 | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
234 mp_msg(MSGT_AO, MSGL_INFO, "AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n", |
7659 | 235 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, |
996 | 236 snd_pcm_get_format_name(alsa_format.format)); |
237 return(1); | |
238 } | |
239 | |
240 /* close audio device */ | |
241 static void uninit() | |
242 { | |
1055 | 243 int err; |
244 | |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
245 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
246 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
247 mp_msg(MSGT_AO, MSGL_ERR, "alsa-uninit: playback drain error: %s\n", snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
248 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
249 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
250 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
251 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
|
252 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
253 mp_msg(MSGT_AO, MSGL_ERR, "alsa-uninit: playback flush error: %s\n", snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
254 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
255 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
256 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
257 if ((err = snd_pcm_close(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
258 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
259 mp_msg(MSGT_AO, MSGL_ERR, "alsa-uninit: pcm close error: %s\n", 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 } |
996 | 262 } |
263 | |
264 /* stop playing and empty buffers (for seeking/pause) */ | |
265 static void reset() | |
266 { | |
267 int err; | |
268 | |
269 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) | |
270 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
271 mp_msg(MSGT_AO, MSGL_ERR, "alsa-reset: playback drain error: %s\n", snd_strerror(err)); |
996 | 272 return; |
273 } | |
274 | |
275 if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
276 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
277 mp_msg(MSGT_AO, MSGL_ERR, "alsa-reset: playback flush error: %s\n", snd_strerror(err)); |
996 | 278 return; |
279 } | |
280 | |
281 if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) | |
282 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
283 mp_msg(MSGT_AO, MSGL_ERR, "alsa-reset: channel prepare error: %s\n", snd_strerror(err)); |
996 | 284 return; |
285 } | |
286 } | |
287 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
288 /* stop playing, keep buffers (for pause) */ |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
289 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
290 { |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
291 int err; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
292 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
293 if ((err = snd_pcm_playback_drain(alsa_handler)) < 0) |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
294 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
295 mp_msg(MSGT_AO, MSGL_ERR, "alsa-pause: playback drain error: %s\n", snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
296 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
297 } |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
298 |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
299 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
|
300 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
301 mp_msg(MSGT_AO, MSGL_ERR, "alsa-pause: playback flush error: %s\n", snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
302 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
303 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
304 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
305 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
306 /* resume playing, after audio_pause() */ |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
307 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
308 { |
1055 | 309 int err; |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
310 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
|
311 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
312 mp_msg(MSGT_AO, MSGL_ERR, "alsa-resume: channel prepare error: %s\n", snd_strerror(err)); |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
313 return; |
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
314 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
315 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
996
diff
changeset
|
316 |
996 | 317 /* |
318 plays 'len' bytes of 'data' | |
319 returns: number of bytes played | |
320 */ | |
321 static int play(void* data, int len, int flags) | |
322 { | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
323 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
|
324 |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
325 if (!len) |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
326 return(0); |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
327 |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
328 if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 329 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
330 if (got_len == -EPIPE) /* underrun? */ |
996 | 331 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
332 mp_msg(MSGT_AO, MSGL_ERR, "alsa-play: alsa underrun, resetting stream\n"); |
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 ((got_len = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
996 | 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 mp_msg(MSGT_AO, MSGL_ERR, "alsa-play: playback prepare error: %s\n", snd_strerror(got_len)); |
996 | 336 return(0); |
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 = snd_pcm_write(alsa_handler, data, len)) < 0) |
996 | 339 { |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
340 mp_msg(MSGT_AO, MSGL_ERR, "alsa-play: write error after reset: %s - giving up\n", |
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
341 snd_strerror(got_len)); |
996 | 342 return(0); |
343 } | |
5902
2639d60fe5c2
play() fix by Jimen Ching <jching@flex.com>, additional printf->mp_msg conversions (for coming i18n support)
alex
parents:
5790
diff
changeset
|
344 return(got_len); /* 2nd write was ok */ |
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 mp_msg(MSGT_AO, MSGL_ERR, "alsa-play: output error: %s\n", snd_strerror(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
|
347 return(0); |
996 | 348 } |
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 return(got_len); |
996 | 350 } |
351 | |
352 /* how many byes are free in the buffer */ | |
353 static int get_space() | |
354 { | |
355 snd_pcm_channel_status_t ch_stat; | |
356 | |
357 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; | |
358 | |
359 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) | |
1046
59fc1f75e486
audio_pause/resume implementacio es kozmetikai valtoztatasok
al3x
parents:
1038
diff
changeset
|
360 return(0); /* error occured */ |
996 | 361 else |
362 return(ch_stat.free); | |
363 } | |
364 | |
3095 | 365 /* delay in seconds between first and last sample in buffer */ |
366 static float get_delay() | |
996 | 367 { |
368 snd_pcm_channel_status_t ch_stat; | |
369 | |
370 ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK; | |
371 | |
372 if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0) | |
3095 | 373 return((float)ao_data.buffersize/(float)ao_data.bps); /* error occured */ |
996 | 374 else |
3095 | 375 return((float)ch_stat.count/(float)ao_data.bps); |
996 | 376 } |