Index: webrtc/call/flexfec_receive_stream_unittest.cc |
diff --git a/webrtc/call/flexfec_receive_stream_unittest.cc b/webrtc/call/flexfec_receive_stream_unittest.cc |
index 68f2a2d0203640c6fb3df8b065614f8d7bf03951..1196b5bea9b654076697b01d7c3cd922a12c9f99 100644 |
--- a/webrtc/call/flexfec_receive_stream_unittest.cc |
+++ b/webrtc/call/flexfec_receive_stream_unittest.cc |
@@ -10,22 +10,41 @@ |
#include "webrtc/base/basictypes.h" |
#include "webrtc/call/flexfec_receive_stream.h" |
+#include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_estimator.h" |
#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
+#include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
#include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
#include "webrtc/test/gmock.h" |
#include "webrtc/test/gtest.h" |
namespace webrtc { |
+namespace { |
+ |
+using ::testing::_; |
+using ::testing::Return; |
+ |
+RtpPacketReceived ParsePacket(const uint8_t* data, size_t length) { |
danilchap
2016/12/13 14:11:24
taking rtc::ArrayView<const uint8_t> as a single p
brandtr
2016/12/14 12:55:49
Done. Added a convenience ctor to rtp::Packet too.
|
+ RtpPacketReceived packet(nullptr); |
+ packet.Parse(data, length); |
danilchap
2016/12/13 14:11:24
EXPECT_TRUE(packet.Parse(data, length));
to have b
brandtr
2016/12/14 12:55:49
Done.
|
+ return packet; |
+} |
+ |
+} // namespace |
+ |
TEST(FlexfecReceiveStreamTest, ConstructDestruct) { |
FlexfecReceiveStream::Config config; |
config.payload_type = 118; |
config.remote_ssrc = 424223; |
config.protected_media_ssrcs = {912512}; |
MockRecoveredPacketReceiver callback; |
+ MockRemoteBitrateEstimator bwe; |
- internal::FlexfecReceiveStream receive_stream(config, &callback); |
+ internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
} |
TEST(FlexfecReceiveStreamTest, StartStop) { |
@@ -34,7 +53,8 @@ TEST(FlexfecReceiveStreamTest, StartStop) { |
config.remote_ssrc = 1652392; |
config.protected_media_ssrcs = {23300443}; |
MockRecoveredPacketReceiver callback; |
- internal::FlexfecReceiveStream receive_stream(config, &callback); |
+ MockRemoteBitrateEstimator bwe; |
+ internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
receive_stream.Start(); |
receive_stream.Stop(); |
@@ -46,12 +66,13 @@ TEST(FlexfecReceiveStreamTest, DoesNotProcessPacketWhenNoMediaSsrcGiven) { |
config.remote_ssrc = 424223; |
config.protected_media_ssrcs = {}; |
MockRecoveredPacketReceiver callback; |
- internal::FlexfecReceiveStream receive_stream(config, &callback); |
+ MockRemoteBitrateEstimator bwe; |
+ internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
const uint8_t packet[] = {0x00, 0x11, 0x22, 0x33}; |
const size_t packet_length = sizeof(packet); |
- EXPECT_FALSE( |
- receive_stream.AddAndProcessReceivedPacket(packet, packet_length)); |
+ EXPECT_FALSE(receive_stream.AddAndProcessReceivedPacket( |
+ ParsePacket(packet, packet_length))); |
} |
// Create a FlexFEC packet that protects a single media packet and ensure |
@@ -98,21 +119,87 @@ TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
config.protected_media_ssrcs = { |
ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
- testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
- internal::FlexfecReceiveStream receive_stream(config, |
- &recovered_packet_receiver); |
+ testing::StrictMock<MockRecoveredPacketReceiver> callback; |
+ MockRemoteBitrateEstimator bwe; |
+ internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
// Do not call back before being started. |
- receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, |
- kFlexfecPacketLength); |
+ receive_stream.AddAndProcessReceivedPacket( |
+ ParsePacket(kFlexfecPacket, kFlexfecPacketLength)); |
// Call back after being started. |
receive_stream.Start(); |
- EXPECT_CALL( |
- recovered_packet_receiver, |
- OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); |
- receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, |
- kFlexfecPacketLength); |
+ EXPECT_CALL(callback, |
+ OnRecoveredPacket(_, kRtpHeaderSize + kPayloadLength[1])); |
+ receive_stream.AddAndProcessReceivedPacket( |
+ ParsePacket(kFlexfecPacket, kFlexfecPacketLength)); |
+} |
+ |
+// Verifies that the BWE is notified of received FlexFEC packets. |
+TEST(FlexfecReceiveStreamTest, |
+ NotifiesBweOfReceivedFecPacketWithTransportSequenceNumberExtension) { |
+ constexpr uint8_t kFlexfecPlType = 118; |
+ constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
+ |
+ // Set up config with RTP header extensions. |
+ FlexfecReceiveStream::Config config; |
+ config.payload_type = kFlexfecPlType; |
+ config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
+ config.protected_media_ssrcs = {123}; |
+ config.transport_cc = true; |
+ config.rtp_header_extensions = { |
+ RtpExtension(TransportSequenceNumber::kUri, 7)}; |
+ RtpHeaderExtensionMap rtp_header_extension_map; |
+ rtp_header_extension_map.Register<TransportSequenceNumber>(7); |
+ |
+ // Create FEC packet with a RTP header extension. |
+ constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
+ constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
+ constexpr uint8_t kMediaPlType = 107; |
+ constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; |
+ constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
+ constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; |
+ constexpr uint8_t kKBit0 = 1 << 7; |
+ constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; |
+ constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; |
+ constexpr uint8_t kSsrcCount = 1; |
+ constexpr uint8_t kReservedBits = 0x00; |
+ constexpr uint8_t kPayloadBits = 0x00; |
+ // clang-format off |
+ constexpr uint8_t kFlexfecPacket[] = { |
+ // RTP header. |
+ 0x90, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], |
+ kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], |
danilchap
2016/12/13 14:11:24
0xaa, 0xbb, 0xcc, 0xdd, // Flexfex rtp timestamp.
|
+ kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], |
+ // Transport-wide sequence number extension. |
+ // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 |
+ 0xbe, 0xde, /* magic constant */ 0x00, 0x01, /* length = 1 */ |
danilchap
2016/12/13 14:11:24
may be instead of inline comments use more lines:
|
+ 0x71, /* ID = 7, L = 1 */ 0xab, 0xcd, /* s.n. */ 0x00, /* pad. */ |
+ // FlexFEC header. |
+ 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], |
+ kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], |
+ kSsrcCount, kReservedBits, kReservedBits, kReservedBits, |
+ kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], |
+ kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], |
+ // FEC payload. |
+ kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
+ // clang-format on |
+ constexpr size_t kFlexfecPacketLength = sizeof(kFlexfecPacket); |
+ |
+ // Set up objects. |
+ testing::StrictMock<MockRecoveredPacketReceiver> callback; |
+ testing::StrictMock<MockRemoteBitrateEstimator> bwe; |
+ internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
+ receive_stream.Start(); |
+ |
+ // Expect recovery and BWE notification. |
+ EXPECT_CALL(callback, OnRecoveredPacket(_, _)).WillOnce(Return(true)); |
+ EXPECT_CALL(bwe, IncomingPacket(_, _, _)); |
+ |
+ // Add packet to receive stream. |
+ RtpPacketReceived parsed_packet(&rtp_header_extension_map); |
+ RTC_DCHECK(parsed_packet.Parse(kFlexfecPacket, kFlexfecPacketLength)); |
+ EXPECT_TRUE(receive_stream.AddAndProcessReceivedPacket(parsed_packet)); |
} |
} // namespace webrtc |