Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: webrtc/modules/audio_coding/neteq/neteq_unittest.cc

Issue 2839163002: NetEq: Add functionality to assist with delay analysis and tooling (Closed)
Patch Set: After first round of reviews Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/neteq_unittest.cc
diff --git a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
index 68a4921147a788b82cb19db4ffe56c10edfeabe2..03a788eed0bd7587980d8e273ae0f267253f7f4d 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
@@ -270,8 +270,6 @@ class NetEqDecodingTest : public ::testing::Test {
void DuplicateCng();
- rtc::Optional<uint32_t> PlayoutTimestamp();
-
NetEq* neteq_;
NetEq::Config config_;
std::unique_ptr<test::RtpFileSource> rtp_source_;
@@ -644,7 +642,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
}
EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
- rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
+ rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp();
ASSERT_TRUE(playout_timestamp);
int32_t delay_before = timestamp - *playout_timestamp;
@@ -736,7 +734,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
// Check that the speech starts again within reasonable time.
double time_until_speech_returns_ms = t_ms - speech_restart_time_ms;
EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms);
- playout_timestamp = PlayoutTimestamp();
+ playout_timestamp = neteq_->GetPlayoutTimestamp();
ASSERT_TRUE(playout_timestamp);
int32_t delay_after = timestamp - *playout_timestamp;
// Compare delay before and after, and make sure it differs less than 20 ms.
@@ -1128,7 +1126,7 @@ void NetEqDecodingTest::WrapTest(uint16_t start_seq_no,
ASSERT_EQ(1u, output.num_channels_);
// Expect delay (in samples) to be less than 2 packets.
- rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
+ rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp();
ASSERT_TRUE(playout_timestamp);
EXPECT_LE(timestamp - *playout_timestamp,
static_cast<uint32_t>(kSamples * 2));
@@ -1207,7 +1205,8 @@ void NetEqDecodingTest::DuplicateCng() {
ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted));
ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
- EXPECT_FALSE(PlayoutTimestamp()); // Returns empty value during CNG.
+ EXPECT_FALSE(
+ neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG.
EXPECT_EQ(timestamp - algorithmic_delay_samples,
out_frame_.timestamp_ + out_frame_.samples_per_channel_);
@@ -1223,7 +1222,8 @@ void NetEqDecodingTest::DuplicateCng() {
ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted));
ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
- EXPECT_FALSE(PlayoutTimestamp()); // Returns empty value during CNG.
+ EXPECT_FALSE(
+ neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG.
EXPECT_EQ(timestamp - algorithmic_delay_samples,
out_frame_.timestamp_ + out_frame_.samples_per_channel_);
}
@@ -1238,16 +1238,12 @@ void NetEqDecodingTest::DuplicateCng() {
ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted));
ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
- rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
+ rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp();
ASSERT_TRUE(playout_timestamp);
EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples,
*playout_timestamp);
}
-rtc::Optional<uint32_t> NetEqDecodingTest::PlayoutTimestamp() {
- return neteq_->GetPlayoutTimestamp();
-}
-
TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { DuplicateCng(); }
TEST_F(NetEqDecodingTest, CngFirst) {
@@ -1590,4 +1586,65 @@ TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) {
EXPECT_FALSE(muted);
}
+TEST_F(NetEqDecodingTest, LastDecodedTimestampsEmpty) {
+ EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty());
+
+ // Pull out data once.
+ AudioFrame output;
+ bool muted;
+ ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
+
+ EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty());
+}
+
+TEST_F(NetEqDecodingTest, LastDecodedTimestampsOneDecoded) {
+ // Insert one packet with PCM16b WB data (this is what PopulateRtpInfo does by
+ // default). Make the length 10 ms.
+ constexpr size_t kPayloadSamples = 16 * 10;
+ constexpr size_t kPayloadBytes = 2 * kPayloadSamples;
+ uint8_t payload[kPayloadBytes] = {0};
+
+ RTPHeader rtp_info;
+ constexpr uint32_t kRtpTimestamp = 0x1234;
+ PopulateRtpInfo(0, kRtpTimestamp, &rtp_info);
+ EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
+
+ // Pull out data once.
+ AudioFrame output;
+ bool muted;
+ ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
+
+ EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp}),
+ neteq_->LastDecodedTimestamps());
+
+ // Nothing decoded on the second call.
+ ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
+ EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty());
+}
+
+TEST_F(NetEqDecodingTest, LastDecodedTimestampsTwoDecoded) {
+ // Insert two packets with PCM16b WB data (this is what PopulateRtpInfo does
+ // by default). Make the length 5 ms so that NetEq must decode them both in
+ // the same GetAudio call.
+ constexpr size_t kPayloadSamples = 16 * 5;
+ constexpr size_t kPayloadBytes = 2 * kPayloadSamples;
+ uint8_t payload[kPayloadBytes] = {0};
+
+ RTPHeader rtp_info;
+ constexpr uint32_t kRtpTimestamp1 = 0x1234;
+ PopulateRtpInfo(0, kRtpTimestamp1, &rtp_info);
+ EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
+ constexpr uint32_t kRtpTimestamp2 = kRtpTimestamp1 + kPayloadSamples;
+ PopulateRtpInfo(1, kRtpTimestamp2, &rtp_info);
+ EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
+
+ // Pull out data once.
+ AudioFrame output;
+ bool muted;
+ ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
+
+ EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp1, kRtpTimestamp2}),
+ neteq_->LastDecodedTimestamps());
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/sync_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698