Audio r_submix : Replace usage of portId by device address am: 2e460345a2
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2677975 Change-Id: I7fb16a97fa159ff715f6dbc3c19c94c2d11db514 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
335037031d
2 changed files with 96 additions and 22 deletions
|
@ -20,16 +20,16 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core-impl/Stream.h"
|
#include "core-impl/Stream.h"
|
||||||
|
#include "core-impl/StreamSwitcher.h"
|
||||||
#include "r_submix/SubmixRoute.h"
|
#include "r_submix/SubmixRoute.h"
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core {
|
namespace aidl::android::hardware::audio::core {
|
||||||
|
|
||||||
using aidl::android::hardware::audio::core::r_submix::AudioConfig;
|
|
||||||
using aidl::android::hardware::audio::core::r_submix::SubmixRoute;
|
|
||||||
|
|
||||||
class StreamRemoteSubmix : public StreamCommonImpl {
|
class StreamRemoteSubmix : public StreamCommonImpl {
|
||||||
public:
|
public:
|
||||||
StreamRemoteSubmix(StreamContext* context, const Metadata& metadata);
|
StreamRemoteSubmix(
|
||||||
|
StreamContext* context, const Metadata& metadata,
|
||||||
|
const ::aidl::android::media::audio::common::AudioDeviceAddress& deviceAddress);
|
||||||
|
|
||||||
::android::status_t init() override;
|
::android::status_t init() override;
|
||||||
::android::status_t drain(StreamDescriptor::DrainMode) override;
|
::android::status_t drain(StreamDescriptor::DrainMode) override;
|
||||||
|
@ -51,16 +51,17 @@ class StreamRemoteSubmix : public StreamCommonImpl {
|
||||||
::android::status_t outWrite(void* buffer, size_t frameCount, size_t* actualFrameCount);
|
::android::status_t outWrite(void* buffer, size_t frameCount, size_t* actualFrameCount);
|
||||||
::android::status_t inRead(void* buffer, size_t frameCount, size_t* actualFrameCount);
|
::android::status_t inRead(void* buffer, size_t frameCount, size_t* actualFrameCount);
|
||||||
|
|
||||||
const int mPortId;
|
const ::aidl::android::media::audio::common::AudioDeviceAddress mDeviceAddress;
|
||||||
const bool mIsInput;
|
const bool mIsInput;
|
||||||
AudioConfig mStreamConfig;
|
r_submix::AudioConfig mStreamConfig;
|
||||||
std::shared_ptr<SubmixRoute> mCurrentRoute = nullptr;
|
std::shared_ptr<r_submix::SubmixRoute> mCurrentRoute = nullptr;
|
||||||
|
|
||||||
// Mutex lock to protect vector of submix routes, each of these submix routes have their mutex
|
// Mutex lock to protect vector of submix routes, each of these submix routes have their mutex
|
||||||
// locks and none of the mutex locks should be taken together.
|
// locks and none of the mutex locks should be taken together.
|
||||||
static std::mutex sSubmixRoutesLock;
|
static std::mutex sSubmixRoutesLock;
|
||||||
static std::map<int32_t, std::shared_ptr<SubmixRoute>> sSubmixRoutes
|
static std::map<::aidl::android::media::audio::common::AudioDeviceAddress,
|
||||||
GUARDED_BY(sSubmixRoutesLock);
|
std::shared_ptr<r_submix::SubmixRoute>>
|
||||||
|
sSubmixRoutes GUARDED_BY(sSubmixRoutesLock);
|
||||||
|
|
||||||
// limit for number of read error log entries to avoid spamming the logs
|
// limit for number of read error log entries to avoid spamming the logs
|
||||||
static constexpr int kMaxReadErrorLogs = 5;
|
static constexpr int kMaxReadErrorLogs = 5;
|
||||||
|
@ -72,7 +73,7 @@ class StreamRemoteSubmix : public StreamCommonImpl {
|
||||||
static constexpr int kReadAttemptSleepUs = 5000;
|
static constexpr int kReadAttemptSleepUs = 5000;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StreamInRemoteSubmix final : public StreamIn, public StreamRemoteSubmix {
|
class StreamInRemoteSubmix final : public StreamIn, public StreamSwitcher {
|
||||||
public:
|
public:
|
||||||
friend class ndk::SharedRefBase;
|
friend class ndk::SharedRefBase;
|
||||||
StreamInRemoteSubmix(
|
StreamInRemoteSubmix(
|
||||||
|
@ -81,13 +82,19 @@ class StreamInRemoteSubmix final : public StreamIn, public StreamRemoteSubmix {
|
||||||
const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones);
|
const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DeviceSwitchBehavior switchCurrentStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices)
|
||||||
|
override;
|
||||||
|
std::unique_ptr<StreamCommonInterfaceEx> createNewStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
|
||||||
|
StreamContext* context, const Metadata& metadata) override;
|
||||||
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
||||||
ndk::ScopedAStatus getActiveMicrophones(
|
ndk::ScopedAStatus getActiveMicrophones(
|
||||||
std::vector<::aidl::android::media::audio::common::MicrophoneDynamicInfo>* _aidl_return)
|
std::vector<::aidl::android::media::audio::common::MicrophoneDynamicInfo>* _aidl_return)
|
||||||
override;
|
override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StreamOutRemoteSubmix final : public StreamOut, public StreamRemoteSubmix {
|
class StreamOutRemoteSubmix final : public StreamOut, public StreamSwitcher {
|
||||||
public:
|
public:
|
||||||
friend class ndk::SharedRefBase;
|
friend class ndk::SharedRefBase;
|
||||||
StreamOutRemoteSubmix(
|
StreamOutRemoteSubmix(
|
||||||
|
@ -97,6 +104,12 @@ class StreamOutRemoteSubmix final : public StreamOut, public StreamRemoteSubmix
|
||||||
offloadInfo);
|
offloadInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DeviceSwitchBehavior switchCurrentStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices)
|
||||||
|
override;
|
||||||
|
std::unique_ptr<StreamCommonInterfaceEx> createNewStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
|
||||||
|
StreamContext* context, const Metadata& metadata) override;
|
||||||
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,18 @@
|
||||||
|
|
||||||
using aidl::android::hardware::audio::common::SinkMetadata;
|
using aidl::android::hardware::audio::common::SinkMetadata;
|
||||||
using aidl::android::hardware::audio::common::SourceMetadata;
|
using aidl::android::hardware::audio::common::SourceMetadata;
|
||||||
|
using aidl::android::hardware::audio::core::r_submix::SubmixRoute;
|
||||||
|
using aidl::android::media::audio::common::AudioDeviceAddress;
|
||||||
using aidl::android::media::audio::common::AudioOffloadInfo;
|
using aidl::android::media::audio::common::AudioOffloadInfo;
|
||||||
using aidl::android::media::audio::common::MicrophoneDynamicInfo;
|
using aidl::android::media::audio::common::MicrophoneDynamicInfo;
|
||||||
using aidl::android::media::audio::common::MicrophoneInfo;
|
using aidl::android::media::audio::common::MicrophoneInfo;
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core {
|
namespace aidl::android::hardware::audio::core {
|
||||||
|
|
||||||
StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& metadata)
|
StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& metadata,
|
||||||
|
const AudioDeviceAddress& deviceAddress)
|
||||||
: StreamCommonImpl(context, metadata),
|
: StreamCommonImpl(context, metadata),
|
||||||
mPortId(context->getPortId()),
|
mDeviceAddress(deviceAddress),
|
||||||
mIsInput(isInput(metadata)) {
|
mIsInput(isInput(metadata)) {
|
||||||
mStreamConfig.frameSize = context->getFrameSize();
|
mStreamConfig.frameSize = context->getFrameSize();
|
||||||
mStreamConfig.format = context->getFormat();
|
mStreamConfig.format = context->getFormat();
|
||||||
|
@ -40,13 +43,14 @@ StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& m
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex StreamRemoteSubmix::sSubmixRoutesLock;
|
std::mutex StreamRemoteSubmix::sSubmixRoutesLock;
|
||||||
std::map<int32_t, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::sSubmixRoutes;
|
std::map<AudioDeviceAddress, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::sSubmixRoutes;
|
||||||
|
|
||||||
::android::status_t StreamRemoteSubmix::init() {
|
::android::status_t StreamRemoteSubmix::init() {
|
||||||
{
|
{
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
std::lock_guard guard(sSubmixRoutesLock);
|
||||||
if (sSubmixRoutes.find(mPortId) != sSubmixRoutes.end()) {
|
auto routeItr = sSubmixRoutes.find(mDeviceAddress);
|
||||||
mCurrentRoute = sSubmixRoutes[mPortId];
|
if (routeItr != sSubmixRoutes.end()) {
|
||||||
|
mCurrentRoute = routeItr->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If route is not available for this port, add it.
|
// If route is not available for this port, add it.
|
||||||
|
@ -59,7 +63,7 @@ std::map<int32_t, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::sSubmixRoute
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
std::lock_guard guard(sSubmixRoutesLock);
|
||||||
sSubmixRoutes.emplace(mPortId, mCurrentRoute);
|
sSubmixRoutes.emplace(mDeviceAddress, mCurrentRoute);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
|
if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
|
||||||
|
@ -116,8 +120,9 @@ ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
|
||||||
std::shared_ptr<SubmixRoute> route = nullptr;
|
std::shared_ptr<SubmixRoute> route = nullptr;
|
||||||
{
|
{
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
std::lock_guard guard(sSubmixRoutesLock);
|
||||||
if (sSubmixRoutes.find(mPortId) != sSubmixRoutes.end()) {
|
auto routeItr = sSubmixRoutes.find(mDeviceAddress);
|
||||||
route = sSubmixRoutes[mPortId];
|
if (routeItr != sSubmixRoutes.end()) {
|
||||||
|
route = routeItr->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (route != nullptr) {
|
if (route != nullptr) {
|
||||||
|
@ -146,7 +151,7 @@ void StreamRemoteSubmix::shutdown() {
|
||||||
LOG(DEBUG) << __func__ << ": pipe destroyed";
|
LOG(DEBUG) << __func__ << ": pipe destroyed";
|
||||||
|
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
std::lock_guard guard(sSubmixRoutesLock);
|
||||||
sSubmixRoutes.erase(mPortId);
|
sSubmixRoutes.erase(mDeviceAddress);
|
||||||
}
|
}
|
||||||
mCurrentRoute.reset();
|
mCurrentRoute.reset();
|
||||||
}
|
}
|
||||||
|
@ -357,7 +362,7 @@ StreamInRemoteSubmix::StreamInRemoteSubmix(StreamContext&& context,
|
||||||
const SinkMetadata& sinkMetadata,
|
const SinkMetadata& sinkMetadata,
|
||||||
const std::vector<MicrophoneInfo>& microphones)
|
const std::vector<MicrophoneInfo>& microphones)
|
||||||
: StreamIn(std::move(context), microphones),
|
: StreamIn(std::move(context), microphones),
|
||||||
StreamRemoteSubmix(&(StreamIn::mContext), sinkMetadata) {}
|
StreamSwitcher(&(StreamIn::mContext), sinkMetadata) {}
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
|
ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
|
||||||
std::vector<MicrophoneDynamicInfo>* _aidl_return) {
|
std::vector<MicrophoneDynamicInfo>* _aidl_return) {
|
||||||
|
@ -366,10 +371,66 @@ ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamSwitcher::DeviceSwitchBehavior StreamInRemoteSubmix::switchCurrentStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
|
||||||
|
// This implementation effectively postpones stream creation until
|
||||||
|
// receiving the first call to 'setConnectedDevices' with a non-empty list.
|
||||||
|
if (isStubStream()) {
|
||||||
|
if (devices.size() == 1) {
|
||||||
|
auto deviceDesc = devices.front().type;
|
||||||
|
if (deviceDesc.type ==
|
||||||
|
::aidl::android::media::audio::common::AudioDeviceType::IN_SUBMIX) {
|
||||||
|
return DeviceSwitchBehavior::CREATE_NEW_STREAM;
|
||||||
|
}
|
||||||
|
LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
|
||||||
|
<< " not supported";
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << __func__ << ": Only single device supported.";
|
||||||
|
}
|
||||||
|
return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
|
||||||
|
}
|
||||||
|
return DeviceSwitchBehavior::USE_CURRENT_STREAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<StreamCommonInterfaceEx> StreamInRemoteSubmix::createNewStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
|
||||||
|
StreamContext* context, const Metadata& metadata) {
|
||||||
|
return std::unique_ptr<StreamCommonInterfaceEx>(
|
||||||
|
new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
|
||||||
|
}
|
||||||
|
|
||||||
StreamOutRemoteSubmix::StreamOutRemoteSubmix(StreamContext&& context,
|
StreamOutRemoteSubmix::StreamOutRemoteSubmix(StreamContext&& context,
|
||||||
const SourceMetadata& sourceMetadata,
|
const SourceMetadata& sourceMetadata,
|
||||||
const std::optional<AudioOffloadInfo>& offloadInfo)
|
const std::optional<AudioOffloadInfo>& offloadInfo)
|
||||||
: StreamOut(std::move(context), offloadInfo),
|
: StreamOut(std::move(context), offloadInfo),
|
||||||
StreamRemoteSubmix(&(StreamOut::mContext), sourceMetadata) {}
|
StreamSwitcher(&(StreamOut::mContext), sourceMetadata) {}
|
||||||
|
|
||||||
|
StreamSwitcher::DeviceSwitchBehavior StreamOutRemoteSubmix::switchCurrentStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
|
||||||
|
// This implementation effectively postpones stream creation until
|
||||||
|
// receiving the first call to 'setConnectedDevices' with a non-empty list.
|
||||||
|
if (isStubStream()) {
|
||||||
|
if (devices.size() == 1) {
|
||||||
|
auto deviceDesc = devices.front().type;
|
||||||
|
if (deviceDesc.type ==
|
||||||
|
::aidl::android::media::audio::common::AudioDeviceType::OUT_SUBMIX) {
|
||||||
|
return DeviceSwitchBehavior::CREATE_NEW_STREAM;
|
||||||
|
}
|
||||||
|
LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
|
||||||
|
<< " not supported";
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << __func__ << ": Only single device supported.";
|
||||||
|
}
|
||||||
|
return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
|
||||||
|
}
|
||||||
|
return DeviceSwitchBehavior::USE_CURRENT_STREAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<StreamCommonInterfaceEx> StreamOutRemoteSubmix::createNewStream(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
|
||||||
|
StreamContext* context, const Metadata& metadata) {
|
||||||
|
return std::unique_ptr<StreamCommonInterfaceEx>(
|
||||||
|
new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aidl::android::hardware::audio::core
|
} // namespace aidl::android::hardware::audio::core
|
||||||
|
|
Loading…
Reference in a new issue