| 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/sender/video_sender.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 10 #include <memory> |
| 8 #include <vector> | 11 #include <vector> |
| 9 | 12 |
| 10 #include "base/bind.h" | 13 #include "base/bind.h" |
| 11 #include "base/macros.h" | 14 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/ptr_util.h" |
| 13 #include "base/test/simple_test_tick_clock.h" | 16 #include "base/test/simple_test_tick_clock.h" |
| 14 #include "media/base/fake_single_thread_task_runner.h" | 17 #include "media/base/fake_single_thread_task_runner.h" |
| 15 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 16 #include "media/cast/cast_environment.h" | 19 #include "media/cast/cast_environment.h" |
| 17 #include "media/cast/constants.h" | 20 #include "media/cast/constants.h" |
| 18 #include "media/cast/logging/simple_event_subscriber.h" | 21 #include "media/cast/logging/simple_event_subscriber.h" |
| 19 #include "media/cast/net/cast_transport_config.h" | 22 #include "media/cast/net/cast_transport_config.h" |
| 20 #include "media/cast/net/cast_transport_impl.h" | 23 #include "media/cast/net/cast_transport_impl.h" |
| 21 #include "media/cast/net/pacing/paced_sender.h" | 24 #include "media/cast/net/pacing/paced_sender.h" |
| 22 #include "media/cast/sender/fake_video_encode_accelerator_factory.h" | 25 #include "media/cast/sender/fake_video_encode_accelerator_factory.h" |
| 23 #include "media/cast/sender/video_frame_factory.h" | 26 #include "media/cast/sender/video_frame_factory.h" |
| 24 #include "media/cast/sender/video_sender.h" | |
| 25 #include "media/cast/test/utility/default_config.h" | 27 #include "media/cast/test/utility/default_config.h" |
| 26 #include "media/cast/test/utility/video_utility.h" | 28 #include "media/cast/test/utility/video_utility.h" |
| 27 #include "media/video/fake_video_encode_accelerator.h" | 29 #include "media/video/fake_video_encode_accelerator.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 32 |
| 31 namespace media { | 33 namespace media { |
| 32 namespace cast { | 34 namespace cast { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 class TransportClient : public CastTransport::Client { | 132 class TransportClient : public CastTransport::Client { |
| 131 public: | 133 public: |
| 132 TransportClient() {} | 134 TransportClient() {} |
| 133 | 135 |
| 134 void OnStatusChanged(CastTransportStatus status) final { | 136 void OnStatusChanged(CastTransportStatus status) final { |
| 135 EXPECT_EQ(TRANSPORT_VIDEO_INITIALIZED, status); | 137 EXPECT_EQ(TRANSPORT_VIDEO_INITIALIZED, status); |
| 136 }; | 138 }; |
| 137 void OnLoggingEventsReceived( | 139 void OnLoggingEventsReceived( |
| 138 scoped_ptr<std::vector<FrameEvent>> frame_events, | 140 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 139 scoped_ptr<std::vector<PacketEvent>> packet_events) final{}; | 141 std::unique_ptr<std::vector<PacketEvent>> packet_events) final{}; |
| 140 void ProcessRtpPacket(scoped_ptr<Packet> packet) final{}; | 142 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final{}; |
| 141 | 143 |
| 142 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 144 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
| 143 }; | 145 }; |
| 144 | 146 |
| 145 } // namespace | 147 } // namespace |
| 146 | 148 |
| 147 class VideoSenderTest : public ::testing::Test { | 149 class VideoSenderTest : public ::testing::Test { |
| 148 protected: | 150 protected: |
| 149 VideoSenderTest() | 151 VideoSenderTest() |
| 150 : testing_clock_(new base::SimpleTestTickClock()), | 152 : testing_clock_(new base::SimpleTestTickClock()), |
| 151 task_runner_(new FakeSingleThreadTaskRunner(testing_clock_)), | 153 task_runner_(new FakeSingleThreadTaskRunner(testing_clock_)), |
| 152 cast_environment_( | 154 cast_environment_(new CastEnvironment( |
| 153 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_), | 155 std::unique_ptr<base::TickClock>(testing_clock_), |
| 154 task_runner_, | 156 task_runner_, |
| 155 task_runner_, | 157 task_runner_, |
| 156 task_runner_)), | 158 task_runner_)), |
| 157 operational_status_(STATUS_UNINITIALIZED), | 159 operational_status_(STATUS_UNINITIALIZED), |
| 158 vea_factory_(task_runner_) { | 160 vea_factory_(task_runner_) { |
| 159 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); | 161 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); |
| 160 vea_factory_.SetAutoRespond(true); | 162 vea_factory_.SetAutoRespond(true); |
| 161 last_pixel_value_ = kPixelValue; | 163 last_pixel_value_ = kPixelValue; |
| 162 transport_ = new TestPacketSender(); | 164 transport_ = new TestPacketSender(); |
| 163 transport_sender_.reset( | 165 transport_sender_.reset( |
| 164 new CastTransportImpl(testing_clock_, base::TimeDelta(), | 166 new CastTransportImpl(testing_clock_, base::TimeDelta(), |
| 165 make_scoped_ptr(new TransportClient()), | 167 base::WrapUnique(new TransportClient()), |
| 166 make_scoped_ptr(transport_), task_runner_)); | 168 base::WrapUnique(transport_), task_runner_)); |
| 167 } | 169 } |
| 168 | 170 |
| 169 ~VideoSenderTest() override {} | 171 ~VideoSenderTest() override {} |
| 170 | 172 |
| 171 void TearDown() final { | 173 void TearDown() final { |
| 172 video_sender_.reset(); | 174 video_sender_.reset(); |
| 173 task_runner_->RunTasks(); | 175 task_runner_->RunTasks(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 // If |external| is true then external video encoder (VEA) is used. | 178 // If |external| is true then external video encoder (VEA) is used. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 void RunTasks(int during_ms) { | 234 void RunTasks(int during_ms) { |
| 233 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(during_ms)); | 235 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(during_ms)); |
| 234 } | 236 } |
| 235 | 237 |
| 236 base::SimpleTestTickClock* const testing_clock_; // Owned by CastEnvironment. | 238 base::SimpleTestTickClock* const testing_clock_; // Owned by CastEnvironment. |
| 237 const scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; | 239 const scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; |
| 238 const scoped_refptr<CastEnvironment> cast_environment_; | 240 const scoped_refptr<CastEnvironment> cast_environment_; |
| 239 OperationalStatus operational_status_; | 241 OperationalStatus operational_status_; |
| 240 FakeVideoEncodeAcceleratorFactory vea_factory_; | 242 FakeVideoEncodeAcceleratorFactory vea_factory_; |
| 241 TestPacketSender* transport_; // Owned by CastTransport. | 243 TestPacketSender* transport_; // Owned by CastTransport. |
| 242 scoped_ptr<CastTransportImpl> transport_sender_; | 244 std::unique_ptr<CastTransportImpl> transport_sender_; |
| 243 scoped_ptr<PeerVideoSender> video_sender_; | 245 std::unique_ptr<PeerVideoSender> video_sender_; |
| 244 int last_pixel_value_; | 246 int last_pixel_value_; |
| 245 base::TimeTicks first_frame_timestamp_; | 247 base::TimeTicks first_frame_timestamp_; |
| 246 | 248 |
| 247 private: | 249 private: |
| 248 DISALLOW_COPY_AND_ASSIGN(VideoSenderTest); | 250 DISALLOW_COPY_AND_ASSIGN(VideoSenderTest); |
| 249 }; | 251 }; |
| 250 | 252 |
| 251 TEST_F(VideoSenderTest, BuiltInEncoder) { | 253 TEST_F(VideoSenderTest, BuiltInEncoder) { |
| 252 InitEncoder(false, true); | 254 InitEncoder(false, true); |
| 253 ASSERT_EQ(STATUS_INITIALIZED, operational_status_); | 255 ASSERT_EQ(STATUS_INITIALIZED, operational_status_); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 video_frame, | 636 video_frame, |
| 635 testing_clock_->NowTicks() + base::TimeDelta::FromMilliseconds(1000)); | 637 testing_clock_->NowTicks() + base::TimeDelta::FromMilliseconds(1000)); |
| 636 RunTasks(33); | 638 RunTasks(33); |
| 637 transport_->SetPause(false); | 639 transport_->SetPause(false); |
| 638 RunTasks(33); | 640 RunTasks(33); |
| 639 EXPECT_EQ(2, transport_->number_of_rtp_packets()); | 641 EXPECT_EQ(2, transport_->number_of_rtp_packets()); |
| 640 } | 642 } |
| 641 | 643 |
| 642 } // namespace cast | 644 } // namespace cast |
| 643 } // namespace media | 645 } // namespace media |
| OLD | NEW |