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

Side by Side Diff: media/video/capture/fake_video_capture_device_unittest.cc

Issue 1064963002: VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "media/base/video_capture_types.h" 10 #include "media/base/video_capture_types.h"
11 #include "media/video/capture/fake_video_capture_device.h" 11 #include "media/video/capture/fake_video_capture_device.h"
12 #include "media/video/capture/fake_video_capture_device_factory.h" 12 #include "media/video/capture/fake_video_capture_device_factory.h"
13 #include "media/video/capture/video_capture_device.h" 13 #include "media/video/capture/video_capture_device.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::SaveArg; 18 using ::testing::SaveArg;
19 19
20 namespace media { 20 namespace media {
21 21
22 namespace { 22 namespace {
23 23
24 static const FakeVideoCaptureDevice::FakeVideoCaptureDeviceType 24 static const FakeVideoCaptureDevice::FakeVideoCaptureDeviceType
25 kCaptureTypes[] = { 25 kCaptureTypes[] = {
26 FakeVideoCaptureDevice::USING_OWN_BUFFERS, 26 FakeVideoCaptureDevice::USING_OWN_BUFFERS,
27 FakeVideoCaptureDevice::USING_OWN_BUFFERS_TRIPLANAR,
27 FakeVideoCaptureDevice::USING_CLIENT_BUFFERS, 28 FakeVideoCaptureDevice::USING_CLIENT_BUFFERS,
28 // TODO(mcasas): Add FakeVideoCaptureDevice::USING_GPU_MEMORY_BUFFERS when 29 FakeVideoCaptureDevice::USING_GPU_MEMORY_BUFFERS,
29 // implemented. 30 };
31
32 class SimpleAccesor : public media::DataHandle {
33 public:
34 explicit SimpleAccesor(void* data) : data_(data) {}
35 void* data() override { return data_; }
36
37 private:
38 void* data_;
30 }; 39 };
31 40
32 // This class is a Client::Buffer that allocates and frees the requested |size|. 41 // This class is a Client::Buffer that allocates and frees the requested |size|.
33 class MockBuffer : public VideoCaptureDevice::Client::Buffer { 42 class MockBuffer : public VideoCaptureDevice::Client::Buffer {
34 public: 43 public:
35 MockBuffer(int buffer_id, size_t size) 44 MockBuffer(int buffer_id, size_t size)
36 : id_(buffer_id), 45 : id_(buffer_id), size_(size), data_(new uint8[size_]) {}
37 size_(size),
38 data_(new uint8[size_]) {}
39 int id() const override { return id_; } 46 int id() const override { return id_; }
40 void* data() const override { return static_cast<void*>(data_); }
41 size_t size() const override { return size_; } 47 size_t size() const override { return size_; }
48 scoped_ptr<media::DataHandle> GetDataHandle() override {
49 return make_scoped_ptr(new SimpleAccesor(data_));
50 }
51 ClientBuffer AsClientBuffer() override { return nullptr; }
42 52
43 private: 53 private:
44 ~MockBuffer() override { delete[] data_; } 54 ~MockBuffer() override { delete[] data_; }
45 55
46 const int id_; 56 const int id_;
47 const size_t size_; 57 const size_t size_;
48 uint8* const data_; 58 uint8* const data_;
49 }; 59 };
50 60
51 class MockClient : public VideoCaptureDevice::Client { 61 class MockClient : public VideoCaptureDevice::Client {
52 public: 62 public:
53 MOCK_METHOD9(OnIncomingCapturedYuvData,
54 void (const uint8* y_data,
55 const uint8* u_data,
56 const uint8* v_data,
57 size_t y_stride,
58 size_t u_stride,
59 size_t v_stride,
60 const VideoCaptureFormat& frame_format,
61 int clockwise_rotation,
62 const base::TimeTicks& timestamp));
63 MOCK_METHOD1(OnError, void(const std::string& reason)); 63 MOCK_METHOD1(OnError, void(const std::string& reason));
64 64
65 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) 65 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb)
66 : frame_cb_(frame_cb) {} 66 : frame_cb_(frame_cb) {}
67 67
68 // Client virtual method for capturing using Device Buffers. 68 // Client virtual methods for capturing using Device Buffers.
69 void OnIncomingCapturedData(const uint8* data, 69 void OnIncomingCapturedData(const uint8* data,
70 int length, 70 int length,
71 const VideoCaptureFormat& format, 71 const VideoCaptureFormat& format,
72 int rotation, 72 int rotation,
73 const base::TimeTicks& timestamp) { 73 const base::TimeTicks& timestamp) {
74 frame_cb_.Run(format); 74 frame_cb_.Run(format);
75 } 75 }
76 void OnIncomingCapturedYuvData(const uint8* y_data,
77 const uint8* u_data,
78 const uint8* v_data,
79 size_t y_stride,
80 size_t u_stride,
81 size_t v_stride,
82 const VideoCaptureFormat& frame_format,
83 int clockwise_rotation,
84 const base::TimeTicks& timestamp) {
85 frame_cb_.Run(frame_format);
86 }
76 87
77 // Virtual methods for capturing using Client's Buffers. 88 // Virtual methods for capturing using Client's Buffers.
78 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format, 89 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format,
79 const gfx::Size& dimensions) { 90 const gfx::Size& dimensions) {
80 EXPECT_EQ(format, PIXEL_FORMAT_I420); 91 EXPECT_TRUE(format == PIXEL_FORMAT_I420 ||
92 format == PIXEL_FORMAT_GPUMEMORYBUFFER);
81 EXPECT_GT(dimensions.GetArea(), 0); 93 EXPECT_GT(dimensions.GetArea(), 0);
82 return make_scoped_refptr(new MockBuffer(0, dimensions.GetArea() * 3 / 2)); 94 const VideoCaptureFormat frame_format(dimensions, 0.0, format);
95 return make_scoped_refptr(
96 new MockBuffer(0, frame_format.ImageAllocationSize()));
97 }
98 void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer,
99 const VideoCaptureFormat& frame_format,
100 const base::TimeTicks& timestamp) {
101 frame_cb_.Run(frame_format);
83 } 102 }
84 void OnIncomingCapturedVideoFrame( 103 void OnIncomingCapturedVideoFrame(
85 const scoped_refptr<Buffer>& buffer, 104 const scoped_refptr<Buffer>& buffer,
86 const scoped_refptr<media::VideoFrame>& frame, 105 const scoped_refptr<media::VideoFrame>& frame,
87 const base::TimeTicks& timestamp) { 106 const base::TimeTicks& timestamp) {
88 VideoCaptureFormat format(frame->natural_size(), 30.0, PIXEL_FORMAT_I420); 107 VideoCaptureFormat format(frame->natural_size(), 30.0, PIXEL_FORMAT_I420);
89 frame_cb_.Run(format); 108 frame_cb_.Run(format);
90 } 109 }
91 110
92 private: 111 private:
(...skipping 25 matching lines...) Expand all
118 FakeVideoCaptureDeviceTest() 137 FakeVideoCaptureDeviceTest()
119 : loop_(new base::MessageLoop()), 138 : loop_(new base::MessageLoop()),
120 client_(new MockClient( 139 client_(new MockClient(
121 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, 140 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured,
122 base::Unretained(this)))), 141 base::Unretained(this)))),
123 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { 142 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {
124 device_enumeration_listener_ = new DeviceEnumerationListener(); 143 device_enumeration_listener_ = new DeviceEnumerationListener();
125 } 144 }
126 145
127 void SetUp() override { 146 void SetUp() override {
128 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_))
129 .Times(0);
130 EXPECT_CALL(*client_, OnError(_)).Times(0); 147 EXPECT_CALL(*client_, OnError(_)).Times(0);
131 } 148 }
132 149
133 void OnFrameCaptured(const VideoCaptureFormat& format) { 150 void OnFrameCaptured(const VideoCaptureFormat& format) {
134 last_format_ = format; 151 last_format_ = format;
135 run_loop_->QuitClosure().Run(); 152 run_loop_->QuitClosure().Run();
136 } 153 }
137 154
138 void WaitForCapturedFrame() { 155 void WaitForCapturedFrame() {
139 run_loop_.reset(new base::RunLoop()); 156 run_loop_.reset(new base::RunLoop());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); 226 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420);
210 EXPECT_GE(supported_formats[2].frame_rate, 20.0); 227 EXPECT_GE(supported_formats[2].frame_rate, 20.0);
211 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); 228 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920);
212 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); 229 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080);
213 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); 230 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420);
214 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 231 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
215 } 232 }
216 } 233 }
217 234
218 }; // namespace media 235 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698