Bug 1388228. P4 - move the implementation of MediaDecoder::CanPlayThroughImpl() down to ChannelMediaDecoder. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 07 Aug 2017 11:48:43 +0800
changeset 642347 28af604ef8701f57f108c6c7283077798bf7e32e
parent 642346 11ee7abb90ab5f780453de4a1294e972e965e538
child 642348 1b0b81079f6017ba679b60e16d6452973ac3d452
push id72707
push userjwwang@mozilla.com
push dateTue, 08 Aug 2017 02:32:36 +0000
bugs1388228
milestone57.0a1
Bug 1388228. P4 - move the implementation of MediaDecoder::CanPlayThroughImpl() down to ChannelMediaDecoder. Because GetStatistics() only makes sense for ChannelMediaResource. MozReview-Commit-ID: HkEpb4frUx1
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/hls/HLSDecoder.h
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -328,12 +328,20 @@ void
 ChannelMediaDecoder::SeekingChanged()
 {
   // Stop updating the bytes downloaded for progress notifications when
   // seeking to prevent wild changes to the progress notification.
   MOZ_ASSERT(NS_IsMainThread());
   mIgnoreProgressData = mLogicallySeeking;
 }
 
+bool
+ChannelMediaDecoder::CanPlayThroughImpl()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  NS_ENSURE_TRUE(GetStateMachine(), false);
+  return GetStatistics().CanPlayThrough();
+}
+
 } // namespace mozilla
 
 // avoid redefined macro in unified build
 #undef LOG
--- a/dom/media/ChannelMediaDecoder.h
+++ b/dom/media/ChannelMediaDecoder.h
@@ -86,16 +86,18 @@ private:
 
   // Called by the MediaResource to keep track of the number of bytes read
   // 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;
+
   WatchManager<ChannelMediaDecoder> mWatchManager;
 
   // True when seeking or otherwise moving the play position around in
   // such a manner that progress event data is inaccurate. This is set
   // during seek and duration operations to prevent the progress indicator
   // from jumping around. Read/Write on the main thread only.
   bool mIgnoreProgressData = false;
 };
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1567,24 +1567,16 @@ MediaDecoder::UnpinForSeek()
   if (!resource || !mPinnedForSeek) {
     return;
   }
   mPinnedForSeek = false;
   resource->Unpin();
 }
 
 bool
-MediaDecoder::CanPlayThroughImpl()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  NS_ENSURE_TRUE(mDecoderStateMachine, false);
-  return GetStatistics().CanPlayThrough();
-}
-
-bool
 MediaDecoder::CanPlayThrough()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   AbstractThread::AutoEnter context(AbstractMainThread());
   bool val = CanPlayThroughImpl();
   if (val != mCanPlayThrough) {
     mCanPlayThrough = val;
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -527,17 +527,17 @@ private:
     mMediaSeekable = false;
   }
 
   void FinishShutdown();
 
   void ConnectMirrors(MediaDecoderStateMachine* aObject);
   void DisconnectMirrors();
 
-  virtual bool CanPlayThroughImpl();
+  virtual bool CanPlayThroughImpl() = 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/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -37,14 +37,21 @@ public:
 
   nsresult Load(nsIChannel* aChannel);
 
   nsresult Play() override;
 
   void Pause() override;
 
 private:
+  bool CanPlayThroughImpl() override final
+  {
+    // TODO: We don't know how to estimate 'canplaythrough' for this decoder.
+    // For now we just return ture for 'autoplay' can work.
+    return true;
+  }
+
   RefPtr<HLSResource> mResource;
 };
 
 } // namespace mozilla
 
 #endif /* HLSDecoder_h_ */