media_foundation_protection_manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_RENDERERS_WIN_MEDIA_FOUNDATION_PROTECTION_MANAGER_H_
  5. #define MEDIA_RENDERERS_WIN_MEDIA_FOUNDATION_PROTECTION_MANAGER_H_
  6. #include <mfapi.h>
  7. #include <mfidl.h>
  8. #include <windows.media.protection.h>
  9. #include <wrl.h>
  10. #include "base/cancelable_callback.h"
  11. #include "base/memory/scoped_refptr.h"
  12. #include "base/memory/weak_ptr.h"
  13. #include "base/task/sequenced_task_runner.h"
  14. #include "media/base/waiting.h"
  15. #include "media/base/win/media_foundation_cdm_proxy.h"
  16. namespace media {
  17. // Implements IMFContentProtectionManager
  18. // (https://docs.microsoft.com/en-us/windows/win32/api/mfidl/nn-mfidl-imfcontentprotectionmanager)
  19. // and ABI::Windows::Media::Protection::IMediaProtectionManager
  20. // (https://docs.microsoft.com/en-us/uwp/api/windows.media.protection.mediaprotectionmanager)
  21. // required by IMFMediaEngineProtectedContent::SetContentProtectionManager in
  22. // https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nf-mfmediaengine-imfmediaengineprotectedcontent-setcontentprotectionmanager.
  23. //
  24. class MediaFoundationProtectionManager
  25. : public Microsoft::WRL::RuntimeClass<
  26. Microsoft::WRL::RuntimeClassFlags<
  27. Microsoft::WRL::RuntimeClassType::WinRtClassicComMix |
  28. Microsoft::WRL::RuntimeClassType::InhibitRoOriginateError>,
  29. IMFContentProtectionManager,
  30. ABI::Windows::Media::Protection::IMediaProtectionManager> {
  31. public:
  32. MediaFoundationProtectionManager();
  33. ~MediaFoundationProtectionManager() override;
  34. HRESULT RuntimeClassInitialize(
  35. scoped_refptr<base::SequencedTaskRunner> task_runner,
  36. WaitingCB waiting_cb);
  37. HRESULT SetCdmProxy(scoped_refptr<MediaFoundationCdmProxy> cdm_proxy);
  38. // IMFContentProtectionManager.
  39. IFACEMETHODIMP BeginEnableContent(IMFActivate* enabler_activate,
  40. IMFTopology* topology,
  41. IMFAsyncCallback* callback,
  42. IUnknown* state) override;
  43. IFACEMETHODIMP EndEnableContent(IMFAsyncResult* async_result) override;
  44. // IMediaProtectionManager.
  45. // MFMediaEngine can query this interface to invoke get_Properties().
  46. IFACEMETHODIMP add_ServiceRequested(
  47. ABI::Windows::Media::Protection::IServiceRequestedEventHandler* handler,
  48. EventRegistrationToken* cookie) override;
  49. IFACEMETHODIMP remove_ServiceRequested(
  50. EventRegistrationToken cookie) override;
  51. IFACEMETHODIMP add_RebootNeeded(
  52. ABI::Windows::Media::Protection::IRebootNeededEventHandler* handler,
  53. EventRegistrationToken* cookie) override;
  54. IFACEMETHODIMP remove_RebootNeeded(EventRegistrationToken cookie) override;
  55. IFACEMETHODIMP add_ComponentLoadFailed(
  56. ABI::Windows::Media::Protection::IComponentLoadFailedEventHandler*
  57. handler,
  58. EventRegistrationToken* cookie) override;
  59. IFACEMETHODIMP remove_ComponentLoadFailed(
  60. EventRegistrationToken cookie) override;
  61. IFACEMETHODIMP get_Properties(
  62. ABI::Windows::Foundation::Collections::IPropertySet** value) override;
  63. private:
  64. HRESULT SetPMPServer(
  65. ABI::Windows::Media::Protection::IMediaProtectionPMPServer* pmp_server);
  66. // These methods are all running on `task_runner_` due to the threading
  67. // requirement of `base::CancelableOnceClosure`.
  68. void OnBeginEnableContent();
  69. void OnEndEnableContent();
  70. void OnWaitingForKeyTimeOut();
  71. scoped_refptr<base::SequencedTaskRunner> task_runner_;
  72. WaitingCB waiting_cb_;
  73. base::CancelableOnceClosure waiting_for_key_time_out_cb_;
  74. scoped_refptr<MediaFoundationCdmProxy> cdm_proxy_;
  75. Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IPropertySet>
  76. property_set_;
  77. // This must be the last member.
  78. base::WeakPtrFactory<MediaFoundationProtectionManager> weak_factory_{this};
  79. };
  80. } // namespace media
  81. #endif // MEDIA_RENDERERS_WIN_MEDIA_FOUNDATION_PROTECTION_MANAGER_H_