OLD | NEW |
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 Loading... |
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 gpu::SyncToken called_sync_token(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(), gpu::SyncToken(), 5), |
278 base::Bind(&TextureCallback, &called_sync_point), | 278 base::Bind(&TextureCallback, &called_sync_token), |
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_token| |
288 // as default value. | 288 // cleared to default value. |
289 EXPECT_EQ(0u, called_sync_point); | 289 EXPECT_FALSE(called_sync_token.HasData()); |
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(const gpu::SyncToken& sync_token) |
297 ~SyncPointClientImpl() override {} | 297 : sync_token_(sync_token) {} |
298 uint32 InsertSyncPoint() override { return sync_point_; } | 298 ~SyncTokenClientImpl() override {} |
299 void WaitSyncPoint(uint32 sync_point) override {} | 299 uint32 InsertSyncPoint() override { |
| 300 return static_cast<uint32>(sync_token_.release_count()); |
| 301 } |
| 302 void WaitSyncToken(const gpu::SyncToken& sync_token) override {} |
300 | 303 |
301 private: | 304 private: |
302 uint32 sync_point_; | 305 gpu::SyncToken sync_token_; |
303 }; | 306 }; |
304 | 307 |
305 } // namespace | 308 } // namespace |
306 | 309 |
307 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 310 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
308 // destroyed with the release sync point, which was updated by clients. | 311 // destroyed with the release sync point, which was updated by clients. |
309 // (i.e. the compositor, webgl). | 312 // (i.e. the compositor, webgl). |
310 TEST(VideoFrame, | 313 TEST(VideoFrame, |
311 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) { | 314 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) { |
312 const int kPlanesNum = 3; | 315 const int kPlanesNum = 3; |
313 gpu::Mailbox mailbox[kPlanesNum]; | 316 gpu::Mailbox mailbox[kPlanesNum]; |
314 for (int i = 0; i < kPlanesNum; ++i) { | 317 for (int i = 0; i < kPlanesNum; ++i) { |
315 mailbox[i].name[0] = 50 + 1; | 318 mailbox[i].name[0] = 50 + 1; |
316 } | 319 } |
317 | 320 |
318 uint32 sync_point = 7; | 321 gpu::SyncToken sync_token(7); |
319 uint32 target = 9; | 322 uint32 target = 9; |
320 uint32 release_sync_point = 111; | 323 gpu::SyncToken release_sync_token(111); |
321 uint32 called_sync_point = 0; | 324 gpu::SyncToken called_sync_token; |
322 { | 325 { |
323 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures( | 326 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures( |
324 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], target, sync_point), | 327 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], sync_token, target), |
325 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], target, sync_point), | 328 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], sync_token, target), |
326 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], target, sync_point), | 329 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], sync_token, target), |
327 base::Bind(&TextureCallback, &called_sync_point), | 330 base::Bind(&TextureCallback, &called_sync_token), |
328 gfx::Size(10, 10), // coded_size | 331 gfx::Size(10, 10), // coded_size |
329 gfx::Rect(10, 10), // visible_rect | 332 gfx::Rect(10, 10), // visible_rect |
330 gfx::Size(10, 10), // natural_size | 333 gfx::Size(10, 10), // natural_size |
331 base::TimeDelta()); // timestamp | 334 base::TimeDelta()); // timestamp |
332 | 335 |
333 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type()); | 336 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type()); |
334 EXPECT_EQ(PIXEL_FORMAT_I420, frame->format()); | 337 EXPECT_EQ(PIXEL_FORMAT_I420, frame->format()); |
335 EXPECT_EQ(3u, VideoFrame::NumPlanes(frame->format())); | 338 EXPECT_EQ(3u, VideoFrame::NumPlanes(frame->format())); |
336 EXPECT_TRUE(frame->HasTextures()); | 339 EXPECT_TRUE(frame->HasTextures()); |
337 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) { | 340 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) { |
338 const gpu::MailboxHolder& mailbox_holder = frame->mailbox_holder(i); | 341 const gpu::MailboxHolder& mailbox_holder = frame->mailbox_holder(i); |
339 EXPECT_EQ(mailbox[i].name[0], mailbox_holder.mailbox.name[0]); | 342 EXPECT_EQ(mailbox[i].name[0], mailbox_holder.mailbox.name[0]); |
340 EXPECT_EQ(target, mailbox_holder.texture_target); | 343 EXPECT_EQ(target, mailbox_holder.texture_target); |
341 EXPECT_EQ(sync_point, mailbox_holder.sync_point); | 344 EXPECT_EQ(sync_token, mailbox_holder.sync_token); |
342 } | 345 } |
343 | 346 |
344 SyncPointClientImpl client(release_sync_point); | 347 SyncTokenClientImpl client(release_sync_token); |
345 frame->UpdateReleaseSyncPoint(&client); | 348 frame->UpdateReleaseSyncToken(&client); |
346 EXPECT_EQ(sync_point, | 349 EXPECT_EQ(sync_token, |
347 frame->mailbox_holder(VideoFrame::kYPlane).sync_point); | 350 frame->mailbox_holder(VideoFrame::kYPlane).sync_token); |
348 } | 351 } |
349 EXPECT_EQ(release_sync_point, called_sync_point); | 352 EXPECT_EQ(release_sync_token, called_sync_token); |
350 } | 353 } |
351 | 354 |
352 TEST(VideoFrame, IsValidConfig_OddCodedSize) { | 355 TEST(VideoFrame, IsValidConfig_OddCodedSize) { |
353 // Odd sizes are valid for all formats. Odd formats may be internally rounded | 356 // Odd sizes are valid for all formats. Odd formats may be internally rounded |
354 // in VideoFrame::CreateFrame because VideoFrame owns the allocation and can | 357 // in VideoFrame::CreateFrame because VideoFrame owns the allocation and can |
355 // pad the requested coded_size to ensure the UV sample boundaries line up | 358 // pad the requested coded_size to ensure the UV sample boundaries line up |
356 // with the Y plane after subsample scaling. See CreateFrame_OddWidth. | 359 // with the Y plane after subsample scaling. See CreateFrame_OddWidth. |
357 gfx::Size odd_size(677, 288); | 360 gfx::Size odd_size(677, 288); |
358 | 361 |
359 // First choosing a format with sub-sampling for UV. | 362 // First choosing a format with sub-sampling for UV. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 476 |
474 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { | 477 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { |
475 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); | 478 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); |
476 int value = -1; | 479 int value = -1; |
477 EXPECT_TRUE(result.GetInteger(key, &value)); | 480 EXPECT_TRUE(result.GetInteger(key, &value)); |
478 EXPECT_EQ(i, value); | 481 EXPECT_EQ(i, value); |
479 } | 482 } |
480 } | 483 } |
481 | 484 |
482 } // namespace media | 485 } // namespace media |
OLD | NEW |