• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
24 namespace 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.
29 class 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.
ptr()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     virtual bool checkFrameCountChange() = 0;  // returns whether frame count has been updated
43                                                // since the last call to this method
44 
45     virtual void update() = 0;  // copies data from the external buffer, noop for allocated buffers
46     virtual void commit() = 0;  // copies data to the external buffer, noop for allocated buffers
47     virtual void update(size_t size) = 0;  // copies partial data from external buffer
48     virtual void commit(size_t size) = 0;  // copies partial data to external buffer
49 
50     static status_t allocate(size_t size, sp<EffectBufferHalInterface>* buffer);
51     static status_t mirror(void* external, size_t size, sp<EffectBufferHalInterface>* buffer);
52 
53   protected:
54     // Subclasses can not be constructed directly by clients.
EffectBufferHalInterface()55     EffectBufferHalInterface() {}
56 
~EffectBufferHalInterface()57     virtual ~EffectBufferHalInterface() {}
58 };
59 
60 } // namespace android
61 
62 #endif // ANDROID_HARDWARE_EFFECT_BUFFER_HAL_INTERFACE_H
63