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

Unified Diff: media/base/video_frame.cc

Issue 446163003: Extend media::VideoFrame to wrap CVPixelBuffer on OS X and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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 | « media/base/video_frame.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/video_frame.cc
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc
index 6b3427db1aa936c1707b507f13e1070ed33710b0..c77dc1348b69258fef99544846521374ddf1f290 100644
--- a/media/base/video_frame.cc
+++ b/media/base/video_frame.cc
@@ -278,6 +278,51 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalDmabufs(
}
#endif
+#if defined(OS_MACOSX)
+// static
+scoped_refptr<VideoFrame> VideoFrame::WrapCVPixelBuffer(
+ CVPixelBufferRef cv_pixel_buffer,
+ base::TimeDelta timestamp) {
+ DCHECK(cv_pixel_buffer);
+ DCHECK(CFGetTypeID(cv_pixel_buffer) == CVPixelBufferGetTypeID());
+
+ OSType cv_format = CVPixelBufferGetPixelFormatType(cv_pixel_buffer);
+ Format format;
+ // There are very few compatible CV pixel formats, so just check each.
+ if (cv_format == kCVPixelFormatType_420YpCbCr8Planar) {
+ format = Format::I420;
+ } else if (cv_format == kCVPixelFormatType_444YpCbCr8) {
+ format = Format::YV24;
+ } else if (cv_format == '420v') {
+ // TODO(jfroy): Use kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange when the
miu 2014/08/25 18:39:35 I've seen others solve this problem by using #ifde
Robert Sesek 2014/08/25 18:42:07 There was already back-and-forth about this on the
+ // minimum OS X and iOS SDKs permits it.
+ format = Format::NV12;
+ } else {
+ DLOG(ERROR) << "CVPixelBuffer format not supported: " << cv_format;
+ return NULL;
+ }
+
+ gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer));
+ gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer));
+ gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer));
+
+ if (!IsValidConfig(format, coded_size, visible_rect, natural_size))
+ return NULL;
+
+ scoped_refptr<VideoFrame> frame(
+ new VideoFrame(format,
+ coded_size,
+ visible_rect,
+ natural_size,
+ scoped_ptr<gpu::MailboxHolder>(),
+ timestamp,
+ false));
+
+ frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN);
+ return frame;
+}
+#endif
+
// static
scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData(
Format format,
@@ -857,6 +902,12 @@ int VideoFrame::dmabuf_fd(size_t plane) const {
}
#endif
+#if defined(OS_MACOSX)
+CVPixelBufferRef VideoFrame::cv_pixel_buffer() const {
+ return cv_pixel_buffer_.get();
+}
+#endif
+
void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
for (int plane = 0; plane < kMaxPlanes; ++plane) {
if (!IsValidPlane(plane, format_))
« no previous file with comments | « media/base/video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698