Move handling of flags of audio ports to libaudiofoundation
Since the flags of an audio port are part of its configuration,
they need to be visible to HAL. Thus, expose them in AudioPort/Config
classes from libaudiofoundation.
To simplify code, removed unneeded implementation of Parcelable
interface by AudioPort and DeviceDescriptorBase.
PolicyAudioPortConfig now doesn't have any fields on its own,
only inline methods.
Bug: 198812639
Test: atest audiofoundation_parcelable_test
Test: atest audiopolicy_tests
Change-Id: I68fd6d232b7e00462866cd6240089a48ad187279
diff --git a/media/libaudiofoundation/AudioPort.cpp b/media/libaudiofoundation/AudioPort.cpp
index a00e00d..634b2e1 100644
--- a/media/libaudiofoundation/AudioPort.cpp
+++ b/media/libaudiofoundation/AudioPort.cpp
@@ -24,6 +24,22 @@
namespace android {
+void AudioPort::setFlags(uint32_t flags)
+{
+ // force direct flag if offload flag is set: offloading implies a direct output stream
+ // and all common behaviors are driven by checking only the direct flag
+ // this should normally be set appropriately in the policy configuration file
+ if (mRole == AUDIO_PORT_ROLE_SOURCE &&
+ (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
+ flags |= AUDIO_OUTPUT_FLAG_DIRECT;
+ }
+ if (useInputChannelMask()) {
+ mFlags.input = static_cast<audio_input_flags_t>(flags);
+ } else {
+ mFlags.output = static_cast<audio_output_flags_t>(flags);
+ }
+}
+
void AudioPort::importAudioPort(const sp<AudioPort>& port, bool force __unused)
{
for (const auto& profileToImport : port->mProfiles) {
@@ -195,16 +211,10 @@
mType == other->getType() &&
mRole == other->getRole() &&
mProfiles.equals(other->getAudioProfiles()) &&
+ getFlags() == other->getFlags() &&
mExtraAudioDescriptors == other->getExtraAudioDescriptors();
}
-status_t AudioPort::writeToParcel(Parcel *parcel) const
-{
- media::AudioPort parcelable;
- return writeToParcelable(&parcelable)
- ?: parcelable.writeToParcel(parcel);
-}
-
status_t AudioPort::writeToParcelable(media::AudioPort* parcelable) const {
parcelable->hal.name = mName;
parcelable->sys.type = VALUE_OR_RETURN_STATUS(
@@ -215,6 +225,8 @@
legacy2aidl_AudioProfileVector(mProfiles, useInputChannelMask()));
parcelable->hal.profiles = aidlProfiles.first;
parcelable->sys.profiles = aidlProfiles.second;
+ parcelable->hal.flags = VALUE_OR_RETURN_STATUS(
+ legacy2aidl_audio_io_flags_AudioIoFlags(mFlags, useInputChannelMask()));
parcelable->hal.extraAudioDescriptors = mExtraAudioDescriptors;
auto aidlGains = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioGains(mGains));
parcelable->hal.gains = aidlGains.first;
@@ -230,12 +242,6 @@
return OK;
}
-status_t AudioPort::readFromParcel(const Parcel *parcel) {
- media::AudioPort parcelable;
- return parcelable.readFromParcel(parcel)
- ?: readFromParcelable(parcelable);
-}
-
status_t AudioPort::readFromParcelable(const media::AudioPort& parcelable) {
mName = parcelable.hal.name;
mType = VALUE_OR_RETURN_STATUS(
@@ -246,6 +252,8 @@
aidl2legacy_AudioProfileVector(
std::make_pair(parcelable.hal.profiles, parcelable.sys.profiles),
useInputChannelMask()));
+ mFlags = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioIoFlags_audio_io_flags(parcelable.hal.flags, useInputChannelMask()));
mExtraAudioDescriptors = parcelable.hal.extraAudioDescriptors;
mGains = VALUE_OR_RETURN_STATUS(
aidl2legacy_AudioGains(std::make_pair(parcelable.hal.gains, parcelable.sys.gains)));
@@ -277,6 +285,9 @@
if (config->config_mask & AUDIO_PORT_CONFIG_GAIN) {
mGain = config->gain;
}
+ if (config->config_mask & AUDIO_PORT_CONFIG_FLAGS) {
+ mFlags = config->flags;
+ }
return NO_ERROR;
}
@@ -330,6 +341,9 @@
} else {
dstConfig->config_mask &= ~AUDIO_PORT_CONFIG_GAIN;
}
+
+ updateField(mFlags, &audio_port_config::flags,
+ dstConfig, srcConfig, AUDIO_PORT_CONFIG_FLAGS, { AUDIO_INPUT_FLAG_NONE });
}
bool AudioPortConfig::hasGainController(bool canUseForVolume) const
@@ -342,12 +356,14 @@
: audioport->getGains().size() > 0;
}
-bool AudioPortConfig::equals(const sp<AudioPortConfig> &other) const
+bool AudioPortConfig::equals(const sp<AudioPortConfig> &other, bool isInput) const
{
return other != nullptr &&
mSamplingRate == other->getSamplingRate() &&
mFormat == other->getFormat() &&
mChannelMask == other->getChannelMask() &&
+ (isInput ? mFlags.input == other->getFlags().input :
+ mFlags.output == other->getFlags().output )&&
// Compare audio gain config
mGain.index == other->mGain.index &&
mGain.mode == other->mGain.mode &&
@@ -370,6 +386,8 @@
media::audio::common::AudioGainConfig aidl_gain = VALUE_OR_RETURN_STATUS(
legacy2aidl_audio_gain_config_AudioGainConfig(mGain, isInput));
parcelable->gain = aidl_gain;
+ parcelable->flags = VALUE_OR_RETURN_STATUS(
+ legacy2aidl_audio_io_flags_AudioIoFlags(mFlags, isInput));
return OK;
}
@@ -393,6 +411,10 @@
mGain = VALUE_OR_RETURN_STATUS(
aidl2legacy_AudioGainConfig_audio_gain_config(parcelable.gain.value(), isInput));
}
+ if (parcelable.flags.has_value()) {
+ mFlags = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioIoFlags_audio_io_flags(parcelable.flags.value(), isInput));
+ }
return OK;
}