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

media / cdm / win / test / dll_main.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <mfapi.h>
#include <wrl/module.h>

#include "base/logging.h"
#include "media/base/win/mf_helpers.h"

using Microsoft::WRL::InProc;
using Microsoft::WRL::Module;

BOOL WINAPI DllMain(_In_opt_ HINSTANCE instance,
                    _In_ DWORD reason,
                    _In_opt_ LPVOID reserved) {
  if (DLL_PROCESS_ATTACH == reason) {
    // Don't need per-thread callbacks
    DisableThreadLibraryCalls(instance);

    Module<InProc>::GetModule().Create();

    HRESULT hr = MFStartup(MF_VERSION);
    if (!SUCCEEDED(hr)) {
      DVLOG(1) << "Failed with HRESULT=" << media::PrintHr(hr);
      return FALSE;
    }
  } else if (DLL_PROCESS_DETACH == reason) {
    Module<InProc>::GetModule().Terminate();
  }

  return TRUE;
}

HRESULT WINAPI
DllGetActivationFactory(_In_ HSTRING activatible_class_id,
                        _COM_Outptr_ IActivationFactory** factory) {
  auto& module = Module<InProc>::GetModule();
  return module.GetActivationFactory(activatible_class_id, factory);
}

HRESULT WINAPI DllCanUnloadNow() {
  auto& module = Module<InProc>::GetModule();
  return (module.Terminate()) ? S_OK : S_FALSE;
}

STDAPI DllGetClassObject(_In_ REFCLSID rclsid,
                         _In_ REFIID riid,
                         _COM_Outptr_ LPVOID FAR* ppv) {
  auto& module = Module<InProc>::GetModule();
  return module.GetClassObject(rclsid, riid, ppv);
}