From 07039a45b0eba8531df1a88c8708ebf02a852123 Mon Sep 17 00:00:00 2001 From: ibaker Date: Mon, 23 May 2022 11:19:47 +0100 Subject: [PATCH] Remove `@Nullable` from some `Dash/Hls/SsMediaSource.Factory` methods The null-behaviour of these methods creates a minimization footgun, because **any** call to these setters will prevent R8 from removing the default implementation (even if it's never used by the app) - this is because R8 can't tell the default implementation is only used if the parameter is `null`. Follow-up to https://github.com/androidx/media/commit/07302a23bd5894d57514c68b2db499ac46726e77 PiperOrigin-RevId: 450395941 --- RELEASENOTES.md | 17 ++++++++ .../exoplayer/dash/DashMediaSource.java | 10 +++-- .../media3/exoplayer/hls/HlsMediaSource.java | 41 ++++++++++--------- .../smoothstreaming/SsMediaSource.java | 13 +++--- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 80dc6230f2..a5c5e2ba23 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -74,10 +74,27 @@ * Parse channel count from DTS `AudioChannelConfiguration` elements. This re-enables audio passthrough for DTS streams ([#10159](https://github.com/google/ExoPlayer/issues/10159)). + * Disallow passing `null` to + `DashMediaSource.Factory.setCompositeSequenceableLoaderFactory`. + Instances of `DefaultCompositeSequenceableLoaderFactory` can be passed + explicitly if required. * HLS: * Fallback to chunkful preparation if the playlist CODECS attribute does not contain the audio codec ([#10065](https://github.com/google/ExoPlayer/issues/10065)). + * Disallow passing `null` to + `HlsMediaSource.Factory.setCompositeSequenceableLoaderFactory`, + `HlsMediaSource.Factory.setPlaylistParserFactory`, and + `HlsMediaSource.Factory.setPlaylistTrackerFactory`. Instances of + `DefaultCompositeSequenceableLoaderFactory`, + `DefaultHlsPlaylistParserFactory`, or a reference to + `DefaultHlsPlaylistTracker.FACTORY` can be passed explicitly if + required. +* Smooth Streaming: + * Disallow passing `null` to + `SsMediaSource.Factory.setCompositeSequenceableLoaderFactory`. Instances + of `DefaultCompositeSequenceableLoaderFactory` can be passed explicitly + if required. * RTSP: * Add RTP reader for MPEG4 ([#35](https://github.com/androidx/media/pull/35)). diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java index 55e8b3f091..7abde693ba 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java @@ -218,11 +218,13 @@ public final class DashMediaSource extends BaseMediaSource { * @return This factory, for convenience. */ public Factory setCompositeSequenceableLoaderFactory( - @Nullable CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { + CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { this.compositeSequenceableLoaderFactory = - compositeSequenceableLoaderFactory != null - ? compositeSequenceableLoaderFactory - : new DefaultCompositeSequenceableLoaderFactory(); + checkNotNull( + compositeSequenceableLoaderFactory, + "DashMediaSource.Factory#setCompositeSequenceableLoaderFactory no longer handles null" + + " by instantiating a new DefaultCompositeSequenceableLoaderFactory. Explicitly" + + " construct and pass an instance in order to retain the old behavior."); return this; } diff --git a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java index d63fb9e77e..0cc5663a03 100644 --- a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java +++ b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/HlsMediaSource.java @@ -189,41 +189,40 @@ public final class HlsMediaSource extends BaseMediaSource } /** - * Sets the factory from which playlist parsers will be obtained. The default value is a {@link - * DefaultHlsPlaylistParserFactory}. + * Sets the factory from which playlist parsers will be obtained. * * @param playlistParserFactory An {@link HlsPlaylistParserFactory}. * @return This factory, for convenience. */ - public Factory setPlaylistParserFactory( - @Nullable HlsPlaylistParserFactory playlistParserFactory) { + public Factory setPlaylistParserFactory(HlsPlaylistParserFactory playlistParserFactory) { this.playlistParserFactory = - playlistParserFactory != null - ? playlistParserFactory - : new DefaultHlsPlaylistParserFactory(); + checkNotNull( + playlistParserFactory, + "HlsMediaSource.Factory#setPlaylistParserFactory no longer handles null by" + + " instantiating a new DefaultHlsPlaylistParserFactory. Explicitly" + + " construct and pass an instance in order to retain the old behavior."); return this; } /** - * Sets the {@link HlsPlaylistTracker} factory. The default value is {@link - * DefaultHlsPlaylistTracker#FACTORY}. + * Sets the {@link HlsPlaylistTracker} factory. * * @param playlistTrackerFactory A factory for {@link HlsPlaylistTracker} instances. * @return This factory, for convenience. */ - public Factory setPlaylistTrackerFactory( - @Nullable HlsPlaylistTracker.Factory playlistTrackerFactory) { + public Factory setPlaylistTrackerFactory(HlsPlaylistTracker.Factory playlistTrackerFactory) { this.playlistTrackerFactory = - playlistTrackerFactory != null - ? playlistTrackerFactory - : DefaultHlsPlaylistTracker.FACTORY; + checkNotNull( + playlistTrackerFactory, + "HlsMediaSource.Factory#setPlaylistTrackerFactory no longer handles null by" + + " defaulting to DefaultHlsPlaylistTracker.FACTORY. Explicitly" + + " pass a reference to this instance in order to retain the old behavior."); return this; } /** * Sets the factory to create composite {@link SequenceableLoader}s for when this media source - * loads data from multiple streams (video, audio etc...). The default is an instance of {@link - * DefaultCompositeSequenceableLoaderFactory}. + * loads data from multiple streams (video, audio etc...). * * @param compositeSequenceableLoaderFactory A factory to create composite {@link * SequenceableLoader}s for when this media source loads data from multiple streams (video, @@ -231,11 +230,13 @@ public final class HlsMediaSource extends BaseMediaSource * @return This factory, for convenience. */ public Factory setCompositeSequenceableLoaderFactory( - @Nullable CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { + CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { this.compositeSequenceableLoaderFactory = - compositeSequenceableLoaderFactory != null - ? compositeSequenceableLoaderFactory - : new DefaultCompositeSequenceableLoaderFactory(); + checkNotNull( + compositeSequenceableLoaderFactory, + "HlsMediaSource.Factory#setCompositeSequenceableLoaderFactory no longer handles null" + + " by instantiating a new DefaultCompositeSequenceableLoaderFactory. Explicitly" + + " construct and pass an instance in order to retain the old behavior."); return this; } diff --git a/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java b/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java index efba32c9c0..b8231da9b1 100644 --- a/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java +++ b/libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/SsMediaSource.java @@ -175,8 +175,7 @@ public final class SsMediaSource extends BaseMediaSource /** * Sets the factory to create composite {@link SequenceableLoader}s for when this media source - * loads data from multiple streams (video, audio etc.). The default is an instance of {@link - * DefaultCompositeSequenceableLoaderFactory}. + * loads data from multiple streams (video, audio etc.). * * @param compositeSequenceableLoaderFactory A factory to create composite {@link * SequenceableLoader}s for when this media source loads data from multiple streams (video, @@ -184,11 +183,13 @@ public final class SsMediaSource extends BaseMediaSource * @return This factory, for convenience. */ public Factory setCompositeSequenceableLoaderFactory( - @Nullable CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { + CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { this.compositeSequenceableLoaderFactory = - compositeSequenceableLoaderFactory != null - ? compositeSequenceableLoaderFactory - : new DefaultCompositeSequenceableLoaderFactory(); + checkNotNull( + compositeSequenceableLoaderFactory, + "SsMediaSource.Factory#setCompositeSequenceableLoaderFactory no longer handles null" + + " by instantiating a new DefaultCompositeSequenceableLoaderFactory. Explicitly" + + " construct and pass an instance in order to retain the old behavior."); return this; }