Bug 1340942. Part 1 - add some members so we don't have to pass the track type around. r=gerald
authorJW Wang <jwwang@mozilla.com>
Fri, 17 Feb 2017 14:48:42 +0800
changeset 372788 ad17a0e96f9e05753c170478c1ea50cab404bcbb
parent 372787 59356eed685503e5f2fb1445adbe0f520c41eed4
child 372789 22cdad8b34c92dd26228339de45c4aa19888ef6b
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1340942
milestone54.0a1
Bug 1340942. Part 1 - add some members so we don't have to pass the track type around. r=gerald MozReview-Commit-ID: Ewipsg8FFqb
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -189,17 +189,21 @@ DecoderAllocPolicy::operator=(std::nullp
 
 class MediaFormatReader::DecoderFactory
 {
   using InitPromise = MediaDataDecoder::InitPromise;
   using TokenPromise = DecoderAllocPolicy::Promise;
   using Token = DecoderAllocPolicy::Token;
 
 public:
-  explicit DecoderFactory(MediaFormatReader* aOwner) : mOwner(aOwner) { }
+  explicit DecoderFactory(MediaFormatReader* aOwner)
+    : mAudio(aOwner->mAudio, TrackInfo::kAudioTrack)
+    , mVideo(aOwner->mVideo, TrackInfo::kVideoTrack)
+    , mOwner(WrapNotNull(aOwner)) { }
+
   void CreateDecoder(TrackType aTrack);
   // Shutdown any decoder pending initialization.
   RefPtr<ShutdownPromise> ShutdownDecoder(TrackType aTrack)
   {
     MOZ_ASSERT(aTrack == TrackInfo::kAudioTrack
                || aTrack == TrackInfo::kVideoTrack);
     auto& data = aTrack == TrackInfo::kAudioTrack ? mAudio : mVideo;
     data.mTokenRequest.DisconnectIfExists();
@@ -226,30 +230,38 @@ private:
     None,
     WaitForToken,
     CreateDecoder,
     WaitForInit
   };
 
   struct Data
   {
+    Data(DecoderData& aOwnerData, TrackType aTrack)
+      : mOwnerData(aOwnerData)
+      , mTrack(aTrack)
+      , mPolicy(DecoderAllocPolicy::Instance(aTrack)) { }
+    DecoderData& mOwnerData;
+    const TrackType mTrack;
+    DecoderAllocPolicy& mPolicy;
     Stage mStage = Stage::None;
     RefPtr<Token> mToken;
     RefPtr<MediaDataDecoder> mDecoder;
     MozPromiseRequestHolder<TokenPromise> mTokenRequest;
     MozPromiseRequestHolder<InitPromise> mInitRequest;
     MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
     RefPtr<ShutdownPromise> mShutdownPromise;
   } mAudio, mVideo;
 
   void RunStage(TrackType aTrack);
   MediaResult DoCreateDecoder(TrackType aTrack);
   void DoInitDecoder(TrackType aTrack);
 
-  MediaFormatReader* const mOwner; // guaranteed to be valid by the owner.
+  // guaranteed to be valid by the owner.
+  const NotNull<MediaFormatReader*> mOwner;
 };
 
 void
 MediaFormatReader::DecoderFactory::CreateDecoder(TrackType aTrack)
 {
   MOZ_ASSERT(aTrack == TrackInfo::kAudioTrack
              || aTrack == TrackInfo::kVideoTrack);
   RunStage(aTrack);