From fdee322c9625dd98753f9f9d6bd5088db67fd3d9 Mon Sep 17 00:00:00 2001 From: jiabin Date: Wed, 22 Mar 2023 22:16:13 +0000 Subject: [PATCH] AHAL: fix StreamUsb crash. 1. By default, the DriverUsb should be standby. When there is data transfer request, it will exit standby. 2. Initialize alsa device profile before reading device info. 3. Open the alsa device proxy after the preparation succeed. Bug: 266216550 Test: atest VtsHalAudioCoreTargetTest Change-Id: I1f0425036df176c52220320135079e7c98daa2d0 --- audio/aidl/default/include/core-impl/StreamUsb.h | 2 +- audio/aidl/default/usb/StreamUsb.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/audio/aidl/default/include/core-impl/StreamUsb.h b/audio/aidl/default/include/core-impl/StreamUsb.h index f1815ddbf5..36e64cbcdb 100644 --- a/audio/aidl/default/include/core-impl/StreamUsb.h +++ b/audio/aidl/default/include/core-impl/StreamUsb.h @@ -56,7 +56,7 @@ class DriverUsb : public DriverInterface { std::vector<::aidl::android::media::audio::common::AudioDeviceAddress> mConnectedDevices GUARDED_BY(mLock); std::vector> mAlsaDeviceProxies GUARDED_BY(mLock); - bool mIsStandby = false; + bool mIsStandby = true; }; class StreamInUsb final : public StreamIn { diff --git a/audio/aidl/default/usb/StreamUsb.cpp b/audio/aidl/default/usb/StreamUsb.cpp index fbfe0f11de..5d1d7febc8 100644 --- a/audio/aidl/default/usb/StreamUsb.cpp +++ b/audio/aidl/default/usb/StreamUsb.cpp @@ -107,10 +107,13 @@ DriverUsb::DriverUsb(const StreamContext& context, bool isInput) ::android::status_t DriverUsb::transfer(void* buffer, size_t frameCount, size_t* actualFrameCount, int32_t* latencyMs) { if (!mConfig.has_value() || mConnectedDevices.empty()) { + LOG(ERROR) << __func__ << ": failed, has config: " << mConfig.has_value() + << ", has connected devices: " << mConnectedDevices.empty(); return ::android::NO_INIT; } if (mIsStandby) { if (::android::status_t status = exitStandby(); status != ::android::OK) { + LOG(ERROR) << __func__ << ": failed to exit standby, status=" << status; return status; } } @@ -151,6 +154,7 @@ DriverUsb::DriverUsb(const StreamContext& context, bool isInput) std::vector> alsaDeviceProxies; for (const auto& device : connectedDevices) { alsa_device_profile profile; + profile_init(&profile, mIsInput ? PCM_IN : PCM_OUT); profile.card = device.get()[0]; profile.device = device.get()[1]; if (!profile_read_device_info(&profile)) { @@ -174,6 +178,11 @@ DriverUsb::DriverUsb(const StreamContext& context, bool isInput) << " error=" << err; return ::android::UNKNOWN_ERROR; } + if (int err = proxy_open(proxy.get()); err != 0) { + LOG(ERROR) << __func__ << ": failed to open device, address=" << device.toString() + << " error=" << err; + return ::android::UNKNOWN_ERROR; + } alsaDeviceProxies.push_back(std::move(proxy)); } {