Bug 1421187 - P4. Make mac decoder output YUV420 format. r?mattwoodrow
There's little advantage over using NV12 and using YUV420 allows for easier and faster frame copy. We assume of course that Apple's VideoToolbox have more optimized code than we do.
MozReview-Commit-ID: IjvepxW3OZI
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -356,17 +356,17 @@ AppleVTDecoder::OutputFrame(CVPixelBuffe
if (useNullSample) {
data = new NullData(aFrameRef.byte_offset,
aFrameRef.composition_timestamp,
aFrameRef.duration);
} else if (mUseSoftwareImages) {
size_t width = CVPixelBufferGetWidth(aImage);
size_t height = CVPixelBufferGetHeight(aImage);
DebugOnly<size_t> planes = CVPixelBufferGetPlaneCount(aImage);
- MOZ_ASSERT(planes == 2, "Likely not NV12 format and it must be.");
+ MOZ_ASSERT(planes == 3, "Likely not YUV420 format and it must be.");
VideoData::YCbCrBuffer buffer;
// Lock the returned image data.
CVReturn rv = CVPixelBufferLockBaseAddress(aImage, kCVPixelBufferLock_ReadOnly);
if (rv != kCVReturnSuccess) {
NS_ERROR("error locking pixel data");
MonitorAutoLock mon(mMonitor);
@@ -386,25 +386,25 @@ AppleVTDecoder::OutputFrame(CVPixelBuffe
buffer.mPlanes[0].mSkip = 0;
// Cb plane.
buffer.mPlanes[1].mData =
static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(aImage, 1));
buffer.mPlanes[1].mStride = CVPixelBufferGetBytesPerRowOfPlane(aImage, 1);
buffer.mPlanes[1].mWidth = (width+1) / 2;
buffer.mPlanes[1].mHeight = (height+1) / 2;
buffer.mPlanes[1].mOffset = 0;
- buffer.mPlanes[1].mSkip = 1;
+ buffer.mPlanes[1].mSkip = 0;
// Cr plane.
buffer.mPlanes[2].mData =
- static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(aImage, 1));
- buffer.mPlanes[2].mStride = CVPixelBufferGetBytesPerRowOfPlane(aImage, 1);
+ static_cast<uint8_t*>(CVPixelBufferGetBaseAddressOfPlane(aImage, 2));
+ buffer.mPlanes[2].mStride = CVPixelBufferGetBytesPerRowOfPlane(aImage, 2);
buffer.mPlanes[2].mWidth = (width+1) / 2;
buffer.mPlanes[2].mHeight = (height+1) / 2;
- buffer.mPlanes[2].mOffset = 1;
- buffer.mPlanes[2].mSkip = 1;
+ buffer.mPlanes[2].mOffset = 0;
+ buffer.mPlanes[2].mSkip = 0;
gfx::IntRect visible = gfx::IntRect(0,
0,
mPictureWidth,
mPictureHeight);
// Copy the image data into our own format.
data =
@@ -597,17 +597,17 @@ AppleVTDecoder::CreateDecoderSpecificati
}
CFDictionaryRef
AppleVTDecoder::CreateOutputConfiguration()
{
if (mUseSoftwareImages) {
// Output format type:
SInt32 PixelFormatTypeValue =
- kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
+ kCVPixelFormatType_420YpCbCr8Planar;
AutoCFRelease<CFNumberRef> PixelFormatTypeNumber =
CFNumberCreate(kCFAllocatorDefault,
kCFNumberSInt32Type,
&PixelFormatTypeValue);
const void* outputKeys[] = { kCVPixelBufferPixelFormatTypeKey };
const void* outputValues[] = { PixelFormatTypeNumber };
static_assert(ArrayLength(outputKeys) == ArrayLength(outputValues),
"Non matching keys/values array size");