Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: media/mojo/common/mojo_shared_buffer_video_frame.h

Issue 1769673002: Transfer media::VideoFrame using mojo shared memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
18 namespace media { 25 namespace media {
19 26
27 namespace interfaces {
28 class VideoFrame;
29 }
30
20 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle 31 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle
21 // which is mapped on constructor and remains so for the lifetime of the 32 // which is mapped on constructor and remains so for the lifetime of the
22 // object. These frames are ref-counted. 33 // object. These frames are ref-counted.
23 class MojoSharedBufferVideoFrame : public VideoFrame { 34 class MojoSharedBufferVideoFrame : public VideoFrame {
24 public: 35 public:
25 // Creates a new I420 frame in shared memory with provided parameters 36 // Creates a new I420 frame in shared memory with provided parameters
26 // (coded_size() == natural_size() == visible_rect()), or returns nullptr. 37 // (coded_size() == natural_size() == visible_rect()), or returns nullptr.
27 // Buffers for the frame are allocated but not initialized. The caller must 38 // Buffers for the frame are allocated but not initialized. The caller must
28 // not make assumptions about the actual underlying sizes, but check the 39 // not make assumptions about the actual underlying sizes, but check the
29 // returned VideoFrame instead. 40 // returned VideoFrame instead.
(...skipping 16 matching lines...) Expand all
46 int32_t y_stride, 57 int32_t y_stride,
47 int32_t u_stride, 58 int32_t u_stride,
48 int32_t v_stride, 59 int32_t v_stride,
49 base::TimeDelta timestamp); 60 base::TimeDelta timestamp);
50 61
51 // Returns the offsets relative to the start of |shared_buffer| for the 62 // Returns the offsets relative to the start of |shared_buffer| for the
52 // |plane| specified. 63 // |plane| specified.
53 size_t PlaneOffset(size_t plane) const; 64 size_t PlaneOffset(size_t plane) const;
54 65
55 private: 66 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
56 MojoSharedBufferVideoFrame(VideoPixelFormat format, 72 MojoSharedBufferVideoFrame(VideoPixelFormat format,
57 const gfx::Size& coded_size, 73 const gfx::Size& coded_size,
58 const gfx::Rect& visible_rect, 74 const gfx::Rect& visible_rect,
59 const gfx::Size& natural_size, 75 const gfx::Size& natural_size,
60 mojo::ScopedSharedBufferHandle handle, 76 mojo::ScopedSharedBufferHandle handle,
61 size_t mapped_size, 77 size_t mapped_size,
62 base::TimeDelta timestamp); 78 base::TimeDelta timestamp);
63 ~MojoSharedBufferVideoFrame() override; 79 ~MojoSharedBufferVideoFrame() override;
64 80
65 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto 81 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto
66 // the shared memory, and then setting the strides and offsets as specified. 82 // the shared memory, and then setting the strides and offsets as specified.
67 bool Init(int32_t y_stride, 83 bool Init(int32_t y_stride,
68 int32_t u_stride, 84 int32_t u_stride,
69 int32_t v_stride, 85 int32_t v_stride,
70 size_t y_offset, 86 size_t y_offset,
71 size_t u_offset, 87 size_t u_offset,
72 size_t v_offset); 88 size_t v_offset);
73 89
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
74 mojo::ScopedSharedBufferHandle shared_buffer_handle_; 98 mojo::ScopedSharedBufferHandle shared_buffer_handle_;
75 size_t shared_buffer_size_; 99 size_t shared_buffer_size_;
76 uint8_t* shared_buffer_data_; 100 uint8_t* shared_buffer_data_;
77 size_t offsets_[kMaxPlanes]; 101 size_t offsets_[kMaxPlanes];
78 102
79 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); 103 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame);
80 }; 104 };
81 105
82 } // namespace media 106 } // namespace media
83 107
84 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_ 108 #endif // MEDIA_MOJO_COMMON_MOJO_SHARED_BUFFER_VIDEO_FRAME_H_
OLDNEW
« no previous file with comments | « media/mojo/common/media_type_converters_unittest.cc ('k') | media/mojo/common/mojo_shared_buffer_video_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698