Bug 1194080: [mp3] Implement MP3TrackDemuxer::GetBuffered(). r=esawin
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 01 Oct 2015 21:34:47 +1000
changeset 265673 4e3ec1168d625e734358ea6b5a5c158c86730f4f
parent 265672 da87848a6239e55b468f49220b7bf0139c4845cc
child 265674 37f3303f163abbd8b9ce4dbd1e024506a5a3040e
push id29467
push userkwierso@gmail.com
push dateFri, 02 Oct 2015 20:33:25 +0000
treeherdermozilla-central@2308353160d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1194080
milestone44.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 1194080: [mp3] Implement MP3TrackDemuxer::GetBuffered(). r=esawin This is done by roughly estimated the duration of the MediaResource buffered range from the average bitrate.
dom/media/MP3Demuxer.cpp
dom/media/MP3Demuxer.h
--- a/dom/media/MP3Demuxer.cpp
+++ b/dom/media/MP3Demuxer.cpp
@@ -313,20 +313,23 @@ MP3TrackDemuxer::SkipToNextRandomAccessP
 
 int64_t
 MP3TrackDemuxer::GetResourceOffset() const {
   return mOffset;
 }
 
 TimeIntervals
 MP3TrackDemuxer::GetBuffered() {
-  // TODO: bug 1169485.
-  MP3DEMUXER_LOG("MP3TrackDemuxer::GetBuffered()");
-  NS_WARNING("Unimplemented function GetBuffered");
-  return TimeIntervals();
+  TimeUnit duration = Duration();
+
+  if (duration <= TimeUnit()) {
+    return TimeIntervals();
+  }
+  AutoPinned<MediaResource> stream(mSource.GetResource());
+  return GetEstimatedBufferedTimeRanges(stream, duration.ToMicroseconds());
 }
 
 int64_t
 MP3TrackDemuxer::StreamLength() const {
   return mSource.GetLength();
 }
 
 TimeUnit
--- a/dom/media/MP3Demuxer.h
+++ b/dom/media/MP3Demuxer.h
@@ -21,16 +21,21 @@ public:
   nsRefPtr<InitPromise> Init() override;
   bool HasTrackType(TrackInfo::TrackType aType) const override;
   uint32_t GetNumberTracks(TrackInfo::TrackType aType) const override;
   already_AddRefed<MediaTrackDemuxer> GetTrackDemuxer(
       TrackInfo::TrackType aType, uint32_t aTrackNumber) override;
   bool IsSeekable() const override;
   void NotifyDataArrived(uint32_t aLength, int64_t aOffset) override;
   void NotifyDataRemoved() override;
+  // Do not shift the calculated buffered range by the start time of the first
+  // decoded frame. The mac MP3 decoder will buffer some samples and the first
+  // frame returned has typically a start time that is non-zero, causing our
+  // buffered range to have a negative start time.
+  bool ShouldComputeStartTime() const override { return false; }
 
 private:
   // Synchronous initialization.
   bool InitInternal();
 
   nsRefPtr<MediaResource> mSource;
   nsRefPtr<MP3TrackDemuxer> mTrackDemuxer;
 };