FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
client-sdk-cpp/src/platform_audio.cpp at main · livekit/client-sdk-cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
livekit
/
client-sdk-cpp
Public
Notifications
You must be signed in to change notification settings
Fork
38
Star
67
Code
Issues
2
Pull requests
5
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
client-sdk-cpp
/
src
/
platform_audio.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
185 lines (150 loc) · 6.32 KB
Breadcrumbs
client-sdk-cpp
/
src
/
platform_audio.cpp
Copy path
File metadata and controls
185 lines (150 loc) · 6.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright 2026 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#
include
"
livekit/platform_audio.h
"
#
include
<
utility
>
#
include
"
ffi.pb.h
"
#
include
"
ffi_client.h
"
namespace
livekit
{
struct
PlatformAudioState
{
FfiHandle handle;
};
namespace
{
std::
uint64_t
requireHandle
(
const
std::shared_ptr<PlatformAudioState>& state) {
if
(!state || !state->
handle
) {
throw
PlatformAudioError
(
"
PlatformAudio has no valid FFI handle
"
);
}
return
static_cast
<std::
uint64_t
>(state->
handle
.
get
());
}
AudioDeviceInfo
fromProto
(
const
proto::AudioDeviceInfo& device) {
AudioDeviceInfo out;
out.
index
= device.
index
();
out.
name
= device.
name
();
out.
id
= device.
has_guid
() ? device.
guid
() :
std::string
();
return
out;
}
std::vector<AudioDeviceInfo>
convertDevices
(
const
google::protobuf::RepeatedPtrField<proto::AudioDeviceInfo>& devices) {
std::vector<AudioDeviceInfo> out;
out.
reserve
(
static_cast
<std::
size_t
>(devices.
size
()));
for
(
const
auto
& device : devices) {
out.
push_back
(
fromProto
(device));
}
return
out;
}
proto::AudioSourceOptions
toProto
(
const
PlatformAudioOptions& options) {
proto::AudioSourceOptions out;
out.
set_echo_cancellation
(options.
echo_cancellation
);
out.
set_noise_suppression
(options.
noise_suppression
);
out.
set_auto_gain_control
(options.
auto_gain_control
);
out.
set_prefer_hardware
(options.
prefer_hardware
);
return
out;
}
proto::GetAudioDevicesResponse
getAudioDevices
(
const
std::shared_ptr<PlatformAudioState>& state) {
proto::FfiRequest req;
req.
mutable_get_audio_devices
()->
set_platform_audio_handle
(
requireHandle
(state));
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
if
(!resp.
has_get_audio_devices
()) {
throw
PlatformAudioError
(
"
FfiResponse missing get_audio_devices
"
);
}
const
auto
& devices = resp.
get_audio_devices
();
if
(devices.
has_error
() && !devices.
error
().
empty
()) {
throw
PlatformAudioError
(devices.
error
());
}
return
devices;
}
}
//
namespace
PlatformAudioSource::PlatformAudioSource
(FfiHandle handle, std::shared_ptr<PlatformAudioState> platform_audio)
noexcept
: handle_(std::move(handle)), platform_audio_(std::move(platform_audio)) {}
PlatformAudio::PlatformAudio
() {
proto::FfiRequest req;
req.
mutable_new_platform_audio
();
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
if
(!resp.
has_new_platform_audio
()) {
throw
PlatformAudioError
(
"
Failed to construct PlatformAudio: FfiResponse missing new_platform_audio
"
);
}
const
auto
& platform_audio = resp.
new_platform_audio
();
if
(platform_audio.
has_error
()) {
throw
PlatformAudioError
(platform_audio.
error
());
}
if
(!platform_audio.
has_platform_audio
()) {
throw
PlatformAudioError
(
"
Failed to construct PlatformAudio: NewPlatformAudioResponse missing platform_audio
"
);
}
const
auto
& owned = platform_audio.
platform_audio
();
state_ = std::make_shared<PlatformAudioState>();
state_->
handle
=
FfiHandle
(
static_cast
<
uintptr_t
>(owned.
handle
().
id
()));
}
std::
int32_t
PlatformAudio::recordingDeviceCount
()
const
{
return
static_cast
<std::
int32_t
>(
getAudioDevices
(state_).
recording_devices_size
());
}
std::
int32_t
PlatformAudio::playoutDeviceCount
()
const
{
return
static_cast
<std::
int32_t
>(
getAudioDevices
(state_).
playout_devices_size
());
}
std::vector<AudioDeviceInfo>
PlatformAudio::recordingDevices
()
const
{
return
convertDevices
(
getAudioDevices
(state_).
recording_devices
());
}
std::vector<AudioDeviceInfo>
PlatformAudio::playoutDevices
()
const
{
return
convertDevices
(
getAudioDevices
(state_).
playout_devices
());
}
void
PlatformAudio::setRecordingDevice
(
const
std::string& device_id)
const
{
proto::FfiRequest req;
auto
* msg = req.
mutable_set_recording_device
();
msg->
set_platform_audio_handle
(
requireHandle
(state_));
msg->
set_device_id
(device_id);
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
if
(!resp.
has_set_recording_device
()) {
throw
PlatformAudioError
(
"
FfiResponse missing set_recording_device
"
);
}
const
auto
& set_device = resp.
set_recording_device
();
if
(set_device.
has_error
() && !set_device.
error
().
empty
()) {
throw
PlatformAudioError
(set_device.
error
());
}
}
void
PlatformAudio::setPlayoutDevice
(
const
std::string& device_id)
const
{
proto::FfiRequest req;
auto
* msg = req.
mutable_set_playout_device
();
msg->
set_platform_audio_handle
(
requireHandle
(state_));
msg->
set_device_id
(device_id);
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
if
(!resp.
has_set_playout_device
()) {
throw
PlatformAudioError
(
"
FfiResponse missing set_playout_device
"
);
}
const
auto
& set_device = resp.
set_playout_device
();
if
(set_device.
has_error
() && !set_device.
error
().
empty
()) {
throw
PlatformAudioError
(set_device.
error
());
}
}
std::shared_ptr<PlatformAudioSource>
PlatformAudio::createAudioSource
(
const
PlatformAudioOptions& options)
const
{
proto::FfiRequest req;
auto
* msg = req.
mutable_new_audio_source
();
msg->
set_type
(proto::AudioSourceType::
AUDIO_SOURCE_PLATFORM
);
msg->
set_platform_audio_handle
(
requireHandle
(state_));
*msg->
mutable_options
() =
toProto
(options);
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
if
(!resp.
has_new_audio_source
()) {
throw
PlatformAudioError
(
"
FfiResponse missing new_audio_source
"
);
}
const
auto
& new_source = resp.
new_audio_source
();
if
(!new_source.
has_source
() || !new_source.
source
().
has_handle
()) {
throw
PlatformAudioError
(
"
NewAudioSourceResponse missing source handle
"
);
}
const
auto
& source = new_source.
source
();
const
std::
uint64_t
handle_id = source.
handle
().
id
();
if
(handle_id ==
0
) {
throw
PlatformAudioError
(
"
NewAudioSourceResponse returned an invalid (null) source handle
"
);
}
FfiHandle
handle
(
static_cast
<
uintptr_t
>(handle_id));
return
std::shared_ptr<PlatformAudioSource>(
new
PlatformAudioSource
(
std::move
(handle), state_));
}
}
//
namespace livekit
Back
|
FazBrowse Home
|
New Git URL