Bug 1259274: [MSE] P1. Remove unnecessary abstraction layer. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 25 Mar 2016 11:31:30 +1100
changeset 290585 d26a81fecde9ef4ea756c02b4f9fcf6934a395fb
parent 290584 b6fc58671a60259a819e783c68cb97ab55592b46
child 290586 8498ca83977b7e846a64136ada2a9425c3b0b69e
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1259274
milestone48.0a1
Bug 1259274: [MSE] P1. Remove unnecessary abstraction layer. r=gerald We now longer require an abstraction layer with the TrackBuffersManager now that the old MSE has been removed. MozReview-Commit-ID: 3uEejohvFQD
dom/media/mediasource/SourceBuffer.cpp
dom/media/mediasource/SourceBuffer.h
dom/media/mediasource/SourceBufferContentManager.cpp
dom/media/mediasource/SourceBufferContentManager.h
dom/media/mediasource/TrackBuffersManager.h
dom/media/mediasource/moz.build
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -28,92 +28,98 @@ class JSObject;
 
 extern mozilla::LogModule* GetMediaSourceLog();
 extern mozilla::LogModule* GetMediaSourceAPILog();
 
 #define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
 #define MSE_DEBUGV(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Verbose, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
 #define MSE_API(arg, ...) MOZ_LOG(GetMediaSourceAPILog(), mozilla::LogLevel::Debug, ("SourceBuffer(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
 
+#if defined(MOZ_GONK_MEDIACODEC) || defined(XP_WIN) || defined(MOZ_APPLEMEDIA) || defined(MOZ_FFMPEG)
+#define MP4_READER_DORMANT_HEURISTIC
+#else
+#undef MP4_READER_DORMANT_HEURISTIC
+#endif
+
 namespace mozilla {
 
 using media::TimeUnit;
 
 namespace dom {
 
 void
 SourceBuffer::SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv)
 {
-  typedef mozilla::SourceBufferContentManager::AppendState AppendState;
+  typedef mozilla::TrackBuffersManager::AppendState AppendState;
 
   MOZ_ASSERT(NS_IsMainThread());
   MSE_API("SetMode(aMode=%d)", aMode);
   if (!IsAttached() || mUpdating) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   if (mAttributes->mGenerateTimestamps &&
       aMode == SourceBufferAppendMode::Segments) {
     aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     return;
   }
   MOZ_ASSERT(mMediaSource->ReadyState() != MediaSourceReadyState::Closed);
   if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
     mMediaSource->SetReadyState(MediaSourceReadyState::Open);
   }
-  if (mContentManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
+  if (mTrackBuffersManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   if (aMode == SourceBufferAppendMode::Sequence) {
     // Will set GroupStartTimestamp to GroupEndTimestamp.
-    mContentManager->RestartGroupStartTimestamp();
+    mTrackBuffersManager->RestartGroupStartTimestamp();
   }
 
   mAttributes->SetAppendMode(aMode);
 }
 
 void
 SourceBuffer::SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv)
 {
-  typedef mozilla::SourceBufferContentManager::AppendState AppendState;
+  typedef mozilla::TrackBuffersManager::AppendState AppendState;
 
   MOZ_ASSERT(NS_IsMainThread());
   MSE_API("SetTimestampOffset(aTimestampOffset=%f)", aTimestampOffset);
   if (!IsAttached() || mUpdating) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   MOZ_ASSERT(mMediaSource->ReadyState() != MediaSourceReadyState::Closed);
   if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
     mMediaSource->SetReadyState(MediaSourceReadyState::Open);
   }
-  if (mContentManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
+  if (mTrackBuffersManager->GetAppendState() == AppendState::PARSING_MEDIA_SEGMENT){
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   mAttributes->SetApparentTimestampOffset(aTimestampOffset);
   if (mAttributes->GetAppendMode() == SourceBufferAppendMode::Sequence) {
-    mContentManager->SetGroupStartTimestamp(mAttributes->GetTimestampOffset());
+    mTrackBuffersManager->SetGroupStartTimestamp(mAttributes->GetTimestampOffset());
   }
 }
 
 TimeRanges*
 SourceBuffer::GetBuffered(ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
   // http://w3c.github.io/media-source/index.html#widl-SourceBuffer-buffered
   // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an InvalidStateError exception and abort these steps.
   if (!IsAttached()) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
   bool rangeChanged = true;
-  media::TimeIntervals intersection = mContentManager->Buffered();
+  media::TimeIntervals intersection = mTrackBuffersManager->Buffered();
   MSE_DEBUGV("intersection=%s", DumpTimeRanges(intersection).get());
   if (mBuffered) {
     media::TimeIntervals currentValue(mBuffered);
     rangeChanged = (intersection != currentValue);
     MSE_DEBUGV("currentValue=%s", DumpTimeRanges(currentValue).get());
   }
   // 5. If intersection ranges does not contain the exact same range information as the current value of this attribute, then update the current value of this attribute to intersection ranges.
   if (rangeChanged) {
@@ -122,17 +128,17 @@ SourceBuffer::GetBuffered(ErrorResult& a
   }
   // 6. Return the current value of this attribute.
   return mBuffered;
 }
 
 media::TimeIntervals
 SourceBuffer::GetTimeIntervals()
 {
-  return mContentManager->Buffered();
+  return mTrackBuffersManager->Buffered();
 }
 
 void
 SourceBuffer::SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_API("SetAppendWindowStart(aAppendWindowStart=%f)", aAppendWindowStart);
   if (!IsAttached() || mUpdating) {
@@ -191,28 +197,28 @@ SourceBuffer::Abort(ErrorResult& aRv)
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   if (mMediaSource->ReadyState() != MediaSourceReadyState::Open) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   AbortBufferAppend();
-  mContentManager->ResetParserState();
+  mTrackBuffersManager->ResetParserState();
   mAttributes->SetAppendWindowStart(0);
   mAttributes->SetAppendWindowEnd(PositiveInfinity<double>());
 }
 
 void
 SourceBuffer::AbortBufferAppend()
 {
   if (mUpdating) {
     if (mPendingAppend.Exists()) {
       mPendingAppend.Disconnect();
-      mContentManager->AbortAppendData();
+      mTrackBuffersManager->AbortAppendData();
       // Some data may have been added by the Segment Parser Loop.
       // Check if we need to update the duration.
       CheckEndTime();
     }
     AbortUpdating();
   }
 }
 
@@ -243,49 +249,49 @@ SourceBuffer::Remove(double aStart, doub
 }
 
 void
 SourceBuffer::RangeRemoval(double aStart, double aEnd)
 {
   StartUpdating();
 
   RefPtr<SourceBuffer> self = this;
-  mContentManager->RangeRemoval(TimeUnit::FromSeconds(aStart),
-                                TimeUnit::FromSeconds(aEnd))
+  mTrackBuffersManager->RangeRemoval(TimeUnit::FromSeconds(aStart),
+                                     TimeUnit::FromSeconds(aEnd))
     ->Then(AbstractThread::MainThread(), __func__,
            [self] (bool) { self->StopUpdating(); },
            []() { MOZ_ASSERT(false); });
 }
 
 void
 SourceBuffer::Detach()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("Detach");
   if (!mMediaSource) {
     MSE_DEBUG("Already detached");
     return;
   }
   AbortBufferAppend();
-  if (mContentManager) {
-    mContentManager->Detach();
+  if (mTrackBuffersManager) {
+    mTrackBuffersManager->Detach();
     mMediaSource->GetDecoder()->GetDemuxer()->DetachSourceBuffer(
-      static_cast<mozilla::TrackBuffersManager*>(mContentManager.get()));
+      mTrackBuffersManager.get());
   }
-  mContentManager = nullptr;
+  mTrackBuffersManager = nullptr;
   mMediaSource = nullptr;
 }
 
 void
 SourceBuffer::Ended()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(IsAttached());
   MSE_DEBUG("Ended");
-  mContentManager->Ended();
+  mTrackBuffersManager->Ended();
   // We want the MediaSourceReader to refresh its buffered range as it may
   // have been modified (end lined up).
   mMediaSource->GetDecoder()->NotifyDataArrived();
 }
 
 SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
   : DOMEventTargetHelper(aMediaSource->GetParentObject())
   , mMediaSource(aMediaSource)
@@ -297,31 +303,37 @@ SourceBuffer::SourceBuffer(MediaSource* 
   MOZ_ASSERT(aMediaSource);
   bool generateTimestamps = false;
   if (aType.LowerCaseEqualsLiteral("audio/mpeg") ||
       aType.LowerCaseEqualsLiteral("audio/aac")) {
     generateTimestamps = true;
   }
   mAttributes = new SourceBufferAttributes(generateTimestamps);
 
-  mContentManager =
-    SourceBufferContentManager::CreateManager(mAttributes,
-                                              aMediaSource->GetDecoder(),
-                                              aType);
-  MSE_DEBUG("Create mContentManager=%p",
-            mContentManager.get());
+  mTrackBuffersManager =
+    new TrackBuffersManager(mAttributes,
+                            aMediaSource->GetDecoder(),
+                            aType);
+
+  // Now that we know what type we're dealing with, enable dormant as needed.
+#if defined(MP4_READER_DORMANT_HEURISTIC)
+  aMediaSource->GetDecoder()->NotifyDormantSupported(Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false));
+#endif
+
+  MSE_DEBUG("Create mTrackBuffersManager=%p",
+            mTrackBuffersManager.get());
 
   ErrorResult dummy;
   if (mAttributes->mGenerateTimestamps) {
     SetMode(SourceBufferAppendMode::Sequence, dummy);
   } else {
     SetMode(SourceBufferAppendMode::Segments, dummy);
   }
   mMediaSource->GetDecoder()->GetDemuxer()->AttachSourceBuffer(
-    static_cast<mozilla::TrackBuffersManager*>(mContentManager.get()));
+    mTrackBuffersManager.get());
 }
 
 SourceBuffer::~SourceBuffer()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mMediaSource);
   MSE_DEBUG("");
 }
@@ -386,47 +398,47 @@ SourceBuffer::AbortUpdating()
   QueueAsyncSimpleEvent("updateend");
 }
 
 void
 SourceBuffer::CheckEndTime()
 {
   MOZ_ASSERT(NS_IsMainThread());
   // Check if we need to update mMediaSource duration
-  double endTime = mContentManager->GroupEndTimestamp().ToSeconds();
+  double endTime = mTrackBuffersManager->GroupEndTimestamp().ToSeconds();
   double duration = mMediaSource->Duration();
   if (endTime > duration) {
     mMediaSource->SetDuration(endTime, MSRangeRemovalAction::SKIP);
   }
 }
 
 void
 SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
 {
   MSE_DEBUG("AppendData(aLength=%u)", aLength);
 
   RefPtr<MediaByteBuffer> data = PrepareAppend(aData, aLength, aRv);
   if (!data) {
     return;
   }
-  mContentManager->AppendData(data, mAttributes->GetTimestampOffset());
+  mTrackBuffersManager->AppendData(data, mAttributes->GetTimestampOffset());
 
   StartUpdating();
 
   BufferAppend();
 }
 
 void
 SourceBuffer::BufferAppend()
 {
   MOZ_ASSERT(mUpdating);
   MOZ_ASSERT(mMediaSource);
   MOZ_ASSERT(!mPendingAppend.Exists());
 
-  mPendingAppend.Begin(mContentManager->BufferAppend()
+  mPendingAppend.Begin(mTrackBuffersManager->BufferAppend()
                        ->Then(AbstractThread::MainThread(), __func__, this,
                               &SourceBuffer::AppendDataCompletedWithSuccess,
                               &SourceBuffer::AppendDataErrored));
 }
 
 void
 SourceBuffer::AppendDataCompletedWithSuccess(bool aHasActiveTracks)
 {
@@ -468,17 +480,17 @@ SourceBuffer::AppendDataErrored(nsresult
   }
 }
 
 void
 SourceBuffer::AppendError(bool aDecoderError)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  mContentManager->ResetParserState();
+  mTrackBuffersManager->ResetParserState();
 
   mUpdating = false;
 
   QueueAsyncSimpleEvent("error");
   QueueAsyncSimpleEvent("updateend");
 
   if (aDecoderError) {
     Optional<MediaSourceEndOfStreamError> decodeError(
@@ -486,17 +498,17 @@ SourceBuffer::AppendError(bool aDecoderE
     ErrorResult dummy;
     mMediaSource->EndOfStream(decodeError, dummy);
   }
 }
 
 already_AddRefed<MediaByteBuffer>
 SourceBuffer::PrepareAppend(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv)
 {
-  typedef SourceBufferContentManager::EvictDataResult Result;
+  typedef TrackBuffersManager::EvictDataResult Result;
 
   if (!IsAttached() || mUpdating) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
   // If the HTMLMediaElement.error attribute is not null, then throw an
   // InvalidStateError exception and abort these steps.
@@ -518,31 +530,31 @@ SourceBuffer::PrepareAppend(const uint8_
   // about.
   // TODO: Make the eviction threshold smaller for audio-only streams.
   // TODO: Drive evictions off memory pressure notifications.
   // TODO: Consider a global eviction threshold  rather than per TrackBuffer.
   TimeUnit newBufferStartTime;
   // Attempt to evict the amount of data we are about to add by lowering the
   // threshold.
   Result evicted =
-    mContentManager->EvictData(TimeUnit::FromSeconds(mMediaSource->GetDecoder()->GetCurrentTime()),
-                               aLength, &newBufferStartTime);
+    mTrackBuffersManager->EvictData(TimeUnit::FromSeconds(mMediaSource->GetDecoder()->GetCurrentTime()),
+                                    aLength, &newBufferStartTime);
   if (evicted == Result::DATA_EVICTED) {
     MSE_DEBUG("AppendData Evict; current buffered start=%f",
               GetBufferedStart());
 
     // We notify that we've evicted from the time range 0 through to
     // the current start point.
     mMediaSource->NotifyEvicted(0.0, newBufferStartTime.ToSeconds());
   }
 
   // See if we have enough free space to append our new data.
   // As we can only evict once we have playable data, we must give a chance
   // to the DASH player to provide a complete media segment.
-  if (aLength > mContentManager->EvictionThreshold() ||
+  if (aLength > mTrackBuffersManager->EvictionThreshold() ||
       evicted == Result::BUFFER_FULL) {
     aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
     return nullptr;
   }
 
   RefPtr<MediaByteBuffer> data = new MediaByteBuffer();
   if (!data->AppendElements(aData, aLength, fallible)) {
     aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
@@ -575,24 +587,24 @@ SourceBuffer::Evict(double aStart, doubl
   MOZ_ASSERT(NS_IsMainThread());
   MSE_DEBUG("Evict(aStart=%f, aEnd=%f)", aStart, aEnd);
   double currentTime = mMediaSource->GetDecoder()->GetCurrentTime();
   double evictTime = aEnd;
   const double safety_threshold = 5;
   if (currentTime + safety_threshold >= evictTime) {
     evictTime -= safety_threshold;
   }
-  mContentManager->EvictBefore(TimeUnit::FromSeconds(evictTime));
+  mTrackBuffersManager->EvictBefore(TimeUnit::FromSeconds(evictTime));
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(SourceBuffer)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(SourceBuffer)
   // Tell the TrackBuffer to end its current SourceBufferResource.
-  SourceBufferContentManager* manager = tmp->mContentManager;
+  TrackBuffersManager* manager = tmp->mTrackBuffersManager;
   if (manager) {
     manager->Detach();
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaSource)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mBuffered)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(DOMEventTargetHelper)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SourceBuffer,
--- a/dom/media/mediasource/SourceBuffer.h
+++ b/dom/media/mediasource/SourceBuffer.h
@@ -19,28 +19,27 @@
 #include "mozilla/mozalloc.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionNoteChild.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupports.h"
 #include "nsString.h"
 #include "nscore.h"
-#include "SourceBufferContentManager.h"
+#include "TrackBuffersManager.h"
 #include "mozilla/Monitor.h"
 
 class JSObject;
 struct JSContext;
 
 namespace mozilla {
 
 class ErrorResult;
 class MediaByteBuffer;
 template <typename T> class AsyncEventRunner;
-class TrackBuffersManager;
 
 namespace dom {
 
 class TimeRanges;
 
 class SourceBufferAttributes {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SourceBufferAttributes);
@@ -248,24 +247,24 @@ private:
                                                   uint32_t aLength,
                                                   ErrorResult& aRv);
 
   void AppendDataCompletedWithSuccess(bool aHasActiveTracks);
   void AppendDataErrored(nsresult aError);
 
   RefPtr<MediaSource> mMediaSource;
 
-  RefPtr<SourceBufferContentManager> mContentManager;
+  RefPtr<TrackBuffersManager> mTrackBuffersManager;
   RefPtr<SourceBufferAttributes> mAttributes;
 
   bool mUpdating;
 
   mozilla::Atomic<bool> mActive;
 
-  MozPromiseRequestHolder<SourceBufferContentManager::AppendPromise> mPendingAppend;
+  MozPromiseRequestHolder<TrackBuffersManager::AppendPromise> mPendingAppend;
   const nsCString mType;
 
   RefPtr<TimeRanges> mBuffered;
 };
 
 } // namespace dom
 
 } // namespace mozilla
deleted file mode 100644
--- a/dom/media/mediasource/SourceBufferContentManager.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "SourceBufferContentManager.h"
-#include "mozilla/Preferences.h"
-#include "TrackBuffersManager.h"
-
-namespace mozilla {
-
-#if defined(MOZ_GONK_MEDIACODEC) || defined(XP_WIN) || defined(MOZ_APPLEMEDIA) || defined(MOZ_FFMPEG)
-#define MP4_READER_DORMANT_HEURISTIC
-#else
-#undef MP4_READER_DORMANT_HEURISTIC
-#endif
-
-already_AddRefed<SourceBufferContentManager>
-SourceBufferContentManager::CreateManager(dom::SourceBufferAttributes* aAttributes,
-                                          MediaSourceDecoder* aParentDecoder,
-                                          const nsACString &aType)
-{
-  RefPtr<SourceBufferContentManager> manager;
-  manager = new TrackBuffersManager(aAttributes, aParentDecoder, aType);
-
-  // Now that we know what type we're dealing with, enable dormant as needed.
-#if defined(MP4_READER_DORMANT_HEURISTIC)
-  aParentDecoder->NotifyDormantSupported(Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false));
-#endif
-
-  return  manager.forget();
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/dom/media/mediasource/SourceBufferContentManager.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef MOZILLA_SOURCEBUFFERCONTENTMANAGER_H_
-#define MOZILLA_SOURCEBUFFERCONTENTMANAGER_H_
-
-#include "mozilla/MozPromise.h"
-
-#include "MediaData.h"
-#include "MediaSourceDecoder.h"
-#include "TimeUnits.h"
-#include "nsString.h"
-
-namespace mozilla {
-
-namespace dom {
-class SourceBuffer;
-class SourceBufferAttributes;
-}
-
-class SourceBufferContentManager {
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SourceBufferContentManager);
-
-  typedef MozPromise<bool, nsresult, /* IsExclusive = */ true> AppendPromise;
-  typedef AppendPromise RangeRemovalPromise;
-
-  static already_AddRefed<SourceBufferContentManager>
-  CreateManager(dom::SourceBufferAttributes* aAttributes,
-                MediaSourceDecoder* aParentDecoder,
-                const nsACString& aType);
-
-  // Add data to the end of the input buffer.
-  // Returns false if the append failed.
-  virtual bool
-  AppendData(MediaByteBuffer* aData, media::TimeUnit aTimestampOffset) = 0;
-
-  // Run MSE Buffer Append Algorithm
-  // 3.5.5 Buffer Append Algorithm.
-  // http://w3c.github.io/media-source/index.html#sourcebuffer-buffer-append
-  virtual RefPtr<AppendPromise> BufferAppend() = 0;
-
-  // Abort any pending AppendData.
-  virtual void AbortAppendData() = 0;
-
-  // Run MSE Reset Parser State Algorithm.
-  // 3.5.2 Reset Parser State
-  // http://w3c.github.io/media-source/#sourcebuffer-reset-parser-state
-  virtual void ResetParserState() = 0;
-
-  // Runs MSE range removal algorithm.
-  // http://w3c.github.io/media-source/#sourcebuffer-coded-frame-removal
-  virtual RefPtr<RangeRemovalPromise> RangeRemoval(media::TimeUnit aStart,
-                                                   media::TimeUnit aEnd) = 0;
-
-  enum class EvictDataResult : int8_t
-  {
-    NO_DATA_EVICTED,
-    DATA_EVICTED,
-    CANT_EVICT,
-    BUFFER_FULL,
-  };
-
-  // Evicts data up to aPlaybackTime. aThreshold is used to
-  // bound the data being evicted. It will not evict more than aThreshold
-  // bytes. aBufferStartTime contains the new start time of the data after the
-  // eviction.
-  virtual EvictDataResult
-  EvictData(media::TimeUnit aPlaybackTime,
-            int64_t aThreshold,
-            media::TimeUnit* aBufferStartTime) = 0;
-
-  // Evicts data up to aTime.
-  virtual void EvictBefore(media::TimeUnit aTime) = 0;
-
-  // Returns the buffered range currently managed.
-  // This may be called on any thread.
-  // Buffered must conform to http://w3c.github.io/media-source/index.html#widl-SourceBuffer-buffered
-  virtual media::TimeIntervals Buffered() = 0;
-
-  // Return the size of the data managed by this SourceBufferContentManager.
-  virtual int64_t GetSize() = 0;
-
-  // Indicate that the MediaSource parent object got into "ended" state.
-  virtual void Ended() = 0;
-
-  // The parent SourceBuffer is about to be destroyed.
-  virtual void Detach() = 0;
-
-  // Current state as per Segment Parser Loop Algorithm
-  // http://w3c.github.io/media-source/index.html#sourcebuffer-segment-parser-loop
-  enum class AppendState : int32_t
-  {
-    WAITING_FOR_SEGMENT,
-    PARSING_INIT_SEGMENT,
-    PARSING_MEDIA_SEGMENT,
-  };
-
-  virtual AppendState GetAppendState()
-  {
-    return AppendState::WAITING_FOR_SEGMENT;
-  }
-
-  virtual void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp) {}
-  virtual void RestartGroupStartTimestamp() {}
-  virtual media::TimeUnit GroupEndTimestamp() = 0;
-  virtual int64_t EvictionThreshold() const = 0;
-
-protected:
-  virtual ~SourceBufferContentManager() { }
-};
-
-} // namespace mozilla
-
-#endif /* MOZILLA_SOURCEBUFFERCONTENTMANAGER_H_ */
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -5,84 +5,130 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_TRACKBUFFERSMANAGER_H_
 #define MOZILLA_TRACKBUFFERSMANAGER_H_
 
 #include "mozilla/Atomics.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Monitor.h"
+#include "mozilla/MozPromise.h"
 #include "mozilla/Pair.h"
 #include "mozilla/dom/SourceBufferBinding.h"
 
-#include "SourceBufferContentManager.h"
+#include "MediaData.h"
 #include "MediaDataDemuxer.h"
 #include "MediaSourceDecoder.h"
+#include "TimeUnits.h"
 #include "nsProxyRelease.h"
+#include "nsString.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
 class ContainerParser;
 class MediaByteBuffer;
 class MediaRawData;
 class MediaSourceDemuxer;
 class SourceBufferResource;
 
 namespace dom {
   class SourceBufferAttributes;
 }
 
-class TrackBuffersManager : public SourceBufferContentManager {
+class TrackBuffersManager {
 public:
-  typedef MozPromise<bool, nsresult, /* IsExclusive = */ true> CodedFrameProcessingPromise;
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TrackBuffersManager);
+
+  typedef MozPromise<bool, nsresult, /* IsExclusive = */ true> AppendPromise;
+  typedef AppendPromise RangeRemovalPromise;
+
+  enum class EvictDataResult : int8_t
+  {
+    NO_DATA_EVICTED,
+    DATA_EVICTED,
+    CANT_EVICT,
+    BUFFER_FULL,
+  };
+
+  // Current state as per Segment Parser Loop Algorithm
+  // http://w3c.github.io/media-source/index.html#sourcebuffer-segment-parser-loop
+  enum class AppendState : int32_t
+  {
+    WAITING_FOR_SEGMENT,
+    PARSING_INIT_SEGMENT,
+    PARSING_MEDIA_SEGMENT,
+  };
+
   typedef TrackInfo::TrackType TrackType;
   typedef MediaData::Type MediaType;
   typedef nsTArray<RefPtr<MediaRawData>> TrackBuffer;
 
+  // Interface for SourceBuffer
   TrackBuffersManager(dom::SourceBufferAttributes* aAttributes,
                       MediaSourceDecoder* aParentDecoder,
                       const nsACString& aType);
 
+  // Add data to the end of the input buffer.
+  // Returns false if the append failed.
   bool AppendData(MediaByteBuffer* aData,
-                  media::TimeUnit aTimestampOffset) override;
+                  media::TimeUnit aTimestampOffset);
 
-  RefPtr<AppendPromise> BufferAppend() override;
+  // Run MSE Buffer Append Algorithm
+  // 3.5.5 Buffer Append Algorithm.
+  // http://w3c.github.io/media-source/index.html#sourcebuffer-buffer-append
+  RefPtr<AppendPromise> BufferAppend();
+
+  // Abort any pending AppendData.
+  void AbortAppendData();
 
-  void AbortAppendData() override;
-
-  void ResetParserState() override;
+  // Run MSE Reset Parser State Algorithm.
+  // 3.5.2 Reset Parser State
+  void ResetParserState();
 
+  // Runs MSE range removal algorithm.
+  // http://w3c.github.io/media-source/#sourcebuffer-coded-frame-removal
   RefPtr<RangeRemovalPromise> RangeRemoval(media::TimeUnit aStart,
-                                             media::TimeUnit aEnd) override;
+                                             media::TimeUnit aEnd);
 
+  // Evicts data up to aPlaybackTime. aThreshold is used to
+  // bound the data being evicted. It will not evict more than aThreshold
+  // bytes. aBufferStartTime contains the new start time of the data after the
+  // eviction.
   EvictDataResult
   EvictData(media::TimeUnit aPlaybackTime,
             int64_t aThresholdReduct,
-            media::TimeUnit* aBufferStartTime) override;
+            media::TimeUnit* aBufferStartTime);
+
+  // Evicts data up to aTime.
+  void EvictBefore(media::TimeUnit aTime);
 
-  void EvictBefore(media::TimeUnit aTime) override;
-
-  media::TimeIntervals Buffered() override;
+  // Returns the buffered range currently managed.
+  // This may be called on any thread.
+  // Buffered must conform to http://w3c.github.io/media-source/index.html#widl-SourceBuffer-buffered
+  media::TimeIntervals Buffered();
 
-  int64_t GetSize() override;
-
-  void Ended() override;
+  // Return the size of the data managed by this SourceBufferContentManager.
+  int64_t GetSize();
 
-  void Detach() override;
+  // Indicate that the MediaSource parent object got into "ended" state.
+  void Ended();
 
-  AppendState GetAppendState() override
+  // The parent SourceBuffer is about to be destroyed.
+  void Detach();
+
+  AppendState GetAppendState()
   {
     return mAppendState;
   }
 
-  void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp) override;
-  void RestartGroupStartTimestamp() override;
-  media::TimeUnit GroupEndTimestamp() override;
-  int64_t EvictionThreshold() const override;
+  void SetGroupStartTimestamp(const media::TimeUnit& aGroupStartTimestamp);
+  void RestartGroupStartTimestamp();
+  media::TimeUnit GroupEndTimestamp();
+  int64_t EvictionThreshold() const;
 
   // Interface for MediaSourceDemuxer
   MediaInfo GetMetadata();
   const TrackBuffer& GetTrackBuffer(TrackInfo::TrackType aTrack);
   const media::TimeIntervals& Buffered(TrackInfo::TrackType);
   media::TimeIntervals SafeBuffered(TrackInfo::TrackType) const;
   bool IsEnded() const
   {
@@ -97,16 +143,18 @@ public:
   already_AddRefed<MediaRawData> GetSample(TrackInfo::TrackType aTrack,
                                            const media::TimeUnit& aFuzz,
                                            bool& aError);
   media::TimeUnit GetNextRandomAccessPoint(TrackInfo::TrackType aTrack);
 
   void AddSizeOfResources(MediaSourceDecoder::ResourceSizes* aSizes);
 
 private:
+  typedef MozPromise<bool, nsresult, /* IsExclusive = */ true> CodedFrameProcessingPromise;
+
   // for MediaSourceDemuxer::GetMozDebugReaderData
   friend class MediaSourceDemuxer;
   virtual ~TrackBuffersManager();
   // All following functions run on the taskqueue.
   RefPtr<AppendPromise> InitSegmentParserLoop();
   void ScheduleSegmentParserLoop();
   void SegmentParserLoop();
   void AppendIncomingBuffers();
--- a/dom/media/mediasource/moz.build
+++ b/dom/media/mediasource/moz.build
@@ -4,34 +4,33 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MOCHITEST_MANIFESTS += ['test/mochitest.ini']
 
 EXPORTS += [
     'AsyncEventRunner.h',
     'MediaSourceDecoder.h',
     'MediaSourceDemuxer.h',
-    'SourceBufferContentManager.h',
+    'TrackBuffersManager.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'MediaSource.h',
     'SourceBuffer.h',
     'SourceBufferList.h',
 ]
 
 UNIFIED_SOURCES += [
     'ContainerParser.cpp',
     'MediaSource.cpp',
     'MediaSourceDecoder.cpp',
     'MediaSourceDemuxer.cpp',
     'MediaSourceUtils.cpp',
     'ResourceQueue.cpp',
     'SourceBuffer.cpp',
-    'SourceBufferContentManager.cpp',
     'SourceBufferList.cpp',
     'SourceBufferResource.cpp',
     'TrackBuffersManager.cpp',
 ]
 
 TEST_DIRS += [
     'gtest',
 ]