Bug 1315850 - Shutdown CDMVideoDecoder. r=jya draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 08 Mar 2017 10:20:33 +1300
changeset 504176 5a2f77ffe84f9b99b4668520c838b29a428578d3
parent 504175 3f9636503523f0c6effab15fa89cce25a961a0b4
child 504177 6f0d72f76e313b55f7c905d5878c63b8d7292b1b
push id50748
push userbmo:cpearce@mozilla.com
push dateFri, 24 Mar 2017 01:10:17 +0000
reviewersjya
bugs1315850
milestone55.0a1
Bug 1315850 - Shutdown CDMVideoDecoder. r=jya This severs the ChromiumCDMVideoDecoder's connection with the CDM. The CDM process will shutdown when the MediaKeys also severs its connection. MozReview-Commit-ID: Aqc4y5Nxjvc
dom/media/gmp/ChromiumCDMParent.cpp
dom/media/gmp/ChromiumCDMParent.h
dom/media/platforms/agnostic/eme/ChromiumCDMVideoDecoder.cpp
--- a/dom/media/gmp/ChromiumCDMParent.cpp
+++ b/dom/media/gmp/ChromiumCDMParent.cpp
@@ -621,10 +621,23 @@ ChromiumCDMParent::Drain()
 }
 
 ipc::IPCResult
 ChromiumCDMParent::RecvDrainComplete()
 {
   mDecodePromise.ResolveIfExists(MediaDataDecoder::DecodedData(), __func__);
   return IPC_OK();
 }
+RefPtr<ShutdownPromise>
+ChromiumCDMParent::ShutdownVideoDecoder()
+{
+  mInitVideoDecoderPromise.RejectIfExists(NS_ERROR_DOM_MEDIA_CANCELED,
+                                          __func__);
+  MOZ_ASSERT(mDecodePromise.IsEmpty());
+  MOZ_ASSERT(mFlushDecoderPromise.IsEmpty());
+  if (!SendDeinitializeVideoDecoder()) {
+    return ShutdownPromise::CreateAndResolve(true, __func__);
+  }
+  return ShutdownPromise::CreateAndResolve(true, __func__);
+}
+
 } // namespace gmp
 } // namespace mozilla
--- a/dom/media/gmp/ChromiumCDMParent.h
+++ b/dom/media/gmp/ChromiumCDMParent.h
@@ -68,16 +68,18 @@ public:
 
   RefPtr<MediaDataDecoder::DecodePromise> DecryptAndDecodeFrame(
     MediaRawData* aSample);
 
   RefPtr<MediaDataDecoder::FlushPromise> FlushVideoDecoder();
 
   RefPtr<MediaDataDecoder::DecodePromise> Drain();
 
+  RefPtr<ShutdownPromise> ShutdownVideoDecoder();
+
 protected:
   ~ChromiumCDMParent() {}
 
   ipc::IPCResult Recv__delete__() override;
   ipc::IPCResult RecvOnResolveNewSessionPromise(
     const uint32_t& aPromiseId,
     const nsCString& aSessionId) override;
   ipc::IPCResult RecvOnResolvePromise(const uint32_t& aPromiseId) override;
--- a/dom/media/platforms/agnostic/eme/ChromiumCDMVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/eme/ChromiumCDMVideoDecoder.cpp
@@ -129,12 +129,20 @@ ChromiumCDMVideoDecoder::Drain()
   MOZ_ASSERT(mCDMParent);
   RefPtr<gmp::ChromiumCDMParent> cdm = mCDMParent;
   return InvokeAsync(mGMPThread, __func__, [cdm]() { return cdm->Drain(); });
 }
 
 RefPtr<ShutdownPromise>
 ChromiumCDMVideoDecoder::Shutdown()
 {
-  return ShutdownPromise::CreateAndResolve(true, __func__);
+  if (!mCDMParent) {
+    // Must have failed to get the CDMParent from the ChromiumCDMProxy
+    // in our constructor; the MediaKeys must have shut down the CDM
+    // before we had a chance to start up the decoder.
+    return ShutdownPromise::CreateAndResolve(true, __func__);
+  }
+  RefPtr<gmp::ChromiumCDMParent> cdm = mCDMParent;
+  return InvokeAsync(
+    mGMPThread, __func__, [cdm]() { return cdm->ShutdownVideoDecoder(); });
 }
 
 } // namespace mozilla