Bug 1429009. P1 - notify 'DownloadProgressed' immediately to preserve the event order. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 08 Jan 2018 14:51:57 +0800
changeset 718310 5b7361b935d5b405fb140fa73f4b7578a6da3ffd
parent 718309 c3bd5ef4eea4a72ad8cfb03b6accc749cd4c6248
child 718311 6ac989510006a56bcb1021d422820377e178455a
push id94872
push userjwwang@mozilla.com
push dateWed, 10 Jan 2018 02:03:34 +0000
bugs1429009
milestone59.0a1
Bug 1429009. P1 - notify 'DownloadProgressed' immediately to preserve the event order. We also need to call GetOwner()->UpdateReadyState() since mCanPlayThrough might have changed. MozReview-Commit-ID: C5djzu1sXqV
dom/media/ChannelMediaDecoder.cpp
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -408,16 +408,18 @@ ChannelMediaDecoder::DurationChanged()
 }
 
 void
 ChannelMediaDecoder::DownloadProgressed()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
+  GetOwner()->DownloadProgressed();
+
   using StatsPromise = MozPromise<MediaStatistics, bool, true>;
   InvokeAsync(GetStateMachine()->OwnerThread(),
               __func__,
               [
                 playbackStats = mPlaybackStatistics,
                 res = RefPtr<BaseMediaResource>(mResource),
                 duration = mDuration,
                 pos = mPlaybackPosition
@@ -433,17 +435,18 @@ ChannelMediaDecoder::DownloadProgressed(
       [ =, self = RefPtr<ChannelMediaDecoder>(this) ](MediaStatistics aStats) {
         if (IsShutdown()) {
           return;
         }
         mCanPlayThrough = aStats.CanPlayThrough();
         GetStateMachine()->DispatchCanPlayThrough(mCanPlayThrough);
         mResource->ThrottleReadahead(ShouldThrottleDownload(aStats));
         AbstractThread::AutoEnter context(AbstractMainThread());
-        GetOwner()->DownloadProgressed();
+        // Update readyState since mCanPlayThrough might have changed.
+        GetOwner()->UpdateReadyState();
       },
       []() { MOZ_ASSERT_UNREACHABLE("Promise not resolved"); });
 }
 
 /* static */ ChannelMediaDecoder::PlaybackRateInfo
 ChannelMediaDecoder::ComputePlaybackRate(const MediaChannelStatistics& aStats,
                                          BaseMediaResource* aResource,
                                          double aDuration)