LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
platform_audio.h
1/*
2 * Copyright 2026 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstdint>
20#include <memory>
21#include <stdexcept>
22#include <string>
23#include <vector>
24
25#include "livekit/ffi_handle.h"
26#include "livekit/visibility.h"
27
28namespace livekit {
29
36struct PlatformAudioState;
37
44 std::uint32_t index = 0;
45
47 std::string name;
48
50 std::string id;
51};
52
59 bool echo_cancellation = true;
60
62 bool noise_suppression = true;
63
65 bool auto_gain_control = true;
66
68 bool prefer_hardware = false;
69};
70
72class LIVEKIT_API PlatformAudioError : public std::runtime_error {
73public:
77 explicit PlatformAudioError(const std::string& message) : std::runtime_error(message) {}
78};
79
84class LIVEKIT_API PlatformAudioSource {
85public:
88
91
97 PlatformAudioSource(PlatformAudioSource&& other) noexcept = default;
98
106
110 std::uint64_t ffiHandleId() const noexcept { return static_cast<std::uint64_t>(handle_.get()); }
111
112private:
113 friend class PlatformAudio;
114
115 PlatformAudioSource(FfiHandle handle, std::shared_ptr<PlatformAudioState> platform_audio) noexcept;
116
117 FfiHandle handle_;
118 std::shared_ptr<PlatformAudioState> platform_audio_;
119};
120
127class LIVEKIT_API PlatformAudio {
128public:
139
147 PlatformAudio(const PlatformAudio& other) = default;
148
157 PlatformAudio& operator=(const PlatformAudio& other) = default;
158
164 PlatformAudio(PlatformAudio&& other) noexcept = default;
165
172 PlatformAudio& operator=(PlatformAudio&& other) noexcept = default;
173
180 std::int32_t recordingDeviceCount() const;
181
188 std::int32_t playoutDeviceCount() const;
189
197 std::vector<AudioDeviceInfo> recordingDevices() const;
198
206 std::vector<AudioDeviceInfo> playoutDevices() const;
207
215 void setRecordingDevice(const std::string& device_id) const;
216
224 void setPlayoutDevice(const std::string& device_id) const;
225
237 std::shared_ptr<PlatformAudioSource> createAudioSource(const PlatformAudioOptions& options = {}) const;
238
239private:
240 std::shared_ptr<PlatformAudioState> state_;
241};
242
243} // namespace livekit
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Error raised when platform audio setup or device operations fail.
Definition platform_audio.h:72
PlatformAudioError(const std::string &message)
Create a platform audio error.
Definition platform_audio.h:77
Audio source backed by WebRTC's platform Audio Device Module.
Definition platform_audio.h:84
std::uint64_t ffiHandleId() const noexcept
Return the underlying FFI handle ID used in FFI requests.
Definition platform_audio.h:110
PlatformAudioSource(PlatformAudioSource &&other) noexcept=default
Move the platform audio source.
PlatformAudioSource & operator=(const PlatformAudioSource &other)=delete
Copy assignment is disabled.
PlatformAudioSource & operator=(PlatformAudioSource &&other) noexcept=default
Move-assign the platform audio source.
PlatformAudioSource(const PlatformAudioSource &other)=delete
Copy construction is disabled.
Platform audio device manager backed by WebRTC's Audio Device Module.
Definition platform_audio.h:127
PlatformAudio(const PlatformAudio &other)=default
Copy the platform audio manager.
std::int32_t playoutDeviceCount() const
Return the current number of playout devices.
std::vector< AudioDeviceInfo > recordingDevices() const
Enumerate available microphones.
std::shared_ptr< PlatformAudioSource > createAudioSource(const PlatformAudioOptions &options={}) const
Create an automatically captured microphone source for LocalAudioTrack.
void setRecordingDevice(const std::string &device_id) const
Select the microphone by device ID.
std::int32_t recordingDeviceCount() const
Return the current number of recording devices.
PlatformAudio & operator=(const PlatformAudio &other)=default
Copy-assign the platform audio manager.
PlatformAudio()
Create a platform audio manager.
PlatformAudio & operator=(PlatformAudio &&other) noexcept=default
Move-assign the platform audio manager.
std::vector< AudioDeviceInfo > playoutDevices() const
Enumerate available speakers/headphones.
PlatformAudio(PlatformAudio &&other) noexcept=default
Move the platform audio manager.
void setPlayoutDevice(const std::string &device_id) const
Select the speaker/headphones by device ID.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
Information about a platform audio device.
Definition platform_audio.h:42
std::string id
Platform-specific stable device identifier.
Definition platform_audio.h:50
std::string name
Device name reported by the operating system.
Definition platform_audio.h:47
std::uint32_t index
Current device index.
Definition platform_audio.h:44
Audio processing options for platform microphone capture.
Definition platform_audio.h:57
bool echo_cancellation
Enable acoustic echo cancellation.
Definition platform_audio.h:59
bool prefer_hardware
Prefer hardware audio processing when the platform provides it.
Definition platform_audio.h:68
bool noise_suppression
Enable background noise suppression.
Definition platform_audio.h:62
bool auto_gain_control
Enable automatic gain control.
Definition platform_audio.h:65