mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make HlsMediaSource.Factory take a factory of trackers instead of an instance
This allows creating multiple HLS media sources from a single Factory, as required by the interface. Issue:#4814 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=213297850
This commit is contained in:
parent
b09e36dcb7
commit
c9e4f6b429
4 changed files with 34 additions and 32 deletions
|
|
@ -40,6 +40,8 @@
|
||||||
([#4422](https://github.com/google/ExoPlayer/issues/4422)).
|
([#4422](https://github.com/google/ExoPlayer/issues/4422)).
|
||||||
* Fix the bitrate being unset on primary track sample formats
|
* Fix the bitrate being unset on primary track sample formats
|
||||||
([#3297](https://github.com/google/ExoPlayer/issues/3297)).
|
([#3297](https://github.com/google/ExoPlayer/issues/3297)).
|
||||||
|
* Make `HlsMediaSource.Factory` take a factory of trackers instead of a
|
||||||
|
tracker instance ([#4814](https://github.com/google/ExoPlayer/issues/4814)).
|
||||||
* DASH:
|
* DASH:
|
||||||
* Support `messageData` attribute for in-manifest event streams.
|
* Support `messageData` attribute for in-manifest event streams.
|
||||||
* Clip periods to their specified durations
|
* Clip periods to their specified durations
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||||
private final HlsDataSourceFactory hlsDataSourceFactory;
|
private final HlsDataSourceFactory hlsDataSourceFactory;
|
||||||
|
|
||||||
private HlsExtractorFactory extractorFactory;
|
private HlsExtractorFactory extractorFactory;
|
||||||
private @Nullable HlsPlaylistParserFactory playlistParserFactory;
|
private HlsPlaylistParserFactory playlistParserFactory;
|
||||||
private @Nullable HlsPlaylistTracker playlistTracker;
|
private HlsPlaylistTracker.Factory playlistTrackerFactory;
|
||||||
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private boolean allowChunklessPreparation;
|
private boolean allowChunklessPreparation;
|
||||||
|
|
@ -90,6 +90,8 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||||
*/
|
*/
|
||||||
public Factory(HlsDataSourceFactory hlsDataSourceFactory) {
|
public Factory(HlsDataSourceFactory hlsDataSourceFactory) {
|
||||||
this.hlsDataSourceFactory = Assertions.checkNotNull(hlsDataSourceFactory);
|
this.hlsDataSourceFactory = Assertions.checkNotNull(hlsDataSourceFactory);
|
||||||
|
playlistParserFactory = new DefaultHlsPlaylistParserFactory();
|
||||||
|
playlistTrackerFactory = DefaultHlsPlaylistTracker.FACTORY;
|
||||||
extractorFactory = HlsExtractorFactory.DEFAULT;
|
extractorFactory = HlsExtractorFactory.DEFAULT;
|
||||||
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||||
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
||||||
|
|
@ -131,9 +133,6 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||||
*
|
*
|
||||||
* <p>Calling this method overrides any calls to {@link #setMinLoadableRetryCount(int)}.
|
* <p>Calling this method overrides any calls to {@link #setMinLoadableRetryCount(int)}.
|
||||||
*
|
*
|
||||||
* <p>If {@link #setPlaylistTracker} is not called on this builder, {@code
|
|
||||||
* loadErrorHandlingPolicy} is used for creating the used {@link DefaultHlsPlaylistTracker}.
|
|
||||||
*
|
|
||||||
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
|
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
|
||||||
* @return This factory, for convenience.
|
* @return This factory, for convenience.
|
||||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
||||||
|
|
@ -168,35 +167,27 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||||
* Sets the factory from which playlist parsers will be obtained. The default value is created
|
* Sets the factory from which playlist parsers will be obtained. The default value is created
|
||||||
* by calling {@link DefaultHlsPlaylistParserFactory#DefaultHlsPlaylistParserFactory()}.
|
* by calling {@link DefaultHlsPlaylistParserFactory#DefaultHlsPlaylistParserFactory()}.
|
||||||
*
|
*
|
||||||
* <p>Must not be called after calling {@link #setPlaylistTracker} on the same builder.
|
|
||||||
*
|
|
||||||
* @param playlistParserFactory An {@link HlsPlaylistParserFactory}.
|
* @param playlistParserFactory An {@link HlsPlaylistParserFactory}.
|
||||||
* @return This factory, for convenience.
|
* @return This factory, for convenience.
|
||||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
||||||
*/
|
*/
|
||||||
public Factory setPlaylistParserFactory(HlsPlaylistParserFactory playlistParserFactory) {
|
public Factory setPlaylistParserFactory(HlsPlaylistParserFactory playlistParserFactory) {
|
||||||
Assertions.checkState(!isCreateCalled);
|
Assertions.checkState(!isCreateCalled);
|
||||||
Assertions.checkState(playlistTracker == null, "A playlist tracker has already been set.");
|
|
||||||
this.playlistParserFactory = Assertions.checkNotNull(playlistParserFactory);
|
this.playlistParserFactory = Assertions.checkNotNull(playlistParserFactory);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the HLS playlist tracker. The default is an instance of {@link
|
* Sets the {@link HlsPlaylistTracker} factory. The default value is {@link
|
||||||
* DefaultHlsPlaylistTracker}. Playlist trackers must not be shared by {@link HlsMediaSource}
|
* DefaultHlsPlaylistTracker#FACTORY}.
|
||||||
* instances.
|
|
||||||
*
|
*
|
||||||
* <p>Must not be called after calling {@link #setPlaylistParserFactory} on the same builder.
|
* @param playlistTrackerFactory A factory for {@link HlsPlaylistTracker} instances.
|
||||||
*
|
|
||||||
* @param playlistTracker A tracker for HLS playlists.
|
|
||||||
* @return This factory, for convenience.
|
* @return This factory, for convenience.
|
||||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
||||||
*/
|
*/
|
||||||
public Factory setPlaylistTracker(HlsPlaylistTracker playlistTracker) {
|
public Factory setPlaylistTrackerFactory(HlsPlaylistTracker.Factory playlistTrackerFactory) {
|
||||||
Assertions.checkState(!isCreateCalled);
|
Assertions.checkState(!isCreateCalled);
|
||||||
Assertions.checkState(
|
this.playlistTrackerFactory = Assertions.checkNotNull(playlistTrackerFactory);
|
||||||
playlistParserFactory == null, "A playlist parser factory has already been set.");
|
|
||||||
this.playlistTracker = Assertions.checkNotNull(playlistTracker);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,26 +232,14 @@ public final class HlsMediaSource extends BaseMediaSource
|
||||||
@Override
|
@Override
|
||||||
public HlsMediaSource createMediaSource(Uri playlistUri) {
|
public HlsMediaSource createMediaSource(Uri playlistUri) {
|
||||||
isCreateCalled = true;
|
isCreateCalled = true;
|
||||||
if (playlistTracker == null) {
|
|
||||||
if (playlistParserFactory == null) {
|
|
||||||
playlistTracker =
|
|
||||||
new DefaultHlsPlaylistTracker(
|
|
||||||
hlsDataSourceFactory,
|
|
||||||
loadErrorHandlingPolicy,
|
|
||||||
new DefaultHlsPlaylistParserFactory());
|
|
||||||
} else {
|
|
||||||
playlistTracker =
|
|
||||||
new DefaultHlsPlaylistTracker(
|
|
||||||
hlsDataSourceFactory, loadErrorHandlingPolicy, playlistParserFactory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new HlsMediaSource(
|
return new HlsMediaSource(
|
||||||
playlistUri,
|
playlistUri,
|
||||||
hlsDataSourceFactory,
|
hlsDataSourceFactory,
|
||||||
extractorFactory,
|
extractorFactory,
|
||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
loadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
playlistTracker,
|
playlistTrackerFactory.createTracker(
|
||||||
|
hlsDataSourceFactory, loadErrorHandlingPolicy, playlistParserFactory),
|
||||||
allowChunklessPreparation,
|
allowChunklessPreparation,
|
||||||
tag);
|
tag);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ import java.util.List;
|
||||||
public final class DefaultHlsPlaylistTracker
|
public final class DefaultHlsPlaylistTracker
|
||||||
implements HlsPlaylistTracker, Loader.Callback<ParsingLoadable<HlsPlaylist>> {
|
implements HlsPlaylistTracker, Loader.Callback<ParsingLoadable<HlsPlaylist>> {
|
||||||
|
|
||||||
|
/** Factory for {@link DefaultHlsPlaylistTracker} instances. */
|
||||||
|
public static final Factory FACTORY = DefaultHlsPlaylistTracker::new;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coefficient applied on the target duration of a playlist to determine the amount of time after
|
* Coefficient applied on the target duration of a playlist to determine the amount of time after
|
||||||
* which an unchanging playlist is considered stuck.
|
* which an unchanging playlist is considered stuck.
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
|
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
|
||||||
|
import com.google.android.exoplayer2.source.hls.HlsDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl;
|
||||||
|
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,6 +38,22 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public interface HlsPlaylistTracker {
|
public interface HlsPlaylistTracker {
|
||||||
|
|
||||||
|
/** Factory for {@link HlsPlaylistTracker} instances. */
|
||||||
|
interface Factory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new tracker instance.
|
||||||
|
*
|
||||||
|
* @param dataSourceFactory The {@link HlsDataSourceFactory} to use for playlist loading.
|
||||||
|
* @param loadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy} for playlist load errors.
|
||||||
|
* @param playlistParserFactory The {@link HlsPlaylistParserFactory} for playlist parsing.
|
||||||
|
*/
|
||||||
|
HlsPlaylistTracker createTracker(
|
||||||
|
HlsDataSourceFactory dataSourceFactory,
|
||||||
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
|
HlsPlaylistParserFactory playlistParserFactory);
|
||||||
|
}
|
||||||
|
|
||||||
/** Listener for primary playlist changes. */
|
/** Listener for primary playlist changes. */
|
||||||
interface PrimaryPlaylistListener {
|
interface PrimaryPlaylistListener {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue