mirror of
https://github.com/samsonjs/media.git
synced 2026-04-09 11:55:46 +00:00
Split creation of AudioCapabilitiesReceiver from instance access
getAudioCapabilities currently creates the receiver and returns the current capabilities. This is error-prone because the capabilities are also available as a class field. This can made cleaner by letting the method just create the receiver and all access to the capabilities can be made via class field. PiperOrigin-RevId: 592591590
This commit is contained in:
parent
770ca66fbc
commit
98519931e7
1 changed files with 7 additions and 6 deletions
|
|
@ -536,7 +536,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
@Nullable private ByteBuffer inputBuffer;
|
||||
private int inputBufferAccessUnitCount;
|
||||
@Nullable private ByteBuffer outputBuffer;
|
||||
private @MonotonicNonNull byte[] preV21OutputBuffer;
|
||||
private byte @MonotonicNonNull [] preV21OutputBuffer;
|
||||
private int preV21OutputBufferOffset;
|
||||
private boolean handledEndOfStream;
|
||||
private boolean stoppedAudioTrack;
|
||||
|
|
@ -616,6 +616,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
|
||||
@Override
|
||||
public @SinkFormatSupport int getFormatSupport(Format format) {
|
||||
maybeStartAudioCapabilitiesReceiver();
|
||||
if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)) {
|
||||
if (!Util.isEncodingLinearPcm(format.pcmEncoding)) {
|
||||
Log.w(TAG, "Invalid PCM encoding: " + format.pcmEncoding);
|
||||
|
|
@ -629,7 +630,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
// guaranteed to support.
|
||||
return SINK_FORMAT_SUPPORTED_WITH_TRANSCODING;
|
||||
}
|
||||
if (getAudioCapabilities().isPassthroughPlaybackSupported(format)) {
|
||||
if (audioCapabilities.isPassthroughPlaybackSupported(format)) {
|
||||
return SINK_FORMAT_SUPPORTED_DIRECTLY;
|
||||
}
|
||||
return SINK_FORMAT_UNSUPPORTED;
|
||||
|
|
@ -666,6 +667,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
boolean enableAudioTrackPlaybackParams;
|
||||
boolean enableOffloadGapless = false;
|
||||
|
||||
maybeStartAudioCapabilitiesReceiver();
|
||||
if (MimeTypes.AUDIO_RAW.equals(inputFormat.sampleMimeType)) {
|
||||
Assertions.checkArgument(Util.isEncodingLinearPcm(inputFormat.pcmEncoding));
|
||||
|
||||
|
|
@ -734,7 +736,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
outputMode = OUTPUT_MODE_PASSTHROUGH;
|
||||
@Nullable
|
||||
Pair<Integer, Integer> encodingAndChannelConfig =
|
||||
getAudioCapabilities().getEncodingAndChannelConfigForPassthrough(inputFormat);
|
||||
audioCapabilities.getEncodingAndChannelConfigForPassthrough(inputFormat);
|
||||
if (encodingAndChannelConfig == null) {
|
||||
throw new ConfigurationException(
|
||||
"Unable to configure passthrough for: " + inputFormat, inputFormat);
|
||||
|
|
@ -1490,7 +1492,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
|
||||
public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) {
|
||||
checkState(playbackLooper == Looper.myLooper());
|
||||
if (!audioCapabilities.equals(getAudioCapabilities())) {
|
||||
if (!audioCapabilities.equals(this.audioCapabilities)) {
|
||||
this.audioCapabilities = audioCapabilities;
|
||||
if (listener != null) {
|
||||
listener.onAudioCapabilitiesChanged();
|
||||
|
|
@ -1703,7 +1705,7 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
: writtenEncodedFrames;
|
||||
}
|
||||
|
||||
private AudioCapabilities getAudioCapabilities() {
|
||||
private void maybeStartAudioCapabilitiesReceiver() {
|
||||
if (audioCapabilitiesReceiver == null && context != null) {
|
||||
// Must be lazily initialized to receive audio capabilities receiver listener event on the
|
||||
// current (playback) thread as the constructor is not called in the playback thread.
|
||||
|
|
@ -1712,7 +1714,6 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
new AudioCapabilitiesReceiver(context, this::onAudioCapabilitiesChanged);
|
||||
audioCapabilities = audioCapabilitiesReceiver.register();
|
||||
}
|
||||
return audioCapabilities;
|
||||
}
|
||||
|
||||
private static boolean isOffloadedPlayback(AudioTrack audioTrack) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue