Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "media/video/capture/screen/screen_capture_device.h" | 5 #include "media/video/capture/screen/screen_capture_device.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "media/video/capture/screen/screen_capture_data.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
| 16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 16 | 17 |
| 17 using ::testing::_; | 18 using ::testing::_; |
| 18 using ::testing::DoAll; | 19 using ::testing::DoAll; |
| 19 using ::testing::InvokeWithoutArgs; | 20 using ::testing::InvokeWithoutArgs; |
| 20 using ::testing::SaveArg; | 21 using ::testing::SaveArg; |
| 21 | 22 |
| 22 namespace media { | 23 namespace media { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 44 bool flip_horiz)); | 45 bool flip_horiz)); |
| 45 MOCK_METHOD2(OnIncomingCapturedVideoFrame, | 46 MOCK_METHOD2(OnIncomingCapturedVideoFrame, |
| 46 void(const scoped_refptr<media::VideoFrame>& frame, | 47 void(const scoped_refptr<media::VideoFrame>& frame, |
| 47 base::Time timestamp)); | 48 base::Time timestamp)); |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 // TODO(sergeyu): Move this to a separate file where it can be reused. | 51 // TODO(sergeyu): Move this to a separate file where it can be reused. |
| 51 class FakeScreenCapturer : public ScreenCapturer { | 52 class FakeScreenCapturer : public ScreenCapturer { |
| 52 public: | 53 public: |
| 53 FakeScreenCapturer() | 54 FakeScreenCapturer() |
| 54 : delegate_(NULL), | 55 : callback_(NULL), |
| 55 frame_index_(0) { | 56 frame_index_(0) { |
| 56 buffer_.reset(new uint8[kBufferSize]); | |
| 57 frames_[0] = new ScreenCaptureData( | |
| 58 buffer_.get(), kTestFrameWidth1 * ScreenCaptureData::kBytesPerPixel, | |
| 59 SkISize::Make(kTestFrameWidth1, kTestFrameHeight1)); | |
| 60 frames_[1] = new ScreenCaptureData( | |
| 61 buffer_.get(), kTestFrameWidth2 * ScreenCaptureData::kBytesPerPixel, | |
| 62 SkISize::Make(kTestFrameWidth2, kTestFrameHeight2)); | |
| 63 } | 57 } |
| 64 virtual ~FakeScreenCapturer() {} | 58 virtual ~FakeScreenCapturer() {} |
| 65 | 59 |
| 66 // VideoFrameCapturer interface. | 60 // VideoFrameCapturer interface. |
| 67 virtual void Start(Delegate* delegate) OVERRIDE { | 61 virtual void Start(Callback* callback) OVERRIDE { |
| 68 delegate_ = delegate; | 62 callback_ = callback; |
| 69 } | 63 } |
| 70 virtual void CaptureFrame() OVERRIDE { | 64 |
| 71 scoped_refptr<ScreenCaptureData> frame = | 65 virtual void Capture(const webrtc::DesktopRegion& region) OVERRIDE { |
| 72 frames_[frame_index_ % arraysize(frames_)]; | 66 webrtc::DesktopSize size; |
| 67 if (frame_index_ == 0) { | |
|
alexeypa (please no reviews)
2013/05/08 22:24:59
Previously, this method was alternating before 1st
Sergey Ulanov
2013/05/09 18:49:02
Doesn't really matter for the test that uses this
| |
| 68 size = webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1); | |
| 69 } else { | |
| 70 size = webrtc::DesktopSize(kTestFrameWidth2, kTestFrameHeight2); | |
| 71 } | |
| 73 frame_index_++; | 72 frame_index_++; |
| 74 delegate_->OnCaptureCompleted(frame); | 73 callback_->OnCaptureCompleted(new webrtc::BasicDesktopFrame(size)); |
| 74 } | |
| 75 | |
| 76 virtual void SetMouseShapeObserver( | |
| 77 MouseShapeObserver* mouse_shape_observer) OVERRIDE { | |
| 75 } | 78 } |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 Delegate* delegate_; | 81 Callback* callback_; |
| 79 scoped_ptr<uint8[]> buffer_; | |
| 80 scoped_refptr<ScreenCaptureData> frames_[2]; | |
| 81 int frame_index_; | 82 int frame_index_; |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 class ScreenCaptureDeviceTest : public testing::Test { | 85 class ScreenCaptureDeviceTest : public testing::Test { |
| 85 public: | 86 public: |
| 86 virtual void SetUp() OVERRIDE { | 87 virtual void SetUp() OVERRIDE { |
| 87 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread"); | 88 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread"); |
| 88 } | 89 } |
| 89 | 90 |
| 90 protected: | 91 protected: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 EXPECT_EQ(kTestFrameWidth1, caps.width); | 162 EXPECT_EQ(kTestFrameWidth1, caps.width); |
| 162 EXPECT_EQ(kTestFrameHeight1, caps.height); | 163 EXPECT_EQ(kTestFrameHeight1, caps.height); |
| 163 EXPECT_EQ(kFrameRate, caps.frame_rate); | 164 EXPECT_EQ(kFrameRate, caps.frame_rate); |
| 164 EXPECT_EQ(VideoCaptureCapability::kARGB, caps.color); | 165 EXPECT_EQ(VideoCaptureCapability::kARGB, caps.color); |
| 165 EXPECT_FALSE(caps.interlaced); | 166 EXPECT_FALSE(caps.interlaced); |
| 166 | 167 |
| 167 EXPECT_EQ(caps.width * caps.height * 4, frame_size); | 168 EXPECT_EQ(caps.width * caps.height * 4, frame_size); |
| 168 } | 169 } |
| 169 | 170 |
| 170 } // namespace media | 171 } // namespace media |
| OLD | NEW |