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 // AudioMixMatchCriterion implementation 26 // AudioMixMatchCriterion(audio_usage_t usage,audio_source_t source,uint32_t rule)27AudioMixMatchCriterion::AudioMixMatchCriterion(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 mValue.mUsage = usage; 35 } else { 36 mValue.mSource = source; 37 } 38 } 39 readFromParcel(Parcel * parcel)40status_t AudioMixMatchCriterion::readFromParcel(Parcel *parcel) 41 { 42 mRule = parcel->readInt32(); 43 if (mRule == RULE_MATCH_ATTRIBUTE_USAGE || 44 mRule == RULE_EXCLUDE_ATTRIBUTE_USAGE) { 45 mValue.mUsage = (audio_usage_t)parcel->readInt32(); 46 } else { 47 mValue.mSource = (audio_source_t)parcel->readInt32(); 48 } 49 return NO_ERROR; 50 } 51 writeToParcel(Parcel * parcel) const52status_t AudioMixMatchCriterion::writeToParcel(Parcel *parcel) const 53 { 54 parcel->writeInt32(mRule); 55 parcel->writeInt32(mValue.mUsage); 56 return NO_ERROR; 57 } 58 59 // 60 // AudioMix implementation 61 // 62 readFromParcel(Parcel * parcel)63status_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 mDeviceType = (audio_devices_t) parcel->readInt32(); 71 mDeviceAddress = parcel->readString8(); 72 mCbFlags = (uint32_t)parcel->readInt32(); 73 size_t size = (size_t)parcel->readInt32(); 74 if (size > MAX_CRITERIA_PER_MIX) { 75 size = MAX_CRITERIA_PER_MIX; 76 } 77 for (size_t i = 0; i < size; i++) { 78 AudioMixMatchCriterion criterion; 79 if (criterion.readFromParcel(parcel) == NO_ERROR) { 80 mCriteria.add(criterion); 81 } 82 } 83 return NO_ERROR; 84 } 85 writeToParcel(Parcel * parcel) const86status_t AudioMix::writeToParcel(Parcel *parcel) const 87 { 88 parcel->writeInt32(mMixType); 89 parcel->writeInt32(mFormat.sample_rate); 90 parcel->writeInt32(mFormat.channel_mask); 91 parcel->writeInt32(mFormat.format); 92 parcel->writeInt32(mRouteFlags); 93 parcel->writeInt32(mDeviceType); 94 parcel->writeString8(mDeviceAddress); 95 parcel->writeInt32(mCbFlags); 96 size_t size = mCriteria.size(); 97 if (size > MAX_CRITERIA_PER_MIX) { 98 size = MAX_CRITERIA_PER_MIX; 99 } 100 size_t sizePosition = parcel->dataPosition(); 101 parcel->writeInt32(size); 102 size_t finalSize = size; 103 for (size_t i = 0; i < size; i++) { 104 size_t position = parcel->dataPosition(); 105 if (mCriteria[i].writeToParcel(parcel) != NO_ERROR) { 106 parcel->setDataPosition(position); 107 finalSize--; 108 } 109 } 110 if (size != finalSize) { 111 size_t position = parcel->dataPosition(); 112 parcel->setDataPosition(sizePosition); 113 parcel->writeInt32(finalSize); 114 parcel->setDataPosition(position); 115 } 116 return NO_ERROR; 117 } 118 119 } // namespace android 120