Bug 1391142. P3 - remove IsLiveStream() from MediaResource. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 17 Aug 2017 15:20:40 +0800
changeset 648648 cdf46c4c7ef38848f60f6a64af1571ee370485fe
parent 648647 baf1ee6805434b218ef57716ba24ba5acd73b52a
child 726897 fa58c9185cad20679572a75e2974e0be1f758c0c
push id74836
push userjwwang@mozilla.com
push dateFri, 18 Aug 2017 05:01:08 +0000
bugs1391142
milestone57.0a1
Bug 1391142. P3 - remove IsLiveStream() from MediaResource. MozReview-Commit-ID: DBFrYfj2lGB
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/MediaResource.h
dom/media/hls/HLSDecoder.h
dom/media/hls/HLSResource.h
dom/media/mediasource/MediaSourceDecoder.h
dom/media/mediasource/MediaSourceResource.h
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -345,16 +345,23 @@ ChannelMediaDecoder::SeekingChanged()
 bool
 ChannelMediaDecoder::CanPlayThroughImpl()
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_TRUE(GetStateMachine(), false);
   return GetStatistics().CanPlayThrough();
 }
 
+bool
+ChannelMediaDecoder::IsLiveStream()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  return mResource->IsLiveStream();
+}
+
 void
 ChannelMediaDecoder::OnPlaybackEvent(MediaEventType aEvent)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MediaDecoder::OnPlaybackEvent(aEvent);
   switch (aEvent) {
     case MediaEventType::PlaybackStarted:
       mPlaybackStatistics.Start();
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -99,16 +99,18 @@ private:
   // from the resource. Called on the main by an event runner dispatched
   // by the MediaResource read functions.
   void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset);
 
   void SeekingChanged();
 
   bool CanPlayThroughImpl() override final;
 
+  bool IsLiveStream() override final;
+
   // The actual playback rate computation.
   void ComputePlaybackRate();
 
   // Something has changed that could affect the computed playback rate,
   // so recompute it.
   void UpdatePlaybackRate();
 
   // Return statistics. This is used for progress events and other things.
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -679,17 +679,17 @@ MediaDecoder::CallSeek(const SeekTarget&
 {
   MOZ_ASSERT(NS_IsMainThread());
   AbstractThread::AutoEnter context(AbstractMainThread());
   DiscardOngoingSeekIfExists();
 
   // Since we don't have a listener for changes in IsLiveStream, our best bet
   // is to ensure IsLiveStream is uptodate when seek begins. This value will be
   // checked when seek is completed.
-  mDecoderStateMachine->DispatchIsLiveStream(GetResource()->IsLiveStream());
+  mDecoderStateMachine->DispatchIsLiveStream(IsLiveStream());
 
   mDecoderStateMachine->InvokeSeek(aTarget)
   ->Then(mAbstractMainThread, __func__, this,
          &MediaDecoder::OnSeekResolved, &MediaDecoder::OnSeekRejected)
   ->Track(mSeekRequest);
 }
 
 double
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -510,16 +510,17 @@ private:
   }
 
   void FinishShutdown();
 
   void ConnectMirrors(MediaDecoderStateMachine* aObject);
   void DisconnectMirrors();
 
   virtual bool CanPlayThroughImpl() = 0;
+  virtual bool IsLiveStream() = 0;
 
   // The state machine object for handling the decoding. It is safe to
   // call methods of this object from other threads. Its internal data
   // is synchronised on a monitor. The lifetime of this object is
   // after mPlayState is LOADING and before mPlayState is SHUTDOWN. It
   // is safe to access it during this period.
   //
   // Explicitly prievate to force access via accessors.
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -239,22 +239,16 @@ public:
 
   /**
    * Fills aRanges with MediaByteRanges representing the data which is cached
    * in the media cache. Stream should be pinned during call and while
    * aRanges is being used.
    */
   virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) = 0;
 
-  // Returns true if the resource is a live stream.
-  virtual bool IsLiveStream()
-  {
-    return GetLength() == -1;
-  }
-
   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
     return 0;
   }
 
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }
 
@@ -331,16 +325,19 @@ public:
   // with a new channel. Any cached data associated with the original
   // stream should be accessible in the new stream too.
   virtual already_AddRefed<BaseMediaResource> CloneData(
     MediaResourceCallback* aCallback)
   {
     return nullptr;
   }
 
+  // Returns true if the resource is a live stream.
+  bool IsLiveStream() { return GetLength() == -1; }
+
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
   {
     // Might be useful to track in the future:
     // - mChannel
     // - mURI (possibly owned, looks like just a ref from mChannel)
     // Not owned:
     // - mCallback
     size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
--- a/dom/media/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -47,14 +47,16 @@ public:
 private:
   bool CanPlayThroughImpl() override final
   {
     // TODO: We don't know how to estimate 'canplaythrough' for this decoder.
     // For now we just return true for 'autoplay' can work.
     return true;
   }
 
+  bool IsLiveStream() override final { return false; }
+
   RefPtr<HLSResource> mResource;
 };
 
 } // namespace mozilla
 
 #endif /* HLSDecoder_h_ */
--- a/dom/media/hls/HLSResource.h
+++ b/dom/media/hls/HLSResource.h
@@ -76,21 +76,16 @@ public:
   nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override
   {
     UNIMPLEMENTED();
     return NS_OK;
   }
 
   bool IsTransportSeekable() override { return true; }
 
-  bool IsLiveStream() override
-  {
-    return false;
-  }
-
   java::GeckoHLSResourceWrapper::GlobalRef GetResourceWrapper() {
     return mHLSResourceWrapper;
   }
 
   void Detach() { mDecoder = nullptr; }
 
 private:
   friend class HLSResourceCallbacksSupport;
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -63,16 +63,17 @@ public:
   bool IsMSE() const override { return true; }
 
   void NotifyInitDataArrived();
 
 private:
   void DoSetMediaSourceDuration(double aDuration);
   media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval);
   bool CanPlayThroughImpl() override;
+  bool IsLiveStream() override final { return !mEnded; }
 
   RefPtr<MediaSourceResource> mResource;
 
   // The owning MediaSource holds a strong reference to this decoder, and
   // calls Attach/DetachMediaSource on this decoder to set and clear
   // mMediaSource.
   dom::MediaSource* mMediaSource;
   RefPtr<MediaSourceDemuxer> mDemuxer;
--- a/dom/media/mediasource/MediaSourceResource.h
+++ b/dom/media/mediasource/MediaSourceResource.h
@@ -54,21 +54,16 @@ public:
   {
     UNIMPLEMENTED();
     aRanges += MediaByteRange(0, GetLength());
     return NS_OK;
   }
 
   bool IsTransportSeekable() override { return true; }
 
-  bool IsLiveStream() override
-  {
-    MonitorAutoLock mon(mMonitor);
-    return !mEnded;
-  }
   void SetEnded(bool aEnded)
   {
     MonitorAutoLock mon(mMonitor);
     mEnded = aEnded;
   }
 
 private:
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override