tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MFMediaEngineExtension.cpp (2677B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "MFMediaEngineExtension.h"
      6 
      7 #include <mfapi.h>
      8 #include <mferror.h>
      9 
     10 #include "MFMediaEngineUtils.h"
     11 #include "MFMediaSource.h"
     12 #include "WMF.h"
     13 
     14 namespace mozilla {
     15 
     16 #define LOG(msg, ...)                         \
     17  MOZ_LOG(gMFMediaEngineLog, LogLevel::Debug, \
     18          ("MFMediaEngineExtension=%p, " msg, this, ##__VA_ARGS__))
     19 
     20 using Microsoft::WRL::ComPtr;
     21 
     22 void MFMediaEngineExtension::SetMediaSource(IMFMediaSource* aMediaSource) {
     23  LOG("SetMediaSource=%p", aMediaSource);
     24  mMediaSource = aMediaSource;
     25 }
     26 
     27 // https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nf-mfmediaengine-imfmediaengineextension-begincreateobject
     28 IFACEMETHODIMP MFMediaEngineExtension::BeginCreateObject(
     29    BSTR aUrl, IMFByteStream* aByteStream, MF_OBJECT_TYPE aType,
     30    IUnknown** aCancelCookie, IMFAsyncCallback* aCallback, IUnknown* aState) {
     31  if (aCancelCookie) {
     32    // We don't support a cancel cookie.
     33    *aCancelCookie = nullptr;
     34  }
     35 
     36  if (aType != MF_OBJECT_MEDIASOURCE) {
     37    LOG("Only support media source type");
     38    return MF_E_UNEXPECTED;
     39  }
     40 
     41  MOZ_ASSERT(mMediaSource);
     42  ComPtr<IMFAsyncResult> result;
     43  ComPtr<IUnknown> sourceUnknown = mMediaSource;
     44  RETURN_IF_FAILED(wmf::MFCreateAsyncResult(sourceUnknown.Get(), aCallback,
     45                                            aState, &result));
     46  RETURN_IF_FAILED(result->SetStatus(S_OK));
     47 
     48  LOG("Creating object");
     49  mIsObjectCreating = true;
     50 
     51  RETURN_IF_FAILED(aCallback->Invoke(result.Get()));
     52  return S_OK;
     53 }
     54 
     55 IFACEMETHODIMP MFMediaEngineExtension::CancelObjectCreation(
     56    IUnknown* aCancelCookie) {
     57  return MF_E_UNEXPECTED;
     58 }
     59 
     60 IFACEMETHODIMP MFMediaEngineExtension::EndCreateObject(IMFAsyncResult* aResult,
     61                                                       IUnknown** aRetObj) {
     62  *aRetObj = nullptr;
     63  if (!mIsObjectCreating) {
     64    LOG("No object is creating, not an expected call");
     65    return MF_E_UNEXPECTED;
     66  }
     67 
     68  RETURN_IF_FAILED(aResult->GetStatus());
     69  RETURN_IF_FAILED(aResult->GetObject(aRetObj));
     70 
     71  LOG("End of creating object");
     72  mIsObjectCreating = false;
     73  return S_OK;
     74 }
     75 
     76 IFACEMETHODIMP MFMediaEngineExtension::CanPlayType(
     77    BOOL aIsAudioOnly, BSTR aMimeType, MF_MEDIA_ENGINE_CANPLAY* aResult) {
     78  // We use MF_MEDIA_ENGINE_EXTENSION to resolve as custom media source for
     79  // MFMediaEngine, MIME types are not used.
     80  *aResult = MF_MEDIA_ENGINE_CANPLAY_NOT_SUPPORTED;
     81  return S_OK;
     82 }
     83 
     84 // TODO : break cycle of mMediaSource
     85 
     86 #undef LOG
     87 
     88 }  // namespace mozilla