| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 1 | /* | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 2 | * Copyright (C) 2019 The Android Open Source Project | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Mikhail Naganov | fa69dc6 | 2018-07-27 09:58:58 -0700 | [diff] [blame] | 17 | #include <set> | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 18 |  | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 19 | #define LOG_TAG "AudioProfile" | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 20 | //#define LOG_NDEBUG 0 | 
|  | 21 |  | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 22 | #include <android-base/stringprintf.h> | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 23 | #include <media/AudioContainers.h> | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 24 | #include <media/AudioProfile.h> | 
|  | 25 | #include <media/TypeConverter.h> | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 26 | #include <utils/Errors.h> | 
|  | 27 |  | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 28 | namespace android { | 
|  | 29 |  | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 30 | bool operator == (const AudioProfile &left, const AudioProfile &right) | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 31 | { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 32 | return (left.getFormat() == right.getFormat()) && | 
|  | 33 | (left.getChannels() == right.getChannels()) && | 
|  | 34 | (left.getSampleRates() == right.getSampleRates()); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 37 | // static | 
|  | 38 | sp<AudioProfile> AudioProfile::createFullDynamic(audio_format_t dynamicFormat) | 
| Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 39 | { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 40 | AudioProfile* dynamicProfile = new AudioProfile(dynamicFormat, | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 41 | ChannelMaskSet(), SampleRateSet()); | 
| Mikhail Naganov | 21b4336 | 2018-06-04 10:37:09 -0700 | [diff] [blame] | 42 | dynamicProfile->setDynamicFormat(true); | 
|  | 43 | dynamicProfile->setDynamicChannels(true); | 
|  | 44 | dynamicProfile->setDynamicRate(true); | 
|  | 45 | return dynamicProfile; | 
|  | 46 | } | 
|  | 47 |  | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 48 | AudioProfile::AudioProfile(audio_format_t format, | 
|  | 49 | audio_channel_mask_t channelMasks, | 
|  | 50 | uint32_t samplingRate) : | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 51 | mName(""), | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 52 | mFormat(format) | 
|  | 53 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 54 | mChannelMasks.insert(channelMasks); | 
|  | 55 | mSamplingRates.insert(samplingRate); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
|  | 58 | AudioProfile::AudioProfile(audio_format_t format, | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 59 | const ChannelMaskSet &channelMasks, | 
|  | 60 | const SampleRateSet &samplingRateCollection) : | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 61 | mName(""), | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 62 | mFormat(format), | 
|  | 63 | mChannelMasks(channelMasks), | 
|  | 64 | mSamplingRates(samplingRateCollection) {} | 
|  | 65 |  | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 66 | void AudioProfile::setChannels(const ChannelMaskSet &channelMasks) | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 67 | { | 
|  | 68 | if (mIsDynamicChannels) { | 
|  | 69 | mChannelMasks = channelMasks; | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 |  | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 73 | void AudioProfile::setSampleRates(const SampleRateSet &sampleRates) | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 74 | { | 
|  | 75 | if (mIsDynamicRate) { | 
|  | 76 | mSamplingRates = sampleRates; | 
|  | 77 | } | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | void AudioProfile::clear() | 
|  | 81 | { | 
|  | 82 | if (mIsDynamicChannels) { | 
|  | 83 | mChannelMasks.clear(); | 
|  | 84 | } | 
|  | 85 | if (mIsDynamicRate) { | 
|  | 86 | mSamplingRates.clear(); | 
|  | 87 | } | 
|  | 88 | } | 
|  | 89 |  | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 90 | void AudioProfile::dump(std::string *dst, int spaces) const | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 91 | { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 92 | dst->append(base::StringPrintf("%s%s%s\n", mIsDynamicFormat ? "[dynamic format]" : "", | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 93 | mIsDynamicChannels ? "[dynamic channels]" : "", | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 94 | mIsDynamicRate ? "[dynamic rates]" : "")); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 95 | if (mName.length() != 0) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 96 | dst->append(base::StringPrintf("%*s- name: %s\n", spaces, "", mName.c_str())); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 97 | } | 
|  | 98 | std::string formatLiteral; | 
|  | 99 | if (FormatConverter::toString(mFormat, formatLiteral)) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 100 | dst->append(base::StringPrintf("%*s- format: %s\n", spaces, "", formatLiteral.c_str())); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 101 | } | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 102 | if (!mSamplingRates.empty()) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 103 | dst->append(base::StringPrintf("%*s- sampling rates:", spaces, "")); | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 104 | for (auto it = mSamplingRates.begin(); it != mSamplingRates.end();) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 105 | dst->append(base::StringPrintf("%d", *it)); | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 106 | dst->append(++it == mSamplingRates.end() ? "" : ", "); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 107 | } | 
| Andy Hung | bb54e20 | 2018-10-05 11:42:02 -0700 | [diff] [blame] | 108 | dst->append("\n"); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 111 | if (!mChannelMasks.empty()) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 112 | dst->append(base::StringPrintf("%*s- channel masks:", spaces, "")); | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 113 | for (auto it = mChannelMasks.begin(); it != mChannelMasks.end();) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 114 | dst->append(base::StringPrintf("0x%04x", *it)); | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 115 | dst->append(++it == mChannelMasks.end() ? "" : ", "); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 116 | } | 
| Andy Hung | bb54e20 | 2018-10-05 11:42:02 -0700 | [diff] [blame] | 117 | dst->append("\n"); | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 118 | } | 
| François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 119 | } | 
|  | 120 |  | 
| jiabin | 0da24a3 | 2019-10-15 16:04:13 -0700 | [diff] [blame] | 121 | bool AudioProfile::equals(const sp<AudioProfile>& other) const | 
|  | 122 | { | 
|  | 123 | return other != nullptr && | 
|  | 124 | mName.compare(other->mName) == 0 && | 
|  | 125 | mFormat == other->getFormat() && | 
|  | 126 | mChannelMasks == other->getChannels() && | 
|  | 127 | mSamplingRates == other->getSampleRates() && | 
|  | 128 | mIsDynamicFormat == other->isDynamicFormat() && | 
|  | 129 | mIsDynamicChannels == other->isDynamicChannels() && | 
|  | 130 | mIsDynamicRate == other->isDynamicRate(); | 
|  | 131 | } | 
|  | 132 |  | 
| jiabin | d19519a | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 133 | status_t AudioProfile::writeToParcel(Parcel *parcel) const | 
|  | 134 | { | 
|  | 135 | status_t status = NO_ERROR; | 
|  | 136 | if ((status = parcel->writeUtf8AsUtf16(mName)) != NO_ERROR) return status; | 
|  | 137 | if ((status = parcel->writeUint32(mFormat)) != NO_ERROR) return status; | 
|  | 138 | std::vector<int> values(mChannelMasks.begin(), mChannelMasks.end()); | 
|  | 139 | if ((status = parcel->writeInt32Vector(values)) != NO_ERROR) return status; | 
|  | 140 | values.clear(); | 
|  | 141 | values.assign(mSamplingRates.begin(), mSamplingRates.end()); | 
|  | 142 | if ((status = parcel->writeInt32Vector(values)) != NO_ERROR) return status; | 
|  | 143 | if ((status = parcel->writeBool(mIsDynamicFormat)) != NO_ERROR) return status; | 
|  | 144 | if ((status = parcel->writeBool(mIsDynamicChannels)) != NO_ERROR) return status; | 
|  | 145 | if ((status = parcel->writeBool(mIsDynamicRate)) != NO_ERROR) return status; | 
|  | 146 | return status; | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | status_t AudioProfile::readFromParcel(const Parcel *parcel) | 
|  | 150 | { | 
|  | 151 | status_t status = NO_ERROR; | 
|  | 152 | if ((status = parcel->readUtf8FromUtf16(&mName)) != NO_ERROR) return status; | 
|  | 153 | static_assert(sizeof(mFormat) == sizeof(uint32_t)); | 
|  | 154 | if ((status = parcel->readUint32(reinterpret_cast<uint32_t*>(&mFormat))) != NO_ERROR) { | 
|  | 155 | return status; | 
|  | 156 | } | 
|  | 157 | std::vector<int> values; | 
|  | 158 | if ((status = parcel->readInt32Vector(&values)) != NO_ERROR) return status; | 
|  | 159 | mChannelMasks.clear(); | 
| Mikhail Naganov | e3b59ac | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 160 | for (auto raw : values) { | 
|  | 161 | mChannelMasks.insert(static_cast<audio_channel_mask_t>(raw)); | 
|  | 162 | } | 
| jiabin | d19519a | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 163 | values.clear(); | 
|  | 164 | if ((status = parcel->readInt32Vector(&values)) != NO_ERROR) return status; | 
|  | 165 | mSamplingRates.clear(); | 
|  | 166 | mSamplingRates.insert(values.begin(), values.end()); | 
|  | 167 | if ((status = parcel->readBool(&mIsDynamicFormat)) != NO_ERROR) return status; | 
|  | 168 | if ((status = parcel->readBool(&mIsDynamicChannels)) != NO_ERROR) return status; | 
|  | 169 | if ((status = parcel->readBool(&mIsDynamicRate)) != NO_ERROR) return status; | 
|  | 170 | return status; | 
|  | 171 | } | 
|  | 172 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 173 | ssize_t AudioProfileVector::add(const sp<AudioProfile> &profile) | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 174 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 175 | ssize_t index = size(); | 
|  | 176 | push_back(profile); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 177 | return index; | 
|  | 178 | } | 
|  | 179 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 180 | void AudioProfileVector::clearProfiles() | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 181 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 182 | for (auto it = begin(); it != end();) { | 
|  | 183 | if ((*it)->isDynamicFormat() && (*it)->hasValidFormat()) { | 
|  | 184 | it = erase(it); | 
|  | 185 | } else { | 
|  | 186 | (*it)->clear(); | 
|  | 187 | ++it; | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 188 | } | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 189 | } | 
|  | 190 | } | 
|  | 191 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 192 | sp<AudioProfile> AudioProfileVector::getFirstValidProfile() const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 193 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 194 | for (const auto &profile : *this) { | 
|  | 195 | if (profile->isValid()) { | 
|  | 196 | return profile; | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 197 | } | 
|  | 198 | } | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 199 | return nullptr; | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 200 | } | 
|  | 201 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 202 | sp<AudioProfile> AudioProfileVector::getFirstValidProfileFor(audio_format_t format) const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 203 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 204 | for (const auto &profile : *this) { | 
|  | 205 | if (profile->isValid() && profile->getFormat() == format) { | 
|  | 206 | return profile; | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 207 | } | 
|  | 208 | } | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 209 | return nullptr; | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 210 | } | 
|  | 211 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 212 | FormatVector AudioProfileVector::getSupportedFormats() const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 213 | { | 
|  | 214 | FormatVector supportedFormats; | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 215 | for (const auto &profile : *this) { | 
|  | 216 | if (profile->hasValidFormat()) { | 
|  | 217 | supportedFormats.push_back(profile->getFormat()); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 218 | } | 
|  | 219 | } | 
|  | 220 | return supportedFormats; | 
|  | 221 | } | 
|  | 222 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 223 | bool AudioProfileVector::hasDynamicChannelsFor(audio_format_t format) const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 224 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 225 | for (const auto &profile : *this) { | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 226 | if (profile->getFormat() == format && profile->isDynamicChannels()) { | 
|  | 227 | return true; | 
|  | 228 | } | 
|  | 229 | } | 
|  | 230 | return false; | 
|  | 231 | } | 
|  | 232 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 233 | bool AudioProfileVector::hasDynamicFormat() const | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 234 | { | 
|  | 235 | for (const auto &profile : *this) { | 
|  | 236 | if (profile->isDynamicFormat()) { | 
|  | 237 | return true; | 
|  | 238 | } | 
|  | 239 | } | 
|  | 240 | return false; | 
|  | 241 | } | 
|  | 242 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 243 | bool AudioProfileVector::hasDynamicProfile() const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 244 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 245 | for (const auto &profile : *this) { | 
|  | 246 | if (profile->isDynamic()) { | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 247 | return true; | 
|  | 248 | } | 
|  | 249 | } | 
|  | 250 | return false; | 
|  | 251 | } | 
|  | 252 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 253 | bool AudioProfileVector::hasDynamicRateFor(audio_format_t format) const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 254 | { | 
| jiabin | 4562b3b | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 255 | for (const auto &profile : *this) { | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 256 | if (profile->getFormat() == format && profile->isDynamicRate()) { | 
|  | 257 | return true; | 
|  | 258 | } | 
|  | 259 | } | 
|  | 260 | return false; | 
|  | 261 | } | 
|  | 262 |  | 
| jiabin | b9733bc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 263 | void AudioProfileVector::dump(std::string *dst, int spaces) const | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 264 | { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 265 | dst->append(base::StringPrintf("%*s- Profiles:\n", spaces, "")); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 266 | for (size_t i = 0; i < size(); i++) { | 
| jiabin | b677643 | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 267 | dst->append(base::StringPrintf("%*sProfile %zu:", spaces + 4, "", i)); | 
|  | 268 | std::string profileStr; | 
|  | 269 | at(i)->dump(&profileStr, spaces + 8); | 
|  | 270 | dst->append(profileStr); | 
| Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 271 | } | 
|  | 272 | } | 
|  | 273 |  | 
| jiabin | d19519a | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 274 | status_t AudioProfileVector::writeToParcel(Parcel *parcel) const | 
|  | 275 | { | 
|  | 276 | status_t status = NO_ERROR; | 
|  | 277 | if ((status = parcel->writeVectorSize(*this)) != NO_ERROR) return status; | 
|  | 278 | for (const auto &audioProfile : *this) { | 
|  | 279 | if ((status = parcel->writeParcelable(*audioProfile)) != NO_ERROR) { | 
|  | 280 | break; | 
|  | 281 | } | 
|  | 282 | } | 
|  | 283 | return status; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | status_t AudioProfileVector::readFromParcel(const Parcel *parcel) | 
|  | 287 | { | 
|  | 288 | status_t status = NO_ERROR; | 
|  | 289 | this->clear(); | 
|  | 290 | if ((status = parcel->resizeOutVector(this)) != NO_ERROR) return status; | 
|  | 291 | for (size_t i = 0; i < this->size(); ++i) { | 
|  | 292 | this->at(i) = new AudioProfile(AUDIO_FORMAT_DEFAULT, AUDIO_CHANNEL_NONE, 0 /*sampleRate*/); | 
|  | 293 | if ((status = parcel->readParcelable(this->at(i).get())) != NO_ERROR) { | 
|  | 294 | this->clear(); | 
|  | 295 | break; | 
|  | 296 | } | 
|  | 297 | } | 
|  | 298 | return status; | 
|  | 299 | } | 
|  | 300 |  | 
| jiabin | 0da24a3 | 2019-10-15 16:04:13 -0700 | [diff] [blame] | 301 | bool AudioProfileVector::equals(const AudioProfileVector& other) const | 
|  | 302 | { | 
|  | 303 | return std::equal(begin(), end(), other.begin(), other.end(), | 
|  | 304 | [](const sp<AudioProfile>& left, const sp<AudioProfile>& right) { | 
|  | 305 | return left->equals(right); | 
|  | 306 | }); | 
|  | 307 | } | 
|  | 308 |  | 
| Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 309 | } // namespace android |