summaryrefslogtreecommitdiffstats
path: root/dom/media/platforms/wmf/MFPMPHostWrapper.cpp
blob: 1e7ba89e7b5f5fb52feae97f7d5c26eb97b7e934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* 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/. */

#include "MFPMPHostWrapper.h"

#include "MFMediaEngineUtils.h"
#include "WMF.h"
#include "mozilla/EMEUtils.h"

namespace mozilla {

using Microsoft::WRL::ComPtr;

#define LOG(msg, ...) EME_LOG("MFPMPHostWrapper=%p, " msg, this, ##__VA_ARGS__)

HRESULT MFPMPHostWrapper::RuntimeClassInitialize(
    Microsoft::WRL::ComPtr<IMFPMPHost>& aHost) {
  mPMPHost = aHost;
  return S_OK;
}

MFPMPHostWrapper::MFPMPHostWrapper() {
  MOZ_COUNT_CTOR(MFPMPHostWrapper);
  LOG("MFPMPHostWrapper created");
}

MFPMPHostWrapper::~MFPMPHostWrapper() {
  MOZ_COUNT_DTOR(MFPMPHostWrapper);
  LOG("MFPMPHostWrapper destroyed");
};

STDMETHODIMP MFPMPHostWrapper::LockProcess() {
  LOG("LockProcess");
  return mPMPHost->LockProcess();
}

STDMETHODIMP MFPMPHostWrapper::UnlockProcess() {
  LOG("UnlockProcess");
  return mPMPHost->UnlockProcess();
}

STDMETHODIMP MFPMPHostWrapper::ActivateClassById(LPCWSTR aId, IStream* aStream,
                                                 REFIID aRiid,
                                                 void** aActivatedClass) {
  LOG("ActivateClassById, id=%ls", aId);
  ComPtr<IMFAttributes> creationAttributes;
  RETURN_IF_FAILED(wmf::MFCreateAttributes(&creationAttributes, 2));
  RETURN_IF_FAILED(creationAttributes->SetString(GUID_ClassName, aId));

  if (aStream) {
    STATSTG statstg;
    RETURN_IF_FAILED(
        aStream->Stat(&statstg, STATFLAG_NOOPEN | STATFLAG_NONAME));
    nsTArray<uint8_t> streamBlob;
    streamBlob.SetLength(statstg.cbSize.LowPart);
    unsigned long readSize = 0;
    RETURN_IF_FAILED(
        aStream->Read(&streamBlob[0], streamBlob.Length(), &readSize));
    RETURN_IF_FAILED(creationAttributes->SetBlob(GUID_ObjectStream,
                                                 &streamBlob[0], readSize));
  }

  ComPtr<IStream> outputStream;
  RETURN_IF_FAILED(CreateStreamOnHGlobal(nullptr, TRUE, &outputStream));
  RETURN_IF_FAILED(wmf::MFSerializeAttributesToStream(creationAttributes.Get(),
                                                      0, outputStream.Get()));
  RETURN_IF_FAILED(outputStream->Seek({}, STREAM_SEEK_SET, nullptr));

  ComPtr<IMFActivate> activator;
  RETURN_IF_FAILED(mPMPHost->CreateObjectByCLSID(
      CLSID_EMEStoreActivate, outputStream.Get(), IID_PPV_ARGS(&activator)));
  RETURN_IF_FAILED(activator->ActivateObject(aRiid, aActivatedClass));
  if (aActivatedClass) {
    LOG("Get class %p for id=%ls", *aActivatedClass, aId);
  } else {
    LOG("No class for id=%ls", aId);
  }
  LOG("Done ActivateClassById, id=%ls", aId);
  return S_OK;
}

void MFPMPHostWrapper::Shutdown() {
  LOG("Shutdown");
  if (mPMPHost) {
    mPMPHost = nullptr;
  }
}

#undef LOG

}  // namespace mozilla