Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions livekit/src/room/utils/utf8_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl<'a> Iterator for Utf8AwareChunks<'a> {
pub trait Utf8AwareChunkExt {
/// Splits the bytes into chunks of the specified size, ensuring that
/// UTF-8 character boundaries are respected.
fn utf8_aware_chunks(&self, chunk_size: usize) -> Utf8AwareChunks;
fn utf8_aware_chunks(&self, chunk_size: usize) -> Utf8AwareChunks<'_>;
}

impl Utf8AwareChunkExt for [u8] {
fn utf8_aware_chunks(&self, chunk_size: usize) -> Utf8AwareChunks {
fn utf8_aware_chunks(&self, chunk_size: usize) -> Utf8AwareChunks<'_> {
Utf8AwareChunks::new(self, chunk_size)
}
}
Expand Down
3 changes: 2 additions & 1 deletion webrtc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ fn main() {
.file("src/objc_video_factory.mm")
.file("src/objc_video_frame_buffer.mm")
.flag("-stdlib=libc++")
.flag("-std=c++20");
.flag("-std=c++20")
.flag("-Wno-nullability-completeness");
}
"ios" => {
println!("cargo:rustc-link-lib=framework=Foundation");
Expand Down
3 changes: 2 additions & 1 deletion webrtc-sys/include/livekit/audio_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <memory>
#include <vector>

#include "api/audio/audio_frame.h"
#include "api/audio_options.h"
Expand Down Expand Up @@ -137,7 +138,7 @@ class AudioTrackSource {
void (*on_complete_)(const SourceContext*) RTC_GUARDED_BY(mutex_);

int missed_frames_ RTC_GUARDED_BY(mutex_) = 0;
int16_t* silence_buffer_ = nullptr;
std::vector<int16_t> silence_buffer_;

int sample_rate_;
int num_channels_;
Expand Down
10 changes: 6 additions & 4 deletions webrtc-sys/src/audio_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ AudioTrackSource::InternalSource::InternalSource(

int samples10ms = sample_rate / 100 * num_channels;

silence_buffer_ = new int16_t[samples10ms]();
silence_buffer_.assign(samples10ms, 0);
queue_size_samples_ = queue_size_ms / 10 * samples10ms;
notify_threshold_samples_ = queue_size_samples_; // TODO: this is currently
// using x2 the queue size
Expand All @@ -164,18 +164,21 @@ AudioTrackSource::InternalSource::InternalSource(
audio_queue_.get(),
[this, samples10ms]() {
webrtc::MutexLock lock(&mutex_);
constexpr int kBitsPerSample = sizeof(int16_t) * 8;

if (buffer_.size() >= samples10ms) {
// Reset |missed_frames_| to 0 so that it won't keep sending silence to webrtc due to audio callback timing drifts.
missed_frames_ = 0;
for (auto sink : sinks_)
sink->OnData(buffer_.data(), sizeof(int16_t) * 8, sample_rate_,
sink->OnData(buffer_.data(), kBitsPerSample, sample_rate_,
num_channels_, samples10ms / num_channels_);

buffer_.erase(buffer_.begin(), buffer_.begin() + samples10ms);
} else {
missed_frames_++;
if (missed_frames_ >= silence_frames_threshold) {
for (auto sink : sinks_)
sink->OnData(silence_buffer_, sizeof(int16_t) * 8, sample_rate_,
sink->OnData(silence_buffer_.data(), kBitsPerSample, sample_rate_,
num_channels_, samples10ms / num_channels_);
}
}
Expand All @@ -192,7 +195,6 @@ AudioTrackSource::InternalSource::InternalSource(
}

AudioTrackSource::InternalSource::~InternalSource() {
delete[] silence_buffer_;
}

bool AudioTrackSource::InternalSource::capture_frame(
Expand Down