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() {
if (updateTimeline()) {
// TODO: Differentiate TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED and
// TIMELINE_CHANGE_REASON_SOURCE_UPDATE [see internal: b/65152553].
Timeline timeline = currentTimeline;
listeners.queueEvent(
Player.EVENT_TIMELINE_CHANGED,
listener ->
listener -> {
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 reason The {@link TimelineChangeReason} responsible for this timeline change.
*/
@SuppressWarnings("deprecation")
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);
}
default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int 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
* accessed by using {@link #getCurrentManifest()} or {@code timeline.getWindow(windowIndex,
* window).manifest} for a given window index.
@ -488,10 +467,7 @@ public interface Player {
*
* @param isLoading Whether the source is currently being loaded.
*/
@SuppressWarnings("deprecation")
default void onIsLoadingChanged(boolean isLoading) {
onLoadingChanged(isLoading);
}
default void onIsLoadingChanged(boolean isLoading) {}
/** @deprecated Use {@link #onIsLoadingChanged(boolean)} instead. */
@Deprecated

View File

@ -999,7 +999,16 @@ import java.util.List;
if (!previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline)) {
listeners.queueEvent(
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) {
listeners.queueEvent(
@ -1042,7 +1051,10 @@ import java.util.List;
if (previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading) {
listeners.queueEvent(
Player.EVENT_IS_LOADING_CHANGED,
listener -> listener.onIsLoadingChanged(newPlaybackInfo.isLoading));
listener -> {
listener.onLoadingChanged(newPlaybackInfo.isLoading);
listener.onIsLoadingChanged(newPlaybackInfo.isLoading);
});
}
if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState
|| previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) {

View File

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

View File

@ -583,10 +583,7 @@ public interface AnalyticsListener {
* @param eventTime The event time.
* @param isLoading Whether the player is loading.
*/
@SuppressWarnings("deprecation")
default void onIsLoadingChanged(EventTime eventTime, boolean isLoading) {
onLoadingChanged(eventTime, isLoading);
}
default void onIsLoadingChanged(EventTime eventTime, boolean isLoading) {}
/** @deprecated Use {@link #onIsLoadingChanged(EventTime, boolean)} instead. */
@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
* have a decoder.
*/
@SuppressWarnings("deprecation")
default void onAudioInputFormatChanged(
EventTime eventTime, Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
onAudioInputFormatChanged(eventTime, format);
}
EventTime eventTime,
Format format,
@Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/**
* 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
* have a decoder.
*/
@SuppressWarnings("deprecation")
default void onVideoInputFormatChanged(
EventTime eventTime, Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
onVideoInputFormatChanged(eventTime, format);
}
EventTime eventTime,
Format format,
@Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/**
* 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
* have a decoder.
*/
@SuppressWarnings("deprecation")
default void onAudioInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
onAudioInputFormatChanged(format);
}
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/**
* 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)}. */
@SuppressWarnings("deprecation") // Calling deprecated listener method.
public void inputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
if (handler != null) {
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
* have a decoder.
*/
@SuppressWarnings("deprecation")
default void onVideoInputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
onVideoInputFormatChanged(format);
}
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {}
/**
* 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,
* DecoderReuseEvaluation)}.
*/
@SuppressWarnings("deprecation") // Calling deprecated listener method.
public void inputFormatChanged(
Format format, @Nullable DecoderReuseEvaluation decoderReuseEvaluation) {
if (handler != null) {
handler.post(
() -> castNonNull(listener).onVideoInputFormatChanged(format, decoderReuseEvaluation));
() -> {
castNonNull(listener).onVideoInputFormatChanged(format);
castNonNull(listener).onVideoInputFormatChanged(format, decoderReuseEvaluation);
});
}
}