Skip to content

Commit

Permalink
Fix Dackka/Metalava errors in the HLS and RTSP modules
Browse files Browse the repository at this point in the history
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
(cherry picked from commit dbfc0cc)
  • Loading branch information
icbaker authored and microkatz committed Nov 10, 2022
1 parent c2c9feb commit 937c463
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@

/** A {@link MediaPeriod} that loads an HLS stream. */
@UnstableApi
public final class HlsMediaPeriod
implements MediaPeriod,
HlsSampleStreamWrapper.Callback,
HlsPlaylistTracker.PlaylistEventListener {
public final class HlsMediaPeriod implements MediaPeriod, HlsPlaylistTracker.PlaylistEventListener {

private final HlsExtractorFactory extractorFactory;
private final HlsPlaylistTracker playlistTracker;
Expand All @@ -84,8 +81,9 @@ public final class HlsMediaPeriod
private final @HlsMediaSource.MetadataType int metadataType;
private final boolean useSessionKeys;
private final PlayerId playerId;
private final HlsSampleStreamWrapper.Callback sampleStreamWrapperCallback;

@Nullable private Callback callback;
@Nullable private MediaPeriod.Callback mediaPeriodCallback;
private int pendingPrepareCount;
private @MonotonicNonNull TrackGroupArray trackGroups;
private HlsSampleStreamWrapper[] sampleStreamWrappers;
Expand Down Expand Up @@ -143,6 +141,7 @@ public HlsMediaPeriod(
this.metadataType = metadataType;
this.useSessionKeys = useSessionKeys;
this.playerId = playerId;
sampleStreamWrapperCallback = new SampleStreamWrapperCallback();
compositeSequenceableLoader =
compositeSequenceableLoaderFactory.createCompositeSequenceableLoader();
streamWrapperIndices = new IdentityHashMap<>();
Expand All @@ -157,12 +156,12 @@ public void release() {
for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
sampleStreamWrapper.release();
}
callback = null;
mediaPeriodCallback = null;
}

@Override
public void prepare(Callback callback, long positionUs) {
this.callback = callback;
this.mediaPeriodCallback = callback;
playlistTracker.addListener(this);
buildAndPrepareSampleStreamWrappers(positionUs);
}
Expand Down Expand Up @@ -439,46 +438,14 @@ public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParame

// 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.

@Override
public void onPlaylistChanged() {
for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) {
streamWrapper.onPlaylistUpdated();
}
callback.onContinueLoadingRequested(this);
mediaPeriodCallback.onContinueLoadingRequested(this);
}

@Override
Expand All @@ -488,7 +455,7 @@ public boolean onPlaylistError(
for (HlsSampleStreamWrapper streamWrapper : sampleStreamWrappers) {
exclusionSucceeded &= streamWrapper.onPlaylistError(url, loadErrorInfo, forceRetry);
}
callback.onContinueLoadingRequested(this);
mediaPeriodCallback.onContinueLoadingRequested(this);
return exclusionSucceeded;
}

Expand Down Expand Up @@ -810,7 +777,7 @@ private HlsSampleStreamWrapper buildSampleStreamWrapper(
return new HlsSampleStreamWrapper(
uid,
trackType,
/* callback= */ this,
/* callback= */ sampleStreamWrapperCallback,
defaultChunkSource,
overridingDrmInitData,
allocator,
Expand Down Expand Up @@ -915,4 +882,38 @@ private static Format deriveAudioFormat(
.setLanguage(language)
.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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class RtpPayloadFormat {
public static final String RTP_MEDIA_VP9 = "VP9";

/** 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)) {
case RTP_MEDIA_AC3:
case RTP_MEDIA_AMR:
Expand Down

0 comments on commit 937c463

Please sign in to comment.