Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: media/base/video_frame_unittest.cc

Issue 9766007: Fix incorrect VideoFrame::row_bytes() for RGB. Add tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/video_frame.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 rgb_frame->data(VideoFrame::kRGBPlane) + 72 rgb_frame->data(VideoFrame::kRGBPlane) +
73 (rgb_frame->stride(VideoFrame::kRGBPlane) * row)); 73 (rgb_frame->stride(VideoFrame::kRGBPlane) * row));
74 for (size_t col = 0; col < rgb_frame->width(); ++col) { 74 for (size_t col = 0; col < rgb_frame->width(); ++col) {
75 SCOPED_TRACE( 75 SCOPED_TRACE(
76 base::StringPrintf("Checking (%" PRIuS ", %" PRIuS ")", row, col)); 76 base::StringPrintf("Checking (%" PRIuS ", %" PRIuS ")", row, col));
77 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]); 77 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]);
78 } 78 }
79 } 79 }
80 } 80 }
81 81
82 // Fill each plane to its reported extents and verify accessors report non
83 // zero values. Additionally, for the first plane verify the rows and
84 // row_bytes values are correct.
85 void ExpectFrameExtents(VideoFrame::Format format, int planes,
86 int bytes_per_pixel, const char* expected_hash) {
87 const unsigned char kFillByte = 0x80;
88 const size_t kWidth = 61;
89 const size_t kHeight = 31;
90 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
91 const base::TimeDelta kDuration = base::TimeDelta::FromMicroseconds(1667);
92
93 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame(
94 format, kWidth, kHeight, kTimestamp, kDuration);
95 ASSERT_TRUE(frame);
96
97 for(int plane = 0; plane < planes; plane++) {
98 SCOPED_TRACE(base::StringPrintf("Checking plane %d", plane));
99 EXPECT_TRUE(frame->data(plane));
100 EXPECT_TRUE(frame->stride(plane));
101 EXPECT_TRUE(frame->rows(plane));
102 EXPECT_TRUE(frame->row_bytes(plane));
103
104 if (plane == 0) {
105 EXPECT_EQ((size_t)frame->rows(plane), kHeight);
106 EXPECT_EQ((size_t)frame->row_bytes(plane), kWidth * bytes_per_pixel);
107 }
108
109 memset(frame->data(plane), kFillByte,
110 frame->stride(plane) * frame->rows(plane));
111 }
112
113 base::MD5Context context;
114 base::MD5Init(&context);
115 frame->HashFrameForTesting(&context);
116 base::MD5Digest digest;
117 base::MD5Final(&digest, &context);
118 EXPECT_EQ(MD5DigestToBase16(digest), expected_hash);
119 }
120
82 TEST(VideoFrame, CreateFrame) { 121 TEST(VideoFrame, CreateFrame) {
83 const size_t kWidth = 64; 122 const size_t kWidth = 64;
84 const size_t kHeight = 48; 123 const size_t kHeight = 48;
85 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); 124 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337);
86 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); 125 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667);
87 const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234); 126 const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234);
88 const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(5678); 127 const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(5678);
89 128
90 // Create a YV12 Video Frame. 129 // Create a YV12 Video Frame.
91 scoped_refptr<media::VideoFrame> frame = 130 scoped_refptr<media::VideoFrame> frame =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 uint8* u_plane = frame->data(VideoFrame::kUPlane); 204 uint8* u_plane = frame->data(VideoFrame::kUPlane);
166 uint8* v_plane = frame->data(VideoFrame::kVPlane); 205 uint8* v_plane = frame->data(VideoFrame::kVPlane);
167 for (size_t y = 0; y < frame->height() / 2; ++y) { 206 for (size_t y = 0; y < frame->height() / 2; ++y) {
168 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); 207 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow)));
169 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); 208 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow)));
170 u_plane += frame->stride(VideoFrame::kUPlane); 209 u_plane += frame->stride(VideoFrame::kUPlane);
171 v_plane += frame->stride(VideoFrame::kVPlane); 210 v_plane += frame->stride(VideoFrame::kVPlane);
172 } 211 }
173 } 212 }
174 213
214 // Ensure each frame is properly sized and allocated. Will trigger OOB reads
215 // and writes as well as incorrect frame hashes otherwise.
216 TEST(VideoFrame, CheckFrameExtents) {
217 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel,
218 // and the expected hash of all planes if filled with kFillByte (defined in
219 // ExpectFrameExtents).
220 ExpectFrameExtents(
221 VideoFrame::RGB555, 1, 2, "31f7739efc76b5d9cb51361ba82533fa");
222 ExpectFrameExtents(
223 VideoFrame::RGB565, 1, 2, "31f7739efc76b5d9cb51361ba82533fa");
224 ExpectFrameExtents(
225 VideoFrame::RGB24, 1, 3, "84361ae9d4b6d4641a11474b3a7a2260");
226 ExpectFrameExtents(
227 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0");
228 ExpectFrameExtents(
229 VideoFrame::RGBA, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0");
230 ExpectFrameExtents(
231 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1");
232 ExpectFrameExtents(
233 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461");
234 }
235
175 } // namespace media 236 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698