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