summaryrefslogtreecommitdiff
path: root/media/base/video_frame_unittest.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2013-07-10 11:40:50 +0100
committerBen Murdoch <benm@google.com>2013-07-10 11:40:50 +0100
commiteb525c5499e34cc9c4b825d6d9e75bb07cc06ace (patch)
treed908ce4bfe1717d2cd53f41327d8b9ba8304355f /media/base/video_frame_unittest.cc
parent3c54152607de4272b3da0c146b71dcba8a0e5610 (diff)
downloadchromium_org-eb525c5499e34cc9c4b825d6d9e75bb07cc06ace.tar.gz
Merge from Chromium at DEPS revision r210036
This commit was generated by merge_to_master.py. Change-Id: Ib0e33a83ad5dfa541481e83d7acfc6970e68f471
Diffstat (limited to 'media/base/video_frame_unittest.cc')
-rw-r--r--media/base/video_frame_unittest.cc213
1 files changed, 213 insertions, 0 deletions
diff --git a/media/base/video_frame_unittest.cc b/media/base/video_frame_unittest.cc
index ce4869c157..b88d20c363 100644
--- a/media/base/video_frame_unittest.cc
+++ b/media/base/video_frame_unittest.cc
@@ -4,6 +4,8 @@
#include "media/base/video_frame.h"
+#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/format_macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
@@ -209,4 +211,215 @@ TEST(VideoFrame, CheckFrameExtents) {
VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461");
}
+static void TextureCallback(uint32* called_sync_point, uint32 sync_point) {
+ *called_sync_point = sync_point;
+}
+
+// Verify the TextureNoLongerNeededCallback is called when VideoFrame is
+// destroyed with the original sync point.
+TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
+ uint32 sync_point = 7;
+ uint32 called_sync_point = 0;
+
+ {
+ scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
+ new VideoFrame::MailboxHolder(
+ gpu::Mailbox(),
+ sync_point,
+ base::Bind(&TextureCallback, &called_sync_point)),
+ 5, // texture_target
+ gfx::Size(10, 10), // coded_size
+ gfx::Rect(10, 10), // visible_rect
+ gfx::Size(10, 10), // natural_size
+ base::TimeDelta(), // timestamp
+ base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
+ base::Closure()); // no_longer_needed_cb
+
+ EXPECT_EQ(0u, called_sync_point);
+ }
+ EXPECT_EQ(sync_point, called_sync_point);
+}
+
+// Verify the TextureNoLongerNeededCallback is called when VideoFrame is
+// destroyed with the new sync point, when the mailbox is taken by a caller.
+TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) {
+ uint32 called_sync_point = 0;
+
+ gpu::Mailbox mailbox;
+ mailbox.name[0] = 50;
+ uint32 sync_point = 7;
+ uint32 target = 9;
+
+ {
+ scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
+ new VideoFrame::MailboxHolder(
+ mailbox,
+ sync_point,
+ base::Bind(&TextureCallback, &called_sync_point)),
+ target,
+ gfx::Size(10, 10), // coded_size
+ gfx::Rect(10, 10), // visible_rect
+ gfx::Size(10, 10), // natural_size
+ base::TimeDelta(), // timestamp
+ base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
+ base::Closure()); // no_longer_needed_cb
+
+ {
+ scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
+ frame->texture_mailbox();
+
+ EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
+ EXPECT_EQ(sync_point, mailbox_holder->sync_point());
+ EXPECT_EQ(target, frame->texture_target());
+
+ // Misuse the callback.
+ sync_point = 12;
+ mailbox_holder->Return(sync_point);
+ EXPECT_EQ(0u, called_sync_point);
+
+ // Finish using the mailbox_holder and drop our reference.
+ sync_point = 10;
+ mailbox_holder->Return(sync_point);
+ }
+ EXPECT_EQ(0u, called_sync_point);
+ }
+ EXPECT_EQ(sync_point, called_sync_point);
+}
+
+// If a caller has taken ownership of the texture mailbox, it should
+// not be released when the VideoFrame is destroyed, but should when
+// the TextureNoLongerNeededCallback is called.
+TEST(VideoFrame,
+ TextureNoLongerNeededCallbackAfterTakingMailboxWithDestroyedFrame) {
+ uint32 called_sync_point = 0;
+
+ gpu::Mailbox mailbox;
+ mailbox.name[0] = 50;
+ uint32 sync_point = 7;
+ uint32 target = 9;
+
+ {
+ scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
+
+ {
+ scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
+ new VideoFrame::MailboxHolder(
+ mailbox,
+ sync_point,
+ base::Bind(&TextureCallback, &called_sync_point)),
+ target,
+ gfx::Size(10, 10), // coded_size
+ gfx::Rect(10, 10), // visible_rect
+ gfx::Size(10, 10), // natural_size
+ base::TimeDelta(), // timestamp
+ base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
+ base::Closure()); // no_longer_needed_cb
+
+ mailbox_holder = frame->texture_mailbox();
+
+ EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
+ EXPECT_EQ(sync_point, mailbox_holder->sync_point());
+ EXPECT_EQ(target, frame->texture_target());
+
+ // Keep a ref on the mailbox_holder after the VideoFrame is dropped.
+ }
+ EXPECT_EQ(0u, called_sync_point);
+
+ // Misuse the callback.
+ sync_point = 12;
+ mailbox_holder->Return(sync_point);
+ EXPECT_EQ(0u, called_sync_point);
+
+ // Finish using the mailbox_holder and drop our ref.
+ sync_point = 10;
+ mailbox_holder->Return(sync_point);
+ }
+ EXPECT_EQ(sync_point, called_sync_point);
+}
+
+// If a caller has taken ownership of the texture mailbox, but does
+// not call the callback, it should still happen with the original
+// sync point.
+TEST(VideoFrame,
+ TextureNoLongerNeededCallbackWhenNotCallingAndFrameDestroyed) {
+ uint32 called_sync_point = 0;
+
+ gpu::Mailbox mailbox;
+ mailbox.name[0] = 50;
+ uint32 sync_point = 7;
+ uint32 target = 9;
+
+ {
+ scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder;
+
+ {
+ scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
+ new VideoFrame::MailboxHolder(
+ mailbox,
+ sync_point,
+ base::Bind(&TextureCallback, &called_sync_point)),
+ target,
+ gfx::Size(10, 10), // coded_size
+ gfx::Rect(10, 10), // visible_rect
+ gfx::Size(10, 10), // natural_size
+ base::TimeDelta(), // timestamp
+ base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
+ base::Closure()); // no_longer_needed_cb
+
+ mailbox_holder = frame->texture_mailbox();
+
+ EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
+ EXPECT_EQ(sync_point, mailbox_holder->sync_point());
+ EXPECT_EQ(target, frame->texture_target());
+
+ // Destroy the video frame.
+ }
+ EXPECT_EQ(0u, called_sync_point);
+
+ // Drop the reference on the mailbox without using it at all.
+ }
+ EXPECT_EQ(sync_point, called_sync_point);
+}
+
+// If a caller has taken ownership of the texture mailbox, but does
+// not call the callback, it should still happen with the original
+// sync point.
+TEST(VideoFrame,
+ TextureNoLongerNeededCallbackAfterTakingMailboxAndNotCalling) {
+ uint32 called_sync_point = 0;
+
+ gpu::Mailbox mailbox;
+ mailbox.name[0] = 50;
+ uint32 sync_point = 7;
+ uint32 target = 9;
+
+ {
+ scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
+ new VideoFrame::MailboxHolder(
+ mailbox,
+ sync_point,
+ base::Bind(&TextureCallback, &called_sync_point)),
+ target,
+ gfx::Size(10, 10), // coded_size
+ gfx::Rect(10, 10), // visible_rect
+ gfx::Size(10, 10), // natural_size
+ base::TimeDelta(), // timestamp
+ base::Callback<void(const SkBitmap&)>(), // read_pixels_cb
+ base::Closure()); // no_longer_needed_cb
+
+ scoped_refptr<VideoFrame::MailboxHolder> mailbox_holder =
+ frame->texture_mailbox();
+
+ EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox().name[0]);
+ EXPECT_EQ(sync_point, mailbox_holder->sync_point());
+ EXPECT_EQ(target, frame->texture_target());
+
+ EXPECT_EQ(0u, called_sync_point);
+
+ // Don't use the mailbox at all and drop our ref on it.
+ }
+ // The VideoFrame is destroyed, it should call the callback.
+ EXPECT_EQ(sync_point, called_sync_point);
+}
+
} // namespace media