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

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

Issue 1427543002: Modified old wait sync point functions to also accept new sync tokens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Folded sync_point into sync_tokens Created 5 years, 1 month 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
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 // Ensure each frame is properly sized and allocated. Will trigger OOB reads 255 // Ensure each frame is properly sized and allocated. Will trigger OOB reads
256 // and writes as well as incorrect frame hashes otherwise. 256 // and writes as well as incorrect frame hashes otherwise.
257 TEST(VideoFrame, CheckFrameExtents) { 257 TEST(VideoFrame, CheckFrameExtents) {
258 // Each call consists of a Format and the expected hash of all 258 // Each call consists of a Format and the expected hash of all
259 // planes if filled with kFillByte (defined in ExpectFrameExtents). 259 // planes if filled with kFillByte (defined in ExpectFrameExtents).
260 ExpectFrameExtents(PIXEL_FORMAT_YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); 260 ExpectFrameExtents(PIXEL_FORMAT_YV12, "8e5d54cb23cd0edca111dd35ffb6ff05");
261 ExpectFrameExtents(PIXEL_FORMAT_YV16, "cce408a044b212db42a10dfec304b3ef"); 261 ExpectFrameExtents(PIXEL_FORMAT_YV16, "cce408a044b212db42a10dfec304b3ef");
262 } 262 }
263 263
264 static void TextureCallback(uint32* called_sync_point, 264 static void TextureCallback(gpu::SyncToken* called_sync_token,
265 uint32 release_sync_point) { 265 const gpu::SyncToken& release_sync_token) {
266 *called_sync_point = release_sync_point; 266 *called_sync_token = release_sync_token;
267 } 267 }
268 268
269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
270 // destroyed with the default release sync point. 270 // destroyed with the default release sync point.
271 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { 271 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
272 uint32 called_sync_point = 1; 272 uint32 called_sync_point = 1;
273 273
274 { 274 {
275 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( 275 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
276 PIXEL_FORMAT_ARGB, 276 PIXEL_FORMAT_ARGB,
277 gpu::MailboxHolder(gpu::Mailbox::Generate(), 5, 0 /* sync_point */), 277 gpu::MailboxHolder(gpu::Mailbox::Generate(), 5, 0 /* sync_point */),
278 base::Bind(&TextureCallback, &called_sync_point), 278 base::Bind(&TextureCallback, &called_sync_point),
279 gfx::Size(10, 10), // coded_size 279 gfx::Size(10, 10), // coded_size
280 gfx::Rect(10, 10), // visible_rect 280 gfx::Rect(10, 10), // visible_rect
281 gfx::Size(10, 10), // natural_size 281 gfx::Size(10, 10), // natural_size
282 base::TimeDelta()); // timestamp 282 base::TimeDelta()); // timestamp
283 EXPECT_EQ(PIXEL_FORMAT_ARGB, frame->format()); 283 EXPECT_EQ(PIXEL_FORMAT_ARGB, frame->format());
284 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type()); 284 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type());
285 EXPECT_TRUE(frame->HasTextures()); 285 EXPECT_TRUE(frame->HasTextures());
286 } 286 }
287 // Nobody set a sync point to |frame|, so |frame| set |called_sync_point| to 0 287 // Nobody set a sync point to |frame|, so |frame| set |called_sync_point| to 0
288 // as default value. 288 // as default value.
289 EXPECT_EQ(0u, called_sync_point); 289 EXPECT_EQ(0u, called_sync_point);
290 } 290 }
291 291
292 namespace { 292 namespace {
293 293
294 class SyncPointClientImpl : public VideoFrame::SyncPointClient { 294 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient {
295 public: 295 public:
296 explicit SyncPointClientImpl(uint32 sync_point) : sync_point_(sync_point) {} 296 explicit SyncTokenClientImpl(uint32 sync_point) : sync_point_(sync_point) {}
297 ~SyncPointClientImpl() override {} 297 ~SyncTokenClientImpl() override {}
298 uint32 InsertSyncPoint() override { return sync_point_; } 298 uint32 InsertSyncPoint() override { return sync_point_; }
299 void WaitSyncPoint(uint32 sync_point) override {} 299 void WaitSyncToken(const gpu::SyncToken& sync_token) override {}
300 300
301 private: 301 private:
302 uint32 sync_point_; 302 uint32 sync_point_;
303 }; 303 };
304 304
305 } // namespace 305 } // namespace
306 306
307 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 307 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
308 // destroyed with the release sync point, which was updated by clients. 308 // destroyed with the release sync point, which was updated by clients.
309 // (i.e. the compositor, webgl). 309 // (i.e. the compositor, webgl).
310 TEST(VideoFrame, 310 TEST(VideoFrame,
311 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) { 311 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) {
312 const int kPlanesNum = 3; 312 const int kPlanesNum = 3;
313 gpu::Mailbox mailbox[kPlanesNum]; 313 gpu::Mailbox mailbox[kPlanesNum];
314 for (int i = 0; i < kPlanesNum; ++i) { 314 for (int i = 0; i < kPlanesNum; ++i) {
315 mailbox[i].name[0] = 50 + 1; 315 mailbox[i].name[0] = 50 + 1;
316 } 316 }
317 317
318 uint32 sync_point = 7; 318 uint32 sync_point = 7;
319 gpu::SyncToken sync_token(sync_point);
319 uint32 target = 9; 320 uint32 target = 9;
320 uint32 release_sync_point = 111; 321 uint32 release_sync_point = 111;
321 uint32 called_sync_point = 0; 322 gpu::SyncToken release_sync_token(release_sync_point);
323 gpu::SyncToken called_sync_token;
322 { 324 {
323 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures( 325 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures(
324 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], target, sync_point), 326 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], target, sync_token),
325 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], target, sync_point), 327 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], target, sync_token),
326 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], target, sync_point), 328 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], target, sync_token),
327 base::Bind(&TextureCallback, &called_sync_point), 329 base::Bind(&TextureCallback, &called_sync_token),
328 gfx::Size(10, 10), // coded_size 330 gfx::Size(10, 10), // coded_size
329 gfx::Rect(10, 10), // visible_rect 331 gfx::Rect(10, 10), // visible_rect
330 gfx::Size(10, 10), // natural_size 332 gfx::Size(10, 10), // natural_size
331 base::TimeDelta()); // timestamp 333 base::TimeDelta()); // timestamp
332 334
333 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type()); 335 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type());
334 EXPECT_EQ(PIXEL_FORMAT_I420, frame->format()); 336 EXPECT_EQ(PIXEL_FORMAT_I420, frame->format());
335 EXPECT_EQ(3u, VideoFrame::NumPlanes(frame->format())); 337 EXPECT_EQ(3u, VideoFrame::NumPlanes(frame->format()));
336 EXPECT_TRUE(frame->HasTextures()); 338 EXPECT_TRUE(frame->HasTextures());
337 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) { 339 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) {
338 const gpu::MailboxHolder& mailbox_holder = frame->mailbox_holder(i); 340 const gpu::MailboxHolder& mailbox_holder = frame->mailbox_holder(i);
339 EXPECT_EQ(mailbox[i].name[0], mailbox_holder.mailbox.name[0]); 341 EXPECT_EQ(mailbox[i].name[0], mailbox_holder.mailbox.name[0]);
340 EXPECT_EQ(target, mailbox_holder.texture_target); 342 EXPECT_EQ(target, mailbox_holder.texture_target);
341 EXPECT_EQ(sync_point, mailbox_holder.sync_point); 343 EXPECT_EQ(sync_token, mailbox_holder.sync_token);
342 } 344 }
343 345
344 SyncPointClientImpl client(release_sync_point); 346 SyncTokenClientImpl client(release_sync_point);
345 frame->UpdateReleaseSyncPoint(&client); 347 frame->UpdateReleaseSyncToken(&client);
346 EXPECT_EQ(sync_point, 348 EXPECT_EQ(sync_token,
347 frame->mailbox_holder(VideoFrame::kYPlane).sync_point); 349 frame->mailbox_holder(VideoFrame::kYPlane).sync_token);
348 } 350 }
349 EXPECT_EQ(release_sync_point, called_sync_point); 351 EXPECT_EQ(release_sync_token, called_sync_token);
350 } 352 }
351 353
352 TEST(VideoFrame, IsValidConfig_OddCodedSize) { 354 TEST(VideoFrame, IsValidConfig_OddCodedSize) {
353 // Odd sizes are valid for all formats. Odd formats may be internally rounded 355 // Odd sizes are valid for all formats. Odd formats may be internally rounded
354 // in VideoFrame::CreateFrame because VideoFrame owns the allocation and can 356 // in VideoFrame::CreateFrame because VideoFrame owns the allocation and can
355 // pad the requested coded_size to ensure the UV sample boundaries line up 357 // pad the requested coded_size to ensure the UV sample boundaries line up
356 // with the Y plane after subsample scaling. See CreateFrame_OddWidth. 358 // with the Y plane after subsample scaling. See CreateFrame_OddWidth.
357 gfx::Size odd_size(677, 288); 359 gfx::Size odd_size(677, 288);
358 360
359 // First choosing a format with sub-sampling for UV. 361 // First choosing a format with sub-sampling for UV.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 475
474 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { 476 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) {
475 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); 477 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i);
476 int value = -1; 478 int value = -1;
477 EXPECT_TRUE(result.GetInteger(key, &value)); 479 EXPECT_TRUE(result.GetInteger(key, &value));
478 EXPECT_EQ(i, value); 480 EXPECT_EQ(i, value);
479 } 481 }
480 } 482 }
481 483
482 } // namespace media 484 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698