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

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

Issue 2908303003: media: Create Mojo StructTraits for VideoFrame (Closed)
Patch Set: Code formatting. 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/logging.h"
8 #include "media/mojo/common/mojo_shared_buffer_video_frame.h"
9
10 namespace mojo {
11
12 // static
13 template <>
14 media::mojom::VideoFrameDataPtr StructTraits<media::mojom::VideoFrameDataView,
15 scoped_refptr<media::VideoFrame>>::
16 data(const scoped_refptr<media::VideoFrame>& input) {
dcheng 2017/06/05 20:33:01 I think we'll need to use a context object for thi
sandersd (OOO until July 31) 2017/06/05 20:46:13 Ack :-(
sandersd (OOO until July 31) 2017/06/06 01:05:47 I was unable to make this work because a SharedBuf
dcheng 2017/06/08 09:41:08 Hmm... so I guess this is tricky. Out of curiosity
yzshen1 2017/06/08 17:45:14 Daniel is right that we should probably put this i
sandersd (OOO until July 31) 2017/06/08 20:10:09 Done.
17 // EOS frames contain no data.
18 if (input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM))
19 return nullptr;
20
21 if (input->storage_type() == media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER) {
22 media::MojoSharedBufferVideoFrame* mojo_frame =
23 static_cast<media::MojoSharedBufferVideoFrame*>(input.get());
24
25 // TODO(jrummell): Should this really be a writable clone?
26 mojo::ScopedSharedBufferHandle duplicated_handle =
27 mojo_frame->Handle().Clone();
28 DCHECK(duplicated_handle.is_valid());
29
30 return media::mojom::VideoFrameData::NewSharedBufferData(
31 media::mojom::SharedBufferVideoFrameData::New(
32 std::move(duplicated_handle), mojo_frame->MappedSize(),
33 mojo_frame->stride(media::VideoFrame::kYPlane),
34 mojo_frame->stride(media::VideoFrame::kUPlane),
35 mojo_frame->stride(media::VideoFrame::kVPlane),
36 mojo_frame->PlaneOffset(media::VideoFrame::kYPlane),
37 mojo_frame->PlaneOffset(media::VideoFrame::kUPlane),
38 mojo_frame->PlaneOffset(media::VideoFrame::kVPlane)));
39 }
40
41 if (input->HasTextures()) {
42 // TODO(sandersd): Friend VideoFrame so that we can access the array?
43 std::vector<gpu::MailboxHolder> mailbox_holder(
44 media::VideoFrame::kMaxPlanes);
45 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; i++)
46 mailbox_holder.push_back(input->mailbox_holder(i));
47 return media::mojom::VideoFrameData::NewMailboxData(
48 media::mojom::MailboxVideoFrameData::New(std::move(mailbox_holder)));
49 }
50
51 NOTREACHED() << "Unsupported VideoFrame conversion";
52 return nullptr;
53 }
54
55 // static
56 template <>
57 bool StructTraits<media::mojom::VideoFrameDataView,
58 scoped_refptr<media::VideoFrame>>::
59 Read(media::mojom::VideoFrameDataView input,
60 scoped_refptr<media::VideoFrame>* output) {
61 // View of the |data| member of the input media::mojom::VideoFrame.
62 media::mojom::VideoFrameDataDataView data;
63 input.GetDataDataView(&data);
64
65 DCHECK_EQ(input.end_of_stream(), data.is_null());
66 if (input.end_of_stream()) {
67 *output = media::VideoFrame::CreateEOSFrame();
68 return true;
69 }
70
71 media::VideoPixelFormat format;
72 if (!input.ReadFormat(&format))
73 return false;
74
75 gfx::Size coded_size;
76 if (!input.ReadCodedSize(&coded_size))
77 return false;
78
79 gfx::Rect visible_rect;
80 if (!input.ReadVisibleRect(&visible_rect))
81 return false;
82
83 gfx::Size natural_size;
84 if (!input.ReadNaturalSize(&natural_size))
85 return false;
86
87 base::TimeDelta timestamp;
88 if (!input.ReadTimestamp(&timestamp))
89 return false;
90
91 if (data.is_shared_buffer_data()) {
92 media::mojom::SharedBufferVideoFrameDataDataView shared_buffer_data;
93 data.GetSharedBufferDataDataView(&shared_buffer_data);
94
95 *output = media::MojoSharedBufferVideoFrame::Create(
96 format, coded_size, visible_rect, natural_size,
97 shared_buffer_data.TakeFrameData(),
98 shared_buffer_data.frame_data_size(), shared_buffer_data.y_offset(),
dcheng 2017/06/05 20:33:01 Do we need to do any basic range checking here?
sandersd (OOO until July 31) 2017/06/06 01:05:47 This should be checked by media::MojoSharedBufferV
99 shared_buffer_data.u_offset(), shared_buffer_data.v_offset(),
100 shared_buffer_data.y_stride(), shared_buffer_data.u_stride(),
101 shared_buffer_data.v_stride(), timestamp);
102 return true;
103 }
104
105 if (data.is_mailbox_data()) {
106 media::mojom::MailboxVideoFrameDataDataView mailbox_data;
107 data.GetMailboxDataDataView(&mailbox_data);
108
109 std::vector<gpu::MailboxHolder> mailbox_holder;
110 if (!mailbox_data.ReadMailboxHolder(&mailbox_holder))
111 return false;
112
113 DCHECK_EQ(mailbox_holder.size(), media::VideoFrame::kMaxPlanes);
114 gpu::MailboxHolder mailbox_holder_array[media::VideoFrame::kMaxPlanes];
115 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; i++)
116 mailbox_holder_array[i] = mailbox_holder[i];
117
118 *output = media::VideoFrame::WrapNativeTextures(
119 format, mailbox_holder_array, media::VideoFrame::ReleaseMailboxCB(),
120 coded_size, visible_rect, natural_size, timestamp);
dcheng 2017/06/05 20:33:01 Similar question about range checks here--anything
sandersd (OOO until July 31) 2017/06/06 01:05:47 This one is fine. I added a check for visible_rect
121 return true;
122 }
123
124 // TODO(sandersd): Switch on the union tag to avoid this ugliness?
125 NOTREACHED();
126 return false;
127 }
128
129 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698