| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ | 5 #ifndef MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ |
| 6 #define MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ | 6 #define MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 14 #include "mojo/public/cpp/system/buffer.h" | 14 #include "mojo/public/cpp/system/buffer.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 | 17 |
| 18 namespace mojo { | |
| 19 template <typename T, typename U> | |
| 20 struct TypeConverter; | |
| 21 template <typename T> | |
| 22 class StructPtr; | |
| 23 }; | |
| 24 | |
| 25 namespace media { | 18 namespace media { |
| 26 | 19 |
| 27 namespace interfaces { | |
| 28 class VideoFrame; | |
| 29 } | |
| 30 | |
| 31 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle | 20 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle |
| 32 // which is mapped on constructor and remains so for the lifetime of the | 21 // which is mapped on constructor and remains so for the lifetime of the |
| 33 // object. These frames are ref-counted. | 22 // object. These frames are ref-counted. |
| 34 class MojoSharedBufferVideoFrame : public VideoFrame { | 23 class MojoSharedBufferVideoFrame : public VideoFrame { |
| 35 public: | 24 public: |
| 36 // Creates a new I420 frame in shared memory with provided parameters | 25 // Creates a new I420 frame in shared memory with provided parameters |
| 37 // (coded_size() == natural_size() == visible_rect()), or returns nullptr. | 26 // (coded_size() == natural_size() == visible_rect()), or returns nullptr. |
| 38 // Buffers for the frame are allocated but not initialized. The caller must | 27 // Buffers for the frame are allocated but not initialized. The caller must |
| 39 // not make assumptions about the actual underlying sizes, but check the | 28 // not make assumptions about the actual underlying sizes, but check the |
| 40 // returned VideoFrame instead. | 29 // returned VideoFrame instead. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 int32_t y_stride, | 46 int32_t y_stride, |
| 58 int32_t u_stride, | 47 int32_t u_stride, |
| 59 int32_t v_stride, | 48 int32_t v_stride, |
| 60 base::TimeDelta timestamp); | 49 base::TimeDelta timestamp); |
| 61 | 50 |
| 62 // Returns the offsets relative to the start of |shared_buffer| for the | 51 // Returns the offsets relative to the start of |shared_buffer| for the |
| 63 // |plane| specified. | 52 // |plane| specified. |
| 64 size_t PlaneOffset(size_t plane) const; | 53 size_t PlaneOffset(size_t plane) const; |
| 65 | 54 |
| 66 private: | 55 private: |
| 67 // mojo::TypeConverter added as a friend so that MojoSharedBufferVideoFrame | |
| 68 // can be transferred across a mojo connection. | |
| 69 friend struct mojo::TypeConverter<mojo::StructPtr<interfaces::VideoFrame>, | |
| 70 scoped_refptr<VideoFrame>>; | |
| 71 | |
| 72 MojoSharedBufferVideoFrame(VideoPixelFormat format, | 56 MojoSharedBufferVideoFrame(VideoPixelFormat format, |
| 73 const gfx::Size& coded_size, | 57 const gfx::Size& coded_size, |
| 74 const gfx::Rect& visible_rect, | 58 const gfx::Rect& visible_rect, |
| 75 const gfx::Size& natural_size, | 59 const gfx::Size& natural_size, |
| 76 mojo::ScopedSharedBufferHandle handle, | 60 mojo::ScopedSharedBufferHandle handle, |
| 77 size_t mapped_size, | 61 size_t mapped_size, |
| 78 base::TimeDelta timestamp); | 62 base::TimeDelta timestamp); |
| 79 ~MojoSharedBufferVideoFrame() override; | 63 ~MojoSharedBufferVideoFrame() override; |
| 80 | 64 |
| 81 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto | 65 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto |
| 82 // the shared memory, and then setting the strides and offsets as specified. | 66 // the shared memory, and then setting the strides and offsets as specified. |
| 83 bool Init(int32_t y_stride, | 67 bool Init(int32_t y_stride, |
| 84 int32_t u_stride, | 68 int32_t u_stride, |
| 85 int32_t v_stride, | 69 int32_t v_stride, |
| 86 size_t y_offset, | 70 size_t y_offset, |
| 87 size_t u_offset, | 71 size_t u_offset, |
| 88 size_t v_offset); | 72 size_t v_offset); |
| 89 | 73 |
| 90 // Returns the mojo shared memory handle. This object continues to own the | |
| 91 // handle. Caller should call duplicate the handle if they want to keep a | |
| 92 // copy of the shared memory. | |
| 93 const mojo::SharedBufferHandle& Handle() const; | |
| 94 | |
| 95 // Returns the size of the shared memory. | |
| 96 size_t MappedSize() const; | |
| 97 | |
| 98 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 74 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
| 99 size_t shared_buffer_size_; | 75 size_t shared_buffer_size_; |
| 100 uint8_t* shared_buffer_data_; | 76 uint8_t* shared_buffer_data_; |
| 101 size_t offsets_[kMaxPlanes]; | 77 size_t offsets_[kMaxPlanes]; |
| 102 | 78 |
| 103 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); | 79 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); |
| 104 }; | 80 }; |
| 105 | 81 |
| 106 } // namespace media | 82 } // namespace media |
| 107 | 83 |
| 108 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ | 84 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ |
| OLD | NEW |