Revert "Revert "Switch the framework AIDL to use AudioChannelLayout""
This reverts commit b75b624f0a2b9a3e0ae6b89ceb6158e82df71b66.
'AudioChannelLayout' is a new type that will be used both by HAL
and framework interfaces. This CL changes the framework interfaces
to use it instead of 'AudioChannelMask' type which was used to
pass legacy 'audio_channel_mask_t' transparently via the AIDL
layer.
Remove the implementation of 'Parcelable' from AudioProfile and
AudioPortConfig in libaudiofoundation because the implementation
not used after converting audio fwk interfaces to AIDL, and
Parcelable's interface methods do not allow passing in any
context. In our case the context is the direction of the I/O
('isInput' flag) which is usually available externally, but absent
from the encapsulated data of these classes.
Update the audiofoundation_parcelable_test, switch to use of static
libs for the framework code so they can run on a device with
default system libraries.
Bug: 188932434
Test: check audio on device
Test: atest audiofoundation_parcelable_test
Test: app-compat/G3Compat/main
Change-Id: I95c56040855187464bfbe7fcc7daf27f69fea55b
diff --git a/media/libaudiofoundation/AudioGain.cpp b/media/libaudiofoundation/AudioGain.cpp
index 5cc2b2f..169899d 100644
--- a/media/libaudiofoundation/AudioGain.cpp
+++ b/media/libaudiofoundation/AudioGain.cpp
@@ -142,7 +142,8 @@
parcelable->mode = VALUE_OR_RETURN_STATUS(
legacy2aidl_audio_gain_mode_t_int32_t_mask(mGain.mode));
parcelable->channelMask = VALUE_OR_RETURN_STATUS(
- legacy2aidl_audio_channel_mask_t_AudioChannelMask(mGain.channel_mask));
+ legacy2aidl_audio_channel_mask_t_AudioChannelLayout(
+ mGain.channel_mask, mUseInChannelMask));
parcelable->minValue = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(mGain.min_value));
parcelable->maxValue = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(mGain.max_value));
parcelable->defaultValue = VALUE_OR_RETURN_STATUS(
@@ -166,7 +167,8 @@
mGain.mode = VALUE_OR_RETURN_STATUS(
aidl2legacy_int32_t_audio_gain_mode_t_mask(parcelable.mode));
mGain.channel_mask = VALUE_OR_RETURN_STATUS(
- aidl2legacy_AudioChannelMask_audio_channel_mask_t(parcelable.channelMask));
+ aidl2legacy_AudioChannelLayout_audio_channel_mask_t(
+ parcelable.channelMask, parcelable.useInChannelMask));
mGain.min_value = VALUE_OR_RETURN_STATUS(convertIntegral<int>(parcelable.minValue));
mGain.max_value = VALUE_OR_RETURN_STATUS(convertIntegral<int>(parcelable.maxValue));
mGain.default_value = VALUE_OR_RETURN_STATUS(convertIntegral<int>(parcelable.defaultValue));
diff --git a/media/libaudiofoundation/AudioPort.cpp b/media/libaudiofoundation/AudioPort.cpp
index 24ecd78..c70a6c2 100644
--- a/media/libaudiofoundation/AudioPort.cpp
+++ b/media/libaudiofoundation/AudioPort.cpp
@@ -210,7 +210,8 @@
parcelable->name = mName;
parcelable->type = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_type_t_AudioPortType(mType));
parcelable->role = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_role_t_AudioPortRole(mRole));
- parcelable->profiles = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioProfileVector(mProfiles));
+ parcelable->profiles = VALUE_OR_RETURN_STATUS(
+ legacy2aidl_AudioProfileVector(mProfiles, useInputChannelMask()));
parcelable->extraAudioDescriptors = mExtraAudioDescriptors;
parcelable->gains = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioGains(mGains));
return OK;
@@ -226,7 +227,8 @@
mName = parcelable.name;
mType = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPortType_audio_port_type_t(parcelable.type));
mRole = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPortRole_audio_port_role_t(parcelable.role));
- mProfiles = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioProfileVector(parcelable.profiles));
+ mProfiles = VALUE_OR_RETURN_STATUS(
+ aidl2legacy_AudioProfileVector(parcelable.profiles, useInputChannelMask()));
mExtraAudioDescriptors = parcelable.extraAudioDescriptors;
mGains = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioGains(parcelable.gains));
return OK;
@@ -330,24 +332,19 @@
mGain.ramp_duration_ms == other->mGain.ramp_duration_ms;
}
-status_t AudioPortConfig::writeToParcel(Parcel *parcel) const {
- media::AudioPortConfig parcelable;
- return writeToParcelable(&parcelable)
- ?: parcelable.writeToParcel(parcel);
-}
-
-status_t AudioPortConfig::writeToParcelable(media::AudioPortConfig* parcelable) const {
+status_t AudioPortConfig::writeToParcelable(
+ media::AudioPortConfig* parcelable, bool isInput) const {
parcelable->sampleRate = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(mSamplingRate));
parcelable->format = VALUE_OR_RETURN_STATUS(
legacy2aidl_audio_format_t_AudioFormatDescription(mFormat));
parcelable->channelMask = VALUE_OR_RETURN_STATUS(
- legacy2aidl_audio_channel_mask_t_AudioChannelMask(mChannelMask));
+ legacy2aidl_audio_channel_mask_t_AudioChannelLayout(mChannelMask, isInput));
parcelable->id = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(mId));
parcelable->gain.index = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(mGain.index));
parcelable->gain.mode = VALUE_OR_RETURN_STATUS(
legacy2aidl_audio_gain_mode_t_int32_t_mask(mGain.mode));
parcelable->gain.channelMask = VALUE_OR_RETURN_STATUS(
- legacy2aidl_audio_channel_mask_t_AudioChannelMask(mGain.channel_mask));
+ legacy2aidl_audio_channel_mask_t_AudioChannelLayout(mGain.channel_mask, isInput));
parcelable->gain.rampDurationMs = VALUE_OR_RETURN_STATUS(
convertIntegral<int32_t>(mGain.ramp_duration_ms));
parcelable->gain.values = VALUE_OR_RETURN_STATUS(convertContainer<std::vector<int32_t>>(
@@ -355,24 +352,20 @@
return OK;
}
-status_t AudioPortConfig::readFromParcel(const Parcel *parcel) {
- media::AudioPortConfig parcelable;
- return parcelable.readFromParcel(parcel)
- ?: readFromParcelable(parcelable);
-}
-
-status_t AudioPortConfig::readFromParcelable(const media::AudioPortConfig& parcelable) {
+status_t AudioPortConfig::readFromParcelable(
+ const media::AudioPortConfig& parcelable, bool isInput) {
mSamplingRate = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(parcelable.sampleRate));
mFormat = VALUE_OR_RETURN_STATUS(
aidl2legacy_AudioFormatDescription_audio_format_t(parcelable.format));
mChannelMask = VALUE_OR_RETURN_STATUS(
- aidl2legacy_AudioChannelMask_audio_channel_mask_t(parcelable.channelMask));
+ aidl2legacy_AudioChannelLayout_audio_channel_mask_t(parcelable.channelMask, isInput));
mId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(parcelable.id));
mGain.index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(parcelable.gain.index));
mGain.mode = VALUE_OR_RETURN_STATUS(
aidl2legacy_int32_t_audio_gain_mode_t_mask(parcelable.gain.mode));
mGain.channel_mask = VALUE_OR_RETURN_STATUS(
- aidl2legacy_AudioChannelMask_audio_channel_mask_t(parcelable.gain.channelMask));
+ aidl2legacy_AudioChannelLayout_audio_channel_mask_t(
+ parcelable.gain.channelMask, isInput));
mGain.ramp_duration_ms = VALUE_OR_RETURN_STATUS(
convertIntegral<unsigned int>(parcelable.gain.rampDurationMs));
if (parcelable.gain.values.size() > std::size(mGain.values)) {
diff --git a/media/libaudiofoundation/AudioProfile.cpp b/media/libaudiofoundation/AudioProfile.cpp
index f2bed25..47b2d54 100644
--- a/media/libaudiofoundation/AudioProfile.cpp
+++ b/media/libaudiofoundation/AudioProfile.cpp
@@ -154,20 +154,17 @@
return *this;
}
-status_t AudioProfile::writeToParcel(Parcel *parcel) const {
- media::AudioProfile parcelable = VALUE_OR_RETURN_STATUS(toParcelable());
- return parcelable.writeToParcel(parcel);
- }
-
ConversionResult<media::AudioProfile>
-AudioProfile::toParcelable() const {
+AudioProfile::toParcelable(bool isInput) const {
media::AudioProfile parcelable;
parcelable.name = mName;
parcelable.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormatDescription(mFormat));
parcelable.channelMasks = VALUE_OR_RETURN(
- convertContainer<std::vector<media::AudioChannelMask>>(
+ convertContainer<std::vector<media::AudioChannelLayout>>(
mChannelMasks,
- legacy2aidl_audio_channel_mask_t_AudioChannelMask));
+ [isInput](audio_channel_mask_t m) {
+ return legacy2aidl_audio_channel_mask_t_AudioChannelLayout(m, isInput);
+ }));
parcelable.samplingRates = VALUE_OR_RETURN(
convertContainer<std::vector<int32_t>>(mSamplingRates,
convertIntegral<int32_t, uint32_t>));
@@ -179,24 +176,17 @@
return parcelable;
}
-status_t AudioProfile::readFromParcel(const Parcel *parcel) {
- media::AudioProfile parcelable;
- if (status_t status = parcelable.readFromParcel(parcel); status != OK) {
- return status;
- }
- *this = *VALUE_OR_RETURN_STATUS(fromParcelable(parcelable));
- return OK;
-}
-
ConversionResult<sp<AudioProfile>>
-AudioProfile::fromParcelable(const media::AudioProfile& parcelable) {
+AudioProfile::fromParcelable(const media::AudioProfile& parcelable, bool isInput) {
sp<AudioProfile> legacy = new AudioProfile();
legacy->mName = parcelable.name;
legacy->mFormat = VALUE_OR_RETURN(
aidl2legacy_AudioFormatDescription_audio_format_t(parcelable.format));
legacy->mChannelMasks = VALUE_OR_RETURN(
convertContainer<ChannelMaskSet>(parcelable.channelMasks,
- aidl2legacy_AudioChannelMask_audio_channel_mask_t));
+ [isInput](const media::AudioChannelLayout& l) {
+ return aidl2legacy_AudioChannelLayout_audio_channel_mask_t(l, isInput);
+ }));
legacy->mSamplingRates = VALUE_OR_RETURN(
convertContainer<SampleRateSet>(parcelable.samplingRates,
convertIntegral<uint32_t, int32_t>));
@@ -210,13 +200,13 @@
}
ConversionResult<sp<AudioProfile>>
-aidl2legacy_AudioProfile(const media::AudioProfile& aidl) {
- return AudioProfile::fromParcelable(aidl);
+aidl2legacy_AudioProfile(const media::AudioProfile& aidl, bool isInput) {
+ return AudioProfile::fromParcelable(aidl, isInput);
}
ConversionResult<media::AudioProfile>
-legacy2aidl_AudioProfile(const sp<AudioProfile>& legacy) {
- return legacy->toParcelable();
+legacy2aidl_AudioProfile(const sp<AudioProfile>& legacy, bool isInput) {
+ return legacy->toParcelable(isInput);
}
ssize_t AudioProfileVector::add(const sp<AudioProfile> &profile)
@@ -330,33 +320,6 @@
}
}
-status_t AudioProfileVector::writeToParcel(Parcel *parcel) const
-{
- status_t status = NO_ERROR;
- if ((status = parcel->writeVectorSize(*this)) != NO_ERROR) return status;
- for (const auto &audioProfile : *this) {
- if ((status = parcel->writeParcelable(*audioProfile)) != NO_ERROR) {
- break;
- }
- }
- return status;
-}
-
-status_t AudioProfileVector::readFromParcel(const Parcel *parcel)
-{
- status_t status = NO_ERROR;
- this->clear();
- if ((status = parcel->resizeOutVector(this)) != NO_ERROR) return status;
- for (size_t i = 0; i < this->size(); ++i) {
- this->at(i) = new AudioProfile(AUDIO_FORMAT_DEFAULT, AUDIO_CHANNEL_NONE, 0 /*sampleRate*/);
- if ((status = parcel->readParcelable(this->at(i).get())) != NO_ERROR) {
- this->clear();
- break;
- }
- }
- return status;
-}
-
bool AudioProfileVector::equals(const AudioProfileVector& other) const
{
return std::equal(begin(), end(), other.begin(), other.end(),
@@ -366,13 +329,19 @@
}
ConversionResult<AudioProfileVector>
-aidl2legacy_AudioProfileVector(const std::vector<media::AudioProfile>& aidl) {
- return convertContainer<AudioProfileVector>(aidl, aidl2legacy_AudioProfile);
+aidl2legacy_AudioProfileVector(const std::vector<media::AudioProfile>& aidl, bool isInput) {
+ return convertContainer<AudioProfileVector>(aidl,
+ [isInput](const media::AudioProfile& p) {
+ return aidl2legacy_AudioProfile(p, isInput);
+ });
}
ConversionResult<std::vector<media::AudioProfile>>
-legacy2aidl_AudioProfileVector(const AudioProfileVector& legacy) {
- return convertContainer<std::vector<media::AudioProfile>>(legacy, legacy2aidl_AudioProfile);
+legacy2aidl_AudioProfileVector(const AudioProfileVector& legacy, bool isInput) {
+ return convertContainer<std::vector<media::AudioProfile>>(legacy,
+ [isInput](const sp<AudioProfile>& p) {
+ return legacy2aidl_AudioProfile(p, isInput);
+ });
}
AudioProfileVector intersectAudioProfiles(const AudioProfileVector& profiles1,
diff --git a/media/libaudiofoundation/DeviceDescriptorBase.cpp b/media/libaudiofoundation/DeviceDescriptorBase.cpp
index 5cfea81..3cce722 100644
--- a/media/libaudiofoundation/DeviceDescriptorBase.cpp
+++ b/media/libaudiofoundation/DeviceDescriptorBase.cpp
@@ -166,7 +166,7 @@
status_t DeviceDescriptorBase::writeToParcelable(media::AudioPort* parcelable) const {
AudioPort::writeToParcelable(parcelable);
- AudioPortConfig::writeToParcelable(&parcelable->activeConfig);
+ AudioPortConfig::writeToParcelable(&parcelable->activeConfig, useInputChannelMask());
parcelable->id = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(mId));
media::AudioPortDeviceExt ext;
@@ -190,7 +190,7 @@
return BAD_VALUE;
}
status_t status = AudioPort::readFromParcelable(parcelable)
- ?: AudioPortConfig::readFromParcelable(parcelable.activeConfig);
+ ?: AudioPortConfig::readFromParcelable(parcelable.activeConfig, useInputChannelMask());
if (status != OK) {
return status;
}
diff --git a/media/libaudiofoundation/include/media/AudioPort.h b/media/libaudiofoundation/include/media/AudioPort.h
index 1cee1c9..6e1d032 100644
--- a/media/libaudiofoundation/include/media/AudioPort.h
+++ b/media/libaudiofoundation/include/media/AudioPort.h
@@ -130,7 +130,7 @@
};
-class AudioPortConfig : public virtual RefBase, public virtual Parcelable
+class AudioPortConfig : public virtual RefBase
{
public:
virtual ~AudioPortConfig() = default;
@@ -152,10 +152,8 @@
bool equals(const sp<AudioPortConfig>& other) const;
- status_t writeToParcel(Parcel* parcel) const override;
- status_t readFromParcel(const Parcel* parcel) override;
- status_t writeToParcelable(media::AudioPortConfig* parcelable) const;
- status_t readFromParcelable(const media::AudioPortConfig& parcelable);
+ status_t writeToParcelable(media::AudioPortConfig* parcelable, bool isInput) const;
+ status_t readFromParcelable(const media::AudioPortConfig& parcelable, bool isInput);
protected:
unsigned int mSamplingRate = 0u;
diff --git a/media/libaudiofoundation/include/media/AudioProfile.h b/media/libaudiofoundation/include/media/AudioProfile.h
index 6a36e78..e34a49f 100644
--- a/media/libaudiofoundation/include/media/AudioProfile.h
+++ b/media/libaudiofoundation/include/media/AudioProfile.h
@@ -29,7 +29,7 @@
namespace android {
-class AudioProfile final : public RefBase, public Parcelable
+class AudioProfile final : public RefBase
{
public:
static sp<AudioProfile> createFullDynamic(audio_format_t dynamicFormat = AUDIO_FORMAT_DEFAULT);
@@ -81,11 +81,9 @@
bool equals(const sp<AudioProfile>& other) const;
- status_t writeToParcel(Parcel* parcel) const override;
- status_t readFromParcel(const Parcel* parcel) override;
-
- ConversionResult<media::AudioProfile> toParcelable() const;
- static ConversionResult<sp<AudioProfile>> fromParcelable(const media::AudioProfile& parcelable);
+ ConversionResult<media::AudioProfile> toParcelable(bool isInput) const;
+ static ConversionResult<sp<AudioProfile>> fromParcelable(
+ const media::AudioProfile& parcelable, bool isInput);
private:
@@ -106,11 +104,11 @@
// Conversion routines, according to AidlConversion.h conventions.
ConversionResult<sp<AudioProfile>>
-aidl2legacy_AudioProfile(const media::AudioProfile& aidl);
+aidl2legacy_AudioProfile(const media::AudioProfile& aidl, bool isInput);
ConversionResult<media::AudioProfile>
-legacy2aidl_AudioProfile(const sp<AudioProfile>& legacy);
+legacy2aidl_AudioProfile(const sp<AudioProfile>& legacy, bool isInput);
-class AudioProfileVector : public std::vector<sp<AudioProfile>>, public Parcelable
+class AudioProfileVector : public std::vector<sp<AudioProfile>>
{
public:
virtual ~AudioProfileVector() = default;
@@ -136,18 +134,15 @@
virtual void dump(std::string *dst, int spaces) const;
bool equals(const AudioProfileVector& other) const;
-
- status_t writeToParcel(Parcel* parcel) const override;
- status_t readFromParcel(const Parcel* parcel) override;
};
bool operator == (const AudioProfile &left, const AudioProfile &right);
// Conversion routines, according to AidlConversion.h conventions.
ConversionResult<AudioProfileVector>
-aidl2legacy_AudioProfileVector(const std::vector<media::AudioProfile>& aidl);
+aidl2legacy_AudioProfileVector(const std::vector<media::AudioProfile>& aidl, bool isInput);
ConversionResult<std::vector<media::AudioProfile>>
-legacy2aidl_AudioProfileVector(const AudioProfileVector& legacy);
+legacy2aidl_AudioProfileVector(const AudioProfileVector& legacy, bool isInput);
AudioProfileVector intersectAudioProfiles(const AudioProfileVector& profiles1,
const AudioProfileVector& profiles2);
diff --git a/media/libaudiofoundation/tests/Android.bp b/media/libaudiofoundation/tests/Android.bp
index bb9a5f2..f3cd446 100644
--- a/media/libaudiofoundation/tests/Android.bp
+++ b/media/libaudiofoundation/tests/Android.bp
@@ -11,12 +11,19 @@
name: "audiofoundation_parcelable_test",
shared_libs: [
- "libaudiofoundation",
+ "libbase",
"libbinder",
"liblog",
"libutils",
],
+ static_libs: [
+ "audioclient-types-aidl-cpp",
+ "libaudioclient_aidl_conversion",
+ "libaudiofoundation",
+ "libstagefright_foundation",
+ ],
+
header_libs: [
"libaudio_system_headers",
],
diff --git a/media/libaudiofoundation/tests/audiofoundation_parcelable_test.cpp b/media/libaudiofoundation/tests/audiofoundation_parcelable_test.cpp
index 068b5d8..2b03a83 100644
--- a/media/libaudiofoundation/tests/audiofoundation_parcelable_test.cpp
+++ b/media/libaudiofoundation/tests/audiofoundation_parcelable_test.cpp
@@ -86,17 +86,6 @@
ASSERT_TRUE(audioGainsFromParcel.equals(audioGains));
}
-TEST(AudioFoundationParcelableTest, ParcelingAudioProfileVector) {
- Parcel data;
- AudioProfileVector audioProfiles = getAudioProfileVectorForTest();
-
- ASSERT_EQ(data.writeParcelable(audioProfiles), NO_ERROR);
- data.setDataPosition(0);
- AudioProfileVector audioProfilesFromParcel;
- ASSERT_EQ(data.readParcelable(&audioProfilesFromParcel), NO_ERROR);
- ASSERT_TRUE(audioProfilesFromParcel.equals(audioProfiles));
-}
-
TEST(AudioFoundationParcelableTest, ParcelingAudioPort) {
Parcel data;
sp<AudioPort> audioPort = new AudioPort(
@@ -116,11 +105,15 @@
Parcel data;
sp<AudioPortConfig> audioPortConfig = new AudioPortConfigTestStub();
audioPortConfig->applyAudioPortConfig(&TEST_AUDIO_PORT_CONFIG);
-
- ASSERT_EQ(data.writeParcelable(*audioPortConfig), NO_ERROR);
+ media::AudioPortConfig parcelable{};
+ ASSERT_EQ(NO_ERROR, audioPortConfig->writeToParcelable(&parcelable, false /*isInput*/));
+ ASSERT_EQ(NO_ERROR, data.writeParcelable(parcelable));
data.setDataPosition(0);
+ media::AudioPortConfig parcelableFromParcel{};
+ ASSERT_EQ(NO_ERROR, data.readParcelable(&parcelableFromParcel));
sp<AudioPortConfig> audioPortConfigFromParcel = new AudioPortConfigTestStub();
- ASSERT_EQ(data.readParcelable(audioPortConfigFromParcel.get()), NO_ERROR);
+ ASSERT_EQ(NO_ERROR, audioPortConfigFromParcel->readFromParcelable(
+ parcelableFromParcel, false /*isInput*/));
ASSERT_TRUE(audioPortConfigFromParcel->equals(audioPortConfig));
}