magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
perkj | 0489e49 | 2016-10-20 00:24:01 -0700 | [diff] [blame] | 10 | #include "webrtc/common_video/include/video_frame_buffer.h" |
| 11 | |
| 12 | #include <string.h> |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 13 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 14 | #include <algorithm> |
| 15 | |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
perkj | 14f4144 | 2015-11-30 22:15:45 -0800 | [diff] [blame] | 17 | #include "webrtc/base/keep_ref_until_done.h" |
nisse | 7cc9cc0 | 2016-03-29 23:44:19 -0700 | [diff] [blame] | 18 | #include "libyuv/convert.h" |
fbarchard | d1f83cf | 2016-07-08 17:33:20 -0700 | [diff] [blame] | 19 | #include "libyuv/planar_functions.h" |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 20 | #include "libyuv/scale.h" |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 21 | |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 24 | NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
| 25 | int width, |
| 26 | int height) |
| 27 | : native_handle_(native_handle), width_(width), height_(height) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 28 | RTC_DCHECK(native_handle != nullptr); |
| 29 | RTC_DCHECK_GT(width, 0); |
| 30 | RTC_DCHECK_GT(height, 0); |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 31 | } |
| 32 | |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame^] | 33 | VideoFrameBuffer::Type NativeHandleBuffer::type() const { |
| 34 | return Type::kNative; |
| 35 | } |
| 36 | |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 37 | int NativeHandleBuffer::width() const { |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 38 | return width_; |
| 39 | } |
| 40 | |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 41 | int NativeHandleBuffer::height() const { |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 42 | return height_; |
| 43 | } |
| 44 | |
nisse | 06176e4 | 2016-04-18 05:34:40 -0700 | [diff] [blame] | 45 | const uint8_t* NativeHandleBuffer::DataY() const { |
| 46 | RTC_NOTREACHED(); // Should not be called. |
| 47 | return nullptr; |
| 48 | } |
| 49 | const uint8_t* NativeHandleBuffer::DataU() const { |
| 50 | RTC_NOTREACHED(); // Should not be called. |
| 51 | return nullptr; |
| 52 | } |
| 53 | const uint8_t* NativeHandleBuffer::DataV() const { |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 54 | RTC_NOTREACHED(); // Should not be called. |
| 55 | return nullptr; |
| 56 | } |
| 57 | |
nisse | 06176e4 | 2016-04-18 05:34:40 -0700 | [diff] [blame] | 58 | int NativeHandleBuffer::StrideY() const { |
| 59 | RTC_NOTREACHED(); // Should not be called. |
| 60 | return 0; |
| 61 | } |
| 62 | int NativeHandleBuffer::StrideU() const { |
| 63 | RTC_NOTREACHED(); // Should not be called. |
| 64 | return 0; |
| 65 | } |
| 66 | int NativeHandleBuffer::StrideV() const { |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 67 | RTC_NOTREACHED(); // Should not be called. |
| 68 | return 0; |
| 69 | } |
| 70 | |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 71 | void* NativeHandleBuffer::native_handle() const { |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 72 | return native_handle_; |
| 73 | } |
| 74 | |
Magnus Jedvert | c464f50 | 2015-08-25 23:22:08 +0200 | [diff] [blame] | 75 | WrappedI420Buffer::WrappedI420Buffer(int width, |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 76 | 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 Jedvert | c464f50 | 2015-08-25 23:22:08 +0200 | [diff] [blame] | 84 | : 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) { |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | WrappedI420Buffer::~WrappedI420Buffer() { |
| 96 | no_longer_used_cb_(); |
| 97 | } |
| 98 | |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame^] | 99 | VideoFrameBuffer::Type WrappedI420Buffer::type() const { |
| 100 | return Type::kI420; |
| 101 | } |
| 102 | |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 103 | int WrappedI420Buffer::width() const { |
| 104 | return width_; |
| 105 | } |
| 106 | |
| 107 | int WrappedI420Buffer::height() const { |
| 108 | return height_; |
| 109 | } |
| 110 | |
nisse | 06176e4 | 2016-04-18 05:34:40 -0700 | [diff] [blame] | 111 | const uint8_t* WrappedI420Buffer::DataY() const { |
| 112 | return y_plane_; |
| 113 | } |
| 114 | const uint8_t* WrappedI420Buffer::DataU() const { |
| 115 | return u_plane_; |
| 116 | } |
| 117 | const uint8_t* WrappedI420Buffer::DataV() const { |
| 118 | return v_plane_; |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 119 | } |
| 120 | |
nisse | 06176e4 | 2016-04-18 05:34:40 -0700 | [diff] [blame] | 121 | int WrappedI420Buffer::StrideY() const { |
| 122 | return y_stride_; |
| 123 | } |
| 124 | int WrappedI420Buffer::StrideU() const { |
| 125 | return u_stride_; |
| 126 | } |
| 127 | int WrappedI420Buffer::StrideV() const { |
| 128 | return v_stride_; |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 129 | } |
| 130 | |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 131 | } // namespace webrtc |