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

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

Issue 1090273006: Revert of 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_I420, 28 // TODO(mcasas): Add FakeVideoCaptureDevice::USING_GPU_MEMORY_BUFFERS when
29 FakeVideoCaptureDevice::USING_CLIENT_BUFFERS_GPU, 29 // implemented.
30 }; 30 };
31 31
32 // This class is a Client::Buffer that allocates and frees the requested |size|. 32 // This class is a Client::Buffer that allocates and frees the requested |size|.
33 class MockBuffer : public VideoCaptureDevice::Client::Buffer { 33 class MockBuffer : public VideoCaptureDevice::Client::Buffer {
34 public: 34 public:
35 MockBuffer(int buffer_id, size_t size) 35 MockBuffer(int buffer_id, size_t size)
36 : id_(buffer_id), size_(size), data_(new uint8[size_]) {} 36 : id_(buffer_id),
37 ~MockBuffer() override { delete[] data_; } 37 size_(size),
38 data_(new uint8[size_]) {}
38 int id() const override { return id_; } 39 int id() const override { return id_; }
40 void* data() const override { return static_cast<void*>(data_); }
39 size_t size() const override { return size_; } 41 size_t size() const override { return size_; }
40 void* data() override { return data_; }
41 ClientBuffer AsClientBuffer() override { return nullptr; }
42 42
43 private: 43 private:
44 ~MockBuffer() override { delete[] data_; }
45
44 const int id_; 46 const int id_;
45 const size_t size_; 47 const size_t size_;
46 uint8* const data_; 48 uint8* const data_;
47 }; 49 };
48 50
49 class MockClient : public VideoCaptureDevice::Client { 51 class MockClient : public VideoCaptureDevice::Client {
50 public: 52 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));
51 MOCK_METHOD1(OnError, void(const std::string& reason)); 63 MOCK_METHOD1(OnError, void(const std::string& reason));
52 64
53 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) 65 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb)
54 : frame_cb_(frame_cb) {} 66 : frame_cb_(frame_cb) {}
55 67
56 // Client virtual methods for capturing using Device Buffers. 68 // Client virtual method for capturing using Device Buffers.
57 void OnIncomingCapturedData(const uint8* data, 69 void OnIncomingCapturedData(const uint8* data,
58 int length, 70 int length,
59 const VideoCaptureFormat& format, 71 const VideoCaptureFormat& format,
60 int rotation, 72 int rotation,
61 const base::TimeTicks& timestamp) { 73 const base::TimeTicks& timestamp) {
62 frame_cb_.Run(format); 74 frame_cb_.Run(format);
63 } 75 }
64 void OnIncomingCapturedYuvData(const uint8* y_data,
65 const uint8* u_data,
66 const uint8* v_data,
67 size_t y_stride,
68 size_t u_stride,
69 size_t v_stride,
70 const VideoCaptureFormat& frame_format,
71 int clockwise_rotation,
72 const base::TimeTicks& timestamp) {
73 frame_cb_.Run(frame_format);
74 }
75 76
76 // Virtual methods for capturing using Client's Buffers. 77 // Virtual methods for capturing using Client's Buffers.
77 scoped_ptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format, 78 scoped_refptr<Buffer> ReserveOutputBuffer(media::VideoPixelFormat format,
78 const gfx::Size& dimensions) { 79 const gfx::Size& dimensions) {
79 EXPECT_TRUE(format == PIXEL_FORMAT_I420 || 80 EXPECT_EQ(format, PIXEL_FORMAT_I420);
80 format == PIXEL_FORMAT_GPUMEMORYBUFFER);
81 EXPECT_GT(dimensions.GetArea(), 0); 81 EXPECT_GT(dimensions.GetArea(), 0);
82 const VideoCaptureFormat frame_format(dimensions, 0.0, format); 82 return make_scoped_refptr(new MockBuffer(0, dimensions.GetArea() * 3 / 2));
83 return make_scoped_ptr(
84 new MockBuffer(0, frame_format.ImageAllocationSize()));
85 }
86 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer,
87 const VideoCaptureFormat& frame_format,
88 const base::TimeTicks& timestamp) {
89 frame_cb_.Run(frame_format);
90 } 83 }
91 void OnIncomingCapturedVideoFrame( 84 void OnIncomingCapturedVideoFrame(
92 scoped_ptr<Buffer> buffer, 85 const scoped_refptr<Buffer>& buffer,
93 const scoped_refptr<media::VideoFrame>& frame, 86 const scoped_refptr<media::VideoFrame>& frame,
94 const base::TimeTicks& timestamp) { 87 const base::TimeTicks& timestamp) {
95 VideoCaptureFormat format(frame->natural_size(), 30.0, PIXEL_FORMAT_I420); 88 VideoCaptureFormat format(frame->natural_size(), 30.0, PIXEL_FORMAT_I420);
96 frame_cb_.Run(format); 89 frame_cb_.Run(format);
97 } 90 }
98 91
99 private: 92 private:
100 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; 93 base::Callback<void(const VideoCaptureFormat&)> frame_cb_;
101 }; 94 };
102 95
(...skipping 22 matching lines...) Expand all
125 FakeVideoCaptureDeviceTest() 118 FakeVideoCaptureDeviceTest()
126 : loop_(new base::MessageLoop()), 119 : loop_(new base::MessageLoop()),
127 client_(new MockClient( 120 client_(new MockClient(
128 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, 121 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured,
129 base::Unretained(this)))), 122 base::Unretained(this)))),
130 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) { 123 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {
131 device_enumeration_listener_ = new DeviceEnumerationListener(); 124 device_enumeration_listener_ = new DeviceEnumerationListener();
132 } 125 }
133 126
134 void SetUp() override { 127 void SetUp() override {
128 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_))
129 .Times(0);
135 EXPECT_CALL(*client_, OnError(_)).Times(0); 130 EXPECT_CALL(*client_, OnError(_)).Times(0);
136 } 131 }
137 132
138 void OnFrameCaptured(const VideoCaptureFormat& format) { 133 void OnFrameCaptured(const VideoCaptureFormat& format) {
139 last_format_ = format; 134 last_format_ = format;
140 run_loop_->QuitClosure().Run(); 135 run_loop_->QuitClosure().Run();
141 } 136 }
142 137
143 void WaitForCapturedFrame() { 138 void WaitForCapturedFrame() {
144 run_loop_.reset(new base::RunLoop()); 139 run_loop_.reset(new base::RunLoop());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); 209 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420);
215 EXPECT_GE(supported_formats[2].frame_rate, 20.0); 210 EXPECT_GE(supported_formats[2].frame_rate, 20.0);
216 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); 211 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920);
217 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); 212 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080);
218 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); 213 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420);
219 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 214 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
220 } 215 }
221 } 216 }
222 217
223 }; // namespace media 218 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device_factory.cc ('k') | media/video/capture/video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698