| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 kYPlane = 0, | 26 kYPlane = 0, |
| 27 kUPlane = 1, | 27 kUPlane = 1, |
| 28 kVPlane = 2, | 28 kVPlane = 2, |
| 29 kNumOfPlanes = 3, | 29 kNumOfPlanes = 3, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Interface of a simple frame buffer containing pixel data. This interface does | 32 // Interface of a simple frame buffer containing pixel data. This interface does |
| 33 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. | 33 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. |
| 34 class VideoFrameBuffer : public rtc::RefCountInterface { | 34 class VideoFrameBuffer : public rtc::RefCountInterface { |
| 35 public: | 35 public: |
| 36 // Returns true if this buffer has a single exclusive owner. | 36 // Returns true if the caller is exclusive owner, and allowed to |
| 37 // call MutableData. |
| 38 virtual bool IsMutable() = 0; |
| 39 |
| 40 // Underlying refcount access, used to implement IsMutable. |
| 41 // TODO(nisse): Demote to protected, as soon as Chrome is changed to |
| 42 // use IsMutable. |
| 37 virtual bool HasOneRef() const = 0; | 43 virtual bool HasOneRef() const = 0; |
| 38 | 44 |
| 39 // The resolution of the frame in pixels. For formats where some planes are | 45 // The resolution of the frame in pixels. For formats where some planes are |
| 40 // subsampled, this is the highest-resolution plane. | 46 // subsampled, this is the highest-resolution plane. |
| 41 virtual int width() const = 0; | 47 virtual int width() const = 0; |
| 42 virtual int height() const = 0; | 48 virtual int height() const = 0; |
| 43 | 49 |
| 44 // Returns pointer to the pixel data for a given plane. The memory is owned by | 50 // Returns pointer to the pixel data for a given plane. The memory is owned by |
| 45 // the VideoFrameBuffer object and must not be freed by the caller. | 51 // the VideoFrameBuffer object and must not be freed by the caller. |
| 46 virtual const uint8_t* data(PlaneType type) const = 0; | 52 virtual const uint8_t* data(PlaneType type) const = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 public: | 75 public: |
| 70 I420Buffer(int width, int height); | 76 I420Buffer(int width, int height); |
| 71 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | 77 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 72 void InitializeData(); | 78 void InitializeData(); |
| 73 | 79 |
| 74 int width() const override; | 80 int width() const override; |
| 75 int height() const override; | 81 int height() const override; |
| 76 const uint8_t* data(PlaneType type) const override; | 82 const uint8_t* data(PlaneType type) const override; |
| 77 // Non-const data access is only allowed if HasOneRef() is true to protect | 83 // Non-const data access is only allowed if HasOneRef() is true to protect |
| 78 // against unexpected overwrites. | 84 // against unexpected overwrites. |
| 85 bool IsMutable() override; |
| 79 uint8_t* MutableData(PlaneType type) override; | 86 uint8_t* MutableData(PlaneType type) override; |
| 80 int stride(PlaneType type) const override; | 87 int stride(PlaneType type) const override; |
| 81 void* native_handle() const override; | 88 void* native_handle() const override; |
| 82 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 89 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 83 | 90 |
| 84 // Create a new buffer and copy the pixel data. | 91 // Create a new buffer and copy the pixel data. |
| 85 static rtc::scoped_refptr<I420Buffer> Copy( | 92 static rtc::scoped_refptr<I420Buffer> Copy( |
| 86 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); | 93 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); |
| 87 | 94 |
| 88 protected: | 95 protected: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 // as their own destructors or conversion methods back to software I420). | 110 // as their own destructors or conversion methods back to software I420). |
| 104 class NativeHandleBuffer : public VideoFrameBuffer { | 111 class NativeHandleBuffer : public VideoFrameBuffer { |
| 105 public: | 112 public: |
| 106 NativeHandleBuffer(void* native_handle, int width, int height); | 113 NativeHandleBuffer(void* native_handle, int width, int height); |
| 107 | 114 |
| 108 int width() const override; | 115 int width() const override; |
| 109 int height() const override; | 116 int height() const override; |
| 110 const uint8_t* data(PlaneType type) const override; | 117 const uint8_t* data(PlaneType type) const override; |
| 111 int stride(PlaneType type) const override; | 118 int stride(PlaneType type) const override; |
| 112 void* native_handle() const override; | 119 void* native_handle() const override; |
| 120 bool IsMutable() override; |
| 113 | 121 |
| 114 protected: | 122 protected: |
| 115 void* native_handle_; | 123 void* native_handle_; |
| 116 const int width_; | 124 const int width_; |
| 117 const int height_; | 125 const int height_; |
| 118 }; | 126 }; |
| 119 | 127 |
| 120 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | 128 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { |
| 121 public: | 129 public: |
| 122 WrappedI420Buffer(int width, | 130 WrappedI420Buffer(int width, |
| 123 int height, | 131 int height, |
| 124 const uint8_t* y_plane, | 132 const uint8_t* y_plane, |
| 125 int y_stride, | 133 int y_stride, |
| 126 const uint8_t* u_plane, | 134 const uint8_t* u_plane, |
| 127 int u_stride, | 135 int u_stride, |
| 128 const uint8_t* v_plane, | 136 const uint8_t* v_plane, |
| 129 int v_stride, | 137 int v_stride, |
| 130 const rtc::Callback0<void>& no_longer_used); | 138 const rtc::Callback0<void>& no_longer_used); |
| 131 int width() const override; | 139 int width() const override; |
| 132 int height() const override; | 140 int height() const override; |
| 133 | 141 |
| 142 bool IsMutable() override; |
| 143 |
| 134 const uint8_t* data(PlaneType type) const override; | 144 const uint8_t* data(PlaneType type) const override; |
| 135 | 145 |
| 136 int stride(PlaneType type) const override; | 146 int stride(PlaneType type) const override; |
| 137 void* native_handle() const override; | 147 void* native_handle() const override; |
| 138 | 148 |
| 139 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 149 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 140 | 150 |
| 141 private: | 151 private: |
| 142 friend class rtc::RefCountedObject<WrappedI420Buffer>; | 152 friend class rtc::RefCountedObject<WrappedI420Buffer>; |
| 143 ~WrappedI420Buffer() override; | 153 ~WrappedI420Buffer() override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 // Helper function to crop |buffer| without making a deep copy. May only be used | 166 // Helper function to crop |buffer| without making a deep copy. May only be used |
| 157 // for non-native frames. | 167 // for non-native frames. |
| 158 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 168 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
| 159 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 169 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 160 int cropped_width, | 170 int cropped_width, |
| 161 int cropped_height); | 171 int cropped_height); |
| 162 | 172 |
| 163 } // namespace webrtc | 173 } // namespace webrtc |
| 164 | 174 |
| 165 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 175 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |