зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1619550 - p1: listen to media segment load event and pass the URL to resource wrapper. r=bryce,geckoview-reviewers,snorp
Differential Revision: https://phabricator.services.mozilla.com/D74989
This commit is contained in:
Родитель
48fdff53fc
Коммит
2be9f52cfa
|
@ -51,6 +51,7 @@ public interface BaseHlsPlayer {
|
|||
}
|
||||
|
||||
public interface ResourceCallbacks {
|
||||
void onLoad(String mediaUrl);
|
||||
void onDataArrived();
|
||||
void onError(int errorCode);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ public class GeckoHLSResourceWrapper {
|
|||
@WrapForJNI(calledFrom = "gecko")
|
||||
Callbacks() {}
|
||||
|
||||
@Override
|
||||
@WrapForJNI
|
||||
public native void onLoad(String mediaUrl);
|
||||
|
||||
@Override
|
||||
@WrapForJNI
|
||||
public native void onDataArrived();
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.mozilla.thirdparty.com.google.android.exoplayer2.Format;
|
|||
import org.mozilla.thirdparty.com.google.android.exoplayer2.PlaybackParameters;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.RendererCapabilities;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.Timeline;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.MediaSource;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.TrackGroup;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
|
@ -29,6 +30,7 @@ import org.mozilla.thirdparty.com.google.android.exoplayer2.trackselection.Mappi
|
|||
import org.mozilla.thirdparty.com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.upstream.DataSource;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.upstream.DataSpec;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.upstream.DefaultAllocator;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import org.mozilla.thirdparty.com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
|
@ -42,6 +44,7 @@ import org.mozilla.gecko.GeckoAppShell;
|
|||
import org.mozilla.gecko.annotation.ReflectionTarget;
|
||||
import org.mozilla.geckoview.BuildConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
@ -83,6 +86,7 @@ public class GeckoHlsPlayer implements BaseHlsPlayer, ExoPlayer.EventListener {
|
|||
private GeckoHlsRendererBase[] mRenderers;
|
||||
private DefaultTrackSelector mTrackSelector;
|
||||
private MediaSource mMediaSource;
|
||||
private SourceEventListener mSourceEventListener;
|
||||
private ComponentListener mComponentListener;
|
||||
private ComponentEventDispatcher mComponentEventDispatcher;
|
||||
|
||||
|
@ -198,6 +202,79 @@ public class GeckoHlsPlayer implements BaseHlsPlayer, ExoPlayer.EventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private final class SourceEventListener implements AdaptiveMediaSourceEventListener {
|
||||
public void onLoadStarted(final DataSpec dataSpec,
|
||||
final int dataType,
|
||||
final int trackType,
|
||||
final Format trackFormat,
|
||||
final int trackSelectionReason,
|
||||
final Object trackSelectionData,
|
||||
final long mediaStartTimeMs,
|
||||
final long mediaEndTimeMs,
|
||||
final long elapsedRealtimeMs) {
|
||||
if (mMainHandler != null && mResourceCallbacks != null) {
|
||||
mMainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (DEBUG) {
|
||||
Log.d(LOGTAG, "[SourceEvent] load-started: url=" + dataSpec.uri + " track=" + trackType + " format=" + trackFormat);
|
||||
}
|
||||
mResourceCallbacks.onLoad(dataSpec.uri.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// Not interested in the following events.
|
||||
public void onLoadCompleted(final DataSpec dataSpec,
|
||||
final int dataType,
|
||||
final int trackType,
|
||||
final Format trackFormat,
|
||||
final int trackSelectionReason,
|
||||
final Object trackSelectionData,
|
||||
final long mediaStartTimeMs,
|
||||
final long mediaEndTimeMs,
|
||||
final long elapsedRealtimeMs,
|
||||
final long loadDurationMs,
|
||||
final long bytesLoaded) {
|
||||
}
|
||||
public void onLoadCanceled(final DataSpec dataSpec,
|
||||
final int dataType,
|
||||
final int trackType,
|
||||
final Format trackFormat,
|
||||
final int trackSelectionReason,
|
||||
final Object trackSelectionData,
|
||||
final long mediaStartTimeMs,
|
||||
final long mediaEndTimeMs,
|
||||
final long elapsedRealtimeMs,
|
||||
final long loadDurationMs,
|
||||
final long bytesLoaded) {
|
||||
}
|
||||
public void onLoadError(final DataSpec dataSpec,
|
||||
final int dataType,
|
||||
final int trackType,
|
||||
final Format trackFormat,
|
||||
final int trackSelectionReason,
|
||||
final Object trackSelectionData,
|
||||
final long mediaStartTimeMs,
|
||||
final long mediaEndTimeMs,
|
||||
final long elapsedRealtimeMs,
|
||||
final long loadDurationMs,
|
||||
final long bytesLoaded,
|
||||
final IOException error,
|
||||
final boolean wasCanceled) {
|
||||
}
|
||||
public void onUpstreamDiscarded(final int trackType,
|
||||
final long mediaStartTimeMs,
|
||||
final long mediaEndTimeMs) {
|
||||
}
|
||||
public void onDownstreamFormatChanged(final int trackType,
|
||||
final Format trackFormat,
|
||||
final int trackSelectionReason,
|
||||
final Object trackSelectionData,
|
||||
final long mediaTimeMs) {
|
||||
}
|
||||
}
|
||||
|
||||
public final class ComponentEventDispatcher {
|
||||
// Called on GeckoHlsPlayerThread from GeckoHls{Audio,Video}Renderer/ExoPlayer
|
||||
public void onDataArrived(final int trackType) {
|
||||
|
@ -621,7 +698,8 @@ public class GeckoHlsPlayer implements BaseHlsPlayer, ExoPlayer.EventListener {
|
|||
|
||||
Uri uri = Uri.parse(url);
|
||||
mMediaDataSourceFactory = buildDataSourceFactory(ctx, BANDWIDTH_METER);
|
||||
mMediaSource = new HlsMediaSource(uri, mMediaDataSourceFactory, mMainHandler, null);
|
||||
mSourceEventListener = new SourceEventListener();
|
||||
mMediaSource = new HlsMediaSource(uri, mMediaDataSourceFactory, mMainHandler, mSourceEventListener);
|
||||
if (DEBUG) {
|
||||
Log.d(LOGTAG, "Uri is " + uri +
|
||||
", ContentType is " + Util.inferContentType(uri.getLastPathSegment()));
|
||||
|
|
Загрузка…
Ссылка в новой задаче