Reland "Change buffer level filter to store current level in number of samples."
This is a reland of 87977dd06e702ed517f26235c12e37bd927527c7 Original change's description: > Change buffer level filter to store current level in number of samples. > > The buffer level should not be converted back and forth between samples and packets in case of variable packet lengths. > > Bug: webrtc:10736 > Change-Id: Ia08dcfac3d8104dc79fbad0704a5f6f12a050a01 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/142178 > Reviewed-by: Minyue Li <minyue@webrtc.org> > Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#28368} Bug: webrtc:10736 Change-Id: I1ff603e65cdd31c7429f36b035dcc00a17b68f3b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143787 Commit-Queue: Minyue Li <minyue@webrtc.org> Reviewed-by: Minyue Li <minyue@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28393}
This commit is contained in:

committed by
Commit Bot

parent
4d6951669c
commit
0ded32d5a3
@ -994,35 +994,35 @@ class AcmReceiverBitExactnessOldApi : public ::testing::Test {
|
|||||||
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \
|
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \
|
||||||
defined(WEBRTC_CODEC_ILBC)
|
defined(WEBRTC_CODEC_ILBC)
|
||||||
TEST_F(AcmReceiverBitExactnessOldApi, 8kHzOutput) {
|
TEST_F(AcmReceiverBitExactnessOldApi, 8kHzOutput) {
|
||||||
Run(8000, PlatformChecksum("bcfbe2e89b4317b22e29557168edf187",
|
Run(8000, PlatformChecksum("73e82368b90b0708bd970da1f357f71d",
|
||||||
"af15addb648cf7f032d6415672365fb3",
|
"e777abcc66fccf8e86ac18450ad8b23c",
|
||||||
"54a0008eb79537dee1d8fdaa5bc29f4b",
|
"5a668d4075a39cd07a2db82ec3bf19ba",
|
||||||
"4598140b5e4f7ee66c5adad609e65a3e",
|
"4598140b5e4f7ee66c5adad609e65a3e",
|
||||||
"3155d7f2593a3276986f36221a61783c"));
|
"99d17cc50d41232a4f96c976231cb59b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AcmReceiverBitExactnessOldApi, 16kHzOutput) {
|
TEST_F(AcmReceiverBitExactnessOldApi, 16kHzOutput) {
|
||||||
Run(16000, PlatformChecksum("1737deef193e6c90e139ce82b7361ae4",
|
Run(16000, PlatformChecksum("f0b9d6961c243a3397b0bb95191b189b",
|
||||||
"9e2a9f7728c71d6559ce3a32d2b10a5d",
|
"c73877b73a7ae2687eabc88de3d3f5bc",
|
||||||
"114958862099142ac78b12100c21cb8d",
|
"70d24360be8290abbd0e56c38f83cdef",
|
||||||
"f2aad418af974a3b1694d5ae5cc2c3c7",
|
"f2aad418af974a3b1694d5ae5cc2c3c7",
|
||||||
"af2889a5ca84fb40c9aa209b9318ee7a"));
|
"564b1b5d2d9bcace5285623cd9822b57"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AcmReceiverBitExactnessOldApi, 32kHzOutput) {
|
TEST_F(AcmReceiverBitExactnessOldApi, 32kHzOutput) {
|
||||||
Run(32000, PlatformChecksum("1bf40ff024c6aa5b832d1d242c29cb3b",
|
Run(32000, PlatformChecksum("881a799ad91f845b1cd833e4e42d1791",
|
||||||
"3c9690cd136e9ecd1b26a22f70fe1d5c",
|
"90e478af57f11bcf678b72ed1ba87765",
|
||||||
"a1a3a01d8e25fcd11f1cedcd02e968b8",
|
"774657761e20fdec6d325d7d4b4101a7",
|
||||||
"100869c8dcde51346c2073e52a272d98",
|
"100869c8dcde51346c2073e52a272d98",
|
||||||
"33695077e9ec6bca80819ce2ba263a78"));
|
"4b77795ba2581097dc8e4db6e6a3a921"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutput) {
|
TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutput) {
|
||||||
Run(48000, PlatformChecksum("bf92db1e502deff5adf6fd2e6ab9a2e5",
|
Run(48000, PlatformChecksum("991b729aef7f08eca75d4c9ece848264",
|
||||||
"c37b110ab50d87620972daee5d1eaf31",
|
"0334f53d4e96156edc302e46ff5cfaec",
|
||||||
"5d55b68be7bcf39b60fcc74519363fb4",
|
"a578705020fe94ebde31b27d61035299",
|
||||||
"bd44bf97e7899186532f91235cef444d",
|
"bd44bf97e7899186532f91235cef444d",
|
||||||
"32eec738698ffe62b9777d6a349cd596"));
|
"c0d4185eacde6cd470c1a2ce4cd45318"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) {
|
TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) {
|
||||||
@ -1105,11 +1105,11 @@ TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) {
|
|||||||
rtc::scoped_refptr<rtc::RefCountedObject<ADFactory>> factory(
|
rtc::scoped_refptr<rtc::RefCountedObject<ADFactory>> factory(
|
||||||
new rtc::RefCountedObject<ADFactory>);
|
new rtc::RefCountedObject<ADFactory>);
|
||||||
Run(48000,
|
Run(48000,
|
||||||
PlatformChecksum("bf92db1e502deff5adf6fd2e6ab9a2e5",
|
PlatformChecksum("991b729aef7f08eca75d4c9ece848264",
|
||||||
"c37b110ab50d87620972daee5d1eaf31",
|
"0334f53d4e96156edc302e46ff5cfaec",
|
||||||
"5d55b68be7bcf39b60fcc74519363fb4",
|
"a578705020fe94ebde31b27d61035299",
|
||||||
"bd44bf97e7899186532f91235cef444d",
|
"bd44bf97e7899186532f91235cef444d",
|
||||||
"32eec738698ffe62b9777d6a349cd596"),
|
"c0d4185eacde6cd470c1a2ce4cd45318"),
|
||||||
factory, [](AudioCodingModule* acm) {
|
factory, [](AudioCodingModule* acm) {
|
||||||
acm->SetReceiveCodecs({{0, {"MockPCMu", 8000, 1}},
|
acm->SetReceiveCodecs({{0, {"MockPCMu", 8000, 1}},
|
||||||
{103, {"ISAC", 16000, 1}},
|
{103, {"ISAC", 16000, 1}},
|
||||||
@ -1328,7 +1328,7 @@ TEST_F(AcmSenderBitExactnessOldApi, IsacWb30ms) {
|
|||||||
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
||||||
"2c9cb15d4ed55b5a0cadd04883bc73b0",
|
"2c9cb15d4ed55b5a0cadd04883bc73b0",
|
||||||
"9336a9b993cbd8a751f0e8958e66c89c",
|
"9336a9b993cbd8a751f0e8958e66c89c",
|
||||||
"bd4682225f7c4ad5f2049f6769713ac2",
|
"5c2eb46199994506236f68b2c8e51b0d",
|
||||||
"343f1f42be0607c61e6516aece424609",
|
"343f1f42be0607c61e6516aece424609",
|
||||||
"2c9cb15d4ed55b5a0cadd04883bc73b0"),
|
"2c9cb15d4ed55b5a0cadd04883bc73b0"),
|
||||||
AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
||||||
@ -1343,11 +1343,11 @@ TEST_F(AcmSenderBitExactnessOldApi, IsacWb30ms) {
|
|||||||
TEST_F(AcmSenderBitExactnessOldApi, IsacWb60ms) {
|
TEST_F(AcmSenderBitExactnessOldApi, IsacWb60ms) {
|
||||||
ASSERT_NO_FATAL_FAILURE(SetUpTest("ISAC", 16000, 1, 103, 960, 960));
|
ASSERT_NO_FATAL_FAILURE(SetUpTest("ISAC", 16000, 1, 103, 960, 960));
|
||||||
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
Run(AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
||||||
"1ad29139a04782a33daad8c2b9b35875",
|
"f59760fa000991ee5fa81f2e607db254",
|
||||||
"14d63c5f08127d280e722e3191b73bdd",
|
"986aa16d7097a26e32e212e39ec58517",
|
||||||
"edcf26694c289e3d9691faf79b74f09f",
|
"9a81e467eb1485f84aca796f8ea65011",
|
||||||
"ef75e900e6f375e3061163c53fd09a63",
|
"ef75e900e6f375e3061163c53fd09a63",
|
||||||
"1ad29139a04782a33daad8c2b9b35875"),
|
"f59760fa000991ee5fa81f2e607db254"),
|
||||||
AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
AcmReceiverBitExactnessOldApi::PlatformChecksum(
|
||||||
"9e0a0ab743ad987b55b8e14802769c56",
|
"9e0a0ab743ad987b55b8e14802769c56",
|
||||||
"ebe04a819d3a9d83a83a17f271e1139a",
|
"ebe04a819d3a9d83a83a17f271e1139a",
|
||||||
|
@ -26,32 +26,22 @@ void BufferLevelFilter::Reset() {
|
|||||||
level_factor_ = 253;
|
level_factor_ = 253;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferLevelFilter::Update(size_t buffer_size_packets,
|
void BufferLevelFilter::Update(size_t buffer_size_samples,
|
||||||
int time_stretched_samples,
|
int time_stretched_samples) {
|
||||||
size_t packet_len_samples) {
|
|
||||||
// Filter:
|
// Filter:
|
||||||
// |filtered_current_level_| = |level_factor_| * |filtered_current_level_| +
|
// |filtered_current_level_| = |level_factor_| * |filtered_current_level_| +
|
||||||
// (1 - |level_factor_|) * |buffer_size_packets|
|
// (1 - |level_factor_|) * |buffer_size_samples|
|
||||||
// |level_factor_| and |filtered_current_level_| are in Q8.
|
// |level_factor_| and |filtered_current_level_| are in Q8.
|
||||||
// |buffer_size_packets| is in Q0.
|
// |buffer_size_samples| is in Q0.
|
||||||
filtered_current_level_ =
|
filtered_current_level_ =
|
||||||
((level_factor_ * filtered_current_level_) >> 8) +
|
((level_factor_ * filtered_current_level_) >> 8) +
|
||||||
((256 - level_factor_) * rtc::dchecked_cast<int>(buffer_size_packets));
|
((256 - level_factor_) * rtc::dchecked_cast<int>(buffer_size_samples));
|
||||||
|
|
||||||
// Account for time-scale operations (accelerate and pre-emptive expand).
|
// Account for time-scale operations (accelerate and pre-emptive expand) and
|
||||||
if (time_stretched_samples && packet_len_samples > 0) {
|
// make sure that the filtered value remains non-negative.
|
||||||
// Time-scaling has been performed since last filter update. Subtract the
|
filtered_current_level_ = rtc::saturated_cast<int>(std::max<int64_t>(
|
||||||
// value of |time_stretched_samples| from |filtered_current_level_| after
|
0,
|
||||||
// converting |time_stretched_samples| from samples to packets in Q8.
|
filtered_current_level_ - (int64_t{time_stretched_samples} * (1 << 8))));
|
||||||
// Make sure that the filtered value remains non-negative.
|
|
||||||
|
|
||||||
int64_t time_stretched_packets =
|
|
||||||
(int64_t{time_stretched_samples} * (1 << 8)) /
|
|
||||||
rtc::dchecked_cast<int64_t>(packet_len_samples);
|
|
||||||
|
|
||||||
filtered_current_level_ = rtc::saturated_cast<int>(
|
|
||||||
std::max<int64_t>(0, filtered_current_level_ - time_stretched_packets));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferLevelFilter::SetTargetBufferLevel(int target_buffer_level) {
|
void BufferLevelFilter::SetTargetBufferLevel(int target_buffer_level) {
|
||||||
@ -66,8 +56,4 @@ void BufferLevelFilter::SetTargetBufferLevel(int target_buffer_level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferLevelFilter::filtered_current_level() const {
|
|
||||||
return filtered_current_level_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -24,20 +24,20 @@ class BufferLevelFilter {
|
|||||||
virtual void Reset();
|
virtual void Reset();
|
||||||
|
|
||||||
// Updates the filter. Current buffer size is |buffer_size_packets| (Q0).
|
// Updates the filter. Current buffer size is |buffer_size_packets| (Q0).
|
||||||
// If |time_stretched_samples| is non-zero, the value is converted to the
|
// |time_stretched_samples| is subtracted from the filtered value (thus
|
||||||
// corresponding number of packets, and is subtracted from the filtered
|
// bypassing the filter operation).
|
||||||
// value (thus bypassing the filter operation). |packet_len_samples| is the
|
virtual void Update(size_t buffer_size_samples, int time_stretched_samples);
|
||||||
// number of audio samples carried in each incoming packet.
|
|
||||||
virtual void Update(size_t buffer_size_packets,
|
|
||||||
int time_stretched_samples,
|
|
||||||
size_t packet_len_samples);
|
|
||||||
|
|
||||||
// Set the current target buffer level (obtained from
|
// Set the current target buffer level in number of packets (obtained from
|
||||||
// DelayManager::base_target_level()). Used to select the appropriate
|
// DelayManager::base_target_level()). Used to select the appropriate
|
||||||
// filter coefficient.
|
// filter coefficient.
|
||||||
virtual void SetTargetBufferLevel(int target_buffer_level);
|
virtual void SetTargetBufferLevel(int target_buffer_level_packets);
|
||||||
|
|
||||||
virtual int filtered_current_level() const;
|
// Returns filtered current level in number of samples.
|
||||||
|
virtual int filtered_current_level() const {
|
||||||
|
// Round to nearest whole sample.
|
||||||
|
return (filtered_current_level_ + (1 << 7)) >> 8;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int level_factor_; // Filter factor for the buffer level filter in Q8.
|
int level_factor_; // Filter factor for the buffer level filter in Q8.
|
||||||
|
@ -35,18 +35,17 @@ TEST(BufferLevelFilter, ConvergenceTest) {
|
|||||||
ss << "times = " << times << ", value = " << value;
|
ss << "times = " << times << ", value = " << value;
|
||||||
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
||||||
for (int i = 0; i < times; ++i) {
|
for (int i = 0; i < times; ++i) {
|
||||||
filter.Update(value, 0 /* time_stretched_samples */,
|
filter.Update(value, 0 /* time_stretched_samples */);
|
||||||
160 /* packet_len_samples */);
|
|
||||||
}
|
}
|
||||||
// Expect the filtered value to be (theoretically)
|
// Expect the filtered value to be (theoretically)
|
||||||
// (1 - (251/256) ^ |times|) * |value|.
|
// (1 - (251/256) ^ |times|) * |value|.
|
||||||
double expected_value_double = (1 - pow(251.0 / 256.0, times)) * value;
|
double expected_value_double = (1 - pow(251.0 / 256.0, times)) * value;
|
||||||
int expected_value = static_cast<int>(expected_value_double);
|
int expected_value = static_cast<int>(expected_value_double);
|
||||||
// filtered_current_level() returns the value in Q8.
|
|
||||||
// The actual value may differ slightly from the expected value due to
|
// The actual value may differ slightly from the expected value due to
|
||||||
// intermediate-stage rounding errors in the filter implementation.
|
// intermediate-stage rounding errors in the filter implementation.
|
||||||
// This is why we have to use EXPECT_NEAR with a tolerance of +/-1.
|
// This is why we have to use EXPECT_NEAR with a tolerance of +/-1.
|
||||||
EXPECT_NEAR(expected_value, filter.filtered_current_level() >> 8, 1);
|
EXPECT_NEAR(expected_value, filter.filtered_current_level(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,38 +59,32 @@ TEST(BufferLevelFilter, FilterFactor) {
|
|||||||
|
|
||||||
filter.SetTargetBufferLevel(3); // Makes filter coefficient 252/256.
|
filter.SetTargetBufferLevel(3); // Makes filter coefficient 252/256.
|
||||||
for (int i = 0; i < kTimes; ++i) {
|
for (int i = 0; i < kTimes; ++i) {
|
||||||
filter.Update(kValue, 0 /* time_stretched_samples */,
|
filter.Update(kValue, 0 /* time_stretched_samples */);
|
||||||
160 /* packet_len_samples */);
|
|
||||||
}
|
}
|
||||||
// Expect the filtered value to be
|
// Expect the filtered value to be
|
||||||
// (1 - (252/256) ^ |kTimes|) * |kValue|.
|
// (1 - (252/256) ^ |kTimes|) * |kValue|.
|
||||||
int expected_value = 14;
|
int expected_value = 15;
|
||||||
// filtered_current_level() returns the value in Q8.
|
EXPECT_EQ(expected_value, filter.filtered_current_level());
|
||||||
EXPECT_EQ(expected_value, filter.filtered_current_level() >> 8);
|
|
||||||
|
|
||||||
filter.Reset();
|
filter.Reset();
|
||||||
filter.SetTargetBufferLevel(7); // Makes filter coefficient 253/256.
|
filter.SetTargetBufferLevel(7); // Makes filter coefficient 253/256.
|
||||||
for (int i = 0; i < kTimes; ++i) {
|
for (int i = 0; i < kTimes; ++i) {
|
||||||
filter.Update(kValue, 0 /* time_stretched_samples */,
|
filter.Update(kValue, 0 /* time_stretched_samples */);
|
||||||
160 /* packet_len_samples */);
|
|
||||||
}
|
}
|
||||||
// Expect the filtered value to be
|
// Expect the filtered value to be
|
||||||
// (1 - (253/256) ^ |kTimes|) * |kValue|.
|
// (1 - (253/256) ^ |kTimes|) * |kValue|.
|
||||||
expected_value = 11;
|
expected_value = 11;
|
||||||
// filtered_current_level() returns the value in Q8.
|
EXPECT_EQ(expected_value, filter.filtered_current_level());
|
||||||
EXPECT_EQ(expected_value, filter.filtered_current_level() >> 8);
|
|
||||||
|
|
||||||
filter.Reset();
|
filter.Reset();
|
||||||
filter.SetTargetBufferLevel(8); // Makes filter coefficient 254/256.
|
filter.SetTargetBufferLevel(8); // Makes filter coefficient 254/256.
|
||||||
for (int i = 0; i < kTimes; ++i) {
|
for (int i = 0; i < kTimes; ++i) {
|
||||||
filter.Update(kValue, 0 /* time_stretched_samples */,
|
filter.Update(kValue, 0 /* time_stretched_samples */);
|
||||||
160 /* packet_len_samples */);
|
|
||||||
}
|
}
|
||||||
// Expect the filtered value to be
|
// Expect the filtered value to be
|
||||||
// (1 - (254/256) ^ |kTimes|) * |kValue|.
|
// (1 - (254/256) ^ |kTimes|) * |kValue|.
|
||||||
expected_value = 7;
|
expected_value = 8;
|
||||||
// filtered_current_level() returns the value in Q8.
|
EXPECT_EQ(expected_value, filter.filtered_current_level());
|
||||||
EXPECT_EQ(expected_value, filter.filtered_current_level() >> 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferLevelFilter, TimeStretchedSamples) {
|
TEST(BufferLevelFilter, TimeStretchedSamples) {
|
||||||
@ -100,62 +93,24 @@ TEST(BufferLevelFilter, TimeStretchedSamples) {
|
|||||||
// Update 10 times with value 100.
|
// Update 10 times with value 100.
|
||||||
const int kTimes = 10;
|
const int kTimes = 10;
|
||||||
const int kValue = 100;
|
const int kValue = 100;
|
||||||
const int kPacketSizeSamples = 160;
|
const int kTimeStretchedSamples = 3;
|
||||||
const int kNumPacketsStretched = 2;
|
|
||||||
const int kTimeStretchedSamples = kNumPacketsStretched * kPacketSizeSamples;
|
|
||||||
for (int i = 0; i < kTimes; ++i) {
|
for (int i = 0; i < kTimes; ++i) {
|
||||||
// Packet size set to 0. Do not expect the parameter
|
filter.Update(kValue, 0);
|
||||||
// |kTimeStretchedSamples| to have any effect.
|
|
||||||
filter.Update(kValue, kTimeStretchedSamples, 0 /* packet_len_samples */);
|
|
||||||
}
|
}
|
||||||
// Expect the filtered value to be
|
// Expect the filtered value to be
|
||||||
// (1 - (251/256) ^ |kTimes|) * |kValue|.
|
// (1 - (251/256) ^ |kTimes|) * |kValue|.
|
||||||
const int kExpectedValue = 17;
|
const int kExpectedValue = 18;
|
||||||
// filtered_current_level() returns the value in Q8.
|
EXPECT_EQ(kExpectedValue, filter.filtered_current_level());
|
||||||
EXPECT_EQ(kExpectedValue, filter.filtered_current_level() >> 8);
|
|
||||||
|
|
||||||
// Update filter again, now with non-zero value for packet length.
|
// Update filter again, now with non-zero value for packet length.
|
||||||
// Set the current filtered value to be the input, in order to isolate the
|
// Set the current filtered value to be the input, in order to isolate the
|
||||||
// impact of |kTimeStretchedSamples|.
|
// impact of |kTimeStretchedSamples|.
|
||||||
filter.Update(filter.filtered_current_level() >> 8, kTimeStretchedSamples,
|
filter.Update(filter.filtered_current_level(), kTimeStretchedSamples);
|
||||||
kPacketSizeSamples);
|
EXPECT_EQ(kExpectedValue - kTimeStretchedSamples,
|
||||||
EXPECT_EQ(kExpectedValue - kNumPacketsStretched,
|
filter.filtered_current_level());
|
||||||
filter.filtered_current_level() >> 8);
|
|
||||||
// Try negative value and verify that we come back to the previous result.
|
// Try negative value and verify that we come back to the previous result.
|
||||||
filter.Update(filter.filtered_current_level() >> 8, -kTimeStretchedSamples,
|
filter.Update(filter.filtered_current_level(), -kTimeStretchedSamples);
|
||||||
kPacketSizeSamples);
|
EXPECT_EQ(kExpectedValue, filter.filtered_current_level());
|
||||||
EXPECT_EQ(kExpectedValue, filter.filtered_current_level() >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(BufferLevelFilter, TimeStretchedSamplesNegativeUnevenFrames) {
|
|
||||||
BufferLevelFilter filter;
|
|
||||||
filter.SetTargetBufferLevel(1); // Makes filter coefficient 251/256.
|
|
||||||
// Update 10 times with value 100.
|
|
||||||
const int kTimes = 10;
|
|
||||||
const int kValue = 100;
|
|
||||||
const int kPacketSizeSamples = 160;
|
|
||||||
const int kTimeStretchedSamples = -3.1415 * kPacketSizeSamples;
|
|
||||||
for (int i = 0; i < kTimes; ++i) {
|
|
||||||
// Packet size set to 0. Do not expect the parameter
|
|
||||||
// |kTimeStretchedSamples| to have any effect.
|
|
||||||
filter.Update(kValue, kTimeStretchedSamples, 0 /* packet_len_samples */);
|
|
||||||
}
|
|
||||||
// Expect the filtered value to be
|
|
||||||
// (1 - (251/256) ^ |kTimes|) * |kValue|.
|
|
||||||
const int kExpectedValue = 17;
|
|
||||||
// filtered_current_level() returns the value in Q8.
|
|
||||||
EXPECT_EQ(kExpectedValue, filter.filtered_current_level() >> 8);
|
|
||||||
|
|
||||||
// Update filter again, now with non-zero value for packet length.
|
|
||||||
// Set the current filtered value to be the input, in order to isolate the
|
|
||||||
// impact of |kTimeStretchedSamples|.
|
|
||||||
filter.Update(filter.filtered_current_level() >> 8, kTimeStretchedSamples,
|
|
||||||
kPacketSizeSamples);
|
|
||||||
EXPECT_EQ(21, filter.filtered_current_level() >> 8);
|
|
||||||
// Try negative value and verify that we come back to the previous result.
|
|
||||||
filter.Update(filter.filtered_current_level() >> 8, -kTimeStretchedSamples,
|
|
||||||
kPacketSizeSamples);
|
|
||||||
EXPECT_EQ(kExpectedValue, filter.filtered_current_level() >> 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -113,11 +113,9 @@ Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer,
|
|||||||
cng_state_ = kCngInternalOn;
|
cng_state_ = kCngInternalOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t samples_left =
|
|
||||||
sync_buffer.FutureLength() - expand.overlap_length();
|
|
||||||
// TODO(jakobi): Use buffer span instead of num samples.
|
// TODO(jakobi): Use buffer span instead of num samples.
|
||||||
const size_t cur_size_samples =
|
const size_t cur_size_samples =
|
||||||
samples_left + packet_buffer_.NumSamplesInBuffer(decoder_frame_length);
|
packet_buffer_.NumSamplesInBuffer(decoder_frame_length);
|
||||||
|
|
||||||
prev_time_scale_ =
|
prev_time_scale_ =
|
||||||
prev_time_scale_ && (prev_mode == kModeAccelerateSuccess ||
|
prev_time_scale_ && (prev_mode == kModeAccelerateSuccess ||
|
||||||
@ -175,8 +173,7 @@ Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer,
|
|||||||
// if the mute factor is low enough (otherwise the expansion was short enough
|
// if the mute factor is low enough (otherwise the expansion was short enough
|
||||||
// to not be noticable).
|
// to not be noticable).
|
||||||
// Note that the MuteFactor is in Q14, so a value of 16384 corresponds to 1.
|
// Note that the MuteFactor is in Q14, so a value of 16384 corresponds to 1.
|
||||||
size_t current_span =
|
size_t current_span = packet_buffer_.GetSpanSamples(decoder_frame_length);
|
||||||
samples_left + packet_buffer_.GetSpanSamples(decoder_frame_length);
|
|
||||||
if ((prev_mode == kModeExpand || prev_mode == kModeCodecPlc) &&
|
if ((prev_mode == kModeExpand || prev_mode == kModeCodecPlc) &&
|
||||||
expand.MuteFactor(0) < 16384 / 2 &&
|
expand.MuteFactor(0) < 16384 / 2 &&
|
||||||
current_span < static_cast<size_t>(delay_manager_->TargetLevel() *
|
current_span < static_cast<size_t>(delay_manager_->TargetLevel() *
|
||||||
@ -193,9 +190,9 @@ Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer,
|
|||||||
return ExpectedPacketAvailable(prev_mode, play_dtmf);
|
return ExpectedPacketAvailable(prev_mode, play_dtmf);
|
||||||
} else if (!PacketBuffer::IsObsoleteTimestamp(
|
} else if (!PacketBuffer::IsObsoleteTimestamp(
|
||||||
available_timestamp, target_timestamp, five_seconds_samples)) {
|
available_timestamp, target_timestamp, five_seconds_samples)) {
|
||||||
return FuturePacketAvailable(
|
return FuturePacketAvailable(decoder_frame_length, prev_mode,
|
||||||
sync_buffer, expand, decoder_frame_length, prev_mode, target_timestamp,
|
target_timestamp, available_timestamp,
|
||||||
available_timestamp, play_dtmf, generated_noise_samples);
|
play_dtmf, generated_noise_samples);
|
||||||
} else {
|
} else {
|
||||||
// This implies that available_timestamp < target_timestamp, which can
|
// This implies that available_timestamp < target_timestamp, which can
|
||||||
// happen when a new stream or codec is received. Signal for a reset.
|
// happen when a new stream or codec is received. Signal for a reset.
|
||||||
@ -215,19 +212,13 @@ void DecisionLogic::FilterBufferLevel(size_t buffer_size_samples) {
|
|||||||
buffer_level_filter_->SetTargetBufferLevel(
|
buffer_level_filter_->SetTargetBufferLevel(
|
||||||
delay_manager_->base_target_level());
|
delay_manager_->base_target_level());
|
||||||
|
|
||||||
size_t buffer_size_packets = 0;
|
|
||||||
if (packet_length_samples_ > 0) {
|
|
||||||
// Calculate size in packets.
|
|
||||||
buffer_size_packets = buffer_size_samples / packet_length_samples_;
|
|
||||||
}
|
|
||||||
int sample_memory_local = 0;
|
int sample_memory_local = 0;
|
||||||
if (prev_time_scale_) {
|
if (prev_time_scale_) {
|
||||||
sample_memory_local = sample_memory_;
|
sample_memory_local = sample_memory_;
|
||||||
timescale_countdown_ = tick_timer_->GetNewCountdown(kMinTimescaleInterval);
|
timescale_countdown_ = tick_timer_->GetNewCountdown(kMinTimescaleInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_level_filter_->Update(buffer_size_packets, sample_memory_local,
|
buffer_level_filter_->Update(buffer_size_samples, sample_memory_local);
|
||||||
packet_length_samples_);
|
|
||||||
prev_time_scale_ = false;
|
prev_time_scale_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,15 +274,22 @@ Operations DecisionLogic::NoPacket(bool play_dtmf) {
|
|||||||
Operations DecisionLogic::ExpectedPacketAvailable(Modes prev_mode,
|
Operations DecisionLogic::ExpectedPacketAvailable(Modes prev_mode,
|
||||||
bool play_dtmf) {
|
bool play_dtmf) {
|
||||||
if (!disallow_time_stretching_ && prev_mode != kModeExpand && !play_dtmf) {
|
if (!disallow_time_stretching_ && prev_mode != kModeExpand && !play_dtmf) {
|
||||||
// Check criterion for time-stretching.
|
// Check criterion for time-stretching. The values are in number of packets
|
||||||
|
// in Q8.
|
||||||
int low_limit, high_limit;
|
int low_limit, high_limit;
|
||||||
delay_manager_->BufferLimits(&low_limit, &high_limit);
|
delay_manager_->BufferLimits(&low_limit, &high_limit);
|
||||||
if (buffer_level_filter_->filtered_current_level() >= high_limit << 2)
|
int buffer_level_packets = 0;
|
||||||
|
if (packet_length_samples_ > 0) {
|
||||||
|
buffer_level_packets =
|
||||||
|
((1 << 8) * buffer_level_filter_->filtered_current_level()) /
|
||||||
|
packet_length_samples_;
|
||||||
|
}
|
||||||
|
if (buffer_level_packets >= high_limit << 2)
|
||||||
return kFastAccelerate;
|
return kFastAccelerate;
|
||||||
if (TimescaleAllowed()) {
|
if (TimescaleAllowed()) {
|
||||||
if (buffer_level_filter_->filtered_current_level() >= high_limit)
|
if (buffer_level_packets >= high_limit)
|
||||||
return kAccelerate;
|
return kAccelerate;
|
||||||
if (buffer_level_filter_->filtered_current_level() < low_limit)
|
if (buffer_level_packets < low_limit)
|
||||||
return kPreemptiveExpand;
|
return kPreemptiveExpand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,8 +297,6 @@ Operations DecisionLogic::ExpectedPacketAvailable(Modes prev_mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Operations DecisionLogic::FuturePacketAvailable(
|
Operations DecisionLogic::FuturePacketAvailable(
|
||||||
const SyncBuffer& sync_buffer,
|
|
||||||
const Expand& expand,
|
|
||||||
size_t decoder_frame_length,
|
size_t decoder_frame_length,
|
||||||
Modes prev_mode,
|
Modes prev_mode,
|
||||||
uint32_t target_timestamp,
|
uint32_t target_timestamp,
|
||||||
@ -327,10 +323,8 @@ Operations DecisionLogic::FuturePacketAvailable(
|
|||||||
return kNormal;
|
return kNormal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t samples_left =
|
|
||||||
sync_buffer.FutureLength() - expand.overlap_length();
|
|
||||||
const size_t cur_size_samples =
|
const size_t cur_size_samples =
|
||||||
samples_left + packet_buffer_.NumPacketsInBuffer() * decoder_frame_length;
|
packet_buffer_.NumPacketsInBuffer() * decoder_frame_length;
|
||||||
|
|
||||||
// If previous was comfort noise, then no merge is needed.
|
// If previous was comfort noise, then no merge is needed.
|
||||||
if (prev_mode == kModeRfc3389Cng || prev_mode == kModeCodecInternalCng) {
|
if (prev_mode == kModeRfc3389Cng || prev_mode == kModeCodecInternalCng) {
|
||||||
@ -365,8 +359,13 @@ Operations DecisionLogic::FuturePacketAvailable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DecisionLogic::UnderTargetLevel() const {
|
bool DecisionLogic::UnderTargetLevel() const {
|
||||||
return buffer_level_filter_->filtered_current_level() <=
|
int buffer_level_packets = 0;
|
||||||
delay_manager_->TargetLevel();
|
if (packet_length_samples_ > 0) {
|
||||||
|
buffer_level_packets =
|
||||||
|
((1 << 8) * buffer_level_filter_->filtered_current_level()) /
|
||||||
|
packet_length_samples_;
|
||||||
|
}
|
||||||
|
return buffer_level_packets <= delay_manager_->TargetLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DecisionLogic::ReinitAfterExpands(uint32_t timestamp_leap) const {
|
bool DecisionLogic::ReinitAfterExpands(uint32_t timestamp_leap) const {
|
||||||
|
@ -134,9 +134,7 @@ class DecisionLogic final {
|
|||||||
|
|
||||||
// Returns the operation to do given that the expected packet is not
|
// Returns the operation to do given that the expected packet is not
|
||||||
// available, but a packet further into the future is at hand.
|
// available, but a packet further into the future is at hand.
|
||||||
Operations FuturePacketAvailable(const SyncBuffer& sync_buffer,
|
Operations FuturePacketAvailable(size_t decoder_frame_length,
|
||||||
const Expand& expand,
|
|
||||||
size_t decoder_frame_length,
|
|
||||||
Modes prev_mode,
|
Modes prev_mode,
|
||||||
uint32_t target_timestamp,
|
uint32_t target_timestamp,
|
||||||
uint32_t available_timestamp,
|
uint32_t available_timestamp,
|
||||||
|
@ -22,10 +22,8 @@ class MockBufferLevelFilter : public BufferLevelFilter {
|
|||||||
virtual ~MockBufferLevelFilter() { Die(); }
|
virtual ~MockBufferLevelFilter() { Die(); }
|
||||||
MOCK_METHOD0(Die, void());
|
MOCK_METHOD0(Die, void());
|
||||||
MOCK_METHOD0(Reset, void());
|
MOCK_METHOD0(Reset, void());
|
||||||
MOCK_METHOD3(Update,
|
MOCK_METHOD2(Update,
|
||||||
void(size_t buffer_size_packets,
|
void(size_t buffer_size_samples, int time_stretched_samples));
|
||||||
int time_stretched_samples,
|
|
||||||
size_t packet_len_samples));
|
|
||||||
MOCK_METHOD1(SetTargetBufferLevel, void(int target_buffer_level));
|
MOCK_METHOD1(SetTargetBufferLevel, void(int target_buffer_level));
|
||||||
MOCK_CONST_METHOD0(filtered_current_level, int());
|
MOCK_CONST_METHOD0(filtered_current_level, int());
|
||||||
};
|
};
|
||||||
|
@ -310,18 +310,12 @@ int NetEqImpl::TargetDelayMs() const {
|
|||||||
|
|
||||||
int NetEqImpl::FilteredCurrentDelayMs() const {
|
int NetEqImpl::FilteredCurrentDelayMs() const {
|
||||||
rtc::CritScope lock(&crit_sect_);
|
rtc::CritScope lock(&crit_sect_);
|
||||||
// Calculate the filtered packet buffer level in samples. The value from
|
|
||||||
// |buffer_level_filter_| is in number of packets, represented in Q8.
|
|
||||||
const size_t packet_buffer_samples =
|
|
||||||
(buffer_level_filter_->filtered_current_level() *
|
|
||||||
decoder_frame_length_) >>
|
|
||||||
8;
|
|
||||||
// Sum up the filtered packet buffer level with the future length of the sync
|
// Sum up the filtered packet buffer level with the future length of the sync
|
||||||
// buffer, and divide the sum by the sample rate.
|
// buffer.
|
||||||
const size_t delay_samples =
|
const int delay_samples = buffer_level_filter_->filtered_current_level() +
|
||||||
packet_buffer_samples + sync_buffer_->FutureLength();
|
sync_buffer_->FutureLength();
|
||||||
// The division below will truncate. The return value is in ms.
|
// The division below will truncate. The return value is in ms.
|
||||||
return static_cast<int>(delay_samples) / rtc::CheckedDivExact(fs_hz_, 1000);
|
return delay_samples / rtc::CheckedDivExact(fs_hz_, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
|
int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
|
||||||
|
@ -458,16 +458,16 @@ TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) {
|
|||||||
webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp");
|
webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp");
|
||||||
|
|
||||||
const std::string output_checksum =
|
const std::string output_checksum =
|
||||||
PlatformChecksum("9652cee1d6771a9cbfda821ae1bbdb41b0dd4dee",
|
PlatformChecksum("998be2e5a707e636af0b6298f54bedfabe72aae1",
|
||||||
"54a7e32f163663c0af35bf70bf45cefc24ad62ef", "not used",
|
"61e238ece4cd3b67d66a0b7047e06b20607dcb79", "not used",
|
||||||
"9652cee1d6771a9cbfda821ae1bbdb41b0dd4dee",
|
"998be2e5a707e636af0b6298f54bedfabe72aae1",
|
||||||
"79496b0a1ef0a3824f3ee04789748a461bed643f");
|
"4116ac2a6e75baac3194b712d6fabe28b384275e");
|
||||||
|
|
||||||
const std::string network_stats_checksum =
|
const std::string network_stats_checksum =
|
||||||
PlatformChecksum("c59b1f9f282b6d8733cdff975e3c150ca4a47d51",
|
PlatformChecksum("3689c9f0ab9e50cefab3e44c37c3d7aa0de82ca4",
|
||||||
"bca95e565996a4ffd6e2ac15736e08843bdca93b", "not used",
|
"0a596217fccd8d90eff7d1666b8cc63143eeda12", "not used",
|
||||||
"c59b1f9f282b6d8733cdff975e3c150ca4a47d51",
|
"3689c9f0ab9e50cefab3e44c37c3d7aa0de82ca4",
|
||||||
"c59b1f9f282b6d8733cdff975e3c150ca4a47d51");
|
"3689c9f0ab9e50cefab3e44c37c3d7aa0de82ca4");
|
||||||
|
|
||||||
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
|
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
|
||||||
FLAG_gen_ref);
|
FLAG_gen_ref);
|
||||||
@ -486,17 +486,17 @@ TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) {
|
|||||||
// Checksum depends on libopus being compiled with or without SSE.
|
// Checksum depends on libopus being compiled with or without SSE.
|
||||||
const std::string maybe_sse =
|
const std::string maybe_sse =
|
||||||
"14a63b3c7b925c82296be4bafc71bec85f2915c2|"
|
"14a63b3c7b925c82296be4bafc71bec85f2915c2|"
|
||||||
"2c05677daa968d6c68b92adf4affb7cd9bb4d363";
|
"eb0b68bddcac00fc85403df64f83126f8ea9bc93";
|
||||||
const std::string output_checksum = PlatformChecksum(
|
const std::string output_checksum = PlatformChecksum(
|
||||||
maybe_sse, "b7b7ed802b0e18ee416973bf3b9ae98599b0181d",
|
maybe_sse, "f95f2a220c9ca5d60b81c4653d46e0de2bee159f",
|
||||||
"5876e52dda90d5ca433c3726555b907b97c86374", maybe_sse, maybe_sse);
|
"6f288a03d34958f62496f18fa85655593eef4dbe", maybe_sse, maybe_sse);
|
||||||
|
|
||||||
const std::string network_stats_checksum =
|
const std::string network_stats_checksum =
|
||||||
PlatformChecksum("adb3272498e436d1c019cbfd71610e9510c54497",
|
PlatformChecksum("0b3d34baffaf651812ffaf06ea1b5ce45ea1c47a",
|
||||||
"fa935a91abc7291db47428a2d7c5361b98713a92",
|
"a71dce66c7bea85ba22d4e29a5298f606f810444",
|
||||||
"42106aa5267300f709f63737707ef07afd9dac61",
|
"7c64e1e915bace7c4bf583484efd64eaf234552f",
|
||||||
"adb3272498e436d1c019cbfd71610e9510c54497",
|
"0b3d34baffaf651812ffaf06ea1b5ce45ea1c47a",
|
||||||
"adb3272498e436d1c019cbfd71610e9510c54497");
|
"0b3d34baffaf651812ffaf06ea1b5ce45ea1c47a");
|
||||||
|
|
||||||
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
|
DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum,
|
||||||
FLAG_gen_ref);
|
FLAG_gen_ref);
|
||||||
@ -796,7 +796,7 @@ TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDriftNetworkFreeze) {
|
|||||||
const double kDriftFactor = 1000.0 / (1000.0 + 25.0);
|
const double kDriftFactor = 1000.0 / (1000.0 + 25.0);
|
||||||
const double kNetworkFreezeTimeMs = 5000.0;
|
const double kNetworkFreezeTimeMs = 5000.0;
|
||||||
const bool kGetAudioDuringFreezeRecovery = false;
|
const bool kGetAudioDuringFreezeRecovery = false;
|
||||||
const int kDelayToleranceMs = 50;
|
const int kDelayToleranceMs = 60;
|
||||||
const int kMaxTimeToSpeechMs = 200;
|
const int kMaxTimeToSpeechMs = 200;
|
||||||
LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs,
|
LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs,
|
||||||
kGetAudioDuringFreezeRecovery, kDelayToleranceMs,
|
kGetAudioDuringFreezeRecovery, kDelayToleranceMs,
|
||||||
|
Reference in New Issue
Block a user