tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nv12_buffer.h (2784B)


      1 /*
      2 *  Copyright (c) 2020 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_NV12_BUFFER_H_
     12 #define API_VIDEO_NV12_BUFFER_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <memory>
     17 
     18 #include "api/scoped_refptr.h"
     19 #include "api/video/video_frame_buffer.h"
     20 #include "rtc_base/memory/aligned_malloc.h"
     21 #include "rtc_base/system/rtc_export.h"
     22 
     23 namespace webrtc {
     24 
     25 // NV12 is a biplanar encoding format, with full-resolution Y and
     26 // half-resolution interleved UV. More information can be found at
     27 // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12.
     28 class RTC_EXPORT NV12Buffer : public NV12BufferInterface {
     29 public:
     30  static scoped_refptr<NV12Buffer> Create(int width, int height);
     31  static scoped_refptr<NV12Buffer> Create(int width,
     32                                          int height,
     33                                          int stride_y,
     34                                          int stride_uv);
     35  static scoped_refptr<NV12Buffer> Copy(const I420BufferInterface& i420_buffer);
     36 
     37  scoped_refptr<I420BufferInterface> ToI420() override;
     38 
     39  int width() const override;
     40  int height() const override;
     41 
     42  int StrideY() const override;
     43  int StrideUV() const override;
     44 
     45  const uint8_t* DataY() const override;
     46  const uint8_t* DataUV() const override;
     47 
     48  uint8_t* MutableDataY();
     49  uint8_t* MutableDataUV();
     50 
     51  // Sets all three planes to all zeros. Used to work around for
     52  // quirks in memory checkers
     53  // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and
     54  // ffmpeg (http://crbug.com/390941).
     55  // TODO(https://crbug.com/390941): Deprecated. Should be deleted if/when those
     56  // issues are resolved in a better way. Or in the mean time, use SetBlack.
     57  void InitializeData();
     58 
     59  // Scale the cropped area of `src` to the size of `this` buffer, and
     60  // write the result into `this`.
     61  void CropAndScaleFrom(const NV12BufferInterface& src,
     62                        int offset_x,
     63                        int offset_y,
     64                        int crop_width,
     65                        int crop_height);
     66 
     67 protected:
     68  NV12Buffer(int width, int height);
     69  NV12Buffer(int width, int height, int stride_y, int stride_uv);
     70 
     71  ~NV12Buffer() override;
     72 
     73 private:
     74  size_t UVOffset() const;
     75 
     76  const int width_;
     77  const int height_;
     78  const int stride_y_;
     79  const int stride_uv_;
     80  const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_;
     81 };
     82 
     83 }  // namespace webrtc
     84 
     85 #endif  // API_VIDEO_NV12_BUFFER_H_