Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/pulseaudio/audio_driver_pulseaudio.h
9973 views
1
/**************************************************************************/
2
/* audio_driver_pulseaudio.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
#ifdef PULSEAUDIO_ENABLED
34
35
#include "core/os/mutex.h"
36
#include "core/os/thread.h"
37
#include "core/templates/safe_refcount.h"
38
#include "servers/audio_server.h"
39
40
#ifdef SOWRAP_ENABLED
41
#include "pulse-so_wrap.h"
42
#else
43
#include <pulse/pulseaudio.h>
44
#endif
45
46
class AudioDriverPulseAudio : public AudioDriver {
47
Thread thread;
48
Mutex mutex;
49
50
pa_mainloop *pa_ml = nullptr;
51
pa_context *pa_ctx = nullptr;
52
pa_stream *pa_str = nullptr;
53
pa_stream *pa_rec_str = nullptr;
54
pa_channel_map pa_map = {};
55
pa_channel_map pa_rec_map = {};
56
57
String output_device_name = "Default";
58
String new_output_device = "Default";
59
String default_output_device;
60
61
String input_device_name;
62
String new_input_device;
63
String default_input_device;
64
65
Vector<int32_t> samples_in;
66
Vector<int16_t> samples_out;
67
68
unsigned int mix_rate = 0;
69
unsigned int buffer_frames = 0;
70
unsigned int pa_buffer_size = 0;
71
int channels = 0;
72
int pa_ready = 0;
73
int pa_status = 0;
74
PackedStringArray pa_devices;
75
PackedStringArray pa_rec_devices;
76
77
SafeFlag active;
78
SafeFlag exit_thread;
79
80
float latency = 0;
81
82
static void pa_state_cb(pa_context *c, void *userdata);
83
static void pa_sink_info_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
84
static void pa_source_info_cb(pa_context *c, const pa_source_info *l, int eol, void *userdata);
85
static void pa_server_info_cb(pa_context *c, const pa_server_info *i, void *userdata);
86
static void pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata);
87
static void pa_sourcelist_cb(pa_context *c, const pa_source_info *l, int eol, void *userdata);
88
89
Error init_output_device();
90
void finish_output_device();
91
92
Error init_input_device();
93
void finish_input_device();
94
95
Error detect_channels(bool capture = false);
96
97
static void thread_func(void *p_udata);
98
99
public:
100
virtual const char *get_name() const override {
101
return "PulseAudio";
102
}
103
104
virtual Error init() override;
105
virtual void start() override;
106
virtual int get_mix_rate() const override;
107
virtual SpeakerMode get_speaker_mode() const override;
108
virtual float get_latency() override;
109
110
virtual void lock() override;
111
virtual void unlock() override;
112
virtual void finish() override;
113
114
virtual PackedStringArray get_output_device_list() override;
115
virtual String get_output_device() override;
116
virtual void set_output_device(const String &p_name) override;
117
118
virtual Error input_start() override;
119
virtual Error input_stop() override;
120
121
virtual PackedStringArray get_input_device_list() override;
122
virtual String get_input_device() override;
123
virtual void set_input_device(const String &p_name) override;
124
125
AudioDriverPulseAudio();
126
~AudioDriverPulseAudio() {}
127
};
128
129
#endif // PULSEAUDIO_ENABLED
130
131