summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChih-Wei Huang <cwhuang@linux.org.tw>2013-01-08 01:01:14 +0800
committerChih-Wei Huang <cwhuang@linux.org.tw>2013-02-04 17:45:38 +0800
commit168c9310f7a26591adbdae01aa347d22b776f3ab (patch)
tree4f06635315338b29b0c4097e278fa2339879c3a7
parentcfde6b1213e204bb8eca55ce16b1a26d4d0eef0b (diff)
downloadplatform_hardware_libaudio-168c9310f7a26591adbdae01aa347d22b776f3ab.tar.gz
platform_hardware_libaudio-168c9310f7a26591adbdae01aa347d22b776f3ab.tar.bz2
platform_hardware_libaudio-168c9310f7a26591adbdae01aa347d22b776f3ab.zip
detect pcm card automatically
-rw-r--r--audio_hw.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/audio_hw.c b/audio_hw.c
index 2d7db30..447f55f 100644
--- a/audio_hw.c
+++ b/audio_hw.c
@@ -173,6 +173,21 @@ static void release_buffer(struct resampler_buffer_provider *buffer_provider,
/* Helper functions */
+static int select_card(int d)
+{
+ int i;
+ char dname[32];
+ for (i = 0; i < 3; ++i) {
+ sprintf(dname, "/dev/snd/pcmC%dD0%c", i, (d == PCM_IN) ? 'c' : 'p');
+ if (!access(dname, R_OK | W_OK)) {
+ ALOGD("found %s %s", (d == PCM_IN) ? "in" : "out", dname);
+ return i;
+ }
+ }
+ ALOGE("no pcm card found!");
+ return -1;
+}
+
static void select_devices(struct audio_device *adev)
{
int headphone_on;
@@ -289,7 +304,11 @@ static int start_output_stream(struct stream_out *out)
pthread_mutex_unlock(&in->lock);
}
- out->pcm = pcm_open(PCM_CARD, device, PCM_OUT | PCM_NORESTART, out->pcm_config);
+ ret = select_card(PCM_OUT);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+ out->pcm = pcm_open(ret, device, PCM_OUT | PCM_NORESTART, out->pcm_config);
if (out->pcm && !pcm_is_ready(out->pcm)) {
ALOGE("pcm_open(out) failed: %s", pcm_get_error(out->pcm));
@@ -357,7 +376,11 @@ static int start_input_stream(struct stream_in *in)
pthread_mutex_unlock(&out->lock);
}
- in->pcm = pcm_open(PCM_CARD, device, PCM_IN, in->pcm_config);
+ ret = select_card(PCM_IN);
+ if (ret < 0) {
+ return -ENODEV;
+ }
+ in->pcm = pcm_open(ret, device, PCM_IN, in->pcm_config);
if (in->pcm && !pcm_is_ready(in->pcm)) {
ALOGE("pcm_open(in) failed: %s", pcm_get_error(in->pcm));