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

Side by Side Diff: content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc

Issue 1204063005: Reland: Video Capture: extract storage info from pixel format in VideoCaptureFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheng@ nit on DCHECK_EQ(expected, actual) Created 5 years, 5 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 (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 // Unit test for VideoCaptureBufferPool. 5 // Unit test for VideoCaptureBufferPool.
6 6
7 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" 7 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "cc/test/test_context_provider.h" 13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_web_graphics_context_3d.h" 14 #include "cc/test/test_web_graphics_context_3d.h"
15 #include "content/browser/compositor/buffer_queue.h" 15 #include "content/browser/compositor/buffer_queue.h"
16 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 16 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
17 #include "content/browser/renderer_host/media/video_capture_controller.h" 17 #include "content/browser/renderer_host/media/video_capture_controller.h"
18 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
19 #include "media/base/video_util.h" 19 #include "media/base/video_util.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace content { 23 namespace content {
24 24
25 static const media::VideoPixelFormat kCaptureFormats[] = { 25 struct PixelFormatAndStorage {
26 media::PIXEL_FORMAT_I420, 26 media::VideoPixelFormat pixel_format;
27 media::PIXEL_FORMAT_TEXTURE, 27 media::VideoPixelStorage pixel_storage;
28 };
29
30 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = {
31 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU},
32 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU},
33 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_TEXTURE},
28 #if !defined(OS_ANDROID) 34 #if !defined(OS_ANDROID)
29 media::PIXEL_FORMAT_GPUMEMORYBUFFER 35 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_GPUMEMORYBUFFER},
36 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_GPUMEMORYBUFFER},
30 #endif 37 #endif
31 }; 38 };
32 39
33 static const int kTestBufferPoolSize = 3; 40 static const int kTestBufferPoolSize = 3;
34 41
35 class VideoCaptureBufferPoolTest 42 class VideoCaptureBufferPoolTest
36 : public testing::TestWithParam<media::VideoPixelFormat> { 43 : public testing::TestWithParam<PixelFormatAndStorage> {
37 protected: 44 protected:
38 // A GpuMemoryBuffer Mock to provide a trivial RGBA buffer as Map() backing. 45 // A GpuMemoryBuffer Mock to provide a trivial RGBA buffer as Map() backing.
39 // We need to allocate on ctor and deallocate on dtor so that consecutive 46 // We need to allocate on ctor and deallocate on dtor so that consecutive
40 // Map()-Unmap() cycles yield the same underlying data pointer. 47 // Map()-Unmap() cycles yield the same underlying data pointer.
41 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer { 48 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer {
42 public: 49 public:
43 explicit MockGpuMemoryBuffer(const gfx::Size& size) 50 explicit MockGpuMemoryBuffer(const gfx::Size& size)
44 : size_(size), data_(new uint8[size_.GetArea() * 4]), mapped_(false) {} 51 : size_(size), data_(new uint8[size_.GetArea() * 4]), mapped_(false) {}
45 ~MockGpuMemoryBuffer() override { delete[] data_; } 52 ~MockGpuMemoryBuffer() override { delete[] data_; }
46 53
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 context_provider, gpu_memory_buffer_manager_.get(), GL_RGBA)); 140 context_provider, gpu_memory_buffer_manager_.get(), GL_RGBA));
134 output_surface_->Initialize(); 141 output_surface_->Initialize();
135 } 142 }
136 #endif 143 #endif
137 144
138 void ExpectDroppedId(int expected_dropped_id) { 145 void ExpectDroppedId(int expected_dropped_id) {
139 expected_dropped_id_ = expected_dropped_id; 146 expected_dropped_id_ = expected_dropped_id;
140 } 147 }
141 148
142 scoped_ptr<Buffer> ReserveBuffer(const gfx::Size& dimensions, 149 scoped_ptr<Buffer> ReserveBuffer(const gfx::Size& dimensions,
143 media::VideoPixelFormat pixel_format) { 150 PixelFormatAndStorage format_and_storage) {
144 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, 151 // To verify that ReserveBuffer always sets |buffer_id_to_drop|,
145 // initialize it to something different than the expected value. 152 // initialize it to something different than the expected value.
146 int buffer_id_to_drop = ~expected_dropped_id_; 153 int buffer_id_to_drop = ~expected_dropped_id_;
147 DVLOG(1) << media::VideoCaptureFormat::PixelFormatToString(pixel_format) 154 DVLOG(1) << media::VideoCaptureFormat::PixelStorageToString(
148 << " " << dimensions.ToString(); 155 format_and_storage.pixel_storage) << " "
149 int buffer_id = 156 << media::VideoCaptureFormat::PixelFormatToString(
150 pool_->ReserveForProducer(pixel_format, dimensions, &buffer_id_to_drop); 157 format_and_storage.pixel_format) << " "
158 << dimensions.ToString();
159 const int buffer_id = pool_->ReserveForProducer(
160 format_and_storage.pixel_format, format_and_storage.pixel_storage,
161 dimensions, &buffer_id_to_drop);
151 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 162 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
152 return scoped_ptr<Buffer>(); 163 return scoped_ptr<Buffer>();
153 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); 164 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop);
154 165
155 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle = 166 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle =
156 pool_->GetBufferHandle(buffer_id); 167 pool_->GetBufferHandle(buffer_id);
157 return scoped_ptr<Buffer>( 168 return scoped_ptr<Buffer>(
158 new Buffer(pool_, buffer_handle.Pass(), buffer_id)); 169 new Buffer(pool_, buffer_handle.Pass(), buffer_id));
159 } 170 }
160 171
161 base::MessageLoop loop_; 172 base::MessageLoop loop_;
162 int expected_dropped_id_; 173 int expected_dropped_id_;
163 scoped_refptr<VideoCaptureBufferPool> pool_; 174 scoped_refptr<VideoCaptureBufferPool> pool_;
164 175
165 private: 176 private:
166 #if !defined(OS_ANDROID) 177 #if !defined(OS_ANDROID)
167 scoped_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; 178 scoped_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_;
168 scoped_ptr<MockBufferQueue> output_surface_; 179 scoped_ptr<MockBufferQueue> output_surface_;
169 #endif 180 #endif
170 181
171 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); 182 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest);
172 }; 183 };
173 184
174 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { 185 TEST_P(VideoCaptureBufferPoolTest, BufferPool) {
175 const gfx::Size size_lo = gfx::Size(10, 10); 186 const gfx::Size size_lo = gfx::Size(10, 10);
176 const gfx::Size size_hi = gfx::Size(21, 33); 187 const gfx::Size size_hi = gfx::Size(21, 33);
177 const media::VideoCaptureFormat format_lo(size_lo, 0.0, GetParam()); 188 const media::VideoCaptureFormat format_lo(
178 const media::VideoCaptureFormat format_hi(size_hi, 0.0, GetParam()); 189 size_lo, 0.0, GetParam().pixel_format, GetParam().pixel_storage);
190 const media::VideoCaptureFormat format_hi(
191 size_hi, 0.0, GetParam().pixel_format, GetParam().pixel_storage);
179 192
180 // Reallocation won't happen for the first part of the test. 193 // Reallocation won't happen for the first part of the test.
181 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); 194 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId);
182 195
183 // The buffer pool should have zero utilization before any buffers have been 196 // The buffer pool should have zero utilization before any buffers have been
184 // reserved. 197 // reserved.
185 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization()); 198 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization());
186 199
187 scoped_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); 200 scoped_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam());
188 ASSERT_NE(nullptr, buffer1.get()); 201 ASSERT_NE(nullptr, buffer1.get());
189 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->size()); 202 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->size());
190 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); 203 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization());
191 scoped_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); 204 scoped_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam());
192 ASSERT_NE(nullptr, buffer2.get()); 205 ASSERT_NE(nullptr, buffer2.get());
193 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->size()); 206 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->size());
194 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); 207 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization());
195 scoped_ptr<Buffer> buffer3 = ReserveBuffer(size_lo, GetParam()); 208 scoped_ptr<Buffer> buffer3 = ReserveBuffer(size_lo, GetParam());
196 ASSERT_NE(nullptr, buffer3.get()); 209 ASSERT_NE(nullptr, buffer3.get());
197 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->size()); 210 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->size());
198 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); 211 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization());
199 212
200 // Texture backed Frames cannot be manipulated via mapping. 213 // Texture backed Frames cannot be manipulated via mapping.
201 if (GetParam() != media::PIXEL_FORMAT_TEXTURE) { 214 if (GetParam().pixel_storage != media::PIXEL_STORAGE_TEXTURE) {
202 ASSERT_NE(nullptr, buffer1->data()); 215 ASSERT_NE(nullptr, buffer1->data());
203 ASSERT_NE(nullptr, buffer2->data()); 216 ASSERT_NE(nullptr, buffer2->data());
204 ASSERT_NE(nullptr, buffer3->data()); 217 ASSERT_NE(nullptr, buffer3->data());
205 218
206 } 219 }
207 // Touch the memory. 220 // Touch the memory.
208 if (buffer1->data() != nullptr) 221 if (buffer1->data() != nullptr)
209 memset(buffer1->data(), 0x11, buffer1->size()); 222 memset(buffer1->data(), 0x11, buffer1->size());
210 if (buffer2->data() != nullptr) 223 if (buffer2->data() != nullptr)
211 memset(buffer2->data(), 0x44, buffer2->size()); 224 memset(buffer2->data(), 0x44, buffer2->size());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 memset(buffer4->data(), 0x55, buffer4->size()); 345 memset(buffer4->data(), 0x55, buffer4->size());
333 buffer2.reset(); 346 buffer2.reset();
334 347
335 if (buffer4->data() != nullptr) 348 if (buffer4->data() != nullptr)
336 memset(buffer4->data(), 0x77, buffer4->size()); 349 memset(buffer4->data(), 0x77, buffer4->size());
337 buffer4.reset(); 350 buffer4.reset();
338 } 351 }
339 352
340 INSTANTIATE_TEST_CASE_P(, 353 INSTANTIATE_TEST_CASE_P(,
341 VideoCaptureBufferPoolTest, 354 VideoCaptureBufferPoolTest,
342 testing::ValuesIn(kCaptureFormats)); 355 testing::ValuesIn(kCapturePixelFormatAndStorages));
343 356
344 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698