• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <policy.h>
20 #include <system/audio_effect.h>
21 #include <utils/KeyedVector.h>
22 #include <utils/RefBase.h>
23 #include <utils/Errors.h>
24 #include <utils/String8.h>
25 
26 namespace android {
27 
28 class EffectDescriptor : public RefBase
29 {
30 public:
EffectDescriptor(const effect_descriptor_t * desc,bool isMusicEffect,int id,audio_io_handle_t io,audio_session_t session)31     EffectDescriptor(const effect_descriptor_t *desc, bool isMusicEffect,
32                      int id, audio_io_handle_t io, audio_session_t session) :
33         mId(id), mIo(io), mSession(session), mEnabled(false), mSuspended(false),
34         mIsMusicEffect(isMusicEffect)
35     {
36         memcpy (&mDesc, desc, sizeof(effect_descriptor_t));
37     }
38 
39     void dump(String8 *dst, int spaces = 0) const;
40 
41     int mId;                   // effect unique ID
42     audio_io_handle_t mIo;     // io the effect is attached to
43     audio_session_t mSession;  // audio session the effect is on
44     effect_descriptor_t mDesc; // effect descriptor
45     bool mEnabled;             // enabled state: CPU load being used or not
46     bool mSuspended;           // enabled but suspended by concurent capture policy
47 
isMusicEffect()48     bool isMusicEffect() const { return mIsMusicEffect; }
49 
50 private:
51     bool mIsMusicEffect;
52 };
53 
54 class EffectDescriptorCollection : public KeyedVector<int, sp<EffectDescriptor> >
55 {
56 public:
57     EffectDescriptorCollection();
58 
59     status_t registerEffect(const effect_descriptor_t *desc, audio_io_handle_t io,
60                             int session, int id, bool isMusicEffect);
61     status_t unregisterEffect(int id);
62     sp<EffectDescriptor> getEffect(int id) const;
63     EffectDescriptorCollection getEffectsForIo(audio_io_handle_t io) const;
64     status_t setEffectEnabled(int id, bool enabled);
65     bool     isEffectEnabled(int id) const;
66     uint32_t getMaxEffectsCpuLoad() const;
67     uint32_t getMaxEffectsMemory() const;
68     bool isNonOffloadableEffectEnabled() const;
69 
70     void moveEffects(audio_session_t session,
71                      audio_io_handle_t srcOutput,
72                      audio_io_handle_t dstOutput);
73     void moveEffects(const std::vector<int>& ids, audio_io_handle_t dstOutput);
74 
75     void dump(String8 *dst, int spaces = 0, bool verbose = true) const;
76 
77 private:
78     status_t setEffectEnabled(const sp<EffectDescriptor> &effectDesc, bool enabled);
79 
80     uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects (in MIPS)
81     uint32_t mTotalEffectsMemory;  // current memory used by effects (in KB)
82     uint32_t mTotalEffectsMemoryMaxUsed; // maximum memory used by effects (in KB)
83 
84     /**
85      * Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
86      */
87     static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
88     /**
89      * Maximum memory allocated to audio effects in KB
90      */
91     static const uint32_t MAX_EFFECTS_MEMORY = 512;
92 };
93 
94 } // namespace android
95