OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/modules/rtp_rtcp/source/rtp_packet_history.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
16 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
17 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.h" |
18 #include "webrtc/test/gmock.h" | |
18 #include "webrtc/test/gtest.h" | 19 #include "webrtc/test/gtest.h" |
19 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 | 23 |
23 class RtpPacketHistoryTest : public ::testing::Test { | 24 class RtpPacketHistoryTest : public ::testing::Test { |
24 protected: | 25 protected: |
25 static constexpr uint16_t kSeqNum = 88; | 26 static constexpr uint16_t kSeqNum = 88; |
26 | 27 |
27 RtpPacketHistoryTest() : fake_clock_(123456), hist_(&fake_clock_) {} | 28 RtpPacketHistoryTest() : fake_clock_(123456), hist_(&fake_clock_) {} |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 213 } |
213 | 214 |
214 fake_clock_.AdvanceTimeMilliseconds(100); | 215 fake_clock_.AdvanceTimeMilliseconds(100); |
215 | 216 |
216 // Retransmit all packets currently in buffer. | 217 // Retransmit all packets currently in buffer. |
217 for (size_t i = 1; i < RtpPacketHistory::kMaxCapacity + 1; ++i) { | 218 for (size_t i = 1; i < RtpPacketHistory::kMaxCapacity + 1; ++i) { |
218 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); | 219 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
223 namespace { | |
224 | |
225 class MockRtpPacketToSend : public RtpPacketToSend { | |
226 public: | |
227 MockRtpPacketToSend() : RtpPacketToSend(nullptr) {} | |
228 virtual ~MockRtpPacketToSend() {} | |
229 MOCK_CONST_METHOD0(headers_size, size_t()); | |
230 MOCK_CONST_METHOD0(size, size_t()); | |
danilchap
2017/03/28 15:10:58
I'm not sure it is good idea to make cheap accesso
minyue-webrtc
2017/03/29 11:39:44
Fully agreed. I think const header size if enough
danilchap
2017/03/29 12:12:53
I'm sorry for making interface of the rtp packet c
| |
231 }; | |
232 | |
233 using ::testing::Return; | |
234 using ::testing::StrictMock; | |
235 | |
236 } // namespace | |
237 | |
238 TEST_F(RtpPacketHistoryTest, GetBestFittingPacket) { | |
239 constexpr int64_t kCaptureTime1 = 1234; | |
240 constexpr int64_t kCaptureTime2 = 5678; | |
241 constexpr int64_t kCaptureTime3 = 9000; | |
242 constexpr size_t kMinPacketRequestBytes = 50; | |
243 | |
244 hist_.SetStorePacketsStatus(true, 3); | |
245 | |
246 std::unique_ptr<MockRtpPacketToSend> packet; | |
247 | |
248 packet.reset(new StrictMock<MockRtpPacketToSend>()); | |
249 packet->set_capture_time_ms(kCaptureTime1); | |
250 EXPECT_CALL(*packet, headers_size()).WillRepeatedly(Return(3)); | |
251 EXPECT_CALL(*packet, size()) | |
252 .WillRepeatedly(Return(kMinPacketRequestBytes + 1)); | |
253 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); | |
254 | |
255 packet.reset(new StrictMock<MockRtpPacketToSend>()); | |
256 packet->set_capture_time_ms(kCaptureTime2); | |
257 EXPECT_CALL(*packet, headers_size()).WillRepeatedly(Return(2)); | |
258 EXPECT_CALL(*packet, size()) | |
259 .WillRepeatedly(Return(kMinPacketRequestBytes + 2)); | |
260 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); | |
261 | |
262 packet.reset(new StrictMock<MockRtpPacketToSend>()); | |
263 packet->set_capture_time_ms(kCaptureTime3); | |
264 EXPECT_CALL(*packet, headers_size()).WillRepeatedly(Return(1)); | |
265 EXPECT_CALL(*packet, size()) | |
266 .WillRepeatedly(Return(kMinPacketRequestBytes + 3)); | |
267 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); | |
268 | |
269 std::unique_ptr<RtpPacketToSend> fit = | |
270 hist_.GetBestFittingPacket(kMinPacketRequestBytes, true); | |
danilchap
2017/03/28 15:10:58
since last parameter of the GetBestFittingPacket m
| |
271 ASSERT_TRUE(fit); | |
272 EXPECT_EQ(kCaptureTime1, fit->capture_time_ms()); | |
273 fit = hist_.GetBestFittingPacket(kMinPacketRequestBytes, false); | |
274 ASSERT_TRUE(fit); | |
275 EXPECT_EQ(kCaptureTime2, fit->capture_time_ms()); | |
276 } | |
277 | |
222 } // namespace webrtc | 278 } // namespace webrtc |
OLD | NEW |