-
Notifications
You must be signed in to change notification settings - Fork 28
PlatformAudio #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stephen-derosa
merged 10 commits into
livekit:main
from
stephen-derosa:sderosa/BOT-377-platform-audio
Jun 10, 2026
Merged
PlatformAudio #140
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cd236a5
PlatformAudio: integration and unit tests
stephen-derosa 42ecc55
some mr comments
stephen-derosa 5191bef
EXPECT_NO_THROW
stephen-derosa bde192e
rm todo
stephen-derosa 3e2540f
comments
stephen-derosa 83831b3
tests
stephen-derosa b445f93
expect no throw
stephen-derosa 3ef5197
PlatformAudio requires audio device
stephen-derosa 95f7208
clarifying comment
stephen-derosa a164ad1
get device count from ffi rather than once on startup
stephen-derosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cpp-example-collection
updated
8 files
| +1 −0 | CMakeLists.txt | |
| +11 −1 | README.md | |
| +16 −0 | platform_audio/CMakeLists.txt | |
| +44 −0 | platform_audio/README.md | |
| +22 −0 | platform_audio/player/CMakeLists.txt | |
| +152 −0 | platform_audio/player/main.cpp | |
| +22 −0 | platform_audio/sender/CMakeLists.txt | |
| +145 −0 | platform_audio/sender/main.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "livekit/ffi_handle.h" | ||
| #include "livekit/visibility.h" | ||
|
|
||
| namespace livekit { | ||
|
|
||
| /// Internal shared state for platform audio handles. | ||
| /// | ||
| /// This forward declaration is exposed only so public wrapper types can hold a | ||
| /// shared implementation pointer. | ||
| /// | ||
| /// @note This object is thread-safe. | ||
| struct PlatformAudioState; | ||
|
|
||
| /// Information about a platform audio device. | ||
| /// | ||
| /// @note Device indices may change when audio hardware is added or removed. Use | ||
| /// the stable `id` value when selecting a device. | ||
| struct AudioDeviceInfo { | ||
| /// Current device index. | ||
| std::uint32_t index = 0; | ||
|
|
||
| /// Device name reported by the operating system. | ||
| std::string name; | ||
|
|
||
| /// Platform-specific stable device identifier. | ||
| std::string id; | ||
| }; | ||
|
|
||
| /// Audio processing options for platform microphone capture. | ||
| /// | ||
| /// The default values enable WebRTC's voice processing path for typical | ||
| /// microphone publishing. | ||
| struct PlatformAudioOptions { | ||
| /// Enable acoustic echo cancellation. | ||
| bool echo_cancellation = true; | ||
|
stephen-derosa marked this conversation as resolved.
|
||
|
|
||
| /// Enable background noise suppression. | ||
| bool noise_suppression = true; | ||
|
|
||
| /// Enable automatic gain control. | ||
| bool auto_gain_control = true; | ||
|
|
||
| /// Prefer hardware audio processing when the platform provides it. | ||
| bool prefer_hardware = false; | ||
| }; | ||
|
|
||
| /// Error raised when platform audio setup or device operations fail. | ||
| class LIVEKIT_API PlatformAudioError : public std::runtime_error { | ||
| public: | ||
| /// Create a platform audio error. | ||
| /// | ||
| /// @param message Human-readable error message. | ||
| explicit PlatformAudioError(const std::string& message) : std::runtime_error(message) {} | ||
| }; | ||
|
|
||
| /// Audio source backed by WebRTC's platform Audio Device Module. | ||
| /// | ||
| /// A PlatformAudioSource captures microphone audio automatically. Unlike | ||
| /// AudioSource, callers do not push frames with captureFrame(). | ||
| class LIVEKIT_API PlatformAudioSource { | ||
| public: | ||
| /// Copy construction is disabled. | ||
| PlatformAudioSource(const PlatformAudioSource& other) = delete; | ||
|
stephen-derosa marked this conversation as resolved.
|
||
|
|
||
| /// Copy assignment is disabled. | ||
| PlatformAudioSource& operator=(const PlatformAudioSource& other) = delete; | ||
|
|
||
| /// Move the platform audio source. | ||
| /// | ||
| /// @param other Source to move from. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudioSource(PlatformAudioSource&& other) noexcept = default; | ||
|
|
||
| /// Move-assign the platform audio source. | ||
| /// | ||
| /// @param other Source to move from. | ||
| /// @return Reference to this source. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudioSource& operator=(PlatformAudioSource&& other) noexcept = default; | ||
|
|
||
| /// Return the underlying FFI handle ID used in FFI requests. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::uint64_t ffiHandleId() const noexcept { return static_cast<std::uint64_t>(handle_.get()); } | ||
|
|
||
| private: | ||
| friend class PlatformAudio; | ||
|
|
||
| PlatformAudioSource(FfiHandle handle, std::shared_ptr<PlatformAudioState> platform_audio) noexcept; | ||
|
|
||
| FfiHandle handle_; | ||
| std::shared_ptr<PlatformAudioState> platform_audio_; | ||
| }; | ||
|
|
||
| /// Platform audio device manager backed by WebRTC's Audio Device Module. | ||
| /// | ||
| /// Use PlatformAudio for microphone capture when built-in echo | ||
| /// cancellation, noise suppression, automatic gain control, and speaker playout | ||
| /// are desired. Use AudioSource instead when the application needs direct access | ||
| /// to raw PCM frames or custom audio generation. | ||
| class LIVEKIT_API PlatformAudio { | ||
| public: | ||
| /// Create a platform audio manager. | ||
| /// | ||
| /// Enables WebRTC's platform Audio Device Module for microphone capture and | ||
| /// speaker playout. | ||
| /// | ||
| /// @throws PlatformAudioError If the FFI response is malformed or the | ||
| /// platform Audio Device Module cannot be created. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| PlatformAudio(); | ||
|
|
||
| /// Copy the platform audio manager. | ||
| /// | ||
| /// The copy shares the same underlying platform audio handle. | ||
| /// | ||
| /// @param other Manager to copy from. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudio(const PlatformAudio& other) = default; | ||
|
|
||
| /// Copy-assign the platform audio manager. | ||
| /// | ||
| /// The assigned instance shares the same underlying platform audio handle. | ||
| /// | ||
| /// @param other Manager to copy from. | ||
| /// @return Reference to this manager. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudio& operator=(const PlatformAudio& other) = default; | ||
|
|
||
| /// Move the platform audio manager. | ||
| /// | ||
| /// @param other Manager to move from. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudio(PlatformAudio&& other) noexcept = default; | ||
|
|
||
| /// Move-assign the platform audio manager. | ||
| /// | ||
| /// @param other Manager to move from. | ||
| /// @return Reference to this manager. | ||
| /// | ||
| /// @note This operation is not thread-safe. | ||
| PlatformAudio& operator=(PlatformAudio&& other) noexcept = default; | ||
|
|
||
| /// Return the current number of recording devices. | ||
| /// | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// enumeration fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::int32_t recordingDeviceCount() const; | ||
|
|
||
| /// Return the current number of playout devices. | ||
| /// | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// enumeration fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::int32_t playoutDeviceCount() const; | ||
|
|
||
| /// Enumerate available microphones. | ||
| /// | ||
| /// @return List of available recording devices. | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// enumeration fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::vector<AudioDeviceInfo> recordingDevices() const; | ||
|
|
||
| /// Enumerate available speakers/headphones. | ||
| /// | ||
| /// @return List of available playout devices. | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// enumeration fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::vector<AudioDeviceInfo> playoutDevices() const; | ||
|
|
||
| /// Select the microphone by device ID. | ||
| /// | ||
| /// @param device_id Stable device identifier from AudioDeviceInfo::id. | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// selection fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| void setRecordingDevice(const std::string& device_id) const; | ||
|
|
||
| /// Select the speaker/headphones by device ID. | ||
| /// | ||
| /// @param device_id Stable device identifier from AudioDeviceInfo::id. | ||
| /// @throws PlatformAudioError If the FFI response is malformed or device | ||
| /// selection fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| void setPlayoutDevice(const std::string& device_id) const; | ||
|
|
||
| /// Create an automatically captured microphone source for LocalAudioTrack. | ||
| /// | ||
| /// Each call returns a new track source handle backed by the shared platform | ||
| /// Audio Device Module; it does not create a separate ADM instance. | ||
| /// | ||
| /// @param options Audio processing options for the platform microphone path. | ||
| /// @return Platform-backed audio source suitable for LocalAudioTrack. | ||
| /// @throws PlatformAudioError If the FFI response is malformed or source | ||
| /// creation fails. | ||
| /// | ||
| /// @note This operation is thread-safe. | ||
| std::shared_ptr<PlatformAudioSource> createAudioSource(const PlatformAudioOptions& options = {}) const; | ||
|
stephen-derosa marked this conversation as resolved.
|
||
|
|
||
| private: | ||
| std::shared_ptr<PlatformAudioState> state_; | ||
| }; | ||
|
|
||
| } // namespace livekit | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.