Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/media/screen_capturer.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 #include "base/test/test_timeouts.h" | |
| 10 #include "base/time.h" | |
| 11 #include "remoting/capturer/capture_data.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using ::testing::_; | |
| 16 using ::testing::DoAll; | |
| 17 using ::testing::InvokeWithoutArgs; | |
| 18 using ::testing::SaveArg; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 namespace { | |
| 23 const int kTestFrameWidth1 = 100; | |
| 24 const int kTestFrameHeight1 = 100; | |
| 25 const int kTestFrameWidth2 = 200; | |
| 26 const int kTestFrameHeight2 = 150; | |
| 27 const int kBufferSize = kTestFrameWidth2 * kTestFrameHeight2 * 4; | |
| 28 | |
| 29 const int kFrameRate = 30; | |
| 30 | |
| 31 class MockFrameObserver : public media::VideoCaptureDevice::EventHandler { | |
| 32 public: | |
| 33 MOCK_METHOD0(OnError, void()); | |
| 34 MOCK_METHOD1(OnFrameInfo, void(const media::VideoCaptureCapability& info)); | |
| 35 MOCK_METHOD3(OnIncomingCapturedFrame, void(const uint8* data, int length, | |
| 36 base::Time timestamp)); | |
| 37 }; | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 // A class to perform video frame capturing for Linux. | |
|
Wez
2013/01/10 00:58:14
For Linux....?
Sergey Ulanov
2013/01/11 23:46:20
Copy-paste failure. Removed this comment.
| |
| 42 class FakeVideoFrameCapturer : public remoting::VideoFrameCapturer { | |
| 43 public: | |
| 44 FakeVideoFrameCapturer() | |
| 45 : delegate_(NULL), | |
| 46 frame_index_(0) { | |
| 47 buffer_.reset(new uint8[kBufferSize]); | |
| 48 frames_[0] = new remoting::CaptureData( | |
| 49 buffer_.get(), kTestFrameWidth1 * remoting::CaptureData::kBytesPerPixel, | |
| 50 SkISize::Make(kTestFrameWidth1, kTestFrameHeight1)); | |
| 51 frames_[1] = new remoting::CaptureData( | |
| 52 buffer_.get(), kTestFrameWidth2 * remoting::CaptureData::kBytesPerPixel, | |
| 53 SkISize::Make(kTestFrameWidth2, kTestFrameHeight2)); | |
| 54 } | |
| 55 virtual ~FakeVideoFrameCapturer() {} | |
| 56 | |
| 57 // VideoFrameCapturer interface. | |
| 58 virtual void Start(Delegate* delegate) OVERRIDE { | |
| 59 delegate_ = delegate; | |
| 60 } | |
| 61 virtual void Stop() OVERRIDE { | |
| 62 DCHECK(delegate_); | |
| 63 delegate_ = NULL; | |
| 64 } | |
| 65 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE { | |
| 66 NOTIMPLEMENTED(); | |
| 67 } | |
| 68 virtual void CaptureFrame() OVERRIDE { | |
| 69 scoped_refptr<remoting::CaptureData> frame = | |
| 70 frames_[frame_index_ % arraysize(frames_)]; | |
| 71 frame_index_++; | |
| 72 size_most_recent_ = frame->size(); | |
| 73 delegate_->OnCaptureCompleted(frame); | |
| 74 } | |
| 75 | |
| 76 virtual const SkISize& size_most_recent() const OVERRIDE { | |
|
Wez
2013/01/10 00:58:14
This has gone, I think?
Sergey Ulanov
2013/01/11 23:46:20
Removed now.
| |
| 77 return size_most_recent_; | |
| 78 } | |
| 79 | |
| 80 private: | |
| 81 Delegate* delegate_; | |
| 82 SkISize size_most_recent_; | |
| 83 scoped_array<uint8> buffer_; | |
| 84 scoped_refptr<remoting::CaptureData> frames_[2]; | |
| 85 int frame_index_; | |
| 86 }; | |
| 87 | |
| 88 TEST(ScreenCaptureTest, Capture) { | |
| 89 ScreenCapturer capturer; | |
| 90 media::VideoCaptureCapability caps; | |
| 91 base::WaitableEvent done_event(false, false); | |
| 92 int frame_size; | |
| 93 | |
| 94 MockFrameObserver frame_observer; | |
| 95 EXPECT_CALL(frame_observer, OnFrameInfo(_)) | |
| 96 .WillOnce(SaveArg<0>(&caps)); | |
| 97 EXPECT_CALL(frame_observer, OnError()) | |
| 98 .Times(0); | |
| 99 EXPECT_CALL(frame_observer, OnIncomingCapturedFrame(_, _, _)) | |
| 100 .WillRepeatedly(DoAll( | |
| 101 SaveArg<1>(&frame_size), | |
| 102 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | |
| 103 | |
| 104 capturer.Allocate(640, 480, kFrameRate, &frame_observer); | |
| 105 capturer.Start(); | |
| 106 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
| 107 capturer.Stop(); | |
| 108 capturer.DeAllocate(); | |
| 109 | |
| 110 EXPECT_GT(caps.width, 0); | |
|
Wez
2013/01/10 00:58:14
Shouldn't these exactly match the frame1 values?
Sergey Ulanov
2013/01/11 23:46:20
No. This test uses real capturer instead of FakeVi
| |
| 111 EXPECT_GT(caps.height, 0); | |
| 112 EXPECT_EQ(kFrameRate, caps.frame_rate); | |
| 113 EXPECT_EQ(media::VideoCaptureCapability::kARGB, caps.color); | |
| 114 EXPECT_EQ(false, caps.interlaced); | |
| 115 | |
| 116 EXPECT_EQ(caps.width * caps.height * 4, frame_size); | |
| 117 } | |
| 118 | |
| 119 TEST(ScreenCaptureTest, ScreenResolutionChange) { | |
| 120 FakeVideoFrameCapturer* mock_capturer = new FakeVideoFrameCapturer(); | |
| 121 | |
| 122 ScreenCapturer capturer; | |
| 123 capturer.set_test_frame_capturer( | |
| 124 scoped_ptr<remoting::VideoFrameCapturer>(mock_capturer)); | |
| 125 | |
| 126 media::VideoCaptureCapability caps; | |
| 127 base::WaitableEvent done_event(false, false); | |
| 128 int frame_size; | |
| 129 | |
| 130 MockFrameObserver frame_observer; | |
| 131 EXPECT_CALL(frame_observer, OnFrameInfo(_)) | |
| 132 .WillOnce(SaveArg<0>(&caps)); | |
| 133 EXPECT_CALL(frame_observer, OnError()) | |
| 134 .Times(0); | |
| 135 EXPECT_CALL(frame_observer, OnIncomingCapturedFrame(_, _, _)) | |
| 136 .WillRepeatedly(DoAll( | |
| 137 SaveArg<1>(&frame_size), | |
| 138 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | |
| 139 | |
| 140 capturer.Allocate(640, 480, kFrameRate, &frame_observer); | |
| 141 capturer.Start(); | |
| 142 // Capture first frame. | |
| 143 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
| 144 done_event.Reset(); | |
| 145 // Capture second frame. | |
| 146 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | |
| 147 capturer.Stop(); | |
| 148 capturer.DeAllocate(); | |
| 149 | |
| 150 EXPECT_EQ(kTestFrameWidth1, caps.width); | |
| 151 EXPECT_EQ(kTestFrameHeight1, caps.height); | |
| 152 EXPECT_EQ(kFrameRate, caps.frame_rate); | |
| 153 EXPECT_EQ(media::VideoCaptureCapability::kARGB, caps.color); | |
| 154 EXPECT_EQ(false, caps.interlaced); | |
| 155 | |
| 156 EXPECT_EQ(caps.width * caps.height * 4, frame_size); | |
| 157 } | |
| 158 | |
| 159 } // namespace content | |
| OLD | NEW |