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

Side by Side Diff: media/mojo/interfaces/video_frame_struct_traits_unittest.cc

Issue 2908303003: media: Create Mojo StructTraits for VideoFrame (Closed)
Patch Set: Remove death test. Created 3 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/mojo/interfaces/video_frame_struct_traits.h"
6
7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h"
10 #include "gpu/command_buffer/common/mailbox.h"
11 #include "gpu/command_buffer/common/mailbox_holder.h"
12 #include "gpu/command_buffer/common/sync_token.h"
13 #include "media/base/video_frame.h"
14 #include "media/mojo/common/mojo_shared_buffer_video_frame.h"
15 #include "media/mojo/interfaces/traits_test_service.mojom.h"
16 #include "mojo/public/cpp/bindings/binding_set.h"
17 #include "mojo/public/cpp/bindings/interface_request.h"
18 #include "mojo/public/cpp/system/buffer.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/geometry/size.h"
22
23 namespace media {
24
25 namespace {
26
27 class VideoFrameStructTraitsTest : public testing::Test,
28 public media::mojom::TraitsTestService {
29 public:
30 VideoFrameStructTraitsTest() = default;
31
32 protected:
33 media::mojom::TraitsTestServicePtr GetTraitsTestProxy() {
34 media::mojom::TraitsTestServicePtr proxy;
35 traits_test_bindings_.AddBinding(this, mojo::MakeRequest(&proxy));
36 return proxy;
37 }
38
39 bool RoundTrip(scoped_refptr<VideoFrame>* frame) {
40 scoped_refptr<VideoFrame> input = std::move(*frame);
41 media::mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
42 return proxy->EchoVideoFrame(std::move(input), frame);
43 }
44
45 private:
46 void EchoVideoFrame(const scoped_refptr<VideoFrame>& f,
47 EchoVideoFrameCallback callback) override {
48 std::move(callback).Run(f);
49 }
50
51 base::MessageLoop loop_;
52 mojo::BindingSet<TraitsTestService> traits_test_bindings_;
53
54 DISALLOW_COPY_AND_ASSIGN(VideoFrameStructTraitsTest);
55 };
56
57 } // namespace
58
59 TEST_F(VideoFrameStructTraitsTest, Null) {
60 scoped_refptr<VideoFrame> frame;
61
62 ASSERT_TRUE(RoundTrip(&frame));
63 EXPECT_FALSE(frame);
64 }
65
66 TEST_F(VideoFrameStructTraitsTest, EOS) {
67 scoped_refptr<VideoFrame> frame = VideoFrame::CreateEOSFrame();
68
69 ASSERT_TRUE(RoundTrip(&frame));
70 ASSERT_TRUE(frame);
71 EXPECT_TRUE(frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
72 }
73
74 TEST_F(VideoFrameStructTraitsTest, MojoSharedBufferVideoFrame) {
75 scoped_refptr<VideoFrame> frame =
76 MojoSharedBufferVideoFrame::CreateDefaultI420(
77 gfx::Size(100, 100), base::TimeDelta::FromSeconds(100));
78
79 ASSERT_TRUE(RoundTrip(&frame));
80 ASSERT_TRUE(frame);
81 EXPECT_FALSE(frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
82 EXPECT_EQ(frame->coded_size(), gfx::Size(100, 100));
83 EXPECT_EQ(frame->timestamp(), base::TimeDelta::FromSeconds(100));
84
85 ASSERT_EQ(frame->storage_type(), VideoFrame::STORAGE_MOJO_SHARED_BUFFER);
86 MojoSharedBufferVideoFrame* mojo_shared_buffer_frame =
87 static_cast<MojoSharedBufferVideoFrame*>(frame.get());
88 EXPECT_TRUE(mojo_shared_buffer_frame->Handle().is_valid());
89 }
90
91 TEST_F(VideoFrameStructTraitsTest, MailboxVideoFrame) {
92 gpu::Mailbox mailbox = gpu::Mailbox::Generate();
93 gpu::MailboxHolder mailbox_holder[VideoFrame::kMaxPlanes];
94 mailbox_holder[0] = gpu::MailboxHolder(mailbox, gpu::SyncToken(), 0);
95 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures(
96 PIXEL_FORMAT_ARGB, mailbox_holder, VideoFrame::ReleaseMailboxCB(),
97 gfx::Size(100, 100), gfx::Rect(10, 10, 80, 80), gfx::Size(200, 100),
98 base::TimeDelta::FromSeconds(100));
99
100 ASSERT_TRUE(RoundTrip(&frame));
101 ASSERT_TRUE(frame);
102 EXPECT_FALSE(frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
103 EXPECT_EQ(frame->format(), PIXEL_FORMAT_ARGB);
104 EXPECT_EQ(frame->coded_size(), gfx::Size(100, 100));
105 EXPECT_EQ(frame->visible_rect(), gfx::Rect(10, 10, 80, 80));
106 EXPECT_EQ(frame->natural_size(), gfx::Size(200, 100));
107 EXPECT_EQ(frame->timestamp(), base::TimeDelta::FromSeconds(100));
108 ASSERT_TRUE(frame->HasTextures());
109 ASSERT_EQ(frame->mailbox_holder(0).mailbox, mailbox);
110 }
111
112 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698