| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/host/video_scheduler.h" | 5 #include "remoting/host/video_scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "media/video/capture/screen/screen_capture_data.h" |
| 11 #include "media/video/capture/screen/screen_capturer_mock_objects.h" |
| 10 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
| 11 #include "remoting/capturer/capture_data.h" | |
| 12 #include "remoting/capturer/video_capturer_mock_objects.h" | |
| 13 #include "remoting/codec/video_encoder.h" | 13 #include "remoting/codec/video_encoder.h" |
| 14 #include "remoting/proto/video.pb.h" | 14 #include "remoting/proto/video.pb.h" |
| 15 #include "remoting/protocol/protocol_mock_objects.h" | 15 #include "remoting/protocol/protocol_mock_objects.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using ::remoting::protocol::MockClientStub; | 19 using ::remoting::protocol::MockClientStub; |
| 20 using ::remoting::protocol::MockVideoStub; | 20 using ::remoting::protocol::MockVideoStub; |
| 21 | 21 |
| 22 using ::testing::_; | 22 using ::testing::_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 | 49 |
| 50 static const int kWidth = 640; | 50 static const int kWidth = 640; |
| 51 static const int kHeight = 480; | 51 static const int kHeight = 480; |
| 52 | 52 |
| 53 class MockVideoEncoder : public VideoEncoder { | 53 class MockVideoEncoder : public VideoEncoder { |
| 54 public: | 54 public: |
| 55 MockVideoEncoder(); | 55 MockVideoEncoder(); |
| 56 virtual ~MockVideoEncoder(); | 56 virtual ~MockVideoEncoder(); |
| 57 | 57 |
| 58 MOCK_METHOD3(Encode, void( | 58 MOCK_METHOD3(Encode, void( |
| 59 scoped_refptr<CaptureData> capture_data, | 59 scoped_refptr<media::ScreenCaptureData> capture_data, |
| 60 bool key_frame, | 60 bool key_frame, |
| 61 const DataAvailableCallback& data_available_callback)); | 61 const DataAvailableCallback& data_available_callback)); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); | 64 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 MockVideoEncoder::MockVideoEncoder() {} | 67 MockVideoEncoder::MockVideoEncoder() {} |
| 68 | 68 |
| 69 MockVideoEncoder::~MockVideoEncoder() {} | 69 MockVideoEncoder::~MockVideoEncoder() {} |
| 70 | 70 |
| 71 class VideoSchedulerTest : public testing::Test { | 71 class VideoSchedulerTest : public testing::Test { |
| 72 public: | 72 public: |
| 73 VideoSchedulerTest() { | 73 VideoSchedulerTest() { |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void SetUp() OVERRIDE { | 76 virtual void SetUp() OVERRIDE { |
| 77 task_runner_ = new AutoThreadTaskRunner( | 77 task_runner_ = new AutoThreadTaskRunner( |
| 78 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); | 78 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); |
| 79 | 79 |
| 80 encoder_ = new MockVideoEncoder(); | 80 encoder_ = new MockVideoEncoder(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void StartVideoScheduler(scoped_ptr<VideoFrameCapturer> capturer) { | 83 void StartVideoScheduler(scoped_ptr<media::ScreenCapturer> capturer) { |
| 84 scheduler_ = VideoScheduler::Create( | 84 scheduler_ = VideoScheduler::Create( |
| 85 task_runner_, // Capture | 85 task_runner_, // Capture |
| 86 task_runner_, // Encode | 86 task_runner_, // Encode |
| 87 task_runner_, // Network | 87 task_runner_, // Network |
| 88 capturer.Pass(), | 88 capturer.Pass(), |
| 89 scoped_ptr<VideoEncoder>(encoder_), | 89 scoped_ptr<VideoEncoder>(encoder_), |
| 90 &client_stub_, | 90 &client_stub_, |
| 91 &video_stub_); | 91 &video_stub_); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GenerateOnCaptureCompleted(); | 94 void GenerateOnCaptureCompleted(); |
| 95 | 95 |
| 96 void StopVideoScheduler(); | 96 void StopVideoScheduler(); |
| 97 | 97 |
| 98 protected: | 98 protected: |
| 99 MessageLoop message_loop_; | 99 MessageLoop message_loop_; |
| 100 base::RunLoop run_loop_; | 100 base::RunLoop run_loop_; |
| 101 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 101 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| 102 scoped_refptr<VideoScheduler> scheduler_; | 102 scoped_refptr<VideoScheduler> scheduler_; |
| 103 | 103 |
| 104 MockClientStub client_stub_; | 104 MockClientStub client_stub_; |
| 105 MockVideoStub video_stub_; | 105 MockVideoStub video_stub_; |
| 106 | 106 |
| 107 // The following mock objects are owned by VideoScheduler. | 107 // The following mock objects are owned by VideoScheduler. |
| 108 MockVideoEncoder* encoder_; | 108 MockVideoEncoder* encoder_; |
| 109 | 109 |
| 110 scoped_refptr<CaptureData> data_; | 110 scoped_refptr<media::ScreenCaptureData> data_; |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); | 113 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 void VideoSchedulerTest::GenerateOnCaptureCompleted() { | 116 void VideoSchedulerTest::GenerateOnCaptureCompleted() { |
| 117 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | 117 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); |
| 118 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); | 118 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); |
| 119 | 119 |
| 120 scheduler_->OnCaptureCompleted(data_); | 120 scheduler_->OnCaptureCompleted(data_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void VideoSchedulerTest::StopVideoScheduler() { | 123 void VideoSchedulerTest::StopVideoScheduler() { |
| 124 scheduler_->Stop(); | 124 scheduler_->Stop(); |
| 125 scheduler_ = NULL; | 125 scheduler_ = NULL; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // This test mocks capturer, encoder and network layer to simulate one capture | 128 // This test mocks capturer, encoder and network layer to simulate one capture |
| 129 // cycle. When the first encoded packet is submitted to the network | 129 // cycle. When the first encoded packet is submitted to the network |
| 130 // VideoScheduler is instructed to come to a complete stop. We expect the stop | 130 // VideoScheduler is instructed to come to a complete stop. We expect the stop |
| 131 // sequence to be executed successfully. | 131 // sequence to be executed successfully. |
| 132 TEST_F(VideoSchedulerTest, StartAndStop) { | 132 TEST_F(VideoSchedulerTest, StartAndStop) { |
| 133 scoped_ptr<MockVideoFrameCapturer> capturer_(new MockVideoFrameCapturer()); | 133 scoped_ptr<media::MockScreenCapturer> capturer( |
| 134 Expectation capturer_start = EXPECT_CALL(*capturer_, Start(_)); | 134 new media::MockScreenCapturer()); |
| 135 Expectation capturer_start = EXPECT_CALL(*capturer, Start(_)); |
| 135 | 136 |
| 136 data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel, | 137 data_ = new media::ScreenCaptureData( |
| 137 SkISize::Make(kWidth, kHeight)); | 138 NULL, kWidth * media::ScreenCaptureData::kBytesPerPixel, |
| 139 SkISize::Make(kWidth, kHeight)); |
| 138 | 140 |
| 139 // First the capturer is called. | 141 // First the capturer is called. |
| 140 Expectation capturer_capture = EXPECT_CALL(*capturer_, CaptureFrame()) | 142 Expectation capturer_capture = EXPECT_CALL(*capturer, CaptureFrame()) |
| 141 .After(capturer_start) | 143 .After(capturer_start) |
| 142 .WillRepeatedly(InvokeWithoutArgs( | 144 .WillRepeatedly(InvokeWithoutArgs( |
| 143 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); | 145 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); |
| 144 | 146 |
| 145 // Expect the encoder be called. | 147 // Expect the encoder be called. |
| 146 EXPECT_CALL(*encoder_, Encode(data_, false, _)) | 148 EXPECT_CALL(*encoder_, Encode(data_, false, _)) |
| 147 .WillRepeatedly(FinishEncode()); | 149 .WillRepeatedly(FinishEncode()); |
| 148 | 150 |
| 149 // By default delete the arguments when ProcessVideoPacket is received. | 151 // By default delete the arguments when ProcessVideoPacket is received. |
| 150 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 152 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 151 .WillRepeatedly(FinishSend()); | 153 .WillRepeatedly(FinishSend()); |
| 152 | 154 |
| 153 // For the first time when ProcessVideoPacket is received we stop the | 155 // For the first time when ProcessVideoPacket is received we stop the |
| 154 // VideoScheduler. | 156 // VideoScheduler. |
| 155 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 157 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 156 .WillOnce(DoAll( | 158 .WillOnce(DoAll( |
| 157 FinishSend(), | 159 FinishSend(), |
| 158 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) | 160 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) |
| 159 .RetiresOnSaturation(); | 161 .RetiresOnSaturation(); |
| 160 | 162 |
| 161 EXPECT_CALL(*capturer_, Stop()) | 163 EXPECT_CALL(*capturer, Stop()) |
| 162 .After(capturer_capture); | 164 .After(capturer_capture); |
| 163 | 165 |
| 164 // Start video frame capture. | 166 // Start video frame capture. |
| 165 StartVideoScheduler(capturer_.PassAs<VideoFrameCapturer>()); | 167 StartVideoScheduler(capturer.PassAs<media::ScreenCapturer>()); |
| 166 | 168 |
| 167 task_runner_ = NULL; | 169 task_runner_ = NULL; |
| 168 run_loop_.Run(); | 170 run_loop_.Run(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 } // namespace remoting | 173 } // namespace remoting |
| OLD | NEW |