| 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 "cc/test/test_context_provider.h" | |
| 13 #include "cc/test/test_web_graphics_context_3d.h" | |
| 14 #include "content/browser/compositor/buffer_queue.h" | |
| 15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | |
| 16 #include "content/browser/renderer_host/media/video_capture_controller.h" | 12 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 17 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 18 #include "media/base/video_util.h" | 14 #include "media/base/video_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 16 |
| 22 namespace content { | 17 namespace content { |
| 23 | 18 |
| 24 static const media::VideoPixelFormat kCaptureFormats[] = { | 19 class VideoCaptureBufferPoolTest : public testing::Test { |
| 25 media::PIXEL_FORMAT_I420, | |
| 26 media::PIXEL_FORMAT_TEXTURE, | |
| 27 media::PIXEL_FORMAT_GPUMEMORYBUFFER | |
| 28 }; | |
| 29 | |
| 30 class VideoCaptureBufferPoolTest | |
| 31 : public testing::TestWithParam<media::VideoPixelFormat> { | |
| 32 protected: | 20 protected: |
| 33 // A GpuMemoryBuffer Mock to provide a trivial RGBA buffer as Map() backing. | |
| 34 // We need to allocate on ctor and deallocate on dtor so that consecutive | |
| 35 // Map()-Unmap() cycles yield the same underlying data pointer. | |
| 36 class MockGpuMemoryBuffer : public gfx::GpuMemoryBuffer { | |
| 37 public: | |
| 38 explicit MockGpuMemoryBuffer(const gfx::Size& size) | |
| 39 : size_(size), data_(new uint8[size_.GetArea() * 4]), mapped_(false) {} | |
| 40 ~MockGpuMemoryBuffer() override { delete[] data_; } | |
| 41 | |
| 42 bool Map(void** data) override { | |
| 43 EXPECT_EQ(mapped_, false); | |
| 44 mapped_ = true; | |
| 45 data[0] = static_cast<void*>(data_); | |
| 46 return true; | |
| 47 } | |
| 48 void Unmap() override { | |
| 49 EXPECT_EQ(mapped_, true); | |
| 50 mapped_ = false; | |
| 51 } | |
| 52 bool IsMapped() const override { return mapped_; } | |
| 53 Format GetFormat() const override { return BGRA_8888; } | |
| 54 void GetStride(int* stride) const override { | |
| 55 *stride = size_.width() * 4; | |
| 56 return; | |
| 57 } | |
| 58 gfx::GpuMemoryBufferHandle GetHandle() const override { | |
| 59 return gfx::GpuMemoryBufferHandle(); | |
| 60 } | |
| 61 ClientBuffer AsClientBuffer() override { return nullptr; } | |
| 62 | |
| 63 private: | |
| 64 const gfx::Size size_; | |
| 65 uint8* const data_; | |
| 66 bool mapped_; | |
| 67 }; | |
| 68 | |
| 69 // The next two classes are needed to replicate the GpuMemoryBuffer allocation | |
| 70 // on Browser side. | |
| 71 class StubBrowserGpuMemoryBufferManager | |
| 72 : public BrowserGpuMemoryBufferManager { | |
| 73 public: | |
| 74 StubBrowserGpuMemoryBufferManager() | |
| 75 : BrowserGpuMemoryBufferManager(nullptr, 1) {} | |
| 76 | |
| 77 scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( | |
| 78 const gfx::Size& size, | |
| 79 gfx::GpuMemoryBuffer::Format format, | |
| 80 gfx::GpuMemoryBuffer::Usage usage) override { | |
| 81 return make_scoped_ptr(new MockGpuMemoryBuffer(size)); | |
| 82 } | |
| 83 }; | |
| 84 #if !defined(OS_ANDROID) | |
| 85 class MockBufferQueue : public BufferQueue { | |
| 86 public: | |
| 87 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider, | |
| 88 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 89 unsigned int internalformat) | |
| 90 : BufferQueue(context_provider, | |
| 91 internalformat, | |
| 92 nullptr, | |
| 93 gpu_memory_buffer_manager, | |
| 94 1) {} | |
| 95 MOCK_METHOD4(CopyBufferDamage, | |
| 96 void(int, int, const gfx::Rect&, const gfx::Rect&)); | |
| 97 }; | |
| 98 #endif | |
| 99 | |
| 100 // This is a generic Buffer tracker | |
| 101 class Buffer { | 21 class Buffer { |
| 102 public: | 22 public: |
| 103 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, | 23 Buffer(const scoped_refptr<VideoCaptureBufferPool> pool, |
| 104 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, | 24 int id, |
| 105 int id) | 25 void* data, |
| 106 : id_(id), pool_(pool), buffer_handle_(buffer_handle.Pass()) {} | 26 size_t size) |
| 27 : pool_(pool), id_(id), data_(data), size_(size) {} |
| 107 ~Buffer() { pool_->RelinquishProducerReservation(id()); } | 28 ~Buffer() { pool_->RelinquishProducerReservation(id()); } |
| 108 int id() const { return id_; } | 29 int id() const { return id_; } |
| 109 size_t size() { return buffer_handle_->size(); } | 30 void* data() const { return data_; } |
| 110 void* data() { return buffer_handle_->data(); } | 31 size_t size() const { return size_; } |
| 111 | 32 |
| 112 private: | 33 private: |
| 34 const scoped_refptr<VideoCaptureBufferPool> pool_; |
| 113 const int id_; | 35 const int id_; |
| 114 const scoped_refptr<VideoCaptureBufferPool> pool_; | 36 void* const data_; |
| 115 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; | 37 const size_t size_; |
| 116 }; | 38 }; |
| 117 | |
| 118 VideoCaptureBufferPoolTest() | 39 VideoCaptureBufferPoolTest() |
| 119 : expected_dropped_id_(0), | 40 : expected_dropped_id_(0), |
| 120 pool_(new VideoCaptureBufferPool(3)) {} | 41 pool_(new VideoCaptureBufferPool(3)) {} |
| 121 | 42 |
| 122 void SetUp() override { | |
| 123 scoped_refptr<cc::TestContextProvider> context_provider = | |
| 124 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); | |
| 125 context_provider->BindToCurrentThread(); | |
| 126 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); | |
| 127 #if !defined(OS_ANDROID) | |
| 128 output_surface_.reset(new MockBufferQueue( | |
| 129 context_provider, gpu_memory_buffer_manager_.get(), GL_RGBA)); | |
| 130 output_surface_->Initialize(); | |
| 131 #endif | |
| 132 } | |
| 133 | |
| 134 void ExpectDroppedId(int expected_dropped_id) { | 43 void ExpectDroppedId(int expected_dropped_id) { |
| 135 expected_dropped_id_ = expected_dropped_id; | 44 expected_dropped_id_ = expected_dropped_id; |
| 136 } | 45 } |
| 137 | 46 |
| 138 scoped_ptr<Buffer> ReserveBuffer(const gfx::Size& dimensions, | 47 scoped_ptr<Buffer> ReserveI420Buffer(const gfx::Size& dimensions) { |
| 139 media::VideoPixelFormat pixel_format) { | 48 // To verify that ReserveI420Buffer always sets |buffer_id_to_drop|, |
| 140 // To verify that ReserveBuffer always sets |buffer_id_to_drop|, | |
| 141 // initialize it to something different than the expected value. | 49 // initialize it to something different than the expected value. |
| 142 int buffer_id_to_drop = ~expected_dropped_id_; | 50 int buffer_id_to_drop = ~expected_dropped_id_; |
| 143 DVLOG(1) << media::VideoCaptureFormat::PixelFormatToString(pixel_format) | 51 int buffer_id = pool_->ReserveForProducer(media::PIXEL_FORMAT_I420, |
| 144 << " " << dimensions.ToString(); | 52 dimensions, &buffer_id_to_drop); |
| 145 int buffer_id = | |
| 146 pool_->ReserveForProducer(pixel_format, dimensions, &buffer_id_to_drop); | |
| 147 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 53 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 148 return scoped_ptr<Buffer>(); | 54 return scoped_ptr<Buffer>(); |
| 55 |
| 56 void* memory; |
| 57 size_t size; |
| 58 pool_->GetBufferInfo(buffer_id, &memory, &size); |
| 149 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); | 59 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); |
| 150 | 60 return scoped_ptr<Buffer>(new Buffer(pool_, buffer_id, memory, size)); |
| 151 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle = | |
| 152 pool_->GetBufferHandle(buffer_id); | |
| 153 return scoped_ptr<Buffer>( | |
| 154 new Buffer(pool_, buffer_handle.Pass(), buffer_id)); | |
| 155 } | 61 } |
| 156 | 62 |
| 157 int expected_dropped_id_; | 63 int expected_dropped_id_; |
| 158 scoped_refptr<VideoCaptureBufferPool> pool_; | 64 scoped_refptr<VideoCaptureBufferPool> pool_; |
| 159 | 65 |
| 160 private: | 66 private: |
| 161 scoped_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; | |
| 162 #if !defined(OS_ANDROID) | |
| 163 scoped_ptr<MockBufferQueue> output_surface_; | |
| 164 #endif | |
| 165 | |
| 166 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); | 67 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); |
| 167 }; | 68 }; |
| 168 | 69 |
| 169 TEST_P(VideoCaptureBufferPoolTest, BufferPool) { | 70 TEST_F(VideoCaptureBufferPoolTest, BufferPool) { |
| 170 const gfx::Size size_lo = gfx::Size(10, 10); | 71 const gfx::Size size_lo = gfx::Size(640, 480); |
| 171 const gfx::Size size_hi = gfx::Size(21, 33); | 72 const gfx::Size size_hi = gfx::Size(1024, 768); |
| 172 const media::VideoCaptureFormat format_lo(size_lo, 0.0, GetParam()); | 73 scoped_refptr<media::VideoFrame> non_pool_frame = |
| 173 const media::VideoCaptureFormat format_hi(size_hi, 0.0, GetParam()); | 74 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, size_lo, |
| 75 gfx::Rect(size_lo), size_lo, |
| 76 base::TimeDelta()); |
| 174 | 77 |
| 175 // Reallocation won't happen for the first part of the test. | 78 // Reallocation won't happen for the first part of the test. |
| 176 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 79 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); |
| 177 | 80 |
| 178 scoped_ptr<Buffer> buffer1 = ReserveBuffer(size_lo, GetParam()); | 81 scoped_ptr<Buffer> buffer1 = ReserveI420Buffer(size_lo); |
| 179 ASSERT_NE(nullptr, buffer1.get()); | 82 ASSERT_TRUE(NULL != buffer1.get()); |
| 180 ASSERT_LE(format_lo.ImageAllocationSize(), buffer1->size()); | 83 ASSERT_LE(media::VideoFrame::AllocationSize(media::VideoFrame::I420, size_lo), |
| 181 scoped_ptr<Buffer> buffer2 = ReserveBuffer(size_lo, GetParam()); | 84 buffer1->size()); |
| 182 ASSERT_NE(nullptr, buffer2.get()); | 85 scoped_ptr<Buffer> buffer2 = ReserveI420Buffer(size_lo); |
| 183 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->size()); | 86 ASSERT_TRUE(NULL != buffer2.get()); |
| 184 scoped_ptr<Buffer> buffer3 = ReserveBuffer(size_lo, GetParam()); | 87 ASSERT_LE(media::VideoFrame::AllocationSize(media::VideoFrame::I420, size_lo), |
| 185 ASSERT_NE(nullptr, buffer3.get()); | 88 buffer2->size()); |
| 186 ASSERT_LE(format_lo.ImageAllocationSize(), buffer3->size()); | 89 scoped_ptr<Buffer> buffer3 = ReserveI420Buffer(size_lo); |
| 90 ASSERT_TRUE(NULL != buffer3.get()); |
| 91 ASSERT_LE(media::VideoFrame::AllocationSize(media::VideoFrame::I420, size_lo), |
| 92 buffer3->size()); |
| 187 | 93 |
| 188 // Texture backed Frames cannot be manipulated via mapping. | |
| 189 if (GetParam() != media::PIXEL_FORMAT_TEXTURE) { | |
| 190 ASSERT_NE(nullptr, buffer1->data()); | |
| 191 ASSERT_NE(nullptr, buffer2->data()); | |
| 192 ASSERT_NE(nullptr, buffer3->data()); | |
| 193 | |
| 194 } | |
| 195 // Touch the memory. | 94 // Touch the memory. |
| 196 if (buffer1->data() != nullptr) | 95 memset(buffer1->data(), 0x11, buffer1->size()); |
| 197 memset(buffer1->data(), 0x11, buffer1->size()); | 96 memset(buffer2->data(), 0x44, buffer2->size()); |
| 198 if (buffer2->data() != nullptr) | 97 memset(buffer3->data(), 0x77, buffer3->size()); |
| 199 memset(buffer2->data(), 0x44, buffer2->size()); | |
| 200 if (buffer3->data() != nullptr) | |
| 201 memset(buffer3->data(), 0x77, buffer3->size()); | |
| 202 | 98 |
| 203 // Fourth buffer should fail. | 99 // Fourth buffer should fail. |
| 204 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 100 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 205 | 101 |
| 206 // Release 1st buffer and retry; this should succeed. | 102 // Release 1st buffer and retry; this should succeed. |
| 207 buffer1.reset(); | 103 buffer1.reset(); |
| 208 scoped_ptr<Buffer> buffer4 = ReserveBuffer(size_lo, GetParam()); | 104 scoped_ptr<Buffer> buffer4 = ReserveI420Buffer(size_lo); |
| 209 ASSERT_NE(nullptr, buffer4.get()); | 105 ASSERT_TRUE(NULL != buffer4.get()); |
| 210 | 106 |
| 211 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 107 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 212 ASSERT_FALSE(ReserveBuffer(size_hi, GetParam())) << "Pool should be empty"; | 108 ASSERT_FALSE(ReserveI420Buffer(size_hi)) << "Pool should be empty"; |
| 213 | 109 |
| 214 // Validate the IDs | 110 // Validate the IDs |
| 215 int buffer_id2 = buffer2->id(); | 111 int buffer_id2 = buffer2->id(); |
| 216 ASSERT_EQ(1, buffer_id2); | 112 ASSERT_EQ(1, buffer_id2); |
| 217 const int buffer_id3 = buffer3->id(); | 113 int buffer_id3 = buffer3->id(); |
| 218 ASSERT_EQ(2, buffer_id3); | 114 ASSERT_EQ(2, buffer_id3); |
| 219 const int buffer_id4 = buffer4->id(); | 115 void* const memory_pointer3 = buffer3->data(); |
| 116 int buffer_id4 = buffer4->id(); |
| 220 ASSERT_EQ(0, buffer_id4); | 117 ASSERT_EQ(0, buffer_id4); |
| 221 void* const memory_pointer3 = buffer3->data(); | |
| 222 | 118 |
| 223 // Deliver a buffer. | 119 // Deliver a buffer. |
| 224 pool_->HoldForConsumers(buffer_id3, 2); | 120 pool_->HoldForConsumers(buffer_id3, 2); |
| 225 | 121 |
| 226 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 122 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 227 | 123 |
| 228 buffer3.reset(); // Old producer releases buffer. Should be a noop. | 124 buffer3.reset(); // Old producer releases buffer. Should be a noop. |
| 229 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 125 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 230 ASSERT_FALSE(ReserveBuffer(size_hi, GetParam())) << "Pool should be empty"; | 126 ASSERT_FALSE(ReserveI420Buffer(size_hi)) << "Pool should be empty"; |
| 231 | 127 |
| 232 buffer2.reset(); // Active producer releases buffer. Should free a buffer. | 128 buffer2.reset(); // Active producer releases buffer. Should free a buffer. |
| 233 | 129 |
| 234 buffer1 = ReserveBuffer(size_lo, GetParam()); | 130 buffer1 = ReserveI420Buffer(size_lo); |
| 235 ASSERT_NE(nullptr, buffer1.get()); | 131 ASSERT_TRUE(NULL != buffer1.get()); |
| 236 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 132 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 237 | 133 |
| 238 // First consumer finishes. | 134 // First consumer finishes. |
| 239 pool_->RelinquishConsumerHold(buffer_id3, 1); | 135 pool_->RelinquishConsumerHold(buffer_id3, 1); |
| 240 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 136 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 241 | 137 |
| 242 // Second consumer finishes. This should free that buffer. | 138 // Second consumer finishes. This should free that buffer. |
| 243 pool_->RelinquishConsumerHold(buffer_id3, 1); | 139 pool_->RelinquishConsumerHold(buffer_id3, 1); |
| 244 buffer3 = ReserveBuffer(size_lo, GetParam()); | 140 buffer3 = ReserveI420Buffer(size_lo); |
| 245 ASSERT_NE(nullptr, buffer3.get()); | 141 ASSERT_TRUE(NULL != buffer3.get()); |
| 246 ASSERT_EQ(buffer_id3, buffer3->id()) << "Buffer ID should be reused."; | 142 ASSERT_EQ(buffer_id3, buffer3->id()) << "Buffer ID should be reused."; |
| 247 ASSERT_EQ(memory_pointer3, buffer3->data()); | 143 ASSERT_EQ(memory_pointer3, buffer3->data()); |
| 248 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 144 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 249 | 145 |
| 250 // Now deliver & consume buffer1, but don't release the buffer. | 146 // Now deliver & consume buffer1, but don't release the buffer. |
| 251 int buffer_id1 = buffer1->id(); | 147 int buffer_id1 = buffer1->id(); |
| 252 ASSERT_EQ(1, buffer_id1); | 148 ASSERT_EQ(1, buffer_id1); |
| 253 pool_->HoldForConsumers(buffer_id1, 5); | 149 pool_->HoldForConsumers(buffer_id1, 5); |
| 254 pool_->RelinquishConsumerHold(buffer_id1, 5); | 150 pool_->RelinquishConsumerHold(buffer_id1, 5); |
| 255 | 151 |
| 256 // Even though the consumer is done with the buffer at |buffer_id1|, it cannot | 152 // Even though the consumer is done with the buffer at |buffer_id1|, it cannot |
| 257 // be re-allocated to the producer, because |buffer1| still references it. But | 153 // be re-allocated to the producer, because |buffer1| still references it. But |
| 258 // when |buffer1| goes away, we should be able to re-reserve the buffer (and | 154 // when |buffer1| goes away, we should be able to re-reserve the buffer (and |
| 259 // the ID ought to be the same). | 155 // the ID ought to be the same). |
| 260 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 156 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 261 buffer1.reset(); // Should free the buffer. | 157 buffer1.reset(); // Should free the buffer. |
| 262 buffer2 = ReserveBuffer(size_lo, GetParam()); | 158 buffer2 = ReserveI420Buffer(size_lo); |
| 263 ASSERT_NE(nullptr, buffer2.get()); | 159 ASSERT_TRUE(NULL != buffer2.get()); |
| 264 ASSERT_EQ(buffer_id1, buffer2->id()); | 160 ASSERT_EQ(buffer_id1, buffer2->id()); |
| 265 buffer_id2 = buffer_id1; | 161 buffer_id2 = buffer_id1; |
| 266 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 162 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 267 | 163 |
| 268 // Now try reallocation with different resolutions. We expect reallocation | 164 // Now try reallocation with different resolutions. We expect reallocation |
| 269 // to occur only when the old buffer is too small. | 165 // to occur only when the old buffer is too small. |
| 270 buffer2.reset(); | 166 buffer2.reset(); |
| 271 ExpectDroppedId(buffer_id2); | 167 ExpectDroppedId(buffer_id2); |
| 272 buffer2 = ReserveBuffer(size_hi, GetParam()); | 168 buffer2 = ReserveI420Buffer(size_hi); |
| 273 ASSERT_NE(nullptr, buffer2.get()); | 169 ASSERT_TRUE(NULL != buffer2.get()); |
| 274 ASSERT_LE(format_hi.ImageAllocationSize(), buffer2->size()); | 170 ASSERT_LE(media::VideoFrame::AllocationSize(media::VideoFrame::I420, size_hi), |
| 171 buffer2->size()); |
| 275 ASSERT_EQ(3, buffer2->id()); | 172 ASSERT_EQ(3, buffer2->id()); |
| 276 void* const memory_pointer_hi = buffer2->data(); | 173 void* const memory_pointer_hi = buffer2->data(); |
| 277 buffer2.reset(); // Frees it. | 174 buffer2.reset(); // Frees it. |
| 278 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); | 175 ExpectDroppedId(VideoCaptureBufferPool::kInvalidId); |
| 279 buffer2 = ReserveBuffer(size_lo, GetParam()); | 176 buffer2 = ReserveI420Buffer(size_lo); |
| 280 void* const memory_pointer_lo = buffer2->data(); | 177 void* const memory_pointer_lo = buffer2->data(); |
| 281 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) | 178 ASSERT_EQ(memory_pointer_hi, memory_pointer_lo) |
| 282 << "Decrease in resolution should not reallocate buffer"; | 179 << "Decrease in resolution should not reallocate buffer"; |
| 283 ASSERT_NE(nullptr, buffer2.get()); | 180 ASSERT_TRUE(NULL != buffer2.get()); |
| 284 ASSERT_EQ(3, buffer2->id()); | 181 ASSERT_EQ(3, buffer2->id()); |
| 285 ASSERT_LE(format_lo.ImageAllocationSize(), buffer2->size()); | 182 ASSERT_LE(media::VideoFrame::AllocationSize(media::VideoFrame::I420, size_lo), |
| 286 ASSERT_FALSE(ReserveBuffer(size_lo, GetParam())) << "Pool should be empty"; | 183 buffer2->size()); |
| 184 ASSERT_FALSE(ReserveI420Buffer(size_lo)) << "Pool should be empty"; |
| 287 | 185 |
| 288 // Tear down the pool_, writing into the buffers. The buffer should preserve | 186 // Tear down the pool_, writing into the buffers. The buffer should preserve |
| 289 // the lifetime of the underlying memory. | 187 // the lifetime of the underlying memory. |
| 290 buffer3.reset(); | 188 buffer3.reset(); |
| 291 pool_ = NULL; | 189 pool_ = NULL; |
| 292 | 190 |
| 293 // Touch the memory. | 191 // Touch the memory. |
| 294 if (buffer2->data() != nullptr) | 192 memset(buffer2->data(), 0x22, buffer2->size()); |
| 295 memset(buffer2->data(), 0x22, buffer2->size()); | 193 memset(buffer4->data(), 0x55, buffer4->size()); |
| 296 if (buffer4->data() != nullptr) | 194 |
| 297 memset(buffer4->data(), 0x55, buffer4->size()); | |
| 298 buffer2.reset(); | 195 buffer2.reset(); |
| 299 | 196 |
| 300 if (buffer4->data() != nullptr) | 197 memset(buffer4->data(), 0x77, buffer4->size()); |
| 301 memset(buffer4->data(), 0x77, buffer4->size()); | |
| 302 buffer4.reset(); | 198 buffer4.reset(); |
| 303 } | 199 } |
| 304 | 200 |
| 305 INSTANTIATE_TEST_CASE_P(, | |
| 306 VideoCaptureBufferPoolTest, | |
| 307 testing::ValuesIn(kCaptureFormats)); | |
| 308 | |
| 309 } // namespace content | 201 } // namespace content |
| OLD | NEW |