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 #ifndef MEDIA_MOJO_COMMON_MOJO_VIDEO_FRAME_H_ | |
| 6 #define MEDIA_MOJO_COMMON_MOJO_VIDEO_FRAME_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "media/base/media_export.h" | |
| 14 #include "media/base/video_frame.h" | |
| 15 #include "mojo/public/cpp/system/buffer.h" | |
| 16 #include "ui/gfx/geometry/rect.h" | |
| 17 #include "ui/gfx/geometry/size.h" | |
| 18 | |
| 19 namespace media { | |
| 20 | |
| 21 // A derived class of media::VideoFrame holding a mojo::SharedBufferHandle | |
| 22 // which is mapped on constructor and remains so for the lifetime of the | |
| 23 // object. These frames are ref-counted. | |
| 24 class MEDIA_EXPORT MojoSharedBufferVideoFrame : public VideoFrame { | |
| 25 public: | |
| 26 // Creates a new I420 frame in shared memory with provided parameters | |
| 27 // (coded_size() == natural_size() == visible_rect()), or returns nullptr. | |
| 28 // Buffers for the frame are allocated but not initialized. The caller must | |
| 29 // not make assumptions about the actual underlying sizes, but check the | |
| 30 // returned VideoFrame instead. | |
| 31 static scoped_refptr<MojoSharedBufferVideoFrame> CreateDefaultI420( | |
| 32 const gfx::Size& dimensions, | |
| 33 base::TimeDelta timestamp); | |
| 34 | |
| 35 // Creates a MojoSharedBufferVideoFrame that uses the memory in |handle|. | |
| 36 // This will take ownership of |handle|, so the caller can no longer use it. | |
| 37 static scoped_refptr<MojoSharedBufferVideoFrame> Create( | |
| 38 VideoPixelFormat format, | |
| 39 const gfx::Size& coded_size, | |
| 40 const gfx::Rect& visible_rect, | |
| 41 const gfx::Size& natural_size, | |
| 42 mojo::ScopedSharedBufferHandle handle, | |
| 43 size_t mapped_size, | |
| 44 size_t y_offset, | |
| 45 size_t u_offset, | |
| 46 size_t v_offset, | |
| 47 int32_t y_stride, | |
| 48 int32_t u_stride, | |
| 49 int32_t v_stride, | |
| 50 base::TimeDelta timestamp); | |
| 51 | |
| 52 // Returns the offsets relative to the start of |shared_buffer| for the | |
| 53 // |plane| specified. | |
| 54 size_t plane_offset(size_t plane) const; | |
| 55 | |
| 56 private: | |
| 57 MojoSharedBufferVideoFrame(VideoPixelFormat format, | |
| 58 const gfx::Size& coded_size, | |
| 59 const gfx::Rect& visible_rect, | |
| 60 const gfx::Size& natural_size, | |
| 61 mojo::ScopedSharedBufferHandle handle, | |
| 62 size_t mapped_size, | |
| 63 base::TimeDelta timestamp); | |
| 64 ~MojoSharedBufferVideoFrame() override; | |
| 65 | |
| 66 // Initializes the MojoSharedBufferVideoFrame by creating a mapping onto | |
| 67 // the shared memory, and then setting the strides and offsets as specified. | |
| 68 bool Init(int32_t y_stride, | |
| 69 int32_t u_stride, | |
| 70 int32_t v_stride, | |
| 71 size_t y_offset, | |
| 72 size_t u_offset, | |
| 73 size_t v_offset); | |
| 74 | |
| 75 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | |
| 76 size_t shared_buffer_size_; | |
| 77 void* buffer_data_; | |
|
xhwang
2016/03/04 00:55:34
nit: shared_buffer_data_ to be consistent with oth
jrummell
2016/03/04 02:19:06
Done.
| |
| 78 size_t offsets_[kMaxPlanes]; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(MojoSharedBufferVideoFrame); | |
| 81 }; | |
| 82 | |
| 83 } // namespace media | |
| 84 | |
| 85 #endif // MEDIA_MOJO_COMMON_MOJO_VIDEO_FRAME_H_ | |
| OLD | NEW |