Phil Burk | 420715b | 2017-12-14 12:26:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 OBOE_OUTPUT_MIXER_OPENSLES_H |
| 18 | #define OBOE_OUTPUT_MIXER_OPENSLES_H |
| 19 | |
| 20 | #include <atomic> |
| 21 | #include <mutex> |
| 22 | |
| 23 | #include <SLES/OpenSLES.h> |
| 24 | #include <SLES/OpenSLES_Android.h> |
| 25 | |
| 26 | namespace oboe { |
| 27 | |
| 28 | /** |
| 29 | * INTERNAL USE ONLY |
| 30 | */ |
| 31 | |
| 32 | class OutputMixerOpenSL { |
| 33 | public: |
Phil Burk | 7040a9d | 2017-12-15 10:54:38 -0800 | [diff] [blame] | 34 | static OutputMixerOpenSL &getInstance(); |
Phil Burk | 420715b | 2017-12-14 12:26:38 -0800 | [diff] [blame] | 35 | |
| 36 | SLresult open(); |
| 37 | |
| 38 | void close(); |
| 39 | |
| 40 | SLresult createAudioPlayer(SLObjectItf *objectItf, |
| 41 | SLDataSource *audioSource); |
| 42 | |
| 43 | private: |
Phil Burk | 7040a9d | 2017-12-15 10:54:38 -0800 | [diff] [blame] | 44 | // Make this a safe Singleton |
| 45 | OutputMixerOpenSL()= default; |
| 46 | ~OutputMixerOpenSL()= default; |
| 47 | OutputMixerOpenSL(const OutputMixerOpenSL&)= delete; |
| 48 | OutputMixerOpenSL& operator=(const OutputMixerOpenSL&)= delete; |
| 49 | |
Phil Burk | 420715b | 2017-12-14 12:26:38 -0800 | [diff] [blame] | 50 | std::mutex mLock; |
Phil Burk | 7040a9d | 2017-12-15 10:54:38 -0800 | [diff] [blame] | 51 | int32_t mOpenCount = 0; |
| 52 | |
Phil Burk | 420715b | 2017-12-14 12:26:38 -0800 | [diff] [blame] | 53 | SLObjectItf mOutputMixObject = 0; |
| 54 | }; |
| 55 | |
| 56 | } // namespace oboe |
| 57 | |
| 58 | #endif //OBOE_OUTPUT_MIXER_OPENSLES_H |