Add CanIgnoreReturnValue to AudioProcessor#configure + implementations

Although it can be useful to check the output format, it's not required or needed.

For some AudioProcessor implementations, it is stated/obvious that
the output format will match the input, in which case there is no
a need to check the return value.

#cleanup

PiperOrigin-RevId: 483403679
This commit is contained in:
samrobinson 2022-10-24 16:27:18 +00:00 committed by microkatz
parent bec504f1ac
commit a7bfa12eec
8 changed files with 17 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -96,6 +97,7 @@ public interface AudioProcessor {
* @return The configured output audio format if this instance is {@link #isActive() active}. * @return The configured output audio format if this instance is {@link #isActive() active}.
* @throws UnhandledAudioFormatException Thrown if the specified format can't be handled as input. * @throws UnhandledAudioFormatException Thrown if the specified format can't be handled as input.
*/ */
@CanIgnoreReturnValue
AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException; AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException;
/** Returns whether the processor is configured and will process input buffers. */ /** Returns whether the processor is configured and will process input buffers. */

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.audio; package com.google.android.exoplayer2.audio;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -47,6 +48,7 @@ public abstract class BaseAudioProcessor implements AudioProcessor {
} }
@Override @Override
@CanIgnoreReturnValue
public final AudioFormat configure(AudioFormat inputAudioFormat) public final AudioFormat configure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
pendingInputAudioFormat = inputAudioFormat; pendingInputAudioFormat = inputAudioFormat;
@ -121,6 +123,7 @@ public abstract class BaseAudioProcessor implements AudioProcessor {
} }
/** Called when the processor is configured for a new input format. */ /** Called when the processor is configured for a new input format. */
@CanIgnoreReturnValue
protected AudioFormat onConfigure(AudioFormat inputAudioFormat) protected AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
return AudioFormat.NOT_SET; return AudioFormat.NOT_SET;

View File

@ -19,6 +19,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
@ -44,6 +45,7 @@ import java.nio.ByteBuffer;
} }
@Override @Override
@CanIgnoreReturnValue
public AudioFormat onConfigure(AudioFormat inputAudioFormat) public AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
@Nullable int[] outputChannels = pendingOutputChannels; @Nullable int[] outputChannels = pendingOutputChannels;

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
@ -36,6 +37,7 @@ import java.nio.ByteBuffer;
private static final double PCM_32_BIT_INT_TO_PCM_32_BIT_FLOAT_FACTOR = 1.0 / 0x7FFFFFFF; private static final double PCM_32_BIT_INT_TO_PCM_32_BIT_FLOAT_FACTOR = 1.0 / 0x7FFFFFFF;
@Override @Override
@CanIgnoreReturnValue
public AudioFormat onConfigure(AudioFormat inputAudioFormat) public AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
@C.PcmEncoding int encoding = inputAudioFormat.encoding; @C.PcmEncoding int encoding = inputAudioFormat.encoding;

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
@ -36,6 +37,7 @@ import java.nio.ByteBuffer;
/* package */ final class ResamplingAudioProcessor extends BaseAudioProcessor { /* package */ final class ResamplingAudioProcessor extends BaseAudioProcessor {
@Override @Override
@CanIgnoreReturnValue
public AudioFormat onConfigure(AudioFormat inputAudioFormat) public AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
@C.PcmEncoding int encoding = inputAudioFormat.encoding; @C.PcmEncoding int encoding = inputAudioFormat.encoding;

View File

@ -22,6 +22,7 @@ import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -143,6 +144,7 @@ public final class SilenceSkippingAudioProcessor extends BaseAudioProcessor {
// AudioProcessor implementation. // AudioProcessor implementation.
@Override @Override
@CanIgnoreReturnValue
public AudioFormat onConfigure(AudioFormat inputAudioFormat) public AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) { if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {

View File

@ -21,6 +21,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
@ -140,6 +141,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
} }
@Override @Override
@CanIgnoreReturnValue
public AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException { public AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException {
if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) { if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) {
throw new UnhandledAudioFormatException(inputAudioFormat); throw new UnhandledAudioFormatException(inputAudioFormat);

View File

@ -23,6 +23,7 @@ import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.BaseAudioProcessor; import com.google.android.exoplayer2.audio.BaseAudioProcessor;
import com.google.android.exoplayer2.audio.SonicAudioProcessor; import com.google.android.exoplayer2.audio.SonicAudioProcessor;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
@ -52,6 +53,7 @@ import java.nio.ByteBuffer;
} }
@Override @Override
@CanIgnoreReturnValue
public AudioFormat onConfigure(AudioFormat inputAudioFormat) public AudioFormat onConfigure(AudioFormat inputAudioFormat)
throws UnhandledAudioFormatException { throws UnhandledAudioFormatException {
return sonicAudioProcessor.configure(inputAudioFormat); return sonicAudioProcessor.configure(inputAudioFormat);