OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
Wez
2013/01/31 00:15:29
Drop (c), change to 2013.
Sergey Ulanov
2013/01/31 02:05:43
same as in the other two files.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/video/capture/screen/screen_capture_device.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/sequenced_task_runner.h" | |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "base/test/test_timeouts.h" | |
11 #include "base/threading/sequenced_worker_pool.h" | |
12 #include "base/time.h" | |
13 #include "media/video/capture/screen/screen_capture_data.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 using ::testing::_; | |
18 using ::testing::DoAll; | |
19 using ::testing::InvokeWithoutArgs; | |
20 using ::testing::SaveArg; | |
21 | |
22 namespace media { | |
23 | |
24 namespace { | |
Wez
2013/01/31 00:15:29
nit: Blank line after namespace, for consistency :
Sergey Ulanov
2013/01/31 02:05:43
Done.
| |
25 const int kTestFrameWidth1 = 100; | |
26 const int kTestFrameHeight1 = 100; | |
27 const int kTestFrameWidth2 = 200; | |
28 const int kTestFrameHeight2 = 150; | |
29 const int kBufferSize = kTestFrameWidth2 * kTestFrameHeight2 * 4; | |
30 | |
31 const int kFrameRate = 30; | |
32 | |
33 class MockFrameObserver : public VideoCaptureDevice::EventHandler { | |
Wez
2013/01/31 00:15:29
Is there really no other test that ever needs to m
Sergey Ulanov
2013/01/31 02:05:43
There is one in media/video/capture/video_capture_
| |
34 public: | |
35 MOCK_METHOD0(OnError, void()); | |
36 MOCK_METHOD1(OnFrameInfo, void(const VideoCaptureCapability& info)); | |
37 MOCK_METHOD3(OnIncomingCapturedFrame, void(const uint8* data, int length, | |
38 base::Time timestamp)); | |
39 }; | |
40 | |
41 } // namespace | |
42 | |
43 class FakeScreenCapturer : public ScreenCapturer { | |
Wez
2013/01/31 00:15:29
We used to have a FakeScreenCapturer in remoting/h
Wez
2013/01/31 00:15:29
If this class stays here it should live in the ano
Sergey Ulanov
2013/01/31 02:05:43
Added TODO.
Sergey Ulanov
2013/01/31 02:05:43
Done.
| |
44 public: | |
45 FakeScreenCapturer() | |
46 : delegate_(NULL), | |
47 frame_index_(0) { | |
48 buffer_.reset(new uint8[kBufferSize]); | |
49 frames_[0] = new ScreenCaptureData( | |
50 buffer_.get(), kTestFrameWidth1 * ScreenCaptureData::kBytesPerPixel, | |
51 SkISize::Make(kTestFrameWidth1, kTestFrameHeight1)); | |
52 frames_[1] = new ScreenCaptureData( | |
53 buffer_.get(), kTestFrameWidth2 * ScreenCaptureData::kBytesPerPixel, | |
54 SkISize::Make(kTestFrameWidth2, kTestFrameHeight2)); | |
55 } | |
56 virtual ~FakeScreenCapturer() {} | |
57 | |
58 // VideoFrameCapturer interface. | |
59 virtual void Start(Delegate* delegate) OVERRIDE { | |
60 delegate_ = delegate; | |
61 } | |
62 virtual void Stop() OVERRIDE { | |
63 delegate_ = NULL; | |
64 } | |
65 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE { | |
66 NOTIMPLEMENTED(); | |
67 } | |
68 virtual void CaptureFrame() OVERRIDE { | |
69 scoped_refptr<ScreenCaptureData> frame = | |
70 frames_[frame_index_ % arraysize(frames_)]; | |
71 frame_index_++; | |
72 delegate_->OnCaptureCompleted(frame); | |
73 } | |
74 | |
75 private: | |
76 Delegate* delegate_; | |
77 scoped_array<uint8> buffer_; | |
78 scoped_refptr<ScreenCaptureData> frames_[2]; | |
79 int frame_index_; | |
80 }; | |
81 | |
82 | |
Wez
2013/01/31 00:15:29
nit: Spurious blank line!
Sergey Ulanov
2013/01/31 02:05:43
Done.
| |
83 class ScreenCaptureDeviceTest : public testing::Test { | |
84 public: | |
85 virtual void SetUp() OVERRIDE { | |
86 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread"); | |
87 } | |
88 | |
89 protected: | |
90 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | |
91 }; | |
92 | |
93 TEST_F(ScreenCaptureDeviceTest, Capture) { | |
94 ScreenCaptureDevice capture_device( | |
95 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken())); | |
96 VideoCaptureCapability caps; | |
97 base::WaitableEvent done_event(false, false); | |
98 int frame_size; | |
99 | |
100 MockFrameObserver frame_observer; | |
101 EXPECT_CALL(frame_observer, OnFrameInfo(_)) | |
102 .WillOnce(SaveArg<0>(&caps)); | |
103 EXPECT_CALL(frame_observer, OnError()) | |
104 .Times(0); | |
105 EXPECT_CALL(frame_observer, OnIncomingCapturedFrame(_, _, _)) | |
106 .WillRepeatedly(DoAll( | |
107 SaveArg<1>(&frame_size), | |
108 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | |
109 | |
110 capture_device.Allocate(640, 480, kFrameRate, &frame_observer); | |
111 capture_device.Start(); | |
112 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
113 capture_device.Stop(); | |
114 capture_device.DeAllocate(); | |
115 | |
116 EXPECT_GT(caps.width, 0); | |
117 EXPECT_GT(caps.height, 0); | |
118 EXPECT_EQ(kFrameRate, caps.frame_rate); | |
Wez
2013/01/31 00:15:29
That seems a peculiar guarantee; do we really inte
Sergey Ulanov
2013/01/31 02:05:43
Actual frame rate may be slower when CPU is slow o
| |
119 EXPECT_EQ(VideoCaptureCapability::kARGB, caps.color); | |
120 EXPECT_EQ(false, caps.interlaced); | |
121 | |
122 EXPECT_EQ(caps.width * caps.height * 4, frame_size); | |
Wez
2013/01/31 00:15:29
Is it required that VideoCapturer implementations
Sergey Ulanov
2013/01/31 02:05:43
Yes.
| |
123 } | |
124 | |
125 TEST_F(ScreenCaptureDeviceTest, ScreenResolutionChange) { | |
126 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | |
127 | |
128 ScreenCaptureDevice capture_device( | |
129 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken())); | |
130 capture_device.set_test_screen_capturer( | |
131 scoped_ptr<ScreenCapturer>(mock_capturer)); | |
132 | |
133 VideoCaptureCapability caps; | |
134 base::WaitableEvent done_event(false, false); | |
135 int frame_size; | |
136 | |
137 MockFrameObserver frame_observer; | |
138 EXPECT_CALL(frame_observer, OnFrameInfo(_)) | |
139 .WillOnce(SaveArg<0>(&caps)); | |
140 EXPECT_CALL(frame_observer, OnError()) | |
141 .Times(0); | |
142 EXPECT_CALL(frame_observer, OnIncomingCapturedFrame(_, _, _)) | |
143 .WillRepeatedly(DoAll( | |
144 SaveArg<1>(&frame_size), | |
145 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | |
146 | |
147 capture_device.Allocate(640, 480, kFrameRate, &frame_observer); | |
148 capture_device.Start(); | |
149 // Capture first frame. | |
150 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
151 done_event.Reset(); | |
152 // Capture second frame. | |
153 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
154 capture_device.Stop(); | |
155 capture_device.DeAllocate(); | |
Wez
2013/01/31 00:15:29
It's not clear to me what property of the class th
Sergey Ulanov
2013/01/31 02:05:43
That it doesn't crash when screen resolution chang
| |
156 | |
157 EXPECT_EQ(kTestFrameWidth1, caps.width); | |
158 EXPECT_EQ(kTestFrameHeight1, caps.height); | |
159 EXPECT_EQ(kFrameRate, caps.frame_rate); | |
160 EXPECT_EQ(VideoCaptureCapability::kARGB, caps.color); | |
161 EXPECT_EQ(false, caps.interlaced); | |
162 | |
163 EXPECT_EQ(caps.width * caps.height * 4, frame_size); | |
164 } | |
165 | |
166 } // namespace media | |
OLD | NEW |