François Gaffie | 112b0af | 2015-11-19 16:13:25 +0100 | [diff] [blame] | 1 | /* |
jiabin | 3e277cc | 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 | 9bb3a1e | 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 | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 22 | #include <android-base/stringprintf.h> |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 23 | #include <media/AudioContainers.h> |
jiabin | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 40 | AudioProfile* dynamicProfile = new AudioProfile(dynamicFormat, |
jiabin | 06e4bab | 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 | 9bb3a1e | 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 | 06e4bab | 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 | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 59 | const ChannelMaskSet &channelMasks, |
| 60 | const SampleRateSet &samplingRateCollection) : |
jiabin | 9bb3a1e | 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 | 06e4bab | 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 | 06e4bab | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 9bb3a1e | 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 | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 102 | if (!mSamplingRates.empty()) { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 103 | dst->append(base::StringPrintf("%*s- sampling rates:", spaces, "")); |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 104 | for (auto it = mSamplingRates.begin(); it != mSamplingRates.end();) { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 105 | dst->append(base::StringPrintf("%d", *it)); |
jiabin | 06e4bab | 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 | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 111 | if (!mChannelMasks.empty()) { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 112 | dst->append(base::StringPrintf("%*s- channel masks:", spaces, "")); |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 113 | for (auto it = mChannelMasks.begin(); it != mChannelMasks.end();) { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 114 | dst->append(base::StringPrintf("0x%04x", *it)); |
jiabin | 06e4bab | 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 | 49e69a1 | 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 | |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 133 | AudioProfile& AudioProfile::operator=(const AudioProfile& other) { |
| 134 | mName = other.mName; |
| 135 | mFormat = other.mFormat; |
| 136 | mChannelMasks = other.mChannelMasks; |
| 137 | mSamplingRates = other.mSamplingRates; |
| 138 | mIsDynamicFormat = other.mIsDynamicFormat; |
| 139 | mIsDynamicChannels = other.mIsDynamicChannels; |
| 140 | mIsDynamicRate = other.mIsDynamicRate; |
| 141 | return *this; |
jiabin | 17058fa | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 144 | status_t AudioProfile::writeToParcel(Parcel *parcel) const { |
| 145 | media::AudioProfile parcelable = VALUE_OR_RETURN_STATUS(toParcelable()); |
| 146 | return parcelable.writeToParcel(parcel); |
| 147 | } |
| 148 | |
| 149 | ConversionResult<media::AudioProfile> |
| 150 | AudioProfile::toParcelable() const { |
| 151 | media::AudioProfile parcelable; |
| 152 | parcelable.name = mName; |
| 153 | parcelable.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(mFormat)); |
| 154 | parcelable.channelMasks = VALUE_OR_RETURN( |
| 155 | convertContainer<std::vector<int32_t>>(mChannelMasks, |
| 156 | legacy2aidl_audio_channel_mask_t_int32_t)); |
| 157 | parcelable.samplingRates = VALUE_OR_RETURN( |
| 158 | convertContainer<std::vector<int32_t>>(mSamplingRates, |
| 159 | convertIntegral<int32_t, uint32_t>)); |
| 160 | parcelable.isDynamicFormat = mIsDynamicFormat; |
| 161 | parcelable.isDynamicChannels = mIsDynamicChannels; |
| 162 | parcelable.isDynamicRate = mIsDynamicRate; |
| 163 | return parcelable; |
| 164 | } |
| 165 | |
| 166 | status_t AudioProfile::readFromParcel(const Parcel *parcel) { |
| 167 | media::AudioProfile parcelable; |
| 168 | if (status_t status = parcelable.readFromParcel(parcel); status != OK) { |
jiabin | 17058fa | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 169 | return status; |
| 170 | } |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 171 | *this = *VALUE_OR_RETURN_STATUS(fromParcelable(parcelable)); |
| 172 | return OK; |
| 173 | } |
| 174 | |
| 175 | ConversionResult<sp<AudioProfile>> |
| 176 | AudioProfile::fromParcelable(const media::AudioProfile& parcelable) { |
| 177 | sp<AudioProfile> legacy = new AudioProfile(); |
| 178 | legacy->mName = parcelable.name; |
| 179 | legacy->mFormat = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(parcelable.format)); |
| 180 | legacy->mChannelMasks = VALUE_OR_RETURN( |
| 181 | convertContainer<ChannelMaskSet>(parcelable.channelMasks, |
| 182 | aidl2legacy_int32_t_audio_channel_mask_t)); |
| 183 | legacy->mSamplingRates = VALUE_OR_RETURN( |
| 184 | convertContainer<SampleRateSet>(parcelable.samplingRates, |
| 185 | convertIntegral<uint32_t, int32_t>)); |
| 186 | legacy->mIsDynamicFormat = parcelable.isDynamicFormat; |
| 187 | legacy->mIsDynamicChannels = parcelable.isDynamicChannels; |
| 188 | legacy->mIsDynamicRate = parcelable.isDynamicRate; |
| 189 | return legacy; |
| 190 | } |
| 191 | |
| 192 | ConversionResult<sp<AudioProfile>> |
| 193 | aidl2legacy_AudioProfile(const media::AudioProfile& aidl) { |
| 194 | return AudioProfile::fromParcelable(aidl); |
| 195 | } |
| 196 | |
| 197 | ConversionResult<media::AudioProfile> |
| 198 | legacy2aidl_AudioProfile(const sp<AudioProfile>& legacy) { |
| 199 | return legacy->toParcelable(); |
jiabin | 17058fa | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 200 | } |
| 201 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 202 | ssize_t AudioProfileVector::add(const sp<AudioProfile> &profile) |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 203 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 204 | ssize_t index = size(); |
| 205 | push_back(profile); |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 206 | return index; |
| 207 | } |
| 208 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 209 | void AudioProfileVector::clearProfiles() |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 210 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 211 | for (auto it = begin(); it != end();) { |
| 212 | if ((*it)->isDynamicFormat() && (*it)->hasValidFormat()) { |
| 213 | it = erase(it); |
| 214 | } else { |
| 215 | (*it)->clear(); |
| 216 | ++it; |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 217 | } |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 221 | sp<AudioProfile> AudioProfileVector::getFirstValidProfile() const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 222 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 223 | for (const auto &profile : *this) { |
| 224 | if (profile->isValid()) { |
| 225 | return profile; |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 228 | return nullptr; |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 229 | } |
| 230 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 231 | sp<AudioProfile> AudioProfileVector::getFirstValidProfileFor(audio_format_t format) const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 232 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 233 | for (const auto &profile : *this) { |
| 234 | if (profile->isValid() && profile->getFormat() == format) { |
| 235 | return profile; |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 238 | return nullptr; |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 239 | } |
| 240 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 241 | FormatVector AudioProfileVector::getSupportedFormats() const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 242 | { |
| 243 | FormatVector supportedFormats; |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 244 | for (const auto &profile : *this) { |
| 245 | if (profile->hasValidFormat()) { |
| 246 | supportedFormats.push_back(profile->getFormat()); |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | return supportedFormats; |
| 250 | } |
| 251 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 252 | bool AudioProfileVector::hasDynamicChannelsFor(audio_format_t format) const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 253 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 254 | for (const auto &profile : *this) { |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 255 | if (profile->getFormat() == format && profile->isDynamicChannels()) { |
| 256 | return true; |
| 257 | } |
| 258 | } |
| 259 | return false; |
| 260 | } |
| 261 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 262 | bool AudioProfileVector::hasDynamicFormat() const |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 263 | { |
| 264 | for (const auto &profile : *this) { |
| 265 | if (profile->isDynamicFormat()) { |
| 266 | return true; |
| 267 | } |
| 268 | } |
| 269 | return false; |
| 270 | } |
| 271 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 272 | bool AudioProfileVector::hasDynamicProfile() const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 273 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 274 | for (const auto &profile : *this) { |
| 275 | if (profile->isDynamic()) { |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 276 | return true; |
| 277 | } |
| 278 | } |
| 279 | return false; |
| 280 | } |
| 281 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 282 | bool AudioProfileVector::hasDynamicRateFor(audio_format_t format) const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 283 | { |
jiabin | 06e4bab | 2019-07-29 10:13:34 -0700 | [diff] [blame] | 284 | for (const auto &profile : *this) { |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 285 | if (profile->getFormat() == format && profile->isDynamicRate()) { |
| 286 | return true; |
| 287 | } |
| 288 | } |
| 289 | return false; |
| 290 | } |
| 291 | |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 292 | bool AudioProfileVector::contains(const sp<AudioProfile>& profile) const |
| 293 | { |
| 294 | for (const auto& audioProfile : *this) { |
| 295 | if (audioProfile->equals(profile)) { |
| 296 | return true; |
| 297 | } |
| 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | |
jiabin | 3e277cc | 2019-09-10 14:27:34 -0700 | [diff] [blame] | 302 | void AudioProfileVector::dump(std::string *dst, int spaces) const |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 303 | { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 304 | dst->append(base::StringPrintf("%*s- Profiles:\n", spaces, "")); |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 305 | for (size_t i = 0; i < size(); i++) { |
jiabin | 9bb3a1e | 2019-08-19 10:10:17 -0700 | [diff] [blame] | 306 | dst->append(base::StringPrintf("%*sProfile %zu:", spaces + 4, "", i)); |
| 307 | std::string profileStr; |
| 308 | at(i)->dump(&profileStr, spaces + 8); |
| 309 | dst->append(profileStr); |
Mikhail Naganov | e50f628 | 2018-07-26 16:20:43 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
jiabin | 17058fa | 2019-10-08 17:33:38 -0700 | [diff] [blame] | 313 | status_t AudioProfileVector::writeToParcel(Parcel *parcel) const |
| 314 | { |
| 315 | status_t status = NO_ERROR; |
| 316 | if ((status = parcel->writeVectorSize(*this)) != NO_ERROR) return status; |
| 317 | for (const auto &audioProfile : *this) { |
| 318 | if ((status = parcel->writeParcelable(*audioProfile)) != NO_ERROR) { |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | return status; |
| 323 | } |
| 324 | |
| 325 | status_t AudioProfileVector::readFromParcel(const Parcel *parcel) |
| 326 | { |
| 327 | status_t status = NO_ERROR; |
| 328 | this->clear(); |
| 329 | if ((status = parcel->resizeOutVector(this)) != NO_ERROR) return status; |
| 330 | for (size_t i = 0; i < this->size(); ++i) { |
| 331 | this->at(i) = new AudioProfile(AUDIO_FORMAT_DEFAULT, AUDIO_CHANNEL_NONE, 0 /*sampleRate*/); |
| 332 | if ((status = parcel->readParcelable(this->at(i).get())) != NO_ERROR) { |
| 333 | this->clear(); |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | return status; |
| 338 | } |
| 339 | |
jiabin | 49e69a1 | 2019-10-15 16:04:13 -0700 | [diff] [blame] | 340 | bool AudioProfileVector::equals(const AudioProfileVector& other) const |
| 341 | { |
| 342 | return std::equal(begin(), end(), other.begin(), other.end(), |
| 343 | [](const sp<AudioProfile>& left, const sp<AudioProfile>& right) { |
| 344 | return left->equals(right); |
| 345 | }); |
| 346 | } |
| 347 | |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 348 | ConversionResult<AudioProfileVector> |
| 349 | aidl2legacy_AudioProfileVector(const std::vector<media::AudioProfile>& aidl) { |
| 350 | return convertContainer<AudioProfileVector>(aidl, aidl2legacy_AudioProfile); |
| 351 | } |
| 352 | |
| 353 | ConversionResult<std::vector<media::AudioProfile>> |
| 354 | legacy2aidl_AudioProfileVector(const AudioProfileVector& legacy) { |
| 355 | return convertContainer<std::vector<media::AudioProfile>>(legacy, legacy2aidl_AudioProfile); |
| 356 | } |
| 357 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 358 | } // namespace android |