Mercurial > mplayer.hg
comparison libmpdemux/ai_alsa1x.c @ 11775:66e491c35dc8
ALSA 1.x audio out driver
author | henry |
---|---|
date | Sun, 11 Jan 2004 17:07:32 +0000 |
parents | 31f12f99118b |
children | dfbe8cd0e081 |
comparison
equal
deleted
inserted
replaced
11774:28b52087c48d | 11775:66e491c35dc8 |
---|---|
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <sys/time.h> | 3 #include <sys/time.h> |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2)) && defined(HAVE_ALSA9) | 7 #if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2)) && defined(HAVE_ALSA1X) |
8 | 8 |
9 #include <alsa/asoundlib.h> | 9 #include <alsa/asoundlib.h> |
10 #include "audio_in.h" | 10 #include "audio_in.h" |
11 #include "mp_msg.h" | 11 #include "mp_msg.h" |
12 | 12 |
13 int ai_alsa_setup(audio_in_t *ai) | 13 int ai_alsa_setup(audio_in_t *ai) |
14 { | 14 { |
15 snd_pcm_hw_params_t *params; | 15 snd_pcm_hw_params_t *params; |
16 snd_pcm_sw_params_t *swparams; | 16 snd_pcm_sw_params_t *swparams; |
17 int buffer_size; | 17 snd_pcm_uframes_t buffer_size, period_size; |
18 int err; | 18 int err; |
19 int dir; | |
19 unsigned int rate; | 20 unsigned int rate; |
20 | 21 |
21 snd_pcm_hw_params_alloca(¶ms); | 22 snd_pcm_hw_params_alloca(¶ms); |
22 snd_pcm_sw_params_alloca(&swparams); | 23 snd_pcm_sw_params_alloca(&swparams); |
23 | 24 |
24 err = snd_pcm_hw_params_any(ai->alsa.handle, params); | 25 err = snd_pcm_hw_params_any(ai->alsa.handle, params); |
25 if (err < 0) { | 26 if (err < 0) { |
26 mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available\n"); | 27 mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available\n"); |
27 return -1; | 28 return -1; |
28 } | 29 } |
30 | |
29 err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, | 31 err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, |
30 SND_PCM_ACCESS_RW_INTERLEAVED); | 32 SND_PCM_ACCESS_RW_INTERLEAVED); |
31 if (err < 0) { | 33 if (err < 0) { |
32 mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n"); | 34 mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n"); |
33 return -1; | 35 return -1; |
34 } | 36 } |
37 | |
35 err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); | 38 err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); |
36 if (err < 0) { | 39 if (err < 0) { |
37 mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n"); | 40 mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n"); |
38 return -1; | 41 return -1; |
39 } | 42 } |
43 | |
40 err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); | 44 err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); |
41 if (err < 0) { | 45 if (err < 0) { |
42 ai->channels = snd_pcm_hw_params_get_channels(params); | 46 snd_pcm_hw_params_get_channels(params, &ai->channels); |
43 mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n", | 47 mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n", |
44 ai->channels); | 48 ai->channels); |
45 } else { | 49 } else { |
46 ai->channels = ai->req_channels; | 50 ai->channels = ai->req_channels; |
47 } | 51 } |
48 | 52 |
49 err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, ai->req_samplerate, 0); | 53 dir = 0; |
50 assert(err >= 0); | 54 rate = ai->req_samplerate; |
51 rate = err; | 55 err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir); |
56 if (err < 0) { | |
57 mp_msg(MSGT_TV, MSGL_ERR, "Cannot set samplerate\n"); | |
58 } | |
52 ai->samplerate = rate; | 59 ai->samplerate = rate; |
53 | 60 |
61 dir = 0; | |
54 ai->alsa.buffer_time = 1000000; | 62 ai->alsa.buffer_time = 1000000; |
55 ai->alsa.buffer_time = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, | 63 err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, |
56 ai->alsa.buffer_time, 0); | 64 &ai->alsa.buffer_time, &dir); |
57 assert(ai->alsa.buffer_time >= 0); | 65 if (err < 0) { |
66 mp_msg(MSGT_TV, MSGL_ERR, "Cannot set buffer time\n"); | |
67 } | |
68 | |
69 dir = 0; | |
58 ai->alsa.period_time = ai->alsa.buffer_time / 4; | 70 ai->alsa.period_time = ai->alsa.buffer_time / 4; |
59 ai->alsa.period_time = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, | 71 err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, |
60 ai->alsa.period_time, 0); | 72 &ai->alsa.period_time, &dir); |
61 assert(ai->alsa.period_time >= 0); | 73 if (err < 0) { |
74 mp_msg(MSGT_TV, MSGL_ERR, "Cannot set period time\n"); | |
75 } | |
76 | |
62 err = snd_pcm_hw_params(ai->alsa.handle, params); | 77 err = snd_pcm_hw_params(ai->alsa.handle, params); |
63 if (err < 0) { | 78 if (err < 0) { |
64 mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hw params:"); | 79 mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hw params: %s\n", snd_strerror(err)); |
65 snd_pcm_hw_params_dump(params, ai->alsa.log); | 80 snd_pcm_hw_params_dump(params, ai->alsa.log); |
66 return -1; | 81 return -1; |
67 } | 82 } |
68 ai->alsa.chunk_size = snd_pcm_hw_params_get_period_size(params, 0); | 83 |
69 buffer_size = snd_pcm_hw_params_get_buffer_size(params); | 84 dir = -1; |
70 if (ai->alsa.chunk_size == buffer_size) { | 85 snd_pcm_hw_params_get_period_size(params, &period_size, &dir); |
86 snd_pcm_hw_params_get_buffer_size(params, &buffer_size); | |
87 ai->alsa.chunk_size = period_size; | |
88 if (period_size == buffer_size) { | |
71 mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size); | 89 mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size); |
72 return -1; | 90 return -1; |
73 } | 91 } |
92 | |
74 snd_pcm_sw_params_current(ai->alsa.handle, swparams); | 93 snd_pcm_sw_params_current(ai->alsa.handle, swparams); |
75 err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0); | 94 err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0); |
76 assert(err >= 0); | 95 assert(err >= 0); |
77 err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size); | 96 err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size); |
78 assert(err >= 0); | 97 assert(err >= 0); |
164 } | 183 } |
165 mp_msg(MSGT_TV, MSGL_ERR, "ALSA read/write error"); | 184 mp_msg(MSGT_TV, MSGL_ERR, "ALSA read/write error"); |
166 return -1; | 185 return -1; |
167 } | 186 } |
168 | 187 |
169 #endif /* HAVE_ALSA9 */ | 188 #endif /* HAVE_ALSA1X */ |