hardware/libaudio
Revision | cdbc332ddb87cbf5f02cf5a4d2754f0cec18680c (tree) |
---|---|
Zeit | 2015-10-07 00:15:21 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
fallback to sampling rates 44100 if possible
@@ -188,6 +188,19 @@ static int select_card(int d) | ||
188 | 188 | return -1; |
189 | 189 | } |
190 | 190 | |
191 | +struct pcm *my_pcm_open(unsigned int card, unsigned int device, unsigned int flags, struct pcm_config *config) | |
192 | +{ | |
193 | + struct pcm *pcm = pcm_open(card, device, flags, config); | |
194 | + if (pcm && !pcm_is_ready(pcm)) { | |
195 | + ALOGE("my_pcm_open(%d) failed: %s", flags, pcm_get_error(pcm)); | |
196 | + pcm_close(pcm); | |
197 | + ALOGI("my_pcm_open: re-try 44100 on card %d", card); | |
198 | + config->rate = 44100; | |
199 | + pcm = pcm_open(card, device, flags, config); | |
200 | + } | |
201 | + return pcm; | |
202 | +} | |
203 | + | |
191 | 204 | static void select_devices(struct audio_device *adev) |
192 | 205 | { |
193 | 206 | int headphone_on; |
@@ -308,7 +321,7 @@ static int start_output_stream(struct stream_out *out) | ||
308 | 321 | if (ret < 0) { |
309 | 322 | return -ENODEV; |
310 | 323 | } |
311 | - out->pcm = pcm_open(ret, device, PCM_OUT | PCM_NORESTART, out->pcm_config); | |
324 | + out->pcm = my_pcm_open(ret, device, PCM_OUT | PCM_NORESTART, out->pcm_config); | |
312 | 325 | |
313 | 326 | if (out->pcm && !pcm_is_ready(out->pcm)) { |
314 | 327 | ALOGE("pcm_open(out) failed: %s", pcm_get_error(out->pcm)); |
@@ -380,7 +393,7 @@ static int start_input_stream(struct stream_in *in) | ||
380 | 393 | if (ret < 0) { |
381 | 394 | return -ENODEV; |
382 | 395 | } |
383 | - in->pcm = pcm_open(ret, device, PCM_IN, in->pcm_config); | |
396 | + in->pcm = my_pcm_open(ret, device, PCM_IN, in->pcm_config); | |
384 | 397 | |
385 | 398 | if (in->pcm && !pcm_is_ready(in->pcm)) { |
386 | 399 | 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, | ||
729 | 742 | break; |
730 | 743 | total_sleep_time_us += sleep_time_us; |
731 | 744 | if (total_sleep_time_us > MAX_WRITE_SLEEP_US) { |
732 | - ALOGW("out_write() limiting sleep time %d to %d", | |
745 | + ALOGV("out_write() limiting sleep time %d to %d", | |
733 | 746 | total_sleep_time_us, MAX_WRITE_SLEEP_US); |
734 | 747 | sleep_time_us = MAX_WRITE_SLEEP_US - |
735 | 748 | (total_sleep_time_us - sleep_time_us); |
@@ -769,6 +782,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, | ||
769 | 782 | if (ret == -EPIPE) { |
770 | 783 | /* In case of underrun, don't sleep since we want to catch up asap */ |
771 | 784 | pthread_mutex_unlock(&out->lock); |
785 | + ALOGW("out_write underrun: %d", ret); | |
772 | 786 | return ret; |
773 | 787 | } |
774 | 788 |
@@ -776,6 +790,7 @@ exit: | ||
776 | 790 | pthread_mutex_unlock(&out->lock); |
777 | 791 | |
778 | 792 | if (ret != 0) { |
793 | + ALOGW("out_write error: %d, sleeping...", ret); | |
779 | 794 | usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / |
780 | 795 | out_get_sample_rate(&stream->common)); |
781 | 796 | } |