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

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

Issue 313623003: WIP: Option2: Android media: VideoFrame should not store so many sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/gpu_video_decoder.h » ('j') | 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/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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 // 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
235 // and writes as well as incorrect frame hashes otherwise. 235 // and writes as well as incorrect frame hashes otherwise.
236 TEST(VideoFrame, CheckFrameExtents) { 236 TEST(VideoFrame, CheckFrameExtents) {
237 // Each call consists of a VideoFrame::Format and the expected hash of all 237 // Each call consists of a VideoFrame::Format and the expected hash of all
238 // planes if filled with kFillByte (defined in ExpectFrameExtents). 238 // planes if filled with kFillByte (defined in ExpectFrameExtents).
239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); 239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05");
240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef"); 240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef");
241 } 241 }
242 242
243 static void TextureCallback(std::vector<uint32>* called_sync_point, 243 static void TextureCallback(
244 const std::vector<uint32>& release_sync_points) { 244 std::map<std::string, uint32>* called_sync_point,
245 called_sync_point->assign(release_sync_points.begin(), 245 const std::map<std::string, uint32>& release_sync_points) {
246 release_sync_points.end()); 246 called_sync_point->clear();
247 for (std::map<std::string, uint32>::const_iterator iter =
248 release_sync_points.begin();
249 iter != release_sync_points.end();
250 iter++) {
251 EXPECT_TRUE(called_sync_point->insert(std::make_pair(iter->first,
252 iter->second)).second);
253 }
247 } 254 }
248 255
249 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 256 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
250 // destroyed with the default release sync points. 257 // destroyed with the default release sync points.
251 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { 258 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
252 std::vector<uint32> called_sync_points; 259 std::map<std::string, uint32> called_sync_points;
253 called_sync_points.push_back(1); 260 called_sync_points["test1"] = 1;
254 261
255 { 262 {
256 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( 263 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
257 make_scoped_ptr( 264 make_scoped_ptr(
258 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), 265 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)),
259 base::Bind(&TextureCallback, &called_sync_points), 266 base::Bind(&TextureCallback, &called_sync_points),
260 gfx::Size(10, 10), // coded_size 267 gfx::Size(10, 10), // coded_size
261 gfx::Rect(10, 10), // visible_rect 268 gfx::Rect(10, 10), // visible_rect
262 gfx::Size(10, 10), // natural_size 269 gfx::Size(10, 10), // natural_size
263 base::TimeDelta(), // timestamp 270 base::TimeDelta(), // timestamp
264 VideoFrame::ReadPixelsCB()); // read_pixels_cb 271 VideoFrame::ReadPixelsCB()); // read_pixels_cb
265 272
266 EXPECT_EQ(1u, called_sync_points.size()); 273 EXPECT_EQ(1u, called_sync_points.size());
267 } 274 }
268 EXPECT_TRUE(called_sync_points.empty()); 275 EXPECT_TRUE(called_sync_points.empty());
269 } 276 }
270 277
271 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 278 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
272 // destroyed with the release sync points, which was updated by clients. 279 // destroyed with the release sync points, which was updated by clients.
273 // (i.e. the compositor, webgl). 280 // (i.e. the compositor, webgl).
274 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { 281 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) {
275 std::vector<uint32> called_sync_points; 282 std::map<std::string, uint32> called_sync_points;
276 283
277 gpu::Mailbox mailbox; 284 gpu::Mailbox mailbox;
278 mailbox.name[0] = 50; 285 mailbox.name[0] = 50;
279 uint32 sync_point = 7; 286 uint32 sync_point = 7;
280 uint32 target = 9; 287 uint32 target = 9;
281 std::vector<uint32> release_sync_points; 288 std::map<std::string, uint32> release_sync_points;
282 release_sync_points.push_back(1); 289 release_sync_points["test1"] = 1;
283 release_sync_points.push_back(2); 290 release_sync_points["test2"] = 2;
284 release_sync_points.push_back(3); 291 release_sync_points["test3"] = 3;
285 292
286 { 293 {
287 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( 294 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
288 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), 295 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)),
289 base::Bind(&TextureCallback, &called_sync_points), 296 base::Bind(&TextureCallback, &called_sync_points),
290 gfx::Size(10, 10), // coded_size 297 gfx::Size(10, 10), // coded_size
291 gfx::Rect(10, 10), // visible_rect 298 gfx::Rect(10, 10), // visible_rect
292 gfx::Size(10, 10), // natural_size 299 gfx::Size(10, 10), // natural_size
293 base::TimeDelta(), // timestamp 300 base::TimeDelta(), // timestamp
294 VideoFrame::ReadPixelsCB()); // read_pixels_cb 301 VideoFrame::ReadPixelsCB()); // read_pixels_cb
295 EXPECT_TRUE(called_sync_points.empty()); 302 EXPECT_TRUE(called_sync_points.empty());
296 303
297 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); 304 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder();
298 305
299 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); 306 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]);
300 EXPECT_EQ(target, mailbox_holder->texture_target); 307 EXPECT_EQ(target, mailbox_holder->texture_target);
301 EXPECT_EQ(sync_point, mailbox_holder->sync_point); 308 EXPECT_EQ(sync_point, mailbox_holder->sync_point);
302 309
303 frame->AppendReleaseSyncPoint(release_sync_points[0]); 310 frame->AppendReleaseSyncPoint("test1", 100);
304 frame->AppendReleaseSyncPoint(release_sync_points[1]); 311 frame->AppendReleaseSyncPoint("test2", 101);
305 frame->AppendReleaseSyncPoint(release_sync_points[2]); 312 frame->AppendReleaseSyncPoint("test3", 102);
313 // Above sync points are overridden.
314 for (std::map<std::string, uint32>::const_iterator iter =
315 release_sync_points.begin();
316 iter != release_sync_points.end();
317 iter++) {
318 frame->AppendReleaseSyncPoint(iter->first, iter->second);
319 }
306 EXPECT_EQ(sync_point, mailbox_holder->sync_point); 320 EXPECT_EQ(sync_point, mailbox_holder->sync_point);
307 } 321 }
308 EXPECT_EQ(release_sync_points, called_sync_points); 322 EXPECT_EQ(release_sync_points, called_sync_points);
309 } 323 }
310 324
311 } // namespace media 325 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/gpu_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698