mirror of
https://github.com/androidx/media.git
synced 2025-05-08 08:00:49 +08:00
Remove minLoadableRetryCount from HLS components
Remove minLoadableRetryCount from HLS components in favor of LoadErrorHandlingPolicy#getMinimumLoadableRetryCount. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=206298419
This commit is contained in:
parent
877837c893
commit
4eee474555
@ -488,32 +488,24 @@ public final class C {
|
|||||||
*/
|
*/
|
||||||
public static final int RESULT_FORMAT_READ = -5;
|
public static final int RESULT_FORMAT_READ = -5;
|
||||||
|
|
||||||
/**
|
/** A data type constant for data of unknown or unspecified type. */
|
||||||
* A data type constant for data of unknown or unspecified type.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_UNKNOWN = 0;
|
public static final int DATA_TYPE_UNKNOWN = 0;
|
||||||
/**
|
/** A data type constant for media, typically containing media samples. */
|
||||||
* A data type constant for media, typically containing media samples.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_MEDIA = 1;
|
public static final int DATA_TYPE_MEDIA = 1;
|
||||||
/**
|
/** A data type constant for media, typically containing only initialization data. */
|
||||||
* A data type constant for media, typically containing only initialization data.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_MEDIA_INITIALIZATION = 2;
|
public static final int DATA_TYPE_MEDIA_INITIALIZATION = 2;
|
||||||
/**
|
/** A data type constant for drm or encryption data. */
|
||||||
* A data type constant for drm or encryption data.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_DRM = 3;
|
public static final int DATA_TYPE_DRM = 3;
|
||||||
/**
|
/** A data type constant for a manifest file. */
|
||||||
* A data type constant for a manifest file.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_MANIFEST = 4;
|
public static final int DATA_TYPE_MANIFEST = 4;
|
||||||
/**
|
/** A data type constant for time synchronization data. */
|
||||||
* A data type constant for time synchronization data.
|
|
||||||
*/
|
|
||||||
public static final int DATA_TYPE_TIME_SYNCHRONIZATION = 5;
|
public static final int DATA_TYPE_TIME_SYNCHRONIZATION = 5;
|
||||||
/** A data type constant for ads loader data. */
|
/** A data type constant for ads loader data. */
|
||||||
public static final int DATA_TYPE_AD = 6;
|
public static final int DATA_TYPE_AD = 6;
|
||||||
|
/**
|
||||||
|
* A data type constant for progressive media live streams, typically containing media samples.
|
||||||
|
*/
|
||||||
|
public static final int DATA_TYPE_MEDIA_LIVE_STREAM = 7;
|
||||||
/**
|
/**
|
||||||
* Applications or extensions may define custom {@code DATA_TYPE_*} constants greater than or
|
* Applications or extensions may define custom {@code DATA_TYPE_*} constants greater than or
|
||||||
* equal to this value.
|
* equal to this value.
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.ParserException;
|
||||||
|
import com.google.android.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil;
|
||||||
|
import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/** Default implementation of {@link LoadErrorHandlingPolicy}. */
|
||||||
|
public final class DefaultLoadErrorHandlingPolicy implements LoadErrorHandlingPolicy {
|
||||||
|
|
||||||
|
/** The default minimum number of times to retry loading data prior to propagating the error. */
|
||||||
|
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
||||||
|
|
||||||
|
private final int minimumLoadableRetryCount;
|
||||||
|
|
||||||
|
/** Creates an instance that returns the default values. */
|
||||||
|
public DefaultLoadErrorHandlingPolicy() {
|
||||||
|
this(DEFAULT_MIN_LOADABLE_RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance with the given value for {@link #getMinimumLoadableRetryCount(int)}.
|
||||||
|
*
|
||||||
|
* @param minimumLoadableRetryCount See {@link #getMinimumLoadableRetryCount}.
|
||||||
|
*/
|
||||||
|
public DefaultLoadErrorHandlingPolicy(int minimumLoadableRetryCount) {
|
||||||
|
this.minimumLoadableRetryCount = minimumLoadableRetryCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blacklists resources whose load error was an {@link InvalidResponseCodeException} with response
|
||||||
|
* code HTTP 404 or 410. The duration of the blacklisting is {@link
|
||||||
|
* ChunkedTrackBlacklistUtil#DEFAULT_TRACK_BLACKLIST_MS}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long getBlacklistDurationMsFor(
|
||||||
|
int dataType, long loadDurationMs, IOException exception, int errorCount) {
|
||||||
|
if (exception instanceof InvalidResponseCodeException) {
|
||||||
|
int responseCode = ((InvalidResponseCodeException) exception).responseCode;
|
||||||
|
return responseCode == 404 // HTTP 404 Not Found.
|
||||||
|
|| responseCode == 410 // HTTP 410 Gone.
|
||||||
|
? ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS
|
||||||
|
: C.TIME_UNSET;
|
||||||
|
}
|
||||||
|
return C.TIME_UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retries for any exception that is not a subclass of {@link ParserException}. The retry delay is
|
||||||
|
* calculated as {@code Math.min((errorCount - 1) * 1000, 5000)}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long getRetryDelayMsFor(
|
||||||
|
int dataType, long loadDurationMs, IOException exception, int errorCount) {
|
||||||
|
return exception instanceof ParserException
|
||||||
|
? C.TIME_UNSET
|
||||||
|
: Math.min((errorCount - 1) * 1000, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns {@link #DEFAULT_MIN_LOADABLE_RETRY_COUNT}. */
|
||||||
|
@Override
|
||||||
|
public int getMinimumLoadableRetryCount(int dataType) {
|
||||||
|
return minimumLoadableRetryCount;
|
||||||
|
}
|
||||||
|
}
|
@ -16,9 +16,6 @@
|
|||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ParserException;
|
|
||||||
import com.google.android.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil;
|
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException;
|
|
||||||
import com.google.android.exoplayer2.upstream.Loader.Callback;
|
import com.google.android.exoplayer2.upstream.Loader.Callback;
|
||||||
import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
import com.google.android.exoplayer2.upstream.Loader.Loadable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -29,74 +26,22 @@ import java.io.IOException;
|
|||||||
* <p>Loader clients may blacklist a resource when a load error occurs. Blacklisting works around
|
* <p>Loader clients may blacklist a resource when a load error occurs. Blacklisting works around
|
||||||
* load errors by loading an alternative resource. Clients do not try blacklisting when a resource
|
* load errors by loading an alternative resource. Clients do not try blacklisting when a resource
|
||||||
* does not have an alternative. When a resource does have valid alternatives, {@link
|
* does not have an alternative. When a resource does have valid alternatives, {@link
|
||||||
* #getBlacklistDurationMsFor(T, long, IOException, int)} defines whether the resource should be
|
* #getBlacklistDurationMsFor(int, long, IOException, int)} defines whether the resource should be
|
||||||
* blacklisted. Blacklisting will succeed if any of the alternatives is not in the black list.
|
* blacklisted. Blacklisting will succeed if any of the alternatives is not in the black list.
|
||||||
*
|
*
|
||||||
* <p>When blacklisting does not take place, {@link #getRetryDelayMsFor(T, long, IOException, int)}
|
* <p>When blacklisting does not take place, {@link #getRetryDelayMsFor(int, long, IOException,
|
||||||
* defines whether the load is retried. Errors whose load is not retried are propagated. Load errors
|
* int)} defines whether the load is retried. Errors whose load is not retried are propagated. Load
|
||||||
* whose load is retried are propagated according to {@link
|
* errors whose load is retried are propagated according to {@link
|
||||||
* #getMinimumLoadableRetryCount(Loadable)}.
|
* #getMinimumLoadableRetryCount(int)}.
|
||||||
*
|
|
||||||
* @param <T> The type of the object being loaded.
|
|
||||||
*/
|
*/
|
||||||
public interface LoadErrorHandlingPolicy<T extends Loadable> {
|
public interface LoadErrorHandlingPolicy {
|
||||||
|
|
||||||
/** The default minimum number of times to retry loading data prior to propagating the error. */
|
|
||||||
int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
|
||||||
|
|
||||||
/** Default implementation of {@link LoadErrorHandlingPolicy}. */
|
|
||||||
LoadErrorHandlingPolicy<Loadable> DEFAULT =
|
|
||||||
new LoadErrorHandlingPolicy<Loadable>() {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blacklists resources whose load error was an {@link InvalidResponseCodeException} with
|
|
||||||
* response code HTTP 404 or 410. The duration of the blacklisting is {@link
|
|
||||||
* ChunkedTrackBlacklistUtil#DEFAULT_TRACK_BLACKLIST_MS}.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long getBlacklistDurationMsFor(
|
|
||||||
Loadable loadable, long loadDurationMs, IOException exception, int errorCount) {
|
|
||||||
if (exception instanceof InvalidResponseCodeException) {
|
|
||||||
int responseCode = ((InvalidResponseCodeException) exception).responseCode;
|
|
||||||
return responseCode == 404 // HTTP 404 Not Found.
|
|
||||||
|| responseCode == 410 // HTTP 410 Gone.
|
|
||||||
? ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS
|
|
||||||
: C.TIME_UNSET;
|
|
||||||
}
|
|
||||||
return C.TIME_UNSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries for any exception that is not a subclass of {@link ParserException}. The retry
|
|
||||||
* delay is calculated as {@code Math.min((errorCount - 1) * 1000, 5000)}.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long getRetryDelayMsFor(
|
|
||||||
Loadable loadable, long loadDurationMs, IOException exception, int errorCount) {
|
|
||||||
return exception instanceof ParserException
|
|
||||||
? C.TIME_UNSET
|
|
||||||
: Math.min((errorCount - 1) * 1000, 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns {@link #DEFAULT_MIN_LOADABLE_RETRY_COUNT}. */
|
|
||||||
@Override
|
|
||||||
public int getMinimumLoadableRetryCount(Loadable loadable) {
|
|
||||||
return DEFAULT_MIN_LOADABLE_RETRY_COUNT;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Returns {@link #DEFAULT}. */
|
|
||||||
static <U extends Loadable> LoadErrorHandlingPolicy<U> getDefault() {
|
|
||||||
@SuppressWarnings("unchecked") // Safe contravariant cast.
|
|
||||||
LoadErrorHandlingPolicy<U> policy = (LoadErrorHandlingPolicy<U>) DEFAULT;
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of milliseconds for which a resource associated to a provided load error
|
* Returns the number of milliseconds for which a resource associated to a provided load error
|
||||||
* should be blacklisted, or {@link C#TIME_UNSET} if the resource should not be blacklisted.
|
* should be blacklisted, or {@link C#TIME_UNSET} if the resource should not be blacklisted.
|
||||||
*
|
*
|
||||||
* @param loadable The loadable whose load failed.
|
* @param dataType One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to
|
||||||
|
* load.
|
||||||
* @param loadDurationMs The duration in milliseconds of the load up to the point at which the
|
* @param loadDurationMs The duration in milliseconds of the load up to the point at which the
|
||||||
* error occurred, including any previous attempts.
|
* error occurred, including any previous attempts.
|
||||||
* @param exception The load error.
|
* @param exception The load error.
|
||||||
@ -105,7 +50,7 @@ public interface LoadErrorHandlingPolicy<T extends Loadable> {
|
|||||||
* not be blacklisted.
|
* not be blacklisted.
|
||||||
*/
|
*/
|
||||||
long getBlacklistDurationMsFor(
|
long getBlacklistDurationMsFor(
|
||||||
T loadable, long loadDurationMs, IOException exception, int errorCount);
|
int dataType, long loadDurationMs, IOException exception, int errorCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of milliseconds to wait before attempting the load again, or {@link
|
* Returns the number of milliseconds to wait before attempting the load again, or {@link
|
||||||
@ -115,7 +60,8 @@ public interface LoadErrorHandlingPolicy<T extends Loadable> {
|
|||||||
* for a specific event before retrying. However, the load is retried if and only if this method
|
* for a specific event before retrying. However, the load is retried if and only if this method
|
||||||
* does not return {@link C#TIME_UNSET}.
|
* does not return {@link C#TIME_UNSET}.
|
||||||
*
|
*
|
||||||
* @param loadable The loadable whose load failed.
|
* @param dataType One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to
|
||||||
|
* load.
|
||||||
* @param loadDurationMs The duration in milliseconds of the load up to the point at which the
|
* @param loadDurationMs The duration in milliseconds of the load up to the point at which the
|
||||||
* error occurred, including any previous attempts.
|
* error occurred, including any previous attempts.
|
||||||
* @param exception The load error.
|
* @param exception The load error.
|
||||||
@ -123,16 +69,17 @@ public interface LoadErrorHandlingPolicy<T extends Loadable> {
|
|||||||
* @return The number of milliseconds to wait before attempting the load again, or {@link
|
* @return The number of milliseconds to wait before attempting the load again, or {@link
|
||||||
* C#TIME_UNSET} if the error is fatal and should not be retried.
|
* C#TIME_UNSET} if the error is fatal and should not be retried.
|
||||||
*/
|
*/
|
||||||
long getRetryDelayMsFor(T loadable, long loadDurationMs, IOException exception, int errorCount);
|
long getRetryDelayMsFor(int dataType, long loadDurationMs, IOException exception, int errorCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the minimum number of times to retry a load in the case of a load error, before
|
* Returns the minimum number of times to retry a load in the case of a load error, before
|
||||||
* propagating the error.
|
* propagating the error.
|
||||||
*
|
*
|
||||||
* @param loadable The loadable to load.
|
* @param dataType One of the {@link C C.DATA_TYPE_*} constants indicating the type of data to
|
||||||
|
* load.
|
||||||
* @return The minimum number of times to retry a load in the case of a load error, before
|
* @return The minimum number of times to retry a load in the case of a load error, before
|
||||||
* propagating the error.
|
* propagating the error.
|
||||||
* @see Loader#startLoading(Loadable, Callback, int)
|
* @see Loader#startLoading(Loadable, Callback, int)
|
||||||
*/
|
*/
|
||||||
int getMinimumLoadableRetryCount(T loadable);
|
int getMinimumLoadableRetryCount(int dataType);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
/** Unit tests for {@link LoadErrorHandlingPolicy#DEFAULT}. */
|
/** Unit tests for {@link DefaultLoadErrorHandlingPolicy}. */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public final class DefaultLoadErrorHandlingPolicyTest {
|
public final class DefaultLoadErrorHandlingPolicyTest {
|
||||||
|
|
||||||
@ -90,12 +90,13 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static long getDefaultPolicyBlacklistOutputFor(IOException exception) {
|
private static long getDefaultPolicyBlacklistOutputFor(IOException exception) {
|
||||||
return LoadErrorHandlingPolicy.DEFAULT.getBlacklistDurationMsFor(
|
return new DefaultLoadErrorHandlingPolicy()
|
||||||
DUMMY_LOADABLE, /* loadDurationMs= */ 1000, exception, /* errorCount= */ 1);
|
.getBlacklistDurationMsFor(
|
||||||
|
C.DATA_TYPE_MEDIA, /* loadDurationMs= */ 1000, exception, /* errorCount= */ 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getDefaultPolicyRetryDelayOutputFor(IOException exception, int errorCount) {
|
private static long getDefaultPolicyRetryDelayOutputFor(IOException exception, int errorCount) {
|
||||||
return LoadErrorHandlingPolicy.DEFAULT.getRetryDelayMsFor(
|
return new DefaultLoadErrorHandlingPolicy()
|
||||||
DUMMY_LOADABLE, /* loadDurationMs= */ 1000, exception, errorCount);
|
.getRetryDelayMsFor(C.DATA_TYPE_MEDIA, /* loadDurationMs= */ 1000, exception, errorCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import com.google.android.exoplayer2.source.SampleStream;
|
|||||||
import com.google.android.exoplayer2.source.SequenceableLoader;
|
import com.google.android.exoplayer2.source.SequenceableLoader;
|
||||||
import com.google.android.exoplayer2.source.TrackGroup;
|
import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.source.chunk.Chunk;
|
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist;
|
||||||
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.source.hls.playlist.HlsPlaylistTracker;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker;
|
||||||
@ -56,8 +55,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
private final HlsPlaylistTracker playlistTracker;
|
private final HlsPlaylistTracker playlistTracker;
|
||||||
private final HlsDataSourceFactory dataSourceFactory;
|
private final HlsDataSourceFactory dataSourceFactory;
|
||||||
private final @Nullable TransferListener mediaTransferListener;
|
private final @Nullable TransferListener mediaTransferListener;
|
||||||
private final LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy;
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private final int minLoadableRetryCount;
|
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final Allocator allocator;
|
private final Allocator allocator;
|
||||||
private final IdentityHashMap<SampleStream, Integer> streamWrapperIndices;
|
private final IdentityHashMap<SampleStream, Integer> streamWrapperIndices;
|
||||||
@ -82,8 +80,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
* and keys.
|
* and keys.
|
||||||
* @param mediaTransferListener The transfer listener to inform of any media data transfers. May
|
* @param mediaTransferListener The transfer listener to inform of any media data transfers. May
|
||||||
* be null if no listener is available.
|
* be null if no listener is available.
|
||||||
* @param chunkLoadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy} for chunk loads.
|
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
|
||||||
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
|
|
||||||
* @param eventDispatcher A dispatcher to notify of events.
|
* @param eventDispatcher A dispatcher to notify of events.
|
||||||
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
||||||
* @param compositeSequenceableLoaderFactory A factory to create composite {@link
|
* @param compositeSequenceableLoaderFactory A factory to create composite {@link
|
||||||
@ -95,8 +92,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
HlsPlaylistTracker playlistTracker,
|
HlsPlaylistTracker playlistTracker,
|
||||||
HlsDataSourceFactory dataSourceFactory,
|
HlsDataSourceFactory dataSourceFactory,
|
||||||
@Nullable TransferListener mediaTransferListener,
|
@Nullable TransferListener mediaTransferListener,
|
||||||
LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
int minLoadableRetryCount,
|
|
||||||
EventDispatcher eventDispatcher,
|
EventDispatcher eventDispatcher,
|
||||||
Allocator allocator,
|
Allocator allocator,
|
||||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||||
@ -105,8 +101,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
this.playlistTracker = playlistTracker;
|
this.playlistTracker = playlistTracker;
|
||||||
this.dataSourceFactory = dataSourceFactory;
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
this.mediaTransferListener = mediaTransferListener;
|
this.mediaTransferListener = mediaTransferListener;
|
||||||
this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.allocator = allocator;
|
this.allocator = allocator;
|
||||||
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
||||||
@ -532,8 +527,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
allocator,
|
allocator,
|
||||||
positionUs,
|
positionUs,
|
||||||
muxedAudioFormat,
|
muxedAudioFormat,
|
||||||
chunkLoadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
minLoadableRetryCount,
|
|
||||||
eventDispatcher);
|
eventDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispat
|
|||||||
import com.google.android.exoplayer2.source.SequenceableLoader;
|
import com.google.android.exoplayer2.source.SequenceableLoader;
|
||||||
import com.google.android.exoplayer2.source.SinglePeriodTimeline;
|
import com.google.android.exoplayer2.source.SinglePeriodTimeline;
|
||||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
||||||
import com.google.android.exoplayer2.source.chunk.Chunk;
|
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistTracker;
|
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistTracker;
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist;
|
||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist;
|
||||||
@ -40,6 +39,7 @@ import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser;
|
|||||||
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker;
|
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker;
|
||||||
import com.google.android.exoplayer2.upstream.Allocator;
|
import com.google.android.exoplayer2.upstream.Allocator;
|
||||||
import com.google.android.exoplayer2.upstream.DataSource;
|
import com.google.android.exoplayer2.upstream.DataSource;
|
||||||
|
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
|
||||||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
@ -64,8 +64,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
private @Nullable ParsingLoadable.Parser<HlsPlaylist> playlistParser;
|
private @Nullable ParsingLoadable.Parser<HlsPlaylist> playlistParser;
|
||||||
private @Nullable HlsPlaylistTracker playlistTracker;
|
private @Nullable HlsPlaylistTracker playlistTracker;
|
||||||
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy;
|
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private int minLoadableRetryCount;
|
|
||||||
private boolean allowChunklessPreparation;
|
private boolean allowChunklessPreparation;
|
||||||
private boolean isCreateCalled;
|
private boolean isCreateCalled;
|
||||||
private @Nullable Object tag;
|
private @Nullable Object tag;
|
||||||
@ -90,8 +89,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
public Factory(HlsDataSourceFactory hlsDataSourceFactory) {
|
public Factory(HlsDataSourceFactory hlsDataSourceFactory) {
|
||||||
this.hlsDataSourceFactory = Assertions.checkNotNull(hlsDataSourceFactory);
|
this.hlsDataSourceFactory = Assertions.checkNotNull(hlsDataSourceFactory);
|
||||||
extractorFactory = HlsExtractorFactory.DEFAULT;
|
extractorFactory = HlsExtractorFactory.DEFAULT;
|
||||||
chunkLoadErrorHandlingPolicy = LoadErrorHandlingPolicy.getDefault();
|
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||||
minLoadableRetryCount = DEFAULT_MIN_LOADABLE_RETRY_COUNT;
|
|
||||||
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,31 +124,41 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link LoadErrorHandlingPolicy} for chunk loads. The default value is {@link
|
* Sets the {@link LoadErrorHandlingPolicy}. The default value is created by calling {@link
|
||||||
* LoadErrorHandlingPolicy#DEFAULT}.
|
* DefaultLoadErrorHandlingPolicy()}.
|
||||||
*
|
*
|
||||||
* @param chunkLoadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy} for chunk loads.
|
* <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}.
|
||||||
* @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 setChunkLoadErrorHandlingPolicy(
|
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
|
||||||
LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy) {
|
|
||||||
Assertions.checkState(!isCreateCalled);
|
Assertions.checkState(!isCreateCalled);
|
||||||
this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the minimum number of times to retry if a loading error occurs. The default value is
|
* Sets the minimum number of times to retry if a loading error occurs. The default value is
|
||||||
* {@link #DEFAULT_MIN_LOADABLE_RETRY_COUNT}.
|
* {@link DefaultLoadErrorHandlingPolicy#DEFAULT_MIN_LOADABLE_RETRY_COUNT}.
|
||||||
|
*
|
||||||
|
* <p>Calling this method is equivalent to calling {@link #setLoadErrorHandlingPolicy} with
|
||||||
|
* {@link DefaultLoadErrorHandlingPolicy(int)
|
||||||
|
* DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)}
|
||||||
*
|
*
|
||||||
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
|
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
|
||||||
* @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.
|
||||||
|
* @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Factory setMinLoadableRetryCount(int minLoadableRetryCount) {
|
public Factory setMinLoadableRetryCount(int minLoadableRetryCount) {
|
||||||
Assertions.checkState(!isCreateCalled);
|
Assertions.checkState(!isCreateCalled);
|
||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
this.loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,8 +242,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
playlistTracker =
|
playlistTracker =
|
||||||
new DefaultHlsPlaylistTracker(
|
new DefaultHlsPlaylistTracker(
|
||||||
hlsDataSourceFactory,
|
hlsDataSourceFactory,
|
||||||
LoadErrorHandlingPolicy.getDefault(),
|
loadErrorHandlingPolicy,
|
||||||
minLoadableRetryCount,
|
|
||||||
playlistParser != null ? playlistParser : new HlsPlaylistParser());
|
playlistParser != null ? playlistParser : new HlsPlaylistParser());
|
||||||
}
|
}
|
||||||
return new HlsMediaSource(
|
return new HlsMediaSource(
|
||||||
@ -243,8 +250,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
hlsDataSourceFactory,
|
hlsDataSourceFactory,
|
||||||
extractorFactory,
|
extractorFactory,
|
||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
chunkLoadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
minLoadableRetryCount,
|
|
||||||
playlistTracker,
|
playlistTracker,
|
||||||
allowChunklessPreparation,
|
allowChunklessPreparation,
|
||||||
tag);
|
tag);
|
||||||
@ -270,19 +276,14 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
public int[] getSupportedTypes() {
|
public int[] getSupportedTypes() {
|
||||||
return new int[] {C.TYPE_HLS};
|
return new int[] {C.TYPE_HLS};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* The default minimum number of times to retry loading data prior to failing.
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
|
||||||
|
|
||||||
private final HlsExtractorFactory extractorFactory;
|
private final HlsExtractorFactory extractorFactory;
|
||||||
private final Uri manifestUri;
|
private final Uri manifestUri;
|
||||||
private final HlsDataSourceFactory dataSourceFactory;
|
private final HlsDataSourceFactory dataSourceFactory;
|
||||||
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private final LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy;
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private final int minLoadableRetryCount;
|
|
||||||
private final boolean allowChunklessPreparation;
|
private final boolean allowChunklessPreparation;
|
||||||
private final HlsPlaylistTracker playlistTracker;
|
private final HlsPlaylistTracker playlistTracker;
|
||||||
private final @Nullable Object tag;
|
private final @Nullable Object tag;
|
||||||
@ -304,7 +305,11 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
DataSource.Factory dataSourceFactory,
|
DataSource.Factory dataSourceFactory,
|
||||||
Handler eventHandler,
|
Handler eventHandler,
|
||||||
MediaSourceEventListener eventListener) {
|
MediaSourceEventListener eventListener) {
|
||||||
this(manifestUri, dataSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler,
|
this(
|
||||||
|
manifestUri,
|
||||||
|
dataSourceFactory,
|
||||||
|
DefaultLoadErrorHandlingPolicy.DEFAULT_MIN_LOADABLE_RETRY_COUNT,
|
||||||
|
eventHandler,
|
||||||
eventListener);
|
eventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,12 +368,10 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
dataSourceFactory,
|
dataSourceFactory,
|
||||||
extractorFactory,
|
extractorFactory,
|
||||||
new DefaultCompositeSequenceableLoaderFactory(),
|
new DefaultCompositeSequenceableLoaderFactory(),
|
||||||
LoadErrorHandlingPolicy.getDefault(),
|
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
||||||
minLoadableRetryCount,
|
|
||||||
new DefaultHlsPlaylistTracker(
|
new DefaultHlsPlaylistTracker(
|
||||||
dataSourceFactory,
|
dataSourceFactory,
|
||||||
LoadErrorHandlingPolicy.getDefault(),
|
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
||||||
minLoadableRetryCount,
|
|
||||||
playlistParser),
|
playlistParser),
|
||||||
/* allowChunklessPreparation= */ false,
|
/* allowChunklessPreparation= */ false,
|
||||||
/* tag= */ null);
|
/* tag= */ null);
|
||||||
@ -382,8 +385,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
HlsDataSourceFactory dataSourceFactory,
|
HlsDataSourceFactory dataSourceFactory,
|
||||||
HlsExtractorFactory extractorFactory,
|
HlsExtractorFactory extractorFactory,
|
||||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||||
LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
int minLoadableRetryCount,
|
|
||||||
HlsPlaylistTracker playlistTracker,
|
HlsPlaylistTracker playlistTracker,
|
||||||
boolean allowChunklessPreparation,
|
boolean allowChunklessPreparation,
|
||||||
@Nullable Object tag) {
|
@Nullable Object tag) {
|
||||||
@ -391,8 +393,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
this.dataSourceFactory = dataSourceFactory;
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
this.extractorFactory = extractorFactory;
|
this.extractorFactory = extractorFactory;
|
||||||
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
||||||
this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
|
||||||
this.playlistTracker = playlistTracker;
|
this.playlistTracker = playlistTracker;
|
||||||
this.allowChunklessPreparation = allowChunklessPreparation;
|
this.allowChunklessPreparation = allowChunklessPreparation;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
@ -422,8 +423,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
playlistTracker,
|
playlistTracker,
|
||||||
dataSourceFactory,
|
dataSourceFactory,
|
||||||
mediaTransferListener,
|
mediaTransferListener,
|
||||||
chunkLoadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
minLoadableRetryCount,
|
|
||||||
eventDispatcher,
|
eventDispatcher,
|
||||||
allocator,
|
allocator,
|
||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
|
@ -85,8 +85,7 @@ import java.util.List;
|
|||||||
private final HlsChunkSource chunkSource;
|
private final HlsChunkSource chunkSource;
|
||||||
private final Allocator allocator;
|
private final Allocator allocator;
|
||||||
private final Format muxedAudioFormat;
|
private final Format muxedAudioFormat;
|
||||||
private final LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy;
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private final int minLoadableRetryCount;
|
|
||||||
private final Loader loader;
|
private final Loader loader;
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private final HlsChunkSource.HlsChunkHolder nextChunkHolder;
|
private final HlsChunkSource.HlsChunkHolder nextChunkHolder;
|
||||||
@ -141,9 +140,7 @@ import java.util.List;
|
|||||||
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
||||||
* @param positionUs The position from which to start loading media.
|
* @param positionUs The position from which to start loading media.
|
||||||
* @param muxedAudioFormat Optional muxed audio {@link Format} as defined by the master playlist.
|
* @param muxedAudioFormat Optional muxed audio {@link Format} as defined by the master playlist.
|
||||||
* @param chunkLoadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy} for chunk loads.
|
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
|
||||||
* @param minLoadableRetryCount The minimum number of times that the source should retry a load
|
|
||||||
* before propagating an error.
|
|
||||||
* @param eventDispatcher A dispatcher to notify of events.
|
* @param eventDispatcher A dispatcher to notify of events.
|
||||||
*/
|
*/
|
||||||
public HlsSampleStreamWrapper(
|
public HlsSampleStreamWrapper(
|
||||||
@ -153,16 +150,14 @@ import java.util.List;
|
|||||||
Allocator allocator,
|
Allocator allocator,
|
||||||
long positionUs,
|
long positionUs,
|
||||||
Format muxedAudioFormat,
|
Format muxedAudioFormat,
|
||||||
LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
int minLoadableRetryCount,
|
|
||||||
EventDispatcher eventDispatcher) {
|
EventDispatcher eventDispatcher) {
|
||||||
this.trackType = trackType;
|
this.trackType = trackType;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.chunkSource = chunkSource;
|
this.chunkSource = chunkSource;
|
||||||
this.allocator = allocator;
|
this.allocator = allocator;
|
||||||
this.muxedAudioFormat = muxedAudioFormat;
|
this.muxedAudioFormat = muxedAudioFormat;
|
||||||
this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
loader = new Loader("Loader:HlsSampleStreamWrapper");
|
loader = new Loader("Loader:HlsSampleStreamWrapper");
|
||||||
nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
|
nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
|
||||||
@ -571,7 +566,9 @@ import java.util.List;
|
|||||||
mediaChunks.add(mediaChunk);
|
mediaChunks.add(mediaChunk);
|
||||||
upstreamTrackFormat = mediaChunk.trackFormat;
|
upstreamTrackFormat = mediaChunk.trackFormat;
|
||||||
}
|
}
|
||||||
long elapsedRealtimeMs = loader.startLoading(loadable, this, minLoadableRetryCount);
|
long elapsedRealtimeMs =
|
||||||
|
loader.startLoading(
|
||||||
|
loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type));
|
||||||
eventDispatcher.loadStarted(
|
eventDispatcher.loadStarted(
|
||||||
loadable.dataSpec,
|
loadable.dataSpec,
|
||||||
loadable.dataSpec.uri,
|
loadable.dataSpec.uri,
|
||||||
@ -654,8 +651,8 @@ import java.util.List;
|
|||||||
|
|
||||||
if (!isMediaChunk || bytesLoaded == 0) {
|
if (!isMediaChunk || bytesLoaded == 0) {
|
||||||
long blacklistDurationMs =
|
long blacklistDurationMs =
|
||||||
chunkLoadErrorHandlingPolicy.getBlacklistDurationMsFor(
|
loadErrorHandlingPolicy.getBlacklistDurationMsFor(
|
||||||
loadable, loadDurationMs, error, errorCount);
|
loadable.type, loadDurationMs, error, errorCount);
|
||||||
if (blacklistDurationMs != C.TIME_UNSET) {
|
if (blacklistDurationMs != C.TIME_UNSET) {
|
||||||
blacklistSucceeded = chunkSource.maybeBlacklistTrack(loadable, blacklistDurationMs);
|
blacklistSucceeded = chunkSource.maybeBlacklistTrack(loadable, blacklistDurationMs);
|
||||||
}
|
}
|
||||||
@ -672,8 +669,8 @@ import java.util.List;
|
|||||||
loadErrorAction = Loader.DONT_RETRY;
|
loadErrorAction = Loader.DONT_RETRY;
|
||||||
} else /* did not blacklist */ {
|
} else /* did not blacklist */ {
|
||||||
long retryDelayMs =
|
long retryDelayMs =
|
||||||
chunkLoadErrorHandlingPolicy.getRetryDelayMsFor(
|
loadErrorHandlingPolicy.getRetryDelayMsFor(
|
||||||
loadable, loadDurationMs, error, errorCount);
|
loadable.type, loadDurationMs, error, errorCount);
|
||||||
loadErrorAction =
|
loadErrorAction =
|
||||||
retryDelayMs != C.TIME_UNSET
|
retryDelayMs != C.TIME_UNSET
|
||||||
? Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs)
|
? Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs)
|
||||||
|
@ -49,9 +49,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
private final HlsDataSourceFactory dataSourceFactory;
|
private final HlsDataSourceFactory dataSourceFactory;
|
||||||
private final ParsingLoadable.Parser<HlsPlaylist> playlistParser;
|
private final ParsingLoadable.Parser<HlsPlaylist> playlistParser;
|
||||||
private final LoadErrorHandlingPolicy<ParsingLoadable<HlsPlaylist>>
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
playlistLoadErrorHandlingPolicy;
|
|
||||||
private final int minRetryCount;
|
|
||||||
private final IdentityHashMap<HlsUrl, MediaPlaylistBundle> playlistBundles;
|
private final IdentityHashMap<HlsUrl, MediaPlaylistBundle> playlistBundles;
|
||||||
private final List<PlaylistEventListener> listeners;
|
private final List<PlaylistEventListener> listeners;
|
||||||
|
|
||||||
@ -67,21 +65,16 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dataSourceFactory A factory for {@link DataSource} instances.
|
* @param dataSourceFactory A factory for {@link DataSource} instances.
|
||||||
* @param playlistLoadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy} for playlist loads.
|
* @param loadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy}.
|
||||||
* @param minRetryCount The minimum number of times loads must be retried before {@link
|
|
||||||
* #maybeThrowPlaylistRefreshError(HlsUrl)} and {@link
|
|
||||||
* #maybeThrowPrimaryPlaylistRefreshError()} propagate any loading errors.
|
|
||||||
* @param playlistParser A {@link ParsingLoadable.Parser} for HLS playlists.
|
* @param playlistParser A {@link ParsingLoadable.Parser} for HLS playlists.
|
||||||
*/
|
*/
|
||||||
public DefaultHlsPlaylistTracker(
|
public DefaultHlsPlaylistTracker(
|
||||||
HlsDataSourceFactory dataSourceFactory,
|
HlsDataSourceFactory dataSourceFactory,
|
||||||
LoadErrorHandlingPolicy<ParsingLoadable<HlsPlaylist>> playlistLoadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
int minRetryCount,
|
|
||||||
ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||||
this.dataSourceFactory = dataSourceFactory;
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
this.minRetryCount = minRetryCount;
|
|
||||||
this.playlistParser = playlistParser;
|
this.playlistParser = playlistParser;
|
||||||
this.playlistLoadErrorHandlingPolicy = playlistLoadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
listeners = new ArrayList<>();
|
listeners = new ArrayList<>();
|
||||||
playlistBundles = new IdentityHashMap<>();
|
playlistBundles = new IdentityHashMap<>();
|
||||||
initialStartTimeUs = C.TIME_UNSET;
|
initialStartTimeUs = C.TIME_UNSET;
|
||||||
@ -106,7 +99,10 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
Assertions.checkState(initialPlaylistLoader == null);
|
Assertions.checkState(initialPlaylistLoader == null);
|
||||||
initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MasterPlaylist");
|
initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MasterPlaylist");
|
||||||
long elapsedRealtime =
|
long elapsedRealtime =
|
||||||
initialPlaylistLoader.startLoading(masterPlaylistLoadable, this, minRetryCount);
|
initialPlaylistLoader.startLoading(
|
||||||
|
masterPlaylistLoadable,
|
||||||
|
this,
|
||||||
|
loadErrorHandlingPolicy.getMinimumLoadableRetryCount(masterPlaylistLoadable.type));
|
||||||
eventDispatcher.loadStarted(
|
eventDispatcher.loadStarted(
|
||||||
masterPlaylistLoadable.dataSpec,
|
masterPlaylistLoadable.dataSpec,
|
||||||
masterPlaylistLoadable.dataSpec.uri,
|
masterPlaylistLoadable.dataSpec.uri,
|
||||||
@ -248,8 +244,8 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
IOException error,
|
IOException error,
|
||||||
int errorCount) {
|
int errorCount) {
|
||||||
long retryDelayMs =
|
long retryDelayMs =
|
||||||
playlistLoadErrorHandlingPolicy.getRetryDelayMsFor(
|
loadErrorHandlingPolicy.getRetryDelayMsFor(
|
||||||
loadable, loadDurationMs, error, errorCount);
|
loadable.type, loadDurationMs, error, errorCount);
|
||||||
boolean isFatal = retryDelayMs == C.TIME_UNSET;
|
boolean isFatal = retryDelayMs == C.TIME_UNSET;
|
||||||
eventDispatcher.loadError(
|
eventDispatcher.loadError(
|
||||||
loadable.dataSpec,
|
loadable.dataSpec,
|
||||||
@ -515,8 +511,8 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
LoadErrorAction loadErrorAction;
|
LoadErrorAction loadErrorAction;
|
||||||
|
|
||||||
long blacklistDurationMs =
|
long blacklistDurationMs =
|
||||||
playlistLoadErrorHandlingPolicy.getBlacklistDurationMsFor(
|
loadErrorHandlingPolicy.getBlacklistDurationMsFor(
|
||||||
loadable, loadDurationMs, error, errorCount);
|
loadable.type, loadDurationMs, error, errorCount);
|
||||||
boolean shouldBlacklist = blacklistDurationMs != C.TIME_UNSET;
|
boolean shouldBlacklist = blacklistDurationMs != C.TIME_UNSET;
|
||||||
|
|
||||||
boolean blacklistingFailed =
|
boolean blacklistingFailed =
|
||||||
@ -527,8 +523,8 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
if (blacklistingFailed) {
|
if (blacklistingFailed) {
|
||||||
long retryDelay =
|
long retryDelay =
|
||||||
playlistLoadErrorHandlingPolicy.getRetryDelayMsFor(
|
loadErrorHandlingPolicy.getRetryDelayMsFor(
|
||||||
loadable, loadDurationMs, error, errorCount);
|
loadable.type, loadDurationMs, error, errorCount);
|
||||||
loadErrorAction =
|
loadErrorAction =
|
||||||
retryDelay != C.TIME_UNSET
|
retryDelay != C.TIME_UNSET
|
||||||
? Loader.createRetryAction(false, retryDelay)
|
? Loader.createRetryAction(false, retryDelay)
|
||||||
@ -562,7 +558,10 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
private void loadPlaylistImmediately() {
|
private void loadPlaylistImmediately() {
|
||||||
long elapsedRealtime =
|
long elapsedRealtime =
|
||||||
mediaPlaylistLoader.startLoading(mediaPlaylistLoadable, this, minRetryCount);
|
mediaPlaylistLoader.startLoading(
|
||||||
|
mediaPlaylistLoadable,
|
||||||
|
this,
|
||||||
|
loadErrorHandlingPolicy.getMinimumLoadableRetryCount(mediaPlaylistLoadable.type));
|
||||||
eventDispatcher.loadStarted(
|
eventDispatcher.loadStarted(
|
||||||
mediaPlaylistLoadable.dataSpec,
|
mediaPlaylistLoadable.dataSpec,
|
||||||
mediaPlaylistLoadable.dataSpec.uri,
|
mediaPlaylistLoadable.dataSpec.uri,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user