OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/basictypes.h" | 11 #include "webrtc/base/basictypes.h" |
12 #include "webrtc/call/flexfec_receive_stream.h" | 12 #include "webrtc/call/flexfec_receive_stream.h" |
13 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" | |
13 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 14 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
16 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | |
17 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | |
19 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | |
15 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" | 20 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
16 #include "webrtc/test/gmock.h" | 21 #include "webrtc/test/gmock.h" |
17 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
18 | 23 |
19 namespace webrtc { | 24 namespace webrtc { |
20 | 25 |
26 namespace { | |
27 | |
28 using ::testing::_; | |
29 using ::testing::Return; | |
30 | |
31 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.
| |
32 RtpPacketReceived packet(nullptr); | |
33 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.
| |
34 return packet; | |
35 } | |
36 | |
37 } // namespace | |
38 | |
21 TEST(FlexfecReceiveStreamTest, ConstructDestruct) { | 39 TEST(FlexfecReceiveStreamTest, ConstructDestruct) { |
22 FlexfecReceiveStream::Config config; | 40 FlexfecReceiveStream::Config config; |
23 config.payload_type = 118; | 41 config.payload_type = 118; |
24 config.remote_ssrc = 424223; | 42 config.remote_ssrc = 424223; |
25 config.protected_media_ssrcs = {912512}; | 43 config.protected_media_ssrcs = {912512}; |
26 MockRecoveredPacketReceiver callback; | 44 MockRecoveredPacketReceiver callback; |
45 MockRemoteBitrateEstimator bwe; | |
27 | 46 |
28 internal::FlexfecReceiveStream receive_stream(config, &callback); | 47 internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
29 } | 48 } |
30 | 49 |
31 TEST(FlexfecReceiveStreamTest, StartStop) { | 50 TEST(FlexfecReceiveStreamTest, StartStop) { |
32 FlexfecReceiveStream::Config config; | 51 FlexfecReceiveStream::Config config; |
33 config.payload_type = 118; | 52 config.payload_type = 118; |
34 config.remote_ssrc = 1652392; | 53 config.remote_ssrc = 1652392; |
35 config.protected_media_ssrcs = {23300443}; | 54 config.protected_media_ssrcs = {23300443}; |
36 MockRecoveredPacketReceiver callback; | 55 MockRecoveredPacketReceiver callback; |
37 internal::FlexfecReceiveStream receive_stream(config, &callback); | 56 MockRemoteBitrateEstimator bwe; |
57 internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); | |
38 | 58 |
39 receive_stream.Start(); | 59 receive_stream.Start(); |
40 receive_stream.Stop(); | 60 receive_stream.Stop(); |
41 } | 61 } |
42 | 62 |
43 TEST(FlexfecReceiveStreamTest, DoesNotProcessPacketWhenNoMediaSsrcGiven) { | 63 TEST(FlexfecReceiveStreamTest, DoesNotProcessPacketWhenNoMediaSsrcGiven) { |
44 FlexfecReceiveStream::Config config; | 64 FlexfecReceiveStream::Config config; |
45 config.payload_type = 118; | 65 config.payload_type = 118; |
46 config.remote_ssrc = 424223; | 66 config.remote_ssrc = 424223; |
47 config.protected_media_ssrcs = {}; | 67 config.protected_media_ssrcs = {}; |
48 MockRecoveredPacketReceiver callback; | 68 MockRecoveredPacketReceiver callback; |
49 internal::FlexfecReceiveStream receive_stream(config, &callback); | 69 MockRemoteBitrateEstimator bwe; |
70 internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); | |
50 const uint8_t packet[] = {0x00, 0x11, 0x22, 0x33}; | 71 const uint8_t packet[] = {0x00, 0x11, 0x22, 0x33}; |
51 const size_t packet_length = sizeof(packet); | 72 const size_t packet_length = sizeof(packet); |
52 | 73 |
53 EXPECT_FALSE( | 74 EXPECT_FALSE(receive_stream.AddAndProcessReceivedPacket( |
54 receive_stream.AddAndProcessReceivedPacket(packet, packet_length)); | 75 ParsePacket(packet, packet_length))); |
55 } | 76 } |
56 | 77 |
57 // Create a FlexFEC packet that protects a single media packet and ensure | 78 // Create a FlexFEC packet that protects a single media packet and ensure |
58 // that the callback is called. Correctness of recovery is checked in the | 79 // that the callback is called. Correctness of recovery is checked in the |
59 // FlexfecReceiver unit tests. | 80 // FlexfecReceiver unit tests. |
60 TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { | 81 TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
61 constexpr uint8_t kFlexfecPlType = 118; | 82 constexpr uint8_t kFlexfecPlType = 118; |
62 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; | 83 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
63 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; | 84 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
64 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; | 85 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
(...skipping 26 matching lines...) Expand all Loading... | |
91 // FEC payload. | 112 // FEC payload. |
92 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; | 113 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
93 // clang-format on | 114 // clang-format on |
94 constexpr size_t kFlexfecPacketLength = sizeof(kFlexfecPacket); | 115 constexpr size_t kFlexfecPacketLength = sizeof(kFlexfecPacket); |
95 | 116 |
96 FlexfecReceiveStream::Config config; | 117 FlexfecReceiveStream::Config config; |
97 config.payload_type = kFlexfecPlType; | 118 config.payload_type = kFlexfecPlType; |
98 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); | 119 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
99 config.protected_media_ssrcs = { | 120 config.protected_media_ssrcs = { |
100 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; | 121 ByteReader<uint32_t>::ReadBigEndian(kMediaSsrc)}; |
101 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; | 122 testing::StrictMock<MockRecoveredPacketReceiver> callback; |
102 internal::FlexfecReceiveStream receive_stream(config, | 123 MockRemoteBitrateEstimator bwe; |
103 &recovered_packet_receiver); | 124 internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); |
104 | 125 |
105 // Do not call back before being started. | 126 // Do not call back before being started. |
106 receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, | 127 receive_stream.AddAndProcessReceivedPacket( |
107 kFlexfecPacketLength); | 128 ParsePacket(kFlexfecPacket, kFlexfecPacketLength)); |
108 | 129 |
109 // Call back after being started. | 130 // Call back after being started. |
110 receive_stream.Start(); | 131 receive_stream.Start(); |
111 EXPECT_CALL( | 132 EXPECT_CALL(callback, |
112 recovered_packet_receiver, | 133 OnRecoveredPacket(_, kRtpHeaderSize + kPayloadLength[1])); |
113 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); | 134 receive_stream.AddAndProcessReceivedPacket( |
114 receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, | 135 ParsePacket(kFlexfecPacket, kFlexfecPacketLength)); |
115 kFlexfecPacketLength); | 136 } |
137 | |
138 // Verifies that the BWE is notified of received FlexFEC packets. | |
139 TEST(FlexfecReceiveStreamTest, | |
140 NotifiesBweOfReceivedFecPacketWithTransportSequenceNumberExtension) { | |
141 constexpr uint8_t kFlexfecPlType = 118; | |
142 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; | |
143 | |
144 // Set up config with RTP header extensions. | |
145 FlexfecReceiveStream::Config config; | |
146 config.payload_type = kFlexfecPlType; | |
147 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); | |
148 config.protected_media_ssrcs = {123}; | |
149 config.transport_cc = true; | |
150 config.rtp_header_extensions = { | |
151 RtpExtension(TransportSequenceNumber::kUri, 7)}; | |
152 RtpHeaderExtensionMap rtp_header_extension_map; | |
153 rtp_header_extension_map.Register<TransportSequenceNumber>(7); | |
154 | |
155 // Create FEC packet with a RTP header extension. | |
156 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; | |
157 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; | |
158 constexpr uint8_t kMediaPlType = 107; | |
159 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; | |
160 constexpr uint8_t kMediaTs[] = {0xaa, 0xbb, 0xcc, 0xdd}; | |
161 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; | |
162 constexpr uint8_t kKBit0 = 1 << 7; | |
163 constexpr uint8_t kFlexfecPktMask[] = {kKBit0 | 0x00, 0x01}; | |
164 constexpr uint8_t kPayloadLength[] = {0x00, 0x04}; | |
165 constexpr uint8_t kSsrcCount = 1; | |
166 constexpr uint8_t kReservedBits = 0x00; | |
167 constexpr uint8_t kPayloadBits = 0x00; | |
168 // clang-format off | |
169 constexpr uint8_t kFlexfecPacket[] = { | |
170 // RTP header. | |
171 0x90, kFlexfecPlType, kFlexfecSeqNum[0], kFlexfecSeqNum[1], | |
172 kFlexfecTs[0], kFlexfecTs[1], kFlexfecTs[2], kFlexfecTs[3], | |
danilchap
2016/12/13 14:11:24
0xaa, 0xbb, 0xcc, 0xdd, // Flexfex rtp timestamp.
| |
173 kFlexfecSsrc[0], kFlexfecSsrc[1], kFlexfecSsrc[2], kFlexfecSsrc[3], | |
174 // Transport-wide sequence number extension. | |
175 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extens ions-01 | |
176 0xbe, 0xde, /* magic constant */ 0x00, 0x01, /* length = 1 */ | |
danilchap
2016/12/13 14:11:24
may be instead of inline comments use more lines:
| |
177 0x71, /* ID = 7, L = 1 */ 0xab, 0xcd, /* s.n. */ 0x00, /* pad. */ | |
178 // FlexFEC header. | |
179 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], | |
180 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], | |
181 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, | |
182 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], | |
183 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], | |
184 // FEC payload. | |
185 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; | |
186 // clang-format on | |
187 constexpr size_t kFlexfecPacketLength = sizeof(kFlexfecPacket); | |
188 | |
189 // Set up objects. | |
190 testing::StrictMock<MockRecoveredPacketReceiver> callback; | |
191 testing::StrictMock<MockRemoteBitrateEstimator> bwe; | |
192 internal::FlexfecReceiveStream receive_stream(config, &callback, &bwe); | |
193 receive_stream.Start(); | |
194 | |
195 // Expect recovery and BWE notification. | |
196 EXPECT_CALL(callback, OnRecoveredPacket(_, _)).WillOnce(Return(true)); | |
197 EXPECT_CALL(bwe, IncomingPacket(_, _, _)); | |
198 | |
199 // Add packet to receive stream. | |
200 RtpPacketReceived parsed_packet(&rtp_header_extension_map); | |
201 RTC_DCHECK(parsed_packet.Parse(kFlexfecPacket, kFlexfecPacketLength)); | |
202 EXPECT_TRUE(receive_stream.AddAndProcessReceivedPacket(parsed_packet)); | |
116 } | 203 } |
117 | 204 |
118 } // namespace webrtc | 205 } // namespace webrtc |
OLD | NEW |