Bug 1159027: Part5. Ensure we have up to date index when calculating offsets. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 11 May 2015 20:57:46 +1000
changeset 243357 9ff00018ff1bba9acd9c9d7d38de9a5e0895b180
parent 243356 456b71b199def9dedeb9485a19b58c2213d9965b
child 243358 1c15a3d5906b7fa05000ff4e5698513b8699383c
push id28738
push usercbook@mozilla.com
push dateTue, 12 May 2015 14:11:31 +0000
treeherdermozilla-central@bedce1b405a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1159027
milestone40.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 1159027: Part5. Ensure we have up to date index when calculating offsets. r=cpearce
dom/media/fmp4/MP4Demuxer.cpp
dom/media/fmp4/MP4Demuxer.h
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -88,31 +88,35 @@ MP4Demuxer::GetNumberTracks(TrackInfo::T
 }
 
 already_AddRefed<MediaTrackDemuxer>
 MP4Demuxer::GetTrackDemuxer(TrackInfo::TrackType aType, uint32_t aTrackNumber)
 {
   if (mMetadata->GetNumberTracks(aType) <= aTrackNumber) {
     return nullptr;
   }
-  nsRefPtr<MediaTrackDemuxer> e =
+  nsRefPtr<MP4TrackDemuxer> e =
     new MP4TrackDemuxer(this, aType, aTrackNumber);
+  mDemuxers.AppendElement(e);
+
   return e.forget();
 }
 
 bool
 MP4Demuxer::IsSeekable() const
 {
   return mMetadata->CanSeek();
 }
 
 void
 MP4Demuxer::NotifyDataArrived(uint32_t aLength, int64_t aOffset)
 {
-  // TODO. May not be required for our use
+  for (uint32_t i = 0; i < mDemuxers.Length(); i++) {
+    mDemuxers[i]->NotifyDataArrived();
+  }
 }
 
 UniquePtr<EncryptionInfo>
 MP4Demuxer::GetCrypto()
 {
   const mp4_demuxer::CryptoFile& cryptoFile = mMetadata->Crypto();
   if (!cryptoFile.valid) {
     return nullptr;
@@ -150,16 +154,17 @@ MP4TrackDemuxer::MP4TrackDemuxer(MP4Demu
     MOZ_ASSERT(false);
   }
   mIndex = new mp4_demuxer::Index(indices,
                                   mStream,
                                   mInfo->mTrackId,
                                   mInfo->IsAudio(),
                                   &mMonitor);
   mIterator = MakeUnique<mp4_demuxer::SampleIterator>(mIndex);
+  NotifyDataArrived(); // Force update of index
 }
 
 UniquePtr<TrackInfo>
 MP4TrackDemuxer::GetInfo() const
 {
   return mInfo->Clone();
 }
 
@@ -296,17 +301,16 @@ MP4TrackDemuxer::GetBuffered()
   nsresult rv = resource->GetCachedRanges(byteRanges);
 
   if (NS_FAILED(rv)) {
     return media::TimeIntervals();
   }
   nsTArray<mp4_demuxer::Interval<int64_t>> timeRanges;
 
   MonitorAutoLock mon(mMonitor);
-  mIndex->UpdateMoofIndex(byteRanges);
   int64_t endComposition =
     mIndex->GetEndCompositionIfBuffered(byteRanges);
 
   mIndex->ConvertByteRangesToTimeRanges(byteRanges, &timeRanges);
   if (endComposition) {
     mp4_demuxer::Interval<int64_t>::SemiNormalAppend(
       timeRanges, mp4_demuxer::Interval<int64_t>(endComposition, endComposition));
   }
@@ -315,9 +319,28 @@ MP4TrackDemuxer::GetBuffered()
   for (size_t i = 0; i < timeRanges.Length(); i++) {
     ranges +=
       media::TimeInterval(media::TimeUnit::FromMicroseconds(timeRanges[i].start),
                           media::TimeUnit::FromMicroseconds(timeRanges[i].end));
   }
   return ranges;
 }
 
+void
+MP4TrackDemuxer::NotifyDataArrived()
+{
+  AutoPinned<MediaResource> resource(mParent->mResource);
+  nsTArray<MediaByteRange> byteRanges;
+  nsresult rv = resource->GetCachedRanges(byteRanges);
+  if (NS_FAILED(rv)) {
+    return;
+  }
+  MonitorAutoLock mon(mMonitor);
+  mIndex->UpdateMoofIndex(byteRanges);
+}
+
+void
+MP4TrackDemuxer::BreakCycles()
+{
+  mParent = nullptr;
+}
+
 } // namespace mozilla
--- a/dom/media/fmp4/MP4Demuxer.h
+++ b/dom/media/fmp4/MP4Demuxer.h
@@ -46,16 +46,17 @@ public:
   virtual void NotifyDataArrived(uint32_t aLength, int64_t aOffset) override;
 
 private:
   friend class MP4TrackDemuxer;
   nsRefPtr<MediaResource> mResource;
   nsRefPtr<mp4_demuxer::ResourceStream> mStream;
   nsRefPtr<MediaLargeByteBuffer> mInitData;
   UniquePtr<mp4_demuxer::MP4Metadata> mMetadata;
+  nsTArray<nsRefPtr<MP4TrackDemuxer>> mDemuxers;
 };
 
 class MP4TrackDemuxer : public MediaTrackDemuxer
 {
 public:
   MP4TrackDemuxer(MP4Demuxer* aParent,
                   TrackInfo::TrackType aType,
                   uint32_t aTrackNumber);
@@ -71,17 +72,21 @@ public:
   virtual nsresult GetNextRandomAccessPoint(media::TimeUnit* aTime) override;
 
   nsRefPtr<SkipAccessPointPromise> SkipToNextRandomAccessPoint(media::TimeUnit aTimeThreshold) override;
 
   virtual media::TimeIntervals GetBuffered() override;
 
   virtual int64_t GetEvictionOffset(media::TimeUnit aTime) override;
 
+  virtual void BreakCycles() override;
+
 private:
+  friend class MP4Demuxer;
+  void NotifyDataArrived();
   void UpdateSamples(nsTArray<nsRefPtr<MediaRawData>>& aSamples);
   nsRefPtr<MP4Demuxer> mParent;
   nsRefPtr<mp4_demuxer::Index> mIndex;
   UniquePtr<mp4_demuxer::SampleIterator> mIterator;
   UniquePtr<TrackInfo> mInfo;
   nsRefPtr<mp4_demuxer::ResourceStream> mStream;
   Maybe<media::TimeUnit> mNextKeyframeTime;
   // Queued samples extracted by the demuxer, but not yet returned.