| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | |
| 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | |
| 13 | |
| 14 #pragma message("WARNING: common_video/include is DEPRECATED; use common_video/i
nclude") | |
| 15 | |
| 16 #include "webrtc/base/callback.h" | |
| 17 #include "webrtc/base/refcount.h" | |
| 18 #include "webrtc/base/scoped_ptr.h" | |
| 19 #include "webrtc/base/scoped_ref_ptr.h" | |
| 20 #include "webrtc/system_wrappers/include/aligned_malloc.h" | |
| 21 | |
| 22 namespace webrtc { | |
| 23 | |
| 24 enum PlaneType { | |
| 25 kYPlane = 0, | |
| 26 kUPlane = 1, | |
| 27 kVPlane = 2, | |
| 28 kNumOfPlanes = 3, | |
| 29 }; | |
| 30 | |
| 31 // Interface of a simple frame buffer containing pixel data. This interface does | |
| 32 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. | |
| 33 class VideoFrameBuffer : public rtc::RefCountInterface { | |
| 34 public: | |
| 35 // Returns true if this buffer has a single exclusive owner. | |
| 36 virtual bool HasOneRef() const = 0; | |
| 37 | |
| 38 // The resolution of the frame in pixels. For formats where some planes are | |
| 39 // subsampled, this is the highest-resolution plane. | |
| 40 virtual int width() const = 0; | |
| 41 virtual int height() const = 0; | |
| 42 | |
| 43 // Returns pointer to the pixel data for a given plane. The memory is owned by | |
| 44 // the VideoFrameBuffer object and must not be freed by the caller. | |
| 45 virtual const uint8_t* data(PlaneType type) const = 0; | |
| 46 | |
| 47 // Non-const data access is disallowed by default. You need to make sure you | |
| 48 // have exclusive access and a writable buffer before calling this function. | |
| 49 virtual uint8_t* MutableData(PlaneType type); | |
| 50 | |
| 51 // Returns the number of bytes between successive rows for a given plane. | |
| 52 virtual int stride(PlaneType type) const = 0; | |
| 53 | |
| 54 // Return the handle of the underlying video frame. This is used when the | |
| 55 // frame is backed by a texture. | |
| 56 virtual void* native_handle() const = 0; | |
| 57 | |
| 58 // Returns a new memory-backed frame buffer converted from this buffer's | |
| 59 // native handle. | |
| 60 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | |
| 61 | |
| 62 protected: | |
| 63 virtual ~VideoFrameBuffer(); | |
| 64 }; | |
| 65 | |
| 66 // Plain I420 buffer in standard memory. | |
| 67 class I420Buffer : public VideoFrameBuffer { | |
| 68 public: | |
| 69 I420Buffer(int width, int height); | |
| 70 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | |
| 71 | |
| 72 int width() const override; | |
| 73 int height() const override; | |
| 74 const uint8_t* data(PlaneType type) const override; | |
| 75 // Non-const data access is only allowed if HasOneRef() is true to protect | |
| 76 // against unexpected overwrites. | |
| 77 uint8_t* MutableData(PlaneType type) override; | |
| 78 int stride(PlaneType type) const override; | |
| 79 void* native_handle() const override; | |
| 80 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | |
| 81 | |
| 82 protected: | |
| 83 ~I420Buffer() override; | |
| 84 | |
| 85 private: | |
| 86 const int width_; | |
| 87 const int height_; | |
| 88 const int stride_y_; | |
| 89 const int stride_u_; | |
| 90 const int stride_v_; | |
| 91 const rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> data_; | |
| 92 }; | |
| 93 | |
| 94 // Base class for native-handle buffer is a wrapper around a |native_handle|. | |
| 95 // This is used for convenience as most native-handle implementations can share | |
| 96 // many VideoFrame implementations, but need to implement a few others (such | |
| 97 // as their own destructors or conversion methods back to software I420). | |
| 98 class NativeHandleBuffer : public VideoFrameBuffer { | |
| 99 public: | |
| 100 NativeHandleBuffer(void* native_handle, int width, int height); | |
| 101 | |
| 102 int width() const override; | |
| 103 int height() const override; | |
| 104 const uint8_t* data(PlaneType type) const override; | |
| 105 int stride(PlaneType type) const override; | |
| 106 void* native_handle() const override; | |
| 107 | |
| 108 protected: | |
| 109 void* native_handle_; | |
| 110 const int width_; | |
| 111 const int height_; | |
| 112 }; | |
| 113 | |
| 114 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | |
| 115 public: | |
| 116 WrappedI420Buffer(int width, | |
| 117 int height, | |
| 118 const uint8_t* y_plane, | |
| 119 int y_stride, | |
| 120 const uint8_t* u_plane, | |
| 121 int u_stride, | |
| 122 const uint8_t* v_plane, | |
| 123 int v_stride, | |
| 124 const rtc::Callback0<void>& no_longer_used); | |
| 125 int width() const override; | |
| 126 int height() const override; | |
| 127 | |
| 128 const uint8_t* data(PlaneType type) const override; | |
| 129 | |
| 130 int stride(PlaneType type) const override; | |
| 131 void* native_handle() const override; | |
| 132 | |
| 133 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | |
| 134 | |
| 135 private: | |
| 136 friend class rtc::RefCountedObject<WrappedI420Buffer>; | |
| 137 ~WrappedI420Buffer() override; | |
| 138 | |
| 139 const int width_; | |
| 140 const int height_; | |
| 141 const uint8_t* const y_plane_; | |
| 142 const uint8_t* const u_plane_; | |
| 143 const uint8_t* const v_plane_; | |
| 144 const int y_stride_; | |
| 145 const int u_stride_; | |
| 146 const int v_stride_; | |
| 147 rtc::Callback0<void> no_longer_used_cb_; | |
| 148 }; | |
| 149 | |
| 150 // Helper function to crop |buffer| without making a deep copy. May only be used | |
| 151 // for non-native frames. | |
| 152 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | |
| 153 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | |
| 154 int cropped_width, | |
| 155 int cropped_height); | |
| 156 | |
| 157 } // namespace webrtc | |
| 158 | |
| 159 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | |
| OLD | NEW |