Bug 1474443 - Remove cycle between MP4Demuxer and MP4TrackDemuxer. r=padenot, a=RyanVM
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 15 Nov 2018 12:44:56 +0000
changeset 501372 fdd0d5ac1d28020c16b5da499d5e65441c4e1f09
parent 501371 b519e727ee9eaa9496136670b81dbe5ba749c44c
child 501373 5cb26828de28e16dbd8e4cc61a13d3d4dd62507f
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, RyanVM
bugs1474443
milestone64.0
Bug 1474443 - Remove cycle between MP4Demuxer and MP4TrackDemuxer. r=padenot, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D12004
dom/media/mp4/MP4Demuxer.cpp
dom/media/mp4/MP4Demuxer.h
--- a/dom/media/mp4/MP4Demuxer.cpp
+++ b/dom/media/mp4/MP4Demuxer.cpp
@@ -5,26 +5,25 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <algorithm>
 #include <limits>
 #include <stdint.h>
 
 #include "MP4Demuxer.h"
 
-#include "mozilla/StaticPrefs.h"
-// Used for telemetry
-#include "mozilla/Telemetry.h"
 #include "AnnexB.h"
+#include "BufferStream.h"
 #include "H264.h"
+#include "Index.h"
+#include "MP4Metadata.h"
 #include "MoofParser.h"
-#include "MP4Metadata.h"
 #include "ResourceStream.h"
-#include "BufferStream.h"
-#include "Index.h"
+#include "mozilla/StaticPrefs.h"
+#include "mozilla/Telemetry.h"
 #include "nsAutoPtr.h"
 #include "nsPrintfCString.h"
 
 extern mozilla::LazyLogModule gMediaDemuxerLog;
 mozilla::LogModule* GetDemuxerLog()
 {
   return gMediaDemuxerLog;
 }
@@ -40,17 +39,17 @@ namespace mozilla {
 
 DDLoggedTypeDeclNameAndBase(MP4TrackDemuxer, MediaTrackDemuxer);
 
 class MP4TrackDemuxer
   : public MediaTrackDemuxer
   , public DecoderDoctorLifeLogger<MP4TrackDemuxer>
 {
 public:
-  MP4TrackDemuxer(MP4Demuxer* aParent,
+  MP4TrackDemuxer(MediaResource* aResource,
                   UniquePtr<TrackInfo>&& aInfo,
                   const IndiceWrapper& aIndices);
 
   UniquePtr<TrackInfo> GetInfo() const override;
 
   RefPtr<SeekPromise> Seek(const media::TimeUnit& aTime) override;
 
   RefPtr<SamplesPromise> GetSamples(int32_t aNumSamples = 1) override;
@@ -59,27 +58,24 @@ public:
 
   nsresult GetNextRandomAccessPoint(media::TimeUnit* aTime) override;
 
   RefPtr<SkipAccessPointPromise>
   SkipToNextRandomAccessPoint(const media::TimeUnit& aTimeThreshold) override;
 
   media::TimeIntervals GetBuffered() override;
 
-  void BreakCycles() override;
-
   void NotifyDataRemoved();
+  void NotifyDataArrived();
 
 private:
-  friend class MP4Demuxer;
-  void NotifyDataArrived();
   already_AddRefed<MediaRawData> GetNextSample();
   void EnsureUpToDateIndex();
   void SetNextKeyFrameTime();
-  RefPtr<MP4Demuxer> mParent;
+  RefPtr<MediaResource> mResource;
   RefPtr<ResourceStream> mStream;
   UniquePtr<TrackInfo> mInfo;
   RefPtr<Index> mIndex;
   UniquePtr<SampleIterator> mIterator;
   Maybe<media::TimeUnit> mNextKeyframeTime;
   // Queued samples extracted by the demuxer, but not yet returned.
   RefPtr<MediaRawData> mQueuedSample;
   bool mNeedReIndex;
@@ -230,18 +226,18 @@ MP4Demuxer::Init()
       MP4Metadata::ResultAndIndice indices =
         metadata.GetTrackIndice(info.Ref()->mTrackId);
       if (!indices.Ref()) {
         if (NS_FAILED(info.Result()) && result == NS_OK) {
           result = std::move(indices.Result());
         }
         continue;
       }
-      RefPtr<MP4TrackDemuxer> demuxer =
-        new MP4TrackDemuxer(this, std::move(info.Ref()), *indices.Ref().get());
+      RefPtr<MP4TrackDemuxer> demuxer = new MP4TrackDemuxer(
+        mResource, std::move(info.Ref()), *indices.Ref().get());
       DDLINKCHILD("audio demuxer", demuxer.get());
       mAudioDemuxers.AppendElement(std::move(demuxer));
     }
   }
 
   if (videoTrackCount.Ref() != 0) {
     for (size_t i = 0; i < videoTrackCount.Ref(); i++) {
       MP4Metadata::ResultAndTrackInfo info =
@@ -266,18 +262,18 @@ MP4Demuxer::Init()
       MP4Metadata::ResultAndIndice indices =
         metadata.GetTrackIndice(info.Ref()->mTrackId);
       if (!indices.Ref()) {
         if (NS_FAILED(info.Result()) && result == NS_OK) {
           result = std::move(indices.Result());
         }
         continue;
       }
-      RefPtr<MP4TrackDemuxer> demuxer =
-        new MP4TrackDemuxer(this, std::move(info.Ref()), *indices.Ref().get());
+      RefPtr<MP4TrackDemuxer> demuxer = new MP4TrackDemuxer(
+        mResource, std::move(info.Ref()), *indices.Ref().get());
       DDLINKCHILD("video demuxer", demuxer.get());
       mVideoDemuxers.AppendElement(std::move(demuxer));
     }
   }
 
   MP4Metadata::ResultAndCryptoFile cryptoFile =
     metadata.Crypto();
   if (NS_FAILED(cryptoFile.Result()) && result == NS_OK) {
@@ -359,21 +355,21 @@ MP4Demuxer::GetCrypto()
   UniquePtr<EncryptionInfo> crypto;
   if (!mCryptoInitData.IsEmpty()) {
     crypto.reset(new EncryptionInfo{});
     crypto->AddInitData(NS_LITERAL_STRING("cenc"), mCryptoInitData);
   }
   return crypto;
 }
 
-MP4TrackDemuxer::MP4TrackDemuxer(MP4Demuxer* aParent,
+MP4TrackDemuxer::MP4TrackDemuxer(MediaResource* aResource,
                                  UniquePtr<TrackInfo>&& aInfo,
                                  const IndiceWrapper& aIndices)
-  : mParent(aParent)
-  , mStream(new ResourceStream(mParent->mResource))
+  : mResource(aResource)
+  , mStream(new ResourceStream(aResource))
   , mInfo(std::move(aInfo))
   , mIndex(new Index(aIndices,
                      mStream,
                      mInfo->mTrackId,
                      mInfo->IsAudio()))
   , mIterator(MakeUnique<SampleIterator>(mIndex))
   , mNeedReIndex(true)
 {
@@ -408,17 +404,17 @@ MP4TrackDemuxer::GetInfo() const
 }
 
 void
 MP4TrackDemuxer::EnsureUpToDateIndex()
 {
   if (!mNeedReIndex) {
     return;
   }
-  AutoPinned<MediaResource> resource(mParent->mResource);
+  AutoPinned<MediaResource> resource(mResource);
   MediaByteRangeSet byteRanges;
   nsresult rv = resource->GetCachedRanges(byteRanges);
   if (NS_FAILED(rv)) {
     return;
   }
   mIndex->UpdateMoofIndex(byteRanges);
   mNeedReIndex = false;
 }
@@ -619,17 +615,17 @@ MP4TrackDemuxer::SkipToNextRandomAccessP
   SkipFailureHolder failure(NS_ERROR_DOM_MEDIA_END_OF_STREAM, parsed);
   return SkipAccessPointPromise::CreateAndReject(std::move(failure), __func__);
 }
 
 media::TimeIntervals
 MP4TrackDemuxer::GetBuffered()
 {
   EnsureUpToDateIndex();
-  AutoPinned<MediaResource> resource(mParent->mResource);
+  AutoPinned<MediaResource> resource(mResource);
   MediaByteRangeSet byteRanges;
   nsresult rv = resource->GetCachedRanges(byteRanges);
 
   if (NS_FAILED(rv)) {
     return media::TimeIntervals();
   }
 
   return mIndex->ConvertByteRangesToTimeRanges(byteRanges);
@@ -639,27 +635,21 @@ void
 MP4TrackDemuxer::NotifyDataArrived()
 {
   mNeedReIndex = true;
 }
 
 void
 MP4TrackDemuxer::NotifyDataRemoved()
 {
-  AutoPinned<MediaResource> resource(mParent->mResource);
+  AutoPinned<MediaResource> resource(mResource);
   MediaByteRangeSet byteRanges;
   nsresult rv = resource->GetCachedRanges(byteRanges);
   if (NS_FAILED(rv)) {
     return;
   }
   mIndex->UpdateMoofIndex(byteRanges, true /* can evict */);
   mNeedReIndex = false;
 }
 
-void
-MP4TrackDemuxer::BreakCycles()
-{
-  mParent = nullptr;
-}
-
 } // namespace mozilla
 
 #undef LOG
--- a/dom/media/mp4/MP4Demuxer.h
+++ b/dom/media/mp4/MP4Demuxer.h
@@ -36,17 +36,16 @@ public:
 
   UniquePtr<EncryptionInfo> GetCrypto() override;
 
   void NotifyDataArrived() override;
 
   void NotifyDataRemoved() override;
 
 private:
-  friend class MP4TrackDemuxer;
   RefPtr<MediaResource> mResource;
   RefPtr<ResourceStream> mStream;
   AutoTArray<RefPtr<MP4TrackDemuxer>, 1> mAudioDemuxers;
   AutoTArray<RefPtr<MP4TrackDemuxer>, 1> mVideoDemuxers;
   nsTArray<uint8_t> mCryptoInitData;
   bool mIsSeekable;
 };