LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
audio_source.h
1/*
2 * Copyright 2025 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
21#include "livekit/audio_frame.h"
22#include "livekit/ffi_handle.h"
23#include "livekit/visibility.h"
24
25namespace livekit {
26
27namespace proto {
28class FfiRequest;
29class FfiResponse;
30} // namespace proto
31
32class FfiClient;
33
35class LIVEKIT_API AudioSource {
36public:
68 AudioSource(int sample_rate, int num_channels, int queue_size_ms = 0);
69 virtual ~AudioSource() = default;
70
71 AudioSource(const AudioSource&) = delete;
72 AudioSource& operator=(const AudioSource&) = delete;
73 AudioSource(AudioSource&&) noexcept = default;
74 AudioSource& operator=(AudioSource&&) noexcept = default;
75
77 int sampleRate() const noexcept { return sample_rate_; }
78
80 int numChannels() const noexcept { return num_channels_; }
81
83 std::uint64_t ffiHandleId() const noexcept { return static_cast<std::uint64_t>(handle_.get()); }
84
86 double queuedDuration() const noexcept;
87
90 void clearQueue();
91
131 void captureFrame(const AudioFrame& frame, int timeout_ms = 20);
132
133private:
134 // Internal helper to reset the local queue tracking (like _release_waiter).
135 void resetQueueTracking() noexcept;
136
137 int sample_rate_;
138 int num_channels_;
139 int queue_size_ms_;
140
141 // RAII wrapper for this audio source's FFI handle
142 FfiHandle handle_;
143
144 // Queue tracking (all in seconds; based on steady_clock in the .cpp).
145 mutable double last_capture_{0.0};
146 mutable double q_size_{0.0};
147};
148
149} // namespace livekit
Represents a raw PCM audio frame with interleaved int16 samples.
Definition audio_frame.h:37
Represents a real-time audio source with an internal audio queue.
Definition audio_source.h:35
AudioSource(int sample_rate, int num_channels, int queue_size_ms=0)
Create a new native audio source.
int numChannels() const noexcept
The number of audio channels.
Definition audio_source.h:80
double queuedDuration() const noexcept
Current duration of queued audio (in seconds).
std::uint64_t ffiHandleId() const noexcept
Underlying FFI handle ID used in FFI requests.
Definition audio_source.h:83
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25