Align pattern of calling deprecated listener methods.

There are two different patterns we use at the moment:
 1. Call both deprecated and non-deprecated method from call site with
    no default method implementation body.
 2. Use default method of non-deprecated method to call deprecated
    method.

Pattern 1 is easier to reason about as it makes the calls more explicit,
so changing all usages of pattern 2 to pattern 1.

PiperOrigin-RevId: 358769803
This commit is contained in:
tonihei 2021-02-22 09:41:57 +00:00 committed by bachinger
parent 93a608d507
commit ceb76f35e9
7 changed files with 59 additions and 64 deletions

View File

@ -708,15 +708,19 @@ public final class CastPlayer extends BasePlayer {
} }
} }
@SuppressWarnings("deprecation") // Calling deprecated listener method.
private void updateTimelineAndNotifyIfChanged() { private void updateTimelineAndNotifyIfChanged() {
if (updateTimeline()) { if (updateTimeline()) {
// TODO: Differentiate TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED and // TODO: Differentiate TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED and
// TIMELINE_CHANGE_REASON_SOURCE_UPDATE [see internal: b/65152553]. // TIMELINE_CHANGE_REASON_SOURCE_UPDATE [see internal: b/65152553].
Timeline timeline = currentTimeline;
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_TIMELINE_CHANGED, Player.EVENT_TIMELINE_CHANGED,
listener -> listener -> {
listener.onTimelineChanged( listener.onTimelineChanged(
currentTimeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE)); timeline, /* manifest= */ null, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
listener.onTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
});
} }
} }

View File

@ -400,30 +400,9 @@ public interface Player {
* @param timeline The latest timeline. Never null, but may be empty. * @param timeline The latest timeline. Never null, but may be empty.
* @param reason The {@link TimelineChangeReason} responsible for this timeline change. * @param reason The {@link TimelineChangeReason} responsible for this timeline change.
*/ */
@SuppressWarnings("deprecation") default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {}
default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
Object manifest = null;
if (timeline.getWindowCount() == 1) {
// Legacy behavior was to report the manifest for single window timelines only.
Timeline.Window window = new Timeline.Window();
manifest = timeline.getWindow(0, window).manifest;
}
// Call deprecated version.
onTimelineChanged(timeline, manifest, reason);
}
/** /**
* Called when the timeline and/or manifest has been refreshed.
*
* <p>Note that if the timeline has changed then a position discontinuity may also have
* occurred. For example, the current period index may have changed as a result of periods being
* added or removed from the timeline. This will <em>not</em> be reported via a separate call to
* {@link #onPositionDiscontinuity(int)}.
*
* @param timeline The latest timeline. Never null, but may be empty.
* @param manifest The latest manifest in case the timeline has a single window only. Always
* null if the timeline has more than a single window.
* @param reason The {@link TimelineChangeReason} responsible for this timeline change.
* @deprecated Use {@link #onTimelineChanged(Timeline, int)} instead. The manifest can be * @deprecated Use {@link #onTimelineChanged(Timeline, int)} instead. The manifest can be
* accessed by using {@link #getCurrentManifest()} or {@code timeline.getWindow(windowIndex, * accessed by using {@link #getCurrentManifest()} or {@code timeline.getWindow(windowIndex,
* window).manifest} for a given window index. * window).manifest} for a given window index.
@ -488,10 +467,7 @@ public interface Player {
* *
* @param isLoading Whether the source is currently being loaded. * @param isLoading Whether the source is currently being loaded.
*/ */
@SuppressWarnings("deprecation") default void onIsLoadingChanged(boolean isLoading) {}
default void onIsLoadingChanged(boolean isLoading) {
onLoadingChanged(isLoading);
}
/** @deprecated Use {@link #onIsLoadingChanged(boolean)} instead. */ /** @deprecated Use {@link #onIsLoadingChanged(boolean)} instead. */
@Deprecated @Deprecated

View File

@ -999,7 +999,16 @@ import java.util.List;
if (!previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline)) { if (!previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline)) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_TIMELINE_CHANGED, Player.EVENT_TIMELINE_CHANGED,
listener -> listener.onTimelineChanged(newPlaybackInfo.timeline, timelineChangeReason)); listener -> {
@Nullable Object manifest = null;
if (newPlaybackInfo.timeline.getWindowCount() == 1) {
// Legacy behavior was to report the manifest for single window timelines only.
Timeline.Window window = new Timeline.Window();
manifest = newPlaybackInfo.timeline.getWindow(0, window).manifest;
}
listener.onTimelineChanged(newPlaybackInfo.timeline, manifest, timelineChangeReason);
listener.onTimelineChanged(newPlaybackInfo.timeline, timelineChangeReason);
});
} }
if (positionDiscontinuity) { if (positionDiscontinuity) {
listeners.queueEvent( listeners.queueEvent(
@ -1042,7 +1051,10 @@ import java.util.List;
if (previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading) { if (previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_IS_LOADING_CHANGED, Player.EVENT_IS_LOADING_CHANGED,
listener -> listener.onIsLoadingChanged(newPlaybackInfo.isLoading)); listener -> {
listener.onLoadingChanged(newPlaybackInfo.isLoading);
listener.onIsLoadingChanged(newPlaybackInfo.isLoading);
});
} }
if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState
|| previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) { || previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) {

View File

@ -207,7 +207,7 @@ public class AnalyticsCollector
// AudioRendererEventListener implementation. // AudioRendererEventListener implementation.
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onAudioEnabled(DecoderCounters counters) { public final void onAudioEnabled(DecoderCounters counters) {
EventTime eventTime = generateReadingMediaPeriodEventTime(); EventTime eventTime = generateReadingMediaPeriodEventTime();
@ -220,7 +220,7 @@ public class AnalyticsCollector
}); });
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onAudioDecoderInitialized( public final void onAudioDecoderInitialized(
String decoderName, long initializedTimestampMs, long initializationDurationMs) { String decoderName, long initializedTimestampMs, long initializationDurationMs) {
@ -235,7 +235,7 @@ public class AnalyticsCollector
}); });
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onAudioInputFormatChanged( public final void onAudioInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
@ -244,6 +244,7 @@ public class AnalyticsCollector
eventTime, eventTime,
AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED, AnalyticsListener.EVENT_AUDIO_INPUT_FORMAT_CHANGED,
listener -> { listener -> {
listener.onAudioInputFormatChanged(eventTime, format);
listener.onAudioInputFormatChanged(eventTime, format, decoderReuseEvaluation); listener.onAudioInputFormatChanged(eventTime, format, decoderReuseEvaluation);
listener.onDecoderInputFormatChanged(eventTime, C.TRACK_TYPE_AUDIO, format); listener.onDecoderInputFormatChanged(eventTime, C.TRACK_TYPE_AUDIO, format);
}); });
@ -278,7 +279,7 @@ public class AnalyticsCollector
listener -> listener.onAudioDecoderReleased(eventTime, decoderName)); listener -> listener.onAudioDecoderReleased(eventTime, decoderName));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onAudioDisabled(DecoderCounters counters) { public final void onAudioDisabled(DecoderCounters counters) {
EventTime eventTime = generatePlayingMediaPeriodEventTime(); EventTime eventTime = generatePlayingMediaPeriodEventTime();
@ -361,7 +362,7 @@ public class AnalyticsCollector
// VideoRendererEventListener implementation. // VideoRendererEventListener implementation.
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onVideoEnabled(DecoderCounters counters) { public final void onVideoEnabled(DecoderCounters counters) {
EventTime eventTime = generateReadingMediaPeriodEventTime(); EventTime eventTime = generateReadingMediaPeriodEventTime();
@ -374,7 +375,7 @@ public class AnalyticsCollector
}); });
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onVideoDecoderInitialized( public final void onVideoDecoderInitialized(
String decoderName, long initializedTimestampMs, long initializationDurationMs) { String decoderName, long initializedTimestampMs, long initializationDurationMs) {
@ -389,7 +390,7 @@ public class AnalyticsCollector
}); });
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onVideoInputFormatChanged( public final void onVideoInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
@ -398,6 +399,7 @@ public class AnalyticsCollector
eventTime, eventTime,
AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED, AnalyticsListener.EVENT_VIDEO_INPUT_FORMAT_CHANGED,
listener -> { listener -> {
listener.onVideoInputFormatChanged(eventTime, format);
listener.onVideoInputFormatChanged(eventTime, format, decoderReuseEvaluation); listener.onVideoInputFormatChanged(eventTime, format, decoderReuseEvaluation);
listener.onDecoderInputFormatChanged(eventTime, C.TRACK_TYPE_VIDEO, format); listener.onDecoderInputFormatChanged(eventTime, C.TRACK_TYPE_VIDEO, format);
}); });
@ -421,7 +423,7 @@ public class AnalyticsCollector
listener -> listener.onVideoDecoderReleased(eventTime, decoderName)); listener -> listener.onVideoDecoderReleased(eventTime, decoderName));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onVideoDisabled(DecoderCounters counters) { public final void onVideoDisabled(DecoderCounters counters) {
EventTime eventTime = generatePlayingMediaPeriodEventTime(); EventTime eventTime = generatePlayingMediaPeriodEventTime();
@ -615,16 +617,20 @@ public class AnalyticsCollector
listener -> listener.onStaticMetadataChanged(eventTime, metadataList)); listener -> listener.onStaticMetadataChanged(eventTime, metadataList));
} }
@SuppressWarnings("deprecation") // Calling deprecated listener method.
@Override @Override
public final void onIsLoadingChanged(boolean isLoading) { public final void onIsLoadingChanged(boolean isLoading) {
EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime(); EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
sendEvent( sendEvent(
eventTime, eventTime,
AnalyticsListener.EVENT_IS_LOADING_CHANGED, AnalyticsListener.EVENT_IS_LOADING_CHANGED,
listener -> listener.onIsLoadingChanged(eventTime, isLoading)); listener -> {
listener.onLoadingChanged(eventTime, isLoading);
listener.onIsLoadingChanged(eventTime, isLoading);
});
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Implementing and calling deprecated listener method.
@Override @Override
public final void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) { public final void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime(); EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
@ -725,7 +731,7 @@ public class AnalyticsCollector
listener -> listener.onPlaybackParametersChanged(eventTime, playbackParameters)); listener -> listener.onPlaybackParametersChanged(eventTime, playbackParameters));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") // Implementing and calling deprecated listener method.
@Override @Override
public final void onSeekProcessed() { public final void onSeekProcessed() {
EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime(); EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();

View File

@ -583,10 +583,7 @@ public interface AnalyticsListener {
* @param eventTime The event time. * @param eventTime The event time.
* @param isLoading Whether the player is loading. * @param isLoading Whether the player is loading.
*/ */
@SuppressWarnings("deprecation") default void onIsLoadingChanged(EventTime eventTime, boolean isLoading) {}
default void onIsLoadingChanged(EventTime eventTime, boolean isLoading) {
onLoadingChanged(eventTime, isLoading);
}
/** @deprecated Use {@link #onIsLoadingChanged(EventTime, boolean)} instead. */ /** @deprecated Use {@link #onIsLoadingChanged(EventTime, boolean)} instead. */
@Deprecated @Deprecated
@ -775,11 +772,10 @@ public interface AnalyticsListener {
* decoder instance can be reused for the new format, or {@code null} if the renderer did not * decoder instance can be reused for the new format, or {@code null} if the renderer did not
* have a decoder. * have a decoder.
*/ */
@SuppressWarnings("deprecation")
default void onAudioInputFormatChanged( default void onAudioInputFormatChanged(
EventTime eventTime, Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { EventTime eventTime,
onAudioInputFormatChanged(eventTime, format); Format format,
} @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/** /**
* Called when the audio position has increased for the first time since the last pause or * Called when the audio position has increased for the first time since the last pause or
@ -918,11 +914,10 @@ public interface AnalyticsListener {
* decoder instance can be reused for the new format, or {@code null} if the renderer did not * decoder instance can be reused for the new format, or {@code null} if the renderer did not
* have a decoder. * have a decoder.
*/ */
@SuppressWarnings("deprecation")
default void onVideoInputFormatChanged( default void onVideoInputFormatChanged(
EventTime eventTime, Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { EventTime eventTime,
onVideoInputFormatChanged(eventTime, format); Format format,
} @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/** /**
* Called after video frames have been dropped. * Called after video frames have been dropped.

View File

@ -69,11 +69,8 @@ public interface AudioRendererEventListener {
* decoder instance can be reused for the new format, or {@code null} if the renderer did not * decoder instance can be reused for the new format, or {@code null} if the renderer did not
* have a decoder. * have a decoder.
*/ */
@SuppressWarnings("deprecation")
default void onAudioInputFormatChanged( default void onAudioInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
onAudioInputFormatChanged(format);
}
/** /**
* Called when the audio position has increased for the first time since the last pause or * Called when the audio position has increased for the first time since the last pause or
@ -186,11 +183,15 @@ public interface AudioRendererEventListener {
} }
/** Invokes {@link AudioRendererEventListener#onAudioInputFormatChanged(Format)}. */ /** Invokes {@link AudioRendererEventListener#onAudioInputFormatChanged(Format)}. */
@SuppressWarnings("deprecation") // Calling deprecated listener method.
public void inputFormatChanged( public void inputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
if (handler != null) { if (handler != null) {
handler.post( handler.post(
() -> castNonNull(listener).onAudioInputFormatChanged(format, decoderReuseEvaluation)); () -> {
castNonNull(listener).onAudioInputFormatChanged(format);
castNonNull(listener).onAudioInputFormatChanged(format, decoderReuseEvaluation);
});
} }
} }

View File

@ -69,11 +69,8 @@ public interface VideoRendererEventListener {
* decoder instance can be reused for the new format, or {@code null} if the renderer did not * decoder instance can be reused for the new format, or {@code null} if the renderer did not
* have a decoder. * have a decoder.
*/ */
@SuppressWarnings("deprecation")
default void onVideoInputFormatChanged( default void onVideoInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
onVideoInputFormatChanged(format);
}
/** /**
* Called to report the number of frames dropped by the renderer. Dropped frames are reported * Called to report the number of frames dropped by the renderer. Dropped frames are reported
@ -205,11 +202,15 @@ public interface VideoRendererEventListener {
* Invokes {@link VideoRendererEventListener#onVideoInputFormatChanged(Format, * Invokes {@link VideoRendererEventListener#onVideoInputFormatChanged(Format,
* DecoderReuseEvaluation)}. * DecoderReuseEvaluation)}.
*/ */
@SuppressWarnings("deprecation") // Calling deprecated listener method.
public void inputFormatChanged( public void inputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) { Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
if (handler != null) { if (handler != null) {
handler.post( handler.post(
() -> castNonNull(listener).onVideoInputFormatChanged(format, decoderReuseEvaluation)); () -> {
castNonNull(listener).onVideoInputFormatChanged(format);
castNonNull(listener).onVideoInputFormatChanged(format, decoderReuseEvaluation);
});
} }
} }