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

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

Issue 178133005: Audit/fix use of media::VideoFrame::coded_size() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2121885f Rebase. Created 6 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
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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/aligned_memory.h" 10 #include "base/memory/aligned_memory.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]); 81 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]);
82 } 82 }
83 } 83 }
84 84
85 base::AlignedFree(rgb_data); 85 base::AlignedFree(rgb_data);
86 } 86 }
87 87
88 // Fill each plane to its reported extents and verify accessors report non 88 // Fill each plane to its reported extents and verify accessors report non
89 // zero values. Additionally, for the first plane verify the rows and 89 // zero values. Additionally, for the first plane verify the rows and
90 // row_bytes values are correct. 90 // row_bytes values are correct.
91 void ExpectFrameExtents(VideoFrame::Format format, int planes, 91 void ExpectFrameExtents(VideoFrame::Format format, const char* expected_hash) {
92 int bytes_per_pixel, const char* expected_hash) {
93 const unsigned char kFillByte = 0x80; 92 const unsigned char kFillByte = 0x80;
94 const int kWidth = 61; 93 const int kWidth = 61;
95 const int kHeight = 31; 94 const int kHeight = 31;
96 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); 95 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
97 96
98 gfx::Size size(kWidth, kHeight); 97 gfx::Size size(kWidth, kHeight);
99 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( 98 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame(
100 format, size, gfx::Rect(size), size, kTimestamp); 99 format, size, gfx::Rect(size), size, kTimestamp);
101 ASSERT_TRUE(frame.get()); 100 ASSERT_TRUE(frame.get());
102 101
103 for(int plane = 0; plane < planes; plane++) { 102 int planes = VideoFrame::NumPlanes(format);
103 for (int plane = 0; plane < planes; plane++) {
104 SCOPED_TRACE(base::StringPrintf("Checking plane %d", plane)); 104 SCOPED_TRACE(base::StringPrintf("Checking plane %d", plane));
105 EXPECT_TRUE(frame->data(plane)); 105 EXPECT_TRUE(frame->data(plane));
106 EXPECT_TRUE(frame->stride(plane)); 106 EXPECT_TRUE(frame->stride(plane));
107 EXPECT_TRUE(frame->rows(plane)); 107 EXPECT_TRUE(frame->rows(plane));
108 EXPECT_TRUE(frame->row_bytes(plane)); 108 EXPECT_TRUE(frame->row_bytes(plane));
109 109
110 if (plane == 0) {
111 EXPECT_EQ(frame->rows(plane), kHeight);
112 EXPECT_EQ(frame->row_bytes(plane), kWidth * bytes_per_pixel);
113 }
114
115 memset(frame->data(plane), kFillByte, 110 memset(frame->data(plane), kFillByte,
116 frame->stride(plane) * frame->rows(plane)); 111 frame->stride(plane) * frame->rows(plane));
117 } 112 }
118 113
119 base::MD5Context context; 114 base::MD5Context context;
120 base::MD5Init(&context); 115 base::MD5Init(&context);
121 frame->HashFrameForTesting(&context); 116 frame->HashFrameForTesting(&context);
122 base::MD5Digest digest; 117 base::MD5Digest digest;
123 base::MD5Final(&digest, &context); 118 base::MD5Final(&digest, &context);
124 EXPECT_EQ(MD5DigestToBase16(digest), expected_hash); 119 EXPECT_EQ(MD5DigestToBase16(digest), expected_hash);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 227 }
233 228
234 EXPECT_FALSE(no_longer_needed_triggered); 229 EXPECT_FALSE(no_longer_needed_triggered);
235 frame = NULL; 230 frame = NULL;
236 EXPECT_TRUE(no_longer_needed_triggered); 231 EXPECT_TRUE(no_longer_needed_triggered);
237 } 232 }
238 233
239 // Ensure each frame is properly sized and allocated. Will trigger OOB reads 234 // Ensure each frame is properly sized and allocated. Will trigger OOB reads
240 // and writes as well as incorrect frame hashes otherwise. 235 // and writes as well as incorrect frame hashes otherwise.
241 TEST(VideoFrame, CheckFrameExtents) { 236 TEST(VideoFrame, CheckFrameExtents) {
242 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, 237 // Each call consists of a VideoFrame::Format and the expected hash of all
243 // and the expected hash of all planes if filled with kFillByte (defined in 238 // planes if filled with kFillByte (defined in ExpectFrameExtents).
244 // ExpectFrameExtents). 239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05");
245 ExpectFrameExtents( 240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef");
246 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1");
247 ExpectFrameExtents(
248 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461");
249 } 241 }
250 242
251 static void TextureCallback(uint32* called_sync_point, 243 static void TextureCallback(uint32* called_sync_point,
252 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { 244 scoped_ptr<gpu::MailboxHolder> mailbox_holder) {
253 *called_sync_point = mailbox_holder->sync_point; 245 *called_sync_point = mailbox_holder->sync_point;
254 } 246 }
255 247
256 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
257 // destroyed with the original sync point. 249 // destroyed with the original sync point.
258 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { 250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 EXPECT_EQ(sync_point, mailbox_holder->sync_point); 293 EXPECT_EQ(sync_point, mailbox_holder->sync_point);
302 294
303 // Finish using the mailbox_holder and drop our reference. 295 // Finish using the mailbox_holder and drop our reference.
304 sync_point = 10; 296 sync_point = 10;
305 mailbox_holder->sync_point = sync_point; 297 mailbox_holder->sync_point = sync_point;
306 } 298 }
307 EXPECT_EQ(sync_point, called_sync_point); 299 EXPECT_EQ(sync_point, called_sync_point);
308 } 300 }
309 301
310 } // namespace media 302 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698