EffectDescriptor.h revision 5f1fa3053c87dd8e9dc528fb8c101907ff747746
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 <RoutingStrategy.h>
20#include <hardware/audio_effect.h>
21#include <utils/KeyedVector.h>
22#include <utils/RefBase.h>
23#include <utils/Errors.h>
24
25namespace android {
26
27
28class EffectDescriptor : public RefBase
29{
30public:
31    status_t dump(int fd);
32
33    int mIo;                // io the effect is attached to
34    routing_strategy mStrategy; // routing strategy the effect is associated to
35    int mSession;               // audio session the effect is on
36    effect_descriptor_t mDesc;  // effect descriptor
37    bool mEnabled;              // enabled state: CPU load being used or not
38};
39
40class EffectDescriptorCollection : public KeyedVector<int, sp<EffectDescriptor> >
41{
42public:
43    EffectDescriptorCollection();
44
45    status_t registerEffect(const effect_descriptor_t *desc, audio_io_handle_t io,
46                            uint32_t strategy, int session, int id);
47    status_t unregisterEffect(int id);
48    status_t setEffectEnabled(int id, bool enabled);
49    uint32_t getMaxEffectsCpuLoad() const;
50    uint32_t getMaxEffectsMemory() const;
51    bool isNonOffloadableEffectEnabled();
52
53    status_t dump(int fd);
54
55private:
56    status_t setEffectEnabled(const sp<EffectDescriptor> &effectDesc, bool enabled);
57
58    uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects (in MIPS)
59    uint32_t mTotalEffectsMemory;  // current memory used by effects (in KB)
60    uint32_t mTotalEffectsMemoryMaxUsed; // maximum memory used by effects (in KB)
61
62    /**
63     * Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
64     */
65    static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
66    /**
67     * Maximum memory allocated to audio effects in KB
68     */
69    static const uint32_t MAX_EFFECTS_MEMORY = 512;
70};
71
72}; // namespace android
73