void CDMCaps::AutoLock::NotifyWhenKeyIdUsable(const CencKeyId& aKey, SamplesWaitingForKey* aListener) { mData.mMonitor.AssertCurrentThreadOwns(); MOZ_ASSERT(!IsKeyUsable(aKey)); MOZ_ASSERT(aListener); mData.mWaitForKeys.AppendElement(WaitForKeys(aKey, aListener)); }
void CDMCaps::AutoLock::CallWhenKeyUsable(const CencKeyId& aKey, nsIRunnable* aContinuation, nsIThread* aTarget) { mData.mMonitor.AssertCurrentThreadOwns(); MOZ_ASSERT(!IsKeyUsable(aKey)); MOZ_ASSERT(aContinuation); mData.mWaitForKeys.AppendElement(WaitForKeys(aKey, aContinuation, aTarget)); }
RefPtr<SamplesWaitingForKey::WaitForKeyPromise> SamplesWaitingForKey::WaitIfKeyNotUsable(MediaRawData* aSample) { if (!aSample || !aSample->mCrypto.mValid || !mProxy) { return WaitForKeyPromise::CreateAndResolve(aSample, __func__); } auto caps = mProxy->Capabilites().Lock(); const auto& keyid = aSample->mCrypto.mKeyId; if (caps->IsKeyUsable(keyid)) { return WaitForKeyPromise::CreateAndResolve(aSample, __func__); } SampleEntry entry; entry.mSample = aSample; RefPtr<WaitForKeyPromise> p = entry.mPromise.Ensure(__func__); { MutexAutoLock lock(mMutex); mSamples.AppendElement(std::move(entry)); } if (mOnWaitingForKeyEvent) { mOnWaitingForKeyEvent->Notify(mType); } caps->NotifyWhenKeyIdUsable(aSample->mCrypto.mKeyId, this); return p; }