| 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 |
| 39 // TODO(nisse): Delete default implementation when subclasses in |
| 40 // Chrome are updated. |
| 41 virtual bool IsMutable() { return false; } |
| 42 |
| 43 // Underlying refcount access, used to implement IsMutable. |
| 44 // TODO(nisse): Demote to protected, as soon as Chrome is changed to |
| 45 // use IsMutable. |
| 37 virtual bool HasOneRef() const = 0; | 46 virtual bool HasOneRef() const = 0; |
| 38 | 47 |
| 39 // The resolution of the frame in pixels. For formats where some planes are | 48 // The resolution of the frame in pixels. For formats where some planes are |
| 40 // subsampled, this is the highest-resolution plane. | 49 // subsampled, this is the highest-resolution plane. |
| 41 virtual int width() const = 0; | 50 virtual int width() const = 0; |
| 42 virtual int height() const = 0; | 51 virtual int height() const = 0; |
| 43 | 52 |
| 44 // Returns pointer to the pixel data for a given plane. The memory is owned by | 53 // 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. | 54 // the VideoFrameBuffer object and must not be freed by the caller. |
| 46 virtual const uint8_t* data(PlaneType type) const = 0; | 55 virtual const uint8_t* data(PlaneType type) const = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 public: | 78 public: |
| 70 I420Buffer(int width, int height); | 79 I420Buffer(int width, int height); |
| 71 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | 80 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 72 void InitializeData(); | 81 void InitializeData(); |
| 73 | 82 |
| 74 int width() const override; | 83 int width() const override; |
| 75 int height() const override; | 84 int height() const override; |
| 76 const uint8_t* data(PlaneType type) const override; | 85 const uint8_t* data(PlaneType type) const override; |
| 77 // Non-const data access is only allowed if HasOneRef() is true to protect | 86 // Non-const data access is only allowed if HasOneRef() is true to protect |
| 78 // against unexpected overwrites. | 87 // against unexpected overwrites. |
| 88 bool IsMutable() override; |
| 79 uint8_t* MutableData(PlaneType type) override; | 89 uint8_t* MutableData(PlaneType type) override; |
| 80 int stride(PlaneType type) const override; | 90 int stride(PlaneType type) const override; |
| 81 void* native_handle() const override; | 91 void* native_handle() const override; |
| 82 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 92 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 83 | 93 |
| 84 // Create a new buffer and copy the pixel data. | 94 // Create a new buffer and copy the pixel data. |
| 85 static rtc::scoped_refptr<I420Buffer> Copy( | 95 static rtc::scoped_refptr<I420Buffer> Copy( |
| 86 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); | 96 const rtc::scoped_refptr<VideoFrameBuffer>& buffer); |
| 87 | 97 |
| 88 protected: | 98 protected: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 103 // as their own destructors or conversion methods back to software I420). | 113 // as their own destructors or conversion methods back to software I420). |
| 104 class NativeHandleBuffer : public VideoFrameBuffer { | 114 class NativeHandleBuffer : public VideoFrameBuffer { |
| 105 public: | 115 public: |
| 106 NativeHandleBuffer(void* native_handle, int width, int height); | 116 NativeHandleBuffer(void* native_handle, int width, int height); |
| 107 | 117 |
| 108 int width() const override; | 118 int width() const override; |
| 109 int height() const override; | 119 int height() const override; |
| 110 const uint8_t* data(PlaneType type) const override; | 120 const uint8_t* data(PlaneType type) const override; |
| 111 int stride(PlaneType type) const override; | 121 int stride(PlaneType type) const override; |
| 112 void* native_handle() const override; | 122 void* native_handle() const override; |
| 123 bool IsMutable() override; |
| 113 | 124 |
| 114 protected: | 125 protected: |
| 115 void* native_handle_; | 126 void* native_handle_; |
| 116 const int width_; | 127 const int width_; |
| 117 const int height_; | 128 const int height_; |
| 118 }; | 129 }; |
| 119 | 130 |
| 120 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | 131 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { |
| 121 public: | 132 public: |
| 122 WrappedI420Buffer(int width, | 133 WrappedI420Buffer(int width, |
| 123 int height, | 134 int height, |
| 124 const uint8_t* y_plane, | 135 const uint8_t* y_plane, |
| 125 int y_stride, | 136 int y_stride, |
| 126 const uint8_t* u_plane, | 137 const uint8_t* u_plane, |
| 127 int u_stride, | 138 int u_stride, |
| 128 const uint8_t* v_plane, | 139 const uint8_t* v_plane, |
| 129 int v_stride, | 140 int v_stride, |
| 130 const rtc::Callback0<void>& no_longer_used); | 141 const rtc::Callback0<void>& no_longer_used); |
| 131 int width() const override; | 142 int width() const override; |
| 132 int height() const override; | 143 int height() const override; |
| 133 | 144 |
| 145 bool IsMutable() override; |
| 146 |
| 134 const uint8_t* data(PlaneType type) const override; | 147 const uint8_t* data(PlaneType type) const override; |
| 135 | 148 |
| 136 int stride(PlaneType type) const override; | 149 int stride(PlaneType type) const override; |
| 137 void* native_handle() const override; | 150 void* native_handle() const override; |
| 138 | 151 |
| 139 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 152 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 140 | 153 |
| 141 private: | 154 private: |
| 142 friend class rtc::RefCountedObject<WrappedI420Buffer>; | 155 friend class rtc::RefCountedObject<WrappedI420Buffer>; |
| 143 ~WrappedI420Buffer() override; | 156 ~WrappedI420Buffer() override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 // Helper function to crop |buffer| without making a deep copy. May only be used | 169 // Helper function to crop |buffer| without making a deep copy. May only be used |
| 157 // for non-native frames. | 170 // for non-native frames. |
| 158 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 171 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
| 159 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 172 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 160 int cropped_width, | 173 int cropped_width, |
| 161 int cropped_height); | 174 int cropped_height); |
| 162 | 175 |
| 163 } // namespace webrtc | 176 } // namespace webrtc |
| 164 | 177 |
| 165 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 178 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |