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

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

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

Powered by Google App Engine
This is Rietveld 408576698