| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/net/cast_transport_impl.h" | 5 #include "media/cast/net/cast_transport_impl.h" |
| 6 | 6 |
| 7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "media/base/fake_single_thread_task_runner.h" | 19 #include "media/base/fake_single_thread_task_runner.h" |
| 18 #include "media/cast/net/cast_transport_config.h" | 20 #include "media/cast/net/cast_transport_config.h" |
| 19 #include "media/cast/net/rtcp/rtcp_defines.h" | 21 #include "media/cast/net/rtcp/rtcp_defines.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 namespace media { | 24 namespace media { |
| 23 namespace cast { | 25 namespace cast { |
| 24 | 26 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 CastTransportRtpConfig rtp_config; | 104 CastTransportRtpConfig rtp_config; |
| 103 rtp_config.ssrc = kAudioSsrc; | 105 rtp_config.ssrc = kAudioSsrc; |
| 104 rtp_config.feedback_ssrc = 3; | 106 rtp_config.feedback_ssrc = 3; |
| 105 rtp_config.rtp_payload_type = 4; | 107 rtp_config.rtp_payload_type = 4; |
| 106 transport_sender_->InitializeAudio(rtp_config, RtcpCastMessageCallback(), | 108 transport_sender_->InitializeAudio(rtp_config, RtcpCastMessageCallback(), |
| 107 RtcpRttCallback(), RtcpPliCallback()); | 109 RtcpRttCallback(), RtcpPliCallback()); |
| 108 } | 110 } |
| 109 | 111 |
| 110 base::SimpleTestTickClock testing_clock_; | 112 base::SimpleTestTickClock testing_clock_; |
| 111 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; | 113 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; |
| 112 scoped_ptr<CastTransportImpl> transport_sender_; | 114 std::unique_ptr<CastTransportImpl> transport_sender_; |
| 113 FakePacketSender* transport_; // Owned by CastTransport. | 115 FakePacketSender* transport_; // Owned by CastTransport. |
| 114 int num_times_logging_callback_called_; | 116 int num_times_logging_callback_called_; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 namespace { | 119 namespace { |
| 118 | 120 |
| 119 class TransportClient : public CastTransport::Client { | 121 class TransportClient : public CastTransport::Client { |
| 120 public: | 122 public: |
| 121 explicit TransportClient( | 123 explicit TransportClient( |
| 122 CastTransportImplTest* cast_transport_sender_impl_test) | 124 CastTransportImplTest* cast_transport_sender_impl_test) |
| 123 : cast_transport_sender_impl_test_(cast_transport_sender_impl_test) {} | 125 : cast_transport_sender_impl_test_(cast_transport_sender_impl_test) {} |
| 124 | 126 |
| 125 void OnStatusChanged(CastTransportStatus status) final{}; | 127 void OnStatusChanged(CastTransportStatus status) final{}; |
| 126 void OnLoggingEventsReceived( | 128 void OnLoggingEventsReceived( |
| 127 scoped_ptr<std::vector<FrameEvent>> frame_events, | 129 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 128 scoped_ptr<std::vector<PacketEvent>> packet_events) final { | 130 std::unique_ptr<std::vector<PacketEvent>> packet_events) final { |
| 129 CHECK(cast_transport_sender_impl_test_); | 131 CHECK(cast_transport_sender_impl_test_); |
| 130 cast_transport_sender_impl_test_->ReceivedLoggingEvents(); | 132 cast_transport_sender_impl_test_->ReceivedLoggingEvents(); |
| 131 }; | 133 }; |
| 132 void ProcessRtpPacket(scoped_ptr<Packet> packet) final{}; | 134 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final{}; |
| 133 | 135 |
| 134 private: | 136 private: |
| 135 CastTransportImplTest* const cast_transport_sender_impl_test_; | 137 CastTransportImplTest* const cast_transport_sender_impl_test_; |
| 136 | 138 |
| 137 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 139 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 } // namespace | 142 } // namespace |
| 141 | 143 |
| 142 void CastTransportImplTest::InitWithoutLogging() { | 144 void CastTransportImplTest::InitWithoutLogging() { |
| 143 transport_ = new FakePacketSender(); | 145 transport_ = new FakePacketSender(); |
| 144 transport_sender_.reset( | 146 transport_sender_.reset( |
| 145 new CastTransportImpl(&testing_clock_, base::TimeDelta(), | 147 new CastTransportImpl(&testing_clock_, base::TimeDelta(), |
| 146 make_scoped_ptr(new TransportClient(nullptr)), | 148 base::WrapUnique(new TransportClient(nullptr)), |
| 147 make_scoped_ptr(transport_), task_runner_)); | 149 base::WrapUnique(transport_), task_runner_)); |
| 148 task_runner_->RunTasks(); | 150 task_runner_->RunTasks(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void CastTransportImplTest::InitWithOptions() { | 153 void CastTransportImplTest::InitWithOptions() { |
| 152 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue); | 154 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue); |
| 153 options->SetBoolean("disable_wifi_scan", true); | 155 options->SetBoolean("disable_wifi_scan", true); |
| 154 options->SetBoolean("media_streaming_mode", true); | 156 options->SetBoolean("media_streaming_mode", true); |
| 155 options->SetInteger("pacer_target_burst_size", 20); | 157 options->SetInteger("pacer_target_burst_size", 20); |
| 156 options->SetInteger("pacer_max_burst_size", 100); | 158 options->SetInteger("pacer_max_burst_size", 100); |
| 157 transport_ = new FakePacketSender(); | 159 transport_ = new FakePacketSender(); |
| 158 transport_sender_.reset( | 160 transport_sender_.reset( |
| 159 new CastTransportImpl(&testing_clock_, base::TimeDelta(), | 161 new CastTransportImpl(&testing_clock_, base::TimeDelta(), |
| 160 make_scoped_ptr(new TransportClient(nullptr)), | 162 base::WrapUnique(new TransportClient(nullptr)), |
| 161 make_scoped_ptr(transport_), task_runner_)); | 163 base::WrapUnique(transport_), task_runner_)); |
| 162 transport_sender_->SetOptions(*options); | 164 transport_sender_->SetOptions(*options); |
| 163 task_runner_->RunTasks(); | 165 task_runner_->RunTasks(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void CastTransportImplTest::InitWithLogging() { | 168 void CastTransportImplTest::InitWithLogging() { |
| 167 transport_ = new FakePacketSender(); | 169 transport_ = new FakePacketSender(); |
| 168 transport_sender_.reset(new CastTransportImpl( | 170 transport_sender_.reset(new CastTransportImpl( |
| 169 &testing_clock_, base::TimeDelta::FromMilliseconds(10), | 171 &testing_clock_, base::TimeDelta::FromMilliseconds(10), |
| 170 make_scoped_ptr(new TransportClient(this)), make_scoped_ptr(transport_), | 172 base::WrapUnique(new TransportClient(this)), base::WrapUnique(transport_), |
| 171 task_runner_)); | 173 task_runner_)); |
| 172 task_runner_->RunTasks(); | 174 task_runner_->RunTasks(); |
| 173 } | 175 } |
| 174 | 176 |
| 175 TEST_F(CastTransportImplTest, InitWithoutLogging) { | 177 TEST_F(CastTransportImplTest, InitWithoutLogging) { |
| 176 InitWithoutLogging(); | 178 InitWithoutLogging(); |
| 177 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(50)); | 179 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(50)); |
| 178 EXPECT_EQ(0, num_times_logging_callback_called_); | 180 EXPECT_EQ(0, num_times_logging_callback_called_); |
| 179 } | 181 } |
| 180 | 182 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 task_runner_->RunTasks(); | 390 task_runner_->RunTasks(); |
| 389 EXPECT_EQ(7, transport_->packets_sent()); | 391 EXPECT_EQ(7, transport_->packets_sent()); |
| 390 EXPECT_EQ(1, num_times_logging_callback_called_); // Only 8 ms since last. | 392 EXPECT_EQ(1, num_times_logging_callback_called_); // Only 8 ms since last. |
| 391 | 393 |
| 392 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(2)); | 394 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(2)); |
| 393 EXPECT_EQ(2, num_times_logging_callback_called_); | 395 EXPECT_EQ(2, num_times_logging_callback_called_); |
| 394 } | 396 } |
| 395 | 397 |
| 396 } // namespace cast | 398 } // namespace cast |
| 397 } // namespace media | 399 } // namespace media |
| OLD | NEW |