OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "media/base/video_frame.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void ExpectFrameExtents(VideoFrame::Format format, int planes, | 86 void ExpectFrameExtents(VideoFrame::Format format, int planes, |
87 int bytes_per_pixel, const char* expected_hash) { | 87 int bytes_per_pixel, const char* expected_hash) { |
88 const unsigned char kFillByte = 0x80; | 88 const unsigned char kFillByte = 0x80; |
89 const int kWidth = 61; | 89 const int kWidth = 61; |
90 const int kHeight = 31; | 90 const int kHeight = 31; |
91 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 91 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
92 | 92 |
93 gfx::Size size(kWidth, kHeight); | 93 gfx::Size size(kWidth, kHeight); |
94 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( | 94 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( |
95 format, size, gfx::Rect(size), size, kTimestamp); | 95 format, size, gfx::Rect(size), size, kTimestamp); |
96 ASSERT_TRUE(frame); | 96 ASSERT_TRUE(frame.get()); |
97 | 97 |
98 for(int plane = 0; plane < planes; plane++) { | 98 for(int plane = 0; plane < planes; plane++) { |
99 SCOPED_TRACE(base::StringPrintf("Checking plane %d", plane)); | 99 SCOPED_TRACE(base::StringPrintf("Checking plane %d", plane)); |
100 EXPECT_TRUE(frame->data(plane)); | 100 EXPECT_TRUE(frame->data(plane)); |
101 EXPECT_TRUE(frame->stride(plane)); | 101 EXPECT_TRUE(frame->stride(plane)); |
102 EXPECT_TRUE(frame->rows(plane)); | 102 EXPECT_TRUE(frame->rows(plane)); |
103 EXPECT_TRUE(frame->row_bytes(plane)); | 103 EXPECT_TRUE(frame->row_bytes(plane)); |
104 | 104 |
105 if (plane == 0) { | 105 if (plane == 0) { |
106 EXPECT_EQ(frame->rows(plane), kHeight); | 106 EXPECT_EQ(frame->rows(plane), kHeight); |
(...skipping 15 matching lines...) Expand all Loading... |
122 TEST(VideoFrame, CreateFrame) { | 122 TEST(VideoFrame, CreateFrame) { |
123 const int kWidth = 64; | 123 const int kWidth = 64; |
124 const int kHeight = 48; | 124 const int kHeight = 48; |
125 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 125 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
126 | 126 |
127 // Create a YV12 Video Frame. | 127 // Create a YV12 Video Frame. |
128 gfx::Size size(kWidth, kHeight); | 128 gfx::Size size(kWidth, kHeight); |
129 scoped_refptr<media::VideoFrame> frame = | 129 scoped_refptr<media::VideoFrame> frame = |
130 VideoFrame::CreateFrame(media::VideoFrame::YV12, size, gfx::Rect(size), | 130 VideoFrame::CreateFrame(media::VideoFrame::YV12, size, gfx::Rect(size), |
131 size, kTimestamp); | 131 size, kTimestamp); |
132 ASSERT_TRUE(frame); | 132 ASSERT_TRUE(frame.get()); |
133 | 133 |
134 // Test VideoFrame implementation. | 134 // Test VideoFrame implementation. |
135 EXPECT_EQ(media::VideoFrame::YV12, frame->format()); | 135 EXPECT_EQ(media::VideoFrame::YV12, frame->format()); |
136 { | 136 { |
137 SCOPED_TRACE(""); | 137 SCOPED_TRACE(""); |
138 InitializeYV12Frame(frame, 0.0f); | 138 InitializeYV12Frame(frame.get(), 0.0f); |
139 ExpectFrameColor(frame, 0xFF000000); | 139 ExpectFrameColor(frame.get(), 0xFF000000); |
140 } | 140 } |
141 base::MD5Digest digest; | 141 base::MD5Digest digest; |
142 base::MD5Context context; | 142 base::MD5Context context; |
143 base::MD5Init(&context); | 143 base::MD5Init(&context); |
144 frame->HashFrameForTesting(&context); | 144 frame->HashFrameForTesting(&context); |
145 base::MD5Final(&digest, &context); | 145 base::MD5Final(&digest, &context); |
146 EXPECT_EQ(MD5DigestToBase16(digest), "9065c841d9fca49186ef8b4ef547e79b"); | 146 EXPECT_EQ(MD5DigestToBase16(digest), "9065c841d9fca49186ef8b4ef547e79b"); |
147 { | 147 { |
148 SCOPED_TRACE(""); | 148 SCOPED_TRACE(""); |
149 InitializeYV12Frame(frame, 1.0f); | 149 InitializeYV12Frame(frame.get(), 1.0f); |
150 ExpectFrameColor(frame, 0xFFFFFFFF); | 150 ExpectFrameColor(frame.get(), 0xFFFFFFFF); |
151 } | 151 } |
152 base::MD5Init(&context); | 152 base::MD5Init(&context); |
153 frame->HashFrameForTesting(&context); | 153 frame->HashFrameForTesting(&context); |
154 base::MD5Final(&digest, &context); | 154 base::MD5Final(&digest, &context); |
155 EXPECT_EQ(MD5DigestToBase16(digest), "911991d51438ad2e1a40ed5f6fc7c796"); | 155 EXPECT_EQ(MD5DigestToBase16(digest), "911991d51438ad2e1a40ed5f6fc7c796"); |
156 | 156 |
157 // Test an empty frame. | 157 // Test an empty frame. |
158 frame = VideoFrame::CreateEmptyFrame(); | 158 frame = VideoFrame::CreateEmptyFrame(); |
159 EXPECT_TRUE(frame->IsEndOfStream()); | 159 EXPECT_TRUE(frame->IsEndOfStream()); |
160 } | 160 } |
161 | 161 |
162 TEST(VideoFrame, CreateBlackFrame) { | 162 TEST(VideoFrame, CreateBlackFrame) { |
163 const int kWidth = 2; | 163 const int kWidth = 2; |
164 const int kHeight = 2; | 164 const int kHeight = 2; |
165 const uint8 kExpectedYRow[] = { 0, 0 }; | 165 const uint8 kExpectedYRow[] = { 0, 0 }; |
166 const uint8 kExpectedUVRow[] = { 128 }; | 166 const uint8 kExpectedUVRow[] = { 128 }; |
167 | 167 |
168 scoped_refptr<media::VideoFrame> frame = | 168 scoped_refptr<media::VideoFrame> frame = |
169 VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); | 169 VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight)); |
170 ASSERT_TRUE(frame); | 170 ASSERT_TRUE(frame.get()); |
171 | 171 |
172 // Test basic properties. | 172 // Test basic properties. |
173 EXPECT_EQ(0, frame->GetTimestamp().InMicroseconds()); | 173 EXPECT_EQ(0, frame->GetTimestamp().InMicroseconds()); |
174 EXPECT_FALSE(frame->IsEndOfStream()); | 174 EXPECT_FALSE(frame->IsEndOfStream()); |
175 | 175 |
176 // Test |frame| properties. | 176 // Test |frame| properties. |
177 EXPECT_EQ(VideoFrame::YV12, frame->format()); | 177 EXPECT_EQ(VideoFrame::YV12, frame->format()); |
178 EXPECT_EQ(kWidth, frame->coded_size().width()); | 178 EXPECT_EQ(kWidth, frame->coded_size().width()); |
179 EXPECT_EQ(kHeight, frame->coded_size().height()); | 179 EXPECT_EQ(kHeight, frame->coded_size().height()); |
180 | 180 |
(...skipping 22 matching lines...) Expand all Loading... |
203 // ExpectFrameExtents). | 203 // ExpectFrameExtents). |
204 ExpectFrameExtents( | 204 ExpectFrameExtents( |
205 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0"); | 205 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0"); |
206 ExpectFrameExtents( | 206 ExpectFrameExtents( |
207 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); | 207 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); |
208 ExpectFrameExtents( | 208 ExpectFrameExtents( |
209 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); | 209 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); |
210 } | 210 } |
211 | 211 |
212 } // namespace media | 212 } // namespace media |
OLD | NEW |