Chromium Code Reviews| Index: media/base/video_frame.cc |
| diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
| index 456cf6e9d887bc089e4c899db1cb84d9e99fd3d3..1da907ec35d97b89a9b52dfbf214a56d54c6fa90 100644 |
| --- a/media/base/video_frame.cc |
| +++ b/media/base/video_frame.cc |
| @@ -278,6 +278,50 @@ 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') { |
| + // NOTE: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange |
|
Robert Sesek
2014/08/12 00:09:40
TODO(jfroy): Use kCVPixelFormatType_420YpCbCr8BiPl
jfroy
2014/08/12 00:46:54
Acknowledged.
|
| + 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, |
| @@ -852,6 +896,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)) |