OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/tuple.h" | |
10 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
11 #include "media/base/mock_filters.h" | 12 #include "media/base/mock_filters.h" |
12 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 // Helper function that initializes a YV12 frame with white and black scan | 18 // Helper function that initializes a YV12 frame with white and black scan |
18 // lines based on the |white_to_black| parameter. If 0, then the entire | 19 // lines based on the |white_to_black| parameter. If 0, then the entire |
19 // frame will be black, if 1 then the entire frame will be white. | 20 // frame will be black, if 1 then the entire frame will be white. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 154 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
154 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 155 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
155 for (size_t y = 0; y < frame->height() / 2; ++y) { | 156 for (size_t y = 0; y < frame->height() / 2; ++y) { |
156 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); | 157 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); |
157 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); | 158 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); |
158 u_plane += frame->stride(VideoFrame::kUPlane); | 159 u_plane += frame->stride(VideoFrame::kUPlane); |
159 v_plane += frame->stride(VideoFrame::kVPlane); | 160 v_plane += frame->stride(VideoFrame::kVPlane); |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
164 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | |
165 // and writes as well as incorrect frame hashes otherwise. | |
166 TEST(VideoFrame, CheckFrameExtents) { | |
167 const unsigned char kFillByte = 0x80; | |
168 const size_t kWidth = 61; | |
169 const size_t kHeight = 31; | |
170 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); | |
171 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); | |
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
Drop the "A" from this and the previous line.
DaleCurtis
2012/03/22 19:45:28
Done.
| |
172 | |
173 // Each entry consists of a tuple of VideoFrame::Format, # of planes, bytes | |
174 // per pixel, and the expected hash of all planes if filled with kFillByte. | |
175 const Tuple4<VideoFrame::Format, int, int, char *> kFrameTests[] = { | |
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
s/char \*/StringPiece/
would allow you to drop the
DaleCurtis
2012/03/22 19:45:28
Dropped all this in favor of extracted function.
| |
176 MakeTuple( | |
177 VideoFrame::RGB555, 1, 2, (char *)"31f7739efc76b5d9cb51361ba82533fa"), | |
178 MakeTuple( | |
179 VideoFrame::RGB565, 1, 2, (char *)"31f7739efc76b5d9cb51361ba82533fa"), | |
180 MakeTuple( | |
181 VideoFrame::RGB24, 1, 3, (char *)"84361ae9d4b6d4641a11474b3a7a2260"), | |
182 MakeTuple( | |
183 VideoFrame::RGB32, 1, 4, (char *)"de6d3d567e282f6a38d478f04fc81fb0"), | |
184 MakeTuple( | |
185 VideoFrame::RGBA, 1, 4, (char *)"de6d3d567e282f6a38d478f04fc81fb0"), | |
186 MakeTuple( | |
187 VideoFrame::YV12, 3, 1, (char *)"71113bdfd4c0de6cf62f48fb74f7a0b1"), | |
188 MakeTuple( | |
189 VideoFrame::YV16, 3, 1, (char *)"9bb99ac3ff350644ebff4d28dc01b461"), | |
190 }; | |
191 | |
192 base::MD5Digest digest; | |
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
This and the next line can go near the bottom of t
DaleCurtis
2012/03/22 19:45:28
Done.
| |
193 base::MD5Context context; | |
194 for(unsigned long i = 0; i < arraysize(kFrameTests); i++) { | |
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
If it were me I'd extract the loop body into a hel
DaleCurtis
2012/03/22 19:45:28
Done.
| |
195 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( | |
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
Add
SCOPED_TRACE(IntToString(i));
for easier debu
DaleCurtis
2012/03/22 19:45:28
Done.
| |
196 kFrameTests[i].a, kWidth, kHeight, kTimestampA, kDurationA); | |
197 ASSERT_TRUE(frame); | |
198 | |
199 // Fill each plane to its reported extents and verify accessors report non | |
200 // zero values. Additionally, for the first plane verify the rows and | |
201 // row_bytes values are correct. | |
202 for(int plane = 0; plane < kFrameTests[i].b; plane++) { | |
203 EXPECT_TRUE(frame->data(plane)); | |
204 EXPECT_TRUE(frame->stride(plane)); | |
205 EXPECT_TRUE(frame->rows(plane)); | |
206 EXPECT_TRUE(frame->row_bytes(plane)); | |
207 | |
208 if (plane == 0) { | |
209 EXPECT_EQ((size_t)frame->rows(plane), kHeight); | |
210 EXPECT_EQ((size_t)frame->row_bytes(plane), kWidth * kFrameTests[i].c); | |
211 } | |
212 | |
213 memset(frame->data(plane), kFillByte, | |
214 frame->stride(plane) * frame->rows(plane)); | |
215 } | |
216 | |
217 base::MD5Init(&context); | |
218 frame->HashFrameForTesting(&context); | |
219 base::MD5Final(&digest, &context); | |
220 EXPECT_EQ(MD5DigestToBase16(digest), kFrameTests[i].d); | |
221 } | |
222 } | |
223 | |
163 } // namespace media | 224 } // namespace media |
OLD | NEW |