Debian Codegraph @

platform/android/audio_driver_opensl.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_driver_opensl.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/os/mutex.h"
34 #include "servers/audio/audio_server.h"
35
36 #include <SLES/OpenSLES.h>
37 #include <SLES/OpenSLES_Android.h>
38
39 class AudioDriverOpenSL : public AudioDriver {
40 bool active = false;
41 Mutex mutex;
42
43 enum {
44 BUFFER_COUNT = 2
45 };
46
47 bool pause = false;
48
49 uint32_t buffer_size = 0;
50 int16_t *buffers[BUFFER_COUNT] = {};
51 int32_t *mixdown_buffer = nullptr;
52 int last_free = 0;
53
54 Vector<int16_t> rec_buffer;
55
56 SLPlayItf playItf = nullptr;
57 SLRecordItf recordItf = nullptr;
58 SLObjectItf sl = nullptr;
59 SLEngineItf EngineItf = nullptr;
60 SLObjectItf OutputMix = nullptr;
61 SLObjectItf player = nullptr;
62 SLObjectItf recorder = nullptr;
63 SLAndroidSimpleBufferQueueItf bufferQueueItf = nullptr;
64 SLAndroidSimpleBufferQueueItf recordBufferQueueItf = nullptr;
65 SLDataSource audioSource;
66 SLDataFormat_PCM pcm;
67 SLDataSink audioSink;
68 SLDataLocator_OutputMix locator_outputmix;
69
70 static AudioDriverOpenSL *s_ad;
71
72 void _buffer_callback(
73 SLAndroidSimpleBufferQueueItf queueItf);
74
75 static void _buffer_callbacks(
76 SLAndroidSimpleBufferQueueItf queueItf,
77 void *pContext);
78
79 void _record_buffer_callback(
80 SLAndroidSimpleBufferQueueItf queueItf);
81
82 static void _record_buffer_callbacks(
83 SLAndroidSimpleBufferQueueItf queueItf,
84 void *pContext);
85
86 Error init_input_device();
87
88 public:
89 virtual const char *get_name() const override {
90 return "Android";
91 }
92
93 virtual Error init() override;
94 virtual void start() override;
95 virtual int get_mix_rate() const override;
96 virtual SpeakerMode get_speaker_mode() const override;
97
98 virtual void lock() override;
99 virtual void unlock() override;
100 virtual void finish() override;
101
102 virtual Error input_start() override;
103 virtual Error input_stop() override;
104
105 void set_pause(bool p_pause);
106
107 AudioDriverOpenSL();
108 };