Chromium Code Reviews| 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 |
|
danilchap
2017/05/31 14:57:33
may be add here
using ::testing::NiceMock;
| |
| 25 using ::testing::UnorderedElementsAre; | 26 using ::testing::UnorderedElementsAre; |
| 26 | 27 |
| 27 const uint32_t kTestRate = 64000u; | 28 const uint32_t kTestRate = 64000u; |
| 28 const uint8_t kTestPayload[] = {'t', 'e', 's', 't'}; | 29 const uint8_t kTestPayload[] = {'t', 'e', 's', 't'}; |
| 29 const uint8_t kPcmuPayloadType = 96; | 30 const uint8_t kPcmuPayloadType = 96; |
| 30 const int64_t kGetSourcesTimeoutMs = 10000; | 31 const int64_t kGetSourcesTimeoutMs = 10000; |
| 31 const uint32_t kSsrc1 = 123; | 32 const uint32_t kSsrc1 = 123; |
| 32 const uint32_t kSsrc2 = 124; | 33 const uint32_t kSsrc2 = 124; |
| 33 const uint32_t kCsrc1 = 111; | 34 const uint32_t kCsrc1 = 111; |
| 34 const uint32_t kCsrc2 = 222; | 35 const uint32_t kCsrc2 = 222; |
| 35 const bool kInOrder = true; | 36 const bool kInOrder = true; |
| 36 | 37 |
| 37 static uint32_t rtp_timestamp(int64_t time_ms) { | 38 static uint32_t rtp_timestamp(int64_t time_ms) { |
| 38 return static_cast<uint32_t>(time_ms * kTestRate / 1000); | 39 return static_cast<uint32_t>(time_ms * kTestRate / 1000); |
| 39 } | 40 } |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 class RtpReceiverTest : public ::testing::Test { | 44 class RtpReceiverTest : public ::testing::Test { |
| 44 protected: | 45 protected: |
| 45 RtpReceiverTest() | 46 RtpReceiverTest() |
| 46 : fake_clock_(123456), | 47 : fake_clock_(123456), |
| 47 rtp_receiver_( | 48 rtp_receiver_( |
| 48 RtpReceiver::CreateAudioReceiver(&fake_clock_, | 49 RtpReceiver::CreateAudioReceiver(&fake_clock_, |
| 49 nullptr, | 50 &mock_rtp_data_, |
| 50 nullptr, | 51 nullptr, |
| 51 &rtp_payload_registry_)) { | 52 &rtp_payload_registry_)) { |
| 52 CodecInst voice_codec = {}; | 53 CodecInst voice_codec = {}; |
| 53 voice_codec.pltype = kPcmuPayloadType; | 54 voice_codec.pltype = kPcmuPayloadType; |
| 54 voice_codec.plfreq = 8000; | 55 voice_codec.plfreq = 8000; |
| 55 voice_codec.rate = kTestRate; | 56 voice_codec.rate = kTestRate; |
| 56 memcpy(voice_codec.plname, "PCMU", 5); | 57 memcpy(voice_codec.plname, "PCMU", 5); |
| 57 rtp_receiver_->RegisterReceivePayload(voice_codec); | 58 rtp_receiver_->RegisterReceivePayload(voice_codec); |
| 58 } | 59 } |
| 59 ~RtpReceiverTest() {} | 60 ~RtpReceiverTest() {} |
| 60 | 61 |
| 61 bool FindSourceByIdAndType(const std::vector<RtpSource>& sources, | 62 bool FindSourceByIdAndType(const std::vector<RtpSource>& sources, |
| 62 uint32_t source_id, | 63 uint32_t source_id, |
| 63 RtpSourceType type, | 64 RtpSourceType type, |
| 64 RtpSource* source) { | 65 RtpSource* source) { |
| 65 for (size_t i = 0; i < sources.size(); ++i) { | 66 for (size_t i = 0; i < sources.size(); ++i) { |
| 66 if (sources[i].source_id() == source_id && | 67 if (sources[i].source_id() == source_id && |
| 67 sources[i].source_type() == type) { | 68 sources[i].source_type() == type) { |
| 68 (*source) = sources[i]; | 69 (*source) = sources[i]; |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 return false; | 73 return false; |
| 73 } | 74 } |
| 74 | 75 |
| 75 SimulatedClock fake_clock_; | 76 SimulatedClock fake_clock_; |
| 77 ::testing::NiceMock<MockRtpData> mock_rtp_data_; | |
|
danilchap
2017/05/31 14:57:33
to make this line look nicer
nisse-webrtc
2017/06/01 06:59:56
Done.
| |
| 76 RTPPayloadRegistry rtp_payload_registry_; | 78 RTPPayloadRegistry rtp_payload_registry_; |
| 77 std::unique_ptr<RtpReceiver> rtp_receiver_; | 79 std::unique_ptr<RtpReceiver> rtp_receiver_; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 TEST_F(RtpReceiverTest, GetSources) { | 82 TEST_F(RtpReceiverTest, GetSources) { |
| 81 int64_t now_ms = fake_clock_.TimeInMilliseconds(); | 83 int64_t now_ms = fake_clock_.TimeInMilliseconds(); |
| 82 | 84 |
| 83 RTPHeader header; | 85 RTPHeader header; |
| 84 header.payloadType = kPcmuPayloadType; | 86 header.payloadType = kPcmuPayloadType; |
| 85 header.ssrc = kSsrc1; | 87 header.ssrc = kSsrc1; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 248 |
| 247 auto csrc_sources = rtp_receiver_impl->csrc_sources_for_testing(); | 249 auto csrc_sources = rtp_receiver_impl->csrc_sources_for_testing(); |
| 248 ASSERT_EQ(1u, csrc_sources.size()); | 250 ASSERT_EQ(1u, csrc_sources.size()); |
| 249 EXPECT_EQ(kCsrc1, csrc_sources.begin()->source_id()); | 251 EXPECT_EQ(kCsrc1, csrc_sources.begin()->source_id()); |
| 250 EXPECT_EQ(RtpSourceType::CSRC, csrc_sources.begin()->source_type()); | 252 EXPECT_EQ(RtpSourceType::CSRC, csrc_sources.begin()->source_type()); |
| 251 EXPECT_EQ(fake_clock_.TimeInMilliseconds(), | 253 EXPECT_EQ(fake_clock_.TimeInMilliseconds(), |
| 252 csrc_sources.begin()->timestamp_ms()); | 254 csrc_sources.begin()->timestamp_ms()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 } // namespace webrtc | 257 } // namespace webrtc |
| OLD | NEW |