blob: 6fa7940b21710931988787783010526fb4dcffea [file] [log] [blame]
Mikhail Naganov022b9952017-01-04 16:36:51 -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_EFFECT_BUFFER_HAL_INTERFACE_H
18#define ANDROID_HARDWARE_EFFECT_BUFFER_HAL_INTERFACE_H
19
20#include <system/audio_effect.h>
21#include <utils/Errors.h>
22#include <utils/RefBase.h>
23
24namespace android {
25
26// Abstraction for an audio buffer. It may be a "mirror" for
27// a buffer that the effect chain doesn't own, or a buffer owned by
28// the effect chain.
29class EffectBufferHalInterface : public RefBase
30{
31 public:
32 virtual audio_buffer_t* audioBuffer() = 0;
33 virtual void* externalData() const = 0;
34 // To be used when interacting with the code that doesn't know about
35 // "mirrored" buffers.
36 virtual void* ptr() {
37 return externalData() != nullptr ? externalData() : audioBuffer()->raw;
38 }
39
40 virtual void setExternalData(void* external) = 0;
41 virtual void setFrameCount(size_t frameCount) = 0;
42
43 virtual void update() = 0; // copies data from the external buffer, noop for allocated buffers
44 virtual void commit() = 0; // copies data to the external buffer, noop for allocated buffers
Mikhail Naganov66916c22017-01-24 17:46:33 -080045 virtual void update(size_t size) = 0; // copies partial data from external buffer
46 virtual void commit(size_t size) = 0; // copies partial data to external buffer
Mikhail Naganov022b9952017-01-04 16:36:51 -080047
48 static status_t allocate(size_t size, sp<EffectBufferHalInterface>* buffer);
49 static status_t mirror(void* external, size_t size, sp<EffectBufferHalInterface>* buffer);
50
51 protected:
52 // Subclasses can not be constructed directly by clients.
53 EffectBufferHalInterface() {}
54
55 virtual ~EffectBufferHalInterface() {}
56};
57
58} // namespace android
59
60#endif // ANDROID_HARDWARE_EFFECT_BUFFER_HAL_INTERFACE_H