Ring Daemon 16.0.0
Loading...
Searching...
No Matches
opensllayer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <SLES/OpenSLES.h>
20#include <SLES/OpenSLES_Android.h>
21#include <vector>
22#include <thread>
23
24#include "audio/audiolayer.h"
25#include "audio_player.h"
26#include "audio_recorder.h"
27
28class AudioPreference;
29
30#include "noncopyable.h"
31
32#include <memory>
33
34namespace jami {
35
36class RingBuffer;
37
38#define ANDROID_BUFFER_QUEUE_LENGTH 2U
39#define BUFFER_SIZE 512U
40
41#define MAX_NUMBER_INTERFACES 5
42#define MAX_NUMBER_INPUT_DEVICES 3
43
50class OpenSLLayer : public AudioLayer
51{
52public:
57
62
67 void startStream(AudioDeviceType stream = AudioDeviceType::ALL) override;
68
73 void stopStream(AudioDeviceType stream = AudioDeviceType::ALL) override;
74
79 std::vector<std::string> getCaptureDeviceList() const override;
80
85 std::vector<std::string> getPlaybackDeviceList() const override;
86
87 void init();
88
89 void initAudioEngine();
91
92 void startAudioCapture();
93 void stopAudioCapture();
94
95 virtual int getAudioDeviceIndex(const std::string&, AudioDeviceType) const override { return 0; }
96
97 virtual std::string getAudioDeviceName(int, AudioDeviceType) const override { return ""; }
98
99 void engineServicePlay();
100 void engineServiceRing();
101 void engineServiceRec();
102
103private:
109 virtual int getIndexCapture() const override { return 0; }
110
116 virtual int getIndexPlayback() const override { return 0; }
117
123 virtual int getIndexRingtone() const override { return 0; }
124
125 uint32_t dbgEngineGetBufCount();
126
127 void dumpAvailableEngineInterfaces();
128
129 NON_COPYABLE(OpenSLLayer);
130
131 virtual void updatePreference(AudioPreference& pref, int index, AudioDeviceType type) override;
132
133 std::mutex recMtx {};
134 std::condition_variable recCv {};
135
139 SLObjectItf engineObject_ {nullptr};
140
144 SLEngineItf engineInterface_ {nullptr};
145
146 AudioFormat hardwareFormat_ {AudioFormat::MONO()};
147 size_t hardwareBuffSize_ {BUFFER_SIZE};
148
149 std::vector<sample_buf> bufs_ {};
150
151 AudioQueue freePlayBufQueue_ {BUF_COUNT};
152 AudioQueue playBufQueue_ {BUF_COUNT};
153
154 AudioQueue freeRingBufQueue_ {BUF_COUNT};
155 AudioQueue ringBufQueue_ {BUF_COUNT};
156
157 AudioQueue freeRecBufQueue_ {BUF_COUNT}; // Owner of the queue
158 AudioQueue recBufQueue_ {BUF_COUNT}; // Owner of the queue
159
160 std::unique_ptr<opensl::AudioPlayer> player_ {};
161 std::unique_ptr<opensl::AudioPlayer> ringtone_ {};
162 std::unique_ptr<opensl::AudioRecorder> recorder_ {};
163
164 std::thread recThread {};
165};
166
167} // namespace jami
#define BUF_COUNT
Main sound class.
std::vector< std::string > getCaptureDeviceList() const override
Scan the sound card available for capture on the system.
void startStream(AudioDeviceType stream=AudioDeviceType::ALL) override
Start the capture stream and prepare the playback stream.
virtual std::string getAudioDeviceName(int, AudioDeviceType) const override
Definition opensllayer.h:97
virtual int getAudioDeviceIndex(const std::string &, AudioDeviceType) const override
Definition opensllayer.h:95
std::vector< std::string > getPlaybackDeviceList() const override
Scan the sound card available for capture on the system.
~OpenSLLayer()
Destructor.
void stopStream(AudioDeviceType stream=AudioDeviceType::ALL) override
Stop the playback and capture streams.
void emitSignal(Args... args)
Definition ring_signal.h:64
AudioDeviceType
Definition audiolayer.h:58
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30
#define BUFFER_SIZE
Definition opensllayer.h:39
static const constexpr AudioFormat MONO()