Skip to content

Commit b9e072b

Browse files
avoid getting webrtc into underrun
1 parent fde0654 commit b9e072b

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

webrtc-sys/include/livekit/audio_track.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ class AudioTrackSource {
137137
const SourceContext* capture_userdata_ RTC_GUARDED_BY(mutex_);
138138
void (*on_complete_)(const SourceContext*) RTC_GUARDED_BY(mutex_);
139139

140-
int missed_frames_ RTC_GUARDED_BY(mutex_) = 0;
141140
std::vector<int16_t> silence_buffer_;
142141

143142
int sample_rate_ = 0;

webrtc-sys/src/audio_track.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ AudioTrackSource::InternalSource::InternalSource(
147147
return; // no audio queue
148148
}
149149

150-
// start sending silence when there is nothing on the queue for 10 frames
151-
// (100ms)
152-
const int silence_frames_threshold = 10;
153-
missed_frames_ = silence_frames_threshold;
154-
155150
int samples10ms = sample_rate / 100 * num_channels;
156151

157152
silence_buffer_.assign(samples10ms, 0);
@@ -171,20 +166,16 @@ AudioTrackSource::InternalSource::InternalSource(
171166
constexpr int kBitsPerSample = sizeof(int16_t) * 8;
172167

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

180173
buffer_.erase(buffer_.begin(), buffer_.begin() + samples10ms);
181174
} else {
182-
missed_frames_++;
183-
if (missed_frames_ >= silence_frames_threshold) {
184-
for (auto sink : sinks_)
185-
sink->OnData(silence_buffer_.data(), kBitsPerSample, sample_rate_,
186-
num_channels_, samples10ms / num_channels_);
187-
}
175+
// Always provide a 10ms frame to avoid playout underruns.
176+
for (auto sink : sinks_)
177+
sink->OnData(silence_buffer_.data(), kBitsPerSample, sample_rate_,
178+
num_channels_, samples10ms / num_channels_);
188179
}
189180

190181
if (on_complete_ && buffer_.size() <= notify_threshold_samples_) {

0 commit comments

Comments
 (0)