From 78df5949569d737f08167b0be4feec93df5f3d0b Mon Sep 17 00:00:00 2001 From: Rajeev Kumar Date: Fri, 1 May 2020 13:02:51 -0700 Subject: Fix invalid implicit declaration of function 'open'. Bug: 155495129 Test: built crosshatch_svelte successfully. Change-Id: I00c6932865f773b0a7393addc45d0acf149a9d44 --- hal/audio_extn/maxxaudio.c | 1 + hal/msm8974/platform.c | 1 + 2 files changed, 2 insertions(+) diff --git a/hal/audio_extn/maxxaudio.c b/hal/audio_extn/maxxaudio.c index 5079233..3b92d14 100644 --- a/hal/audio_extn/maxxaudio.c +++ b/hal/audio_extn/maxxaudio.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c index 8fa9826..2d35365 100644 --- a/hal/msm8974/platform.c +++ b/hal/msm8974/platform.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include -- cgit v1.2.3 From 3077da8e90b3a19e834dce22485a084b7ada8ea9 Mon Sep 17 00:00:00 2001 From: Preetam Singh Date: Tue, 4 Aug 2020 18:54:09 +0530 Subject: hal: retry a2dp path start up when failed Check if a2dp path start failed and do retry from out_write to recover the path is possible, which can avoid blocking write if path set up failed. Bug: 148926518 Test: manual test Change-Id: If0df472ca0fb6454588fe2b58f1b0cc53bb6e650 Signed-off-by: Eric Huang --- hal/audio_extn/a2dp.c | 1 + hal/audio_hw.c | 53 ++++++++++++++++++++++++++++++--------------------- hal/audio_hw.h | 1 + 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c index d7e2e2a..d594dc0 100644 --- a/hal/audio_extn/a2dp.c +++ b/hal/audio_extn/a2dp.c @@ -1424,6 +1424,7 @@ int audio_extn_a2dp_start_playback() if (ret != 0 ) { ALOGE("%s: Bluetooth controller start failed", __func__); a2dp.a2dp_started = false; + ret = -ETIMEDOUT; } else { if (configure_a2dp_encoder_format() == true) { a2dp.a2dp_started = true; diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 0f9dcf0..ad84d5d 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -803,10 +803,13 @@ int enable_snd_device(struct audio_device *adev, ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name); - if (is_a2dp_device(snd_device) && - (audio_extn_a2dp_start_playback() < 0)) { - ALOGE("%s: failed to configure A2DP control path", __func__); - goto on_error; + if (is_a2dp_device(snd_device)) { + if (audio_extn_a2dp_start_playback() < 0) { + ALOGE("%s: failed to configure A2DP control path", __func__); + goto on_error; + } else { + adev->a2dp_started = true; + } } audio_route_apply_and_update_path(adev->audio_route, device_name); @@ -839,9 +842,10 @@ int disable_snd_device(struct audio_device *adev, if (adev->snd_dev_ref_cnt[snd_device] == 0) { audio_extn_dsm_feedback_enable(adev, snd_device, false); - if (is_a2dp_device(snd_device)) + if (is_a2dp_device(snd_device)) { audio_extn_a2dp_stop_playback(); - + adev->a2dp_started = false; + } if ((snd_device == SND_DEVICE_OUT_SPEAKER || snd_device == SND_DEVICE_OUT_SPEAKER_SAFE || snd_device == SND_DEVICE_OUT_SPEAKER_REVERSE || @@ -2463,16 +2467,13 @@ int start_output_stream(struct stream_out *out) } if (out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) { - if (!audio_extn_a2dp_is_ready()) { - if (out->devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { - a2dp_combo = true; - } else { - if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) { - ALOGE("%s: A2DP profile is not ready, return error", __func__); - ret = -EAGAIN; - goto error_config; - } - } + if (out->devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) { + a2dp_combo = true; + } else if (!audio_extn_a2dp_is_ready() && + !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) { + ALOGE("%s: A2DP profile is not ready, return error", __func__); + ret = -EAGAIN; + goto error_config; } } out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK); @@ -2505,11 +2506,14 @@ int start_output_stream(struct stream_out *out) audio_streaming_hint_start(); audio_extn_perf_lock_acquire(); + if (!(out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) || + audio_extn_a2dp_is_ready()) { + select_devices(adev, out->usecase); + } + if ((out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) && - (!audio_extn_a2dp_is_ready())) { - if (!a2dp_combo) { - check_a2dp_restore_l(adev, out, false); - } else { + (!audio_extn_a2dp_is_ready() || !adev->a2dp_started)) { + if (a2dp_combo) { audio_devices_t dev = out->devices; if (dev & AUDIO_DEVICE_OUT_SPEAKER_SAFE) out->devices = AUDIO_DEVICE_OUT_SPEAKER_SAFE; @@ -2517,9 +2521,13 @@ int start_output_stream(struct stream_out *out) out->devices = AUDIO_DEVICE_OUT_SPEAKER; select_devices(adev, out->usecase); out->devices = dev; + } else if (!audio_extn_a2dp_is_ready()) { + check_a2dp_restore_l(adev, out, false); + } else { + ALOGE("%s: A2DP is not started, return error", __func__); + ret = -EINVAL; + goto error_open; } - } else { - select_devices(adev, out->usecase); } audio_extn_extspk_update(adev->extspk); @@ -6606,6 +6614,7 @@ static int adev_open(const hw_module_t *module, const char *name, adev->primary_output = NULL; adev->bluetooth_nrec = true; adev->acdb_settings = TTY_MODE_OFF; + adev->a2dp_started = false; /* adev->cur_hdmi_channels = 0; by calloc() */ adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int)); voice_init(adev); diff --git a/hal/audio_hw.h b/hal/audio_hw.h index e980e88..b709b1d 100644 --- a/hal/audio_hw.h +++ b/hal/audio_hw.h @@ -431,6 +431,7 @@ struct audio_device { snd_device_t last_logged_snd_device[AUDIO_USECASE_MAX][2]; /* [out, in] */ int camera_orientation; /* CAMERA_BACK_LANDSCAPE ... CAMERA_FRONT_PORTRAIT */ bool bt_sco_on; + bool a2dp_started; }; int select_devices(struct audio_device *adev, -- cgit v1.2.3 From 1350928f7ae5769ec22b0922d12eb31dfe4ed59d Mon Sep 17 00:00:00 2001 From: llololo Date: Fri, 21 Aug 2020 02:38:24 +0000 Subject: audio_hal: Ensure input buffer size represents an integral number of frames. Update get input buffer size logic for record use cases such that the size is also a multiple of bytes per sample period. For 1 channel 24 bit recording the computed value was not a multiple of bytes per sample and this mismatches with the computed value by ALSA causing buffer invalid errors because the use case pointers difference was reaching stop threshold. Bug: 152727483 Test: repro steps in the bug. Change-Id: I953366e09d98352d30b82f40c18a261d2355cf2c --- hal/audio_hw.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hal/audio_hw.c b/hal/audio_hw.c index fa03a41..d165668 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -2746,23 +2746,21 @@ static size_t get_stream_buffer_size(size_t duration_ms, int channel_count, bool is_low_latency) { - size_t size = 0; + // Compute target frames based on time or period size. + size_t target_frames = is_low_latency + ? configured_low_latency_capture_period_size // record only + : (sample_rate * duration_ms) / 1000; - size = (sample_rate * duration_ms) / 1000; - if (is_low_latency) - size = configured_low_latency_capture_period_size; - - size *= channel_count * audio_bytes_per_sample(format); + // Round up to a multiple of 16 frames in case sizing for the MixerThread. + if (!is_low_latency) { // low latency flag set for record only + target_frames = (target_frames + 0xf) & ~0xf; + } - /* make sure the size is multiple of 32 bytes - * At 48 kHz mono 16-bit PCM: - * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15) - * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10) - */ - size += 0x1f; - size &= ~0x1f; + // Buffer size is the target frames multiplied by the frame size in bytes. + const size_t frame_size = channel_count * audio_bytes_per_sample(format); + const size_t buffer_size = target_frames * frame_size; - return size; + return buffer_size; } static uint32_t out_get_sample_rate(const struct audio_stream *stream) -- cgit v1.2.3 From 49b1536ed6ee60ab1bd652d23079a073d269dd61 Mon Sep 17 00:00:00 2001 From: llololo Date: Thu, 8 Apr 2021 09:25:58 +0000 Subject: audio_hw_usb: reduce the number of the retries in usb_get_capability reduce the number of the retries to avoid hitting timecheck timeout 5s. Bug: 172888755 Test: usb audio function simple test Change-Id: I0a30b3246e13e440acf89b6b9f05480ca796259b --- hal/audio_extn/usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hal/audio_extn/usb.c b/hal/audio_extn/usb.c index b0b5049..4bf6a32 100644 --- a/hal/audio_extn/usb.c +++ b/hal/audio_extn/usb.c @@ -336,7 +336,7 @@ static int usb_get_capability(int type, char *bit_width_str = NULL; struct usb_device_config * usb_device_info; bool check = false; - int tries=5; + int tries=3; memset(path, 0, sizeof(path)); ALOGV("%s: for %s", __func__, (type == USB_PLAYBACK) ? @@ -354,7 +354,7 @@ static int usb_get_capability(int type, // TODO: figure up if this wait is needed any more while (tries--) { if (access(path, F_OK) < 0) { - ALOGW("stream %s doesn't exist retrying\n", path); + ALOGW("stream %s doesn't exist retrying %d more times\n", path, tries); sleep(1); continue; } -- cgit v1.2.3