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