mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +08:00
HLS playlist tracking cleanup
Make the public loadPlaylist method not take an argument again. PiperOrigin-RevId: 342646259
This commit is contained in:
parent
e832a4e0fc
commit
0a778ceb1c
@ -89,6 +89,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
public static final int METADATA_TYPE_ID3 = 1;
|
public static final int METADATA_TYPE_ID3 = 1;
|
||||||
/** Type for ESMG metadata in HLS streams. */
|
/** Type for ESMG metadata in HLS streams. */
|
||||||
public static final int METADATA_TYPE_EMSG = 3;
|
public static final int METADATA_TYPE_EMSG = 3;
|
||||||
|
|
||||||
/** Factory for {@link HlsMediaSource}s. */
|
/** Factory for {@link HlsMediaSource}s. */
|
||||||
public static final class Factory implements MediaSourceFactory {
|
public static final class Factory implements MediaSourceFactory {
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshPlaylist(Uri url) {
|
public void refreshPlaylist(Uri url) {
|
||||||
playlistBundles.get(url).loadPlaylist(url);
|
playlistBundles.get(url).loadPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -259,7 +259,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
// We don't need to load the playlist again. We can use the same result.
|
// We don't need to load the playlist again. We can use the same result.
|
||||||
primaryBundle.processLoadedPlaylist((HlsMediaPlaylist) result, loadEventInfo);
|
primaryBundle.processLoadedPlaylist((HlsMediaPlaylist) result, loadEventInfo);
|
||||||
} else {
|
} else {
|
||||||
primaryBundle.loadPlaylist(primaryMediaPlaylistUrl);
|
primaryBundle.loadPlaylist();
|
||||||
}
|
}
|
||||||
loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
|
loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
|
||||||
eventDispatcher.loadCompleted(loadEventInfo, C.DATA_TYPE_MANIFEST);
|
eventDispatcher.loadCompleted(loadEventInfo, C.DATA_TYPE_MANIFEST);
|
||||||
@ -324,7 +324,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
MediaPlaylistBundle bundle = playlistBundles.get(variants.get(i).url);
|
MediaPlaylistBundle bundle = playlistBundles.get(variants.get(i).url);
|
||||||
if (currentTimeMs > bundle.excludeUntilMs) {
|
if (currentTimeMs > bundle.excludeUntilMs) {
|
||||||
primaryMediaPlaylistUrl = bundle.playlistUrl;
|
primaryMediaPlaylistUrl = bundle.playlistUrl;
|
||||||
bundle.loadPlaylist(primaryMediaPlaylistUrl);
|
bundle.loadPlaylist();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
primaryMediaPlaylistUrl = url;
|
primaryMediaPlaylistUrl = url;
|
||||||
playlistBundles.get(primaryMediaPlaylistUrl).loadPlaylist(url);
|
playlistBundles.get(primaryMediaPlaylistUrl).loadPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether any of the variants in the master playlist have the specified playlist URL. */
|
/** Returns whether any of the variants in the master playlist have the specified playlist URL. */
|
||||||
@ -480,7 +480,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
private long earliestNextLoadTimeMs;
|
private long earliestNextLoadTimeMs;
|
||||||
private long excludeUntilMs;
|
private long excludeUntilMs;
|
||||||
private boolean loadPending;
|
private boolean loadPending;
|
||||||
private IOException playlistError;
|
@Nullable private IOException playlistError;
|
||||||
|
|
||||||
public MediaPlaylistBundle(Uri playlistUrl) {
|
public MediaPlaylistBundle(Uri playlistUrl) {
|
||||||
this.playlistUrl = playlistUrl;
|
this.playlistUrl = playlistUrl;
|
||||||
@ -505,33 +505,8 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|| lastSnapshotLoadMs + snapshotValidityDurationMs > currentTimeMs;
|
|| lastSnapshotLoadMs + snapshotValidityDurationMs > currentTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release() {
|
public void loadPlaylist() {
|
||||||
mediaPlaylistLoader.release();
|
loadPlaylistInternal(playlistUrl);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the playlist.
|
|
||||||
*
|
|
||||||
* @param requestUri The URI to be used for loading the playlist.
|
|
||||||
*/
|
|
||||||
public void loadPlaylist(Uri requestUri) {
|
|
||||||
excludeUntilMs = 0;
|
|
||||||
if (loadPending || mediaPlaylistLoader.isLoading() || mediaPlaylistLoader.hasFatalError()) {
|
|
||||||
// Load already pending, in progress, or a fatal error has been encountered. Do nothing.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long currentTimeMs = SystemClock.elapsedRealtime();
|
|
||||||
if (currentTimeMs < earliestNextLoadTimeMs) {
|
|
||||||
loadPending = true;
|
|
||||||
playlistRefreshHandler.postDelayed(
|
|
||||||
() -> {
|
|
||||||
loadPending = false;
|
|
||||||
loadPlaylistImmediately(requestUri);
|
|
||||||
},
|
|
||||||
earliestNextLoadTimeMs - currentTimeMs);
|
|
||||||
} else {
|
|
||||||
loadPlaylistImmediately(requestUri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void maybeThrowPlaylistRefreshError() throws IOException {
|
public void maybeThrowPlaylistRefreshError() throws IOException {
|
||||||
@ -541,6 +516,10 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
mediaPlaylistLoader.release();
|
||||||
|
}
|
||||||
|
|
||||||
// Loader.Callback implementation.
|
// Loader.Callback implementation.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -609,7 +588,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
// Intercept bad request and service unavailable to force a full, non-blocking request
|
// Intercept bad request and service unavailable to force a full, non-blocking request
|
||||||
// (see RFC 8216, section 6.2.5.2).
|
// (see RFC 8216, section 6.2.5.2).
|
||||||
earliestNextLoadTimeMs = SystemClock.elapsedRealtime();
|
earliestNextLoadTimeMs = SystemClock.elapsedRealtime();
|
||||||
loadPlaylist(/* requestUri= */ playlistUrl);
|
loadPlaylist();
|
||||||
castNonNull(eventDispatcher)
|
castNonNull(eventDispatcher)
|
||||||
.loadError(loadEventInfo, loadable.type, error, /* wasCanceled= */ true);
|
.loadError(loadEventInfo, loadable.type, error, /* wasCanceled= */ true);
|
||||||
return Loader.DONT_RETRY;
|
return Loader.DONT_RETRY;
|
||||||
@ -648,6 +627,26 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
|
public void loadPlaylistInternal(Uri playlistRequestUri) {
|
||||||
|
excludeUntilMs = 0;
|
||||||
|
if (loadPending || mediaPlaylistLoader.isLoading() || mediaPlaylistLoader.hasFatalError()) {
|
||||||
|
// Load already pending, in progress, or a fatal error has been encountered. Do nothing.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long currentTimeMs = SystemClock.elapsedRealtime();
|
||||||
|
if (currentTimeMs < earliestNextLoadTimeMs) {
|
||||||
|
loadPending = true;
|
||||||
|
playlistRefreshHandler.postDelayed(
|
||||||
|
() -> {
|
||||||
|
loadPending = false;
|
||||||
|
loadPlaylistImmediately(playlistRequestUri);
|
||||||
|
},
|
||||||
|
earliestNextLoadTimeMs - currentTimeMs);
|
||||||
|
} else {
|
||||||
|
loadPlaylistImmediately(playlistRequestUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadPlaylistImmediately(Uri playlistRequestUri) {
|
private void loadPlaylistImmediately(Uri playlistRequestUri) {
|
||||||
ParsingLoadable<HlsPlaylist> mediaPlaylistLoadable =
|
ParsingLoadable<HlsPlaylist> mediaPlaylistLoadable =
|
||||||
new ParsingLoadable<>(
|
new ParsingLoadable<>(
|
||||||
@ -721,7 +720,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
// next load will be scheduled when refreshPlaylist is called, or when this playlist becomes
|
// next load will be scheduled when refreshPlaylist is called, or when this playlist becomes
|
||||||
// the primary.
|
// the primary.
|
||||||
if (playlistUrl.equals(primaryMediaPlaylistUrl) && !playlistSnapshot.hasEndTag) {
|
if (playlistUrl.equals(primaryMediaPlaylistUrl) && !playlistSnapshot.hasEndTag) {
|
||||||
loadPlaylist(getMediaPlaylistUriForReload());
|
loadPlaylistInternal(getMediaPlaylistUriForReload());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user