Merge changes from topic "fix-aidl-mix-ports-and-bt" into main
* changes: audio: Fix BT AIDL HAL module implementation audio r_submix: Suggest configuration from the peer audio: Refactor configuration population
This commit is contained in:
commit
eafa78c929
19 changed files with 616 additions and 344 deletions
|
@ -93,32 +93,6 @@ bool hasDynamicProfilesOnly(const std::vector<AudioProfile>& profiles) {
|
||||||
return std::all_of(profiles.begin(), profiles.end(), isDynamicProfile);
|
return std::all_of(profiles.begin(), profiles.end(), isDynamicProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: does not assign an ID to the config.
|
|
||||||
bool generateDefaultPortConfig(const AudioPort& port, AudioPortConfig* config) {
|
|
||||||
const bool allowDynamicConfig = port.ext.getTag() == AudioPortExt::device;
|
|
||||||
*config = {};
|
|
||||||
config->portId = port.id;
|
|
||||||
for (const auto& profile : port.profiles) {
|
|
||||||
if (isDynamicProfile(profile)) continue;
|
|
||||||
config->format = profile.format;
|
|
||||||
config->channelMask = *profile.channelMasks.begin();
|
|
||||||
config->sampleRate = Int{.value = *profile.sampleRates.begin()};
|
|
||||||
config->flags = port.flags;
|
|
||||||
config->ext = port.ext;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (allowDynamicConfig) {
|
|
||||||
config->format = AudioFormatDescription{};
|
|
||||||
config->channelMask = AudioChannelLayout{};
|
|
||||||
config->sampleRate = Int{.value = 0};
|
|
||||||
config->flags = port.flags;
|
|
||||||
config->ext = port.ext;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
LOG(ERROR) << __func__ << ": port " << port.id << " only has dynamic profiles";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& format,
|
bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& format,
|
||||||
AudioProfile* profile) {
|
AudioProfile* profile) {
|
||||||
if (auto profilesIt =
|
if (auto profilesIt =
|
||||||
|
@ -204,10 +178,11 @@ ndk::ScopedAStatus Module::createStreamContext(
|
||||||
}
|
}
|
||||||
auto& configs = getConfig().portConfigs;
|
auto& configs = getConfig().portConfigs;
|
||||||
auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
|
auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
|
||||||
|
const int32_t nominalLatencyMs = getNominalLatencyMs(*portConfigIt);
|
||||||
// Since this is a private method, it is assumed that
|
// Since this is a private method, it is assumed that
|
||||||
// validity of the portConfigId has already been checked.
|
// validity of the portConfigId has already been checked.
|
||||||
const int32_t minimumStreamBufferSizeFrames = calculateBufferSizeFrames(
|
const int32_t minimumStreamBufferSizeFrames =
|
||||||
getNominalLatencyMs(*portConfigIt), portConfigIt->sampleRate.value().value);
|
calculateBufferSizeFrames(nominalLatencyMs, portConfigIt->sampleRate.value().value);
|
||||||
if (in_bufferSizeFrames < minimumStreamBufferSizeFrames) {
|
if (in_bufferSizeFrames < minimumStreamBufferSizeFrames) {
|
||||||
LOG(ERROR) << __func__ << ": insufficient buffer size " << in_bufferSizeFrames
|
LOG(ERROR) << __func__ << ": insufficient buffer size " << in_bufferSizeFrames
|
||||||
<< ", must be at least " << minimumStreamBufferSizeFrames;
|
<< ", must be at least " << minimumStreamBufferSizeFrames;
|
||||||
|
@ -241,7 +216,7 @@ ndk::ScopedAStatus Module::createStreamContext(
|
||||||
std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
|
std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
|
||||||
std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
|
std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
|
||||||
portConfigIt->format.value(), portConfigIt->channelMask.value(),
|
portConfigIt->format.value(), portConfigIt->channelMask.value(),
|
||||||
portConfigIt->sampleRate.value().value, flags, getNominalLatencyMs(*portConfigIt),
|
portConfigIt->sampleRate.value().value, flags, nominalLatencyMs,
|
||||||
portConfigIt->ext.get<AudioPortExt::mix>().handle,
|
portConfigIt->ext.get<AudioPortExt::mix>().handle,
|
||||||
std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
|
std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
|
||||||
asyncCallback, outEventCallback,
|
asyncCallback, outEventCallback,
|
||||||
|
@ -328,6 +303,29 @@ ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, Audio
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Module::generateDefaultPortConfig(const AudioPort& port, AudioPortConfig* config) {
|
||||||
|
const bool allowDynamicConfig = port.ext.getTag() == AudioPortExt::device;
|
||||||
|
for (const auto& profile : port.profiles) {
|
||||||
|
if (isDynamicProfile(profile)) continue;
|
||||||
|
config->format = profile.format;
|
||||||
|
config->channelMask = *profile.channelMasks.begin();
|
||||||
|
config->sampleRate = Int{.value = *profile.sampleRates.begin()};
|
||||||
|
config->flags = port.flags;
|
||||||
|
config->ext = port.ext;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (allowDynamicConfig) {
|
||||||
|
config->format = AudioFormatDescription{};
|
||||||
|
config->channelMask = AudioChannelLayout{};
|
||||||
|
config->sampleRate = Int{.value = 0};
|
||||||
|
config->flags = port.flags;
|
||||||
|
config->ext = port.ext;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
LOG(ERROR) << __func__ << ": port " << port.id << " only has dynamic profiles";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Module::populateConnectedProfiles() {
|
void Module::populateConnectedProfiles() {
|
||||||
Configuration& config = getConfig();
|
Configuration& config = getConfig();
|
||||||
for (const AudioPort& port : config.ports) {
|
for (const AudioPort& port : config.ports) {
|
||||||
|
@ -617,10 +615,11 @@ ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdA
|
||||||
|
|
||||||
std::vector<AudioRoute*> routesToMixPorts = getAudioRoutesForAudioPortImpl(templateId);
|
std::vector<AudioRoute*> routesToMixPorts = getAudioRoutesForAudioPortImpl(templateId);
|
||||||
std::set<int32_t> routableMixPortIds = getRoutableAudioPortIds(templateId, &routesToMixPorts);
|
std::set<int32_t> routableMixPortIds = getRoutableAudioPortIds(templateId, &routesToMixPorts);
|
||||||
|
const int32_t nextPortId = getConfig().nextPortId++;
|
||||||
if (!mDebug.simulateDeviceConnections) {
|
if (!mDebug.simulateDeviceConnections) {
|
||||||
// Even if the device port has static profiles, the HAL module might need to update
|
// Even if the device port has static profiles, the HAL module might need to update
|
||||||
// them, or abort the connection process.
|
// them, or abort the connection process.
|
||||||
RETURN_STATUS_IF_ERROR(populateConnectedDevicePort(&connectedPort));
|
RETURN_STATUS_IF_ERROR(populateConnectedDevicePort(&connectedPort, nextPortId));
|
||||||
} else if (hasDynamicProfilesOnly(connectedPort.profiles)) {
|
} else if (hasDynamicProfilesOnly(connectedPort.profiles)) {
|
||||||
auto& connectedProfiles = getConfig().connectedProfiles;
|
auto& connectedProfiles = getConfig().connectedProfiles;
|
||||||
if (auto connectedProfilesIt = connectedProfiles.find(templateId);
|
if (auto connectedProfilesIt = connectedProfiles.find(templateId);
|
||||||
|
@ -644,7 +643,7 @@ ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedPort.id = getConfig().nextPortId++;
|
connectedPort.id = nextPortId;
|
||||||
auto [connectedPortsIt, _] =
|
auto [connectedPortsIt, _] =
|
||||||
mConnectedDevicePorts.insert(std::pair(connectedPort.id, std::set<int32_t>()));
|
mConnectedDevicePorts.insert(std::pair(connectedPort.id, std::set<int32_t>()));
|
||||||
LOG(DEBUG) << __func__ << ": template port " << templateId << " external device connected, "
|
LOG(DEBUG) << __func__ << ": template port " << templateId << " external device connected, "
|
||||||
|
@ -1035,6 +1034,18 @@ ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPa
|
||||||
|
|
||||||
ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requested,
|
ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requested,
|
||||||
AudioPortConfig* out_suggested, bool* _aidl_return) {
|
AudioPortConfig* out_suggested, bool* _aidl_return) {
|
||||||
|
auto generate = [this](const AudioPort& port, AudioPortConfig* config) {
|
||||||
|
return generateDefaultPortConfig(port, config);
|
||||||
|
};
|
||||||
|
return setAudioPortConfigImpl(in_requested, generate, out_suggested, _aidl_return);
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus Module::setAudioPortConfigImpl(
|
||||||
|
const AudioPortConfig& in_requested,
|
||||||
|
const std::function<bool(const ::aidl::android::media::audio::common::AudioPort& port,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig* config)>&
|
||||||
|
fillPortConfig,
|
||||||
|
AudioPortConfig* out_suggested, bool* applied) {
|
||||||
LOG(DEBUG) << __func__ << ": requested " << in_requested.toString();
|
LOG(DEBUG) << __func__ << ": requested " << in_requested.toString();
|
||||||
auto& configs = getConfig().portConfigs;
|
auto& configs = getConfig().portConfigs;
|
||||||
auto existing = configs.end();
|
auto existing = configs.end();
|
||||||
|
@ -1063,7 +1074,8 @@ ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requeste
|
||||||
*out_suggested = *existing;
|
*out_suggested = *existing;
|
||||||
} else {
|
} else {
|
||||||
AudioPortConfig newConfig;
|
AudioPortConfig newConfig;
|
||||||
if (generateDefaultPortConfig(*portIt, &newConfig)) {
|
newConfig.portId = portIt->id;
|
||||||
|
if (fillPortConfig(*portIt, &newConfig)) {
|
||||||
*out_suggested = newConfig;
|
*out_suggested = newConfig;
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << __func__ << ": unable generate a default config for port " << portId;
|
LOG(ERROR) << __func__ << ": unable generate a default config for port " << portId;
|
||||||
|
@ -1168,17 +1180,17 @@ ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requeste
|
||||||
if (existing == configs.end() && requestedIsValid && requestedIsFullySpecified) {
|
if (existing == configs.end() && requestedIsValid && requestedIsFullySpecified) {
|
||||||
out_suggested->id = getConfig().nextPortId++;
|
out_suggested->id = getConfig().nextPortId++;
|
||||||
configs.push_back(*out_suggested);
|
configs.push_back(*out_suggested);
|
||||||
*_aidl_return = true;
|
*applied = true;
|
||||||
LOG(DEBUG) << __func__ << ": created new port config " << out_suggested->toString();
|
LOG(DEBUG) << __func__ << ": created new port config " << out_suggested->toString();
|
||||||
} else if (existing != configs.end() && requestedIsValid) {
|
} else if (existing != configs.end() && requestedIsValid) {
|
||||||
*existing = *out_suggested;
|
*existing = *out_suggested;
|
||||||
*_aidl_return = true;
|
*applied = true;
|
||||||
LOG(DEBUG) << __func__ << ": updated port config " << out_suggested->toString();
|
LOG(DEBUG) << __func__ << ": updated port config " << out_suggested->toString();
|
||||||
} else {
|
} else {
|
||||||
LOG(DEBUG) << __func__ << ": not applied; existing config ? " << (existing != configs.end())
|
LOG(DEBUG) << __func__ << ": not applied; existing config ? " << (existing != configs.end())
|
||||||
<< "; requested is valid? " << requestedIsValid << ", fully specified? "
|
<< "; requested is valid? " << requestedIsValid << ", fully specified? "
|
||||||
<< requestedIsFullySpecified;
|
<< requestedIsFullySpecified;
|
||||||
*_aidl_return = false;
|
*applied = false;
|
||||||
}
|
}
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
@ -1530,7 +1542,7 @@ bool Module::isMmapSupported() {
|
||||||
return mIsMmapSupported.value();
|
return mIsMmapSupported.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Module::populateConnectedDevicePort(AudioPort* audioPort) {
|
ndk::ScopedAStatus Module::populateConnectedDevicePort(AudioPort* audioPort, int32_t) {
|
||||||
if (audioPort->ext.getTag() != AudioPortExt::device) {
|
if (audioPort->ext.getTag() != AudioPortExt::device) {
|
||||||
LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
|
LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
|
|
|
@ -34,7 +34,7 @@ using aidl::android::media::audio::common::AudioProfile;
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core {
|
namespace aidl::android::hardware::audio::core {
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleAlsa::populateConnectedDevicePort(AudioPort* audioPort) {
|
ndk::ScopedAStatus ModuleAlsa::populateConnectedDevicePort(AudioPort* audioPort, int32_t) {
|
||||||
auto deviceProfile = alsa::getDeviceProfile(*audioPort);
|
auto deviceProfile = alsa::getDeviceProfile(*audioPort);
|
||||||
if (!deviceProfile.has_value()) {
|
if (!deviceProfile.has_value()) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "AHAL_BluetoothPortProxy"
|
#define LOG_TAG "AHAL_BluetoothAudioPort"
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
|
@ -254,12 +254,7 @@ bool BluetoothAudioPortAidl::inUse() const {
|
||||||
return (mCookie != ::aidl::android::hardware::bluetooth::audio::kObserversCookieUndefined);
|
return (mCookie != ::aidl::android::hardware::bluetooth::audio::kObserversCookieUndefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BluetoothAudioPortAidl::getPreferredDataIntervalUs(size_t* interval_us) const {
|
bool BluetoothAudioPortAidl::getPreferredDataIntervalUs(size_t& interval_us) const {
|
||||||
if (!interval_us) {
|
|
||||||
LOG(ERROR) << __func__ << ": bad input arg";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inUse()) {
|
if (!inUse()) {
|
||||||
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
||||||
return false;
|
return false;
|
||||||
|
@ -272,16 +267,11 @@ bool BluetoothAudioPortAidl::getPreferredDataIntervalUs(size_t* interval_us) con
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*interval_us = hal_audio_cfg.get<AudioConfiguration::pcmConfig>().dataIntervalUs;
|
interval_us = hal_audio_cfg.get<AudioConfiguration::pcmConfig>().dataIntervalUs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BluetoothAudioPortAidl::loadAudioConfig(PcmConfiguration* audio_cfg) const {
|
bool BluetoothAudioPortAidl::loadAudioConfig(PcmConfiguration& audio_cfg) {
|
||||||
if (!audio_cfg) {
|
|
||||||
LOG(ERROR) << __func__ << ": bad input arg";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inUse()) {
|
if (!inUse()) {
|
||||||
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
||||||
return false;
|
return false;
|
||||||
|
@ -293,15 +283,26 @@ bool BluetoothAudioPortAidl::loadAudioConfig(PcmConfiguration* audio_cfg) const
|
||||||
LOG(ERROR) << __func__ << ": unsupported audio cfg tag";
|
LOG(ERROR) << __func__ << ": unsupported audio cfg tag";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*audio_cfg = hal_audio_cfg.get<AudioConfiguration::pcmConfig>();
|
audio_cfg = hal_audio_cfg.get<AudioConfiguration::pcmConfig>();
|
||||||
LOG(VERBOSE) << __func__ << debugMessage() << ", state*=" << getState() << ", PcmConfig=["
|
LOG(VERBOSE) << __func__ << debugMessage() << ", state*=" << getState() << ", PcmConfig=["
|
||||||
<< audio_cfg->toString() << "]";
|
<< audio_cfg.toString() << "]";
|
||||||
if (audio_cfg->channelMode == ChannelMode::UNKNOWN) {
|
if (audio_cfg.channelMode == ChannelMode::UNKNOWN) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BluetoothAudioPortAidlOut::loadAudioConfig(PcmConfiguration& audio_cfg) {
|
||||||
|
if (!BluetoothAudioPortAidl::loadAudioConfig(audio_cfg)) return false;
|
||||||
|
// WAR to support Mono / 16 bits per sample as the Bluetooth stack requires
|
||||||
|
if (audio_cfg.channelMode == ChannelMode::MONO && audio_cfg.bitsPerSample == 16) {
|
||||||
|
mIsStereoToMono = true;
|
||||||
|
audio_cfg.channelMode = ChannelMode::STEREO;
|
||||||
|
LOG(INFO) << __func__ << ": force channels = to be AUDIO_CHANNEL_OUT_STEREO";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool BluetoothAudioPortAidl::standby() {
|
bool BluetoothAudioPortAidl::standby() {
|
||||||
if (!inUse()) {
|
if (!inUse()) {
|
||||||
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
LOG(ERROR) << __func__ << ": BluetoothAudioPortAidl is not in use";
|
||||||
|
@ -435,7 +436,7 @@ bool BluetoothAudioPortAidl::suspend() {
|
||||||
retval = condWaitState(BluetoothStreamState::SUSPENDING);
|
retval = condWaitState(BluetoothStreamState::SUSPENDING);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << __func__ << debugMessage() << ", state=" << getState()
|
LOG(ERROR) << __func__ << debugMessage() << ", state=" << getState()
|
||||||
<< " Hal fails";
|
<< " failure to suspend stream";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,25 @@
|
||||||
|
|
||||||
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::bluetooth::audio::ChannelMode;
|
||||||
|
using aidl::android::hardware::bluetooth::audio::PcmConfiguration;
|
||||||
|
using aidl::android::media::audio::common::AudioChannelLayout;
|
||||||
|
using aidl::android::media::audio::common::AudioConfigBase;
|
||||||
using aidl::android::media::audio::common::AudioDeviceDescription;
|
using aidl::android::media::audio::common::AudioDeviceDescription;
|
||||||
using aidl::android::media::audio::common::AudioDeviceType;
|
using aidl::android::media::audio::common::AudioDeviceType;
|
||||||
|
using aidl::android::media::audio::common::AudioFormatDescription;
|
||||||
|
using aidl::android::media::audio::common::AudioFormatType;
|
||||||
|
using aidl::android::media::audio::common::AudioIoFlags;
|
||||||
using aidl::android::media::audio::common::AudioOffloadInfo;
|
using aidl::android::media::audio::common::AudioOffloadInfo;
|
||||||
using aidl::android::media::audio::common::AudioPort;
|
using aidl::android::media::audio::common::AudioPort;
|
||||||
|
using aidl::android::media::audio::common::AudioPortConfig;
|
||||||
using aidl::android::media::audio::common::AudioPortExt;
|
using aidl::android::media::audio::common::AudioPortExt;
|
||||||
|
using aidl::android::media::audio::common::AudioProfile;
|
||||||
|
using aidl::android::media::audio::common::Int;
|
||||||
using aidl::android::media::audio::common::MicrophoneInfo;
|
using aidl::android::media::audio::common::MicrophoneInfo;
|
||||||
|
using aidl::android::media::audio::common::PcmType;
|
||||||
using android::bluetooth::audio::aidl::BluetoothAudioPortAidl;
|
using android::bluetooth::audio::aidl::BluetoothAudioPortAidl;
|
||||||
|
using android::bluetooth::audio::aidl::BluetoothAudioPortAidlIn;
|
||||||
using android::bluetooth::audio::aidl::BluetoothAudioPortAidlOut;
|
using android::bluetooth::audio::aidl::BluetoothAudioPortAidlOut;
|
||||||
|
|
||||||
// TODO(b/312265159) bluetooth audio should be in its own process
|
// TODO(b/312265159) bluetooth audio should be in its own process
|
||||||
|
@ -39,6 +51,35 @@ extern "C" binder_status_t createIBluetoothAudioProviderFactory();
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core {
|
namespace aidl::android::hardware::audio::core {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
PcmType pcmTypeFromBitsPerSample(int8_t bitsPerSample) {
|
||||||
|
if (bitsPerSample == 8)
|
||||||
|
return PcmType::UINT_8_BIT;
|
||||||
|
else if (bitsPerSample == 16)
|
||||||
|
return PcmType::INT_16_BIT;
|
||||||
|
else if (bitsPerSample == 24)
|
||||||
|
return PcmType::INT_24_BIT;
|
||||||
|
else if (bitsPerSample == 32)
|
||||||
|
return PcmType::INT_32_BIT;
|
||||||
|
ALOGE("Unsupported bitsPerSample: %d", bitsPerSample);
|
||||||
|
return PcmType::DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioChannelLayout channelLayoutFromChannelMode(ChannelMode mode) {
|
||||||
|
if (mode == ChannelMode::MONO) {
|
||||||
|
return AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
|
||||||
|
AudioChannelLayout::LAYOUT_MONO);
|
||||||
|
} else if (mode == ChannelMode::STEREO || mode == ChannelMode::DUALMONO) {
|
||||||
|
return AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
|
||||||
|
AudioChannelLayout::LAYOUT_STEREO);
|
||||||
|
}
|
||||||
|
ALOGE("Unsupported channel mode: %s", toString(mode).c_str());
|
||||||
|
return AudioChannelLayout{};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
ModuleBluetooth::ModuleBluetooth(std::unique_ptr<Module::Configuration>&& config)
|
ModuleBluetooth::ModuleBluetooth(std::unique_ptr<Module::Configuration>&& config)
|
||||||
: Module(Type::BLUETOOTH, std::move(config)) {
|
: Module(Type::BLUETOOTH, std::move(config)) {
|
||||||
// TODO(b/312265159) bluetooth audio should be in its own process
|
// TODO(b/312265159) bluetooth audio should be in its own process
|
||||||
|
@ -95,66 +136,130 @@ ndk::ScopedAStatus ModuleBluetooth::setMicMute(bool in_mute __unused) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleBluetooth::setAudioPortConfig(const AudioPortConfig& in_requested,
|
||||||
|
AudioPortConfig* out_suggested,
|
||||||
|
bool* _aidl_return) {
|
||||||
|
auto fillConfig = [this](const AudioPort& port, AudioPortConfig* config) {
|
||||||
|
if (port.ext.getTag() == AudioPortExt::device) {
|
||||||
|
CachedProxy proxy;
|
||||||
|
auto status = findOrCreateProxy(port, proxy);
|
||||||
|
if (status.isOk()) {
|
||||||
|
const auto& pcmConfig = proxy.pcmConfig;
|
||||||
|
LOG(DEBUG) << "setAudioPortConfig: suggesting port config from "
|
||||||
|
<< pcmConfig.toString();
|
||||||
|
const auto pcmType = pcmTypeFromBitsPerSample(pcmConfig.bitsPerSample);
|
||||||
|
const auto channelMask = channelLayoutFromChannelMode(pcmConfig.channelMode);
|
||||||
|
if (pcmType != PcmType::DEFAULT && channelMask != AudioChannelLayout{}) {
|
||||||
|
config->format =
|
||||||
|
AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType};
|
||||||
|
config->channelMask = channelMask;
|
||||||
|
config->sampleRate = Int{.value = pcmConfig.sampleRateHz};
|
||||||
|
config->flags = port.flags;
|
||||||
|
config->ext = port.ext;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return generateDefaultPortConfig(port, config);
|
||||||
|
};
|
||||||
|
return Module::setAudioPortConfigImpl(in_requested, fillConfig, out_suggested, _aidl_return);
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleBluetooth::checkAudioPatchEndpointsMatch(
|
||||||
|
const std::vector<AudioPortConfig*>& sources, const std::vector<AudioPortConfig*>& sinks) {
|
||||||
|
// Both sources and sinks must be non-empty, this is guaranteed by 'setAudioPatch'.
|
||||||
|
const bool isInput = sources[0]->ext.getTag() == AudioPortExt::device;
|
||||||
|
const int32_t devicePortId = isInput ? sources[0]->portId : sinks[0]->portId;
|
||||||
|
const auto proxyIt = mProxies.find(devicePortId);
|
||||||
|
if (proxyIt == mProxies.end()) return ndk::ScopedAStatus::ok();
|
||||||
|
const auto& pcmConfig = proxyIt->second.pcmConfig;
|
||||||
|
const AudioPortConfig* mixPortConfig = isInput ? sinks[0] : sources[0];
|
||||||
|
if (!StreamBluetooth::checkConfigParams(
|
||||||
|
pcmConfig, AudioConfigBase{.sampleRate = mixPortConfig->sampleRate->value,
|
||||||
|
.channelMask = *(mixPortConfig->channelMask),
|
||||||
|
.format = *(mixPortConfig->format)})) {
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
|
}
|
||||||
|
if (int32_t handle = mixPortConfig->ext.get<AudioPortExt::mix>().handle; handle > 0) {
|
||||||
|
mConnections.insert(std::pair(handle, devicePortId));
|
||||||
|
}
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleBluetooth::onExternalDeviceConnectionChanged(const AudioPort& audioPort,
|
||||||
|
bool connected) {
|
||||||
|
if (!connected) mProxies.erase(audioPort.id);
|
||||||
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleBluetooth::createInputStream(
|
ndk::ScopedAStatus ModuleBluetooth::createInputStream(
|
||||||
StreamContext&& context, const SinkMetadata& sinkMetadata,
|
StreamContext&& context, const SinkMetadata& sinkMetadata,
|
||||||
const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) {
|
const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) {
|
||||||
|
CachedProxy proxy;
|
||||||
|
RETURN_STATUS_IF_ERROR(fetchAndCheckProxy(context, proxy));
|
||||||
return createStreamInstance<StreamInBluetooth>(result, std::move(context), sinkMetadata,
|
return createStreamInstance<StreamInBluetooth>(result, std::move(context), sinkMetadata,
|
||||||
microphones, getBtProfileManagerHandles());
|
microphones, getBtProfileManagerHandles(),
|
||||||
|
proxy.ptr, proxy.pcmConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleBluetooth::createOutputStream(
|
ndk::ScopedAStatus ModuleBluetooth::createOutputStream(
|
||||||
StreamContext&& context, const SourceMetadata& sourceMetadata,
|
StreamContext&& context, const SourceMetadata& sourceMetadata,
|
||||||
const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) {
|
const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) {
|
||||||
|
CachedProxy proxy;
|
||||||
|
RETURN_STATUS_IF_ERROR(fetchAndCheckProxy(context, proxy));
|
||||||
return createStreamInstance<StreamOutBluetooth>(result, std::move(context), sourceMetadata,
|
return createStreamInstance<StreamOutBluetooth>(result, std::move(context), sourceMetadata,
|
||||||
offloadInfo, getBtProfileManagerHandles());
|
offloadInfo, getBtProfileManagerHandles(),
|
||||||
|
proxy.ptr, proxy.pcmConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleBluetooth::populateConnectedDevicePort(AudioPort* audioPort) {
|
ndk::ScopedAStatus ModuleBluetooth::populateConnectedDevicePort(AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) {
|
||||||
if (audioPort->ext.getTag() != AudioPortExt::device) {
|
if (audioPort->ext.getTag() != AudioPortExt::device) {
|
||||||
LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
|
LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
}
|
}
|
||||||
|
if (!::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::IsAidlAvailable()) {
|
||||||
|
LOG(ERROR) << __func__ << ": IBluetoothAudioProviderFactory AIDL service not available";
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
|
}
|
||||||
const auto& devicePort = audioPort->ext.get<AudioPortExt::device>();
|
const auto& devicePort = audioPort->ext.get<AudioPortExt::device>();
|
||||||
const auto& description = devicePort.device.type;
|
const auto& description = devicePort.device.type;
|
||||||
// Since the configuration of the BT module is static, there is nothing to populate here.
|
// This method must return an error when the device can not be connected.
|
||||||
// However, this method must return an error when the device can not be connected,
|
|
||||||
// this is determined by the status of BT profiles.
|
|
||||||
if (description.connection == AudioDeviceDescription::CONNECTION_BT_A2DP) {
|
if (description.connection == AudioDeviceDescription::CONNECTION_BT_A2DP) {
|
||||||
bool isA2dpEnabled = false;
|
bool isA2dpEnabled = false;
|
||||||
if (!!mBluetoothA2dp) {
|
if (!!mBluetoothA2dp) {
|
||||||
RETURN_STATUS_IF_ERROR((*mBluetoothA2dp).isEnabled(&isA2dpEnabled));
|
RETURN_STATUS_IF_ERROR((*mBluetoothA2dp).isEnabled(&isA2dpEnabled));
|
||||||
}
|
}
|
||||||
LOG(DEBUG) << __func__ << ": isA2dpEnabled: " << isA2dpEnabled;
|
LOG(DEBUG) << __func__ << ": isA2dpEnabled: " << isA2dpEnabled;
|
||||||
return isA2dpEnabled ? ndk::ScopedAStatus::ok()
|
if (!isA2dpEnabled) return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
: ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
|
||||||
} else if (description.connection == AudioDeviceDescription::CONNECTION_BT_LE) {
|
} else if (description.connection == AudioDeviceDescription::CONNECTION_BT_LE) {
|
||||||
bool isLeEnabled = false;
|
bool isLeEnabled = false;
|
||||||
if (!!mBluetoothLe) {
|
if (!!mBluetoothLe) {
|
||||||
RETURN_STATUS_IF_ERROR((*mBluetoothLe).isEnabled(&isLeEnabled));
|
RETURN_STATUS_IF_ERROR((*mBluetoothLe).isEnabled(&isLeEnabled));
|
||||||
}
|
}
|
||||||
LOG(DEBUG) << __func__ << ": isLeEnabled: " << isLeEnabled;
|
LOG(DEBUG) << __func__ << ": isLeEnabled: " << isLeEnabled;
|
||||||
return isLeEnabled ? ndk::ScopedAStatus::ok()
|
if (!isLeEnabled) return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
: ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
|
||||||
} else if (description.connection == AudioDeviceDescription::CONNECTION_WIRELESS &&
|
} else if (description.connection == AudioDeviceDescription::CONNECTION_WIRELESS &&
|
||||||
description.type == AudioDeviceType::OUT_HEARING_AID) {
|
description.type == AudioDeviceType::OUT_HEARING_AID) {
|
||||||
// Hearing aids can use a number of profiles, thus the only way to check
|
// Hearing aids can use a number of profiles, no single switch exists.
|
||||||
// connectivity is to try to talk to the BT HAL.
|
} else {
|
||||||
if (!::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
|
LOG(ERROR) << __func__ << ": unsupported device type: " << audioPort->toString();
|
||||||
IsAidlAvailable()) {
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
|
||||||
}
|
|
||||||
std::shared_ptr<BluetoothAudioPortAidl> proxy = std::shared_ptr<BluetoothAudioPortAidl>(
|
|
||||||
std::make_shared<BluetoothAudioPortAidlOut>());
|
|
||||||
if (proxy->registerPort(description)) {
|
|
||||||
LOG(DEBUG) << __func__ << ": registered hearing aid port";
|
|
||||||
proxy->unregisterPort();
|
|
||||||
return ndk::ScopedAStatus::ok();
|
|
||||||
}
|
|
||||||
LOG(DEBUG) << __func__ << ": failed to register hearing aid port";
|
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
|
||||||
}
|
}
|
||||||
LOG(ERROR) << __func__ << ": unsupported device type: " << audioPort->toString();
|
CachedProxy proxy;
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
RETURN_STATUS_IF_ERROR(createProxy(*audioPort, nextPortId, proxy));
|
||||||
|
// Since the device is already connected and configured by the BT stack, provide
|
||||||
|
// the current configuration instead of all possible profiles.
|
||||||
|
const auto& pcmConfig = proxy.pcmConfig;
|
||||||
|
audioPort->profiles.clear();
|
||||||
|
audioPort->profiles.push_back(
|
||||||
|
AudioProfile{.format = AudioFormatDescription{.type = AudioFormatType::PCM,
|
||||||
|
.pcm = pcmTypeFromBitsPerSample(
|
||||||
|
pcmConfig.bitsPerSample)},
|
||||||
|
.channelMasks = std::vector<AudioChannelLayout>(
|
||||||
|
{channelLayoutFromChannelMode(pcmConfig.channelMode)}),
|
||||||
|
.sampleRates = std::vector<int>({pcmConfig.sampleRateHz})});
|
||||||
|
LOG(DEBUG) << __func__ << ": " << audioPort->toString();
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleBluetooth::onMasterMuteChanged(bool) {
|
ndk::ScopedAStatus ModuleBluetooth::onMasterMuteChanged(bool) {
|
||||||
|
@ -167,4 +272,77 @@ ndk::ScopedAStatus ModuleBluetooth::onMasterVolumeChanged(float) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ModuleBluetooth::getNominalLatencyMs(const AudioPortConfig& portConfig) {
|
||||||
|
const auto connectionsIt = mConnections.find(portConfig.ext.get<AudioPortExt::mix>().handle);
|
||||||
|
if (connectionsIt != mConnections.end()) {
|
||||||
|
const auto proxyIt = mProxies.find(connectionsIt->second);
|
||||||
|
if (proxyIt != mProxies.end()) {
|
||||||
|
auto proxy = proxyIt->second.ptr;
|
||||||
|
size_t dataIntervalUs = 0;
|
||||||
|
if (!proxy->getPreferredDataIntervalUs(dataIntervalUs)) {
|
||||||
|
LOG(WARNING) << __func__ << ": could not fetch preferred data interval";
|
||||||
|
}
|
||||||
|
const bool isInput = portConfig.flags->getTag() == AudioIoFlags::input;
|
||||||
|
return isInput ? StreamInBluetooth::getNominalLatencyMs(dataIntervalUs)
|
||||||
|
: StreamOutBluetooth::getNominalLatencyMs(dataIntervalUs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG(ERROR) << __func__ << ": no connection or proxy found for " << portConfig.toString();
|
||||||
|
return Module::getNominalLatencyMs(portConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleBluetooth::createProxy(const AudioPort& audioPort, int32_t instancePortId,
|
||||||
|
CachedProxy& proxy) {
|
||||||
|
const bool isInput = audioPort.flags.getTag() == AudioIoFlags::input;
|
||||||
|
proxy.ptr = isInput ? std::shared_ptr<BluetoothAudioPortAidl>(
|
||||||
|
std::make_shared<BluetoothAudioPortAidlIn>())
|
||||||
|
: std::shared_ptr<BluetoothAudioPortAidl>(
|
||||||
|
std::make_shared<BluetoothAudioPortAidlOut>());
|
||||||
|
const auto& devicePort = audioPort.ext.get<AudioPortExt::device>();
|
||||||
|
if (const auto device = devicePort.device.type; !proxy.ptr->registerPort(device)) {
|
||||||
|
LOG(ERROR) << __func__ << ": failed to register BT port for " << device.toString();
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
|
}
|
||||||
|
if (!proxy.ptr->loadAudioConfig(proxy.pcmConfig)) {
|
||||||
|
LOG(ERROR) << __func__ << ": state=" << proxy.ptr->getState()
|
||||||
|
<< ", failed to load audio config";
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
|
}
|
||||||
|
mProxies.insert(std::pair(instancePortId, proxy));
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleBluetooth::fetchAndCheckProxy(const StreamContext& context,
|
||||||
|
CachedProxy& proxy) {
|
||||||
|
const auto connectionsIt = mConnections.find(context.getMixPortHandle());
|
||||||
|
if (connectionsIt != mConnections.end()) {
|
||||||
|
const auto proxyIt = mProxies.find(connectionsIt->second);
|
||||||
|
if (proxyIt != mProxies.end()) {
|
||||||
|
proxy = proxyIt->second;
|
||||||
|
mProxies.erase(proxyIt);
|
||||||
|
}
|
||||||
|
mConnections.erase(connectionsIt);
|
||||||
|
}
|
||||||
|
if (proxy.ptr != nullptr) {
|
||||||
|
if (!StreamBluetooth::checkConfigParams(
|
||||||
|
proxy.pcmConfig, AudioConfigBase{.sampleRate = context.getSampleRate(),
|
||||||
|
.channelMask = context.getChannelLayout(),
|
||||||
|
.format = context.getFormat()})) {
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Not having a proxy is OK, it may happen in VTS tests when streams are opened on unconnected
|
||||||
|
// mix ports.
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleBluetooth::findOrCreateProxy(const AudioPort& audioPort,
|
||||||
|
CachedProxy& proxy) {
|
||||||
|
if (auto proxyIt = mProxies.find(audioPort.id); proxyIt != mProxies.end()) {
|
||||||
|
proxy = proxyIt->second;
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
return createProxy(audioPort, audioPort.id, proxy);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aidl::android::hardware::audio::core
|
} // namespace aidl::android::hardware::audio::core
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOG_TAG "AHAL_StreamBluetooth"
|
#include <algorithm>
|
||||||
|
|
||||||
|
#define LOG_TAG "AHAL_StreamBluetooth"
|
||||||
#include <Utils.h>
|
#include <Utils.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <audio_utils/clock.h>
|
#include <audio_utils/clock.h>
|
||||||
|
@ -31,6 +32,7 @@ using aidl::android::hardware::bluetooth::audio::ChannelMode;
|
||||||
using aidl::android::hardware::bluetooth::audio::PcmConfiguration;
|
using aidl::android::hardware::bluetooth::audio::PcmConfiguration;
|
||||||
using aidl::android::hardware::bluetooth::audio::PresentationPosition;
|
using aidl::android::hardware::bluetooth::audio::PresentationPosition;
|
||||||
using aidl::android::media::audio::common::AudioChannelLayout;
|
using aidl::android::media::audio::common::AudioChannelLayout;
|
||||||
|
using aidl::android::media::audio::common::AudioConfigBase;
|
||||||
using aidl::android::media::audio::common::AudioDevice;
|
using aidl::android::media::audio::common::AudioDevice;
|
||||||
using aidl::android::media::audio::common::AudioDeviceAddress;
|
using aidl::android::media::audio::common::AudioDeviceAddress;
|
||||||
using aidl::android::media::audio::common::AudioFormatDescription;
|
using aidl::android::media::audio::common::AudioFormatDescription;
|
||||||
|
@ -48,51 +50,33 @@ namespace aidl::android::hardware::audio::core {
|
||||||
constexpr int kBluetoothDefaultInputBufferMs = 20;
|
constexpr int kBluetoothDefaultInputBufferMs = 20;
|
||||||
constexpr int kBluetoothDefaultOutputBufferMs = 10;
|
constexpr int kBluetoothDefaultOutputBufferMs = 10;
|
||||||
// constexpr int kBluetoothSpatializerOutputBufferMs = 10;
|
// constexpr int kBluetoothSpatializerOutputBufferMs = 10;
|
||||||
|
constexpr int kBluetoothDefaultRemoteDelayMs = 200;
|
||||||
|
|
||||||
// pcm configuration params are not really used by the module
|
|
||||||
StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadata,
|
StreamBluetooth::StreamBluetooth(StreamContext* context, const Metadata& metadata,
|
||||||
ModuleBluetooth::BtProfileHandles&& btHandles)
|
ModuleBluetooth::BtProfileHandles&& btHandles,
|
||||||
|
const std::shared_ptr<BluetoothAudioPortAidl>& btDeviceProxy,
|
||||||
|
const PcmConfiguration& pcmConfig)
|
||||||
: StreamCommonImpl(context, metadata),
|
: StreamCommonImpl(context, metadata),
|
||||||
mSampleRate(getContext().getSampleRate()),
|
|
||||||
mChannelLayout(getContext().getChannelLayout()),
|
|
||||||
mFormat(getContext().getFormat()),
|
|
||||||
mFrameSizeBytes(getContext().getFrameSize()),
|
mFrameSizeBytes(getContext().getFrameSize()),
|
||||||
mIsInput(isInput(metadata)),
|
mIsInput(isInput(metadata)),
|
||||||
mBluetoothA2dp(std::move(std::get<ModuleBluetooth::BtInterface::BTA2DP>(btHandles))),
|
mBluetoothA2dp(std::move(std::get<ModuleBluetooth::BtInterface::BTA2DP>(btHandles))),
|
||||||
mBluetoothLe(std::move(std::get<ModuleBluetooth::BtInterface::BTLE>(btHandles))) {
|
mBluetoothLe(std::move(std::get<ModuleBluetooth::BtInterface::BTLE>(btHandles))),
|
||||||
mPreferredDataIntervalUs =
|
mPreferredDataIntervalUs(pcmConfig.dataIntervalUs != 0
|
||||||
(mIsInput ? kBluetoothDefaultInputBufferMs : kBluetoothDefaultOutputBufferMs) * 1000;
|
? pcmConfig.dataIntervalUs
|
||||||
mPreferredFrameCount = frameCountFromDurationUs(mPreferredDataIntervalUs, mSampleRate);
|
: (mIsInput ? kBluetoothDefaultInputBufferMs
|
||||||
mIsInitialized = false;
|
: kBluetoothDefaultOutputBufferMs) *
|
||||||
mIsReadyToClose = false;
|
1000),
|
||||||
}
|
mPreferredFrameCount(
|
||||||
|
frameCountFromDurationUs(mPreferredDataIntervalUs, pcmConfig.sampleRateHz)),
|
||||||
|
mBtDeviceProxy(btDeviceProxy) {}
|
||||||
|
|
||||||
::android::status_t StreamBluetooth::init() {
|
::android::status_t StreamBluetooth::init() {
|
||||||
return ::android::OK; // defering this till we get AudioDeviceDescription
|
|
||||||
}
|
|
||||||
|
|
||||||
const StreamCommonInterface::ConnectedDevices& StreamBluetooth::getConnectedDevices() const {
|
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
return StreamCommonImpl::getConnectedDevices();
|
if (mBtDeviceProxy == nullptr) {
|
||||||
}
|
// This is a normal situation in VTS tests.
|
||||||
|
LOG(INFO) << __func__ << ": no BT HAL proxy, stream is non-functional";
|
||||||
ndk::ScopedAStatus StreamBluetooth::setConnectedDevices(
|
|
||||||
const std::vector<AudioDevice>& connectedDevices) {
|
|
||||||
if (mIsInput && connectedDevices.size() > 1) {
|
|
||||||
LOG(ERROR) << __func__ << ": wrong device size(" << connectedDevices.size()
|
|
||||||
<< ") for input stream";
|
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
|
||||||
}
|
}
|
||||||
for (const auto& connectedDevice : connectedDevices) {
|
return ::android::OK;
|
||||||
if (connectedDevice.address.getTag() != AudioDeviceAddress::mac) {
|
|
||||||
LOG(ERROR) << __func__ << ": bad device address" << connectedDevice.address.toString();
|
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::lock_guard guard(mLock);
|
|
||||||
RETURN_STATUS_IF_ERROR(StreamCommonImpl::setConnectedDevices(connectedDevices));
|
|
||||||
mIsInitialized = false; // updated connected device list, need initialization
|
|
||||||
return ndk::ScopedAStatus::ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t StreamBluetooth::drain(StreamDescriptor::DrainMode) {
|
::android::status_t StreamBluetooth::drain(StreamDescriptor::DrainMode) {
|
||||||
|
@ -112,167 +96,111 @@ ndk::ScopedAStatus StreamBluetooth::setConnectedDevices(
|
||||||
::android::status_t StreamBluetooth::transfer(void* buffer, size_t frameCount,
|
::android::status_t StreamBluetooth::transfer(void* buffer, size_t frameCount,
|
||||||
size_t* actualFrameCount, int32_t* latencyMs) {
|
size_t* actualFrameCount, int32_t* latencyMs) {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
if (!mIsInitialized || mIsReadyToClose) {
|
if (mBtDeviceProxy == nullptr || mBtDeviceProxy->getState() == BluetoothStreamState::DISABLED) {
|
||||||
// 'setConnectedDevices' has been called or stream is ready to close, so no transfers
|
|
||||||
*actualFrameCount = 0;
|
*actualFrameCount = 0;
|
||||||
*latencyMs = StreamDescriptor::LATENCY_UNKNOWN;
|
*latencyMs = StreamDescriptor::LATENCY_UNKNOWN;
|
||||||
return ::android::OK;
|
return ::android::OK;
|
||||||
}
|
}
|
||||||
*actualFrameCount = 0;
|
*actualFrameCount = 0;
|
||||||
*latencyMs = 0;
|
*latencyMs = 0;
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
if (!mBtDeviceProxy->start()) {
|
||||||
if (!proxy->start()) {
|
LOG(ERROR) << __func__ << ": state= " << mBtDeviceProxy->getState() << " failed to start";
|
||||||
LOG(ERROR) << __func__ << ": state = " << proxy->getState() << " failed to start ";
|
return -EIO;
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
const size_t fc = std::min(frameCount, mPreferredFrameCount);
|
|
||||||
const size_t bytesToTransfer = fc * mFrameSizeBytes;
|
|
||||||
if (mIsInput) {
|
|
||||||
const size_t totalRead = proxy->readData(buffer, bytesToTransfer);
|
|
||||||
*actualFrameCount = std::max(*actualFrameCount, totalRead / mFrameSizeBytes);
|
|
||||||
} else {
|
|
||||||
const size_t totalWrite = proxy->writeData(buffer, bytesToTransfer);
|
|
||||||
*actualFrameCount = std::max(*actualFrameCount, totalWrite / mFrameSizeBytes);
|
|
||||||
}
|
|
||||||
PresentationPosition presentation_position;
|
|
||||||
if (!proxy->getPresentationPosition(presentation_position)) {
|
|
||||||
LOG(ERROR) << __func__ << ": getPresentationPosition returned error ";
|
|
||||||
return ::android::UNKNOWN_ERROR;
|
|
||||||
}
|
|
||||||
*latencyMs =
|
|
||||||
std::max(*latencyMs, (int32_t)(presentation_position.remoteDeviceAudioDelayNanos /
|
|
||||||
NANOS_PER_MILLISECOND));
|
|
||||||
}
|
}
|
||||||
|
const size_t fc = std::min(frameCount, mPreferredFrameCount);
|
||||||
|
const size_t bytesToTransfer = fc * mFrameSizeBytes;
|
||||||
|
if (mIsInput) {
|
||||||
|
const size_t totalRead = mBtDeviceProxy->readData(buffer, bytesToTransfer);
|
||||||
|
*actualFrameCount = std::max(*actualFrameCount, totalRead / mFrameSizeBytes);
|
||||||
|
} else {
|
||||||
|
const size_t totalWrite = mBtDeviceProxy->writeData(buffer, bytesToTransfer);
|
||||||
|
*actualFrameCount = std::max(*actualFrameCount, totalWrite / mFrameSizeBytes);
|
||||||
|
}
|
||||||
|
PresentationPosition presentation_position;
|
||||||
|
if (!mBtDeviceProxy->getPresentationPosition(presentation_position)) {
|
||||||
|
presentation_position.remoteDeviceAudioDelayNanos =
|
||||||
|
kBluetoothDefaultRemoteDelayMs * NANOS_PER_MILLISECOND;
|
||||||
|
LOG(WARNING) << __func__ << ": getPresentationPosition failed, latency info is unavailable";
|
||||||
|
}
|
||||||
|
// TODO(b/317117580): incorporate logic from
|
||||||
|
// packages/modules/Bluetooth/system/audio_bluetooth_hw/stream_apis.cc
|
||||||
|
// out_calculate_feeding_delay_ms / in_calculate_starving_delay_ms
|
||||||
|
*latencyMs = std::max(*latencyMs, (int32_t)(presentation_position.remoteDeviceAudioDelayNanos /
|
||||||
|
NANOS_PER_MILLISECOND));
|
||||||
return ::android::OK;
|
return ::android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t StreamBluetooth::initialize() {
|
// static
|
||||||
if (!::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::IsAidlAvailable()) {
|
bool StreamBluetooth::checkConfigParams(const PcmConfiguration& pcmConfig,
|
||||||
LOG(ERROR) << __func__ << ": IBluetoothAudioProviderFactory service not available";
|
const AudioConfigBase& config) {
|
||||||
return ::android::UNKNOWN_ERROR;
|
if ((int)config.sampleRate != pcmConfig.sampleRateHz) {
|
||||||
}
|
LOG(ERROR) << __func__ << ": sample rate mismatch, stream value=" << config.sampleRate
|
||||||
if (StreamCommonImpl::getConnectedDevices().empty()) {
|
<< ", BT HAL value=" << pcmConfig.sampleRateHz;
|
||||||
LOG(ERROR) << __func__ << ", has no connected devices";
|
|
||||||
return ::android::NO_INIT;
|
|
||||||
}
|
|
||||||
// unregister older proxies (if any)
|
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
|
||||||
proxy->stop();
|
|
||||||
proxy->unregisterPort();
|
|
||||||
}
|
|
||||||
mBtDeviceProxies.clear();
|
|
||||||
for (auto it = StreamCommonImpl::getConnectedDevices().begin();
|
|
||||||
it != StreamCommonImpl::getConnectedDevices().end(); ++it) {
|
|
||||||
std::shared_ptr<BluetoothAudioPortAidl> proxy =
|
|
||||||
mIsInput ? std::shared_ptr<BluetoothAudioPortAidl>(
|
|
||||||
std::make_shared<BluetoothAudioPortAidlIn>())
|
|
||||||
: std::shared_ptr<BluetoothAudioPortAidl>(
|
|
||||||
std::make_shared<BluetoothAudioPortAidlOut>());
|
|
||||||
if (proxy->registerPort(it->type)) {
|
|
||||||
LOG(ERROR) << __func__ << ": cannot init HAL";
|
|
||||||
return ::android::UNKNOWN_ERROR;
|
|
||||||
}
|
|
||||||
PcmConfiguration config;
|
|
||||||
if (!proxy->loadAudioConfig(&config)) {
|
|
||||||
LOG(ERROR) << __func__ << ": state=" << proxy->getState()
|
|
||||||
<< " failed to get audio config";
|
|
||||||
return ::android::UNKNOWN_ERROR;
|
|
||||||
}
|
|
||||||
// TODO: Ensure minimum duration for spatialized output?
|
|
||||||
// WAR to support Mono / 16 bits per sample as the Bluetooth stack required
|
|
||||||
if (!mIsInput && config.channelMode == ChannelMode::MONO && config.bitsPerSample == 16) {
|
|
||||||
proxy->forcePcmStereoToMono(true);
|
|
||||||
config.channelMode = ChannelMode::STEREO;
|
|
||||||
LOG(INFO) << __func__ << ": force channels = to be AUDIO_CHANNEL_OUT_STEREO";
|
|
||||||
}
|
|
||||||
if (!checkConfigParams(config)) {
|
|
||||||
LOG(ERROR) << __func__ << " checkConfigParams failed";
|
|
||||||
return ::android::UNKNOWN_ERROR;
|
|
||||||
}
|
|
||||||
mBtDeviceProxies.push_back(std::move(proxy));
|
|
||||||
}
|
|
||||||
mIsInitialized = true;
|
|
||||||
return ::android::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StreamBluetooth::checkConfigParams(
|
|
||||||
::aidl::android::hardware::bluetooth::audio::PcmConfiguration& config) {
|
|
||||||
if ((int)mSampleRate != config.sampleRateHz) {
|
|
||||||
LOG(ERROR) << __func__ << ": Sample Rate mismatch, stream val = " << mSampleRate
|
|
||||||
<< " hal val = " << config.sampleRateHz;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto channelCount = aidl::android::hardware::audio::common::getChannelCount(mChannelLayout);
|
const auto channelCount =
|
||||||
if ((config.channelMode == ChannelMode::MONO && channelCount != 1) ||
|
aidl::android::hardware::audio::common::getChannelCount(config.channelMask);
|
||||||
(config.channelMode == ChannelMode::STEREO && channelCount != 2)) {
|
if ((pcmConfig.channelMode == ChannelMode::MONO && channelCount != 1) ||
|
||||||
LOG(ERROR) << __func__ << ": Channel count mismatch, stream val = " << channelCount
|
(pcmConfig.channelMode == ChannelMode::STEREO && channelCount != 2)) {
|
||||||
<< " hal val = " << toString(config.channelMode);
|
LOG(ERROR) << __func__ << ": Channel count mismatch, stream value=" << channelCount
|
||||||
|
<< ", BT HAL value=" << toString(pcmConfig.channelMode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mFormat.type != AudioFormatType::PCM) {
|
if (config.format.type != AudioFormatType::PCM) {
|
||||||
LOG(ERROR) << __func__ << ": unexpected format type "
|
LOG(ERROR) << __func__
|
||||||
<< aidl::android::media::audio::common::toString(mFormat.type);
|
<< ": unexpected stream format type: " << toString(config.format.type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int8_t bps = aidl::android::hardware::audio::common::getPcmSampleSizeInBytes(mFormat.pcm) * 8;
|
const int8_t bitsPerSample =
|
||||||
if (bps != config.bitsPerSample) {
|
aidl::android::hardware::audio::common::getPcmSampleSizeInBytes(config.format.pcm) * 8;
|
||||||
LOG(ERROR) << __func__ << ": bits per sample mismatch, stream val = " << bps
|
if (bitsPerSample != pcmConfig.bitsPerSample) {
|
||||||
<< " hal val = " << config.bitsPerSample;
|
LOG(ERROR) << __func__ << ": bits per sample mismatch, stream value=" << bitsPerSample
|
||||||
|
<< ", BT HAL value=" << pcmConfig.bitsPerSample;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config.dataIntervalUs > 0) {
|
|
||||||
mPreferredDataIntervalUs =
|
|
||||||
std::min((int32_t)mPreferredDataIntervalUs, config.dataIntervalUs);
|
|
||||||
mPreferredFrameCount = frameCountFromDurationUs(mPreferredDataIntervalUs, mSampleRate);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamBluetooth::prepareToClose() {
|
ndk::ScopedAStatus StreamBluetooth::prepareToClose() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
mIsReadyToClose = true;
|
if (mBtDeviceProxy != nullptr) {
|
||||||
|
if (mBtDeviceProxy->getState() != BluetoothStreamState::DISABLED) {
|
||||||
|
mBtDeviceProxy->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t StreamBluetooth::standby() {
|
::android::status_t StreamBluetooth::standby() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
if (!mIsInitialized) {
|
if (mBtDeviceProxy != nullptr) mBtDeviceProxy->suspend();
|
||||||
if (auto status = initialize(); status != ::android::OK) return status;
|
|
||||||
}
|
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
|
||||||
if (!proxy->suspend()) {
|
|
||||||
LOG(ERROR) << __func__ << ": state = " << proxy->getState() << " failed to stand by ";
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ::android::OK;
|
return ::android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t StreamBluetooth::start() {
|
::android::status_t StreamBluetooth::start() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
if (!mIsInitialized) return initialize();
|
if (mBtDeviceProxy != nullptr) mBtDeviceProxy->start();
|
||||||
return ::android::OK;
|
return ::android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamBluetooth::shutdown() {
|
void StreamBluetooth::shutdown() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
if (mBtDeviceProxy != nullptr) {
|
||||||
proxy->stop();
|
mBtDeviceProxy->stop();
|
||||||
proxy->unregisterPort();
|
mBtDeviceProxy = nullptr;
|
||||||
}
|
}
|
||||||
mBtDeviceProxies.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamBluetooth::updateMetadataCommon(const Metadata& metadata) {
|
ndk::ScopedAStatus StreamBluetooth::updateMetadataCommon(const Metadata& metadata) {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
if (!mIsInitialized) return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
if (mBtDeviceProxy == nullptr) {
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
if (isInput(metadata)) {
|
if (isInput(metadata)) {
|
||||||
isOk = mBtDeviceProxies[0]->updateSinkMetadata(std::get<SinkMetadata>(metadata));
|
isOk = mBtDeviceProxy->updateSinkMetadata(std::get<SinkMetadata>(metadata));
|
||||||
} else {
|
} else {
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
isOk = mBtDeviceProxy->updateSourceMetadata(std::get<SourceMetadata>(metadata));
|
||||||
if (!proxy->updateSourceMetadata(std::get<SourceMetadata>(metadata))) isOk = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return isOk ? ndk::ScopedAStatus::ok()
|
return isOk ? ndk::ScopedAStatus::ok()
|
||||||
: ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
: ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
|
@ -280,7 +208,6 @@ ndk::ScopedAStatus StreamBluetooth::updateMetadataCommon(const Metadata& metadat
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamBluetooth::bluetoothParametersUpdated() {
|
ndk::ScopedAStatus StreamBluetooth::bluetoothParametersUpdated() {
|
||||||
if (mIsInput) {
|
if (mIsInput) {
|
||||||
LOG(WARNING) << __func__ << ": not handled";
|
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
auto applyParam = [](const std::shared_ptr<BluetoothAudioPortAidl>& proxy,
|
auto applyParam = [](const std::shared_ptr<BluetoothAudioPortAidl>& proxy,
|
||||||
|
@ -297,15 +224,10 @@ ndk::ScopedAStatus StreamBluetooth::bluetoothParametersUpdated() {
|
||||||
bool hasLeParam, enableLe;
|
bool hasLeParam, enableLe;
|
||||||
auto btLe = mBluetoothLe.lock();
|
auto btLe = mBluetoothLe.lock();
|
||||||
hasLeParam = btLe != nullptr && btLe->isEnabled(&enableLe).isOk();
|
hasLeParam = btLe != nullptr && btLe->isEnabled(&enableLe).isOk();
|
||||||
std::unique_lock lock(mLock);
|
std::lock_guard guard(mLock);
|
||||||
::android::base::ScopedLockAssertion lock_assertion(mLock);
|
if (mBtDeviceProxy != nullptr) {
|
||||||
if (!mIsInitialized) {
|
if ((hasA2dpParam && mBtDeviceProxy->isA2dp() && !applyParam(mBtDeviceProxy, enableA2dp)) ||
|
||||||
LOG(WARNING) << __func__ << ": init not done";
|
(hasLeParam && mBtDeviceProxy->isLeAudio() && !applyParam(mBtDeviceProxy, enableLe))) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
|
|
||||||
}
|
|
||||||
for (auto proxy : mBtDeviceProxies) {
|
|
||||||
if ((hasA2dpParam && proxy->isA2dp() && !applyParam(proxy, enableA2dp)) ||
|
|
||||||
(hasLeParam && proxy->isLeAudio() && !applyParam(proxy, enableLe))) {
|
|
||||||
LOG(DEBUG) << __func__ << ": applyParam failed";
|
LOG(DEBUG) << __func__ << ": applyParam failed";
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
@ -313,11 +235,20 @@ ndk::ScopedAStatus StreamBluetooth::bluetoothParametersUpdated() {
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
int32_t StreamInBluetooth::getNominalLatencyMs(size_t dataIntervalUs) {
|
||||||
|
if (dataIntervalUs == 0) dataIntervalUs = kBluetoothDefaultInputBufferMs * 1000LL;
|
||||||
|
return dataIntervalUs / 1000LL;
|
||||||
|
}
|
||||||
|
|
||||||
StreamInBluetooth::StreamInBluetooth(StreamContext&& context, const SinkMetadata& sinkMetadata,
|
StreamInBluetooth::StreamInBluetooth(StreamContext&& context, const SinkMetadata& sinkMetadata,
|
||||||
const std::vector<MicrophoneInfo>& microphones,
|
const std::vector<MicrophoneInfo>& microphones,
|
||||||
ModuleBluetooth::BtProfileHandles&& btProfileHandles)
|
ModuleBluetooth::BtProfileHandles&& btProfileHandles,
|
||||||
|
const std::shared_ptr<BluetoothAudioPortAidl>& btDeviceProxy,
|
||||||
|
const PcmConfiguration& pcmConfig)
|
||||||
: StreamIn(std::move(context), microphones),
|
: StreamIn(std::move(context), microphones),
|
||||||
StreamBluetooth(&mContextInstance, sinkMetadata, std::move(btProfileHandles)) {}
|
StreamBluetooth(&mContextInstance, sinkMetadata, std::move(btProfileHandles), btDeviceProxy,
|
||||||
|
pcmConfig) {}
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamInBluetooth::getActiveMicrophones(
|
ndk::ScopedAStatus StreamInBluetooth::getActiveMicrophones(
|
||||||
std::vector<MicrophoneDynamicInfo>* _aidl_return __unused) {
|
std::vector<MicrophoneDynamicInfo>* _aidl_return __unused) {
|
||||||
|
@ -325,11 +256,20 @@ ndk::ScopedAStatus StreamInBluetooth::getActiveMicrophones(
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
int32_t StreamOutBluetooth::getNominalLatencyMs(size_t dataIntervalUs) {
|
||||||
|
if (dataIntervalUs == 0) dataIntervalUs = kBluetoothDefaultOutputBufferMs * 1000LL;
|
||||||
|
return dataIntervalUs / 1000LL;
|
||||||
|
}
|
||||||
|
|
||||||
StreamOutBluetooth::StreamOutBluetooth(StreamContext&& context,
|
StreamOutBluetooth::StreamOutBluetooth(StreamContext&& context,
|
||||||
const SourceMetadata& sourceMetadata,
|
const SourceMetadata& sourceMetadata,
|
||||||
const std::optional<AudioOffloadInfo>& offloadInfo,
|
const std::optional<AudioOffloadInfo>& offloadInfo,
|
||||||
ModuleBluetooth::BtProfileHandles&& btProfileHandles)
|
ModuleBluetooth::BtProfileHandles&& btProfileHandles,
|
||||||
|
const std::shared_ptr<BluetoothAudioPortAidl>& btDeviceProxy,
|
||||||
|
const PcmConfiguration& pcmConfig)
|
||||||
: StreamOut(std::move(context), offloadInfo),
|
: StreamOut(std::move(context), offloadInfo),
|
||||||
StreamBluetooth(&mContextInstance, sourceMetadata, std::move(btProfileHandles)) {}
|
StreamBluetooth(&mContextInstance, sourceMetadata, std::move(btProfileHandles), btDeviceProxy,
|
||||||
|
pcmConfig) {}
|
||||||
|
|
||||||
} // namespace aidl::android::hardware::audio::core
|
} // namespace aidl::android::hardware::audio::core
|
||||||
|
|
|
@ -73,12 +73,7 @@ class BluetoothAudioPort {
|
||||||
* Bluetooth stack
|
* Bluetooth stack
|
||||||
*/
|
*/
|
||||||
virtual bool loadAudioConfig(
|
virtual bool loadAudioConfig(
|
||||||
::aidl::android::hardware::bluetooth::audio::PcmConfiguration*) const = 0;
|
::aidl::android::hardware::bluetooth::audio::PcmConfiguration&) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* WAR to support Mono mode / 16 bits per sample
|
|
||||||
*/
|
|
||||||
virtual void forcePcmStereoToMono(bool) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the Audio framework / HAL wants to change the stream state, it invokes
|
* When the Audio framework / HAL wants to change the stream state, it invokes
|
||||||
|
@ -145,7 +140,7 @@ class BluetoothAudioPort {
|
||||||
|
|
||||||
virtual bool isLeAudio() const = 0;
|
virtual bool isLeAudio() const = 0;
|
||||||
|
|
||||||
virtual bool getPreferredDataIntervalUs(size_t*) const = 0;
|
virtual bool getPreferredDataIntervalUs(size_t&) const = 0;
|
||||||
|
|
||||||
virtual size_t writeData(const void*, size_t) const { return 0; }
|
virtual size_t writeData(const void*, size_t) const { return 0; }
|
||||||
|
|
||||||
|
@ -162,10 +157,8 @@ class BluetoothAudioPortAidl : public BluetoothAudioPort {
|
||||||
|
|
||||||
void unregisterPort() override;
|
void unregisterPort() override;
|
||||||
|
|
||||||
bool loadAudioConfig(::aidl::android::hardware::bluetooth::audio::PcmConfiguration* audio_cfg)
|
bool loadAudioConfig(
|
||||||
const override;
|
::aidl::android::hardware::bluetooth::audio::PcmConfiguration& audio_cfg) override;
|
||||||
|
|
||||||
void forcePcmStereoToMono(bool force) override { mIsStereoToMono = force; }
|
|
||||||
|
|
||||||
bool standby() override;
|
bool standby() override;
|
||||||
bool start() override;
|
bool start() override;
|
||||||
|
@ -193,7 +186,7 @@ class BluetoothAudioPortAidl : public BluetoothAudioPort {
|
||||||
|
|
||||||
bool isLeAudio() const override;
|
bool isLeAudio() const override;
|
||||||
|
|
||||||
bool getPreferredDataIntervalUs(size_t* interval_us) const override;
|
bool getPreferredDataIntervalUs(size_t& interval_us) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t mCookie;
|
uint16_t mCookie;
|
||||||
|
@ -228,6 +221,9 @@ class BluetoothAudioPortAidl : public BluetoothAudioPort {
|
||||||
|
|
||||||
class BluetoothAudioPortAidlOut : public BluetoothAudioPortAidl {
|
class BluetoothAudioPortAidlOut : public BluetoothAudioPortAidl {
|
||||||
public:
|
public:
|
||||||
|
bool loadAudioConfig(
|
||||||
|
::aidl::android::hardware::bluetooth::audio::PcmConfiguration& audio_cfg) override;
|
||||||
|
|
||||||
// The audio data path to the Bluetooth stack (Software encoding)
|
// The audio data path to the Bluetooth stack (Software encoding)
|
||||||
size_t writeData(const void* buffer, size_t bytes) const override;
|
size_t writeData(const void* buffer, size_t bytes) const override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -188,7 +189,7 @@ class Module : public BnModule {
|
||||||
// If the module is unable to populate the connected device port correctly, the returned error
|
// If the module is unable to populate the connected device port correctly, the returned error
|
||||||
// code must correspond to the errors of `IModule.connectedExternalDevice` method.
|
// code must correspond to the errors of `IModule.connectedExternalDevice` method.
|
||||||
virtual ndk::ScopedAStatus populateConnectedDevicePort(
|
virtual ndk::ScopedAStatus populateConnectedDevicePort(
|
||||||
::aidl::android::media::audio::common::AudioPort* audioPort);
|
::aidl::android::media::audio::common::AudioPort* audioPort, int32_t nextPortId);
|
||||||
// If the module finds that the patch endpoints configurations are not matched, the returned
|
// If the module finds that the patch endpoints configurations are not matched, the returned
|
||||||
// error code must correspond to the errors of `IModule.setAudioPatch` method.
|
// error code must correspond to the errors of `IModule.setAudioPatch` method.
|
||||||
virtual ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
virtual ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
||||||
|
@ -210,6 +211,7 @@ class Module : public BnModule {
|
||||||
const int32_t rawSizeFrames =
|
const int32_t rawSizeFrames =
|
||||||
aidl::android::hardware::audio::common::frameCountFromDurationMs(latencyMs,
|
aidl::android::hardware::audio::common::frameCountFromDurationMs(latencyMs,
|
||||||
sampleRateHz);
|
sampleRateHz);
|
||||||
|
if (latencyMs >= 5) return rawSizeFrames;
|
||||||
int32_t powerOf2 = 1;
|
int32_t powerOf2 = 1;
|
||||||
while (powerOf2 < rawSizeFrames) powerOf2 <<= 1;
|
while (powerOf2 < rawSizeFrames) powerOf2 <<= 1;
|
||||||
return powerOf2;
|
return powerOf2;
|
||||||
|
@ -227,12 +229,16 @@ class Module : public BnModule {
|
||||||
std::set<int32_t> findConnectedPortConfigIds(int32_t portConfigId);
|
std::set<int32_t> findConnectedPortConfigIds(int32_t portConfigId);
|
||||||
ndk::ScopedAStatus findPortIdForNewStream(
|
ndk::ScopedAStatus findPortIdForNewStream(
|
||||||
int32_t in_portConfigId, ::aidl::android::media::audio::common::AudioPort** port);
|
int32_t in_portConfigId, ::aidl::android::media::audio::common::AudioPort** port);
|
||||||
|
// Note: does not assign an ID to the config.
|
||||||
|
bool generateDefaultPortConfig(const ::aidl::android::media::audio::common::AudioPort& port,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig* config);
|
||||||
std::vector<AudioRoute*> getAudioRoutesForAudioPortImpl(int32_t portId);
|
std::vector<AudioRoute*> getAudioRoutesForAudioPortImpl(int32_t portId);
|
||||||
Configuration& getConfig();
|
Configuration& getConfig();
|
||||||
const ConnectedDevicePorts& getConnectedDevicePorts() const { return mConnectedDevicePorts; }
|
const ConnectedDevicePorts& getConnectedDevicePorts() const { return mConnectedDevicePorts; }
|
||||||
bool getMasterMute() const { return mMasterMute; }
|
bool getMasterMute() const { return mMasterMute; }
|
||||||
bool getMasterVolume() const { return mMasterVolume; }
|
bool getMasterVolume() const { return mMasterVolume; }
|
||||||
bool getMicMute() const { return mMicMute; }
|
bool getMicMute() const { return mMicMute; }
|
||||||
|
const ModuleDebug& getModuleDebug() const { return mDebug; }
|
||||||
const Patches& getPatches() const { return mPatches; }
|
const Patches& getPatches() const { return mPatches; }
|
||||||
std::set<int32_t> getRoutableAudioPortIds(int32_t portId,
|
std::set<int32_t> getRoutableAudioPortIds(int32_t portId,
|
||||||
std::vector<AudioRoute*>* routes = nullptr);
|
std::vector<AudioRoute*>* routes = nullptr);
|
||||||
|
@ -243,6 +249,12 @@ class Module : public BnModule {
|
||||||
template <typename C>
|
template <typename C>
|
||||||
std::set<int32_t> portIdsFromPortConfigIds(C portConfigIds);
|
std::set<int32_t> portIdsFromPortConfigIds(C portConfigIds);
|
||||||
void registerPatch(const AudioPatch& patch);
|
void registerPatch(const AudioPatch& patch);
|
||||||
|
ndk::ScopedAStatus setAudioPortConfigImpl(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPortConfig& in_requested,
|
||||||
|
const std::function<bool(const ::aidl::android::media::audio::common::AudioPort& port,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig*
|
||||||
|
config)>& fillPortConfig,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig* out_suggested, bool* applied);
|
||||||
ndk::ScopedAStatus updateStreamsConnectedState(const AudioPatch& oldPatch,
|
ndk::ScopedAStatus updateStreamsConnectedState(const AudioPatch& oldPatch,
|
||||||
const AudioPatch& newPatch);
|
const AudioPatch& newPatch);
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,8 @@ class ModuleAlsa : public Module {
|
||||||
protected:
|
protected:
|
||||||
// Extension methods of 'Module'.
|
// Extension methods of 'Module'.
|
||||||
ndk::ScopedAStatus populateConnectedDevicePort(
|
ndk::ScopedAStatus populateConnectedDevicePort(
|
||||||
::aidl::android::media::audio::common::AudioPort* audioPort) override;
|
::aidl::android::media::audio::common::AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aidl::android::hardware::audio::core
|
} // namespace aidl::android::hardware::audio::core
|
||||||
|
|
|
@ -16,7 +16,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "core-impl/Bluetooth.h"
|
#include "core-impl/Bluetooth.h"
|
||||||
|
#include "core-impl/DevicePortProxy.h"
|
||||||
#include "core-impl/Module.h"
|
#include "core-impl/Module.h"
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core {
|
namespace aidl::android::hardware::audio::core {
|
||||||
|
@ -31,6 +34,11 @@ class ModuleBluetooth final : public Module {
|
||||||
ModuleBluetooth(std::unique_ptr<Configuration>&& config);
|
ModuleBluetooth(std::unique_ptr<Configuration>&& config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct CachedProxy {
|
||||||
|
std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl> ptr;
|
||||||
|
::aidl::android::hardware::bluetooth::audio::PcmConfiguration pcmConfig;
|
||||||
|
};
|
||||||
|
|
||||||
ChildInterface<BluetoothA2dp>& getBtA2dp();
|
ChildInterface<BluetoothA2dp>& getBtA2dp();
|
||||||
ChildInterface<BluetoothLe>& getBtLe();
|
ChildInterface<BluetoothLe>& getBtLe();
|
||||||
BtProfileHandles getBtProfileManagerHandles();
|
BtProfileHandles getBtProfileManagerHandles();
|
||||||
|
@ -40,6 +48,17 @@ class ModuleBluetooth final : public Module {
|
||||||
ndk::ScopedAStatus getMicMute(bool* _aidl_return) override;
|
ndk::ScopedAStatus getMicMute(bool* _aidl_return) override;
|
||||||
ndk::ScopedAStatus setMicMute(bool in_mute) override;
|
ndk::ScopedAStatus setMicMute(bool in_mute) override;
|
||||||
|
|
||||||
|
ndk::ScopedAStatus setAudioPortConfig(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPortConfig& in_requested,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig* out_suggested,
|
||||||
|
bool* _aidl_return) override;
|
||||||
|
|
||||||
|
ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
|
||||||
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks)
|
||||||
|
override;
|
||||||
|
void onExternalDeviceConnectionChanged(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPort& audioPort, bool connected);
|
||||||
ndk::ScopedAStatus createInputStream(
|
ndk::ScopedAStatus createInputStream(
|
||||||
StreamContext&& context,
|
StreamContext&& context,
|
||||||
const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata,
|
const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata,
|
||||||
|
@ -52,12 +71,24 @@ class ModuleBluetooth final : public Module {
|
||||||
offloadInfo,
|
offloadInfo,
|
||||||
std::shared_ptr<StreamOut>* result) override;
|
std::shared_ptr<StreamOut>* result) override;
|
||||||
ndk::ScopedAStatus populateConnectedDevicePort(
|
ndk::ScopedAStatus populateConnectedDevicePort(
|
||||||
::aidl::android::media::audio::common::AudioPort* audioPort) override;
|
::aidl::android::media::audio::common::AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) override;
|
||||||
ndk::ScopedAStatus onMasterMuteChanged(bool mute) override;
|
ndk::ScopedAStatus onMasterMuteChanged(bool mute) override;
|
||||||
ndk::ScopedAStatus onMasterVolumeChanged(float volume) override;
|
ndk::ScopedAStatus onMasterVolumeChanged(float volume) override;
|
||||||
|
int32_t getNominalLatencyMs(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPortConfig& portConfig) override;
|
||||||
|
|
||||||
|
ndk::ScopedAStatus createProxy(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPort& audioPort,
|
||||||
|
int32_t instancePortId, CachedProxy& proxy);
|
||||||
|
ndk::ScopedAStatus fetchAndCheckProxy(const StreamContext& context, CachedProxy& proxy);
|
||||||
|
ndk::ScopedAStatus findOrCreateProxy(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPort& audioPort, CachedProxy& proxy);
|
||||||
|
|
||||||
ChildInterface<BluetoothA2dp> mBluetoothA2dp;
|
ChildInterface<BluetoothA2dp> mBluetoothA2dp;
|
||||||
ChildInterface<BluetoothLe> mBluetoothLe;
|
ChildInterface<BluetoothLe> mBluetoothLe;
|
||||||
|
std::map<int32_t /*instantiated device port ID*/, CachedProxy> mProxies;
|
||||||
|
std::map<int32_t /*mix port handle*/, int32_t /*instantiated device port ID*/> mConnections;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aidl::android::hardware::audio::core
|
} // namespace aidl::android::hardware::audio::core
|
||||||
|
|
|
@ -29,6 +29,10 @@ class ModuleRemoteSubmix : public Module {
|
||||||
// IModule interfaces
|
// IModule interfaces
|
||||||
ndk::ScopedAStatus getMicMute(bool* _aidl_return) override;
|
ndk::ScopedAStatus getMicMute(bool* _aidl_return) override;
|
||||||
ndk::ScopedAStatus setMicMute(bool in_mute) override;
|
ndk::ScopedAStatus setMicMute(bool in_mute) override;
|
||||||
|
ndk::ScopedAStatus setAudioPortConfig(
|
||||||
|
const ::aidl::android::media::audio::common::AudioPortConfig& in_requested,
|
||||||
|
::aidl::android::media::audio::common::AudioPortConfig* out_suggested,
|
||||||
|
bool* _aidl_return) override;
|
||||||
|
|
||||||
// Module interfaces
|
// Module interfaces
|
||||||
ndk::ScopedAStatus createInputStream(
|
ndk::ScopedAStatus createInputStream(
|
||||||
|
@ -43,7 +47,8 @@ class ModuleRemoteSubmix : public Module {
|
||||||
offloadInfo,
|
offloadInfo,
|
||||||
std::shared_ptr<StreamOut>* result) override;
|
std::shared_ptr<StreamOut>* result) override;
|
||||||
ndk::ScopedAStatus populateConnectedDevicePort(
|
ndk::ScopedAStatus populateConnectedDevicePort(
|
||||||
::aidl::android::media::audio::common::AudioPort* audioPort) override;
|
::aidl::android::media::audio::common::AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) override;
|
||||||
ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
||||||
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
|
||||||
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks)
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks)
|
||||||
|
|
|
@ -44,7 +44,8 @@ class ModuleUsb final : public ModuleAlsa {
|
||||||
offloadInfo,
|
offloadInfo,
|
||||||
std::shared_ptr<StreamOut>* result) override;
|
std::shared_ptr<StreamOut>* result) override;
|
||||||
ndk::ScopedAStatus populateConnectedDevicePort(
|
ndk::ScopedAStatus populateConnectedDevicePort(
|
||||||
::aidl::android::media::audio::common::AudioPort* audioPort) override;
|
::aidl::android::media::audio::common::AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) override;
|
||||||
ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
ndk::ScopedAStatus checkAudioPatchEndpointsMatch(
|
||||||
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sources,
|
||||||
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks)
|
const std::vector<::aidl::android::media::audio::common::AudioPortConfig*>& sinks)
|
||||||
|
|
|
@ -31,8 +31,16 @@ namespace aidl::android::hardware::audio::core {
|
||||||
|
|
||||||
class StreamBluetooth : public StreamCommonImpl {
|
class StreamBluetooth : public StreamCommonImpl {
|
||||||
public:
|
public:
|
||||||
StreamBluetooth(StreamContext* context, const Metadata& metadata,
|
static bool checkConfigParams(
|
||||||
ModuleBluetooth::BtProfileHandles&& btHandles);
|
const ::aidl::android::hardware::bluetooth::audio::PcmConfiguration& pcmConfig,
|
||||||
|
const ::aidl::android::media::audio::common::AudioConfigBase& config);
|
||||||
|
|
||||||
|
StreamBluetooth(
|
||||||
|
StreamContext* context, const Metadata& metadata,
|
||||||
|
ModuleBluetooth::BtProfileHandles&& btHandles,
|
||||||
|
const std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl>&
|
||||||
|
btDeviceProxy,
|
||||||
|
const ::aidl::android::hardware::bluetooth::audio::PcmConfiguration& pcmConfig);
|
||||||
// Methods of 'DriverInterface'.
|
// Methods of 'DriverInterface'.
|
||||||
::android::status_t init() override;
|
::android::status_t init() override;
|
||||||
::android::status_t drain(StreamDescriptor::DrainMode) override;
|
::android::status_t drain(StreamDescriptor::DrainMode) override;
|
||||||
|
@ -47,40 +55,35 @@ class StreamBluetooth : public StreamCommonImpl {
|
||||||
// Overridden methods of 'StreamCommonImpl', called on a Binder thread.
|
// Overridden methods of 'StreamCommonImpl', called on a Binder thread.
|
||||||
ndk::ScopedAStatus updateMetadataCommon(const Metadata& metadata) override;
|
ndk::ScopedAStatus updateMetadataCommon(const Metadata& metadata) override;
|
||||||
ndk::ScopedAStatus prepareToClose() override;
|
ndk::ScopedAStatus prepareToClose() override;
|
||||||
const ConnectedDevices& getConnectedDevices() const override;
|
|
||||||
ndk::ScopedAStatus setConnectedDevices(const ConnectedDevices& devices) override;
|
|
||||||
ndk::ScopedAStatus bluetoothParametersUpdated() override;
|
ndk::ScopedAStatus bluetoothParametersUpdated() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Audio Pcm Config
|
|
||||||
const uint32_t mSampleRate;
|
|
||||||
const ::aidl::android::media::audio::common::AudioChannelLayout mChannelLayout;
|
|
||||||
const ::aidl::android::media::audio::common::AudioFormatDescription mFormat;
|
|
||||||
const size_t mFrameSizeBytes;
|
const size_t mFrameSizeBytes;
|
||||||
const bool mIsInput;
|
const bool mIsInput;
|
||||||
const std::weak_ptr<IBluetoothA2dp> mBluetoothA2dp;
|
const std::weak_ptr<IBluetoothA2dp> mBluetoothA2dp;
|
||||||
const std::weak_ptr<IBluetoothLe> mBluetoothLe;
|
const std::weak_ptr<IBluetoothLe> mBluetoothLe;
|
||||||
size_t mPreferredDataIntervalUs;
|
const size_t mPreferredDataIntervalUs;
|
||||||
size_t mPreferredFrameCount;
|
const size_t mPreferredFrameCount;
|
||||||
|
|
||||||
mutable std::mutex mLock;
|
mutable std::mutex mLock;
|
||||||
bool mIsInitialized GUARDED_BY(mLock);
|
// The lock is also used to serialize calls to the proxy.
|
||||||
bool mIsReadyToClose GUARDED_BY(mLock);
|
std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl> mBtDeviceProxy
|
||||||
std::vector<std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl>>
|
GUARDED_BY(mLock); // proxy may be null if the stream is not connected to a device
|
||||||
mBtDeviceProxies GUARDED_BY(mLock);
|
|
||||||
|
|
||||||
::android::status_t initialize() REQUIRES(mLock);
|
|
||||||
bool checkConfigParams(::aidl::android::hardware::bluetooth::audio::PcmConfiguration& config);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StreamInBluetooth final : public StreamIn, public StreamBluetooth {
|
class StreamInBluetooth final : public StreamIn, public StreamBluetooth {
|
||||||
public:
|
public:
|
||||||
friend class ndk::SharedRefBase;
|
friend class ndk::SharedRefBase;
|
||||||
|
|
||||||
|
static int32_t getNominalLatencyMs(size_t dataIntervalUs);
|
||||||
|
|
||||||
StreamInBluetooth(
|
StreamInBluetooth(
|
||||||
StreamContext&& context,
|
StreamContext&& context,
|
||||||
const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata,
|
const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata,
|
||||||
const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones,
|
const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones,
|
||||||
ModuleBluetooth::BtProfileHandles&& btHandles);
|
ModuleBluetooth::BtProfileHandles&& btHandles,
|
||||||
|
const std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl>&
|
||||||
|
btDeviceProxy,
|
||||||
|
const ::aidl::android::hardware::bluetooth::audio::PcmConfiguration& pcmConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
||||||
|
@ -92,12 +95,18 @@ class StreamInBluetooth final : public StreamIn, public StreamBluetooth {
|
||||||
class StreamOutBluetooth final : public StreamOut, public StreamBluetooth {
|
class StreamOutBluetooth final : public StreamOut, public StreamBluetooth {
|
||||||
public:
|
public:
|
||||||
friend class ndk::SharedRefBase;
|
friend class ndk::SharedRefBase;
|
||||||
|
|
||||||
|
static int32_t getNominalLatencyMs(size_t dataIntervalUs);
|
||||||
|
|
||||||
StreamOutBluetooth(
|
StreamOutBluetooth(
|
||||||
StreamContext&& context,
|
StreamContext&& context,
|
||||||
const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata,
|
const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata,
|
||||||
const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>&
|
const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>&
|
||||||
offloadInfo,
|
offloadInfo,
|
||||||
ModuleBluetooth::BtProfileHandles&& btHandles);
|
ModuleBluetooth::BtProfileHandles&& btHandles,
|
||||||
|
const std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl>&
|
||||||
|
btDeviceProxy,
|
||||||
|
const ::aidl::android::hardware::bluetooth::audio::PcmConfiguration& pcmConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
void onClose(StreamDescriptor::State) override { defaultOnClose(); }
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core-impl/Stream.h"
|
#include "core-impl/Stream.h"
|
||||||
|
@ -56,13 +55,6 @@ class StreamRemoteSubmix : public StreamCommonImpl {
|
||||||
r_submix::AudioConfig mStreamConfig;
|
r_submix::AudioConfig mStreamConfig;
|
||||||
std::shared_ptr<r_submix::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
|
|
||||||
// locks and none of the mutex locks should be taken together.
|
|
||||||
static std::mutex sSubmixRoutesLock;
|
|
||||||
static std::map<::aidl::android::media::audio::common::AudioDeviceAddress,
|
|
||||||
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;
|
||||||
// The duration of kMaxReadFailureAttempts * READ_ATTEMPT_SLEEP_MS must be strictly inferior
|
// The duration of kMaxReadFailureAttempts * READ_ATTEMPT_SLEEP_MS must be strictly inferior
|
||||||
|
|
|
@ -27,14 +27,36 @@
|
||||||
|
|
||||||
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::media::audio::common::AudioDeviceAddress;
|
||||||
using aidl::android::media::audio::common::AudioFormatType;
|
using aidl::android::media::audio::common::AudioFormatType;
|
||||||
|
using aidl::android::media::audio::common::AudioIoFlags;
|
||||||
using aidl::android::media::audio::common::AudioOffloadInfo;
|
using aidl::android::media::audio::common::AudioOffloadInfo;
|
||||||
using aidl::android::media::audio::common::AudioPort;
|
using aidl::android::media::audio::common::AudioPort;
|
||||||
using aidl::android::media::audio::common::AudioPortConfig;
|
using aidl::android::media::audio::common::AudioPortConfig;
|
||||||
|
using aidl::android::media::audio::common::AudioPortExt;
|
||||||
|
using aidl::android::media::audio::common::AudioProfile;
|
||||||
|
using aidl::android::media::audio::common::Int;
|
||||||
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 {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::optional<r_submix::AudioConfig> getRemoteEndConfig(const AudioPort& audioPort) {
|
||||||
|
const auto& deviceAddress = audioPort.ext.get<AudioPortExt::device>().device.address;
|
||||||
|
const bool isInput = audioPort.flags.getTag() == AudioIoFlags::input;
|
||||||
|
if (auto submixRoute = r_submix::SubmixRoute::findRoute(deviceAddress);
|
||||||
|
submixRoute != nullptr) {
|
||||||
|
if ((isInput && submixRoute->isStreamOutOpen()) ||
|
||||||
|
(!isInput && submixRoute->isStreamInOpen())) {
|
||||||
|
return submixRoute->getPipeConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleRemoteSubmix::getMicMute(bool* _aidl_return __unused) {
|
ndk::ScopedAStatus ModuleRemoteSubmix::getMicMute(bool* _aidl_return __unused) {
|
||||||
LOG(DEBUG) << __func__ << ": is not supported";
|
LOG(DEBUG) << __func__ << ": is not supported";
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
|
@ -45,6 +67,26 @@ ndk::ScopedAStatus ModuleRemoteSubmix::setMicMute(bool in_mute __unused) {
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndk::ScopedAStatus ModuleRemoteSubmix::setAudioPortConfig(const AudioPortConfig& in_requested,
|
||||||
|
AudioPortConfig* out_suggested,
|
||||||
|
bool* _aidl_return) {
|
||||||
|
auto fillConfig = [this](const AudioPort& port, AudioPortConfig* config) {
|
||||||
|
if (port.ext.getTag() == AudioPortExt::device) {
|
||||||
|
if (auto pipeConfig = getRemoteEndConfig(port); pipeConfig.has_value()) {
|
||||||
|
LOG(DEBUG) << "setAudioPortConfig: suggesting port config from the remote end.";
|
||||||
|
config->format = pipeConfig->format;
|
||||||
|
config->channelMask = pipeConfig->channelLayout;
|
||||||
|
config->sampleRate = Int{.value = pipeConfig->sampleRate};
|
||||||
|
config->flags = port.flags;
|
||||||
|
config->ext = port.ext;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return generateDefaultPortConfig(port, config);
|
||||||
|
};
|
||||||
|
return Module::setAudioPortConfigImpl(in_requested, fillConfig, out_suggested, _aidl_return);
|
||||||
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleRemoteSubmix::createInputStream(
|
ndk::ScopedAStatus ModuleRemoteSubmix::createInputStream(
|
||||||
StreamContext&& context, const SinkMetadata& sinkMetadata,
|
StreamContext&& context, const SinkMetadata& sinkMetadata,
|
||||||
const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) {
|
const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) {
|
||||||
|
@ -67,8 +109,23 @@ ndk::ScopedAStatus ModuleRemoteSubmix::createOutputStream(
|
||||||
offloadInfo);
|
offloadInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleRemoteSubmix::populateConnectedDevicePort(AudioPort* audioPort) {
|
ndk::ScopedAStatus ModuleRemoteSubmix::populateConnectedDevicePort(AudioPort* audioPort, int32_t) {
|
||||||
// Find the corresponding mix port and copy its profiles.
|
if (audioPort->ext.getTag() != AudioPortExt::device) {
|
||||||
|
LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
|
}
|
||||||
|
// If there is already a pipe with a stream for the port address, provide its configuration as
|
||||||
|
// the only option. Otherwise, find the corresponding mix port and copy its profiles.
|
||||||
|
if (auto pipeConfig = getRemoteEndConfig(*audioPort); pipeConfig.has_value()) {
|
||||||
|
audioPort->profiles.clear();
|
||||||
|
audioPort->profiles.push_back(AudioProfile{
|
||||||
|
.format = pipeConfig->format,
|
||||||
|
.channelMasks = std::vector<AudioChannelLayout>({pipeConfig->channelLayout}),
|
||||||
|
.sampleRates = std::vector<int>({pipeConfig->sampleRate})});
|
||||||
|
LOG(DEBUG) << __func__ << ": populated from remote end as: " << audioPort->toString();
|
||||||
|
return ndk::ScopedAStatus::ok();
|
||||||
|
}
|
||||||
|
|
||||||
// At this moment, the port has the same ID as the template port, see connectExternalDevice.
|
// At this moment, the port has the same ID as the template port, see connectExternalDevice.
|
||||||
std::vector<AudioRoute*> routes = getAudioRoutesForAudioPortImpl(audioPort->id);
|
std::vector<AudioRoute*> routes = getAudioRoutesForAudioPortImpl(audioPort->id);
|
||||||
if (routes.empty()) {
|
if (routes.empty()) {
|
||||||
|
@ -87,6 +144,7 @@ ndk::ScopedAStatus ModuleRemoteSubmix::populateConnectedDevicePort(AudioPort* au
|
||||||
RETURN_STATUS_IF_ERROR(getAudioPort(route->sinkPortId, &mixPort));
|
RETURN_STATUS_IF_ERROR(getAudioPort(route->sinkPortId, &mixPort));
|
||||||
}
|
}
|
||||||
audioPort->profiles = mixPort.profiles;
|
audioPort->profiles = mixPort.profiles;
|
||||||
|
LOG(DEBUG) << __func__ << ": populated from the mix port as: " << audioPort->toString();
|
||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,26 +43,10 @@ StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& m
|
||||||
mStreamConfig.sampleRate = context->getSampleRate();
|
mStreamConfig.sampleRate = context->getSampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex StreamRemoteSubmix::sSubmixRoutesLock;
|
|
||||||
std::map<AudioDeviceAddress, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::sSubmixRoutes;
|
|
||||||
|
|
||||||
::android::status_t StreamRemoteSubmix::init() {
|
::android::status_t StreamRemoteSubmix::init() {
|
||||||
{
|
mCurrentRoute = SubmixRoute::findOrCreateRoute(mDeviceAddress, mStreamConfig);
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
if (mCurrentRoute == nullptr) {
|
||||||
auto routeItr = sSubmixRoutes.find(mDeviceAddress);
|
return ::android::NO_INIT;
|
||||||
if (routeItr != sSubmixRoutes.end()) {
|
|
||||||
mCurrentRoute = routeItr->second;
|
|
||||||
}
|
|
||||||
// If route is not available for this port, add it.
|
|
||||||
if (mCurrentRoute == nullptr) {
|
|
||||||
// Initialize the pipe.
|
|
||||||
mCurrentRoute = std::make_shared<SubmixRoute>();
|
|
||||||
if (::android::OK != mCurrentRoute->createPipe(mStreamConfig)) {
|
|
||||||
LOG(ERROR) << __func__ << ": create pipe failed";
|
|
||||||
return ::android::NO_INIT;
|
|
||||||
}
|
|
||||||
sSubmixRoutes.emplace(mDeviceAddress, mCurrentRoute);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
|
if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
|
||||||
LOG(ERROR) << __func__ << ": invalid stream config";
|
LOG(ERROR) << __func__ << ": invalid stream config";
|
||||||
|
@ -80,7 +64,6 @@ std::map<AudioDeviceAddress, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::s
|
||||||
return ::android::NO_INIT;
|
return ::android::NO_INIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentRoute->openStream(mIsInput);
|
mCurrentRoute->openStream(mIsInput);
|
||||||
return ::android::OK;
|
return ::android::OK;
|
||||||
}
|
}
|
||||||
|
@ -114,14 +97,7 @@ std::map<AudioDeviceAddress, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::s
|
||||||
|
|
||||||
ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
|
ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
|
||||||
if (!mIsInput) {
|
if (!mIsInput) {
|
||||||
std::shared_ptr<SubmixRoute> route = nullptr;
|
std::shared_ptr<SubmixRoute> route = SubmixRoute::findRoute(mDeviceAddress);
|
||||||
{
|
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
|
||||||
auto routeItr = sSubmixRoutes.find(mDeviceAddress);
|
|
||||||
if (routeItr != sSubmixRoutes.end()) {
|
|
||||||
route = routeItr->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (route != nullptr) {
|
if (route != nullptr) {
|
||||||
sp<MonoPipe> sink = route->getSink();
|
sp<MonoPipe> sink = route->getSink();
|
||||||
if (sink == nullptr) {
|
if (sink == nullptr) {
|
||||||
|
@ -148,9 +124,7 @@ void StreamRemoteSubmix::shutdown() {
|
||||||
if (!mCurrentRoute->hasAtleastOneStreamOpen()) {
|
if (!mCurrentRoute->hasAtleastOneStreamOpen()) {
|
||||||
mCurrentRoute->releasePipe();
|
mCurrentRoute->releasePipe();
|
||||||
LOG(DEBUG) << __func__ << ": pipe destroyed";
|
LOG(DEBUG) << __func__ << ": pipe destroyed";
|
||||||
|
SubmixRoute::removeRoute(mDeviceAddress);
|
||||||
std::lock_guard guard(sSubmixRoutesLock);
|
|
||||||
sSubmixRoutes.erase(mDeviceAddress);
|
|
||||||
}
|
}
|
||||||
mCurrentRoute.reset();
|
mCurrentRoute.reset();
|
||||||
}
|
}
|
||||||
|
@ -201,7 +175,7 @@ long StreamRemoteSubmix::getDelayInUsForFrameCount(size_t frameCount) {
|
||||||
|
|
||||||
// Calculate the maximum size of the pipe buffer in frames for the specified stream.
|
// Calculate the maximum size of the pipe buffer in frames for the specified stream.
|
||||||
size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
|
size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
|
||||||
auto pipeConfig = mCurrentRoute->mPipeConfig;
|
auto pipeConfig = mCurrentRoute->getPipeConfig();
|
||||||
const size_t maxFrameSize = std::max(mStreamConfig.frameSize, pipeConfig.frameSize);
|
const size_t maxFrameSize = std::max(mStreamConfig.frameSize, pipeConfig.frameSize);
|
||||||
return (pipeConfig.frameCount * pipeConfig.frameSize) / maxFrameSize;
|
return (pipeConfig.frameCount * pipeConfig.frameSize) / maxFrameSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,49 @@
|
||||||
#include "SubmixRoute.h"
|
#include "SubmixRoute.h"
|
||||||
|
|
||||||
using aidl::android::hardware::audio::common::getChannelCount;
|
using aidl::android::hardware::audio::common::getChannelCount;
|
||||||
|
using aidl::android::media::audio::common::AudioDeviceAddress;
|
||||||
|
|
||||||
namespace aidl::android::hardware::audio::core::r_submix {
|
namespace aidl::android::hardware::audio::core::r_submix {
|
||||||
|
|
||||||
|
// static
|
||||||
|
SubmixRoute::RoutesMonitor SubmixRoute::getRoutes() {
|
||||||
|
static std::mutex submixRoutesLock;
|
||||||
|
static RoutesMap submixRoutes;
|
||||||
|
return RoutesMonitor(submixRoutesLock, submixRoutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
std::shared_ptr<SubmixRoute> SubmixRoute::findOrCreateRoute(const AudioDeviceAddress& deviceAddress,
|
||||||
|
const AudioConfig& pipeConfig) {
|
||||||
|
auto routes = getRoutes();
|
||||||
|
auto routeItr = routes->find(deviceAddress);
|
||||||
|
if (routeItr != routes->end()) {
|
||||||
|
return routeItr->second;
|
||||||
|
}
|
||||||
|
auto route = std::make_shared<SubmixRoute>();
|
||||||
|
if (::android::OK != route->createPipe(pipeConfig)) {
|
||||||
|
LOG(ERROR) << __func__ << ": create pipe failed";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
routes->emplace(deviceAddress, route);
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
std::shared_ptr<SubmixRoute> SubmixRoute::findRoute(const AudioDeviceAddress& deviceAddress) {
|
||||||
|
auto routes = getRoutes();
|
||||||
|
auto routeItr = routes->find(deviceAddress);
|
||||||
|
if (routeItr != routes->end()) {
|
||||||
|
return routeItr->second;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void SubmixRoute::removeRoute(const AudioDeviceAddress& deviceAddress) {
|
||||||
|
getRoutes()->erase(deviceAddress);
|
||||||
|
}
|
||||||
|
|
||||||
// Verify a submix input or output stream can be opened.
|
// Verify a submix input or output stream can be opened.
|
||||||
bool SubmixRoute::isStreamConfigValid(bool isInput, const AudioConfig& streamConfig) {
|
bool SubmixRoute::isStreamConfigValid(bool isInput, const AudioConfig& streamConfig) {
|
||||||
// If the stream is already open, don't open it again.
|
// If the stream is already open, don't open it again.
|
||||||
|
@ -44,6 +84,7 @@ bool SubmixRoute::isStreamConfigValid(bool isInput, const AudioConfig& streamCon
|
||||||
// Compare this stream config with existing pipe config, returning false if they do *not*
|
// Compare this stream config with existing pipe config, returning false if they do *not*
|
||||||
// match, true otherwise.
|
// match, true otherwise.
|
||||||
bool SubmixRoute::isStreamConfigCompatible(const AudioConfig& streamConfig) {
|
bool SubmixRoute::isStreamConfigCompatible(const AudioConfig& streamConfig) {
|
||||||
|
std::lock_guard guard(mLock);
|
||||||
if (streamConfig.channelLayout != mPipeConfig.channelLayout) {
|
if (streamConfig.channelLayout != mPipeConfig.channelLayout) {
|
||||||
LOG(ERROR) << __func__ << ": channel count mismatch, stream channels = "
|
LOG(ERROR) << __func__ << ": channel count mismatch, stream channels = "
|
||||||
<< streamConfig.channelLayout.toString()
|
<< streamConfig.channelLayout.toString()
|
||||||
|
@ -162,17 +203,14 @@ void SubmixRoute::closeStream(bool isInput) {
|
||||||
LOG(FATAL) << __func__ << ": Negotiation for the source failed, index = " << index;
|
LOG(FATAL) << __func__ << ": Negotiation for the source failed, index = " << index;
|
||||||
return ::android::BAD_INDEX;
|
return ::android::BAD_INDEX;
|
||||||
}
|
}
|
||||||
LOG(VERBOSE) << __func__ << ": created pipe";
|
LOG(VERBOSE) << __func__ << ": Pipe frame size : " << streamConfig.frameSize
|
||||||
|
<< ", pipe frames : " << sink->maxFrames();
|
||||||
mPipeConfig = streamConfig;
|
|
||||||
mPipeConfig.frameCount = sink->maxFrames();
|
|
||||||
|
|
||||||
LOG(VERBOSE) << __func__ << ": Pipe frame size : " << mPipeConfig.frameSize
|
|
||||||
<< ", pipe frames : " << mPipeConfig.frameCount;
|
|
||||||
|
|
||||||
// Save references to the source and sink.
|
// Save references to the source and sink.
|
||||||
{
|
{
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
|
mPipeConfig = streamConfig;
|
||||||
|
mPipeConfig.frameCount = sink->maxFrames();
|
||||||
mSink = std::move(sink);
|
mSink = std::move(sink);
|
||||||
mSource = std::move(source);
|
mSource = std::move(source);
|
||||||
}
|
}
|
||||||
|
@ -181,15 +219,15 @@ void SubmixRoute::closeStream(bool isInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release references to the sink and source.
|
// Release references to the sink and source.
|
||||||
void SubmixRoute::releasePipe() {
|
AudioConfig SubmixRoute::releasePipe() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
mSink.clear();
|
mSink.clear();
|
||||||
mSource.clear();
|
mSource.clear();
|
||||||
|
return mPipeConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
::android::status_t SubmixRoute::resetPipe() {
|
::android::status_t SubmixRoute::resetPipe() {
|
||||||
releasePipe();
|
return createPipe(releasePipe());
|
||||||
return createPipe(mPipeConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubmixRoute::standby(bool isInput) {
|
void SubmixRoute::standby(bool isInput) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <media/nbaio/MonoPipeReader.h>
|
#include <media/nbaio/MonoPipeReader.h>
|
||||||
|
|
||||||
#include <aidl/android/media/audio/common/AudioChannelLayout.h>
|
#include <aidl/android/media/audio/common/AudioChannelLayout.h>
|
||||||
|
#include <aidl/android/media/audio/common/AudioDeviceAddress.h>
|
||||||
#include <aidl/android/media/audio/common/AudioFormatDescription.h>
|
#include <aidl/android/media/audio/common/AudioFormatDescription.h>
|
||||||
|
|
||||||
using aidl::android::media::audio::common::AudioChannelLayout;
|
using aidl::android::media::audio::common::AudioChannelLayout;
|
||||||
|
@ -60,7 +61,13 @@ struct AudioConfig {
|
||||||
|
|
||||||
class SubmixRoute {
|
class SubmixRoute {
|
||||||
public:
|
public:
|
||||||
AudioConfig mPipeConfig;
|
static std::shared_ptr<SubmixRoute> findOrCreateRoute(
|
||||||
|
const ::aidl::android::media::audio::common::AudioDeviceAddress& deviceAddress,
|
||||||
|
const AudioConfig& pipeConfig);
|
||||||
|
static std::shared_ptr<SubmixRoute> findRoute(
|
||||||
|
const ::aidl::android::media::audio::common::AudioDeviceAddress& deviceAddress);
|
||||||
|
static void removeRoute(
|
||||||
|
const ::aidl::android::media::audio::common::AudioDeviceAddress& deviceAddress);
|
||||||
|
|
||||||
bool isStreamInOpen() {
|
bool isStreamInOpen() {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
|
@ -90,6 +97,10 @@ class SubmixRoute {
|
||||||
std::lock_guard guard(mLock);
|
std::lock_guard guard(mLock);
|
||||||
return mSource;
|
return mSource;
|
||||||
}
|
}
|
||||||
|
AudioConfig getPipeConfig() {
|
||||||
|
std::lock_guard guard(mLock);
|
||||||
|
return mPipeConfig;
|
||||||
|
}
|
||||||
|
|
||||||
bool isStreamConfigValid(bool isInput, const AudioConfig& streamConfig);
|
bool isStreamConfigValid(bool isInput, const AudioConfig& streamConfig);
|
||||||
void closeStream(bool isInput);
|
void closeStream(bool isInput);
|
||||||
|
@ -98,17 +109,31 @@ class SubmixRoute {
|
||||||
bool hasAtleastOneStreamOpen();
|
bool hasAtleastOneStreamOpen();
|
||||||
int notifyReadError();
|
int notifyReadError();
|
||||||
void openStream(bool isInput);
|
void openStream(bool isInput);
|
||||||
void releasePipe();
|
AudioConfig releasePipe();
|
||||||
::android::status_t resetPipe();
|
::android::status_t resetPipe();
|
||||||
bool shouldBlockWrite();
|
bool shouldBlockWrite();
|
||||||
void standby(bool isInput);
|
void standby(bool isInput);
|
||||||
long updateReadCounterFrames(size_t frameCount);
|
long updateReadCounterFrames(size_t frameCount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using RoutesMap = std::map<::aidl::android::media::audio::common::AudioDeviceAddress,
|
||||||
|
std::shared_ptr<r_submix::SubmixRoute>>;
|
||||||
|
class RoutesMonitor {
|
||||||
|
public:
|
||||||
|
RoutesMonitor(std::mutex& mutex, RoutesMap& routes) : mLock(mutex), mRoutes(routes) {}
|
||||||
|
RoutesMap* operator->() { return &mRoutes; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::lock_guard<std::mutex> mLock;
|
||||||
|
RoutesMap& mRoutes;
|
||||||
|
};
|
||||||
|
|
||||||
|
static RoutesMonitor getRoutes();
|
||||||
|
|
||||||
bool isStreamConfigCompatible(const AudioConfig& streamConfig);
|
bool isStreamConfigCompatible(const AudioConfig& streamConfig);
|
||||||
|
|
||||||
std::mutex mLock;
|
std::mutex mLock;
|
||||||
|
AudioConfig mPipeConfig GUARDED_BY(mLock);
|
||||||
bool mStreamInOpen GUARDED_BY(mLock) = false;
|
bool mStreamInOpen GUARDED_BY(mLock) = false;
|
||||||
int mInputRefCount GUARDED_BY(mLock) = 0;
|
int mInputRefCount GUARDED_BY(mLock) = 0;
|
||||||
bool mStreamInStandby GUARDED_BY(mLock) = true;
|
bool mStreamInStandby GUARDED_BY(mLock) = true;
|
||||||
|
|
|
@ -87,12 +87,13 @@ ndk::ScopedAStatus ModuleUsb::createOutputStream(StreamContext&& context,
|
||||||
offloadInfo);
|
offloadInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleUsb::populateConnectedDevicePort(AudioPort* audioPort) {
|
ndk::ScopedAStatus ModuleUsb::populateConnectedDevicePort(AudioPort* audioPort,
|
||||||
|
int32_t nextPortId) {
|
||||||
if (!isUsbDevicePort(*audioPort)) {
|
if (!isUsbDevicePort(*audioPort)) {
|
||||||
LOG(ERROR) << __func__ << ": port id " << audioPort->id << " is not a usb device port";
|
LOG(ERROR) << __func__ << ": port id " << audioPort->id << " is not a usb device port";
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
}
|
}
|
||||||
return ModuleAlsa::populateConnectedDevicePort(audioPort);
|
return ModuleAlsa::populateConnectedDevicePort(audioPort, nextPortId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ModuleUsb::checkAudioPatchEndpointsMatch(
|
ndk::ScopedAStatus ModuleUsb::checkAudioPatchEndpointsMatch(
|
||||||
|
|
|
@ -500,14 +500,12 @@ bool BluetoothAudioSession::GetPresentationPosition(
|
||||||
<< " has NO session";
|
<< " has NO session";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool retval = false;
|
|
||||||
|
|
||||||
if (!stack_iface_->getPresentationPosition(&presentation_position).isOk()) {
|
if (!stack_iface_->getPresentationPosition(&presentation_position).isOk()) {
|
||||||
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
|
LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType="
|
||||||
<< toString(session_type_) << " failed";
|
<< toString(session_type_) << " failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return retval;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothAudioSession::UpdateSourceMetadata(
|
void BluetoothAudioSession::UpdateSourceMetadata(
|
||||||
|
|
Loading…
Reference in a new issue