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