blob: 0322dd1fd506027d4529464871ffbc0dca3393d1 [file] [log] [blame]
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +00001/*
2 * Copyright (c) 2015 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 */
perkj0489e492016-10-20 00:24:01 -070010#include "webrtc/common_video/include/video_frame_buffer.h"
11
12#include <string.h>
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000013
Niels Möller718a7632016-06-13 13:06:01 +020014#include <algorithm>
15
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000016#include "webrtc/base/checks.h"
perkj14f41442015-11-30 22:15:45 -080017#include "webrtc/base/keep_ref_until_done.h"
nisse7cc9cc02016-03-29 23:44:19 -070018#include "libyuv/convert.h"
fbarchardd1f83cf2016-07-08 17:33:20 -070019#include "libyuv/planar_functions.h"
Niels Möller718a7632016-06-13 13:06:01 +020020#include "libyuv/scale.h"
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000021
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000022namespace webrtc {
23
Peter Boströmeb66e802015-06-05 11:08:03 +020024NativeHandleBuffer::NativeHandleBuffer(void* native_handle,
25 int width,
26 int height)
27 : native_handle_(native_handle), width_(width), height_(height) {
henrikg91d6ede2015-09-17 00:24:34 -070028 RTC_DCHECK(native_handle != nullptr);
29 RTC_DCHECK_GT(width, 0);
30 RTC_DCHECK_GT(height, 0);
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000031}
32
magjed712338e2017-05-11 05:11:57 -070033VideoFrameBuffer::Type NativeHandleBuffer::type() const {
34 return Type::kNative;
35}
36
Peter Boströmeb66e802015-06-05 11:08:03 +020037int NativeHandleBuffer::width() const {
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000038 return width_;
39}
40
Peter Boströmeb66e802015-06-05 11:08:03 +020041int NativeHandleBuffer::height() const {
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000042 return height_;
43}
44
nisse06176e42016-04-18 05:34:40 -070045const uint8_t* NativeHandleBuffer::DataY() const {
46 RTC_NOTREACHED(); // Should not be called.
47 return nullptr;
48}
49const uint8_t* NativeHandleBuffer::DataU() const {
50 RTC_NOTREACHED(); // Should not be called.
51 return nullptr;
52}
53const uint8_t* NativeHandleBuffer::DataV() const {
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000054 RTC_NOTREACHED(); // Should not be called.
55 return nullptr;
56}
57
nisse06176e42016-04-18 05:34:40 -070058int NativeHandleBuffer::StrideY() const {
59 RTC_NOTREACHED(); // Should not be called.
60 return 0;
61}
62int NativeHandleBuffer::StrideU() const {
63 RTC_NOTREACHED(); // Should not be called.
64 return 0;
65}
66int NativeHandleBuffer::StrideV() const {
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000067 RTC_NOTREACHED(); // Should not be called.
68 return 0;
69}
70
Peter Boströmeb66e802015-06-05 11:08:03 +020071void* NativeHandleBuffer::native_handle() const {
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +000072 return native_handle_;
73}
74
Magnus Jedvertc464f502015-08-25 23:22:08 +020075WrappedI420Buffer::WrappedI420Buffer(int width,
Per33544192015-04-02 12:30:51 +020076 int height,
77 const uint8_t* y_plane,
78 int y_stride,
79 const uint8_t* u_plane,
80 int u_stride,
81 const uint8_t* v_plane,
82 int v_stride,
83 const rtc::Callback0<void>& no_longer_used)
Magnus Jedvertc464f502015-08-25 23:22:08 +020084 : width_(width),
85 height_(height),
86 y_plane_(y_plane),
87 u_plane_(u_plane),
88 v_plane_(v_plane),
89 y_stride_(y_stride),
90 u_stride_(u_stride),
91 v_stride_(v_stride),
92 no_longer_used_cb_(no_longer_used) {
Per33544192015-04-02 12:30:51 +020093}
94
95WrappedI420Buffer::~WrappedI420Buffer() {
96 no_longer_used_cb_();
97}
98
magjed712338e2017-05-11 05:11:57 -070099VideoFrameBuffer::Type WrappedI420Buffer::type() const {
100 return Type::kI420;
101}
102
Per33544192015-04-02 12:30:51 +0200103int WrappedI420Buffer::width() const {
104 return width_;
105}
106
107int WrappedI420Buffer::height() const {
108 return height_;
109}
110
nisse06176e42016-04-18 05:34:40 -0700111const uint8_t* WrappedI420Buffer::DataY() const {
112 return y_plane_;
113}
114const uint8_t* WrappedI420Buffer::DataU() const {
115 return u_plane_;
116}
117const uint8_t* WrappedI420Buffer::DataV() const {
118 return v_plane_;
Per33544192015-04-02 12:30:51 +0200119}
120
nisse06176e42016-04-18 05:34:40 -0700121int WrappedI420Buffer::StrideY() const {
122 return y_stride_;
123}
124int WrappedI420Buffer::StrideU() const {
125 return u_stride_;
126}
127int WrappedI420Buffer::StrideV() const {
128 return v_stride_;
Per33544192015-04-02 12:30:51 +0200129}
130
magjed@webrtc.org2386d6d2015-03-05 14:03:08 +0000131} // namespace webrtc