Prior to https://codereview.webrtc.org/2750783004/ Reset() intentionally did not zero out the buffer. After that change, callers calling Reset() and then mutable_data() were performing a wasteful zeroing. This change adds ResetWithoutMuting() to match the old behavior and switches the sole non-test caller of Reset() to use ResetWithoutMuting() instead. Prior to this change (optimized, Linux): $ out/Default/webrtc_perf_tests --gtest_filter=NetEqPerformanceTest.Run* \ --gtest_repeat=10 | grep neteq_performance *RESULT neteq_performance: 10_pl_10_drift= 4051 ms *RESULT neteq_performance: 0_pl_0_drift= 1768 ms *RESULT neteq_performance: 10_pl_10_drift= 3666 ms *RESULT neteq_performance: 0_pl_0_drift= 1690 ms *RESULT neteq_performance: 10_pl_10_drift= 3685 ms *RESULT neteq_performance: 0_pl_0_drift= 1693 ms *RESULT neteq_performance: 10_pl_10_drift= 3720 ms *RESULT neteq_performance: 0_pl_0_drift= 1690 ms *RESULT neteq_performance: 10_pl_10_drift= 3780 ms *RESULT neteq_performance: 0_pl_0_drift= 1728 ms *RESULT neteq_performance: 10_pl_10_drift= 3733 ms *RESULT neteq_performance: 0_pl_0_drift= 1737 ms *RESULT neteq_performance: 10_pl_10_drift= 3781 ms *RESULT neteq_performance: 0_pl_0_drift= 1744 ms *RESULT neteq_performance: 10_pl_10_drift= 3712 ms *RESULT neteq_performance: 0_pl_0_drift= 1731 ms *RESULT neteq_performance: 10_pl_10_drift= 3681 ms *RESULT neteq_performance: 0_pl_0_drift= 1691 ms *RESULT neteq_performance: 10_pl_10_drift= 3681 ms *RESULT neteq_performance: 0_pl_0_drift= 1690 ms With this change: $ out/Default/webrtc_perf_tests --gtest_filter=NetEqPerformanceTest.Run* \ --gtest_repeat=10 | grep neteq_performance *RESULT neteq_performance: 10_pl_10_drift= 3824 ms *RESULT neteq_performance: 0_pl_0_drift= 1632 ms *RESULT neteq_performance: 10_pl_10_drift= 3502 ms *RESULT neteq_performance: 0_pl_0_drift= 1521 ms *RESULT neteq_performance: 10_pl_10_drift= 3520 ms *RESULT neteq_performance: 0_pl_0_drift= 1534 ms *RESULT neteq_performance: 10_pl_10_drift= 3517 ms *RESULT neteq_performance: 0_pl_0_drift= 1530 ms *RESULT neteq_performance: 10_pl_10_drift= 3521 ms *RESULT neteq_performance: 0_pl_0_drift= 1527 ms *RESULT neteq_performance: 10_pl_10_drift= 3511 ms *RESULT neteq_performance: 0_pl_0_drift= 1533 ms *RESULT neteq_performance: 10_pl_10_drift= 3518 ms *RESULT neteq_performance: 0_pl_0_drift= 1523 ms *RESULT neteq_performance: 10_pl_10_drift= 3503 ms *RESULT neteq_performance: 0_pl_0_drift= 1524 ms *RESULT neteq_performance: 10_pl_10_drift= 3514 ms *RESULT neteq_performance: 0_pl_0_drift= 1534 ms *RESULT neteq_performance: 10_pl_10_drift= 3501 ms *RESULT neteq_performance: 0_pl_0_drift= 1530 ms BUG=webrtc:7343,chromium:738852,chromium:738839 Change-Id: Idcbb276ca0ed27fff95164a73f1c1fa310175ee5 Reviewed-on: https://chromium-review.googlesource.com/563021 Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org> Reviewed-by: Olga Sharonova <olka@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18939}
109 lines
3.6 KiB
C++
109 lines
3.6 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include <algorithm> // Access to min.
|
|
|
|
#include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
namespace webrtc {
|
|
|
|
size_t SyncBuffer::FutureLength() const {
|
|
return Size() - next_index_;
|
|
}
|
|
|
|
void SyncBuffer::PushBack(const AudioMultiVector& append_this) {
|
|
size_t samples_added = append_this.Size();
|
|
AudioMultiVector::PushBack(append_this);
|
|
AudioMultiVector::PopFront(samples_added);
|
|
if (samples_added <= next_index_) {
|
|
next_index_ -= samples_added;
|
|
} else {
|
|
// This means that we are pushing out future data that was never used.
|
|
// assert(false);
|
|
// TODO(hlundin): This assert must be disabled to support 60 ms frames.
|
|
// This should not happen even for 60 ms frames, but it does. Investigate
|
|
// why.
|
|
next_index_ = 0;
|
|
}
|
|
dtmf_index_ -= std::min(dtmf_index_, samples_added);
|
|
}
|
|
|
|
void SyncBuffer::PushFrontZeros(size_t length) {
|
|
InsertZerosAtIndex(length, 0);
|
|
}
|
|
|
|
void SyncBuffer::InsertZerosAtIndex(size_t length, size_t position) {
|
|
position = std::min(position, Size());
|
|
length = std::min(length, Size() - position);
|
|
AudioMultiVector::PopBack(length);
|
|
for (size_t channel = 0; channel < Channels(); ++channel) {
|
|
channels_[channel]->InsertZerosAt(length, position);
|
|
}
|
|
if (next_index_ >= position) {
|
|
// We are moving the |next_index_| sample.
|
|
set_next_index(next_index_ + length); // Overflow handled by subfunction.
|
|
}
|
|
if (dtmf_index_ > 0 && dtmf_index_ >= position) {
|
|
// We are moving the |dtmf_index_| sample.
|
|
set_dtmf_index(dtmf_index_ + length); // Overflow handled by subfunction.
|
|
}
|
|
}
|
|
|
|
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this,
|
|
size_t length,
|
|
size_t position) {
|
|
position = std::min(position, Size()); // Cap |position| in the valid range.
|
|
length = std::min(length, Size() - position);
|
|
AudioMultiVector::OverwriteAt(insert_this, length, position);
|
|
}
|
|
|
|
void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this,
|
|
size_t position) {
|
|
ReplaceAtIndex(insert_this, insert_this.Size(), position);
|
|
}
|
|
|
|
void SyncBuffer::GetNextAudioInterleaved(size_t requested_len,
|
|
AudioFrame* output) {
|
|
RTC_DCHECK(output);
|
|
const size_t samples_to_read = std::min(FutureLength(), requested_len);
|
|
output->ResetWithoutMuting();
|
|
const size_t tot_samples_read =
|
|
ReadInterleavedFromIndex(next_index_, samples_to_read,
|
|
output->mutable_data());
|
|
const size_t samples_read_per_channel = tot_samples_read / Channels();
|
|
next_index_ += samples_read_per_channel;
|
|
output->num_channels_ = Channels();
|
|
output->samples_per_channel_ = samples_read_per_channel;
|
|
}
|
|
|
|
void SyncBuffer::IncreaseEndTimestamp(uint32_t increment) {
|
|
end_timestamp_ += increment;
|
|
}
|
|
|
|
void SyncBuffer::Flush() {
|
|
Zeros(Size());
|
|
next_index_ = Size();
|
|
end_timestamp_ = 0;
|
|
dtmf_index_ = 0;
|
|
}
|
|
|
|
void SyncBuffer::set_next_index(size_t value) {
|
|
// Cannot set |next_index_| larger than the size of the buffer.
|
|
next_index_ = std::min(value, Size());
|
|
}
|
|
|
|
void SyncBuffer::set_dtmf_index(size_t value) {
|
|
// Cannot set |dtmf_index_| larger than the size of the buffer.
|
|
dtmf_index_ = std::min(value, Size());
|
|
}
|
|
|
|
} // namespace webrtc
|