Mercurial > mplayer.hg
comparison libao2/ao_alsa9.c @ 1115:a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
author | al3x |
---|---|
date | Tue, 12 Jun 2001 15:42:21 +0000 |
parents | cab5ba9ffc6c |
children | d2dd25dd11bc |
comparison
equal
deleted
inserted
replaced
1114:ce92a1d0c60c | 1115:a16b569f2702 |
---|---|
53 break; | 53 break; |
54 } | 54 } |
55 return(CONTROL_UNKNOWN); | 55 return(CONTROL_UNKNOWN); |
56 } | 56 } |
57 | 57 |
58 #define start | |
58 /* | 59 /* |
59 open & setup audio device | 60 open & setup audio device |
60 return: 1=success 0=fail | 61 return: 1=success 0=fail |
61 */ | 62 */ |
62 static int init(int rate_hz, int channels, int format, int flags) | 63 static int init(int rate_hz, int channels, int format, int flags) |
63 { | 64 { |
64 int err; | 65 int err; |
65 int cards = -1; | 66 int cards = -1; |
66 snd_pcm_info_t *alsa_info; | 67 snd_pcm_info_t *alsa_info; |
67 int chunck_size; | |
68 | 68 |
69 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, | 69 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
70 channels, audio_out_format_name(format)); | 70 channels, audio_out_format_name(format)); |
71 | 71 |
72 alsa_handler = NULL; | 72 alsa_handler = NULL; |
86 ao_samplerate = rate_hz; | 86 ao_samplerate = rate_hz; |
87 ao_bps = ao_samplerate*(ao_channels+1); | 87 ao_bps = ao_samplerate*(ao_channels+1); |
88 ao_outburst = OUTBURST; | 88 ao_outburst = OUTBURST; |
89 ao_buffersize = 16384; | 89 ao_buffersize = 16384; |
90 | 90 |
91 memset(&alsa_format, 0, sizeof(alsa_format)); | |
92 switch (format) | 91 switch (format) |
93 { | 92 { |
94 case AFMT_S8: | 93 case AFMT_S8: |
95 alsa_format = SND_PCM_FORMAT_S8; | 94 alsa_format = SND_PCM_FORMAT_S8; |
96 break; | 95 break; |
122 break; | 121 break; |
123 case -1: | 122 case -1: |
124 printf("alsa-init: invalid format (%s) requested - output disabled\n", | 123 printf("alsa-init: invalid format (%s) requested - output disabled\n", |
125 audio_out_format_name(format)); | 124 audio_out_format_name(format)); |
126 return(0); | 125 return(0); |
126 default: | |
127 break; | |
127 } | 128 } |
128 | 129 |
129 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) | 130 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) |
130 { | 131 { |
131 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); | 132 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); |
192 ao_samplerate, 0)) < 0) | 193 ao_samplerate, 0)) < 0) |
193 { | 194 { |
194 printf("alsa-init: unable to set channels: %s\n", | 195 printf("alsa-init: unable to set channels: %s\n", |
195 snd_strerror(err)); | 196 snd_strerror(err)); |
196 return(0); | 197 return(0); |
198 } | |
199 | |
200 { | |
201 int fragment_size = 4096; | |
202 int fragment_count = 8; | |
203 snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, fragment_size / 4, 0); | |
204 snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, fragment_count, 0); | |
197 } | 205 } |
198 | 206 |
199 #ifdef buffersize | 207 #ifdef buffersize |
200 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) | 208 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) |
201 { | 209 { |
264 { | 272 { |
265 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); | 273 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); |
266 return(0); | 274 return(0); |
267 } | 275 } |
268 | 276 |
277 #ifdef start | |
269 if ((err = snd_pcm_start(alsa_handler)) < 0) | 278 if ((err = snd_pcm_start(alsa_handler)) < 0) |
270 { | 279 { |
271 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | 280 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); |
272 if (err != -EPIPE) | 281 if (err != -EPIPE) |
273 return(0); | 282 return(0); |
275 { | 284 { |
276 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | 285 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); |
277 return(0); | 286 return(0); |
278 } | 287 } |
279 } | 288 } |
280 | 289 #endif |
281 printf("AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n", | 290 printf("AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n", |
282 ao_samplerate, ao_channels+1, ao_bps, ao_buffersize, | 291 ao_samplerate, ao_channels+1, ao_bps, ao_buffersize, |
283 snd_pcm_format_description(alsa_format)); | 292 snd_pcm_format_description(alsa_format)); |
284 return(1); | 293 return(1); |
285 } | 294 } |
382 plays 'len' bytes of 'data' | 391 plays 'len' bytes of 'data' |
383 returns: number of bytes played | 392 returns: number of bytes played |
384 */ | 393 */ |
385 static int play(void* data, int len, int flags) | 394 static int play(void* data, int len, int flags) |
386 { | 395 { |
387 if ((len = snd_pcm_writei(alsa_handler, data, len)) != len) | 396 int got_len; |
388 { | 397 |
389 if (len == -EPIPE) /* underrun? */ | 398 if ((got_len = snd_pcm_writei(alsa_handler, data, len/4)) != len/4) |
399 { | |
400 if (got_len == -EPIPE) /* underrun? */ | |
390 { | 401 { |
391 printf("alsa-play: alsa underrun, resetting stream\n"); | 402 printf("alsa-play: alsa underrun, resetting stream\n"); |
392 if ((len = snd_pcm_prepare(alsa_handler)) < 0) | 403 if ((len = snd_pcm_prepare(alsa_handler)) < 0) |
393 { | 404 { |
394 printf("alsa-play: playback prepare error: %s\n", snd_strerror(len)); | 405 printf("alsa-play: playback prepare error: %s\n", snd_strerror(len)); |