Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_API_VIDEO_I420_BUFFER_H_ | |
| 12 #define WEBRTC_API_VIDEO_I420_BUFFER_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/api/video/video_rotation.h" | |
| 17 #include "webrtc/api/video/video_frame_buffer.h" | |
| 18 #include "webrtc/system_wrappers/include/aligned_malloc.h" | |
| 19 | |
| 20 namespace webrtc { | |
| 21 | |
| 22 // Plain I420 buffer in standard memory. | |
| 23 class I420Buffer : public VideoFrameBuffer { | |
| 24 public: | |
| 25 static rtc::scoped_refptr<I420Buffer> Create(int width, int height); | |
| 26 static rtc::scoped_refptr<I420Buffer> Create(int width, | |
| 27 int height, | |
| 28 int stride_y, | |
| 29 int stride_u, | |
| 30 int stride_v); | |
| 31 | |
| 32 // Create a new buffer and copy the pixel data. | |
| 33 static rtc::scoped_refptr<I420Buffer> Copy(const VideoFrameBuffer& buffer); | |
| 34 | |
| 35 static rtc::scoped_refptr<I420Buffer> Copy( | |
| 36 int width, int height, | |
| 37 const uint8_t* data_y, int stride_y, | |
| 38 const uint8_t* data_u, int stride_u, | |
| 39 const uint8_t* data_v, int stride_v); | |
| 40 | |
| 41 // Returns a rotated copy of |src|. | |
| 42 static rtc::scoped_refptr<I420Buffer> Rotate(const VideoFrameBuffer& src, | |
|
the sun
2016/12/05 22:36:29
IIUC most of these utility functions don't even ne
nisse-webrtc
2016/12/06 12:02:15
I found webrtc::I420Buffer::Rotate to be a reasona
the sun
2016/12/07 15:43:51
If it makes no practical difference, then leave it
| |
| 43 VideoRotation rotation); | |
| 44 | |
| 45 // Sets all three planes to all zeros. Used to work around for | |
| 46 // quirks in memory checkers | |
| 47 // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and | |
| 48 // ffmpeg (http://crbug.com/390941). | |
| 49 // TODO(nisse): Deprecated. Should be deleted if/when those issues | |
| 50 // are resolved in a better way. | |
| 51 void InitializeData(); | |
| 52 | |
| 53 // Sets the frame buffer to all black. | |
| 54 // TODO(nisse): Make this a static method instead? | |
| 55 void SetToBlack(); | |
| 56 | |
| 57 int width() const override; | |
| 58 int height() const override; | |
| 59 const uint8_t* DataY() const override; | |
| 60 const uint8_t* DataU() const override; | |
| 61 const uint8_t* DataV() const override; | |
| 62 | |
| 63 uint8_t* MutableDataY(); | |
|
the sun
2016/12/05 22:36:29
Put overrides from base class together in one sect
nisse-webrtc
2016/12/06 12:02:15
Ok, will reorder.
nisse-webrtc
2016/12/13 15:08:02
Done.
| |
| 64 uint8_t* MutableDataU(); | |
| 65 uint8_t* MutableDataV(); | |
| 66 int StrideY() const override; | |
| 67 int StrideU() const override; | |
| 68 int StrideV() const override; | |
| 69 | |
| 70 void* native_handle() const override; | |
| 71 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | |
| 72 | |
| 73 // Scale the cropped area of |src| to the size of |this| buffer, and | |
| 74 // write the result into |this|. | |
| 75 void CropAndScaleFrom(const VideoFrameBuffer& src, | |
| 76 int offset_x, | |
| 77 int offset_y, | |
| 78 int crop_width, | |
| 79 int crop_height); | |
| 80 | |
| 81 // The common case of a center crop, when needed to adjust the | |
| 82 // aspect ratio without distorting the image. | |
| 83 void CropAndScaleFrom(const VideoFrameBuffer& src); | |
| 84 | |
| 85 // Scale all of |src| to the size of |this| buffer, with no cropping. | |
| 86 void ScaleFrom(const VideoFrameBuffer& src); | |
| 87 | |
| 88 // TODO(nisse): Deprecated, delete once downstream applications are updated. | |
| 89 // Returns a rotated versions of |src|. Native buffers are not | |
| 90 // supported. The reason this function doesn't return an I420Buffer, | |
| 91 // is that it returns |src| unchanged in case |rotation| is zero. | |
| 92 static rtc::scoped_refptr<VideoFrameBuffer> Rotate( | |
| 93 rtc::scoped_refptr<VideoFrameBuffer> src, | |
| 94 VideoRotation rotation); | |
| 95 | |
| 96 protected: | |
| 97 I420Buffer(int width, int height); | |
| 98 I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); | |
| 99 | |
| 100 ~I420Buffer() override; | |
| 101 | |
| 102 private: | |
| 103 const int width_; | |
| 104 const int height_; | |
| 105 const int stride_y_; | |
| 106 const int stride_u_; | |
| 107 const int stride_v_; | |
| 108 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; | |
| 109 }; | |
| 110 | |
| 111 } // namespace webrtc | |
| 112 | |
| 113 #endif // WEBRTC_API_VIDEO_I420_BUFFER_H_ | |
| OLD | NEW |