| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "media/base/video_frame_pool.h" | 5 #include "media/base/video_frame_pool.h" |
| 6 #include "testing/gmock/include/gmock/gmock.h" | 6 #include "testing/gmock/include/gmock/gmock.h" |
| 7 | 7 |
| 8 namespace media { | 8 namespace media { |
| 9 | 9 |
| 10 class VideoFramePoolTest : public ::testing::Test { | 10 class VideoFramePoolTest : public ::testing::Test { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 void CheckPoolSize(size_t size) const { | 34 void CheckPoolSize(size_t size) const { |
| 35 EXPECT_EQ(size, pool_->GetPoolSizeForTesting()); | 35 EXPECT_EQ(size, pool_->GetPoolSizeForTesting()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 scoped_ptr<VideoFramePool> pool_; | 39 scoped_ptr<VideoFramePool> pool_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 TEST_F(VideoFramePoolTest, FrameInitializedAndZeroed) { |
| 43 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10); |
| 44 |
| 45 // Verify that frame is initialized with zeros. |
| 46 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) |
| 47 EXPECT_EQ(0, frame->data(i)[0]); |
| 48 } |
| 49 |
| 42 TEST_F(VideoFramePoolTest, SimpleFrameReuse) { | 50 TEST_F(VideoFramePoolTest, SimpleFrameReuse) { |
| 43 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10); | 51 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10); |
| 44 const uint8* old_y_data = frame->data(VideoFrame::kYPlane); | 52 const uint8* old_y_data = frame->data(VideoFrame::kYPlane); |
| 45 | 53 |
| 46 // Clear frame reference to return the frame to the pool. | 54 // Clear frame reference to return the frame to the pool. |
| 47 frame = NULL; | 55 frame = NULL; |
| 48 | 56 |
| 49 // Verify that the next frame from the pool uses the same memory. | 57 // Verify that the next frame from the pool uses the same memory. |
| 50 scoped_refptr<VideoFrame> new_frame = CreateFrame(PIXEL_FORMAT_YV12, 20); | 58 scoped_refptr<VideoFrame> new_frame = CreateFrame(PIXEL_FORMAT_YV12, 20); |
| 51 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane)); | 59 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 // Destroy the pool. | 82 // Destroy the pool. |
| 75 pool_.reset(); | 83 pool_.reset(); |
| 76 | 84 |
| 77 // Write to the Y plane. The memory tools should detect a | 85 // Write to the Y plane. The memory tools should detect a |
| 78 // use-after-free if the storage was actually removed by pool destruction. | 86 // use-after-free if the storage was actually removed by pool destruction. |
| 79 memset(frame->data(VideoFrame::kYPlane), 0xff, | 87 memset(frame->data(VideoFrame::kYPlane), 0xff, |
| 80 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane)); | 88 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane)); |
| 81 } | 89 } |
| 82 | 90 |
| 83 } // namespace media | 91 } // namespace media |
| OLD | NEW |