Bug 1208922. Part 4 - remove AbstractMediaDecoder::GetCDMProxy() and devirtualize MediaDecoder::SetCDMProxy(). r=cpearce.
authorJW Wang <jwwang@mozilla.com>
Sun, 27 Sep 2015 18:59:08 +0800
changeset 298515 20b1d715338b972874f8bed076a176425dcaec0d
parent 298514 db7c6afb4cb72bb00846c7766c952705c8031d03
child 298516 f946f0d4e017c7fbbddc765e4db01e7eba86e3c8
push idunknown
push userunknown
push dateunknown
reviewerscpearce
bugs1208922
milestone44.0a1
Bug 1208922. Part 4 - remove AbstractMediaDecoder::GetCDMProxy() and devirtualize MediaDecoder::SetCDMProxy(). r=cpearce.
dom/media/AbstractMediaDecoder.h
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
dom/media/mediasource/MediaSourceDecoder.cpp
dom/media/mediasource/MediaSourceDecoder.h
--- a/dom/media/AbstractMediaDecoder.h
+++ b/dom/media/AbstractMediaDecoder.h
@@ -158,21 +158,16 @@ public:
   private:
     AbstractMediaDecoder* mDecoder;
   };
 
   // Classes directly inheriting from AbstractMediaDecoder do not support
   // Observe and it should never be called directly.
   NS_IMETHOD Observe(nsISupports *aSubject, const char * aTopic, const char16_t * aData) override
   { MOZ_CRASH("Forbidden method"); return NS_OK; }
-
-#ifdef MOZ_EME
-  virtual nsresult SetCDMProxy(CDMProxy* aProxy) { return NS_ERROR_NOT_IMPLEMENTED; }
-  virtual CDMProxy* GetCDMProxy() { return nullptr; }
-#endif
 };
 
 class MetadataContainer
 {
 protected:
   MetadataContainer(AbstractMediaDecoder* aDecoder,
                     nsAutoPtr<MediaInfo> aInfo,
                     nsAutoPtr<MetadataTags> aTags,
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1436,42 +1436,34 @@ MediaDecoder::CanPlayThrough()
 
 #ifdef MOZ_EME
 nsRefPtr<MediaDecoder::CDMProxyPromise>
 MediaDecoder::RequestCDMProxy() const
 {
   return mCDMProxyPromise;
 }
 
-nsresult
+void
 MediaDecoder::SetCDMProxy(CDMProxy* aProxy)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsRefPtr<CDMProxy> proxy = aProxy;
   {
     CDMCaps::AutoLock caps(aProxy->Capabilites());
     if (!caps.AreCapsKnown()) {
       nsRefPtr<MediaDecoder> self = this;
       nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
         self->mCDMProxyPromiseHolder.ResolveIfExists(proxy, __func__);
       });
       caps.CallOnMainThreadWhenCapsAvailable(r);
-      return NS_OK;
+      return;
     }
   }
   mCDMProxyPromiseHolder.ResolveIfExists(proxy, __func__);
-  return NS_OK;
-}
-
-CDMProxy*
-MediaDecoder::GetCDMProxy()
-{
-  GetReentrantMonitor().AssertCurrentThreadIn();
-  return mProxy;
 }
 #endif
 
 #ifdef MOZ_RAW
 bool
 MediaDecoder::IsRawEnabled()
 {
   return Preferences::GetBool("media.raw.enabled");
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -665,21 +665,17 @@ public:
 
 #ifdef MOZ_EME
   typedef MozPromise<nsRefPtr<CDMProxy>, bool /* aIgnored */, /* IsExclusive = */ true> CDMProxyPromise;
 
   // Resolved when a CDMProxy is available and the capabilities are known or
   // rejected when this decoder is about to shut down.
   nsRefPtr<CDMProxyPromise> RequestCDMProxy() const;
 
-  // This takes the decoder monitor.
-  virtual nsresult SetCDMProxy(CDMProxy* aProxy) override;
-
-  // Decoder monitor must be held.
-  virtual CDMProxy* GetCDMProxy() override;
+  void SetCDMProxy(CDMProxy* aProxy);
 #endif
 
 #ifdef MOZ_RAW
   static bool IsRawEnabled();
 #endif
 
   static bool IsOggEnabled();
   static bool IsOpusEnabled();
@@ -819,17 +815,16 @@ private:
   nsRefPtr<MediaDecoderStateMachine> mDecoderStateMachine;
 
   // |ReentrantMonitor| for detecting when the video play state changes. A call
   // to |Wait| on this monitor will block the thread until the next state
   // change.  Explicitly private for force access via GetReentrantMonitor.
   ReentrantMonitor mReentrantMonitor;
 
 #ifdef MOZ_EME
-  nsRefPtr<CDMProxy> mProxy;
   MozPromiseHolder<CDMProxyPromise> mCDMProxyPromiseHolder;
   nsRefPtr<CDMProxyPromise> mCDMProxyPromise;
 #endif
 
 protected:
   virtual void CallSeek(const SeekTarget& aTarget);
 
   // Returns true if heuristic dormant is supported.
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -46,35 +46,16 @@ MP4Decoder::MP4Decoder()
 
 MediaDecoderStateMachine* MP4Decoder::CreateStateMachine()
 {
   MediaDecoderReader* reader = new MediaFormatReader(this, new MP4Demuxer(GetResource()));
 
   return new MediaDecoderStateMachine(this, reader);
 }
 
-#ifdef MOZ_EME
-nsresult
-MP4Decoder::SetCDMProxy(CDMProxy* aProxy)
-{
-  nsresult rv = MediaDecoder::SetCDMProxy(aProxy);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (aProxy) {
-    // The MediaFormatReader can't decrypt EME content until it has a CDMProxy,
-    // and the CDMProxy knows the capabilities of the CDM. The MediaFormatReader
-    // remains in "waiting for resources" state until then.
-    CDMCaps::AutoLock caps(aProxy->Capabilites());
-    nsCOMPtr<nsIRunnable> task(
-      NS_NewRunnableMethod(this, &MediaDecoder::NotifyWaitingForResourcesStatusChanged));
-    caps.CallOnMainThreadWhenCapsAvailable(task);
-  }
-  return NS_OK;
-}
-#endif
-
 static bool
 IsSupportedAudioCodec(const nsAString& aCodec,
                       bool& aOutContainsAAC,
                       bool& aOutContainsMP3)
 {
   // AAC-LC or HE-AAC in M4A.
   aOutContainsAAC = aCodec.EqualsASCII("mp4a.40.2")     // MPEG4 AAC-LC
                     || aCodec.EqualsASCII("mp4a.40.5")  // MPEG4 HE-AAC
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -20,20 +20,16 @@ public:
     if (!IsEnabled()) {
       return nullptr;
     }
     return new MP4Decoder();
   }
 
   virtual MediaDecoderStateMachine* CreateStateMachine() override;
 
-#ifdef MOZ_EME
-  virtual nsresult SetCDMProxy(CDMProxy* aProxy) override;
-#endif
-
   // Returns true if aMIMEType is a type that we think we can render with the
   // a MP4 platform decoder backend. If aCodecs is non emtpy, it is filled
   // with a comma-delimited list of codecs to check support for. Notes in
   // out params wether the codecs string contains AAC or H.264.
   static bool CanHandleMediaType(const nsACString& aMIMEType,
                                  const nsAString& aCodecs,
                                  bool& aOutContainsAAC,
                                  bool& aOutContainsH264,
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -226,38 +226,16 @@ MediaSourceDecoder::GetMediaSourceDurati
 }
 
 void
 MediaSourceDecoder::GetMozDebugReaderData(nsAString& aString)
 {
   mDemuxer->GetMozDebugReaderData(aString);
 }
 
-#ifdef MOZ_EME
-nsresult
-MediaSourceDecoder::SetCDMProxy(CDMProxy* aProxy)
-{
-  nsresult rv = MediaDecoder::SetCDMProxy(aProxy);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (aProxy) {
-    // The sub readers can't decrypt EME content until they have a CDMProxy,
-    // and the CDMProxy knows the capabilities of the CDM. The MediaSourceReader
-    // remains in "waiting for resources" state until then. We need to kick the
-    // reader out of waiting if the CDM gets added with known capabilities.
-    CDMCaps::AutoLock caps(aProxy->Capabilites());
-    if (!caps.AreCapsKnown()) {
-      nsCOMPtr<nsIRunnable> task(
-        NS_NewRunnableMethod(this, &MediaDecoder::NotifyWaitingForResourcesStatusChanged));
-      caps.CallOnMainThreadWhenCapsAvailable(task);
-    }
-  }
-  return NS_OK;
-}
-#endif
-
 double
 MediaSourceDecoder::GetDuration()
 {
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   return ExplicitDuration();
 }
 
 #undef MSE_DEBUG
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -61,20 +61,16 @@ public:
 
   // Return the duration of the video in seconds.
   virtual double GetDuration() override;
 
   void SetInitialDuration(int64_t aDuration);
   void SetMediaSourceDuration(double aDuration, MSRangeRemovalAction aAction);
   double GetMediaSourceDuration();
 
-#ifdef MOZ_EME
-  virtual nsresult SetCDMProxy(CDMProxy* aProxy) override;
-#endif
-
   MediaSourceDemuxer* GetDemuxer()
   {
     return mDemuxer;
   }
 
   // Returns a string describing the state of the MediaSource internal
   // buffered data. Used for debugging purposes.
   void GetMozDebugReaderData(nsAString& aString);