Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(887)

Unified Diff: webrtc/common_video/corevideo_frame_buffer.cc

Issue 1853503003: Add CoreVideoFrameBuffer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rename file for readability. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_video/common_video.gyp ('k') | webrtc/common_video/include/corevideo_frame_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_video/corevideo_frame_buffer.cc
diff --git a/webrtc/common_video/corevideo_frame_buffer.cc b/webrtc/common_video/corevideo_frame_buffer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..55dc00da858b9eaae93961cb38359502d0da4041
--- /dev/null
+++ b/webrtc/common_video/corevideo_frame_buffer.cc
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/common_video/include/corevideo_frame_buffer.h"
+
+#include "libyuv/convert.h"
+#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
+
+namespace webrtc {
+
+CoreVideoFrameBuffer::CoreVideoFrameBuffer(CVPixelBufferRef pixel_buffer)
+ : NativeHandleBuffer(pixel_buffer,
+ CVPixelBufferGetWidth(pixel_buffer),
+ CVPixelBufferGetHeight(pixel_buffer)),
+ pixel_buffer_(pixel_buffer) {
+ CVBufferRetain(pixel_buffer_);
+}
+
+CoreVideoFrameBuffer::~CoreVideoFrameBuffer() {
+ CVBufferRelease(pixel_buffer_);
+}
+
+rtc::scoped_refptr<VideoFrameBuffer>
+CoreVideoFrameBuffer::NativeToI420Buffer() {
+ RTC_DCHECK(CVPixelBufferGetPixelFormatType(pixel_buffer_) ==
+ kCVPixelFormatType_420YpCbCr8BiPlanarFullRange);
+ size_t width = CVPixelBufferGetWidthOfPlane(pixel_buffer_, 0);
+ size_t height = CVPixelBufferGetHeightOfPlane(pixel_buffer_, 0);
+ // TODO(tkchin): Use a frame buffer pool.
+ rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
+ new rtc::RefCountedObject<webrtc::I420Buffer>(width, height);
+ CVPixelBufferLockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly);
+ const uint8_t* src_y = static_cast<const uint8_t*>(
+ CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 0));
+ int src_y_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 0);
+ const uint8_t* src_uv = static_cast<const uint8_t*>(
+ CVPixelBufferGetBaseAddressOfPlane(pixel_buffer_, 1));
+ int src_uv_stride = CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer_, 1);
+ int ret = libyuv::NV12ToI420(
+ src_y, src_y_stride, src_uv, src_uv_stride,
+ buffer->MutableData(webrtc::kYPlane), buffer->stride(webrtc::kYPlane),
+ buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane),
+ buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane),
+ width, height);
+ CVPixelBufferUnlockBaseAddress(pixel_buffer_, kCVPixelBufferLock_ReadOnly);
+ if (ret) {
+ LOG(LS_ERROR) << "Error converting NV12 to I420: " << ret;
+ return nullptr;
+ }
+ return buffer;
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/common_video/common_video.gyp ('k') | webrtc/common_video/include/corevideo_frame_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698