Index: media/base/video_frame.cc |
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
index 456cf6e9d887bc089e4c899db1cb84d9e99fd3d3..f80b0aa7875861cb484bb143b721d8b14d3e21d7 100644 |
--- a/media/base/video_frame.cc |
+++ b/media/base/video_frame.cc |
@@ -16,6 +16,10 @@ |
#include "media/base/video_util.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#if defined(OS_MACOSX) |
+#include <CoreVideo/CoreVideo.h> |
+#endif |
+ |
namespace media { |
static inline size_t RoundUp(size_t value, size_t alignment) { |
@@ -278,6 +282,49 @@ 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 |
Robert Sesek
2014/08/07 16:12:57
nit: capitalization and punctuation
jfroy
2014/08/07 16:22:14
Acknowledged.
|
+ if (cv_format == kCVPixelFormatType_420YpCbCr8Planar) { |
+ format = Format::I420; |
+ } else if (cv_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) { |
Robert Sesek
2014/08/07 16:12:57
This is only available on 10.7 and later. This wil
jfroy
2014/08/07 16:22:14
Wow, are you telling me Chrome needs to build on 1
Robert Sesek
2014/08/07 16:34:42
Yes. Build and run. This has been the requirement
jfroy
2014/08/07 16:52:45
I'm brand new to Chrome development, I didn't know
Robert Sesek
2014/08/07 18:00:15
Actually, it's quite trivial. You just need go/mac
|
+ format = Format::NV12; |
+ } else if (cv_format == kCVPixelFormatType_444YpCbCr8) { |
+ format = Format::YV24; |
+ } 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, |
@@ -852,6 +899,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)) |