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 { |
11 public: | 11 public: |
12 VideoFramePoolTest() : pool_(new VideoFramePool()) {} | 12 VideoFramePoolTest() : pool_(new VideoFramePool()) {} |
13 | 13 |
14 | |
tommi (sloooow) - chröme
2014/03/05 16:17:37
nit: one empty line should be enough
perkj_chrome
2014/03/05 16:39:49
Done.
| |
14 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, | 15 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, |
15 int timestamp_ms) { | 16 int timestamp_ms) { |
16 gfx::Size coded_size(320,240); | 17 gfx::Size coded_size(320,240); |
17 gfx::Rect visible_rect(coded_size); | 18 gfx::Rect visible_rect(coded_size); |
19 | |
20 return CreateFrame(format, coded_size, visible_rect, timestamp_ms); | |
21 } | |
22 | |
23 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, | |
24 const gfx::Size& coded_size, | |
25 const gfx::Rect& visible_rect, | |
26 int timestamp_ms) { | |
18 gfx::Size natural_size(coded_size); | 27 gfx::Size natural_size(coded_size); |
19 | |
20 scoped_refptr<VideoFrame> frame = | 28 scoped_refptr<VideoFrame> frame = |
21 pool_->CreateFrame( | 29 pool_->CreateFrame( |
22 format, coded_size, visible_rect, natural_size, | 30 format, coded_size, visible_rect, natural_size, |
23 base::TimeDelta::FromMilliseconds(timestamp_ms)); | 31 base::TimeDelta::FromMilliseconds(timestamp_ms)); |
24 EXPECT_EQ(format, frame->format()); | 32 EXPECT_EQ(format, frame->format()); |
25 EXPECT_EQ(base::TimeDelta::FromMilliseconds(timestamp_ms), | 33 EXPECT_EQ(base::TimeDelta::FromMilliseconds(timestamp_ms), |
26 frame->GetTimestamp()); | 34 frame->GetTimestamp()); |
27 EXPECT_EQ(coded_size, frame->coded_size()); | 35 EXPECT_EQ(coded_size, frame->coded_size()); |
28 EXPECT_EQ(visible_rect, frame->visible_rect()); | 36 EXPECT_EQ(visible_rect, frame->visible_rect()); |
29 EXPECT_EQ(natural_size, frame->natural_size()); | 37 EXPECT_EQ(natural_size, frame->natural_size()); |
(...skipping 14 matching lines...) Expand all Loading... | |
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(VideoFrame::YV12, 20); | 58 scoped_refptr<VideoFrame> new_frame = CreateFrame(VideoFrame::YV12, 20); |
51 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane)); | 59 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane)); |
52 } | 60 } |
53 | 61 |
62 TEST_F(VideoFramePoolTest, FrameReuseWithDifferentVisibleRect) { | |
63 scoped_refptr<VideoFrame> frame = CreateFrame(VideoFrame::YV12, 10); | |
64 const uint8* old_y_data = frame->data(VideoFrame::kYPlane); | |
65 const gfx::Size coded_size = frame->coded_size(); | |
66 | |
67 // Clear frame reference to return the frame to the pool. | |
68 frame = NULL; | |
69 | |
70 // Verify that the next frame from the pool uses the same memory even if the | |
71 // visible rect has changed. | |
72 gfx::Rect visible_rect(5, 5, coded_size.width() - 10, | |
73 coded_size.height() - 10); | |
74 scoped_refptr<VideoFrame> new_frame = CreateFrame( | |
75 VideoFrame::YV12, coded_size, visible_rect, 20); | |
76 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane)); | |
Ami GONE FROM CHROMIUM
2014/03/05 16:23:42
EXPECT_EQ(new_frame->visible_rect(), visible_rect)
perkj_chrome
2014/03/05 16:39:49
That is done in CreateFrame for all calls to Creat
| |
77 } | |
78 | |
54 TEST_F(VideoFramePoolTest, SimpleFormatChange) { | 79 TEST_F(VideoFramePoolTest, SimpleFormatChange) { |
55 scoped_refptr<VideoFrame> frame_a = CreateFrame(VideoFrame::YV12, 10); | 80 scoped_refptr<VideoFrame> frame_a = CreateFrame(VideoFrame::YV12, 10); |
56 scoped_refptr<VideoFrame> frame_b = CreateFrame(VideoFrame::YV12, 10); | 81 scoped_refptr<VideoFrame> frame_b = CreateFrame(VideoFrame::YV12, 10); |
57 | 82 |
58 // Clear frame references to return the frames to the pool. | 83 // Clear frame references to return the frames to the pool. |
59 frame_a = NULL; | 84 frame_a = NULL; |
60 frame_b = NULL; | 85 frame_b = NULL; |
61 | 86 |
62 // Verify that both frames are in the pool. | 87 // Verify that both frames are in the pool. |
63 CheckPoolSize(2u); | 88 CheckPoolSize(2u); |
(...skipping 10 matching lines...) Expand all Loading... | |
74 // Destroy the pool. | 99 // Destroy the pool. |
75 pool_.reset(); | 100 pool_.reset(); |
76 | 101 |
77 // Write to the Y plane. The memory tools should detect a | 102 // Write to the Y plane. The memory tools should detect a |
78 // use-after-free if the storage was actually removed by pool destruction. | 103 // use-after-free if the storage was actually removed by pool destruction. |
79 memset(frame->data(VideoFrame::kYPlane), 0xff, | 104 memset(frame->data(VideoFrame::kYPlane), 0xff, |
80 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane)); | 105 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane)); |
81 } | 106 } |
82 | 107 |
83 } // namespace media | 108 } // namespace media |
OLD | NEW |