| 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> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 gpu::SurfaceHandle surface_handle) override { | 112 gpu::SurfaceHandle surface_handle) override { |
| 113 return base::MakeUnique<MockGpuMemoryBuffer>(size); | 113 return base::MakeUnique<MockGpuMemoryBuffer>(size); |
| 114 } | 114 } |
| 115 }; | 115 }; |
| 116 #endif | 116 #endif |
| 117 | 117 |
| 118 // This is a generic Buffer tracker | 118 // This is a generic Buffer tracker |
| 119 class Buffer { | 119 class Buffer { |
| 120 public: | 120 public: |
| 121 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, | 121 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, |
| 122 std::unique_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, | 122 std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle, |
| 123 int id) | 123 int id) |
| 124 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} | 124 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} |
| 125 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 125 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 126 int id() const { return id_; } | 126 int id() const { return id_; } |
| 127 size_t mapped_size() { return buffer_handle_->mapped_size(); } | 127 size_t mapped_size() { return buffer_handle_->mapped_size(); } |
| 128 void* data() { return buffer_handle_->data(0); } | 128 void* data() { return buffer_handle_->data(0); } |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 const int id_; | 131 const int id_; |
| 132 const scoped_refptr<VideoCaptureBufferPool> pool_; | 132 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 133 const std::unique_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; | 133 const std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle_; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 VideoCaptureBufferPoolTest() | 136 VideoCaptureBufferPoolTest() |
| 137 : expected_dropped_id_(0), | 137 : expected_dropped_id_(0), |
| 138 pool_(new VideoCaptureBufferPool(kTestBufferPoolSize)) {} | 138 pool_(new VideoCaptureBufferPoolImpl(kTestBufferPoolSize)) {} |
| 139 | 139 |
| 140 #if !defined(OS_ANDROID) | 140 #if !defined(OS_ANDROID) |
| 141 void SetUp() override { | 141 void SetUp() override { |
| 142 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); | 142 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); |
| 143 } | 143 } |
| 144 #endif | 144 #endif |
| 145 | 145 |
| 146 void ExpectDroppedId(int expected_dropped_id) { | 146 void ExpectDroppedId(int expected_dropped_id) { |
| 147 expected_dropped_id_ = expected_dropped_id; | 147 expected_dropped_id_ = expected_dropped_id; |
| 148 } | 148 } |
| 149 | 149 |
| 150 std::unique_ptr<Buffer> ReserveBuffer( | 150 std::unique_ptr<Buffer> ReserveBuffer( |
| 151 const gfx::Size& dimensions, | 151 const gfx::Size& dimensions, |
| 152 PixelFormatAndStorage format_and_storage) { | 152 PixelFormatAndStorage format_and_storage) { |
| 153 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, | 153 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, |
| 154 // initialize it to something different than the expected value. | 154 // initialize it to something different than the expected value. |
| 155 int buffer_id_to_drop = ~expected_dropped_id_; | 155 int buffer_id_to_drop = ~expected_dropped_id_; |
| 156 DVLOG(1) << media::VideoCaptureFormat::PixelStorageToString( | 156 DVLOG(1) << media::VideoCaptureFormat::PixelStorageToString( |
| 157 format_and_storage.pixel_storage) << " " | 157 format_and_storage.pixel_storage) << " " |
| 158 << media::VideoPixelFormatToString(format_and_storage.pixel_format) | 158 << media::VideoPixelFormatToString(format_and_storage.pixel_format) |
| 159 << " " << dimensions.ToString(); | 159 << " " << dimensions.ToString(); |
| 160 const int buffer_id = pool_->ReserveForProducer( | 160 const int buffer_id = pool_->ReserveForProducer( |
| 161 dimensions, format_and_storage.pixel_format, | 161 dimensions, format_and_storage.pixel_format, |
| 162 format_and_storage.pixel_storage, &buffer_id_to_drop); | 162 format_and_storage.pixel_storage, &buffer_id_to_drop); |
| 163 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 163 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 164 return std::unique_ptr<Buffer>(); | 164 return std::unique_ptr<Buffer>(); |
| 165 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); | 165 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); |
| 166 | 166 |
| 167 std::unique_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle = | 167 std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle = |
| 168 pool_->GetBufferHandle(buffer_id); | 168 pool_->GetBufferHandle(buffer_id); |
| 169 return std::unique_ptr<Buffer>( | 169 return std::unique_ptr<Buffer>( |
| 170 new Buffer(pool_, std::move(buffer_handle), buffer_id)); | 170 new Buffer(pool_, std::move(buffer_handle), buffer_id)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 std::unique_ptr<Buffer> ResurrectLastBuffer( | 173 std::unique_ptr<Buffer> ResurrectLastBuffer( |
| 174 const gfx::Size& dimensions, | 174 const gfx::Size& dimensions, |
| 175 PixelFormatAndStorage format_and_storage) { | 175 PixelFormatAndStorage format_and_storage) { |
| 176 const int buffer_id = pool_->ResurrectLastForProducer( | 176 const int buffer_id = pool_->ResurrectLastForProducer( |
| 177 dimensions, format_and_storage.pixel_format, | 177 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()); | 495 ASSERT_NE(nullptr, held_buffers.back().get()); |
| 496 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 496 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 497 ASSERT_EQ(nullptr, resurrected.get()); | 497 ASSERT_EQ(nullptr, resurrected.get()); |
| 498 } | 498 } |
| 499 | 499 |
| 500 INSTANTIATE_TEST_CASE_P(, | 500 INSTANTIATE_TEST_CASE_P(, |
| 501 VideoCaptureBufferPoolTest, | 501 VideoCaptureBufferPoolTest, |
| 502 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 502 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 503 | 503 |
| 504 } // namespace content | 504 } // namespace content |
| OLD | NEW |