Chromium Code Reviews| 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 | 10 |
| 11 #include "webrtc/common_video/include/video_frame_buffer.h" | 11 #include "webrtc/common_video/include/video_frame_buffer.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/keep_ref_until_done.h" | 14 #include "webrtc/base/keep_ref_until_done.h" |
| 15 #include "webrtc/base/logging.h" | |
| 15 #include "libyuv/convert.h" | 16 #include "libyuv/convert.h" |
| 16 | 17 |
| 17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. | 18 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. |
| 18 static const int kBufferAlignment = 64; | 19 static const int kBufferAlignment = 64; |
| 19 | 20 |
| 20 namespace webrtc { | 21 namespace webrtc { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { | 25 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 const uint8_t* v_plane = buffer->data(kVPlane) + | 260 const uint8_t* v_plane = buffer->data(kVPlane) + |
| 260 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; | 261 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; |
| 261 return new rtc::RefCountedObject<WrappedI420Buffer>( | 262 return new rtc::RefCountedObject<WrappedI420Buffer>( |
| 262 cropped_width, cropped_height, | 263 cropped_width, cropped_height, |
| 263 y_plane, buffer->stride(kYPlane), | 264 y_plane, buffer->stride(kYPlane), |
| 264 u_plane, buffer->stride(kUPlane), | 265 u_plane, buffer->stride(kUPlane), |
| 265 v_plane, buffer->stride(kVPlane), | 266 v_plane, buffer->stride(kVPlane), |
| 266 rtc::KeepRefUntilDone(buffer)); | 267 rtc::KeepRefUntilDone(buffer)); |
| 267 } | 268 } |
| 268 | 269 |
| 270 #if defined(WEBRTC_MAC) || defined(WEBRTC_IOS) | |
|
pbos-webrtc
2016/04/01 11:56:10
I want this in a separate file that's only compile
tkchin_webrtc
2016/04/01 16:09:29
Done.
| |
| 271 | |
| 272 CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer) | |
| 273 : NativeHandleBuffer(pixel_buffer, | |
| 274 CVPixelBufferGetWidth(pixel_buffer), | |
| 275 CVPixelBufferGetHeight(pixel_buffer)), | |
| 276 pixel_buffer_(pixel_buffer) { | |
| 277 CVBufferRetain(pixel_buffer_); | |
| 278 } | |
| 279 | |
| 280 CoreVideoFrameBuffer::~CoreVideoFrameBuffer() { | |
| 281 CVBufferRelease(pixel_buffer_); | |
| 282 } | |
| 283 | |
| 284 rtc::scoped_refptr<VideoFrameBuffer> | |
| 285 CoreVideoFrameBuffer::NativeToI420Buffer() { | |
| 286 RTC_DCHECK(CVPixelBufferGetPixelFormatType(pixel_buffer_) == | |
| 287 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange); | |
| 288 size_t width = CVPixelBufferGetWidthOfPlane(pixel_buffer_, 0); | |
| 289 size_t height = CVPixelBufferGetHeightOfPlane(pixel_buffer_, 0); | |
| 290 // TODO(tkchin): Use a frame buffer pool. | |
| 291 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = | |
| 292 new rtc::RefCountedObject<webrtc::I420Buffer>(width, height); | |
| 293 CVPixelBufferLockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); | |
| 294 const uint8_t* src_y = static_cast<const uint8_t*>( | |
| 295 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 0)); | |
| 296 int src_y_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 0); | |
| 297 const uint8_t* src_uv = static_cast<const uint8_t*>( | |
| 298 CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 1)); | |
| 299 int src_uv_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 1); | |
| 300 int ret = libyuv::NV12ToI420( | |
| 301 src_y, src_y_stride, src_uv, src_uv_stride, | |
| 302 buffer->MutableData(webrtc::kYPlane), buffer->stride(webrtc::kYPlane), | |
| 303 buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane), | |
| 304 buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane), | |
| 305 width, height); | |
| 306 CVPixelBufferUnlockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly); | |
| 307 if (ret) { | |
| 308 LOG(LS_ERROR) << "Error converting NV12 to I420: " << ret; | |
| 309 return nullptr; | |
| 310 } | |
| 311 return buffer; | |
| 312 } | |
| 313 | |
| 314 #endif // if defined(WEBRTC_MAC) || defined(WEBRTC_IOS) | |
| 315 | |
| 269 } // namespace webrtc | 316 } // namespace webrtc |
| OLD | NEW |