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