diff --git a/media/renderers/win/media_foundation_protection_manager.cc b/media/renderers/win/media_foundation_protection_manager.cc index 0000000..0000001 100644 --- a/media/renderers/win/media_foundation_protection_manager.cc +++ b/media/renderers/win/media_foundation_protection_manager.cc @@ -26,6 +26,24 @@ MediaFoundationProtectionManager::MediaFoundationProtectionManager() { MediaFoundationProtectionManager::~MediaFoundationProtectionManager() { DVLOG_FUNC(1); + DCHECK(!task_runner_ || task_runner_->RunsTasksInCurrentSequence()); +} + +// MFMediaEngine holds a reference to this object and may drop it on an MF +// threadpool thread after IMFMediaEngine::Shutdown(). `weak_factory_` and +// `waiting_for_key_time_out_cb_` are sequence-affine and must be destroyed on +// `task_runner_`, so bounce destruction back when the last Release() arrives +// off-sequence (matches MediaFoundationSourceWrapper / +// MediaFoundationStreamWrapper). +IFACEMETHODIMP_(ULONG) MediaFoundationProtectionManager::Release() { + ULONG ref_count = InternalRelease(); + if (ref_count == 0) { + if (task_runner_ && !task_runner_->RunsTasksInCurrentSequence()) { + task_runner_->DeleteSoon(FROM_HERE, this); + } else { + delete this; + } + } + return ref_count; } HRESULT MediaFoundationProtectionManager::RuntimeClassInitialize( diff --git a/media/renderers/win/media_foundation_protection_manager.h b/media/renderers/win/media_foundation_protection_manager.h index 0000000..0000001 100644 --- a/media/renderers/win/media_foundation_protection_manager.h +++ b/media/renderers/win/media_foundation_protection_manager.h @@ -37,6 +37,10 @@ class MediaFoundationProtectionManager MediaFoundationProtectionManager(); ~MediaFoundationProtectionManager() override; + // Ensure destruction happens on `task_runner_` even when MFMediaEngine drops + // its last reference on an MF threadpool thread. + IFACEMETHODIMP_(ULONG) Release() override; + HRESULT RuntimeClassInitialize( scoped_refptr task_runner, WaitingCB waiting_cb);