Fix Dackka/Metalava errors in the HLS and RTSP modules

This makes two fixes:
1. Remove `HlsSampleStreamWrapper.Callback` (package-private) from the
   list of interfaces implemented by `HlsMediaPeriod` (`public`) and
   move the implementation to a private inner class instead. This avoids
   Metalava complaining about a public class that inherits from a
   package-private type.
2. Reduce the visibility of
   `RtpPayloadFormat.isFormatSupported(MediaDescription)` from `public`
   to package-private. The `MediaDescription` type is already
   package-private, so this method was already unusable outside the
   package.

#minor-release

PiperOrigin-RevId: 487472781
This commit is contained in:
ibaker 2022-11-10 09:59:35 +00:00 committed by microkatz
parent 7905744a83
commit dbfc0cc770
2 changed files with 44 additions and 43 deletions

View File

@ -63,10 +63,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** A {@link MediaPeriod} that loads an HLS stream. */ /** A {@link MediaPeriod} that loads an HLS stream. */
@UnstableApi @UnstableApi
public final class HlsMediaPeriod public final class HlsMediaPeriod implements MediaPeriod, HlsPlaylistTracker.PlaylistEventListener {
implements MediaPeriod,
HlsSampleStreamWrapper.Callback,
HlsPlaylistTracker.PlaylistEventListener {
private final HlsExtractorFactory extractorFactory; private final HlsExtractorFactory extractorFactory;
private final HlsPlaylistTracker playlistTracker; private final HlsPlaylistTracker playlistTracker;
@ -84,8 +81,9 @@ public final class HlsMediaPeriod
private final @HlsMediaSource.MetadataType int metadataType; private final @HlsMediaSource.MetadataType int metadataType;
private final boolean useSessionKeys; private final boolean useSessionKeys;
private final PlayerId playerId; private final PlayerId playerId;
private final HlsSampleStreamWrapper.Callback sampleStreamWrapperCallback;
@Nullable private Callback callback; @Nullable private MediaPeriod.Callback mediaPeriodCallback;
private int pendingPrepareCount; private int pendingPrepareCount;
private @MonotonicNonNull TrackGroupArray trackGroups; private @MonotonicNonNull TrackGroupArray trackGroups;
private HlsSampleStreamWrapper[] sampleStreamWrappers; private HlsSampleStreamWrapper[] sampleStreamWrappers;
@ -143,6 +141,7 @@ public final class HlsMediaPeriod
this.metadataType = metadataType; this.metadataType = metadataType;
this.useSessionKeys = useSessionKeys; this.useSessionKeys = useSessionKeys;
this.playerId = playerId; this.playerId = playerId;
sampleStreamWrapperCallback = new SampleStreamWrapperCallback();
compositeSequenceableLoader = compositeSequenceableLoader =
compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(); compositeSequenceableLoaderFactory.createCompositeSequenceableLoader();
streamWrapperIndices = new IdentityHashMap<>(); streamWrapperIndices = new IdentityHashMap<>();
@ -157,12 +156,12 @@ public final class HlsMediaPeriod
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) { for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
sampleStreamWrapper.release(); sampleStreamWrapper.release();
} }
callback = null; mediaPeriodCallback = null;
} }
@Override @Override
public void prepare(Callback callback, long positionUs) { public void prepare(Callback callback, long positionUs) {
this.callback = callback; this.mediaPeriodCallback = callback;
playlistTracker.addListener(this); playlistTracker.addListener(this);
buildAndPrepareSampleStreamWrappers(positionUs); buildAndPrepareSampleStreamWrappers(positionUs);
} }
@ -439,38 +438,6 @@ public final class HlsMediaPeriod
// HlsSampleStreamWrapper.Callback implementation. // HlsSampleStreamWrapper.Callback implementation.
@Override
public void onPrepared() {
if (--pendingPrepareCount > 0) {
return;
}
int totalTrackGroupCount = 0;
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
totalTrackGroupCount += sampleStreamWrapper.getTrackGroups().length;
}
TrackGroup[] trackGroupArray = new TrackGroup[totalTrackGroupCount];
int trackGroupIndex = 0;
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
int wrapperTrackGroupCount = sampleStreamWrapper.getTrackGroups().length;
for (int j = 0; j < wrapperTrackGroupCount; j++) {
trackGroupArray[trackGroupIndex++] = sampleStreamWrapper.getTrackGroups().get(j);
}
}
trackGroups = new TrackGroupArray(trackGroupArray);
callback.onPrepared(this);
}
@Override
public void onPlaylistRefreshRequired(Uri url) {
playlistTracker.refreshPlaylist(url);
}
@Override
public void onContinueLoadingRequested(HlsSampleStreamWrapper sampleStreamWrapper) {
callback.onContinueLoadingRequested(this);
}
// PlaylistListener implementation. // PlaylistListener implementation.
@Override @Override
@ -478,7 +445,7 @@ public final class HlsMediaPeriod
for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) { for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) {
streamWrapper.onPlaylistUpdated(); streamWrapper.onPlaylistUpdated();
} }
callback.onContinueLoadingRequested(this); mediaPeriodCallback.onContinueLoadingRequested(this);
} }
@Override @Override
@ -488,7 +455,7 @@ public final class HlsMediaPeriod
for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) { for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) {
exclusionSucceeded &= streamWrapper.onPlaylistError(url, loadErrorInfo, forceRetry); exclusionSucceeded &= streamWrapper.onPlaylistError(url, loadErrorInfo, forceRetry);
} }
callback.onContinueLoadingRequested(this); mediaPeriodCallback.onContinueLoadingRequested(this);
return exclusionSucceeded; return exclusionSucceeded;
} }
@ -810,7 +777,7 @@ public final class HlsMediaPeriod
return new HlsSampleStreamWrapper( return new HlsSampleStreamWrapper(
uid, uid,
trackType, trackType,
/* callback= */ this, /* callback= */ sampleStreamWrapperCallback,
defaultChunkSource, defaultChunkSource,
overridingDrmInitData, overridingDrmInitData,
allocator, allocator,
@ -915,4 +882,38 @@ public final class HlsMediaPeriod
.setLanguage(language) .setLanguage(language)
.build(); .build();
} }
private class SampleStreamWrapperCallback implements HlsSampleStreamWrapper.Callback {
@Override
public void onPrepared() {
if (--pendingPrepareCount > 0) {
return;
}
int totalTrackGroupCount = 0;
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
totalTrackGroupCount += sampleStreamWrapper.getTrackGroups().length;
}
TrackGroup[] trackGroupArray = new TrackGroup[totalTrackGroupCount];
int trackGroupIndex = 0;
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
int wrapperTrackGroupCount = sampleStreamWrapper.getTrackGroups().length;
for (int j = 0; j < wrapperTrackGroupCount; j++) {
trackGroupArray[trackGroupIndex++] = sampleStreamWrapper.getTrackGroups().get(j);
}
}
trackGroups = new TrackGroupArray(trackGroupArray);
mediaPeriodCallback.onPrepared(HlsMediaPeriod.this);
}
@Override
public void onPlaylistRefreshRequired(Uri url) {
playlistTracker.refreshPlaylist(url);
}
@Override
public void onContinueLoadingRequested(HlsSampleStreamWrapper sampleStreamWrapper) {
mediaPeriodCallback.onContinueLoadingRequested(HlsMediaPeriod.this);
}
}
} }

View File

@ -58,7 +58,7 @@ public final class RtpPayloadFormat {
public static final String RTP_MEDIA_VP9 = "VP9"; public static final String RTP_MEDIA_VP9 = "VP9";
/** Returns whether the format of a {@link MediaDescription} is supported. */ /** Returns whether the format of a {@link MediaDescription} is supported. */
public static boolean isFormatSupported(MediaDescription mediaDescription) { /* package */ static boolean isFormatSupported(MediaDescription mediaDescription) {
switch (Ascii.toUpperCase(mediaDescription.rtpMapAttribute.mediaEncoding)) { switch (Ascii.toUpperCase(mediaDescription.rtpMapAttribute.mediaEncoding)) {
case RTP_MEDIA_AC3: case RTP_MEDIA_AC3:
case RTP_MEDIA_AMR: case RTP_MEDIA_AMR: