| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // native handle. | 51 // native handle. |
| 52 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | 52 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; |
| 53 | 53 |
| 54 protected: | 54 protected: |
| 55 virtual ~VideoFrameBuffer(); | 55 virtual ~VideoFrameBuffer(); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Plain I420 buffer in standard memory. | 58 // Plain I420 buffer in standard memory. |
| 59 class I420Buffer : public VideoFrameBuffer { | 59 class I420Buffer : public VideoFrameBuffer { |
| 60 public: | 60 public: |
| 61 I420Buffer(int width, int height); | |
| 62 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | |
| 63 | |
| 64 static rtc::scoped_refptr<I420Buffer> Create(int width, int height); | 61 static rtc::scoped_refptr<I420Buffer> Create(int width, int height); |
| 65 static rtc::scoped_refptr<I420Buffer> Create(int width, | 62 static rtc::scoped_refptr<I420Buffer> Create(int width, |
| 66 int height, | 63 int height, |
| 67 int stride_y, | 64 int stride_y, |
| 68 int stride_u, | 65 int stride_u, |
| 69 int stride_v); | 66 int stride_v); |
| 70 | 67 |
| 68 // Create a new buffer and copy the pixel data. |
| 69 static rtc::scoped_refptr<I420Buffer> Copy(const VideoFrameBuffer& buffer); |
| 70 |
| 71 static rtc::scoped_refptr<I420Buffer> Copy( |
| 72 int width, int height, |
| 73 const uint8_t* data_y, int stride_y, |
| 74 const uint8_t* data_u, int stride_u, |
| 75 const uint8_t* data_v, int stride_v); |
| 76 |
| 77 // Returns a rotated versions of |src|. Native buffers are not |
| 78 // supported. The reason this function doesn't return an I420Buffer, |
| 79 // is that it returns |src| unchanged in case |rotation| is zero. |
| 80 // TODO(nisse): Consider dropping the special handling of zero |
| 81 // rotation, and leave any optimizing that case to the caller. |
| 82 static rtc::scoped_refptr<VideoFrameBuffer> Rotate( |
| 83 rtc::scoped_refptr<VideoFrameBuffer> src, |
| 84 VideoRotation rotation); |
| 85 |
| 71 // Sets all three planes to all zeros. Used to work around for | 86 // Sets all three planes to all zeros. Used to work around for |
| 72 // quirks in memory checkers | 87 // quirks in memory checkers |
| 73 // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and | 88 // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and |
| 74 // ffmpeg (http://crbug.com/390941). | 89 // ffmpeg (http://crbug.com/390941). |
| 75 // TODO(nisse): Should be deleted if/when those issues are resolved | 90 // TODO(nisse): Should be deleted if/when those issues are resolved |
| 76 // in a better way. | 91 // in a better way. |
| 77 void InitializeData(); | 92 void InitializeData(); |
| 78 | 93 |
| 79 // Sets the frame buffer to all black. | 94 // Sets the frame buffer to all black. |
| 80 void SetToBlack(); | 95 void SetToBlack(); |
| 81 | 96 |
| 82 int width() const override; | 97 int width() const override; |
| 83 int height() const override; | 98 int height() const override; |
| 84 const uint8_t* DataY() const override; | 99 const uint8_t* DataY() const override; |
| 85 const uint8_t* DataU() const override; | 100 const uint8_t* DataU() const override; |
| 86 const uint8_t* DataV() const override; | 101 const uint8_t* DataV() const override; |
| 87 | 102 |
| 88 uint8_t* MutableDataY(); | 103 uint8_t* MutableDataY(); |
| 89 uint8_t* MutableDataU(); | 104 uint8_t* MutableDataU(); |
| 90 uint8_t* MutableDataV(); | 105 uint8_t* MutableDataV(); |
| 91 int StrideY() const override; | 106 int StrideY() const override; |
| 92 int StrideU() const override; | 107 int StrideU() const override; |
| 93 int StrideV() const override; | 108 int StrideV() const override; |
| 94 | 109 |
| 95 void* native_handle() const override; | 110 void* native_handle() const override; |
| 96 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 111 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 97 | 112 |
| 98 // Create a new buffer and copy the pixel data. | |
| 99 static rtc::scoped_refptr<I420Buffer> Copy(const VideoFrameBuffer& buffer); | |
| 100 | |
| 101 // Scale the cropped area of |src| to the size of |this| buffer, and | 113 // Scale the cropped area of |src| to the size of |this| buffer, and |
| 102 // write the result into |this|. | 114 // write the result into |this|. |
| 103 void CropAndScaleFrom(const VideoFrameBuffer& src, | 115 void CropAndScaleFrom(const VideoFrameBuffer& src, |
| 104 int offset_x, | 116 int offset_x, |
| 105 int offset_y, | 117 int offset_y, |
| 106 int crop_width, | 118 int crop_width, |
| 107 int crop_height); | 119 int crop_height); |
| 108 | 120 |
| 109 // The common case of a center crop, when needed to adjust the | 121 // The common case of a center crop, when needed to adjust the |
| 110 // aspect ratio without distorting the image. | 122 // aspect ratio without distorting the image. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 int crop_height) { | 138 int crop_height) { |
| 127 CropAndScaleFrom(*src, offset_x, offset_y, crop_width, crop_height); | 139 CropAndScaleFrom(*src, offset_x, offset_y, crop_width, crop_height); |
| 128 } | 140 } |
| 129 void CropAndScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { | 141 void CropAndScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { |
| 130 CropAndScaleFrom(*src); | 142 CropAndScaleFrom(*src); |
| 131 } | 143 } |
| 132 void ScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { | 144 void ScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { |
| 133 ScaleFrom(*src); | 145 ScaleFrom(*src); |
| 134 } | 146 } |
| 135 | 147 |
| 136 // Returns a rotated versions of |src|. Native buffers are not | 148 protected: |
| 137 // supported. The reason this function doesn't return an I420Buffer, | 149 I420Buffer(int width, int height); |
| 138 // is that it returns |src| unchanged in case |rotation| is zero. | 150 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 139 static rtc::scoped_refptr<VideoFrameBuffer> Rotate( | |
| 140 rtc::scoped_refptr<VideoFrameBuffer> src, | |
| 141 VideoRotation rotation); | |
| 142 | 151 |
| 143 protected: | |
| 144 ~I420Buffer() override; | 152 ~I420Buffer() override; |
| 145 | 153 |
| 146 private: | 154 private: |
| 147 const int width_; | 155 const int width_; |
| 148 const int height_; | 156 const int height_; |
| 149 const int stride_y_; | 157 const int stride_y_; |
| 150 const int stride_u_; | 158 const int stride_u_; |
| 151 const int stride_v_; | 159 const int stride_v_; |
| 152 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; | 160 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; |
| 153 }; | 161 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const uint8_t* const v_plane_; | 221 const uint8_t* const v_plane_; |
| 214 const int y_stride_; | 222 const int y_stride_; |
| 215 const int u_stride_; | 223 const int u_stride_; |
| 216 const int v_stride_; | 224 const int v_stride_; |
| 217 rtc::Callback0<void> no_longer_used_cb_; | 225 rtc::Callback0<void> no_longer_used_cb_; |
| 218 }; | 226 }; |
| 219 | 227 |
| 220 } // namespace webrtc | 228 } // namespace webrtc |
| 221 | 229 |
| 222 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 230 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |