Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: remoting/host/video_scheduler_unittest.cc

Issue 15692018: Remove screen capturers from media/video/capture/screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/video_scheduler.cc ('k') | remoting/host/win/session_desktop_environment.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_capturer_mock_objects.h"
11 #include "remoting/base/auto_thread_task_runner.h" 10 #include "remoting/base/auto_thread_task_runner.h"
12 #include "remoting/codec/video_encoder.h" 11 #include "remoting/codec/video_encoder.h"
13 #include "remoting/proto/video.pb.h" 12 #include "remoting/proto/video.pb.h"
14 #include "remoting/protocol/protocol_mock_objects.h" 13 #include "remoting/protocol/protocol_mock_objects.h"
15 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
17 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.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::_;
23 using ::testing::AtLeast; 23 using ::testing::AtLeast;
24 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
25 using ::testing::DeleteArg; 25 using ::testing::DeleteArg;
26 using ::testing::DoAll; 26 using ::testing::DoAll;
27 using ::testing::Expectation; 27 using ::testing::Expectation;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 MockVideoEncoder::MockVideoEncoder() {} 66 MockVideoEncoder::MockVideoEncoder() {}
67 67
68 MockVideoEncoder::~MockVideoEncoder() {} 68 MockVideoEncoder::~MockVideoEncoder() {}
69 69
70 class VideoSchedulerTest : public testing::Test { 70 class VideoSchedulerTest : public testing::Test {
71 public: 71 public:
72 VideoSchedulerTest(); 72 VideoSchedulerTest();
73 73
74 virtual void SetUp() OVERRIDE; 74 virtual void SetUp() OVERRIDE;
75 75
76 void StartVideoScheduler(scoped_ptr<media::ScreenCapturer> capturer); 76 void StartVideoScheduler(scoped_ptr<webrtc::ScreenCapturer> capturer);
77 void StopVideoScheduler(); 77 void StopVideoScheduler();
78 78
79 // media::ScreenCapturer mocks. 79 // webrtc::ScreenCapturer mocks.
80 void OnCapturerStart(media::ScreenCapturer::Callback* callback); 80 void OnCapturerStart(webrtc::ScreenCapturer::Callback* callback);
81 void OnCaptureFrame(const webrtc::DesktopRegion& region); 81 void OnCaptureFrame(const webrtc::DesktopRegion& region);
82 82
83 protected: 83 protected:
84 base::MessageLoop message_loop_; 84 base::MessageLoop message_loop_;
85 base::RunLoop run_loop_; 85 base::RunLoop run_loop_;
86 scoped_refptr<AutoThreadTaskRunner> task_runner_; 86 scoped_refptr<AutoThreadTaskRunner> task_runner_;
87 scoped_refptr<VideoScheduler> scheduler_; 87 scoped_refptr<VideoScheduler> scheduler_;
88 88
89 MockClientStub client_stub_; 89 MockClientStub client_stub_;
90 MockVideoStub video_stub_; 90 MockVideoStub video_stub_;
91 91
92 // The following mock objects are owned by VideoScheduler. 92 // The following mock objects are owned by VideoScheduler.
93 MockVideoEncoder* encoder_; 93 MockVideoEncoder* encoder_;
94 94
95 scoped_ptr<webrtc::DesktopFrame> frame_; 95 scoped_ptr<webrtc::DesktopFrame> frame_;
96 96
97 // Points to the callback passed to media::ScreenCapturer::Start(). 97 // Points to the callback passed to webrtc::ScreenCapturer::Start().
98 media::ScreenCapturer::Callback* capturer_callback_; 98 webrtc::ScreenCapturer::Callback* capturer_callback_;
99 99
100 private: 100 private:
101 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); 101 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest);
102 }; 102 };
103 103
104 VideoSchedulerTest::VideoSchedulerTest() 104 VideoSchedulerTest::VideoSchedulerTest()
105 : encoder_(NULL), 105 : encoder_(NULL),
106 capturer_callback_(NULL) { 106 capturer_callback_(NULL) {
107 } 107 }
108 108
109 void VideoSchedulerTest::SetUp() { 109 void VideoSchedulerTest::SetUp() {
110 task_runner_ = new AutoThreadTaskRunner( 110 task_runner_ = new AutoThreadTaskRunner(
111 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); 111 message_loop_.message_loop_proxy(), run_loop_.QuitClosure());
112 112
113 encoder_ = new MockVideoEncoder(); 113 encoder_ = new MockVideoEncoder();
114 } 114 }
115 115
116 void VideoSchedulerTest::StartVideoScheduler( 116 void VideoSchedulerTest::StartVideoScheduler(
117 scoped_ptr<media::ScreenCapturer> capturer) { 117 scoped_ptr<webrtc::ScreenCapturer> capturer) {
118 scheduler_ = new VideoScheduler( 118 scheduler_ = new VideoScheduler(
119 task_runner_, // Capture 119 task_runner_, // Capture
120 task_runner_, // Encode 120 task_runner_, // Encode
121 task_runner_, // Network 121 task_runner_, // Network
122 capturer.Pass(), 122 capturer.Pass(),
123 scoped_ptr<VideoEncoder>(encoder_), 123 scoped_ptr<VideoEncoder>(encoder_),
124 &client_stub_, 124 &client_stub_,
125 &video_stub_); 125 &video_stub_);
126 scheduler_->Start(); 126 scheduler_->Start();
127 } 127 }
128 128
129 void VideoSchedulerTest::StopVideoScheduler() { 129 void VideoSchedulerTest::StopVideoScheduler() {
130 scheduler_->Stop(); 130 scheduler_->Stop();
131 scheduler_ = NULL; 131 scheduler_ = NULL;
132 } 132 }
133 133
134 void VideoSchedulerTest::OnCapturerStart( 134 void VideoSchedulerTest::OnCapturerStart(
135 media::ScreenCapturer::Callback* callback) { 135 webrtc::ScreenCapturer::Callback* callback) {
136 EXPECT_FALSE(capturer_callback_); 136 EXPECT_FALSE(capturer_callback_);
137 EXPECT_TRUE(callback); 137 EXPECT_TRUE(callback);
138 138
139 capturer_callback_ = callback; 139 capturer_callback_ = callback;
140 } 140 }
141 141
142 void VideoSchedulerTest::OnCaptureFrame(const webrtc::DesktopRegion& region) { 142 void VideoSchedulerTest::OnCaptureFrame(const webrtc::DesktopRegion& region) {
143 frame_->mutable_updated_region()->SetRect( 143 frame_->mutable_updated_region()->SetRect(
144 webrtc::DesktopRect::MakeXYWH(0, 0, 10, 10)); 144 webrtc::DesktopRect::MakeXYWH(0, 0, 10, 10));
145 capturer_callback_->OnCaptureCompleted(frame_.release()); 145 capturer_callback_->OnCaptureCompleted(frame_.release());
146 } 146 }
147 147
148 // This test mocks capturer, encoder and network layer to simulate one capture 148 // This test mocks capturer, encoder and network layer to simulate one capture
149 // cycle. When the first encoded packet is submitted to the network 149 // cycle. When the first encoded packet is submitted to the network
150 // VideoScheduler is instructed to come to a complete stop. We expect the stop 150 // VideoScheduler is instructed to come to a complete stop. We expect the stop
151 // sequence to be executed successfully. 151 // sequence to be executed successfully.
152 TEST_F(VideoSchedulerTest, StartAndStop) { 152 TEST_F(VideoSchedulerTest, StartAndStop) {
153 scoped_ptr<media::MockScreenCapturer> capturer( 153 scoped_ptr<webrtc::MockScreenCapturer> capturer(
154 new media::MockScreenCapturer()); 154 new webrtc::MockScreenCapturer());
155 Expectation capturer_start = 155 Expectation capturer_start =
156 EXPECT_CALL(*capturer, Start(_)) 156 EXPECT_CALL(*capturer, Start(_))
157 .WillOnce(Invoke(this, &VideoSchedulerTest::OnCapturerStart)); 157 .WillOnce(Invoke(this, &VideoSchedulerTest::OnCapturerStart));
158 158
159 frame_.reset(new webrtc::BasicDesktopFrame( 159 frame_.reset(new webrtc::BasicDesktopFrame(
160 webrtc::DesktopSize(kWidth, kHeight))); 160 webrtc::DesktopSize(kWidth, kHeight)));
161 webrtc::DesktopFrame* frame_ptr = frame_.get(); 161 webrtc::DesktopFrame* frame_ptr = frame_.get();
162 162
163 // First the capturer is called. 163 // First the capturer is called.
164 Expectation capturer_capture = EXPECT_CALL(*capturer, Capture(_)) 164 Expectation capturer_capture = EXPECT_CALL(*capturer, Capture(_))
(...skipping 10 matching lines...) Expand all
175 175
176 // For the first time when ProcessVideoPacket is received we stop the 176 // For the first time when ProcessVideoPacket is received we stop the
177 // VideoScheduler. 177 // VideoScheduler.
178 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 178 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
179 .WillOnce(DoAll( 179 .WillOnce(DoAll(
180 FinishSend(), 180 FinishSend(),
181 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) 181 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler)))
182 .RetiresOnSaturation(); 182 .RetiresOnSaturation();
183 183
184 // Start video frame capture. 184 // Start video frame capture.
185 StartVideoScheduler(capturer.PassAs<media::ScreenCapturer>()); 185 StartVideoScheduler(capturer.PassAs<webrtc::ScreenCapturer>());
186 186
187 task_runner_ = NULL; 187 task_runner_ = NULL;
188 run_loop_.Run(); 188 run_loop_.Run();
189 } 189 }
190 190
191 } // namespace remoting 191 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/video_scheduler.cc ('k') | remoting/host/win/session_desktop_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698