Sergio Garcia Murillo | 1389c4b | 2023-01-09 18:29:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 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 API_VIDEO_I410_BUFFER_H_ |
| 12 | #define API_VIDEO_I410_BUFFER_H_ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | #include <memory> |
| 17 | |
| 18 | #include "api/scoped_refptr.h" |
| 19 | #include "api/video/video_frame_buffer.h" |
| 20 | #include "api/video/video_rotation.h" |
| 21 | #include "rtc_base/memory/aligned_malloc.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // Plain I410 (yuv 444 planar 10 bits) buffer in standard memory. |
| 26 | class RTC_EXPORT I410Buffer : public I410BufferInterface { |
| 27 | public: |
| 28 | static rtc::scoped_refptr<I410Buffer> Create(int width, int height); |
| 29 | static rtc::scoped_refptr<I410Buffer> Create(int width, |
| 30 | int height, |
| 31 | int stride_y, |
| 32 | int stride_u, |
| 33 | int stride_v); |
| 34 | |
| 35 | // Create a new buffer and copy the pixel data. |
| 36 | static rtc::scoped_refptr<I410Buffer> Copy(const I410BufferInterface& buffer); |
| 37 | |
| 38 | static rtc::scoped_refptr<I410Buffer> Copy(int width, |
| 39 | int height, |
| 40 | const uint16_t* data_y, |
| 41 | int stride_y, |
| 42 | const uint16_t* data_u, |
| 43 | int stride_u, |
| 44 | const uint16_t* data_v, |
| 45 | int stride_v); |
| 46 | |
| 47 | // Returns a rotated copy of |src|. |
| 48 | static rtc::scoped_refptr<I410Buffer> Rotate(const I410BufferInterface& src, |
| 49 | VideoRotation rotation); |
| 50 | |
| 51 | rtc::scoped_refptr<I420BufferInterface> ToI420() final; |
| 52 | const I420BufferInterface* GetI420() const final { return nullptr; } |
| 53 | |
| 54 | // Sets all three planes to all zeros. Used to work around for |
| 55 | // quirks in memory checkers |
| 56 | // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and |
| 57 | // ffmpeg (http://crbug.com/390941). |
| 58 | // TODO(https://crbug.com/390941): Deprecated. Should be deleted if/when those |
| 59 | // issues are resolved in a better way. Or in the mean time, use SetBlack. |
| 60 | void InitializeData(); |
| 61 | |
| 62 | int width() const override; |
| 63 | int height() const override; |
| 64 | const uint16_t* DataY() const override; |
| 65 | const uint16_t* DataU() const override; |
| 66 | const uint16_t* DataV() const override; |
| 67 | |
| 68 | int StrideY() const override; |
| 69 | int StrideU() const override; |
| 70 | int StrideV() const override; |
| 71 | |
| 72 | uint16_t* MutableDataY(); |
| 73 | uint16_t* MutableDataU(); |
| 74 | uint16_t* MutableDataV(); |
| 75 | |
| 76 | // Scale the cropped area of |src| to the size of |this| buffer, and |
| 77 | // write the result into |this|. |
| 78 | void CropAndScaleFrom(const I410BufferInterface& src, |
| 79 | int offset_x, |
| 80 | int offset_y, |
| 81 | int crop_width, |
| 82 | int crop_height); |
| 83 | |
| 84 | // Scale all of `src` to the size of `this` buffer, with no cropping. |
| 85 | void ScaleFrom(const I410BufferInterface& src); |
| 86 | |
| 87 | protected: |
| 88 | I410Buffer(int width, int height); |
| 89 | I410Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 90 | |
| 91 | ~I410Buffer() override; |
| 92 | |
| 93 | private: |
| 94 | const int width_; |
| 95 | const int height_; |
| 96 | const int stride_y_; |
| 97 | const int stride_u_; |
| 98 | const int stride_v_; |
| 99 | const std::unique_ptr<uint16_t, AlignedFreeDeleter> data_; |
| 100 | }; |
| 101 | |
| 102 | } // namespace webrtc |
| 103 | |
| 104 | #endif // API_VIDEO_I410_BUFFER_H_ |