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