OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/common_video/include/video_frame_buffer.h" | 10 #include "webrtc/common_video/include/video_frame_buffer.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 int WrappedI420Buffer::StrideY() const { | 117 int WrappedI420Buffer::StrideY() const { |
118 return y_stride_; | 118 return y_stride_; |
119 } | 119 } |
120 int WrappedI420Buffer::StrideU() const { | 120 int WrappedI420Buffer::StrideU() const { |
121 return u_stride_; | 121 return u_stride_; |
122 } | 122 } |
123 int WrappedI420Buffer::StrideV() const { | 123 int WrappedI420Buffer::StrideV() const { |
124 return v_stride_; | 124 return v_stride_; |
125 } | 125 } |
126 | 126 |
| 127 // Template to implement a wrapped buffer for a I4??BufferInterface. |
| 128 template <typename Base> |
| 129 class WrappedYuvBuffer : public Base { |
| 130 public: |
| 131 WrappedYuvBuffer(int width, |
| 132 int height, |
| 133 const uint8_t* y_plane, |
| 134 int y_stride, |
| 135 const uint8_t* u_plane, |
| 136 int u_stride, |
| 137 const uint8_t* v_plane, |
| 138 int v_stride, |
| 139 const rtc::Callback0<void>& no_longer_used) |
| 140 : width_(width), |
| 141 height_(height), |
| 142 y_plane_(y_plane), |
| 143 u_plane_(u_plane), |
| 144 v_plane_(v_plane), |
| 145 y_stride_(y_stride), |
| 146 u_stride_(u_stride), |
| 147 v_stride_(v_stride), |
| 148 no_longer_used_cb_(no_longer_used) {} |
| 149 |
| 150 int width() const override { return width_; } |
| 151 |
| 152 int height() const override { return height_; } |
| 153 |
| 154 const uint8_t* DataY() const override { return y_plane_; } |
| 155 |
| 156 const uint8_t* DataU() const override { return u_plane_; } |
| 157 |
| 158 const uint8_t* DataV() const override { return v_plane_; } |
| 159 |
| 160 int StrideY() const override { return y_stride_; } |
| 161 |
| 162 int StrideU() const override { return u_stride_; } |
| 163 |
| 164 int StrideV() const override { return v_stride_; } |
| 165 |
| 166 private: |
| 167 friend class rtc::RefCountedObject<WrappedYuvBuffer>; |
| 168 |
| 169 ~WrappedYuvBuffer() override { no_longer_used_cb_(); } |
| 170 |
| 171 const int width_; |
| 172 const int height_; |
| 173 const uint8_t* const y_plane_; |
| 174 const uint8_t* const u_plane_; |
| 175 const uint8_t* const v_plane_; |
| 176 const int y_stride_; |
| 177 const int u_stride_; |
| 178 const int v_stride_; |
| 179 rtc::Callback0<void> no_longer_used_cb_; |
| 180 }; |
| 181 |
| 182 rtc::scoped_refptr<I420BufferInterface> WrapI420Buffer( |
| 183 int width, |
| 184 int height, |
| 185 const uint8_t* y_plane, |
| 186 int y_stride, |
| 187 const uint8_t* u_plane, |
| 188 int u_stride, |
| 189 const uint8_t* v_plane, |
| 190 int v_stride, |
| 191 const rtc::Callback0<void>& no_longer_used) { |
| 192 return rtc::scoped_refptr<I420BufferInterface>( |
| 193 new rtc::RefCountedObject<WrappedYuvBuffer<I420BufferInterface>>( |
| 194 width, height, y_plane, y_stride, u_plane, u_stride, v_plane, |
| 195 v_stride, no_longer_used)); |
| 196 } |
| 197 |
| 198 rtc::scoped_refptr<I444BufferInterface> WrapI444Buffer( |
| 199 int width, |
| 200 int height, |
| 201 const uint8_t* y_plane, |
| 202 int y_stride, |
| 203 const uint8_t* u_plane, |
| 204 int u_stride, |
| 205 const uint8_t* v_plane, |
| 206 int v_stride, |
| 207 const rtc::Callback0<void>& no_longer_used) { |
| 208 return rtc::scoped_refptr<I444BufferInterface>( |
| 209 new rtc::RefCountedObject<WrappedYuvBuffer<I444BufferInterface>>( |
| 210 width, height, y_plane, y_stride, u_plane, u_stride, v_plane, |
| 211 v_stride, no_longer_used)); |
| 212 } |
| 213 |
| 214 rtc::scoped_refptr<PlanarYuvBuffer> WrapYuvBuffer( |
| 215 VideoFrameBuffer::Type type, |
| 216 int width, |
| 217 int height, |
| 218 const uint8_t* y_plane, |
| 219 int y_stride, |
| 220 const uint8_t* u_plane, |
| 221 int u_stride, |
| 222 const uint8_t* v_plane, |
| 223 int v_stride, |
| 224 const rtc::Callback0<void>& no_longer_used) { |
| 225 switch (type) { |
| 226 case VideoFrameBuffer::Type::kI420: |
| 227 return WrapI420Buffer(width, height, y_plane, y_stride, u_plane, u_stride, |
| 228 v_plane, v_stride, no_longer_used); |
| 229 case VideoFrameBuffer::Type::kI444: |
| 230 return WrapI444Buffer(width, height, y_plane, y_stride, u_plane, u_stride, |
| 231 v_plane, v_stride, no_longer_used); |
| 232 default: |
| 233 FATAL() << "Unexpected frame buffer type."; |
| 234 return nullptr; |
| 235 } |
| 236 } |
| 237 |
127 } // namespace webrtc | 238 } // namespace webrtc |
OLD | NEW |