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

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

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 11 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.h » ('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 "remoting/base/auto_thread_task_runner.h"
10 #include "remoting/capturer/capture_data.h" 11 #include "remoting/capturer/capture_data.h"
11 #include "remoting/capturer/video_capturer_mock_objects.h" 12 #include "remoting/capturer/video_capturer_mock_objects.h"
12 #include "remoting/codec/video_encoder.h" 13 #include "remoting/codec/video_encoder.h"
13 #include "remoting/proto/video.pb.h" 14 #include "remoting/proto/video.pb.h"
14 #include "remoting/protocol/protocol_mock_objects.h" 15 #include "remoting/protocol/protocol_mock_objects.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 using ::remoting::protocol::MockClientStub; 19 using ::remoting::protocol::MockClientStub;
19 using ::remoting::protocol::MockVideoStub; 20 using ::remoting::protocol::MockVideoStub;
(...skipping 17 matching lines...) Expand all
37 ACTION(FinishEncode) { 38 ACTION(FinishEncode) {
38 scoped_ptr<VideoPacket> packet(new VideoPacket()); 39 scoped_ptr<VideoPacket> packet(new VideoPacket());
39 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); 40 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION);
40 arg2.Run(packet.Pass()); 41 arg2.Run(packet.Pass());
41 } 42 }
42 43
43 ACTION(FinishSend) { 44 ACTION(FinishSend) {
44 arg1.Run(); 45 arg1.Run();
45 } 46 }
46 47
47 ACTION_P2(StopVideoScheduler, scheduler, task) {
48 scheduler->get()->Stop(task);
49 }
50
51 } // namespace 48 } // namespace
52 49
53 static const int kWidth = 640; 50 static const int kWidth = 640;
54 static const int kHeight = 480; 51 static const int kHeight = 480;
55 52
56 class MockVideoEncoder : public VideoEncoder { 53 class MockVideoEncoder : public VideoEncoder {
57 public: 54 public:
58 MockVideoEncoder(); 55 MockVideoEncoder();
59 virtual ~MockVideoEncoder(); 56 virtual ~MockVideoEncoder();
60 57
61 MOCK_METHOD3(Encode, void( 58 MOCK_METHOD3(Encode, void(
62 scoped_refptr<CaptureData> capture_data, 59 scoped_refptr<CaptureData> capture_data,
63 bool key_frame, 60 bool key_frame,
64 const DataAvailableCallback& data_available_callback)); 61 const DataAvailableCallback& data_available_callback));
65 62
66 private: 63 private:
67 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); 64 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder);
68 }; 65 };
69 66
70 MockVideoEncoder::MockVideoEncoder() {} 67 MockVideoEncoder::MockVideoEncoder() {}
71 68
72 MockVideoEncoder::~MockVideoEncoder() {} 69 MockVideoEncoder::~MockVideoEncoder() {}
73 70
74 class VideoSchedulerTest : public testing::Test { 71 class VideoSchedulerTest : public testing::Test {
75 public: 72 public:
76 VideoSchedulerTest() { 73 VideoSchedulerTest() {
77 } 74 }
78 75
79 virtual void SetUp() OVERRIDE { 76 virtual void SetUp() OVERRIDE {
77 task_runner_ = new AutoThreadTaskRunner(
78 message_loop_.message_loop_proxy(), run_loop_.QuitClosure());
79
80 encoder_ = new MockVideoEncoder(); 80 encoder_ = new MockVideoEncoder();
81 } 81 }
82 82
83 void StartVideoScheduler() { 83 void StartVideoScheduler(scoped_ptr<VideoFrameCapturer> capturer) {
84 scheduler_ = VideoScheduler::Create( 84 scheduler_ = VideoScheduler::Create(
85 message_loop_.message_loop_proxy(), 85 task_runner_, // Capture
86 message_loop_.message_loop_proxy(), 86 task_runner_, // Encode
87 message_loop_.message_loop_proxy(), 87 task_runner_, // Network
88 &capturer_, 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();
97
96 protected: 98 protected:
97 MessageLoop message_loop_; 99 MessageLoop message_loop_;
100 base::RunLoop run_loop_;
101 scoped_refptr<AutoThreadTaskRunner> task_runner_;
98 scoped_refptr<VideoScheduler> scheduler_; 102 scoped_refptr<VideoScheduler> scheduler_;
99 103
100 MockClientStub client_stub_; 104 MockClientStub client_stub_;
101 MockVideoStub video_stub_; 105 MockVideoStub video_stub_;
102 MockVideoFrameCapturer capturer_;
103 106
104 // The following mock objects are owned by VideoScheduler. 107 // The following mock objects are owned by VideoScheduler.
105 MockVideoEncoder* encoder_; 108 MockVideoEncoder* encoder_;
106 109
107 scoped_refptr<CaptureData> data_; 110 scoped_refptr<CaptureData> data_;
108 111
109 private: 112 private:
110 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); 113 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest);
111 }; 114 };
112 115
113 void VideoSchedulerTest::GenerateOnCaptureCompleted() { 116 void VideoSchedulerTest::GenerateOnCaptureCompleted() {
114 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); 117 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10));
115 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); 118 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op);
116 119
117 scheduler_->OnCaptureCompleted(data_); 120 scheduler_->OnCaptureCompleted(data_);
118 } 121 }
119 122
123 void VideoSchedulerTest::StopVideoScheduler() {
124 scheduler_->Stop();
125 scheduler_ = NULL;
126 }
127
120 // 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
121 // cycle. When the first encoded packet is submitted to the network 129 // cycle. When the first encoded packet is submitted to the network
122 // 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
123 // sequence to be executed successfully. 131 // sequence to be executed successfully.
124 TEST_F(VideoSchedulerTest, StartAndStop) { 132 TEST_F(VideoSchedulerTest, StartAndStop) {
125 Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); 133 scoped_ptr<MockVideoFrameCapturer> capturer_(new MockVideoFrameCapturer());
134 Expectation capturer_start = EXPECT_CALL(*capturer_, Start(_));
126 135
127 data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel, 136 data_ = new CaptureData(NULL, kWidth * CaptureData::kBytesPerPixel,
128 SkISize::Make(kWidth, kHeight)); 137 SkISize::Make(kWidth, kHeight));
129 138
130 // Create a RunLoop through which to drive |message_loop_|.
131 base::RunLoop run_loop;
132
133 // First the capturer is called. 139 // First the capturer is called.
134 Expectation capturer_capture = EXPECT_CALL(capturer_, CaptureFrame()) 140 Expectation capturer_capture = EXPECT_CALL(*capturer_, CaptureFrame())
135 .After(capturer_start) 141 .After(capturer_start)
136 .WillRepeatedly(InvokeWithoutArgs( 142 .WillRepeatedly(InvokeWithoutArgs(
137 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); 143 this, &VideoSchedulerTest::GenerateOnCaptureCompleted));
138 144
139 // Expect the encoder be called. 145 // Expect the encoder be called.
140 EXPECT_CALL(*encoder_, Encode(data_, false, _)) 146 EXPECT_CALL(*encoder_, Encode(data_, false, _))
141 .WillRepeatedly(FinishEncode()); 147 .WillRepeatedly(FinishEncode());
142 148
143 // By default delete the arguments when ProcessVideoPacket is received. 149 // By default delete the arguments when ProcessVideoPacket is received.
144 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 150 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
145 .WillRepeatedly(FinishSend()); 151 .WillRepeatedly(FinishSend());
146 152
147 // For the first time when ProcessVideoPacket is received we stop the 153 // For the first time when ProcessVideoPacket is received we stop the
148 // VideoScheduler. 154 // VideoScheduler.
149 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 155 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
150 .WillOnce(DoAll( 156 .WillOnce(DoAll(
151 FinishSend(), 157 FinishSend(),
152 StopVideoScheduler(&scheduler_, run_loop.QuitClosure()))) 158 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler)))
153 .RetiresOnSaturation(); 159 .RetiresOnSaturation();
154 160
155 EXPECT_CALL(capturer_, Stop()) 161 EXPECT_CALL(*capturer_, Stop())
156 .After(capturer_capture); 162 .After(capturer_capture);
157 163
158 // Start video frame capture. 164 // Start video frame capture.
159 StartVideoScheduler(); 165 StartVideoScheduler(capturer_.PassAs<VideoFrameCapturer>());
160 run_loop.Run(); 166
167 task_runner_ = NULL;
168 run_loop_.Run();
161 } 169 }
162 170
163 } // namespace remoting 171 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/video_scheduler.cc ('k') | remoting/host/win/session_desktop_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698