Chromium Code Reviews| 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 |
| 11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| 13 | 13 |
| 14 #include <stdint.h> | |
| 15 | |
| 16 #include <memory> | 14 #include <memory> |
| 17 | 15 |
| 16 #include "webrtc/api/video/video_frame_buffer.h" | |
| 17 // TODO(nisse): For backwards compatibility, files including this file | |
| 18 // expect it to declare I420Buffer. Delete after callers are updated. | |
|
mflodman
2016/12/22 06:10:37
Is it the same for video_rotation.h? If so, add th
nisse-webrtc
2017/01/09 11:41:18
I'm trying to delete the video_rotation.h include,
| |
| 19 #include "webrtc/api/video/i420_buffer.h" | |
| 20 #include "webrtc/api/video/video_rotation.h" | |
| 18 #include "webrtc/base/callback.h" | 21 #include "webrtc/base/callback.h" |
| 19 #include "webrtc/base/refcount.h" | |
| 20 #include "webrtc/base/scoped_ref_ptr.h" | 22 #include "webrtc/base/scoped_ref_ptr.h" |
| 21 #include "webrtc/common_video/rotation.h" | |
| 22 #include "webrtc/system_wrappers/include/aligned_malloc.h" | |
| 23 | 23 |
| 24 namespace webrtc { | 24 namespace webrtc { |
| 25 | 25 |
| 26 // Interface of a simple frame buffer containing pixel data. This interface does | |
| 27 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. | |
| 28 class VideoFrameBuffer : public rtc::RefCountInterface { | |
| 29 public: | |
| 30 // The resolution of the frame in pixels. For formats where some planes are | |
| 31 // subsampled, this is the highest-resolution plane. | |
| 32 virtual int width() const = 0; | |
| 33 virtual int height() const = 0; | |
| 34 | |
| 35 // Returns pointer to the pixel data for a given plane. The memory is owned by | |
| 36 // the VideoFrameBuffer object and must not be freed by the caller. | |
| 37 virtual const uint8_t* DataY() const = 0; | |
| 38 virtual const uint8_t* DataU() const = 0; | |
| 39 virtual const uint8_t* DataV() const = 0; | |
| 40 | |
| 41 // Returns the number of bytes between successive rows for a given plane. | |
| 42 virtual int StrideY() const = 0; | |
| 43 virtual int StrideU() const = 0; | |
| 44 virtual int StrideV() const = 0; | |
| 45 | |
| 46 // Return the handle of the underlying video frame. This is used when the | |
| 47 // frame is backed by a texture. | |
| 48 virtual void* native_handle() const = 0; | |
| 49 | |
| 50 // Returns a new memory-backed frame buffer converted from this buffer's | |
| 51 // native handle. | |
| 52 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | |
| 53 | |
| 54 protected: | |
| 55 virtual ~VideoFrameBuffer(); | |
| 56 }; | |
| 57 | |
| 58 // Plain I420 buffer in standard memory. | |
| 59 class I420Buffer : public VideoFrameBuffer { | |
| 60 public: | |
| 61 static rtc::scoped_refptr<I420Buffer> Create(int width, int height); | |
| 62 static rtc::scoped_refptr<I420Buffer> Create(int width, | |
| 63 int height, | |
| 64 int stride_y, | |
| 65 int stride_u, | |
| 66 int stride_v); | |
| 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 | |
| 86 // Sets all three planes to all zeros. Used to work around for | |
| 87 // quirks in memory checkers | |
| 88 // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and | |
| 89 // ffmpeg (http://crbug.com/390941). | |
| 90 // TODO(nisse): Should be deleted if/when those issues are resolved | |
| 91 // in a better way. | |
| 92 void InitializeData(); | |
| 93 | |
| 94 // Sets the frame buffer to all black. | |
| 95 void SetToBlack(); | |
| 96 | |
| 97 int width() const override; | |
| 98 int height() const override; | |
| 99 const uint8_t* DataY() const override; | |
| 100 const uint8_t* DataU() const override; | |
| 101 const uint8_t* DataV() const override; | |
| 102 | |
| 103 uint8_t* MutableDataY(); | |
| 104 uint8_t* MutableDataU(); | |
| 105 uint8_t* MutableDataV(); | |
| 106 int StrideY() const override; | |
| 107 int StrideU() const override; | |
| 108 int StrideV() const override; | |
| 109 | |
| 110 void* native_handle() const override; | |
| 111 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | |
| 112 | |
| 113 // Scale the cropped area of |src| to the size of |this| buffer, and | |
| 114 // write the result into |this|. | |
| 115 void CropAndScaleFrom(const VideoFrameBuffer& src, | |
| 116 int offset_x, | |
| 117 int offset_y, | |
| 118 int crop_width, | |
| 119 int crop_height); | |
| 120 | |
| 121 // The common case of a center crop, when needed to adjust the | |
| 122 // aspect ratio without distorting the image. | |
| 123 void CropAndScaleFrom(const VideoFrameBuffer& src); | |
| 124 | |
| 125 // Scale all of |src| to the size of |this| buffer, with no cropping. | |
| 126 void ScaleFrom(const VideoFrameBuffer& src); | |
| 127 | |
| 128 protected: | |
| 129 I420Buffer(int width, int height); | |
| 130 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | |
| 131 | |
| 132 ~I420Buffer() override; | |
| 133 | |
| 134 private: | |
| 135 const int width_; | |
| 136 const int height_; | |
| 137 const int stride_y_; | |
| 138 const int stride_u_; | |
| 139 const int stride_v_; | |
| 140 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; | |
| 141 }; | |
| 142 | |
| 143 // Base class for native-handle buffer is a wrapper around a |native_handle|. | 26 // Base class for native-handle buffer is a wrapper around a |native_handle|. |
| 144 // This is used for convenience as most native-handle implementations can share | 27 // This is used for convenience as most native-handle implementations can share |
| 145 // many VideoFrame implementations, but need to implement a few others (such | 28 // many VideoFrame implementations, but need to implement a few others (such |
| 146 // as their own destructors or conversion methods back to software I420). | 29 // as their own destructors or conversion methods back to software I420). |
| 147 class NativeHandleBuffer : public VideoFrameBuffer { | 30 class NativeHandleBuffer : public VideoFrameBuffer { |
| 148 public: | 31 public: |
| 149 NativeHandleBuffer(void* native_handle, int width, int height); | 32 NativeHandleBuffer(void* native_handle, int width, int height); |
| 150 | 33 |
| 151 int width() const override; | 34 int width() const override; |
| 152 int height() const override; | 35 int height() const override; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 const uint8_t* const v_plane_; | 84 const uint8_t* const v_plane_; |
| 202 const int y_stride_; | 85 const int y_stride_; |
| 203 const int u_stride_; | 86 const int u_stride_; |
| 204 const int v_stride_; | 87 const int v_stride_; |
| 205 rtc::Callback0<void> no_longer_used_cb_; | 88 rtc::Callback0<void> no_longer_used_cb_; |
| 206 }; | 89 }; |
| 207 | 90 |
| 208 } // namespace webrtc | 91 } // namespace webrtc |
| 209 | 92 |
| 210 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ | 93 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |