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

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

Issue 2307493002: NetEq: Flush and reset if the speech and cng sample rates mismatch (Closed)
Patch Set: Updates after review Created 4 years, 3 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
« no previous file with comments | « webrtc/modules/audio_coding/neteq/packet_buffer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
index 45669430f78f119582abb5fcb79d8c2f28424cf3..3635a765368ea8e1b2ebe837e8a19682c88dfccb 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
@@ -384,6 +384,67 @@ TEST(PacketBuffer, Reordering) {
EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
}
+// The test first inserts a packet with narrow-band CNG, then a packet with
+// wide-band speech. The expected behavior of the packet buffer is to detect a
+// change in sample rate, even though no speech packet has been inserted before,
+// and flush out the CNG packet.
+TEST(PacketBuffer, CngFirstThenSpeechWithNewSampleRate) {
+ TickTimer tick_timer;
+ PacketBuffer buffer(10, &tick_timer); // 10 packets.
+ const uint8_t kCngPt = 13;
+ const int kPayloadLen = 10;
+ const uint8_t kSpeechPt = 100;
+
+ MockDecoderDatabase decoder_database;
+ auto factory = CreateBuiltinAudioDecoderFactory();
+ const DecoderDatabase::DecoderInfo infoCng(NetEqDecoder::kDecoderCNGnb, "",
minyue-webrtc 2016/09/01 15:59:45 info_cng
hlundin-webrtc 2016/09/01 16:11:15 kInfoCng, because it is a compile-time constant.
hlundin-webrtc 2016/09/01 16:15:27 No, you are right. Because of "factory", this is n
+ factory);
+ EXPECT_CALL(decoder_database, GetDecoderInfo(kCngPt))
+ .WillRepeatedly(Return(&infoCng));
+ const DecoderDatabase::DecoderInfo infoSpeech(NetEqDecoder::kDecoderPCM16Bwb,
+ "", factory);
+ EXPECT_CALL(decoder_database, GetDecoderInfo(kSpeechPt))
+ .WillRepeatedly(Return(&infoSpeech));
minyue-webrtc 2016/09/01 15:59:45 info_speech
hlundin-webrtc 2016/09/01 16:11:15 kInfoSpeech, because it is a compile-time constant
hlundin-webrtc 2016/09/01 16:15:26 No, you are right. Because of "factory", this is n
+
+ // Insert first packet, which is narrow-band CNG.
+ PacketGenerator gen(0, 0, kCngPt, 10);
+ PacketList list;
+ list.push_back(gen.NextPacket(kPayloadLen));
+ rtc::Optional<uint8_t> current_pt;
+ rtc::Optional<uint8_t> current_cng_pt;
+ EXPECT_EQ(PacketBuffer::kOK,
+ buffer.InsertPacketList(&list, decoder_database, &current_pt,
+ &current_cng_pt));
+ EXPECT_TRUE(list.empty());
+ EXPECT_EQ(1u, buffer.NumPacketsInBuffer());
+ ASSERT_TRUE(buffer.NextRtpHeader());
+ EXPECT_EQ(kCngPt, buffer.NextRtpHeader()->payloadType);
+ EXPECT_FALSE(current_pt); // Current payload type not set.
+ EXPECT_EQ(rtc::Optional<uint8_t>(kCngPt),
+ current_cng_pt); // CNG payload type set.
+
+ // Insert second packet, which is wide-band speech.
+ Packet* packet = gen.NextPacket(kPayloadLen);
+ packet->header.payloadType = kSpeechPt;
+ list.push_back(packet);
+ // Expect the buffer to flush out the CNG packet, since it does not match the
+ // new speech sample rate.
+ EXPECT_EQ(PacketBuffer::kFlushed,
+ buffer.InsertPacketList(&list, decoder_database, &current_pt,
+ &current_cng_pt));
+ EXPECT_TRUE(list.empty());
+ EXPECT_EQ(1u, buffer.NumPacketsInBuffer());
+ ASSERT_TRUE(buffer.NextRtpHeader());
+ EXPECT_EQ(kSpeechPt, buffer.NextRtpHeader()->payloadType);
+
+ EXPECT_EQ(rtc::Optional<uint8_t>(kSpeechPt),
+ current_pt); // Current payload type set.
+ EXPECT_FALSE(current_cng_pt); // CNG payload type reset.
+
+ buffer.Flush(); // Clean up.
+ EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
+}
+
TEST(PacketBuffer, Failures) {
const uint16_t start_seq_no = 17;
const uint32_t start_ts = 4711;
« no previous file with comments | « webrtc/modules/audio_coding/neteq/packet_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698