OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/common_types.h" | 13 #include "webrtc/common_types.h" |
14 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 14 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
15 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 18 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h" |
19 #include "webrtc/test/gmock.h" | 20 #include "webrtc/test/gmock.h" |
20 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 namespace { | 24 namespace { |
24 | 25 |
| 26 using ::testing::NiceMock; |
25 using ::testing::UnorderedElementsAre; | 27 using ::testing::UnorderedElementsAre; |
26 | 28 |
27 const uint32_t kTestRate = 64000u; | 29 const uint32_t kTestRate = 64000u; |
28 const uint8_t kTestPayload[] = {'t', 'e', 's', 't'}; | 30 const uint8_t kTestPayload[] = {'t', 'e', 's', 't'}; |
29 const uint8_t kPcmuPayloadType = 96; | 31 const uint8_t kPcmuPayloadType = 96; |
30 const int64_t kGetSourcesTimeoutMs = 10000; | 32 const int64_t kGetSourcesTimeoutMs = 10000; |
31 const uint32_t kSsrc1 = 123; | 33 const uint32_t kSsrc1 = 123; |
32 const uint32_t kSsrc2 = 124; | 34 const uint32_t kSsrc2 = 124; |
33 const uint32_t kCsrc1 = 111; | 35 const uint32_t kCsrc1 = 111; |
34 const uint32_t kCsrc2 = 222; | 36 const uint32_t kCsrc2 = 222; |
35 const bool kInOrder = true; | 37 const bool kInOrder = true; |
36 | 38 |
37 static uint32_t rtp_timestamp(int64_t time_ms) { | 39 static uint32_t rtp_timestamp(int64_t time_ms) { |
38 return static_cast<uint32_t>(time_ms * kTestRate / 1000); | 40 return static_cast<uint32_t>(time_ms * kTestRate / 1000); |
39 } | 41 } |
40 | 42 |
41 } // namespace | 43 } // namespace |
42 | 44 |
43 class RtpReceiverTest : public ::testing::Test { | 45 class RtpReceiverTest : public ::testing::Test { |
44 protected: | 46 protected: |
45 RtpReceiverTest() | 47 RtpReceiverTest() |
46 : fake_clock_(123456), | 48 : fake_clock_(123456), |
47 rtp_receiver_( | 49 rtp_receiver_( |
48 RtpReceiver::CreateAudioReceiver(&fake_clock_, | 50 RtpReceiver::CreateAudioReceiver(&fake_clock_, |
49 nullptr, | 51 &mock_rtp_data_, |
50 nullptr, | 52 nullptr, |
51 &rtp_payload_registry_)) { | 53 &rtp_payload_registry_)) { |
52 CodecInst voice_codec = {}; | 54 CodecInst voice_codec = {}; |
53 voice_codec.pltype = kPcmuPayloadType; | 55 voice_codec.pltype = kPcmuPayloadType; |
54 voice_codec.plfreq = 8000; | 56 voice_codec.plfreq = 8000; |
55 voice_codec.rate = kTestRate; | 57 voice_codec.rate = kTestRate; |
56 memcpy(voice_codec.plname, "PCMU", 5); | 58 memcpy(voice_codec.plname, "PCMU", 5); |
57 rtp_receiver_->RegisterReceivePayload(voice_codec); | 59 rtp_receiver_->RegisterReceivePayload(voice_codec); |
58 } | 60 } |
59 ~RtpReceiverTest() {} | 61 ~RtpReceiverTest() {} |
60 | 62 |
61 bool FindSourceByIdAndType(const std::vector<RtpSource>& sources, | 63 bool FindSourceByIdAndType(const std::vector<RtpSource>& sources, |
62 uint32_t source_id, | 64 uint32_t source_id, |
63 RtpSourceType type, | 65 RtpSourceType type, |
64 RtpSource* source) { | 66 RtpSource* source) { |
65 for (size_t i = 0; i < sources.size(); ++i) { | 67 for (size_t i = 0; i < sources.size(); ++i) { |
66 if (sources[i].source_id() == source_id && | 68 if (sources[i].source_id() == source_id && |
67 sources[i].source_type() == type) { | 69 sources[i].source_type() == type) { |
68 (*source) = sources[i]; | 70 (*source) = sources[i]; |
69 return true; | 71 return true; |
70 } | 72 } |
71 } | 73 } |
72 return false; | 74 return false; |
73 } | 75 } |
74 | 76 |
75 SimulatedClock fake_clock_; | 77 SimulatedClock fake_clock_; |
| 78 NiceMock<MockRtpData> mock_rtp_data_; |
76 RTPPayloadRegistry rtp_payload_registry_; | 79 RTPPayloadRegistry rtp_payload_registry_; |
77 std::unique_ptr<RtpReceiver> rtp_receiver_; | 80 std::unique_ptr<RtpReceiver> rtp_receiver_; |
78 }; | 81 }; |
79 | 82 |
80 TEST_F(RtpReceiverTest, GetSources) { | 83 TEST_F(RtpReceiverTest, GetSources) { |
81 int64_t now_ms = fake_clock_.TimeInMilliseconds(); | 84 int64_t now_ms = fake_clock_.TimeInMilliseconds(); |
82 | 85 |
83 RTPHeader header; | 86 RTPHeader header; |
84 header.payloadType = kPcmuPayloadType; | 87 header.payloadType = kPcmuPayloadType; |
85 header.ssrc = kSsrc1; | 88 header.ssrc = kSsrc1; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 249 |
247 auto csrc_sources = rtp_receiver_impl->csrc_sources_for_testing(); | 250 auto csrc_sources = rtp_receiver_impl->csrc_sources_for_testing(); |
248 ASSERT_EQ(1u, csrc_sources.size()); | 251 ASSERT_EQ(1u, csrc_sources.size()); |
249 EXPECT_EQ(kCsrc1, csrc_sources.begin()->source_id()); | 252 EXPECT_EQ(kCsrc1, csrc_sources.begin()->source_id()); |
250 EXPECT_EQ(RtpSourceType::CSRC, csrc_sources.begin()->source_type()); | 253 EXPECT_EQ(RtpSourceType::CSRC, csrc_sources.begin()->source_type()); |
251 EXPECT_EQ(fake_clock_.TimeInMilliseconds(), | 254 EXPECT_EQ(fake_clock_.TimeInMilliseconds(), |
252 csrc_sources.begin()->timestamp_ms()); | 255 csrc_sources.begin()->timestamp_ms()); |
253 } | 256 } |
254 | 257 |
255 } // namespace webrtc | 258 } // namespace webrtc |
OLD | NEW |