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