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 // Note that this test does not exercise the class VideoCaptureBufferPool | |
| 7 // in isolation. The "unit under test" is an instance of VideoCaptureBufferPool | |
| 8 // with some context that is specific to renderer_host/media, and therefore | |
| 9 // this test must lives here and not in media/capture/video. | |
|
mcasas
2016/09/22 21:41:56
s/lives/live/
File-class comments are rare in Chr
chfremer
2016/09/22 23:41:52
Done.
| |
| 6 | 10 |
| 7 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 11 #include "media/capture/video/video_capture_buffer_pool.h" |
| 8 | 12 |
| 9 #include <stddef.h> | 13 #include <stddef.h> |
| 10 #include <stdint.h> | 14 #include <stdint.h> |
| 11 #include <string.h> | 15 #include <string.h> |
| 12 | 16 |
| 13 #include <memory> | 17 #include <memory> |
| 14 #include <utility> | 18 #include <utility> |
| 15 #include <vector> | 19 #include <vector> |
| 16 | 20 |
| 17 #include "base/bind.h" | 21 #include "base/bind.h" |
| 18 #include "base/macros.h" | 22 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
| 21 #include "base/message_loop/message_loop.h" | 25 #include "base/message_loop/message_loop.h" |
| 22 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 23 #include "cc/test/test_context_provider.h" | 27 #include "cc/test/test_context_provider.h" |
| 24 #include "cc/test/test_web_graphics_context_3d.h" | 28 #include "cc/test/test_web_graphics_context_3d.h" |
| 25 #include "components/display_compositor/buffer_queue.h" | 29 #include "components/display_compositor/buffer_queue.h" |
| 26 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 30 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 27 #include "content/browser/renderer_host/media/video_capture_buffer_handle.h" | 31 #include "content/browser/renderer_host/media/renderer_host_video_capture_buffer _tracker_factory.h" |
| 28 #include "content/browser/renderer_host/media/video_capture_controller.h" | 32 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 29 #include "media/base/video_frame.h" | 33 #include "media/base/video_frame.h" |
| 34 #include "media/capture/video/video_capture_buffer_pool_impl.h" | |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 37 |
| 33 namespace content { | 38 namespace content { |
| 34 | 39 |
| 35 struct PixelFormatAndStorage { | 40 struct PixelFormatAndStorage { |
| 36 media::VideoPixelFormat pixel_format; | 41 media::VideoPixelFormat pixel_format; |
| 37 media::VideoPixelStorage pixel_storage; | 42 media::VideoPixelStorage pixel_storage; |
| 38 }; | 43 }; |
| 39 | 44 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 gfx::BufferUsage usage, | 117 gfx::BufferUsage usage, |
| 113 gpu::SurfaceHandle surface_handle) override { | 118 gpu::SurfaceHandle surface_handle) override { |
| 114 return base::MakeUnique<MockGpuMemoryBuffer>(size); | 119 return base::MakeUnique<MockGpuMemoryBuffer>(size); |
| 115 } | 120 } |
| 116 }; | 121 }; |
| 117 #endif | 122 #endif |
| 118 | 123 |
| 119 // This is a generic Buffer tracker | 124 // This is a generic Buffer tracker |
| 120 class Buffer { | 125 class Buffer { |
| 121 public: | 126 public: |
| 122 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, | 127 Buffer(const scoped_refptr<media::VideoCaptureBufferPool> pool, |
| 123 std::unique_ptr<VideoCaptureBufferHandle> buffer_handle, | 128 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle, |
| 124 int id) | 129 int id) |
| 125 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} | 130 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} |
| 126 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 131 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 127 int id() const { return id_; } | 132 int id() const { return id_; } |
| 128 size_t mapped_size() { return buffer_handle_->mapped_size(); } | 133 size_t mapped_size() { return buffer_handle_->mapped_size(); } |
| 129 void* data() { return buffer_handle_->data(0); } | 134 void* data() { return buffer_handle_->data(0); } |
| 130 | 135 |
| 131 private: | 136 private: |
| 132 const int id_; | 137 const int id_; |
| 133 const scoped_refptr<VideoCaptureBufferPool> pool_; | 138 const scoped_refptr<media::VideoCaptureBufferPool> pool_; |
| 134 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; | 139 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_; |
| 135 }; | 140 }; |
| 136 | 141 |
| 137 VideoCaptureBufferPoolTest() | 142 VideoCaptureBufferPoolTest() |
| 138 : expected_dropped_id_(0), | 143 : expected_dropped_id_(0), |
| 139 pool_(new VideoCaptureBufferPoolImpl(kTestBufferPoolSize)) {} | 144 pool_(new media::VideoCaptureBufferPoolImpl( |
| 145 base::MakeUnique<RendererHostVideoCaptureBufferTrackerFactory>(), | |
| 146 kTestBufferPoolSize)) {} | |
| 140 | 147 |
| 141 #if !defined(OS_ANDROID) | 148 #if !defined(OS_ANDROID) |
| 142 void SetUp() override { | 149 void SetUp() override { |
| 143 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); | 150 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); |
| 144 } | 151 } |
| 145 #endif | 152 #endif |
| 146 | 153 |
| 147 void ExpectDroppedId(int expected_dropped_id) { | 154 void ExpectDroppedId(int expected_dropped_id) { |
| 148 expected_dropped_id_ = expected_dropped_id; | 155 expected_dropped_id_ = expected_dropped_id; |
| 149 } | 156 } |
| 150 | 157 |
| 151 std::unique_ptr<Buffer> ReserveBuffer( | 158 std::unique_ptr<Buffer> ReserveBuffer( |
| 152 const gfx::Size& dimensions, | 159 const gfx::Size& dimensions, |
| 153 PixelFormatAndStorage format_and_storage) { | 160 PixelFormatAndStorage format_and_storage) { |
| 154 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, | 161 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, |
| 155 // initialize it to something different than the expected value. | 162 // initialize it to something different than the expected value. |
| 156 int buffer_id_to_drop = ~expected_dropped_id_; | 163 int buffer_id_to_drop = ~expected_dropped_id_; |
| 157 DVLOG(1) << media::VideoCaptureFormat::PixelStorageToString( | 164 DVLOG(1) << media::VideoCaptureFormat::PixelStorageToString( |
| 158 format_and_storage.pixel_storage) << " " | 165 format_and_storage.pixel_storage) << " " |
| 159 << media::VideoPixelFormatToString(format_and_storage.pixel_format) | 166 << media::VideoPixelFormatToString(format_and_storage.pixel_format) |
| 160 << " " << dimensions.ToString(); | 167 << " " << dimensions.ToString(); |
| 161 const int buffer_id = pool_->ReserveForProducer( | 168 const int buffer_id = pool_->ReserveForProducer( |
| 162 dimensions, format_and_storage.pixel_format, | 169 dimensions, format_and_storage.pixel_format, |
| 163 format_and_storage.pixel_storage, &buffer_id_to_drop); | 170 format_and_storage.pixel_storage, &buffer_id_to_drop); |
| 164 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 171 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId) |
| 165 return std::unique_ptr<Buffer>(); | 172 return std::unique_ptr<Buffer>(); |
| 166 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); | 173 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); |
| 167 | 174 |
| 168 std::unique_ptr<VideoCaptureBufferHandle> buffer_handle = | 175 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle = |
| 169 pool_->GetBufferHandle(buffer_id); | 176 pool_->GetBufferHandle(buffer_id); |
| 170 return std::unique_ptr<Buffer>( | 177 return std::unique_ptr<Buffer>( |
| 171 new Buffer(pool_, std::move(buffer_handle), buffer_id)); | 178 new Buffer(pool_, std::move(buffer_handle), buffer_id)); |
| 172 } | 179 } |
| 173 | 180 |
| 174 std::unique_ptr<Buffer> ResurrectLastBuffer( | 181 std::unique_ptr<Buffer> ResurrectLastBuffer( |
| 175 const gfx::Size& dimensions, | 182 const gfx::Size& dimensions, |
| 176 PixelFormatAndStorage format_and_storage) { | 183 PixelFormatAndStorage format_and_storage) { |
| 177 const int buffer_id = pool_->ResurrectLastForProducer( | 184 const int buffer_id = pool_->ResurrectLastForProducer( |
| 178 dimensions, format_and_storage.pixel_format, | 185 dimensions, format_and_storage.pixel_format, |
| 179 format_and_storage.pixel_storage); | 186 format_and_storage.pixel_storage); |
| 180 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 187 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId) |
| 181 return std::unique_ptr<Buffer>(); | 188 return std::unique_ptr<Buffer>(); |
| 182 return std::unique_ptr<Buffer>( | 189 return std::unique_ptr<Buffer>( |
| 183 new Buffer(pool_, pool_->GetBufferHandle(buffer_id), buffer_id)); | 190 new Buffer(pool_, pool_->GetBufferHandle(buffer_id), buffer_id)); |
| 184 } | 191 } |
| 185 | 192 |
| 186 base::MessageLoop loop_; | 193 base::MessageLoop loop_; |
| 187 int expected_dropped_id_; | 194 int expected_dropped_id_; |
| 188 scoped_refptr<VideoCaptureBufferPool> pool_; | 195 scoped_refptr<media::VideoCaptureBufferPool> pool_; |
| 189 | 196 |
| 190 private: | 197 private: |
| 191 #if !defined(OS_ANDROID) | 198 #if !defined(OS_ANDROID) |
| 192 std::unique_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 199 std::unique_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 193 #endif | 200 #endif |
| 194 | 201 |
| 195 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); | 202 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); |
| 196 }; | 203 }; |
| 197 | 204 |
| 198 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { | 205 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { |
| 199 const gfx::Size size_lo = gfx::Size(10, 10); | 206 const gfx::Size size_lo = gfx::Size(10, 10); |
| 200 const gfx::Size size_hi = gfx::Size(21, 33); | 207 const gfx::Size size_hi = gfx::Size(21, 33); |
| 201 const media::VideoCaptureFormat format_lo( | 208 const media::VideoCaptureFormat format_lo( |
| 202 size_lo, 0.0, GetParam().pixel_format, GetParam().pixel_storage); | 209 size_lo, 0.0, GetParam().pixel_format, GetParam().pixel_storage); |
| 203 const media::VideoCaptureFormat format_hi( | 210 const media::VideoCaptureFormat format_hi( |
| 204 size_hi, 0.0, GetParam().pixel_format, GetParam().pixel_storage); | 211 size_hi, 0.0, GetParam().pixel_format, GetParam().pixel_storage); |
| 205 | 212 |
| 206 // Reallocation won't happen for the first part of the test. | 213 // Reallocation won't happen for the first part of the test. |
| 207 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 214 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 208 | 215 |
| 209 // The buffer pool should have zero utilization before any buffers have been | 216 // The buffer pool should have zero utilization before any buffers have been |
| 210 // reserved. | 217 // reserved. |
| 211 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization()); | 218 ASSERT_EQ(0.0, pool_->GetBufferPoolUtilization()); |
| 212 | 219 |
| 213 std::unique_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); | 220 std::unique_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); |
| 214 ASSERT_NE(nullptr, buffer1.get()); | 221 ASSERT_NE(nullptr, buffer1.get()); |
| 215 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 222 ASSERT_EQ(1.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 216 std::unique_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); | 223 std::unique_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); |
| 217 ASSERT_NE(nullptr, buffer2.get()); | 224 ASSERT_NE(nullptr, buffer2.get()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 ExpectDroppedId(buffer_id2); | 334 ExpectDroppedId(buffer_id2); |
| 328 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 335 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 329 buffer2 = ReserveBuffer(size_hi, GetParam()); | 336 buffer2 = ReserveBuffer(size_hi, GetParam()); |
| 330 ASSERT_NE(nullptr, buffer2.get()); | 337 ASSERT_NE(nullptr, buffer2.get()); |
| 331 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) | 338 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) |
| 332 ASSERT_LE(format_hi.ImageAllocationSize(), buffer2->mapped_size()); | 339 ASSERT_LE(format_hi.ImageAllocationSize(), buffer2->mapped_size()); |
| 333 ASSERT_EQ(3, buffer2->id()); | 340 ASSERT_EQ(3, buffer2->id()); |
| 334 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 341 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 335 void* const memory_pointer_hi = buffer2->data(); | 342 void* const memory_pointer_hi = buffer2->data(); |
| 336 buffer2.reset(); // Frees it. | 343 buffer2.reset(); // Frees it. |
| 337 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 344 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 338 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 345 ASSERT_EQ(2.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| 339 buffer2 = ReserveBuffer(size_lo, GetParam()); | 346 buffer2 = ReserveBuffer(size_lo, GetParam()); |
| 340 void* const memory_pointer_lo = buffer2->data(); | 347 void* const memory_pointer_lo = buffer2->data(); |
| 341 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) | 348 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) |
| 342 << "Decrease in resolution should not reallocate buffer"; | 349 << "Decrease in resolution should not reallocate buffer"; |
| 343 ASSERT_NE(nullptr, buffer2.get()); | 350 ASSERT_NE(nullptr, buffer2.get()); |
| 344 ASSERT_EQ(3, buffer2->id()); | 351 ASSERT_EQ(3, buffer2->id()); |
| 345 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) | 352 if (GetParam().pixel_storage != media::PIXEL_STORAGE_GPUMEMORYBUFFER) |
| 346 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); | 353 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->mapped_size()); |
| 347 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); | 354 ASSERT_EQ(3.0 / kTestBufferPoolSize, pool_->GetBufferPoolUtilization()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 362 buffer2.reset(); | 369 buffer2.reset(); |
| 363 | 370 |
| 364 if (buffer4->data() != nullptr) | 371 if (buffer4->data() != nullptr) |
| 365 memset(buffer4->data(), 0x77, buffer4->mapped_size()); | 372 memset(buffer4->data(), 0x77, buffer4->mapped_size()); |
| 366 buffer4.reset(); | 373 buffer4.reset(); |
| 367 } | 374 } |
| 368 | 375 |
| 369 // Tests that a previously-released buffer can be immediately resurrected under | 376 // Tests that a previously-released buffer can be immediately resurrected under |
| 370 // normal conditions. | 377 // normal conditions. |
| 371 TEST_P(VideoCaptureBufferPoolTest, ResurrectsLastBuffer) { | 378 TEST_P(VideoCaptureBufferPoolTest, ResurrectsLastBuffer) { |
| 372 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 379 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 373 | 380 |
| 374 // At the start, there should be nothing to resurrect. | 381 // At the start, there should be nothing to resurrect. |
| 375 std::unique_ptr<Buffer> resurrected = | 382 std::unique_ptr<Buffer> resurrected = |
| 376 ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 383 ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 377 ASSERT_EQ(nullptr, resurrected.get()); | 384 ASSERT_EQ(nullptr, resurrected.get()); |
| 378 | 385 |
| 379 // Reserve a 10x10 buffer and fill it with 0xab values. | 386 // Reserve a 10x10 buffer and fill it with 0xab values. |
| 380 std::unique_ptr<Buffer> original = | 387 std::unique_ptr<Buffer> original = |
| 381 ReserveBuffer(gfx::Size(10, 10), GetParam()); | 388 ReserveBuffer(gfx::Size(10, 10), GetParam()); |
| 382 ASSERT_NE(nullptr, original.get()); | 389 ASSERT_NE(nullptr, original.get()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 406 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 413 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 407 ASSERT_NE(nullptr, resurrected.get()); | 414 ASSERT_NE(nullptr, resurrected.get()); |
| 408 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); | 415 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); |
| 409 resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); | 416 resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); |
| 410 for (size_t i = 0; i < original_mapped_size; ++i) | 417 for (size_t i = 0; i < original_mapped_size; ++i) |
| 411 EXPECT_EQ(0xbc, resurrected_memory[i]) << "Mismatch at byte offset: " << i; | 418 EXPECT_EQ(0xbc, resurrected_memory[i]) << "Mismatch at byte offset: " << i; |
| 412 } | 419 } |
| 413 | 420 |
| 414 // Tests that a buffer cannot be resurrected if its properties do not match. | 421 // Tests that a buffer cannot be resurrected if its properties do not match. |
| 415 TEST_P(VideoCaptureBufferPoolTest, DoesNotResurrectIfPropertiesNotMatched) { | 422 TEST_P(VideoCaptureBufferPoolTest, DoesNotResurrectIfPropertiesNotMatched) { |
| 416 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 423 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 417 | 424 |
| 418 // Reserve a 10x10 buffer, fill it with 0xcd values, and release it. | 425 // Reserve a 10x10 buffer, fill it with 0xcd values, and release it. |
| 419 std::unique_ptr<Buffer> original = | 426 std::unique_ptr<Buffer> original = |
| 420 ReserveBuffer(gfx::Size(10, 10), GetParam()); | 427 ReserveBuffer(gfx::Size(10, 10), GetParam()); |
| 421 ASSERT_NE(nullptr, original.get()); | 428 ASSERT_NE(nullptr, original.get()); |
| 422 const size_t original_mapped_size = original->mapped_size(); | 429 const size_t original_mapped_size = original->mapped_size(); |
| 423 memset(original->data(), 0xcd, original_mapped_size); | 430 memset(original->data(), 0xcd, original_mapped_size); |
| 424 original.reset(); | 431 original.reset(); |
| 425 | 432 |
| 426 // Expect that the buffer cannot be resurrected if the dimensions do not | 433 // Expect that the buffer cannot be resurrected if the dimensions do not |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 456 ASSERT_NE(nullptr, resurrected.get()); | 463 ASSERT_NE(nullptr, resurrected.get()); |
| 457 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); | 464 ASSERT_EQ(original_mapped_size, resurrected->mapped_size()); |
| 458 uint8_t* resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); | 465 uint8_t* resurrected_memory = reinterpret_cast<uint8_t*>(resurrected->data()); |
| 459 for (size_t i = 0; i < original_mapped_size; ++i) | 466 for (size_t i = 0; i < original_mapped_size; ++i) |
| 460 EXPECT_EQ(0xcd, resurrected_memory[i]) << "Mismatch at byte offset: " << i; | 467 EXPECT_EQ(0xcd, resurrected_memory[i]) << "Mismatch at byte offset: " << i; |
| 461 } | 468 } |
| 462 | 469 |
| 463 // Tests that the buffers are managed by the pool such that the last-released | 470 // Tests that the buffers are managed by the pool such that the last-released |
| 464 // buffer is kept around as long as possible (for successful resurrection). | 471 // buffer is kept around as long as possible (for successful resurrection). |
| 465 TEST_P(VideoCaptureBufferPoolTest, AvoidsClobberingForResurrectingLastBuffer) { | 472 TEST_P(VideoCaptureBufferPoolTest, AvoidsClobberingForResurrectingLastBuffer) { |
| 466 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 473 ExpectDroppedId(media::VideoCaptureBufferPool::kInvalidId); |
| 467 | 474 |
| 468 // Reserve a 10x10 buffer, fill it with 0xde values, and release it. | 475 // Reserve a 10x10 buffer, fill it with 0xde values, and release it. |
| 469 std::unique_ptr<Buffer> original = | 476 std::unique_ptr<Buffer> original = |
| 470 ReserveBuffer(gfx::Size(10, 10), GetParam()); | 477 ReserveBuffer(gfx::Size(10, 10), GetParam()); |
| 471 ASSERT_NE(nullptr, original.get()); | 478 ASSERT_NE(nullptr, original.get()); |
| 472 const size_t original_mapped_size = original->mapped_size(); | 479 const size_t original_mapped_size = original->mapped_size(); |
| 473 memset(original->data(), 0xde, original_mapped_size); | 480 memset(original->data(), 0xde, original_mapped_size); |
| 474 original.reset(); | 481 original.reset(); |
| 475 | 482 |
| 476 // Reserve all but one of the pool's buffers. | 483 // Reserve all but one of the pool's buffers. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 496 ASSERT_NE(nullptr, held_buffers.back().get()); | 503 ASSERT_NE(nullptr, held_buffers.back().get()); |
| 497 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); | 504 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); |
| 498 ASSERT_EQ(nullptr, resurrected.get()); | 505 ASSERT_EQ(nullptr, resurrected.get()); |
| 499 } | 506 } |
| 500 | 507 |
| 501 INSTANTIATE_TEST_CASE_P(, | 508 INSTANTIATE_TEST_CASE_P(, |
| 502 VideoCaptureBufferPoolTest, | 509 VideoCaptureBufferPoolTest, |
| 503 testing::ValuesIn(kCapturePixelFormatAndStorages)); | 510 testing::ValuesIn(kCapturePixelFormatAndStorages)); |
| 504 | 511 |
| 505 } // namespace content | 512 } // namespace content |
| OLD | NEW |