diff options
| author | Chih-Wei Huang <cwhuang@linux.org.tw> | 2015-06-26 01:00:00 +0800 |
|---|---|---|
| committer | Chih-Wei Huang <cwhuang@linux.org.tw> | 2015-10-06 23:15:21 +0800 |
| commit | cdbc332ddb87cbf5f02cf5a4d2754f0cec18680c (patch) | |
| tree | 8167754bdcef210138f3c6a78f08e57fa5f1b199 | |
| parent | 9dada96500ea2bb63e0c1273bbad8f878d55704a (diff) | |
| download | platform_hardware_libaudio-cdbc332ddb87cbf5f02cf5a4d2754f0cec18680c.tar.gz platform_hardware_libaudio-cdbc332ddb87cbf5f02cf5a4d2754f0cec18680c.tar.bz2 platform_hardware_libaudio-cdbc332ddb87cbf5f02cf5a4d2754f0cec18680c.zip | |
fallback to sampling rates 44100 if possible
| -rw-r--r-- | audio_hw.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -188,6 +188,19 @@ static int select_card(int d) return -1; } +struct pcm *my_pcm_open(unsigned int card, unsigned int device, unsigned int flags, struct pcm_config *config) +{ + struct pcm *pcm = pcm_open(card, device, flags, config); + if (pcm && !pcm_is_ready(pcm)) { + ALOGE("my_pcm_open(%d) failed: %s", flags, pcm_get_error(pcm)); + pcm_close(pcm); + ALOGI("my_pcm_open: re-try 44100 on card %d", card); + config->rate = 44100; + pcm = pcm_open(card, device, flags, config); + } + return pcm; +} + static void select_devices(struct audio_device *adev) { int headphone_on; @@ -308,7 +321,7 @@ static int start_output_stream(struct stream_out *out) if (ret < 0) { return -ENODEV; } - out->pcm = pcm_open(ret, device, PCM_OUT | PCM_NORESTART, out->pcm_config); + out->pcm = my_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)); @@ -380,7 +393,7 @@ static int start_input_stream(struct stream_in *in) if (ret < 0) { return -ENODEV; } - in->pcm = pcm_open(ret, device, PCM_IN, in->pcm_config); + in->pcm = my_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)); @@ -729,7 +742,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, break; total_sleep_time_us += sleep_time_us; if (total_sleep_time_us > MAX_WRITE_SLEEP_US) { - ALOGW("out_write() limiting sleep time %d to %d", + ALOGV("out_write() limiting sleep time %d to %d", total_sleep_time_us, MAX_WRITE_SLEEP_US); sleep_time_us = MAX_WRITE_SLEEP_US - (total_sleep_time_us - sleep_time_us); @@ -769,6 +782,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, if (ret == -EPIPE) { /* In case of underrun, don't sleep since we want to catch up asap */ pthread_mutex_unlock(&out->lock); + ALOGW("out_write underrun: %d", ret); return ret; } @@ -776,6 +790,7 @@ exit: pthread_mutex_unlock(&out->lock); if (ret != 0) { + ALOGW("out_write error: %d, sleeping...", ret); usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / out_get_sample_rate(&stream->common)); } |
