1 /* 2 * Copyright (C) 2015 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 #pragma once 18 19 #include <binder/Parcel.h> 20 #include <binder/Parcelable.h> 21 #include <utils/Errors.h> 22 #include <utils/RefBase.h> 23 #include <system/audio.h> 24 #include <string> 25 #include <vector> 26 27 namespace android { 28 29 class AudioGain: public RefBase, public Parcelable 30 { 31 public: 32 AudioGain(int index, bool useInChannelMask); ~AudioGain()33 virtual ~AudioGain() {} 34 setMode(audio_gain_mode_t mode)35 void setMode(audio_gain_mode_t mode) { mGain.mode = mode; } getMode()36 const audio_gain_mode_t &getMode() const { return mGain.mode; } 37 setChannelMask(audio_channel_mask_t mask)38 void setChannelMask(audio_channel_mask_t mask) { mGain.channel_mask = mask; } getChannelMask()39 const audio_channel_mask_t &getChannelMask() const { return mGain.channel_mask; } 40 setMinValueInMb(int minValue)41 void setMinValueInMb(int minValue) { mGain.min_value = minValue; } getMinValueInMb()42 int getMinValueInMb() const { return mGain.min_value; } 43 setMaxValueInMb(int maxValue)44 void setMaxValueInMb(int maxValue) { mGain.max_value = maxValue; } getMaxValueInMb()45 int getMaxValueInMb() const { return mGain.max_value; } 46 setDefaultValueInMb(int defaultValue)47 void setDefaultValueInMb(int defaultValue) { mGain.default_value = defaultValue; } getDefaultValueInMb()48 int getDefaultValueInMb() const { return mGain.default_value; } 49 setStepValueInMb(uint32_t stepValue)50 void setStepValueInMb(uint32_t stepValue) { mGain.step_value = stepValue; } getStepValueInMb()51 int getStepValueInMb() const { return mGain.step_value; } 52 setMinRampInMs(uint32_t minRamp)53 void setMinRampInMs(uint32_t minRamp) { mGain.min_ramp_ms = minRamp; } getMinRampInMs()54 int getMinRampInMs() const { return mGain.min_ramp_ms; } 55 setMaxRampInMs(uint32_t maxRamp)56 void setMaxRampInMs(uint32_t maxRamp) { mGain.max_ramp_ms = maxRamp; } getMaxRampInMs()57 int getMaxRampInMs() const { return mGain.max_ramp_ms; } 58 59 // TODO: remove dump from here (split serialization) 60 void dump(std::string *dst, int spaces, int index) const; 61 62 void getDefaultConfig(struct audio_gain_config *config); 63 status_t checkConfig(const struct audio_gain_config *config); 64 setUseForVolume(bool canUseForVolume)65 void setUseForVolume(bool canUseForVolume) { mUseForVolume = canUseForVolume; } canUseForVolume()66 bool canUseForVolume() const { return mUseForVolume; } 67 getGain()68 const struct audio_gain &getGain() const { return mGain; } 69 70 bool equals(const sp<AudioGain>& other) const; 71 72 status_t writeToParcel(Parcel* parcel) const override; 73 status_t readFromParcel(const Parcel* parcel) override; 74 75 private: 76 int mIndex; 77 struct audio_gain mGain; 78 bool mUseInChannelMask; 79 bool mUseForVolume = false; 80 }; 81 82 class AudioGains : public std::vector<sp<AudioGain> >, public Parcelable 83 { 84 public: canUseForVolume()85 bool canUseForVolume() const 86 { 87 for (const auto &gain: *this) { 88 if (gain->canUseForVolume()) { 89 return true; 90 } 91 } 92 return false; 93 } 94 add(const sp<AudioGain> gain)95 int32_t add(const sp<AudioGain> gain) 96 { 97 push_back(gain); 98 return 0; 99 } 100 101 bool equals(const AudioGains& other) const; 102 103 status_t writeToParcel(Parcel* parcel) const override; 104 status_t readFromParcel(const Parcel* parcel) override; 105 }; 106 107 } // namespace android 108