nv12_buffer.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef API_VIDEO_NV12_BUFFER_H_
  11. #define API_VIDEO_NV12_BUFFER_H_
  12. #include <memory>
  13. #include <utility>
  14. #include "api/scoped_refptr.h"
  15. #include "api/video/video_frame_buffer.h"
  16. #include "rtc_base/memory/aligned_malloc.h"
  17. #include "rtc_base/system/rtc_export.h"
  18. namespace webrtc {
  19. // NV12 is a biplanar encoding format, with full-resolution Y and
  20. // half-resolution interleved UV. More information can be found at
  21. // http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12.
  22. class RTC_EXPORT NV12Buffer : public NV12BufferInterface {
  23. public:
  24. static rtc::scoped_refptr<NV12Buffer> Create(int width, int height);
  25. static rtc::scoped_refptr<NV12Buffer> Create(int width,
  26. int height,
  27. int stride_y,
  28. int stride_uv);
  29. static rtc::scoped_refptr<NV12Buffer> Copy(
  30. const I420BufferInterface& i420_buffer);
  31. rtc::scoped_refptr<I420BufferInterface> ToI420() override;
  32. int width() const override;
  33. int height() const override;
  34. int StrideY() const override;
  35. int StrideUV() const override;
  36. const uint8_t* DataY() const override;
  37. const uint8_t* DataUV() const override;
  38. uint8_t* MutableDataY();
  39. uint8_t* MutableDataUV();
  40. // Sets all three planes to all zeros. Used to work around for
  41. // quirks in memory checkers
  42. // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and
  43. // ffmpeg (http://crbug.com/390941).
  44. // TODO(nisse): Deprecated. Should be deleted if/when those issues
  45. // are resolved in a better way. Or in the mean time, use SetBlack.
  46. void InitializeData();
  47. protected:
  48. NV12Buffer(int width, int height);
  49. NV12Buffer(int width, int height, int stride_y, int stride_uv);
  50. ~NV12Buffer() override;
  51. private:
  52. size_t UVOffset() const;
  53. const int width_;
  54. const int height_;
  55. const int stride_y_;
  56. const int stride_uv_;
  57. const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_;
  58. };
  59. } // namespace webrtc
  60. #endif // API_VIDEO_NV12_BUFFER_H_