mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Expose AudioOffload track state.
Adds a new event to AudioOffloadListener to get the offload state of the track, which indicates when software decoding is taking place. PiperOrigin-RevId: 465264362
This commit is contained in:
parent
2fbe1bbfb3
commit
fe2b846552
2 changed files with 33 additions and 1 deletions
|
|
@ -423,6 +423,16 @@ public interface ExoPlayer extends Player {
|
||||||
* <p>This method is experimental, and will be renamed or removed in a future release.
|
* <p>This method is experimental, and will be renamed or removed in a future release.
|
||||||
*/
|
*/
|
||||||
default void onExperimentalSleepingForOffloadChanged(boolean sleepingForOffload) {}
|
default void onExperimentalSleepingForOffloadChanged(boolean sleepingForOffload) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the value of {@link AudioTrack#isOffloadedPlayback} changes.
|
||||||
|
*
|
||||||
|
* <p>This should not be generally required to be acted upon. But when offload is critical for
|
||||||
|
* efficiency, or audio features (gapless, playback speed), this will let the app know.
|
||||||
|
*
|
||||||
|
* <p>This method is experimental, and will be renamed or removed in a future release.
|
||||||
|
*/
|
||||||
|
default void onExperimentalOffloadedPlayback(boolean offloadedPlayback) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.ExoPlayer.AudioOffloadListener;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
import com.google.android.exoplayer2.analytics.PlayerId;
|
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||||
|
|
@ -265,6 +266,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
private boolean enableAudioTrackPlaybackParams;
|
private boolean enableAudioTrackPlaybackParams;
|
||||||
private int offloadMode;
|
private int offloadMode;
|
||||||
AudioTrackBufferSizeProvider audioTrackBufferSizeProvider;
|
AudioTrackBufferSizeProvider audioTrackBufferSizeProvider;
|
||||||
|
@Nullable AudioOffloadListener audioOffloadListener;
|
||||||
|
|
||||||
/** Creates a new builder. */
|
/** Creates a new builder. */
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
|
@ -370,6 +372,19 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an optional {@link AudioOffloadListener} to receive events relevant to offloaded
|
||||||
|
* playback.
|
||||||
|
*
|
||||||
|
* <p>The default value is null.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Builder setExperimentalAudioOffloadListener(
|
||||||
|
@Nullable AudioOffloadListener audioOffloadListener) {
|
||||||
|
this.audioOffloadListener = audioOffloadListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Builds the {@link DefaultAudioSink}. Must only be called once per Builder instance. */
|
/** Builds the {@link DefaultAudioSink}. Must only be called once per Builder instance. */
|
||||||
public DefaultAudioSink build() {
|
public DefaultAudioSink build() {
|
||||||
if (audioProcessorChain == null) {
|
if (audioProcessorChain == null) {
|
||||||
|
|
@ -500,6 +515,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
initializationExceptionPendingExceptionHolder;
|
initializationExceptionPendingExceptionHolder;
|
||||||
private final PendingExceptionHolder<WriteException> writeExceptionPendingExceptionHolder;
|
private final PendingExceptionHolder<WriteException> writeExceptionPendingExceptionHolder;
|
||||||
private final AudioTrackBufferSizeProvider audioTrackBufferSizeProvider;
|
private final AudioTrackBufferSizeProvider audioTrackBufferSizeProvider;
|
||||||
|
@Nullable private final AudioOffloadListener audioOffloadListener;
|
||||||
|
|
||||||
@Nullable private PlayerId playerId;
|
@Nullable private PlayerId playerId;
|
||||||
@Nullable private Listener listener;
|
@Nullable private Listener listener;
|
||||||
|
|
@ -660,6 +676,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
new PendingExceptionHolder<>(AUDIO_TRACK_RETRY_DURATION_MS);
|
new PendingExceptionHolder<>(AUDIO_TRACK_RETRY_DURATION_MS);
|
||||||
writeExceptionPendingExceptionHolder =
|
writeExceptionPendingExceptionHolder =
|
||||||
new PendingExceptionHolder<>(AUDIO_TRACK_RETRY_DURATION_MS);
|
new PendingExceptionHolder<>(AUDIO_TRACK_RETRY_DURATION_MS);
|
||||||
|
audioOffloadListener = builder.audioOffloadListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AudioSink implementation.
|
// AudioSink implementation.
|
||||||
|
|
@ -1087,7 +1104,12 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
|
|
||||||
private AudioTrack buildAudioTrack(Configuration configuration) throws InitializationException {
|
private AudioTrack buildAudioTrack(Configuration configuration) throws InitializationException {
|
||||||
try {
|
try {
|
||||||
return configuration.buildAudioTrack(tunneling, audioAttributes, audioSessionId);
|
AudioTrack audioTrack =
|
||||||
|
configuration.buildAudioTrack(tunneling, audioAttributes, audioSessionId);
|
||||||
|
if (audioOffloadListener != null) {
|
||||||
|
audioOffloadListener.onExperimentalOffloadedPlayback(isOffloadedPlayback(audioTrack));
|
||||||
|
}
|
||||||
|
return audioTrack;
|
||||||
} catch (InitializationException e) {
|
} catch (InitializationException e) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onAudioSinkError(e);
|
listener.onAudioSinkError(e);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue