| 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "cc/test/test_context_provider.h" | 23 #include "cc/test/test_context_provider.h" |
| 24 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
| 25 #include "components/display_compositor/buffer_queue.h" | 25 #include "components/display_compositor/buffer_queue.h" |
| 26 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 26 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 27 #include "content/browser/renderer_host/media/video_capture_buffer_handle.h" |
| 27 #include "content/browser/renderer_host/media/video_capture_controller.h" | 28 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 28 #include "media/base/video_frame.h" | 29 #include "media/base/video_frame.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 struct PixelFormatAndStorage { | 35 struct PixelFormatAndStorage { |
| 35 media::VideoPixelFormat pixel_format; | 36 media::VideoPixelFormat pixel_format; |
| 36 media::VideoPixelStorage pixel_storage; | 37 media::VideoPixelStorage pixel_storage; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 gpu::SurfaceHandle surface_handle) override { | 113 gpu::SurfaceHandle surface_handle) override { |
| 113 return base::MakeUnique<MockGpuMemoryBuffer>(size); | 114 return base::MakeUnique<MockGpuMemoryBuffer>(size); |
| 114 } | 115 } |
| 115 }; | 116 }; |
| 116 #endif | 117 #endif |
| 117 | 118 |
| 118 // This is a generic Buffer tracker | 119 // This is a generic Buffer tracker |
| 119 class Buffer { | 120 class Buffer { |
| 120 public: | 121 public: |
| 121 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, | 122 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, |
| 122 std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle, | 123 std::unique_ptr<VideoCaptureBufferHandle> buffer_handle, |
| 123 int id) | 124 int id) |
| 124 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} | 125 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} |
| 125 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 126 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 126 int id() const { return id_; } | 127 int id() const { return id_; } |
| 127 size_t mapped_size() { return buffer_handle_->mapped_size(); } | 128 size_t mapped_size() { return buffer_handle_->mapped_size(); } |
| 128 void* data() { return buffer_handle_->data(0); } | 129 void* data() { return buffer_handle_->data(0); } |
| 129 | 130 |
| 130 private: | 131 private: |
| 131 const int id_; | 132 const int id_; |
| 132 const scoped_refptr<VideoCaptureBufferPool> pool_; | 133 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 133 const std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle_; | 134 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; |
| 134 }; | 135 }; |
| 135 | 136 |
| 136 VideoCaptureBufferPoolTest() | 137 VideoCaptureBufferPoolTest() |
| 137 : expected_dropped_id_(0), | 138 : expected_dropped_id_(0), |
| 138 pool_(new VideoCaptureBufferPoolImpl(kTestBufferPoolSize)) {} | 139 pool_(new VideoCaptureBufferPoolImpl(kTestBufferPoolSize)) {} |
| 139 | 140 |
| 140 #if !defined(OS_ANDROID) | 141 #if !defined(OS_ANDROID) |
| 141 void SetUp() override { | 142 void SetUp() override { |
| 142 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); | 143 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); |
| 143 } | 144 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 format_and_storage.pixel_storage) << " " | 158 format_and_storage.pixel_storage) << " " |
| 158 << media::VideoPixelFormatToString(format_and_storage.pixel_format) | 159 << media::VideoPixelFormatToString(format_and_storage.pixel_format) |
| 159 << " " << dimensions.ToString(); | 160 << " " << dimensions.ToString(); |
| 160 const int buffer_id = pool_->ReserveForProducer( | 161 const int buffer_id = pool_->ReserveForProducer( |
| 161 dimensions, format_and_storage.pixel_format, | 162 dimensions, format_and_storage.pixel_format, |
| 162 format_and_storage.pixel_storage, &buffer_id_to_drop); | 163 format_and_storage.pixel_storage, &buffer_id_to_drop); |
| 163 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 164 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 164 return std::unique_ptr<Buffer>(); | 165 return std::unique_ptr<Buffer>(); |
| 165 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); | 166 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); |
| 166 | 167 |
| 167 std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle = | 168 std::unique_ptr<VideoCaptureBufferHandle> buffer_handle = |
| 168 pool_->GetBufferHandle(buffer_id); | 169 pool_->GetBufferHandle(buffer_id); |
| 169 return std::unique_ptr<Buffer>( | 170 return std::unique_ptr<Buffer>( |
| 170 new Buffer(pool_, std::move(buffer_handle), buffer_id)); | 171 new Buffer(pool_, std::move(buffer_handle), buffer_id)); |
| 171 } | 172 } |
| 172 | 173 |
| 173 std::unique_ptr<Buffer> ResurrectLastBuffer( | 174 std::unique_ptr<Buffer> ResurrectLastBuffer( |
| 174 const gfx::Size& dimensions, | 175 const gfx::Size& dimensions, |
| 175 PixelFormatAndStorage format_and_storage) { | 176 PixelFormatAndStorage format_and_storage) { |
| 176 const int buffer_id = pool_->ResurrectLastForProducer( | 177 const int buffer_id = pool_->ResurrectLastForProducer( |
| 177 dimensions, format_and_storage.pixel_format, | 178 dimensions, format_and_storage.pixel_format, |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 ASSERT_NE(nullptr, held_buffers.back().get()); | 496 ASSERT_NE(nullptr, held_buffers.back().get()); |
| 496 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 497 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 497 ASSERT_EQ(nullptr, resurrected.get()); | 498 ASSERT_EQ(nullptr, resurrected.get()); |
| 498 } | 499 } |
| 499 | 500 |
| 500 INSTANTIATE_TEST_CASE_P(, | 501 INSTANTIATE_TEST_CASE_P(, |
| 501 VideoCaptureBufferPoolTest, | 502 VideoCaptureBufferPoolTest, |
| 502 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 503 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 503 | 504 |
| 504 } // namespace content | 505 } // namespace content |
| OLD | NEW |