| 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" |
| 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" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 | 23 |
| 25 struct PixelFormatAndStorage { | 24 struct PixelFormatAndStorage { |
| 26 media::VideoPixelFormat pixel_format; | 25 media::VideoPixelFormat pixel_format; |
| 27 media::VideoPixelStorage pixel_storage; | 26 media::VideoPixelStorage pixel_storage; |
| 28 }; | 27 }; |
| 29 | 28 |
| 30 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { | 29 static const PixelFormatAndStorage kCapturePixelFormatAndStorages[] = { |
| 31 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, | 30 {media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU}, |
| 32 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, | 31 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_CPU}, |
| 33 {media::PIXEL_FORMAT_ARGB, media::PIXEL_STORAGE_TEXTURE}, | |
| 34 #if !defined(OS_ANDROID) | 32 #if !defined(OS_ANDROID) |
| 35 {media::PIXEL_FORMAT_I420, | 33 {media::PIXEL_FORMAT_I420, |
| 36 media::PIXEL_STORAGE_GPUMEMORYBUFFER}, | 34 media::PIXEL_STORAGE_GPUMEMORYBUFFER}, |
| 37 #endif | 35 #endif |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 static const int kTestBufferPoolSize = 3; | 38 static const int kTestBufferPoolSize = 3; |
| 41 | 39 |
| 42 class VideoCaptureBufferPoolTest | 40 class VideoCaptureBufferPoolTest |
| 43 : public testing::TestWithParam<PixelFormatAndStorage> { | 41 : public testing::TestWithParam<PixelFormatAndStorage> { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT_NE(nullptr, buffer3.get()); | 216 ASSERT_NE(nullptr, buffer3.get()); |
| 219 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 217 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 220 | 218 |
| 221 // GMB backed frames have their platform and format specific allocations. | 219 // GMB backed frames have their platform and format specific allocations. |
| 222 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) { | 220 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) { |
| 223 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); | 221 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->mapped_size()); |
| 224 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); | 222 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); |
| 225 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); | 223 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->mapped_size()); |
| 226 } | 224 } |
| 227 | 225 |
| 228 // Texture backed Frames cannot be manipulated via mapping. | 226 ASSERT_NE(nullptr, buffer1->data()); |
| 229 if (GetParam().pixel_storage != media::PIXEL_STORAGE_TEXTURE) { | 227 ASSERT_NE(nullptr, buffer2->data()); |
| 230 ASSERT_NE(nullptr, buffer1->data()); | 228 ASSERT_NE(nullptr, buffer3->data()); |
| 231 ASSERT_NE(nullptr, buffer2->data()); | 229 |
| 232 ASSERT_NE(nullptr, buffer3->data()); | |
| 233 } | |
| 234 // Touch the memory. | 230 // Touch the memory. |
| 235 if (buffer1->data() != nullptr) | 231 if (buffer1->data() != nullptr) |
| 236 memset(buffer1->data(), 0x11, buffer1->mapped_size()); | 232 memset(buffer1->data(), 0x11, buffer1->mapped_size()); |
| 237 if (buffer2->data() != nullptr) | 233 if (buffer2->data() != nullptr) |
| 238 memset(buffer2->data(), 0x44, buffer2->mapped_size()); | 234 memset(buffer2->data(), 0x44, buffer2->mapped_size()); |
| 239 if (buffer3->data() != nullptr) | 235 if (buffer3->data() != nullptr) |
| 240 memset(buffer3->data(), 0x77, buffer3->mapped_size()); | 236 memset(buffer3->data(), 0x77, buffer3->mapped_size()); |
| 241 | 237 |
| 242 // Fourth buffer should fail. Buffer pool utilization should be at 100%. | 238 // Fourth buffer should fail. Buffer pool utilization should be at 100%. |
| 243 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 239 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) | 360 if (buffer4->data() != nullptr) |
| 365 memset(buffer4->data(), 0x77, buffer4->mapped_size()); | 361 memset(buffer4->data(), 0x77, buffer4->mapped_size()); |
| 366 buffer4.reset(); | 362 buffer4.reset(); |
| 367 } | 363 } |
| 368 | 364 |
| 369 INSTANTIATE_TEST_CASE_P(, | 365 INSTANTIATE_TEST_CASE_P(, |
| 370 VideoCaptureBufferPoolTest, | 366 VideoCaptureBufferPoolTest, |
| 371 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 367 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 372 | 368 |
| 373 } // namespace content | 369 } // namespace content |
| OLD | NEW |