Bug 1474443 - Remove cycle between MP4Demuxer and MP4TrackDemuxer. r=padenot
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 15 Nov 2018 12:44:56 +0000
changeset 446566 9c7f5d38a1f4c3d1ca7ddcf74c161206c5c59c82
parent 446565 003af65241156a247b0cfeb4604d1483036a002f
child 446567 2dcd2dc5f9e2a075aaf5f94f29ce1fef4344a860
push id35043
push userebalazs@mozilla.com
push dateThu, 15 Nov 2018 16:12:36 +0000
treeherdermozilla-central@59026ada59bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1474443
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1474443 - Remove cycle between MP4Demuxer and MP4TrackDemuxer. r=padenot 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;
 };