mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Tweak offload disable Javadoc
PiperOrigin-RevId: 326998407
This commit is contained in:
parent
10fa745fab
commit
02ed809a18
1 changed files with 17 additions and 18 deletions
|
|
@ -327,15 +327,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
private AuxEffectInfo auxEffectInfo;
|
private AuxEffectInfo auxEffectInfo;
|
||||||
private boolean tunneling;
|
private boolean tunneling;
|
||||||
private long lastFeedElapsedRealtimeMs;
|
private long lastFeedElapsedRealtimeMs;
|
||||||
/**
|
private boolean offloadDisabledUntilNextConfiguration;
|
||||||
* Do not retrying offload if it just failed.
|
|
||||||
*
|
|
||||||
* <p>{@link AudioManager#isOffloadedPlaybackSupported(AudioFormat,
|
|
||||||
* android.media.AudioAttributes)} does not guaranty that offload is available (eg: using {@link
|
|
||||||
* android.media.AudioPlaybackCaptureConfiguration}) will disable offload. As a result only try
|
|
||||||
* once per track/seek to play in offload mode.
|
|
||||||
*/
|
|
||||||
private boolean disableOffloadAfterFailureUntilNextConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new default audio sink.
|
* Creates a new default audio sink.
|
||||||
|
|
@ -466,7 +458,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
return SINK_FORMAT_SUPPORTED_WITH_TRANSCODING;
|
return SINK_FORMAT_SUPPORTED_WITH_TRANSCODING;
|
||||||
}
|
}
|
||||||
if (enableOffload
|
if (enableOffload
|
||||||
&& !disableOffloadAfterFailureUntilNextConfiguration
|
&& !offloadDisabledUntilNextConfiguration
|
||||||
&& isOffloadedPlaybackSupported(format, audioAttributes)) {
|
&& isOffloadedPlaybackSupported(format, audioAttributes)) {
|
||||||
return SINK_FORMAT_SUPPORTED_DIRECTLY;
|
return SINK_FORMAT_SUPPORTED_DIRECTLY;
|
||||||
}
|
}
|
||||||
|
|
@ -575,8 +567,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
"Invalid output channel config (mode=" + outputMode + ") for: " + inputFormat);
|
"Invalid output channel config (mode=" + outputMode + ") for: " + inputFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
disableOffloadAfterFailureUntilNextConfiguration = false;
|
offloadDisabledUntilNextConfiguration = false;
|
||||||
|
|
||||||
Configuration pendingConfiguration =
|
Configuration pendingConfiguration =
|
||||||
new Configuration(
|
new Configuration(
|
||||||
inputFormat,
|
inputFormat,
|
||||||
|
|
@ -836,9 +827,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
return Assertions.checkNotNull(configuration)
|
return Assertions.checkNotNull(configuration)
|
||||||
.buildAudioTrack(tunneling, audioAttributes, audioSessionId);
|
.buildAudioTrack(tunneling, audioAttributes, audioSessionId);
|
||||||
} catch (InitializationException e) {
|
} catch (InitializationException e) {
|
||||||
if (configuration.outputModeIsOffload()) {
|
maybeDisableOffload();
|
||||||
disableOffloadAfterFailureUntilNextConfiguration = true;
|
|
||||||
}
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -929,8 +918,8 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
|
|
||||||
if (bytesWritten < 0) {
|
if (bytesWritten < 0) {
|
||||||
boolean isRecoverable = isAudioTrackDeadObject(bytesWritten);
|
boolean isRecoverable = isAudioTrackDeadObject(bytesWritten);
|
||||||
if (isRecoverable && configuration.outputModeIsOffload()) {
|
if (isRecoverable) {
|
||||||
disableOffloadAfterFailureUntilNextConfiguration = true;
|
maybeDisableOffload();
|
||||||
}
|
}
|
||||||
throw new WriteException(bytesWritten);
|
throw new WriteException(bytesWritten);
|
||||||
}
|
}
|
||||||
|
|
@ -966,6 +955,16 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maybeDisableOffload() {
|
||||||
|
if (!configuration.outputModeIsOffload()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Offload was requested, but may not be available. There are cases when this can occur even if
|
||||||
|
// AudioManager.isOffloadedPlaybackSupported returned true. For example, due to use of an
|
||||||
|
// AudioPlaybackCaptureConfiguration. Disable offload until the sink is next configured.
|
||||||
|
offloadDisabledUntilNextConfiguration = true;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isAudioTrackDeadObject(int status) {
|
private static boolean isAudioTrackDeadObject(int status) {
|
||||||
return Util.SDK_INT >= 24 && status == AudioTrack.ERROR_DEAD_OBJECT;
|
return Util.SDK_INT >= 24 && status == AudioTrack.ERROR_DEAD_OBJECT;
|
||||||
}
|
}
|
||||||
|
|
@ -1200,7 +1199,7 @@ public final class DefaultAudioSink implements AudioSink {
|
||||||
}
|
}
|
||||||
audioSessionId = C.AUDIO_SESSION_ID_UNSET;
|
audioSessionId = C.AUDIO_SESSION_ID_UNSET;
|
||||||
playing = false;
|
playing = false;
|
||||||
disableOffloadAfterFailureUntilNextConfiguration = false;
|
offloadDisabledUntilNextConfiguration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue