Bug 1495025 - P2. Use lambda for callback. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 08 Oct 2018 13:24:19 +0200
changeset 495698 2851d7aead763576969cf47383066977ae75f4b3
parent 495697 107add19c310179d442ce6649d2848364ab5fb86
child 495699 5e7ea76f73f3f4673408c252fbd896ceb841578b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1495025
milestone64.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 1495025 - P2. Use lambda for callback. r=cpearce I find it easier to read than a function pointer making you search elsewhere to see what it's about Depends on D7294 Differential Revision: https://phabricator.services.mozilla.com/D7295
dom/media/platforms/wmf/DXVA2Manager.cpp
dom/media/platforms/wmf/MFTDecoder.cpp
dom/media/platforms/wmf/MFTDecoder.h
--- a/dom/media/platforms/wmf/DXVA2Manager.cpp
+++ b/dom/media/platforms/wmf/DXVA2Manager.cpp
@@ -1110,32 +1110,16 @@ D3D11DXVA2Manager::CopyToBGRATexture(ID3
     [&]() -> void { hr = mTransform->Output(&outputSample); });
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   texture.forget(aOutTexture);
 
   return S_OK;
 }
 
-HRESULT ConfigureOutput(IMFMediaType* aOutput, void* aData)
-{
-  HRESULT hr =
-    aOutput->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
-  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
-
-  hr = aOutput->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
-  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
-
-  gfx::IntSize* size = reinterpret_cast<gfx::IntSize*>(aData);
-  hr = MFSetAttributeSize(aOutput, MF_MT_FRAME_SIZE, size->width, size->height);
-  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
-
-  return S_OK;
-}
-
 HRESULT
 D3D11DXVA2Manager::ConfigureForSize(IMFMediaType* aInputType,
                                     uint32_t aWidth,
                                     uint32_t aHeight)
 {
   GUID inputSubType = { 0 };
   HRESULT hr = aInputType->GetGUID(MF_MT_SUBTYPE, &inputSubType);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
@@ -1177,21 +1161,30 @@ D3D11DXVA2Manager::ConfigureForSize(IMFM
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   hr = outputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   hr = outputType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
-  gfx::IntSize size(aWidth, aHeight);
   hr = E_FAIL;
   mozilla::mscom::EnsureMTA([&]() -> void {
-    hr =
-      mTransform->SetMediaTypes(inputType, outputType, ConfigureOutput, &size);
+    hr = mTransform->SetMediaTypes(
+      inputType, outputType, [aWidth, aHeight](IMFMediaType* aOutput) {
+        HRESULT hr = aOutput->SetUINT32(MF_MT_INTERLACE_MODE,
+                                        MFVideoInterlace_Progressive);
+        NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
+        hr = aOutput->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
+        NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
+        hr = MFSetAttributeSize(aOutput, MF_MT_FRAME_SIZE, aWidth, aHeight);
+        NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
+
+        return S_OK;
+      });
   });
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   mWidth = aWidth;
   mHeight = aHeight;
   mInputType = inputType;
 
   return S_OK;
--- a/dom/media/platforms/wmf/MFTDecoder.cpp
+++ b/dom/media/platforms/wmf/MFTDecoder.cpp
@@ -80,35 +80,33 @@ MFTDecoder::Create(HMODULE aDecoderDLL, 
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   return S_OK;
 }
 
 HRESULT
 MFTDecoder::SetMediaTypes(IMFMediaType* aInputType,
                           IMFMediaType* aOutputType,
-                          ConfigureOutputCallback aCallback,
-                          void* aData)
+                          std::function<HRESULT(IMFMediaType*)>&& aCallback)
 {
   MOZ_ASSERT(mscom::IsCurrentThreadMTA());
   mOutputType = aOutputType;
 
   // Set the input type to the one the caller gave us...
   HRESULT hr = mDecoder->SetInputType(0, aInputType, 0);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   GUID currentSubtype = {0};
   hr = aOutputType->GetGUID(MF_MT_SUBTYPE, &currentSubtype);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   hr = SetDecoderOutputType(currentSubtype,
                             aOutputType,
                             true /* match all attributes */,
-                            aCallback,
-                            aData);
+                            std::move(aCallback));
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   hr = mDecoder->GetInputStreamInfo(0, &mInputStreamInfo);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
   hr = SendMFTMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0);
   NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
@@ -140,25 +138,25 @@ MFTDecoder::FindDecoderOutputType(bool a
   return FindDecoderOutputTypeWithSubtype(currentSubtype, aMatchAllAttributes);
 }
 
 HRESULT
 MFTDecoder::FindDecoderOutputTypeWithSubtype(const GUID& aSubType,
                                              bool aMatchAllAttributes)
 {
   return SetDecoderOutputType(
-    aSubType, nullptr, aMatchAllAttributes, nullptr, nullptr);
+    aSubType, nullptr, aMatchAllAttributes, [](IMFMediaType*) { return S_OK; });
 }
 
 HRESULT
-MFTDecoder::SetDecoderOutputType(const GUID& aSubType,
-                                 IMFMediaType* aTypeToUse,
-                                 bool aMatchAllAttributes,
-                                 ConfigureOutputCallback aCallback,
-                                 void* aData)
+MFTDecoder::SetDecoderOutputType(
+  const GUID& aSubType,
+  IMFMediaType* aTypeToUse,
+  bool aMatchAllAttributes,
+  std::function<HRESULT(IMFMediaType*)>&& aCallback)
 {
   MOZ_ASSERT(mscom::IsCurrentThreadMTA());
   NS_ENSURE_TRUE(mDecoder != nullptr, E_POINTER);
 
   if (!aTypeToUse) {
     aTypeToUse = mOutputType;
   }
 
@@ -175,20 +173,19 @@ MFTDecoder::SetDecoderOutputType(const G
     BOOL resultMatch = aSubType == outSubtype;
 
     if (resultMatch && aMatchAllAttributes) {
       hr = aTypeToUse->Compare(outputType, MF_ATTRIBUTES_MATCH_OUR_ITEMS,
                                &resultMatch);
       NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
     }
     if (resultMatch == TRUE) {
-      if (aCallback) {
-        hr = aCallback(outputType, aData);
-        NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
-      }
+      hr = aCallback(outputType);
+      NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
+
       hr = mDecoder->SetOutputType(0, outputType, 0);
       NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
       hr = mDecoder->GetOutputStreamInfo(0, &mOutputStreamInfo);
       NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
       mMFTProvidesOutputSamples = IsFlagSet(mOutputStreamInfo.dwFlags,
                                             MFT_OUTPUT_STREAM_PROVIDES_SAMPLES);
--- a/dom/media/platforms/wmf/MFTDecoder.h
+++ b/dom/media/platforms/wmf/MFTDecoder.h
@@ -33,22 +33,20 @@ public:
 
   // Sets the input and output media types. Call after Init().
   //
   // Params:
   //  - aInputType needs at least major and minor types set.
   //  - aOutputType needs at least major and minor types set.
   //    This is used to select the matching output type out
   //    of all the available output types of the MFT.
-  typedef HRESULT (*ConfigureOutputCallback)(IMFMediaType* aOutputType,
-                                             void* aData);
   HRESULT SetMediaTypes(IMFMediaType* aInputType,
                         IMFMediaType* aOutputType,
-                        ConfigureOutputCallback aCallback = nullptr,
-                        void* aData = nullptr);
+                        std::function<HRESULT(IMFMediaType*)>&& aCallback =
+                          [](IMFMediaType* aOutput) { return S_OK; });
 
   // Returns the MFT's IMFAttributes object.
   already_AddRefed<IMFAttributes> GetAttributes();
 
   // Retrieves the media type being output. This may not be valid until
   //  the first sample is decoded.
   HRESULT GetOutputMediaType(RefPtr<IMFMediaType>& aMediaType);
 
@@ -89,21 +87,21 @@ public:
   HRESULT SendMFTMessage(MFT_MESSAGE_TYPE aMsg, ULONG_PTR aData);
 
   HRESULT FindDecoderOutputTypeWithSubtype(const GUID& aSubType,
                                            bool aMatchAllAttributes);
   HRESULT FindDecoderOutputType(bool aMatchAllAttributes);
 private:
   // Will search a suitable MediaType using aTypeToUse if set, if not will
   // use the current mOutputType.
-  HRESULT SetDecoderOutputType(const GUID& aSubType,
-                               IMFMediaType* aTypeToUse,
-                               bool aMatchAllAttributes,
-                               ConfigureOutputCallback aCallback,
-                               void* aData);
+  HRESULT SetDecoderOutputType(
+    const GUID& aSubType,
+    IMFMediaType* aTypeToUse,
+    bool aMatchAllAttributes,
+    std::function<HRESULT(IMFMediaType*)>&& aCallback);
   HRESULT CreateOutputSample(RefPtr<IMFSample>* aOutSample);
 
   MFT_INPUT_STREAM_INFO mInputStreamInfo;
   MFT_OUTPUT_STREAM_INFO mOutputStreamInfo;
 
   RefPtr<IMFTransform> mDecoder;
 
   RefPtr<IMFMediaType> mOutputType;