Bug 1540581 - P8. Set decoding format back to NV12 and set colorspace. r=bryce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 Apr 2019 12:37:16 +0000
changeset 469136 d2b6cc14a04347d2b69015c0dc08bb7718863ba3
parent 469135 cc37bdabd566f3b0e29be2c4bc00eacd585aed0d
child 469137 89bd3aee893e45ed10f08bf1d558d4dd03a13d06
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1540581
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540581 - P8. Set decoding format back to NV12 and set colorspace. r=bryce Differential Revision: https://phabricator.services.mozilla.com/D26062
dom/media/platforms/apple/AppleVTDecoder.cpp
dom/media/platforms/apple/AppleVTDecoder.h
dom/media/platforms/wrappers/MediaChangeMonitor.cpp
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -30,16 +30,17 @@ using namespace layers;
 AppleVTDecoder::AppleVTDecoder(const VideoInfo& aConfig, TaskQueue* aTaskQueue,
                                layers::ImageContainer* aImageContainer,
                                CreateDecoderParams::OptionSet aOptions)
     : mExtraData(aConfig.mExtraData),
       mPictureWidth(aConfig.mImage.width),
       mPictureHeight(aConfig.mImage.height),
       mDisplayWidth(aConfig.mDisplay.width),
       mDisplayHeight(aConfig.mDisplay.height),
+      mColorSpace(aConfig.mColorSpace),
       mTaskQueue(aTaskQueue),
       mMaxRefFrames(aOptions.contains(CreateDecoderParams::Option::LowLatency)
                         ? 0
                         : H264::ComputeMaxRefFrames(aConfig.mExtraData)),
       mImageContainer(aImageContainer)
 #ifdef MOZ_WIDGET_UIKIT
       ,
       mUseSoftwareImages(true)
@@ -368,31 +369,34 @@ void AppleVTDecoder::OutputFrame(CVPixel
     buffer.mPlanes[2].mData =
         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 = 0;
     buffer.mPlanes[2].mSkip = 0;
 
+    buffer.mYUVColorSpace = mColorSpace;
+
     gfx::IntRect visible = gfx::IntRect(0, 0, mPictureWidth, mPictureHeight);
 
     // Copy the image data into our own format.
     data = VideoData::CreateAndCopyData(
         info, mImageContainer, aFrameRef.byte_offset,
         aFrameRef.composition_timestamp, aFrameRef.duration, buffer,
         aFrameRef.is_sync_point, aFrameRef.decode_timestamp, visible);
     // Unlock the returned image data.
     CVPixelBufferUnlockBaseAddress(aImage, kCVPixelBufferLock_ReadOnly);
   } else {
 #ifndef MOZ_WIDGET_UIKIT
     IOSurfacePtr surface = MacIOSurfaceLib::CVPixelBufferGetIOSurface(aImage);
     MOZ_ASSERT(surface, "Decoder didn't return an IOSurface backed buffer");
 
     RefPtr<MacIOSurface> macSurface = new MacIOSurface(surface);
+    macSurface->SetYUVColorSpace(mColorSpace);
 
     RefPtr<layers::Image> image = new layers::MacIOSurfaceImage(macSurface);
 
     data = VideoData::CreateFromImage(
         info.mDisplay, aFrameRef.byte_offset, aFrameRef.composition_timestamp,
         aFrameRef.duration, image.forget(), aFrameRef.is_sync_point,
         aFrameRef.decode_timestamp);
 #else
@@ -537,17 +541,17 @@ CFDictionaryRef AppleVTDecoder::CreateOu
 
     return CFDictionaryCreate(
         kCFAllocatorDefault, outputKeys, outputValues, ArrayLength(outputKeys),
         &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
   }
 
 #ifndef MOZ_WIDGET_UIKIT
   // Output format type:
-  SInt32 PixelFormatTypeValue = kCVPixelFormatType_422YpCbCr8;
+  SInt32 PixelFormatTypeValue = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
   AutoCFRelease<CFNumberRef> PixelFormatTypeNumber = CFNumberCreate(
       kCFAllocatorDefault, kCFNumberSInt32Type, &PixelFormatTypeValue);
   // Construct IOSurface Properties
   const void* IOSurfaceKeys[] = {MacIOSurfaceLib::kPropIsGlobal};
   const void* IOSurfaceValues[] = {kCFBooleanTrue};
   static_assert(ArrayLength(IOSurfaceKeys) == ArrayLength(IOSurfaceValues),
                 "Non matching keys/values array size");
 
--- a/dom/media/platforms/apple/AppleVTDecoder.h
+++ b/dom/media/platforms/apple/AppleVTDecoder.h
@@ -5,22 +5,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_AppleVTDecoder_h
 #define mozilla_AppleVTDecoder_h
 
 #include <CoreFoundation/CFDictionary.h>  // For CFDictionaryRef
 #include <CoreMedia/CoreMedia.h>          // For CMVideoFormatDescriptionRef
 #include <VideoToolbox/VideoToolbox.h>    // For VTDecompressionSessionRef
-
 #include "PlatformDecoderModule.h"
-#include "mozilla/Atomics.h"
-#include "nsIThread.h"
 #include "ReorderQueue.h"
 #include "TimeUnits.h"
+#include "mozilla/Atomics.h"
+#include "mozilla/gfx/Types.h"
+#include "nsIThread.h"
 
 namespace mozilla {
 
 DDLoggedTypeDeclNameAndBase(AppleVTDecoder, MediaDataDecoder);
 
 class AppleVTDecoder : public MediaDataDecoder,
                        public DecoderDoctorLifeLogger<AppleVTDecoder> {
  public:
@@ -83,16 +83,17 @@ class AppleVTDecoder : public MediaDataD
   AppleFrameRef* CreateAppleFrameRef(const MediaRawData* aSample);
   CFDictionaryRef CreateOutputConfiguration();
 
   const RefPtr<MediaByteBuffer> mExtraData;
   const uint32_t mPictureWidth;
   const uint32_t mPictureHeight;
   const uint32_t mDisplayWidth;
   const uint32_t mDisplayHeight;
+  const gfx::YUVColorSpace mColorSpace;
 
   // Method to set up the decompression session.
   MediaResult InitializeSession();
   nsresult WaitForAsynchronousFrames();
   CFDictionaryRef CreateDecoderSpecification();
   CFDictionaryRef CreateDecoderExtensions();
 
   const RefPtr<TaskQueue> mTaskQueue;
--- a/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
+++ b/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
@@ -124,16 +124,19 @@ class H264ChangeMonitor : public MediaCh
         spsdata.pic_width > 0 && spsdata.pic_height > 0) {
       H264::EnsureSPSIsSane(spsdata);
       mCurrentConfig.mImage.width = spsdata.pic_width;
       mCurrentConfig.mImage.height = spsdata.pic_height;
       mCurrentConfig.mDisplay.width = spsdata.display_width;
       mCurrentConfig.mDisplay.height = spsdata.display_height;
       mCurrentConfig.SetImageRect(
           gfx::IntRect(0, 0, spsdata.pic_width, spsdata.pic_height));
+      mCurrentConfig.mColorDepth = spsdata.ColorDepth();
+      mCurrentConfig.mColorSpace = spsdata.ColorSpace();
+      mCurrentConfig.mFullRange = spsdata.video_full_range_flag;
     }
     mCurrentConfig.mExtraData = aExtraData;
     mTrackInfo = new TrackInfoSharedPtr(mCurrentConfig, mStreamID++);
   }
 
   VideoInfo mCurrentConfig;
   uint32_t mStreamID = 0;
   const bool mFullParsing;