Bug 1369598 - Notify HLSDemuxer initialized after underlying GekcoHlsPlayer is ready with data. r=jolin
authorKilik Kuo <kikuo@mozilla.com>
Thu, 08 Jun 2017 22:41:35 +0800
changeset 414743 6d3323e4e07182b3370e2aba1254bfb9e8b0fb27
parent 414742 5c0b6ba1da0667d4c9fbea57d2b1d64344836ff5
child 414744 eaf99ba3813aa82632262ba4fc0438a7e2574af6
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjolin
bugs1369598
milestone56.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 1369598 - Notify HLSDemuxer initialized after underlying GekcoHlsPlayer is ready with data. r=jolin MozReview-Commit-ID: CkdNwoVHmD3
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsPlayer.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsRendererBase.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsPlayer.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsPlayer.java
@@ -78,31 +78,40 @@ public class GeckoHlsPlayer implements E
     private RendererController mRendererController = new RendererController(true, true);
 
     // Provide statistical information of tracks.
     private class HlsMediaTracksInfo {
         private int mNumVideoTracks = 0;
         private int mNumAudioTracks = 0;
         private boolean mVideoInfoUpdated = false;
         private boolean mAudioInfoUpdated = false;
+        private boolean mVideoDataArrived = false;
+        private boolean mAudioDataArrived = false;
         HlsMediaTracksInfo(int numVideoTracks, int numAudioTracks) {
             this.mNumVideoTracks = numVideoTracks;
             this.mNumAudioTracks = numAudioTracks;
         }
         public boolean hasVideo() { return mNumVideoTracks > 0; }
         public boolean hasAudio() { return mNumAudioTracks > 0; }
         public int getNumOfVideoTracks() { return mNumVideoTracks; }
         public int getNumOfAudioTracks() { return mNumAudioTracks; }
         public void onVideoInfoUpdated() { mVideoInfoUpdated = true; }
         public void onAudioInfoUpdated() { mAudioInfoUpdated = true; }
+        public void onDataArrived(int trackType) {
+            if (trackType == C.TRACK_TYPE_VIDEO) {
+                mVideoDataArrived = true;
+            } else if (trackType == C.TRACK_TYPE_AUDIO) {
+                mAudioDataArrived = true;
+            }
+        }
         public boolean videoReady() {
-            return hasVideo() ? mVideoInfoUpdated : true;
+            return !hasVideo() || (mVideoInfoUpdated && mVideoDataArrived);
         }
         public boolean audioReady() {
-            return hasAudio() ? mAudioInfoUpdated : true;
+            return !hasAudio() || (mAudioInfoUpdated && mAudioDataArrived);
         }
     }
     private HlsMediaTracksInfo mTracksInfo = null;
 
     private boolean mIsPlayerInitDone = false;
     private boolean mIsDemuxerInitDone = false;
     private DemuxerCallbacks mDemuxerCallbacks;
     private ResourceCallbacks mResourceCallbacks;
@@ -174,27 +183,27 @@ public class GeckoHlsPlayer implements E
         }
         if (mTracksInfo.videoReady() && mTracksInfo.audioReady()) {
             mDemuxerCallbacks.onInitialized(mTracksInfo.hasAudio(), mTracksInfo.hasVideo());
             mIsDemuxerInitDone = true;
         }
     }
 
     public final class ComponentEventDispatcher {
-        public void onDataArrived() {
+        public void onDataArrived(final int trackType) {
             assertTrue(mMainHandler != null);
             assertTrue(mComponentListener != null);
             if (!mIsPlayerInitDone) {
                 return;
             }
             if (mMainHandler != null && mComponentListener != null) {
                 mMainHandler.post(new Runnable() {
                     @Override
                     public void run() {
-                        mComponentListener.onDataArrived();
+                        mComponentListener.onDataArrived(trackType);
                     }
                 });
             }
         }
 
         public void onVideoInputFormatChanged(final Format format) {
             assertTrue(mMainHandler != null);
             assertTrue(mComponentListener != null);
@@ -226,20 +235,23 @@ public class GeckoHlsPlayer implements E
                 });
             }
         }
     }
 
     public final class ComponentListener {
 
         // General purpose implementation
-        public void onDataArrived() {
+        public void onDataArrived(int trackType) {
             assertTrue(mResourceCallbacks != null);
+            assertTrue(mTracksInfo != null);
             Log.d(LOGTAG, "[CB][onDataArrived]");
+            mTracksInfo.onDataArrived(trackType);
             mResourceCallbacks.onDataArrived();
+            checkInitDone();
         }
 
         public void onVideoInputFormatChanged(Format format) {
             assertTrue(mTracksInfo != null);
             if (DEBUG) {
                 Log.d(LOGTAG, "[CB] onVideoInputFormatChanged [" + format + "]");
                 Log.d(LOGTAG, "[CB] SampleMIMEType [" +
                               format.sampleMimeType + "], ContainerMIMEType [" +
@@ -294,17 +306,17 @@ public class GeckoHlsPlayer implements E
         mDemuxerCallbacks = callback;
     }
 
     @Override
     public void onLoadingChanged(boolean isLoading) {
         if (DEBUG) { Log.d(LOGTAG, "loading [" + isLoading + "]"); }
         if (!isLoading) {
             // To update buffered position.
-            mComponentEventDispatcher.onDataArrived();
+            mComponentEventDispatcher.onDataArrived(C.TRACK_TYPE_DEFAULT);
         }
     }
 
     @Override
     public void onPlayerStateChanged(boolean playWhenReady, int state) {
         if (DEBUG) { Log.d(LOGTAG, "state [" + playWhenReady + ", " + getStateString(state) + "]"); }
         if (state == ExoPlayer.STATE_READY) {
             mPlayer.setPlayWhenReady(true);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsRendererBase.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsRendererBase.java
@@ -227,17 +227,17 @@ public abstract class GeckoHlsRendererBa
 
         maybeNotifyDataArrived();
         return true;
     }
 
     private void maybeNotifyDataArrived() {
         if (mWaitingForData && isQueuedEnoughData()) {
             if (DEBUG) { Log.d(LOGTAG, "onDataArrived"); }
-            mPlayerEventDispatcher.onDataArrived();
+            mPlayerEventDispatcher.onDataArrived(getTrackType());
             mWaitingForData = false;
         }
     }
 
     private void readFormat() {
         int result = readSource(mFormatHolder, null, true);
         if (result == C.RESULT_FORMAT_READ) {
             onInputFormatChanged(mFormatHolder.format);