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

media / cdm / win / test / media_foundation_clear_key_input_trust_authority.h [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.

#ifndef MEDIA_CDM_WIN_TEST_MEDIA_FOUNDATION_CLEAR_KEY_INPUT_TRUST_AUTHORITY_H_
#define MEDIA_CDM_WIN_TEST_MEDIA_FOUNDATION_CLEAR_KEY_INPUT_TRUST_AUTHORITY_H_

#include <mferror.h>
#include <mfidl.h>
#include <wrl/implements.h>

#include "base/memory/scoped_refptr.h"
#include "base/synchronization/lock.h"
#include "media/cdm/aes_decryptor.h"

namespace media {

class MediaFoundationClearKeyInputTrustAuthority final
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
          IMFInputTrustAuthority,
          IMFShutdown,
          Microsoft::WRL::FtmBase> {
 public:
  MediaFoundationClearKeyInputTrustAuthority();
  ~MediaFoundationClearKeyInputTrustAuthority() override;
  MediaFoundationClearKeyInputTrustAuthority(
      const MediaFoundationClearKeyInputTrustAuthority&) = delete;
  MediaFoundationClearKeyInputTrustAuthority& operator=(
      const MediaFoundationClearKeyInputTrustAuthority&) = delete;

  HRESULT RuntimeClassInitialize(
      _In_ UINT32 stream_id,
      _In_ scoped_refptr<AesDecryptor> aes_decryptor);

  // IMFInputTrustAuthority
  STDMETHODIMP GetDecrypter(_In_ REFIID riid, _COM_Outptr_ void** ppv) override;
  STDMETHODIMP RequestAccess(
      _In_ MFPOLICYMANAGER_ACTION action,
      _COM_Outptr_ IMFActivate** content_enabler_activate) override;
  STDMETHODIMP GetPolicy(_In_ MFPOLICYMANAGER_ACTION action,
                         _COM_Outptr_ IMFOutputPolicy** policy) override;
  STDMETHODIMP BindAccess(
      _In_ MFINPUTTRUSTAUTHORITY_ACCESS_PARAMS* params) override;
  STDMETHODIMP UpdateAccess(
      _In_ MFINPUTTRUSTAUTHORITY_ACCESS_PARAMS* params) override;
  STDMETHODIMP Reset() override;

  // IMFShutdown
  STDMETHODIMP GetShutdownStatus(_Out_ MFSHUTDOWN_STATUS* status) override;
  STDMETHODIMP Shutdown() override;

 private:
  HRESULT GetShutdownStatus() {
    base::AutoLock lock(lock_);
    return (is_shutdown_) ? MF_E_SHUTDOWN : S_OK;
  }

  scoped_refptr<AesDecryptor> aes_decryptor_;

  // For IMFShutdown
  base::Lock lock_;
  bool is_shutdown_ GUARDED_BY(lock_) = false;
};

}  // namespace media

#endif  // MEDIA_CDM_WIN_TEST_MEDIA_FOUNDATION_CLEAR_KEY_INPUT_TRUST_AUTHORITY_H_