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 // 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" |
|
mcasas
2015/11/13 19:13:57
Probably remove these two includes.
miu
2015/11/14 03:43:47
They seem to be used for testing GMBs (see lines 1
| |
| 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" |
|
mcasas
2015/11/13 19:13:57
Probably unused too.
miu
2015/11/14 03:43:47
Done.
| |
| 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 struct PixelFormatAndStorage { |
| 26 media::VideoPixelFormat pixel_format; | 26 media::VideoPixelFormat pixel_format; |
| 27 media::VideoPixelStorage pixel_storage; | 27 media::VideoPixelStorage pixel_storage; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { | 30 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { |
| 31 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, | 31 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, |
| 32 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, | 32 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, |
|
mcasas
2015/11/13 19:13:57
At the level of VCBP, CPU storage should support
miu
2015/11/14 03:43:47
Good questions. A few points:
1. There's nothing
| |
| 33 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_TEXTURE}, | |
| 34 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
| 35 {media::PIXEL_FORMAT_I420, | 34 {media::PIXEL_FORMAT_I420, |
| 36 media::PIXEL_STORAGE_GPUMEMORYBUFFER}, | 35 media::PIXEL_STORAGE_GPUMEMORYBUFFER}, |
| 37 #endif | 36 #endif |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 static const int kTestBufferPoolSize = 3; | 39 static const int kTestBufferPoolSize = 3; |
| 41 | 40 |
| 42 class VideoCaptureBufferPoolTest | 41 class VideoCaptureBufferPoolTest |
| 43 : public testing::TestWithParam<PixelFormatAndStorage> { | 42 : public testing::TestWithParam<PixelFormatAndStorage> { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ASSERT_NE(nullptr, buffer3.get()); | 217 ASSERT_NE(nullptr, buffer3.get()); |
| 219 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 218 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 220 | 219 |
| 221 // GMB backed frames have their platform and format specific allocations. | 220 // GMB backed frames have their platform and format specific allocations. |
| 222 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) { | 221 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) { |
| 223 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); | 222 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); |
| 224 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); | 223 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); |
| 225 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); | 224 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); |
| 226 } | 225 } |
| 227 | 226 |
| 228 // Texture backed Frames cannot be manipulated via mapping. | 227 ASSERT_NE(nullptr, buffer1->data()); |
| 229 if (GetParam().pixel_storage != media::PIXEL_STORAGE_TEXTURE) { | 228 ASSERT_NE(nullptr, buffer2->data()); |
| 230 ASSERT_NE(nullptr, buffer1->data()); | 229 ASSERT_NE(nullptr, buffer3->data()); |
| 231 ASSERT_NE(nullptr, buffer2->data()); | 230 |
| 232 ASSERT_NE(nullptr, buffer3->data()); | |
| 233 } | |
| 234 // Touch the memory. | 231 // Touch the memory. |
| 235 if (buffer1->data() != nullptr) | 232 if (buffer1->data() != nullptr) |
| 236 memset(buffer1->data(), 0x11, buffer1->mapped_size()); | 233 memset(buffer1->data(), 0x11, buffer1->mapped_size()); |
| 237 if (buffer2->data() != nullptr) | 234 if (buffer2->data() != nullptr) |
| 238 memset(buffer2->data(), 0x44, buffer2->mapped_size()); | 235 memset(buffer2->data(), 0x44, buffer2->mapped_size()); |
| 239 if (buffer3->data() != nullptr) | 236 if (buffer3->data() != nullptr) |
| 240 memset(buffer3->data(), 0x77, buffer3->mapped_size()); | 237 memset(buffer3->data(), 0x77, buffer3->mapped_size()); |
| 241 | 238 |
| 242 // Fourth buffer should fail. Buffer pool utilization should be at 100%. | 239 // Fourth buffer should fail. Buffer pool utilization should be at 100%. |
| 243 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 240 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 if (buffer4->data() != nullptr) | 361 if (buffer4->data() != nullptr) |
| 365 memset(buffer4->data(), 0x77, buffer4->mapped_size()); | 362 memset(buffer4->data(), 0x77, buffer4->mapped_size()); |
| 366 buffer4.reset(); | 363 buffer4.reset(); |
| 367 } | 364 } |
| 368 | 365 |
| 369 INSTANTIATE_TEST_CASE_P(, | 366 INSTANTIATE_TEST_CASE_P(, |
| 370 VideoCaptureBufferPoolTest, | 367 VideoCaptureBufferPoolTest, |
| 371 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 368 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 372 | 369 |
| 373 } // namespace content | 370 } // namespace content |
| OLD | NEW |