Commit 9f3c595e by christosts Committed by Marc Baechinger

DefaultTrackSelector: Constrain audio channel count

The track selector will select multi-channel formats when those can be
spatialized, otherwise the selector will prefer stereo/mono audio
tracks. When the device supports audio spatialization (Android 12L+),
the DefaultTrackSelector will monitor for changes in the platform
Spatializer and trigger a new track selection upon a
Spatializer change event.

Devices with a `television` UI mode are excluded from audio channel
count constraints.

#minor-release

PiperOrigin-RevId: 453957269
parent 91748410
...@@ -369,6 +369,7 @@ import java.util.concurrent.TimeoutException; ...@@ -369,6 +369,7 @@ import java.util.concurrent.TimeoutException;
deviceInfo = createDeviceInfo(streamVolumeManager); deviceInfo = createDeviceInfo(streamVolumeManager);
videoSize = VideoSize.UNKNOWN; videoSize = VideoSize.UNKNOWN;
trackSelector.setAudioAttributes(audioAttributes);
sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_SESSION_ID, audioSessionId); sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_SESSION_ID, audioSessionId);
sendRendererMessage(TRACK_TYPE_VIDEO, MSG_SET_AUDIO_SESSION_ID, audioSessionId); sendRendererMessage(TRACK_TYPE_VIDEO, MSG_SET_AUDIO_SESSION_ID, audioSessionId);
sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_ATTRIBUTES, audioAttributes); sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_ATTRIBUTES, audioAttributes);
...@@ -1364,6 +1365,7 @@ import java.util.concurrent.TimeoutException; ...@@ -1364,6 +1365,7 @@ import java.util.concurrent.TimeoutException;
} }
audioFocusManager.setAudioAttributes(handleAudioFocus ? newAudioAttributes : null); audioFocusManager.setAudioAttributes(handleAudioFocus ? newAudioAttributes : null);
trackSelector.setAudioAttributes(newAudioAttributes);
boolean playWhenReady = getPlayWhenReady(); boolean playWhenReady = getPlayWhenReady();
@AudioFocusManager.PlayerCommand @AudioFocusManager.PlayerCommand
int playerCommand = audioFocusManager.updateAudioFocus(playWhenReady, getPlaybackState()); int playerCommand = audioFocusManager.updateAudioFocus(playWhenReady, getPlaybackState());
......
...@@ -107,6 +107,7 @@ public final class DownloadHelper { ...@@ -107,6 +107,7 @@ public final class DownloadHelper {
DefaultTrackSelector.Parameters.DEFAULT_WITHOUT_CONTEXT DefaultTrackSelector.Parameters.DEFAULT_WITHOUT_CONTEXT
.buildUpon() .buildUpon()
.setForceHighestSupportedBitrate(true) .setForceHighestSupportedBitrate(true)
.setConstrainAudioChannelCountToDeviceCapabilities(false)
.build(); .build();
/** Returns the default parameters used for track selection for downloading. */ /** Returns the default parameters used for track selection for downloading. */
...@@ -114,6 +115,7 @@ public final class DownloadHelper { ...@@ -114,6 +115,7 @@ public final class DownloadHelper {
return DefaultTrackSelector.Parameters.getDefaults(context) return DefaultTrackSelector.Parameters.getDefaults(context)
.buildUpon() .buildUpon()
.setForceHighestSupportedBitrate(true) .setForceHighestSupportedBitrate(true)
.setConstrainAudioChannelCountToDeviceCapabilities(false)
.build(); .build();
} }
......
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.trackselection; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.trackselection;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
...@@ -25,6 +26,7 @@ import com.google.android.exoplayer2.Renderer; ...@@ -25,6 +26,7 @@ import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.RendererConfiguration; import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
...@@ -109,7 +111,8 @@ public abstract class TrackSelector { ...@@ -109,7 +111,8 @@ public abstract class TrackSelector {
* it has previously made are no longer valid. * it has previously made are no longer valid.
* @param bandwidthMeter A bandwidth meter which can be used by track selections to select tracks. * @param bandwidthMeter A bandwidth meter which can be used by track selections to select tracks.
*/ */
public final void init(InvalidationListener listener, BandwidthMeter bandwidthMeter) { @CallSuper
public void init(InvalidationListener listener, BandwidthMeter bandwidthMeter) {
this.listener = listener; this.listener = listener;
this.bandwidthMeter = bandwidthMeter; this.bandwidthMeter = bandwidthMeter;
} }
...@@ -118,9 +121,10 @@ public abstract class TrackSelector { ...@@ -118,9 +121,10 @@ public abstract class TrackSelector {
* Called by the player to release the selector. The selector cannot be used until {@link * Called by the player to release the selector. The selector cannot be used until {@link
* #init(InvalidationListener, BandwidthMeter)} is called again. * #init(InvalidationListener, BandwidthMeter)} is called again.
*/ */
public final void release() { @CallSuper
this.listener = null; public void release() {
this.bandwidthMeter = null; listener = null;
bandwidthMeter = null;
} }
/** /**
...@@ -175,6 +179,11 @@ public abstract class TrackSelector { ...@@ -175,6 +179,11 @@ public abstract class TrackSelector {
return false; return false;
} }
/** Called by the player to set the {@link AudioAttributes} that will be used for playback. */
public void setAudioAttributes(AudioAttributes audioAttributes) {
// Default implementation is no-op.
}
/** /**
* Calls {@link InvalidationListener#onTrackSelectionsInvalidated()} to invalidate all previously * Calls {@link InvalidationListener#onTrackSelectionsInvalidated()} to invalidate all previously
* generated track selections. * generated track selections.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment