Commit 40c2c94f authored by magjed's avatar magjed Committed by Commit bot

Mac Video Capture: Add support for pixel format NV12 for AVFoundation

BUG=346634

Review URL: https://codereview.chromium.org/860333003

Cr-Commit-Position: refs/heads/master@{#313886}
parent 5fdae3e4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "media/base/mac/corevideo_glue.h"
#include "media/video/capture/mac/video_capture_device_mac.h" #include "media/video/capture/mac/video_capture_device_mac.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -25,6 +26,8 @@ media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) { ...@@ -25,6 +26,8 @@ media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) {
return media::PIXEL_FORMAT_YUY2; return media::PIXEL_FORMAT_YUY2;
case CoreMediaGlue::kCMVideoCodecType_JPEG_OpenDML: case CoreMediaGlue::kCMVideoCodecType_JPEG_OpenDML:
return media::PIXEL_FORMAT_MJPEG; return media::PIXEL_FORMAT_MJPEG;
case CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
return media::PIXEL_FORMAT_NV12;
default: default:
return media::PIXEL_FORMAT_UNKNOWN; return media::PIXEL_FORMAT_UNKNOWN;
} }
...@@ -312,9 +315,31 @@ media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) { ...@@ -312,9 +315,31 @@ media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) {
// Lock the frame and calculate frame size. // Lock the frame and calculate frame size.
if (CVPixelBufferLockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly) == if (CVPixelBufferLockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly) ==
kCVReturnSuccess) { kCVReturnSuccess) {
baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); baseAddress = static_cast<char*>(
frameSize = CVPixelBufferGetHeight(videoFrame) * CVPixelBufferGetPlaneCount(videoFrame) == 0
CVPixelBufferGetBytesPerRow(videoFrame); ? CVPixelBufferGetBaseAddress(videoFrame)
: CVPixelBufferGetBaseAddressOfPlane(videoFrame, 0));
// Chromium expects the data to be tightly packed, i.e. no row padding
// and the planes should follow consecutively.
switch (captureFormat.pixel_format) {
case media::PIXEL_FORMAT_YUY2:
case media::PIXEL_FORMAT_UYVY:
CHECK_EQ(CVPixelBufferGetBytesPerRow(videoFrame),
static_cast<size_t>(2 * captureFormat.frame_size.width()));
frameSize = captureFormat.frame_size.GetArea() * 16 / 8; // 16bpp.
break;
case media::PIXEL_FORMAT_NV12:
CHECK_EQ(CVPixelBufferGetBytesPerRowOfPlane(videoFrame, 0),
static_cast<size_t>(captureFormat.frame_size.width()));
CHECK_EQ(CVPixelBufferGetBytesPerRowOfPlane(videoFrame, 1),
static_cast<size_t>(captureFormat.frame_size.width()));
CHECK_EQ(CVPixelBufferGetBaseAddressOfPlane(videoFrame, 1),
baseAddress + captureFormat.frame_size.GetArea());
frameSize = captureFormat.frame_size.GetArea() * 12 / 8; // 12bpp.
break;
default:
NOTREACHED();
}
} else { } else {
videoFrame = nil; videoFrame = nil;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment