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 <string> 20 #include <utility> 21 #include <vector> 22 23 #include <android/media/AudioGainSys.h> 24 #include <media/AidlConversion.h> 25 #include <utils/Errors.h> 26 #include <utils/RefBase.h> 27 #include <system/audio.h> 28 29 namespace android { 30 31 class AudioGain: public RefBase 32 { 33 public: 34 AudioGain(int index, bool isInput); 35 virtual ~AudioGain() = default; 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 using Aidl = std::pair<media::audio::common::AudioGain, media::AudioGainSys>; 75 ConversionResult<Aidl> toParcelable() const; 76 static ConversionResult<sp<AudioGain>> fromParcelable(const Aidl& aidl); 77 78 private: 79 int mIndex; 80 bool mIsInput; 81 struct audio_gain mGain = {}; 82 bool mUseForVolume = false; 83 }; 84 85 // Conversion routines, according to AidlConversion.h conventions. 86 ConversionResult<sp<AudioGain>> 87 aidl2legacy_AudioGain(const AudioGain::Aidl& aidl); 88 ConversionResult<AudioGain::Aidl> 89 legacy2aidl_AudioGain(const sp<AudioGain>& legacy); 90 91 class AudioGains : public std::vector<sp<AudioGain>> 92 { 93 public: canUseForVolume()94 bool canUseForVolume() const 95 { 96 for (const auto &gain: *this) { 97 if (gain->canUseForVolume()) { 98 return true; 99 } 100 } 101 return false; 102 } 103 add(const sp<AudioGain> & gain)104 int32_t add(const sp<AudioGain>& gain) 105 { 106 push_back(gain); 107 return 0; 108 } 109 110 bool equals(const AudioGains& other) const; 111 112 using Aidl = std::pair< 113 std::vector<media::audio::common::AudioGain>, 114 std::vector<media::AudioGainSys>>; 115 }; 116 117 // Conversion routines, according to AidlConversion.h conventions. 118 ConversionResult<AudioGains> 119 aidl2legacy_AudioGains(const AudioGains::Aidl& aidl); 120 ConversionResult<AudioGains::Aidl> 121 legacy2aidl_AudioGains(const AudioGains& legacy); 122 123 } // namespace android 124