blob: 8eb484c069594b40019ba7d9d57fdbc1c307631e [file] [log] [blame]
Evan Shrubsole84995432020-09-09 16:14:19 +02001/*
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 <memory>
15#include <utility>
16
17#include "api/scoped_refptr.h"
18#include "api/video/video_frame_buffer.h"
19#include "rtc_base/memory/aligned_malloc.h"
20#include "rtc_base/system/rtc_export.h"
21
22namespace webrtc {
23
24// NV12 is a biplanar encoding format, with full-resolution Y and
25// half-resolution interleved UV. More information can be found at
26// http://msdn.microsoft.com/library/windows/desktop/dd206750.aspx#nv12.
27class RTC_EXPORT NV12Buffer : public NV12BufferInterface {
28 public:
29 static rtc::scoped_refptr<NV12Buffer> Create(int width, int height);
30 static rtc::scoped_refptr<NV12Buffer> Create(int width,
31 int height,
32 int stride_y,
33 int stride_uv);
34
35 rtc::scoped_refptr<I420BufferInterface> ToI420() override;
36
37 int width() const override;
38 int height() const override;
39
40 int StrideY() const override;
41 int StrideUV() const override;
42
43 const uint8_t* DataY() const override;
44 const uint8_t* DataUV() const override;
45
46 uint8_t* MutableDataY();
47 uint8_t* MutableDataUV();
48
49 protected:
50 NV12Buffer(int width, int height);
51 NV12Buffer(int width, int height, int stride_y, int stride_uv);
52
53 ~NV12Buffer() override;
54
55 private:
56 size_t UVOffset() const;
57
58 const int width_;
59 const int height_;
60 const int stride_y_;
61 const int stride_uv_;
62 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_;
63};
64
65} // namespace webrtc
66
67#endif // API_VIDEO_NV12_BUFFER_H_