Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/common/mojo_video_frame.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "build/build_config.h" | |
|
mcasas
2016/02/25 15:12:35
Needed?
jrummell
2016/02/25 21:51:47
Nope. Removed.
| |
| 10 | |
| 11 namespace media { | |
| 12 | |
| 13 // static | |
| 14 scoped_refptr<MojoVideoFrame> MojoVideoFrame::Create( | |
| 15 const gfx::Size& dimensions, | |
| 16 base::TimeDelta timestamp) { | |
| 17 const StorageType storage_type = STORAGE_MOJO_SHARED_MEMORY; | |
| 18 const VideoPixelFormat format = PIXEL_FORMAT_I420; | |
| 19 gfx::Rect visible_rect(dimensions); | |
| 20 if (!IsValidConfig(format, storage_type, dimensions, visible_rect, | |
| 21 dimensions)) { | |
| 22 LOG(DFATAL) << __FUNCTION__ << " Invalid config." | |
|
mcasas
2016/02/25 15:12:35
nit: space before closing |"|
jrummell
2016/02/25 21:51:47
Done.
| |
| 23 << ConfigToString(format, storage_type, dimensions, | |
| 24 visible_rect, dimensions); | |
| 25 return nullptr; | |
| 26 } | |
| 27 | |
| 28 // Allocate a shared memory buffer big enough to hold the desired frame. | |
| 29 size_t requested_size = VideoFrame::AllocationSize(format, dimensions); | |
| 30 mojo::ScopedSharedBufferHandle handle; | |
| 31 MojoResult result = | |
|
mcasas
2016/02/25 15:12:35
nit: const ?
jrummell
2016/02/25 21:51:48
Done.
| |
| 32 mojo::CreateSharedBuffer(nullptr, requested_size, &handle); | |
| 33 if (result != MOJO_RESULT_OK) | |
| 34 return nullptr; | |
| 35 | |
| 36 // Now allocate the frame and initialize it. | |
| 37 scoped_refptr<MojoVideoFrame> frame(new MojoVideoFrame( | |
| 38 format, storage_type, dimensions, visible_rect, dimensions, | |
| 39 std::move(handle), requested_size, timestamp)); | |
| 40 if (!frame->Init(dimensions.width(), dimensions.width() / 2, | |
| 41 dimensions.width() / 2, 0 /* y_offset */, | |
| 42 dimensions.GetArea(), dimensions.GetArea() * 5 / 4)) | |
| 43 return nullptr; | |
| 44 | |
| 45 return frame; | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 scoped_refptr<MojoVideoFrame> MojoVideoFrame::Create( | |
| 50 VideoPixelFormat format, | |
| 51 const gfx::Size& coded_size, | |
| 52 const gfx::Rect& visible_rect, | |
| 53 const gfx::Size& natural_size, | |
| 54 mojo::SharedBufferHandle handle, | |
| 55 size_t data_size, | |
| 56 size_t y_offset, | |
| 57 size_t u_offset, | |
| 58 size_t v_offset, | |
| 59 int32_t y_stride, | |
| 60 int32_t u_stride, | |
| 61 int32_t v_stride, | |
| 62 base::TimeDelta timestamp) { | |
| 63 const StorageType storage_type = STORAGE_MOJO_SHARED_MEMORY; | |
|
mcasas
2016/02/25 15:12:35
Since |storage_type| is always the same in
this fi
jrummell
2016/02/25 21:51:48
Done.
| |
| 64 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, | |
| 65 natural_size)) { | |
| 66 LOG(DFATAL) << __FUNCTION__ << " Invalid config." | |
| 67 << ConfigToString(format, storage_type, coded_size, | |
| 68 visible_rect, natural_size); | |
| 69 return nullptr; | |
| 70 } | |
| 71 | |
| 72 // Make a copy of the shared memory handle. | |
| 73 mojo::ScopedSharedBufferHandle duplicated_handle; | |
| 74 MojoResult result = | |
| 75 mojo::DuplicateBuffer(handle, nullptr, &duplicated_handle); | |
| 76 if (result != MOJO_RESULT_OK) | |
| 77 return nullptr; | |
| 78 | |
| 79 // Now allocate the frame and initialize it. | |
| 80 scoped_refptr<MojoVideoFrame> frame(new MojoVideoFrame( | |
| 81 format, storage_type, coded_size, visible_rect, natural_size, | |
| 82 std::move(duplicated_handle), data_size, timestamp)); | |
| 83 if (!frame->Init(y_stride, u_stride, v_stride, y_offset, u_offset, v_offset)) | |
| 84 return nullptr; | |
| 85 | |
| 86 return frame; | |
| 87 } | |
| 88 | |
| 89 MojoVideoFrame::MojoVideoFrame(VideoPixelFormat format, | |
| 90 StorageType storage_type, | |
|
mcasas
2016/02/25 15:12:35
This parameter is not needed since is always
the
jrummell
2016/02/25 21:51:48
Done.
| |
| 91 const gfx::Size& coded_size, | |
| 92 const gfx::Rect& visible_rect, | |
| 93 const gfx::Size& natural_size, | |
|
mcasas
2016/02/25 15:12:35
IIRC the only case of |natural_size| being
differe
jrummell
2016/02/25 21:51:48
I talked with xhwang@. Apparently both Netflix and
| |
| 94 mojo::ScopedSharedBufferHandle handle, | |
| 95 size_t mapped_size, | |
| 96 base::TimeDelta timestamp) | |
| 97 : VideoFrame(format, | |
| 98 storage_type, | |
| 99 coded_size, | |
| 100 visible_rect, | |
| 101 natural_size, | |
| 102 timestamp), | |
| 103 shared_buffer_handle_(std::move(handle)), | |
| 104 shared_buffer_size_(mapped_size) { | |
| 105 DCHECK(shared_buffer_handle_.is_valid()); | |
| 106 } | |
| 107 | |
| 108 bool MojoVideoFrame::Init(int32_t y_stride, | |
| 109 int32_t u_stride, | |
| 110 int32_t v_stride, | |
| 111 size_t y_offset, | |
| 112 size_t u_offset, | |
| 113 size_t v_offset) { | |
| 114 uint8_t* frame_data = nullptr; | |
| 115 MojoResult result = mojo::MapBuffer( | |
|
mcasas
2016/02/25 15:12:35
const.
jrummell
2016/02/25 21:51:47
Done.
| |
| 116 shared_buffer_handle_.get(), 0 /* offset */, shared_buffer_size_, | |
| 117 reinterpret_cast<void**>(&frame_data), MOJO_MAP_BUFFER_FLAG_NONE); | |
| 118 if (result != MOJO_RESULT_OK || !frame_data) | |
| 119 return false; | |
| 120 | |
| 121 set_stride(kYPlane, y_stride); | |
| 122 set_stride(kUPlane, u_stride); | |
| 123 set_stride(kVPlane, v_stride); | |
| 124 offsets_[kYPlane] = y_offset; | |
| 125 offsets_[kUPlane] = u_offset; | |
| 126 offsets_[kVPlane] = v_offset; | |
| 127 set_data(kYPlane, frame_data + y_offset); | |
| 128 set_data(kUPlane, frame_data + u_offset); | |
| 129 set_data(kVPlane, frame_data + v_offset); | |
| 130 return true; | |
| 131 } | |
| 132 | |
| 133 MojoVideoFrame::~MojoVideoFrame() {} | |
| 134 | |
| 135 mojo::SharedBufferHandle MojoVideoFrame::handle() const { | |
| 136 return shared_buffer_handle_.get(); | |
| 137 } | |
| 138 | |
| 139 size_t MojoVideoFrame::mapped_size() const { | |
| 140 return shared_buffer_size_; | |
| 141 } | |
| 142 | |
| 143 size_t MojoVideoFrame::plane_offset(size_t plane) const { | |
| 144 DCHECK(IsValidPlane(plane, format())); | |
| 145 return offsets_[plane]; | |
| 146 } | |
| 147 | |
| 148 } // namespace media | |
| OLD | NEW |