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

Unified Diff: webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc

Issue 2895083002: Add FlexfecReceiver unit test for infinite recovery loop. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc
index 508521da5dc487bdf1a3c3a5f0d9e4e0a72ba757..39ee86b69b3a6890bcd52e9906f7ee79cf1e484f 100644
--- a/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc
@@ -301,10 +301,17 @@ TEST_F(FlexfecReceiverTest, DoesNotCallbackTwice) {
Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length)));
receiver_.OnRtpPacket(ParsePacket(*packet_with_rtp_header));
- // Receive FEC packet again.
+ // Receive the FEC packet again, but do not call back.
receiver_.OnRtpPacket(ParsePacket(*packet_with_rtp_header));
- // Do not call back again.
+ // Receive the first media packet again, but do not call back.
+ media_it = media_packets.begin();
+ receiver_.OnRtpPacket(ParsePacket(**media_it));
+
+ // Receive the second media packet again (the one recovered above),
+ // but do not call back again.
+ media_it++;
+ receiver_.OnRtpPacket(ParsePacket(**media_it));
}
// Here we are implicitly assuming packet masks that are suitable for
@@ -464,6 +471,58 @@ TEST_F(FlexfecReceiverTest, RecoversWithMediaPacketsOutOfOrder) {
}
}
+// Recovered media packet may be fed back into the FlexfecReceiver by the
+// callback. This test ensures the idempotency of such a situation.
+TEST_F(FlexfecReceiverTest, RecoveryCallbackDoesNotLoopInfinitely) {
+ class LoopbackRecoveredPacketReceiver : public RecoveredPacketReceiver {
+ public:
+ LoopbackRecoveredPacketReceiver()
+ : receiver_(nullptr), did_receive_call_back_(false) {}
+
+ void SetReceiver(FlexfecReceiver* receiver) { receiver_ = receiver; }
+
+ bool DidReceiveCallback() { return did_receive_call_back_; }
+
+ // Implements RecoveredPacketReceiver.
+ void OnRecoveredPacket(const uint8_t* packet, size_t length) {
nisse-webrtc 2017/05/22 10:39:05 Can you add the recursion counter here? Something
brandtr 2017/05/22 11:52:39 Yes, that makes a lot of sense! I forgot that I ha
+ RtpPacketReceived parsed_packet;
+ EXPECT_TRUE(parsed_packet.Parse(packet, length));
+ RTC_DCHECK(receiver_);
+ receiver_->OnRtpPacket(parsed_packet);
+ did_receive_call_back_ = true;
+ }
+
+ private:
+ FlexfecReceiver* receiver_;
+ bool did_receive_call_back_;
+ } loopback_recovered_packet_receiver;
+
+ // Feed recovered packets back into |receiver|.
+ FlexfecReceiver receiver(kFlexfecSsrc, kMediaSsrc,
+ &loopback_recovered_packet_receiver);
+ loopback_recovered_packet_receiver.SetReceiver(&receiver);
+
+ const size_t kNumMediaPackets = 2;
+ const size_t kNumFecPackets = 1;
+
+ PacketList media_packets;
+ PacketizeFrame(kNumMediaPackets, 0, &media_packets);
+ std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets);
+
+ // Receive first media packet but drop second.
+ auto media_it = media_packets.begin();
+ receiver.OnRtpPacket(ParsePacket(**media_it));
+
+ // Receive FEC packet and verify that a packet was recovered.
+ auto fec_it = fec_packets.begin();
+ std::unique_ptr<Packet> packet_with_rtp_header =
+ packet_generator_.BuildFlexfecPacket(**fec_it);
+ receiver.OnRtpPacket(ParsePacket(*packet_with_rtp_header));
+ EXPECT_TRUE(loopback_recovered_packet_receiver.DidReceiveCallback());
+
+ // No extra callback, and thus no infinite loop.
nisse-webrtc 2017/05/22 08:39:20 If this test fails (by undoing the fix in the othe
brandtr 2017/05/22 09:10:09 Yes, I this test crashes by undoing your change.
danilchap 2017/05/22 09:17:28 did you try EXPECT_DEATH ? (not sure it would in t
danilchap 2017/05/22 09:18:22 nvm... it is for opposite case.
nisse-webrtc 2017/05/22 10:39:05 I agree it's worth doing only if it can be done by
+}
+
TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) {
const size_t kNumMediaPackets = 2;
const size_t kNumFecPackets = 1;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698