Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jacklayer.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 "noncopyable.h"
20#include "audio/audiolayer.h"
21
22#include <jack/jack.h>
23#include <jack/ringbuffer.h>
24
25#include <thread>
26#include <mutex>
27#include <vector>
28#include <condition_variable>
29#include <memory>
30
31namespace jami {
32
33class RingBuffer;
34
35class JackLayer : public AudioLayer
36{
37private:
39 jack_client_t* captureClient_;
40 jack_client_t* playbackClient_;
41 std::vector<jack_port_t*> out_ports_;
42 std::vector<jack_port_t*> in_ports_;
43 std::vector<jack_ringbuffer_t*> out_ringbuffers_;
44 std::vector<jack_ringbuffer_t*> in_ringbuffers_;
45 std::thread ringbuffer_thread_;
46 std::mutex ringbuffer_thread_mutex_;
47 std::condition_variable data_ready_;
48
49 static int process_capture(jack_nframes_t frames, void* arg);
50 static int process_playback(jack_nframes_t frames, void* arg);
51
52 void ringbuffer_worker();
53 void playback();
54 void capture();
55
56 std::unique_ptr<AudioFrame> read();
57 void write(const AudioFrame& buffer);
58 size_t writeSpace();
59
60 std::vector<std::string> getCaptureDeviceList() const;
61 std::vector<std::string> getPlaybackDeviceList() const;
62
63 int getAudioDeviceIndex(const std::string& name, AudioDeviceType type) const;
64 std::string getAudioDeviceName(int index, AudioDeviceType type) const;
65 int getIndexCapture() const;
66 int getIndexPlayback() const;
67 int getIndexRingtone() const;
68 void updatePreference(AudioPreference& pref, int index, AudioDeviceType type);
69
73 void startStream(AudioDeviceType stream = AudioDeviceType::ALL);
74
78 void stopStream(AudioDeviceType stream = AudioDeviceType::ALL);
79
80 static void onShutdown(void* data);
81
82public:
84 ~JackLayer();
85};
86
87} // namespace jami
Main sound class.
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