Mercurial > mplayer.hg
comparison libao2/ao_alsa9.c @ 2209:a59f952fad34
applied patch by Joy Winter <joy@pingfm.org>
author | arpi |
---|---|
date | Mon, 15 Oct 2001 11:17:19 +0000 |
parents | 3c390543302c |
children | 981a9e5118ce |
comparison
equal
deleted
inserted
replaced
2208:4bdb8be1b506 | 2209:a59f952fad34 |
---|---|
1 /* | 1 /* |
2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer | 2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer |
3 | 3 |
4 (C) Alex Beregszaszi <alex@naxine.org> | 4 (C) Alex Beregszaszi <alex@naxine.org> |
5 | 5 |
6 Don't use this buggy driver, ALSA-0.9.x emulates OSS very well... | 6 modified for better alsa-0.9.0beta8a-support by Joy Winter <joy@pingfm.org> |
7 | |
8 This driver is still at alpha stage. | |
9 If you want stable sound-support use the OSS emulation instead. | |
10 | |
11 Any bugreports regarding to this driver are welcome either to the mplayer-user-mailinglist or directly to the authors. | |
7 */ | 12 */ |
8 | 13 |
9 #include <errno.h> | 14 #include <errno.h> |
10 #include <sys/asoundlib.h> | 15 #include <sys/asoundlib.h> |
11 | 16 |
19 | 24 |
20 static ao_info_t info = | 25 static ao_info_t info = |
21 { | 26 { |
22 "ALSA-0.9.x audio output", | 27 "ALSA-0.9.x audio output", |
23 "alsa9", | 28 "alsa9", |
24 "Alex Beregszaszi <alex@naxine.org>", | 29 "Alex Beregszaszi <alex@naxine.org>, Joy Winter <joy@pingfm.org>", |
25 "under developement" | 30 "under developement" |
26 }; | 31 }; |
27 | 32 |
28 LIBAO_EXTERN(alsa9) | 33 LIBAO_EXTERN(alsa9) |
29 | 34 |
39 static snd_pcm_t *alsa_handler; | 44 static snd_pcm_t *alsa_handler; |
40 static snd_pcm_format_t alsa_format; | 45 static snd_pcm_format_t alsa_format; |
41 static snd_pcm_hw_params_t *alsa_hwparams; | 46 static snd_pcm_hw_params_t *alsa_hwparams; |
42 static snd_pcm_sw_params_t *alsa_swparams; | 47 static snd_pcm_sw_params_t *alsa_swparams; |
43 static char *alsa_device; | 48 static char *alsa_device; |
44 #define ALSA_DEVICE_SIZE 48 /* war 48 */ | 49 #define ALSA_DEVICE_SIZE 48 |
45 | 50 |
46 static int alsa_fragsize = 8192; /* 4096 war 8192*/ | 51 static int alsa_fragsize = 8192; /* possible 4096, original 8192 */ |
47 static int alsa_fragcount = 8; /* war 8 */ | 52 static int alsa_fragcount = 8; |
53 | |
54 static int chunk_size = -1; | |
55 static int start_delay = 1; | |
48 | 56 |
49 /* to set/get/query special features/parameters */ | 57 /* to set/get/query special features/parameters */ |
50 static int control(int cmd, int arg) | 58 static int control(int cmd, int arg) |
51 { | 59 { |
52 switch(cmd) | 60 switch(cmd) |
67 } | 75 } |
68 } | 76 } |
69 return(CONTROL_UNKNOWN); | 77 return(CONTROL_UNKNOWN); |
70 } | 78 } |
71 | 79 |
72 #undef start /* war undef */ | 80 #undef start /* orig. undef */ |
73 #define buffersize | 81 #define buffersize |
74 #undef buffertime /* war undef? */ | 82 #define buffertime /* orig. undef? */ |
75 #define set_period | 83 #define set_period |
76 #define sw_params /* war undef */ | 84 #define sw_params /* orig. undef */ |
77 #undef set_start_mode /* war undef */ | 85 #undef set_start_mode /* orig. undef */ |
78 | 86 |
79 /* | 87 /* |
80 open & setup audio device | 88 open & setup audio device |
81 return: 1=success 0=fail | 89 return: 1=success 0=fail |
82 */ | 90 */ |
84 { | 92 { |
85 int err; | 93 int err; |
86 int cards = -1; | 94 int cards = -1; |
87 snd_pcm_info_t *alsa_info; | 95 snd_pcm_info_t *alsa_info; |
88 | 96 |
89 printf("alsa-init: Don't use this buggy driver, ALSA-0.9.x emulates OSS very well... modified by me\n"); | 97 size_t xfer_align; //new |
90 | 98 snd_pcm_uframes_t start_threshold, stop_threshold; //new |
99 | |
100 printf("alsa-init: this driver is still at alpha-stage. if you want stable sound support use the OSS emulation instead.\n"); | |
91 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, | 101 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
92 channels, audio_out_format_name(format)); | 102 channels, audio_out_format_name(format)); |
93 | 103 |
94 alsa_handler = NULL; | 104 alsa_handler = NULL; |
95 | 105 |
100 { | 110 { |
101 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); | 111 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); |
102 return(0); | 112 return(0); |
103 } | 113 } |
104 | 114 |
105 ao_samplerate = rate_hz; /*war rate_hz */ | 115 ao_samplerate = rate_hz; |
106 ao_bps = channels; /* really this is bytes per frame so bad varname */ | 116 ao_bps = channels; /* really this is bytes per frame so bad varname */ |
107 /* ao_bps = channels */ | |
108 ao_format = format; | 117 ao_format = format; |
109 ao_channels = channels; | 118 ao_channels = channels; |
110 ao_outburst = OUTBURST; | 119 ao_outburst = OUTBURST; |
111 ao_buffersize = 16384; | 120 ao_buffersize = 16384; |
112 | 121 |
182 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); | 191 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
183 return(0); | 192 return(0); |
184 } | 193 } |
185 | 194 |
186 snd_pcm_hw_params_malloc(&alsa_hwparams); | 195 snd_pcm_hw_params_malloc(&alsa_hwparams); |
187 snd_pcm_sw_params_malloc(&alsa_swparams); | 196 //snd_pcm_sw_params_malloc(&alsa_swparams); |
188 | 197 snd_pcm_sw_params_alloca(&alsa_swparams); |
189 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) | 198 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) |
190 { | 199 { |
191 printf("alsa-init: unable to get initial parameters: %s\n", | 200 printf("alsa-init: unable to get initial parameters: %s\n", |
192 snd_strerror(err)); | 201 snd_strerror(err)); |
193 return(0); | 202 return(0); |
216 snd_strerror(err)); | 225 snd_strerror(err)); |
217 return(0); | 226 return(0); |
218 } | 227 } |
219 | 228 |
220 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_samplerate, 0)) < 0) | 229 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_samplerate, 0)) < 0) |
221 /* war nur snd_pcm_hw_params_set_rate */ | 230 /* was originally only snd_pcm_hw_params_set_rate jp*/ |
222 { | 231 { |
223 printf("alsa-init: unable to set samplerate-2: %s\n", | 232 printf("alsa-init: unable to set samplerate-2: %s\n", |
224 snd_strerror(err)); | 233 snd_strerror(err)); |
225 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); | 234 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); jp |
226 return(0); | 235 return(0); |
227 } | 236 } |
228 | 237 |
229 #ifdef set_period | 238 #ifdef set_period |
230 { | 239 { |
232 { | 241 { |
233 printf("alsa-init: unable to set periodsize: %s\n", | 242 printf("alsa-init: unable to set periodsize: %s\n", |
234 snd_strerror(err)); | 243 snd_strerror(err)); |
235 return(0); | 244 return(0); |
236 } | 245 } |
237 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) | 246 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) |
238 { | 247 { |
239 printf("alsa-init: unable to set periods: %s\n", | 248 printf("alsa-init: unable to set periods: %s\n", |
240 snd_strerror(err)); | 249 snd_strerror(err)); |
241 return(0); | 250 return(0); |
242 } | 251 } |
243 } | 252 } |
244 #endif | 253 #endif |
245 #ifdef buffersize | 254 #ifdef buffersize |
246 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) | 255 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) |
247 { | 256 { |
256 } | 265 } |
257 #endif | 266 #endif |
258 | 267 |
259 #ifdef buffertime | 268 #ifdef buffertime |
260 { | 269 { |
261 int alsa_buffer_time = 60; /* war 60 */ | 270 int alsa_buffer_time = 500000; /* original 60 */ |
262 | 271 |
263 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0) | 272 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0) |
264 { | 273 { |
265 printf("alsa-init: unable to set buffer time near: %s\n", | 274 printf("alsa-init: unable to set buffer time near: %s\n", |
266 snd_strerror(err)); | 275 snd_strerror(err)); |
267 return(0); | 276 return(0); |
268 } else | 277 } else |
269 alsa_buffer_time = err; | 278 alsa_buffer_time = err; |
270 | 279 |
271 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/ao_bps, 0)) < 0) | 280 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0) |
272 /* war alsa_buffer_time/ao_bps */ | 281 /* original: alsa_buffer_time/ao_bps */ |
273 { | 282 { |
274 printf("alsa-init: unable to set period time: %s\n", | 283 printf("alsa-init: unable to set period time: %s\n", |
275 snd_strerror(err)); | 284 snd_strerror(err)); |
276 return(0); | 285 return(0); |
277 } | 286 } |
286 snd_strerror(err)); | 295 snd_strerror(err)); |
287 return(0); | 296 return(0); |
288 } | 297 } |
289 | 298 |
290 #ifdef sw_params | 299 #ifdef sw_params |
300 { | |
301 chunk_size = snd_pcm_hw_params_get_period_size(alsa_hwparams, 0); | |
302 start_threshold = (double) ao_samplerate * start_delay / 1000000; | |
303 xfer_align = snd_pcm_sw_params_get_xfer_align(alsa_swparams); | |
304 | |
291 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) | 305 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) |
292 { | 306 { |
293 printf("alsa-init: unable to get parameters: %s\n", | 307 printf("alsa-init: unable to get parameters: %s\n", |
294 snd_strerror(err)); | 308 snd_strerror(err)); |
295 return(0); | 309 return(0); |
296 } | 310 } |
311 | |
312 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, chunk_size)) < 0) | |
313 { | |
314 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err)); | |
315 return(0); | |
316 } | |
317 | |
318 | |
319 | |
320 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_handler, alsa_swparams, start_threshold)) < 0) | |
321 { | |
322 printf("alsa-init: unable to set start_threshold %s\n",snd_strerror(err)); | |
323 return(0); | |
324 } | |
325 } | |
326 // if ((err = snd_pcm_sw_params_set_xfer_align(alsa_handler, alsa_swparams, xfer_align)) < 0) | |
327 //{ | |
328 // printf("alsa-init: unable to set xfer_align: %s\n", | |
329 // snd_strerror(err)); | |
330 // return(0); | |
331 //} | |
297 | 332 |
298 #ifdef set_start_mode | 333 #ifdef set_start_mode |
299 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams, | 334 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams, |
300 SND_PCM_START_DATA)) < 0) | 335 SND_PCM_START_DATA)) < 0) |
301 { | 336 { |
451 { | 486 { |
452 int got_len; | 487 int got_len; |
453 | 488 |
454 got_len = snd_pcm_writei(alsa_handler, data, len / 4); | 489 got_len = snd_pcm_writei(alsa_handler, data, len / 4); |
455 | 490 |
456 // war: if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps)) { | 491 //if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps)) { |
457 | 492 //SHOULD BE FIXED |
458 if (got_len == -EPIPE) /* underrun? */ | 493 if (got_len == -EPIPE) /* underrun? */ |
459 { | 494 { |
460 printf("alsa-play: alsa underrun, resetting stream\n"); | 495 printf("alsa-play: alsa underrun, resetting stream\n"); |
461 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0) | 496 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0) |
462 { | 497 { |
470 return(0); | 505 return(0); |
471 } | 506 } |
472 return(len); /* 2nd write was ok */ | 507 return(len); /* 2nd write was ok */ |
473 } | 508 } |
474 return(len); | 509 return(len); |
510 //} | |
475 } | 511 } |
476 | 512 |
477 /* how many byes are free in the buffer */ | 513 /* how many byes are free in the buffer */ |
478 static int get_space() | 514 static int get_space() |
479 { | 515 { |