blob: 8b956cdb9be00619ab2f4c93fbdb2a53e0fff6a5 [file] [log] [blame]
Mikhail Naganova331de12017-01-04 16:33:55 -08001/*
Kevin Rocard96d2cd92018-11-14 16:22:07 -08002 * Copyright (C) 2018 The Android Open Source Project
Mikhail Naganova331de12017-01-04 16:33:55 -08003 *
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
Kevin Rocard96d2cd92018-11-14 16:22:07 -080017#ifndef ANDROID_HARDWARE_AUDIO_EFFECT_AUDIO_BUFFER_MANAGER_H_
18#define ANDROID_HARDWARE_AUDIO_EFFECT_AUDIO_BUFFER_MANAGER_H_
19
20#include PATH(android/hardware/audio/effect/FILE_VERSION/types.h)
Mikhail Naganova331de12017-01-04 16:33:55 -080021
22#include <mutex>
23
Mikhail Naganova331de12017-01-04 16:33:55 -080024#include <android/hidl/memory/1.0/IMemory.h>
25#include <system/audio_effect.h>
Mikhail Naganova331de12017-01-04 16:33:55 -080026#include <utils/KeyedVector.h>
Kevin Rocard22505e62017-12-14 18:50:12 -080027#include <utils/RefBase.h>
Mikhail Naganova331de12017-01-04 16:33:55 -080028#include <utils/Singleton.h>
29
Kevin Rocard96d2cd92018-11-14 16:22:07 -080030using ::android::hardware::audio::effect::CPP_VERSION::AudioBuffer;
Mikhail Naganova331de12017-01-04 16:33:55 -080031using ::android::hidl::memory::V1_0::IMemory;
32
33namespace android {
34namespace hardware {
35namespace audio {
36namespace effect {
Kevin Rocard96d2cd92018-11-14 16:22:07 -080037namespace CPP_VERSION {
Mikhail Naganova331de12017-01-04 16:33:55 -080038namespace implementation {
39
40class AudioBufferWrapper : public RefBase {
Kevin Rocard22505e62017-12-14 18:50:12 -080041 public:
Mikhail Naganova331de12017-01-04 16:33:55 -080042 explicit AudioBufferWrapper(const AudioBuffer& buffer);
43 virtual ~AudioBufferWrapper();
44 bool init();
45 audio_buffer_t* getHalBuffer() { return &mHalBuffer; }
Kevin Rocard22505e62017-12-14 18:50:12 -080046
47 private:
Mikhail Naganova331de12017-01-04 16:33:55 -080048 AudioBufferWrapper(const AudioBufferWrapper&) = delete;
49 void operator=(AudioBufferWrapper) = delete;
50
51 AudioBuffer mHidlBuffer;
52 sp<IMemory> mHidlMemory;
53 audio_buffer_t mHalBuffer;
54};
55
56} // namespace implementation
Kevin Rocard96d2cd92018-11-14 16:22:07 -080057} // namespace CPP_VERSION
Mikhail Naganova331de12017-01-04 16:33:55 -080058} // namespace effect
59} // namespace audio
60} // namespace hardware
61} // namespace android
62
Kevin Rocard96d2cd92018-11-14 16:22:07 -080063using ::android::hardware::audio::effect::CPP_VERSION::implementation::AudioBufferWrapper;
Mikhail Naganova331de12017-01-04 16:33:55 -080064
65namespace android {
66
67// This class needs to be in 'android' ns because Singleton macros require that.
68class AudioBufferManager : public Singleton<AudioBufferManager> {
Kevin Rocard22505e62017-12-14 18:50:12 -080069 public:
Mikhail Naganova331de12017-01-04 16:33:55 -080070 bool wrap(const AudioBuffer& buffer, sp<AudioBufferWrapper>* wrapper);
71
Kevin Rocard22505e62017-12-14 18:50:12 -080072 private:
Kevin Rocard96d2cd92018-11-14 16:22:07 -080073 friend class hardware::audio::effect::CPP_VERSION::implementation::AudioBufferWrapper;
Mikhail Naganova331de12017-01-04 16:33:55 -080074
75 // Called by AudioBufferWrapper.
76 void removeEntry(uint64_t id);
77
78 std::mutex mLock;
79 KeyedVector<uint64_t, wp<AudioBufferWrapper>> mBuffers;
80};
81
82} // namespace android
Kevin Rocard96d2cd92018-11-14 16:22:07 -080083
84#endif // ANDROID_HARDWARE_AUDIO_EFFECT_AUDIO_BUFFER_MANAGER_H_