| 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 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. | |
| 46 virtual bool HasOneRef() const = 0; | |
| 47 | |
| 48 // The resolution of the frame in pixels. For formats where some planes are | 36 // The resolution of the frame in pixels. For formats where some planes are |
| 49 // subsampled, this is the highest-resolution plane. | 37 // subsampled, this is the highest-resolution plane. |
| 50 virtual int width() const = 0; | 38 virtual int width() const = 0; |
| 51 virtual int height() const = 0; | 39 virtual int height() const = 0; |
| 52 | 40 |
| 53 // TODO(nisse): For the transition, we use default implementations | 41 // TODO(nisse): For the transition, we use default implementations |
| 54 // of the stride and data methods where the new methods calls the | 42 // of the stride and data methods where the new methods calls the |
| 55 // old method, and the old method calls the new methods. Subclasses | 43 // old method, and the old method calls the new methods. Subclasses |
| 56 // must override either the new methods or the old method, to break | 44 // must override either the new methods or the old method, to break |
| 57 // infinite recursion. And similarly for the strides. When | 45 // infinite recursion. And similarly for the strides. When |
| 58 // applications, in particular Chrome, are updated, delete the old | 46 // applications, in particular Chrome, are updated, delete the old |
| 59 // method and delete the default implementation of the new methods. | 47 // method and delete the default implementation of the new methods. |
| 60 | 48 |
| 61 // Returns pointer to the pixel data for a given plane. The memory is owned by | 49 // Returns pointer to the pixel data for a given plane. The memory is owned by |
| 62 // the VideoFrameBuffer object and must not be freed by the caller. | 50 // the VideoFrameBuffer object and must not be freed by the caller. |
| 63 virtual const uint8_t* DataY() const; | 51 virtual const uint8_t* DataY() const; |
| 64 virtual const uint8_t* DataU() const; | 52 virtual const uint8_t* DataU() const; |
| 65 virtual const uint8_t* DataV() const; | 53 virtual const uint8_t* DataV() const; |
| 66 // Deprecated method. | 54 // Deprecated method. |
| 67 // TODO(nisse): Delete after all users are updated. | 55 // TODO(nisse): Delete after all users are updated. |
| 68 virtual const uint8_t* data(PlaneType type) const; | 56 virtual const uint8_t* data(PlaneType type) const; |
| 69 | 57 |
| 70 // Non-const data access is allowed only if HasOneRef() is true. | 58 // TODO(nisse): Move MutableData methods to the I420Buffer subclass. |
| 59 // Non-const data access. |
| 71 virtual uint8_t* MutableDataY(); | 60 virtual uint8_t* MutableDataY(); |
| 72 virtual uint8_t* MutableDataU(); | 61 virtual uint8_t* MutableDataU(); |
| 73 virtual uint8_t* MutableDataV(); | 62 virtual uint8_t* MutableDataV(); |
| 74 // Deprecated method. TODO(nisse): Delete after all users are updated. | 63 // Deprecated method. TODO(nisse): Delete after all users are updated. |
| 75 virtual uint8_t* MutableData(PlaneType type); | 64 virtual uint8_t* MutableData(PlaneType type); |
| 76 | 65 |
| 77 // Returns the number of bytes between successive rows for a given plane. | 66 // Returns the number of bytes between successive rows for a given plane. |
| 78 virtual int StrideY() const; | 67 virtual int StrideY() const; |
| 79 virtual int StrideU() const; | 68 virtual int StrideU() const; |
| 80 virtual int StrideV() const; | 69 virtual int StrideV() const; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 public: | 87 public: |
| 99 I420Buffer(int width, int height); | 88 I420Buffer(int width, int height); |
| 100 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | 89 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 101 void InitializeData(); | 90 void InitializeData(); |
| 102 | 91 |
| 103 int width() const override; | 92 int width() const override; |
| 104 int height() const override; | 93 int height() const override; |
| 105 const uint8_t* DataY() const override; | 94 const uint8_t* DataY() const override; |
| 106 const uint8_t* DataU() const override; | 95 const uint8_t* DataU() const override; |
| 107 const uint8_t* DataV() const override; | 96 const uint8_t* DataV() const override; |
| 108 // Non-const data access is only allowed if IsMutable() is true, to protect | 97 |
| 109 // against unexpected overwrites. | |
| 110 bool IsMutable() override; | |
| 111 uint8_t* MutableDataY() override; | 98 uint8_t* MutableDataY() override; |
| 112 uint8_t* MutableDataU() override; | 99 uint8_t* MutableDataU() override; |
| 113 uint8_t* MutableDataV() override; | 100 uint8_t* MutableDataV() override; |
| 114 int StrideY() const override; | 101 int StrideY() const override; |
| 115 int StrideU() const override; | 102 int StrideU() const override; |
| 116 int StrideV() const override; | 103 int StrideV() const override; |
| 117 | 104 |
| 118 void* native_handle() const override; | 105 void* native_handle() const override; |
| 119 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 106 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 120 | 107 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 145 int width() const override; | 132 int width() const override; |
| 146 int height() const override; | 133 int height() const override; |
| 147 const uint8_t* DataY() const override; | 134 const uint8_t* DataY() const override; |
| 148 const uint8_t* DataU() const override; | 135 const uint8_t* DataU() const override; |
| 149 const uint8_t* DataV() const override; | 136 const uint8_t* DataV() const override; |
| 150 int StrideY() const override; | 137 int StrideY() const override; |
| 151 int StrideU() const override; | 138 int StrideU() const override; |
| 152 int StrideV() const override; | 139 int StrideV() const override; |
| 153 | 140 |
| 154 void* native_handle() const override; | 141 void* native_handle() const override; |
| 155 bool IsMutable() override; | |
| 156 | 142 |
| 157 protected: | 143 protected: |
| 158 void* native_handle_; | 144 void* native_handle_; |
| 159 const int width_; | 145 const int width_; |
| 160 const int height_; | 146 const int height_; |
| 161 }; | 147 }; |
| 162 | 148 |
| 163 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { | 149 class WrappedI420Buffer : public webrtc::VideoFrameBuffer { |
| 164 public: | 150 public: |
| 165 WrappedI420Buffer(int width, | 151 WrappedI420Buffer(int width, |
| 166 int height, | 152 int height, |
| 167 const uint8_t* y_plane, | 153 const uint8_t* y_plane, |
| 168 int y_stride, | 154 int y_stride, |
| 169 const uint8_t* u_plane, | 155 const uint8_t* u_plane, |
| 170 int u_stride, | 156 int u_stride, |
| 171 const uint8_t* v_plane, | 157 const uint8_t* v_plane, |
| 172 int v_stride, | 158 int v_stride, |
| 173 const rtc::Callback0<void>& no_longer_used); | 159 const rtc::Callback0<void>& no_longer_used); |
| 174 int width() const override; | 160 int width() const override; |
| 175 int height() const override; | 161 int height() const override; |
| 176 | 162 |
| 177 bool IsMutable() override; | |
| 178 | |
| 179 const uint8_t* DataY() const override; | 163 const uint8_t* DataY() const override; |
| 180 const uint8_t* DataU() const override; | 164 const uint8_t* DataU() const override; |
| 181 const uint8_t* DataV() const override; | 165 const uint8_t* DataV() const override; |
| 182 int StrideY() const override; | 166 int StrideY() const override; |
| 183 int StrideU() const override; | 167 int StrideU() const override; |
| 184 int StrideV() const override; | 168 int StrideV() const override; |
| 185 | 169 |
| 186 void* native_handle() const override; | 170 void* native_handle() const override; |
| 187 | 171 |
| 188 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 172 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 205 // Helper function to crop |buffer| without making a deep copy. May only be used | 189 // Helper function to crop |buffer| without making a deep copy. May only be used |
| 206 // for non-native frames. | 190 // for non-native frames. |
| 207 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 191 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
| 208 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 192 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
| 209 int cropped_width, | 193 int cropped_width, |
| 210 int cropped_height); | 194 int cropped_height); |
| 211 | 195 |
| 212 } // namespace webrtc | 196 } // namespace webrtc |
| 213 | 197 |
| 214 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 198 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |