| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 11 #include "media/cast/cast_environment.h" | 11 #include "media/cast/cast_environment.h" |
| 12 #include "media/cast/logging/simple_event_subscriber.h" | 12 #include "media/cast/logging/simple_event_subscriber.h" |
| 13 #include "media/cast/test/fake_gpu_video_accelerator_factories.h" | |
| 14 #include "media/cast/test/fake_single_thread_task_runner.h" | 13 #include "media/cast/test/fake_single_thread_task_runner.h" |
| 14 #include "media/cast/test/fake_video_encode_accelerator.h" |
| 15 #include "media/cast/test/utility/default_config.h" |
| 15 #include "media/cast/test/utility/video_utility.h" | 16 #include "media/cast/test/utility/video_utility.h" |
| 16 #include "media/cast/transport/cast_transport_config.h" | 17 #include "media/cast/transport/cast_transport_config.h" |
| 17 #include "media/cast/transport/cast_transport_sender_impl.h" | 18 #include "media/cast/transport/cast_transport_sender_impl.h" |
| 18 #include "media/cast/transport/pacing/paced_sender.h" | 19 #include "media/cast/transport/pacing/paced_sender.h" |
| 19 #include "media/cast/video_sender/video_sender.h" | 20 #include "media/cast/video_sender/video_sender.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 namespace media { | 24 namespace media { |
| 24 namespace cast { | 25 namespace cast { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | 28 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); |
| 28 static const uint8 kPixelValue = 123; | 29 static const uint8 kPixelValue = 123; |
| 29 static const int kWidth = 320; | 30 static const int kWidth = 320; |
| 30 static const int kHeight = 240; | 31 static const int kHeight = 240; |
| 31 | 32 |
| 32 using testing::_; | 33 using testing::_; |
| 33 using testing::AtLeast; | 34 using testing::AtLeast; |
| 34 | 35 |
| 36 void CreateVideoEncodeAccelerator( |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 38 scoped_ptr<VideoEncodeAccelerator> fake_vea, |
| 39 const ReceiveVideoEncodeAcceleratorCallback& callback) { |
| 40 callback.Run(task_runner, fake_vea.Pass()); |
| 41 } |
| 42 |
| 43 void CreateSharedMemory( |
| 44 size_t size, const ReceiveVideoEncodeMemoryCallback& callback) { |
| 45 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 46 if (!shm->CreateAndMapAnonymous(size)) { |
| 47 NOTREACHED(); |
| 48 return; |
| 49 } |
| 50 callback.Run(shm.Pass()); |
| 51 } |
| 52 |
| 35 class TestPacketSender : public transport::PacketSender { | 53 class TestPacketSender : public transport::PacketSender { |
| 36 public: | 54 public: |
| 37 TestPacketSender() : number_of_rtp_packets_(0), number_of_rtcp_packets_(0) {} | 55 TestPacketSender() : number_of_rtp_packets_(0), number_of_rtcp_packets_(0) {} |
| 38 | 56 |
| 39 // A singular packet implies a RTCP packet. | 57 // A singular packet implies a RTCP packet. |
| 40 virtual bool SendPacket(const Packet& packet) OVERRIDE { | 58 virtual bool SendPacket(const Packet& packet) OVERRIDE { |
| 41 if (Rtcp::IsRtcpPacket(&packet[0], packet.size())) { | 59 if (Rtcp::IsRtcpPacket(&packet[0], packet.size())) { |
| 42 ++number_of_rtcp_packets_; | 60 ++number_of_rtcp_packets_; |
| 43 } else { | 61 } else { |
| 44 ++number_of_rtp_packets_; | 62 ++number_of_rtp_packets_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 int number_of_rtcp_packets_; | 73 int number_of_rtcp_packets_; |
| 56 | 74 |
| 57 DISALLOW_COPY_AND_ASSIGN(TestPacketSender); | 75 DISALLOW_COPY_AND_ASSIGN(TestPacketSender); |
| 58 }; | 76 }; |
| 59 | 77 |
| 60 class PeerVideoSender : public VideoSender { | 78 class PeerVideoSender : public VideoSender { |
| 61 public: | 79 public: |
| 62 PeerVideoSender( | 80 PeerVideoSender( |
| 63 scoped_refptr<CastEnvironment> cast_environment, | 81 scoped_refptr<CastEnvironment> cast_environment, |
| 64 const VideoSenderConfig& video_config, | 82 const VideoSenderConfig& video_config, |
| 65 const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories, | 83 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
| 84 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
| 66 const CastInitializationCallback& cast_initialization_cb, | 85 const CastInitializationCallback& cast_initialization_cb, |
| 67 transport::CastTransportSender* const transport_sender) | 86 transport::CastTransportSender* const transport_sender) |
| 68 : VideoSender(cast_environment, | 87 : VideoSender(cast_environment, |
| 69 video_config, | 88 video_config, |
| 70 gpu_factories, | 89 create_vea_cb, |
| 90 create_video_encode_mem_cb, |
| 71 cast_initialization_cb, | 91 cast_initialization_cb, |
| 72 transport_sender) {} | 92 transport_sender) {} |
| 73 using VideoSender::OnReceivedCastFeedback; | 93 using VideoSender::OnReceivedCastFeedback; |
| 74 }; | 94 }; |
| 75 } // namespace | 95 } // namespace |
| 76 | 96 |
| 77 class VideoSenderTest : public ::testing::Test { | 97 class VideoSenderTest : public ::testing::Test { |
| 78 protected: | 98 protected: |
| 79 VideoSenderTest() { | 99 VideoSenderTest() { |
| 80 testing_clock_ = new base::SimpleTestTickClock(); | 100 testing_clock_ = new base::SimpleTestTickClock(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 video_config.max_bitrate = 5000000; | 148 video_config.max_bitrate = 5000000; |
| 129 video_config.min_bitrate = 1000000; | 149 video_config.min_bitrate = 1000000; |
| 130 video_config.start_bitrate = 1000000; | 150 video_config.start_bitrate = 1000000; |
| 131 video_config.max_qp = 56; | 151 video_config.max_qp = 56; |
| 132 video_config.min_qp = 0; | 152 video_config.min_qp = 0; |
| 133 video_config.max_frame_rate = 30; | 153 video_config.max_frame_rate = 30; |
| 134 video_config.max_number_of_video_buffers_used = 1; | 154 video_config.max_number_of_video_buffers_used = 1; |
| 135 video_config.codec = transport::kVp8; | 155 video_config.codec = transport::kVp8; |
| 136 | 156 |
| 137 if (external) { | 157 if (external) { |
| 138 video_sender_.reset(new PeerVideoSender( | 158 scoped_ptr<VideoEncodeAccelerator> fake_vea( |
| 139 cast_environment_, | 159 new test::FakeVideoEncodeAccelerator()); |
| 140 video_config, | 160 video_sender_.reset( |
| 141 new test::FakeGpuVideoAcceleratorFactories(task_runner_), | 161 new PeerVideoSender(cast_environment_, |
| 142 base::Bind(&VideoSenderTest::InitializationResult, | 162 video_config, |
| 143 base::Unretained(this)), | 163 base::Bind(&CreateVideoEncodeAccelerator, |
| 144 transport_sender_.get())); | 164 task_runner_, |
| 165 base::Passed(&fake_vea)), |
| 166 base::Bind(&CreateSharedMemory), |
| 167 base::Bind(&VideoSenderTest::InitializationResult, |
| 168 base::Unretained(this)), |
| 169 transport_sender_.get())); |
| 145 } else { | 170 } else { |
| 146 video_sender_.reset( | 171 video_sender_.reset( |
| 147 new PeerVideoSender(cast_environment_, | 172 new PeerVideoSender(cast_environment_, |
| 148 video_config, | 173 video_config, |
| 149 NULL, | 174 CreateDefaultVideoEncodeAcceleratorCallback(), |
| 175 CreateDefaultVideoEncodeMemoryCallback(), |
| 150 base::Bind(&VideoSenderTest::InitializationResult, | 176 base::Bind(&VideoSenderTest::InitializationResult, |
| 151 base::Unretained(this)), | 177 base::Unretained(this)), |
| 152 transport_sender_.get())); | 178 transport_sender_.get())); |
| 153 } | 179 } |
| 154 } | 180 } |
| 155 | 181 |
| 156 scoped_refptr<media::VideoFrame> GetNewVideoFrame() { | 182 scoped_refptr<media::VideoFrame> GetNewVideoFrame() { |
| 157 gfx::Size size(kWidth, kHeight); | 183 gfx::Size size(kWidth, kHeight); |
| 158 scoped_refptr<media::VideoFrame> video_frame = | 184 scoped_refptr<media::VideoFrame> video_frame = |
| 159 media::VideoFrame::CreateFrame( | 185 media::VideoFrame::CreateFrame( |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Empty the pipeline. | 366 // Empty the pipeline. |
| 341 RunTasks(100); | 367 RunTasks(100); |
| 342 // Should have sent at least 7 packets. | 368 // Should have sent at least 7 packets. |
| 343 EXPECT_GE( | 369 EXPECT_GE( |
| 344 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), | 370 transport_.number_of_rtp_packets() + transport_.number_of_rtcp_packets(), |
| 345 7); | 371 7); |
| 346 } | 372 } |
| 347 | 373 |
| 348 } // namespace cast | 374 } // namespace cast |
| 349 } // namespace media | 375 } // namespace media |
| OLD | NEW |