Add equals functions for classes in libaudiofoundation.

Add equals functions that can be used to check if current object is the
same as the given object by checking if all members are the same.

Bug: 135621476
Test: make
Change-Id: Idcf09587f629e6719e9dcf2f0fb7d68a01eafef9
gugelfrei
jiabin 5 years ago
parent 17058fa562
commit 49e69a1e68

@ -24,6 +24,8 @@
#define ALOGVV(a...) do { } while(0)
#endif
#include <algorithm>
#include <android-base/stringprintf.h>
#include <media/AudioGain.h>
#include <utils/Log.h>
@ -111,6 +113,22 @@ void AudioGain::dump(std::string *dst, int spaces, int index) const
dst->append(base::StringPrintf("%*s- max_ramp_ms: %d ms\n", spaces, "", mGain.max_ramp_ms));
}
bool AudioGain::equals(const sp<AudioGain>& other) const
{
return other != nullptr &&
mUseInChannelMask == other->mUseInChannelMask &&
mUseForVolume == other->mUseForVolume &&
// Compare audio gain
mGain.mode == other->mGain.mode &&
mGain.channel_mask == other->mGain.channel_mask &&
mGain.min_value == other->mGain.min_value &&
mGain.max_value == other->mGain.max_value &&
mGain.default_value == other->mGain.default_value &&
mGain.step_value == other->mGain.step_value &&
mGain.min_ramp_ms == other->mGain.min_ramp_ms &&
mGain.max_ramp_ms == other->mGain.max_ramp_ms;
}
status_t AudioGain::writeToParcel(android::Parcel *parcel) const
{
status_t status = NO_ERROR;
@ -145,6 +163,14 @@ status_t AudioGain::readFromParcel(const android::Parcel *parcel)
return status;
}
bool AudioGains::equals(const AudioGains &other) const
{
return std::equal(begin(), end(), other.begin(), other.end(),
[](const sp<AudioGain>& left, const sp<AudioGain>& right) {
return left->equals(right);
});
}
status_t AudioGains::writeToParcel(android::Parcel *parcel) const {
status_t status = NO_ERROR;
if ((status = parcel->writeVectorSize(*this)) != NO_ERROR) return status;

@ -105,6 +105,16 @@ void AudioPort::log(const char* indent) const
ALOGI("%s Port[nm:%s, type:%d, role:%d]", indent, mName.c_str(), mType, mRole);
}
bool AudioPort::equals(const sp<AudioPort> &other) const
{
return other != nullptr &&
mGains.equals(other->getGains()) &&
mName.compare(other->getName()) == 0 &&
mType == other->getType() &&
mRole == other->getRole() &&
mProfiles.equals(other->getAudioProfiles());
}
status_t AudioPort::writeToParcel(Parcel *parcel) const
{
status_t status = NO_ERROR;
@ -218,6 +228,21 @@ bool AudioPortConfig::hasGainController(bool canUseForVolume) const
: audioport->getGains().size() > 0;
}
bool AudioPortConfig::equals(const sp<AudioPortConfig> &other) const
{
return other != nullptr &&
mSamplingRate == other->getSamplingRate() &&
mFormat == other->getFormat() &&
mChannelMask == other->getChannelMask() &&
// Compare audio gain config
mGain.index == other->mGain.index &&
mGain.mode == other->mGain.mode &&
mGain.channel_mask == other->mGain.channel_mask &&
std::equal(std::begin(mGain.values), std::end(mGain.values),
std::begin(other->mGain.values)) &&
mGain.ramp_duration_ms == other->mGain.ramp_duration_ms;
}
status_t AudioPortConfig::writeToParcel(Parcel *parcel) const
{
status_t status = NO_ERROR;

@ -118,6 +118,18 @@ void AudioProfile::dump(std::string *dst, int spaces) const
}
}
bool AudioProfile::equals(const sp<AudioProfile>& other) const
{
return other != nullptr &&
mName.compare(other->mName) == 0 &&
mFormat == other->getFormat() &&
mChannelMasks == other->getChannels() &&
mSamplingRates == other->getSampleRates() &&
mIsDynamicFormat == other->isDynamicFormat() &&
mIsDynamicChannels == other->isDynamicChannels() &&
mIsDynamicRate == other->isDynamicRate();
}
status_t AudioProfile::writeToParcel(Parcel *parcel) const
{
status_t status = NO_ERROR;
@ -284,4 +296,12 @@ status_t AudioProfileVector::readFromParcel(const Parcel *parcel)
return status;
}
bool AudioProfileVector::equals(const AudioProfileVector& other) const
{
return std::equal(begin(), end(), other.begin(), other.end(),
[](const sp<AudioProfile>& left, const sp<AudioProfile>& right) {
return left->equals(right);
});
}
} // namespace android

@ -110,6 +110,15 @@ void DeviceDescriptorBase::log() const
AudioPort::log(" ");
}
bool DeviceDescriptorBase::equals(const sp<DeviceDescriptorBase> &other) const
{
return other != nullptr &&
static_cast<const AudioPort*>(this)->equals(other) &&
static_cast<const AudioPortConfig*>(this)->equals(other) &&
mAddress.compare(other->address()) == 0 &&
mDeviceType == other->type();
}
status_t DeviceDescriptorBase::writeToParcel(Parcel *parcel) const
{
status_t status = NO_ERROR;

@ -67,6 +67,8 @@ public:
const struct audio_gain &getGain() const { return mGain; }
bool equals(const sp<AudioGain>& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;
@ -96,6 +98,8 @@ public:
return 0;
}
bool equals(const AudioGains& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;
};

@ -81,6 +81,8 @@ public:
void log(const char* indent) const;
bool equals(const sp<AudioPort>& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;
@ -113,6 +115,8 @@ public:
bool hasGainController(bool canUseForVolume = false) const;
bool equals(const sp<AudioPortConfig>& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;

@ -68,6 +68,8 @@ public:
void dump(std::string *dst, int spaces) const;
bool equals(const sp<AudioProfile>& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;
@ -105,6 +107,8 @@ public:
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;
};

@ -53,6 +53,8 @@ public:
void log() const;
std::string toString() const;
bool equals(const sp<DeviceDescriptorBase>& other) const;
status_t writeToParcel(Parcel* parcel) const override;
status_t readFromParcel(const Parcel* parcel) override;

Loading…
Cancel
Save