Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef MEDIA_MOJO_INTERFACES_VIDEO_FRAME_STRUCT_TRAITS_H_ | |
| 6 #define MEDIA_MOJO_INTERFACES_VIDEO_FRAME_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "media/base/video_frame.h" | |
| 11 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" | |
| 12 #include "media/mojo/interfaces/media_types.mojom.h" | |
| 13 #include "mojo/public/cpp/bindings/struct_traits.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 | |
| 17 template <> | |
| 18 struct StructTraits<media::mojom::VideoFrameDataView, | |
| 19 scoped_refptr<media::VideoFrame>> { | |
| 20 static bool IsNull(const scoped_refptr<media::VideoFrame>& input) { | |
| 21 return !!input; | |
| 22 } | |
| 23 | |
| 24 static void SetToNull(scoped_refptr<media::VideoFrame>* input) { | |
| 25 *input = nullptr; | |
| 26 } | |
| 27 | |
| 28 static media::VideoPixelFormat format( | |
| 29 const scoped_refptr<media::VideoFrame>& input) { | |
| 30 return input->format(); | |
| 31 } | |
| 32 | |
| 33 static gfx::Size coded_size(const scoped_refptr<media::VideoFrame>& input) { | |
|
dcheng
2017/06/05 20:33:02
Nit: return non-trivial types by const ref: due to
sandersd (OOO until July 31)
2017/06/06 01:05:47
This is the first time I've heard gfx::Size referr
| |
| 34 return input->coded_size(); | |
| 35 } | |
| 36 | |
| 37 static gfx::Rect visible_rect(const scoped_refptr<media::VideoFrame>& input) { | |
| 38 return input->visible_rect(); | |
| 39 } | |
| 40 | |
| 41 static gfx::Size natural_size(const scoped_refptr<media::VideoFrame>& input) { | |
| 42 return input->natural_size(); | |
| 43 } | |
| 44 | |
| 45 static bool end_of_stream(const scoped_refptr<media::VideoFrame>& input) { | |
| 46 return input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM); | |
|
dcheng
2017/06/05 20:33:01
I'm assuming this is a cheap calculation (otherwis
sandersd (OOO until July 31)
2017/06/05 20:46:13
This one should be fine.
| |
| 47 } | |
| 48 | |
| 49 static base::TimeDelta timestamp( | |
|
dcheng
2017/06/05 20:33:01
But returning base::Time* by value is fine.
sandersd (OOO until July 31)
2017/06/06 01:05:47
Acknowledged.
| |
| 50 const scoped_refptr<media::VideoFrame>& input) { | |
| 51 return input->timestamp(); | |
| 52 } | |
| 53 | |
| 54 static media::mojom::VideoFrameDataPtr data( | |
| 55 const scoped_refptr<media::VideoFrame>& input) { | |
|
dcheng
2017/06/05 20:33:02
Hmm, isn't this in the .cc as well? I'm assuming t
sandersd (OOO until July 31)
2017/06/05 20:46:13
Yes, it is, but they should have identical content
| |
| 56 // EOS frames contain no data. | |
| 57 if (input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM)) | |
| 58 return nullptr; | |
| 59 | |
| 60 if (input->storage_type() == | |
| 61 media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { | |
| 62 media::MojoSharedBufferVideoFrame* mojo_frame = | |
| 63 static_cast<media::MojoSharedBufferVideoFrame*>(input.get()); | |
| 64 | |
| 65 // TODO(jrummell): Should this really be a writable clone? | |
| 66 mojo::ScopedSharedBufferHandle duplicated_handle = | |
| 67 mojo_frame->Handle().Clone(); | |
| 68 DCHECK(duplicated_handle.is_valid()); | |
| 69 | |
| 70 return media::mojom::VideoFrameData::NewSharedBufferData( | |
| 71 media::mojom::SharedBufferVideoFrameData::New( | |
| 72 std::move(duplicated_handle), mojo_frame->MappedSize(), | |
| 73 mojo_frame->stride(media::VideoFrame::kYPlane), | |
| 74 mojo_frame->stride(media::VideoFrame::kUPlane), | |
| 75 mojo_frame->stride(media::VideoFrame::kVPlane), | |
| 76 mojo_frame->PlaneOffset(media::VideoFrame::kYPlane), | |
| 77 mojo_frame->PlaneOffset(media::VideoFrame::kUPlane), | |
| 78 mojo_frame->PlaneOffset(media::VideoFrame::kVPlane))); | |
| 79 } | |
| 80 | |
| 81 if (input->HasTextures()) { | |
| 82 // TODO(sandersd): Friend VideoFrame so that we can access the array? | |
| 83 std::vector<gpu::MailboxHolder> mailbox_holder( | |
| 84 media::VideoFrame::kMaxPlanes); | |
| 85 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; i++) | |
| 86 mailbox_holder.push_back(input->mailbox_holder(i)); | |
| 87 return media::mojom::VideoFrameData::NewMailboxData( | |
| 88 media::mojom::MailboxVideoFrameData::New(std::move(mailbox_holder))); | |
| 89 } | |
| 90 | |
| 91 NOTREACHED() << "Unsupported VideoFrame conversion"; | |
| 92 return nullptr; | |
| 93 } | |
| 94 | |
| 95 static bool Read(media::mojom::VideoFrameDataView input, | |
|
dcheng
2017/06/05 20:33:02
Ditto.
sandersd (OOO until July 31)
2017/06/06 01:05:47
Acknowledged.
| |
| 96 scoped_refptr<media::VideoFrame>* output) { | |
| 97 // View of the |data| member of the input media::mojom::VideoFrame. | |
| 98 media::mojom::VideoFrameDataDataView data; | |
| 99 input.GetDataDataView(&data); | |
| 100 | |
| 101 DCHECK_EQ(input.end_of_stream(), data.is_null()); | |
| 102 if (input.end_of_stream()) { | |
| 103 *output = media::VideoFrame::CreateEOSFrame(); | |
| 104 return true; | |
| 105 } | |
| 106 | |
| 107 media::VideoPixelFormat format; | |
| 108 if (!input.ReadFormat(&format)) | |
| 109 return false; | |
| 110 | |
| 111 gfx::Size coded_size; | |
| 112 if (!input.ReadCodedSize(&coded_size)) | |
| 113 return false; | |
| 114 | |
| 115 gfx::Rect visible_rect; | |
| 116 if (!input.ReadVisibleRect(&visible_rect)) | |
| 117 return false; | |
| 118 | |
| 119 gfx::Size natural_size; | |
| 120 if (!input.ReadNaturalSize(&natural_size)) | |
| 121 return false; | |
| 122 | |
| 123 base::TimeDelta timestamp; | |
| 124 if (!input.ReadTimestamp(×tamp)) | |
| 125 return false; | |
| 126 | |
| 127 if (data.is_shared_buffer_data()) { | |
| 128 media::mojom::SharedBufferVideoFrameDataDataView shared_buffer_data; | |
| 129 data.GetSharedBufferDataDataView(&shared_buffer_data); | |
| 130 | |
| 131 *output = media::MojoSharedBufferVideoFrame::Create( | |
| 132 format, coded_size, visible_rect, natural_size, | |
| 133 shared_buffer_data.TakeFrameData(), | |
| 134 shared_buffer_data.frame_data_size(), shared_buffer_data.y_offset(), | |
| 135 shared_buffer_data.u_offset(), shared_buffer_data.v_offset(), | |
| 136 shared_buffer_data.y_stride(), shared_buffer_data.u_stride(), | |
| 137 shared_buffer_data.v_stride(), timestamp); | |
| 138 return true; | |
| 139 } | |
| 140 | |
| 141 if (data.is_mailbox_data()) { | |
| 142 media::mojom::MailboxVideoFrameDataDataView mailbox_data; | |
| 143 data.GetMailboxDataDataView(&mailbox_data); | |
| 144 | |
| 145 std::vector<gpu::MailboxHolder> mailbox_holder; | |
| 146 if (!mailbox_data.ReadMailboxHolder(&mailbox_holder)) | |
| 147 return false; | |
| 148 | |
| 149 DCHECK_EQ(mailbox_holder.size(), media::VideoFrame::kMaxPlanes); | |
| 150 gpu::MailboxHolder mailbox_holder_array[media::VideoFrame::kMaxPlanes]; | |
| 151 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; i++) | |
| 152 mailbox_holder_array[i] = mailbox_holder[i]; | |
| 153 | |
| 154 *output = media::VideoFrame::WrapNativeTextures( | |
| 155 format, mailbox_holder_array, media::VideoFrame::ReleaseMailboxCB(), | |
| 156 coded_size, visible_rect, natural_size, timestamp); | |
| 157 return true; | |
| 158 } | |
| 159 | |
| 160 // TODO(sandersd): Switch on the union tag to avoid this ugliness? | |
| 161 NOTREACHED(); | |
| 162 return false; | |
| 163 } | |
| 164 }; | |
| 165 | |
| 166 } // namespace mojo | |
| 167 | |
| 168 #endif // MEDIA_MOJO_INTERFACES_VIDEO_FRAME_STRUCT_TRAITS_H_ | |
| OLD | NEW |