blob: e19db126ad4e5626e2f9a256c0ac5f7a85bce9a1 [file] [log] [blame]
Mikhail Naganova331de12017-01-04 16:33:55 -08001/*
2 * Copyright (C) 2017 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#ifndef android_hardware_audio_effect_V2_0_AudioBufferManager_H_
18#define android_hardware_audio_effect_V2_0_AudioBufferManager_H_
19
20#include <mutex>
21
22#include <android/hardware/audio/effect/2.0/types.h>
23#include <android/hidl/memory/1.0/IMemory.h>
24#include <system/audio_effect.h>
Mikhail Naganova331de12017-01-04 16:33:55 -080025#include <utils/KeyedVector.h>
Kevin Rocard22505e62017-12-14 18:50:12 -080026#include <utils/RefBase.h>
Mikhail Naganova331de12017-01-04 16:33:55 -080027#include <utils/Singleton.h>
28
29using ::android::hardware::audio::effect::V2_0::AudioBuffer;
30using ::android::hidl::memory::V1_0::IMemory;
31
32namespace android {
33namespace hardware {
34namespace audio {
35namespace effect {
36namespace V2_0 {
37namespace implementation {
38
39class AudioBufferWrapper : public RefBase {
Kevin Rocard22505e62017-12-14 18:50:12 -080040 public:
Mikhail Naganova331de12017-01-04 16:33:55 -080041 explicit AudioBufferWrapper(const AudioBuffer& buffer);
42 virtual ~AudioBufferWrapper();
43 bool init();
44 audio_buffer_t* getHalBuffer() { return &mHalBuffer; }
Kevin Rocard22505e62017-12-14 18:50:12 -080045
46 private:
Mikhail Naganova331de12017-01-04 16:33:55 -080047 AudioBufferWrapper(const AudioBufferWrapper&) = delete;
48 void operator=(AudioBufferWrapper) = delete;
49
50 AudioBuffer mHidlBuffer;
51 sp<IMemory> mHidlMemory;
52 audio_buffer_t mHalBuffer;
53};
54
55} // namespace implementation
56} // namespace V2_0
57} // namespace effect
58} // namespace audio
59} // namespace hardware
60} // namespace android
61
62using ::android::hardware::audio::effect::V2_0::implementation::AudioBufferWrapper;
63
64namespace android {
65
66// This class needs to be in 'android' ns because Singleton macros require that.
67class AudioBufferManager : public Singleton<AudioBufferManager> {
Kevin Rocard22505e62017-12-14 18:50:12 -080068 public:
Mikhail Naganova331de12017-01-04 16:33:55 -080069 bool wrap(const AudioBuffer& buffer, sp<AudioBufferWrapper>* wrapper);
70
Kevin Rocard22505e62017-12-14 18:50:12 -080071 private:
Mikhail Naganova331de12017-01-04 16:33:55 -080072 friend class hardware::audio::effect::V2_0::implementation::AudioBufferWrapper;
73
74 // Called by AudioBufferWrapper.
75 void removeEntry(uint64_t id);
76
77 std::mutex mLock;
78 KeyedVector<uint64_t, wp<AudioBufferWrapper>> mBuffers;
79};
80
81} // namespace android
82
83#endif // android_hardware_audio_effect_V2_0_AudioBufferManager_H_