Index: media/base/video_frame.cc |
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
index 456cf6e9d887bc089e4c899db1cb84d9e99fd3d3..c39dcbaddb51341f565148bde930eaa36e36f9b6 100644 |
--- a/media/base/video_frame.cc |
+++ b/media/base/video_frame.cc |
@@ -278,6 +278,54 @@ 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; |
+ } |
+#if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) || \ |
+ (__IPHONE_OS_VERSION_MIN_REQUIRED >= 40000) |
Robert Sesek
2014/08/07 18:00:15
Does //media even get compiled on iOS? If not, rem
jfroy
2014/08/07 18:08:20
It is for my purpose. I can still switch to using
Robert Sesek
2014/08/07 18:14:44
If this code doesn't build on iOS, then remove the
|
+ else if (cv_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) { |
+ format = Format::NV12; |
+ } |
+#endif |
+ 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 +900,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)) |