Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/mojo/interfaces/video_frame_struct_traits.h" | 5 #include "media/mojo/interfaces/video_frame_struct_traits.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" | 11 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 media::mojom::VideoFrameDataPtr MakeVideoFrameData( | 17 media::mojom::VideoFrameDataPtr MakeVideoFrameData( |
| 18 const scoped_refptr<media::VideoFrame>& input) { | 18 const scoped_refptr<media::VideoFrame>& input) { |
| 19 // EOS frames contain no data. | 19 if (input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM)) { |
| 20 if (input->metadata()->IsTrue(media::VideoFrameMetadata::END_OF_STREAM)) | 20 return media::mojom::VideoFrameData::NewEosData( |
| 21 return nullptr; | 21 media::mojom::EosVideoFrameData::New()); |
| 22 } | |
| 22 | 23 |
| 23 if (input->storage_type() == media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { | 24 if (input->storage_type() == media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { |
| 24 media::MojoSharedBufferVideoFrame* mojo_frame = | 25 media::MojoSharedBufferVideoFrame* mojo_frame = |
| 25 static_cast<media::MojoSharedBufferVideoFrame*>(input.get()); | 26 static_cast<media::MojoSharedBufferVideoFrame*>(input.get()); |
| 26 | 27 |
| 27 mojo::ScopedSharedBufferHandle dup = mojo_frame->Handle().Clone(); | 28 mojo::ScopedSharedBufferHandle dup = mojo_frame->Handle().Clone(); |
| 28 DCHECK(dup.is_valid()); | 29 DCHECK(dup.is_valid()); |
| 29 | 30 |
| 30 return media::mojom::VideoFrameData::NewSharedBufferData( | 31 return media::mojom::VideoFrameData::NewSharedBufferData( |
| 31 media::mojom::SharedBufferVideoFrameData::New( | 32 media::mojom::SharedBufferVideoFrameData::New( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 80 |
| 80 // static | 81 // static |
| 81 bool StructTraits<media::mojom::VideoFrameDataView, | 82 bool StructTraits<media::mojom::VideoFrameDataView, |
| 82 scoped_refptr<media::VideoFrame>>:: | 83 scoped_refptr<media::VideoFrame>>:: |
| 83 Read(media::mojom::VideoFrameDataView input, | 84 Read(media::mojom::VideoFrameDataView input, |
| 84 scoped_refptr<media::VideoFrame>* output) { | 85 scoped_refptr<media::VideoFrame>* output) { |
| 85 // View of the |data| member of the input media::mojom::VideoFrame. | 86 // View of the |data| member of the input media::mojom::VideoFrame. |
| 86 media::mojom::VideoFrameDataDataView data; | 87 media::mojom::VideoFrameDataDataView data; |
| 87 input.GetDataDataView(&data); | 88 input.GetDataDataView(&data); |
| 88 | 89 |
| 89 DCHECK_EQ(input.end_of_stream(), data.is_null()); | 90 if (data.is_eos_data()) { |
| 90 if (input.end_of_stream()) { | |
| 91 *output = media::VideoFrame::CreateEOSFrame(); | 91 *output = media::VideoFrame::CreateEOSFrame(); |
| 92 return !!*output; | 92 return !!*output; |
| 93 } | 93 } |
| 94 | 94 |
| 95 media::VideoPixelFormat format; | 95 media::VideoPixelFormat format; |
| 96 if (!input.ReadFormat(&format)) | 96 if (!input.ReadFormat(&format)) |
| 97 return false; | 97 return false; |
| 98 | 98 |
| 99 gfx::Size coded_size; | 99 gfx::Size coded_size; |
| 100 if (!input.ReadCodedSize(&coded_size)) | 100 if (!input.ReadCodedSize(&coded_size)) |
| 101 return false; | 101 return false; |
| 102 | 102 |
| 103 gfx::Rect visible_rect; | 103 gfx::Rect visible_rect; |
| 104 if (!input.ReadVisibleRect(&visible_rect)) | 104 if (!input.ReadVisibleRect(&visible_rect)) |
| 105 return false; | 105 return false; |
| 106 | 106 |
| 107 // Coded size must contain the visible rect. | 107 // Ensure that |visible_rect| is contained inside |coded_size|. |
| 108 if (visible_rect.right() > coded_size.width() || | 108 visible_rect.Intersect(gfx::Rect(coded_size)); |
|
dcheng
2017/06/10 00:40:55
Hmm, the original code returned false in that case
sandersd (OOO until July 31)
2017/06/10 01:15:31
There is a trade-off here. Relevant facts:
- |v
| |
| 109 visible_rect.bottom() > coded_size.height()) { | |
| 110 return false; | |
| 111 } | |
| 112 | 109 |
| 113 gfx::Size natural_size; | 110 gfx::Size natural_size; |
| 114 if (!input.ReadNaturalSize(&natural_size)) | 111 if (!input.ReadNaturalSize(&natural_size)) |
| 115 return false; | 112 return false; |
| 116 | 113 |
| 117 base::TimeDelta timestamp; | 114 base::TimeDelta timestamp; |
| 118 if (!input.ReadTimestamp(×tamp)) | 115 if (!input.ReadTimestamp(×tamp)) |
| 119 return false; | 116 return false; |
| 120 | 117 |
| 121 if (data.is_shared_buffer_data()) { | 118 if (data.is_shared_buffer_data()) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 152 coded_size, visible_rect, natural_size, timestamp); | 149 coded_size, visible_rect, natural_size, timestamp); |
| 153 return !!*output; | 150 return !!*output; |
| 154 } | 151 } |
| 155 | 152 |
| 156 // TODO(sandersd): Switch on the union tag to avoid this ugliness? | 153 // TODO(sandersd): Switch on the union tag to avoid this ugliness? |
| 157 NOTREACHED(); | 154 NOTREACHED(); |
| 158 return false; | 155 return false; |
| 159 } | 156 } |
| 160 | 157 |
| 161 } // namespace mojo | 158 } // namespace mojo |
| OLD | NEW |