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/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
15 #include "mojo/public/cpp/system/buffer.h" | 15 #include "mojo/public/cpp/system/buffer.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
18 | 18 |
19 namespace mojo { | |
20 template <typename T, typename U> | |
21 struct TypeConverter; | |
22 template <typename T> | |
23 class StructPtr; | |
24 }; | |
25 | |
26 namespace media { | 19 namespace media { |
27 | 20 |
28 namespace mojom { | |
29 class VideoFrame; | |
30 } | |
31 | |
32 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle | 21 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle |
33 // which is mapped on constructor and remains so for the lifetime of the | 22 // which is mapped on constructor and remains so for the lifetime of the |
34 // object. These frames are ref-counted. | 23 // object. These frames are ref-counted. |
35 class MojoSharedBufferVideoFrame : public VideoFrame { | 24 class MojoSharedBufferVideoFrame : public VideoFrame { |
36 public: | 25 public: |
37 // Callback called when this object is destructed. Ownership of the shared | 26 // Callback called when this object is destructed. Ownership of the shared |
38 // memory is transferred to the callee. | 27 // memory is transferred to the callee. |
39 using MojoSharedBufferDoneCB = | 28 using MojoSharedBufferDoneCB = |
40 base::Callback<void(mojo::ScopedSharedBufferHandle buffer, | 29 base::Callback<void(mojo::ScopedSharedBufferHandle buffer, |
41 size_t capacity)>; | 30 size_t capacity)>; |
(...skipping 23 matching lines...) Expand all Loading... |
65 size_t v_offset, | 54 size_t v_offset, |
66 int32_t y_stride, | 55 int32_t y_stride, |
67 int32_t u_stride, | 56 int32_t u_stride, |
68 int32_t v_stride, | 57 int32_t v_stride, |
69 base::TimeDelta timestamp); | 58 base::TimeDelta timestamp); |
70 | 59 |
71 // Returns the offsets relative to the start of |shared_buffer| for the | 60 // Returns the offsets relative to the start of |shared_buffer| for the |
72 // |plane| specified. | 61 // |plane| specified. |
73 size_t PlaneOffset(size_t plane) const; | 62 size_t PlaneOffset(size_t plane) const; |
74 | 63 |
| 64 // Returns a reference to the mojo shared memory handle. Caller should |
| 65 // duplicate the handle if they want to extend the lifetime of the buffer. |
| 66 const mojo::SharedBufferHandle& Handle() const; |
| 67 |
| 68 // Returns the size of the shared memory. |
| 69 size_t MappedSize() const; |
| 70 |
75 // Sets the callback to be called to free the shared buffer. If not null, | 71 // Sets the callback to be called to free the shared buffer. If not null, |
76 // it is called on destruction, and is passed ownership of |handle|. | 72 // it is called on destruction, and is passed ownership of |handle|. |
77 void SetMojoSharedBufferDoneCB( | 73 void SetMojoSharedBufferDoneCB( |
78 const MojoSharedBufferDoneCB& mojo_shared_buffer_done_cb); | 74 const MojoSharedBufferDoneCB& mojo_shared_buffer_done_cb); |
79 | 75 |
80 private: | 76 private: |
81 // mojo::TypeConverter added as a friend so that MojoSharedBufferVideoFrame | |
82 // can be transferred across a mojo connection. | |
83 friend struct mojo::TypeConverter<mojo::StructPtr<mojom::VideoFrame>, | |
84 scoped_refptr<VideoFrame>>; | |
85 friend class MojoDecryptorService; | 77 friend class MojoDecryptorService; |
86 | 78 |
87 MojoSharedBufferVideoFrame(VideoPixelFormat format, | 79 MojoSharedBufferVideoFrame(VideoPixelFormat format, |
88 const gfx::Size& coded_size, | 80 const gfx::Size& coded_size, |
89 const gfx::Rect& visible_rect, | 81 const gfx::Rect& visible_rect, |
90 const gfx::Size& natural_size, | 82 const gfx::Size& natural_size, |
91 mojo::ScopedSharedBufferHandle handle, | 83 mojo::ScopedSharedBufferHandle handle, |
92 size_t mapped_size, | 84 size_t mapped_size, |
93 base::TimeDelta timestamp); | 85 base::TimeDelta timestamp); |
94 ~MojoSharedBufferVideoFrame() override; | 86 ~MojoSharedBufferVideoFrame() override; |
95 | 87 |
96 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto | 88 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto |
97 // the shared memory, and then setting the strides and offsets as specified. | 89 // the shared memory, and then setting the strides and offsets as specified. |
98 bool Init(int32_t y_stride, | 90 bool Init(int32_t y_stride, |
99 int32_t u_stride, | 91 int32_t u_stride, |
100 int32_t v_stride, | 92 int32_t v_stride, |
101 size_t y_offset, | 93 size_t y_offset, |
102 size_t u_offset, | 94 size_t u_offset, |
103 size_t v_offset); | 95 size_t v_offset); |
104 | 96 |
105 // Returns the mojo shared memory handle. This object continues to own the | |
106 // handle. Caller should call duplicate the handle if they want to keep a | |
107 // copy of the shared memory. | |
108 const mojo::SharedBufferHandle& Handle() const; | |
109 | |
110 // Returns the size of the shared memory. | |
111 size_t MappedSize() const; | |
112 | |
113 uint8_t* shared_buffer_data() { | 97 uint8_t* shared_buffer_data() { |
114 return reinterpret_cast<uint8_t*>(shared_buffer_mapping_.get()); | 98 return reinterpret_cast<uint8_t*>(shared_buffer_mapping_.get()); |
115 }; | 99 }; |
116 | 100 |
117 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 101 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
118 mojo::ScopedSharedBufferMapping shared_buffer_mapping_; | 102 mojo::ScopedSharedBufferMapping shared_buffer_mapping_; |
119 size_t shared_buffer_size_; | 103 size_t shared_buffer_size_; |
120 size_t offsets_[kMaxPlanes]; | 104 size_t offsets_[kMaxPlanes]; |
121 MojoSharedBufferDoneCB mojo_shared_buffer_done_cb_; | 105 MojoSharedBufferDoneCB mojo_shared_buffer_done_cb_; |
122 | 106 |
123 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); | 107 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); |
124 }; | 108 }; |
125 | 109 |
126 } // namespace media | 110 } // namespace media |
127 | 111 |
128 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ | 112 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ |
OLD | NEW |