Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 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 | |
| 17 | #define LOG_TAG "AudioPolicy" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | #include <media/AudioPolicy.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | // |
| 25 | // AttributeMatchCriterion implementation |
| 26 | // |
| 27 | AttributeMatchCriterion::AttributeMatchCriterion(audio_usage_t usage, |
| 28 | audio_source_t source, |
| 29 | uint32_t rule) |
| 30 | : mRule(rule) |
| 31 | { |
| 32 | if (mRule == RULE_MATCH_ATTRIBUTE_USAGE || |
| 33 | mRule == RULE_EXCLUDE_ATTRIBUTE_USAGE) { |
| 34 | mAttr.mUsage = usage; |
| 35 | } else { |
| 36 | mAttr.mSource = source; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | status_t AttributeMatchCriterion::readFromParcel(Parcel *parcel) |
| 41 | { |
| 42 | mRule = parcel->readInt32(); |
| 43 | if (mRule == RULE_MATCH_ATTRIBUTE_USAGE || |
| 44 | mRule == RULE_EXCLUDE_ATTRIBUTE_USAGE) { |
| 45 | mAttr.mUsage = (audio_usage_t)parcel->readInt32(); |
| 46 | } else { |
| 47 | mAttr.mSource = (audio_source_t)parcel->readInt32(); |
| 48 | } |
| 49 | return NO_ERROR; |
| 50 | } |
| 51 | |
| 52 | status_t AttributeMatchCriterion::writeToParcel(Parcel *parcel) const |
| 53 | { |
| 54 | parcel->writeInt32(mRule); |
| 55 | parcel->writeInt32(mAttr.mUsage); |
| 56 | return NO_ERROR; |
| 57 | } |
| 58 | |
| 59 | // |
| 60 | // AudioMix implementation |
| 61 | // |
| 62 | |
| 63 | status_t AudioMix::readFromParcel(Parcel *parcel) |
| 64 | { |
| 65 | mMixType = parcel->readInt32(); |
| 66 | mFormat.sample_rate = (uint32_t)parcel->readInt32(); |
| 67 | mFormat.channel_mask = (audio_channel_mask_t)parcel->readInt32(); |
| 68 | mFormat.format = (audio_format_t)parcel->readInt32(); |
| 69 | mRouteFlags = parcel->readInt32(); |
| 70 | mRegistrationId = parcel->readString8(); |
| 71 | size_t size = (size_t)parcel->readInt32(); |
| 72 | if (size > MAX_CRITERIA_PER_MIX) { |
| 73 | size = MAX_CRITERIA_PER_MIX; |
| 74 | } |
| 75 | for (size_t i = 0; i < size; i++) { |
| 76 | AttributeMatchCriterion criterion; |
| 77 | if (criterion.readFromParcel(parcel) == NO_ERROR) { |
| 78 | mCriteria.add(criterion); |
| 79 | } |
| 80 | } |
| 81 | return NO_ERROR; |
| 82 | } |
| 83 | |
| 84 | status_t AudioMix::writeToParcel(Parcel *parcel) const |
| 85 | { |
| 86 | parcel->writeInt32(mMixType); |
| 87 | parcel->writeInt32(mFormat.sample_rate); |
| 88 | parcel->writeInt32(mFormat.channel_mask); |
| 89 | parcel->writeInt32(mFormat.format); |
| 90 | parcel->writeInt32(mRouteFlags); |
| 91 | parcel->writeString8(mRegistrationId); |
| 92 | size_t size = mCriteria.size(); |
| 93 | if (size > MAX_CRITERIA_PER_MIX) { |
| 94 | size = MAX_CRITERIA_PER_MIX; |
| 95 | } |
| 96 | size_t sizePosition = parcel->dataPosition(); |
| 97 | parcel->writeInt32(size); |
| 98 | size_t finalSize = size; |
| 99 | for (size_t i = 0; i < size; i++) { |
| 100 | size_t position = parcel->dataPosition(); |
| 101 | if (mCriteria[i].writeToParcel(parcel) != NO_ERROR) { |
| 102 | parcel->setDataPosition(position); |
| 103 | finalSize--; |
| 104 | } |
| 105 | } |
| 106 | if (size != finalSize) { |
| 107 | size_t position = parcel->dataPosition(); |
| 108 | parcel->setDataPosition(sizePosition); |
| 109 | parcel->writeInt32(finalSize); |
| 110 | parcel->setDataPosition(position); |
| 111 | } |
| 112 | return NO_ERROR; |
| 113 | } |
| 114 | |
| 115 | }; // namespace android |