Bug 1379056 - GeckoHlsPlayer should handle the case when obtain a negative duration from ExoPlayer. r=JamesCheng
authorKilik Kuo <kikuo@mozilla.com>
Fri, 07 Jul 2017 13:00:06 +0800
changeset 367822 e8851a94e09f22aa6e03101d9e40019c555f9a13
parent 367821 ce6e74eb7da1faa7462280f4e9b43cdf02fa78ec
child 367823 603eec06815dff85d97c3577020d39eb38850b45
push id32147
push userkwierso@gmail.com
push dateSat, 08 Jul 2017 00:22:09 +0000
treeherdermozilla-central@06c1a0dc0fd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamesCheng
bugs1379056
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 1379056 - GeckoHlsPlayer should handle the case when obtain a negative duration from ExoPlayer. r=JamesCheng We might get a negative duration from ExoPlayer if it's unknown at that time, Setting it to 0 to align the default duration value in VideoInfo/AudioInfo. MozReview-Commit-ID: qASyfKJPzY
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/BaseHlsPlayer.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsPlayer.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/BaseHlsPlayer.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/BaseHlsPlayer.java
@@ -69,18 +69,16 @@ public interface BaseHlsPlayer {
 
     // =======================================================================
     // API for GeckoHLSDemuxerWrapper
     // =======================================================================
     public void addDemuxerWrapperCallbackListener(DemuxerCallbacks callback);
 
     public ConcurrentLinkedQueue<GeckoHLSSample> getSamples(TrackType trackType, int number);
 
-    public long getDuration();
-
     public long getBufferedPosition();
 
     public int getNumberOfTracks(TrackType trackType);
 
     public GeckoVideoInfo getVideoInfo(int index);
 
     public GeckoAudioInfo getAudioInfo(int index);
 
--- 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
@@ -255,16 +255,27 @@ public class GeckoHlsPlayer implements B
             AppConstants.USER_AGENT_FENNEC_MOBILE,
             bandwidthMeter /* listener */,
             DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
             DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
             true /* allowCrossProtocolRedirects */
         );
     }
 
+    private long getDuration() {
+        assertTrue(mPlayer != null);
+        if (isLiveStream()) {
+            return 0L;
+        }
+        // Value returned by getDuration() is in milliseconds.
+        long duration = Math.max(0L, mPlayer.getDuration() * 1000L);
+        if (DEBUG) { Log.d(LOGTAG, "getDuration : " + duration  + "(Us)"); }
+        return duration;
+    }
+
     // To make sure that each player has a unique id, GeckoHlsPlayer should be
     // created only from synchronized APIs in GeckoPlayerFactory.
     public GeckoHlsPlayer() {
         mPlayerId = sPlayerId.incrementAndGet();
         if (DEBUG) { Log.d(LOGTAG, " construct player with id(" + mPlayerId + ")"); }
     }
 
     // Should be only called by GeckoPlayerFactory and GeckoHLSResourceWrapper.
@@ -562,28 +573,16 @@ public class GeckoHlsPlayer implements B
             return mARenderer != null ? mARenderer.getQueuedSamples(number) :
                                         new ConcurrentLinkedQueue<GeckoHLSSample>();
         } else {
             return new ConcurrentLinkedQueue<GeckoHLSSample>();
         }
     }
 
     @Override
-    public long getDuration() {
-        assertTrue(mPlayer != null);
-        if (isLiveStream()) {
-            return 0L;
-        }
-        // Value returned by getDuration() is in milliseconds.
-        long duration = mPlayer.getDuration() * 1000;
-        if (DEBUG) { Log.d(LOGTAG, "getDuration : " + duration  + "(Us)"); }
-        return duration;
-    }
-
-    @Override
     public long getBufferedPosition() {
         assertTrue(mPlayer != null);
         // Value returned by getBufferedPosition() is in milliseconds.
         long bufferedPos = Math.max(0L, mPlayer.getBufferedPosition() * 1000L);
         if (DEBUG) { Log.d(LOGTAG, "getBufferedPosition : " + bufferedPos + "(Us)"); }
         return bufferedPos;
     }