Bug 1138967 - Part 2: Create IMFYCbCrImage so that image data copying happens off the decoder thread. r=nical, r=cpearce, a=lmandel
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 19 Mar 2015 10:16:23 +1300
changeset 250450 07e266d45703
parent 250449 c1356c27fa1b
child 250451 0c23dcbc6bf7
push id4591
push userryanvm@gmail.com
push date2015-03-19 18:13 +0000
treeherdermozilla-beta@9b7aa96d0e11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, cpearce, lmandel
bugs1138967
milestone37.0
Bug 1138967 - Part 2: Create IMFYCbCrImage so that image data copying happens off the decoder thread. r=nical, r=cpearce, a=lmandel
dom/media/fmp4/wmf/WMFVideoMFTManager.cpp
gfx/layers/IMFYCbCrImage.h
gfx/layers/moz.build
--- a/dom/media/fmp4/wmf/WMFVideoMFTManager.cpp
+++ b/dom/media/fmp4/wmf/WMFVideoMFTManager.cpp
@@ -14,26 +14,28 @@
 #include "nsThreadUtils.h"
 #include "Layers.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mp4_demuxer/AnnexB.h"
 #include "mp4_demuxer/DecoderData.h"
 #include "prlog.h"
 #include "gfx2DGlue.h"
 #include "gfxWindowsPlatform.h"
+#include "IMFYCbCrImage.h"
 
 #ifdef PR_LOGGING
 PRLogModuleInfo* GetDemuxerLog();
 #define LOG(...) PR_LOG(GetDemuxerLog(), PR_LOG_DEBUG, (__VA_ARGS__))
 #else
 #define LOG(...)
 #endif
 
 using mozilla::gfx::ToIntRect;
 using mozilla::layers::Image;
+using mozilla::layers::IMFYCbCrImage;
 using mozilla::layers::LayerManager;
 using mozilla::layers::LayersBackend;
 
 const GUID MFVideoFormat_VP80 =
 {
   0x30385056,
   0x0000,
   0x0010,
@@ -381,30 +383,36 @@ WMFVideoMFTManager::CreateBasicVideoFram
   b.mPlanes[2].mStride = halfStride;
   b.mPlanes[2].mHeight = halfHeight;
   b.mPlanes[2].mWidth = halfWidth;
   b.mPlanes[2].mOffset = 0;
   b.mPlanes[2].mSkip = 0;
 
   Microseconds pts = GetSampleTime(aSample);
   Microseconds duration = GetSampleDuration(aSample);
-  nsRefPtr<VideoData> v = VideoData::Create(mVideoInfo,
-                                            mImageContainer,
-                                            aStreamOffset,
-                                            std::max(0LL, pts),
-                                            duration,
-                                            b,
-                                            false,
-                                            -1,
-                                            ToIntRect(mPictureRegion));
-  if (twoDBuffer) {
-    twoDBuffer->Unlock2D();
-  } else {
-    buffer->Unlock();
-  }
+
+  nsRefPtr<layers::PlanarYCbCrImage> image =
+    new IMFYCbCrImage(buffer, twoDBuffer);
+
+  VideoData::SetVideoDataToImage(image,
+                                 mVideoInfo,
+                                 b,
+                                 ToIntRect(mPictureRegion),
+                                 false);
+
+  nsRefPtr<VideoData> v =
+    VideoData::CreateFromImage(mVideoInfo,
+                               mImageContainer,
+                               aStreamOffset,
+                               std::max(0LL, pts),
+                               duration,
+                               image.forget(),
+                               false,
+                               -1,
+                               ToIntRect(mPictureRegion));
 
   v.forget(aOutVideoData);
   return S_OK;
 }
 
 HRESULT
 WMFVideoMFTManager::CreateD3DVideoFrame(IMFSample* aSample,
                                         int64_t aStreamOffset,
new file mode 100644
--- /dev/null
+++ b/gfx/layers/IMFYCbCrImage.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GFX_IMFYCBCRIMAGE_H
+#define GFX_IMFYCBCRIMAGE_H
+
+#include "mozilla/RefPtr.h"
+#include "ImageContainer.h"
+#include "Mfidl.h"
+
+namespace mozilla {
+namespace layers {
+
+class IMFYCbCrImage : public PlanarYCbCrImage
+{
+public:
+  IMFYCbCrImage(IMFMediaBuffer* aBuffer, IMF2DBuffer* a2DBuffer)
+    : PlanarYCbCrImage(nullptr)
+    , mBuffer(aBuffer)
+    , m2DBuffer(a2DBuffer)
+  {}
+
+  virtual bool IsValid() { return true; }
+
+protected:
+  virtual uint8_t* AllocateBuffer(uint32_t aSize) MOZ_OVERRIDE {
+    MOZ_CRASH("Can't do manual allocations with IMFYCbCrImage");
+    return nullptr;
+  }
+
+  ~IMFYCbCrImage()
+  {
+    if (m2DBuffer) {
+      m2DBuffer->Unlock2D();
+    }
+    else {
+      mBuffer->Unlock();
+    }
+  }
+
+  RefPtr<IMFMediaBuffer> mBuffer;
+  RefPtr<IMF2DBuffer> m2DBuffer;
+};
+
+} // namepace layers
+} // namespace mozilla
+
+#endif // GFX_D3DSURFACEIMAGE_H
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -21,16 +21,17 @@ EXPORTS += [
     'CopyableCanvasLayer.h',
     'D3D9SurfaceImage.h',
     'FrameMetrics.h',
     'GLImages.h',
     'GrallocImages.h',
     'ImageContainer.h',
     'ImageLayers.h',
     'ImageTypes.h',
+    'IMFYCbCrImage.h',
     'ipc/ThreadSafeRefcountingWithMainThreadDestruction.h',
     'Layers.h',
     'LayerScope.h',
     'LayersLogging.h',
     'LayerSorter.h',
     'LayersTypes.h',
     'LayerTreeInvalidation.h',
     'opengl/Composer2D.h',