mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
Fix some AudioProcessor nits
- Fix nullness warnings - Fix annotations - Make TeeAudioProcessor flush its sink for every format change PiperOrigin-RevId: 234017068
This commit is contained in:
parent
3e6cf42f83
commit
03006f0595
@ -194,10 +194,9 @@ public final class GvrAudioProcessor implements AudioProcessor {
|
||||
}
|
||||
|
||||
private void maybeReleaseGvrAudioSurround() {
|
||||
if (this.gvrAudioSurround != null) {
|
||||
GvrAudioSurround gvrAudioSurround = this.gvrAudioSurround;
|
||||
this.gvrAudioSurround = null;
|
||||
if (gvrAudioSurround != null) {
|
||||
gvrAudioSurround.release();
|
||||
gvrAudioSurround = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,10 @@ import java.util.Arrays;
|
||||
|
||||
private int channelCount;
|
||||
private int sampleRateHz;
|
||||
private @Nullable int[] pendingOutputChannels;
|
||||
@Nullable private int[] pendingOutputChannels;
|
||||
|
||||
private boolean active;
|
||||
private @Nullable int[] outputChannels;
|
||||
@Nullable private int[] outputChannels;
|
||||
private ByteBuffer buffer;
|
||||
private ByteBuffer outputBuffer;
|
||||
private boolean inputEnded;
|
||||
@ -112,7 +112,7 @@ import java.util.Arrays;
|
||||
|
||||
@Override
|
||||
public void queueInput(ByteBuffer inputBuffer) {
|
||||
Assertions.checkState(outputChannels != null);
|
||||
int[] outputChannels = Assertions.checkNotNull(this.outputChannels);
|
||||
int position = inputBuffer.position();
|
||||
int limit = inputBuffer.limit();
|
||||
int frameCount = (limit - position) / (2 * channelCount);
|
||||
|
@ -32,7 +32,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
private int sampleRateHz;
|
||||
private int channelCount;
|
||||
private @C.PcmEncoding int sourceEncoding;
|
||||
@C.PcmEncoding private int sourceEncoding;
|
||||
private ByteBuffer buffer;
|
||||
private ByteBuffer outputBuffer;
|
||||
private boolean inputEnded;
|
||||
|
@ -28,7 +28,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
private int sampleRateHz;
|
||||
private int channelCount;
|
||||
private @C.PcmEncoding int encoding;
|
||||
@C.PcmEncoding private int encoding;
|
||||
private ByteBuffer buffer;
|
||||
private ByteBuffer outputBuffer;
|
||||
private boolean inputEnded;
|
||||
|
@ -93,7 +93,7 @@ public final class SilenceSkippingAudioProcessor implements AudioProcessor {
|
||||
*/
|
||||
private byte[] paddingBuffer;
|
||||
|
||||
private @State int state;
|
||||
@State private int state;
|
||||
private int maybeSilenceBufferSize;
|
||||
private int paddingSize;
|
||||
private boolean hasOutputNoise;
|
||||
|
@ -69,7 +69,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
||||
private int outputSampleRateHz;
|
||||
private int pendingOutputSampleRateHz;
|
||||
|
||||
private @Nullable Sonic sonic;
|
||||
@Nullable private Sonic sonic;
|
||||
private ByteBuffer buffer;
|
||||
private ShortBuffer shortBuffer;
|
||||
private ByteBuffer outputBuffer;
|
||||
@ -201,7 +201,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
||||
|
||||
@Override
|
||||
public void queueInput(ByteBuffer inputBuffer) {
|
||||
Assertions.checkState(sonic != null);
|
||||
Sonic sonic = Assertions.checkNotNull(this.sonic);
|
||||
if (inputBuffer.hasRemaining()) {
|
||||
ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
|
||||
int inputSize = inputBuffer.remaining();
|
||||
@ -227,8 +227,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
||||
|
||||
@Override
|
||||
public void queueEndOfStream() {
|
||||
Assertions.checkState(sonic != null);
|
||||
sonic.queueEndOfStream();
|
||||
Assertions.checkNotNull(sonic).queueEndOfStream();
|
||||
inputEnded = true;
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,7 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
||||
|
||||
private int sampleRateHz;
|
||||
private int channelCount;
|
||||
private @C.Encoding int encoding;
|
||||
private boolean isActive;
|
||||
@C.Encoding private int encoding;
|
||||
|
||||
private ByteBuffer buffer;
|
||||
private ByteBuffer outputBuffer;
|
||||
@ -79,19 +78,21 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(int sampleRateHz, int channelCount, @C.Encoding int encoding)
|
||||
throws UnhandledFormatException {
|
||||
public boolean configure(int sampleRateHz, int channelCount, @C.Encoding int encoding) {
|
||||
boolean formatChanged =
|
||||
sampleRateHz != this.sampleRateHz
|
||||
|| channelCount != this.channelCount
|
||||
|| encoding != this.encoding;
|
||||
this.sampleRateHz = sampleRateHz;
|
||||
this.channelCount = channelCount;
|
||||
this.encoding = encoding;
|
||||
boolean wasActive = isActive;
|
||||
isActive = true;
|
||||
return !wasActive;
|
||||
// The sink always needs to be flushed if the format is changing.
|
||||
return formatChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return isActive;
|
||||
return sampleRateHz != Format.NO_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -145,7 +146,7 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
@Override
|
||||
public boolean isEnded() {
|
||||
return inputEnded && buffer == EMPTY_BUFFER;
|
||||
return inputEnded && outputBuffer == EMPTY_BUFFER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ import java.nio.ByteOrder;
|
||||
/** Audio processor for trimming samples from the start/end of data. */
|
||||
/* package */ final class TrimmingAudioProcessor implements AudioProcessor {
|
||||
|
||||
private static final int OUTPUT_ENCODING = C.ENCODING_PCM_16BIT;
|
||||
@C.Encoding private static final int OUTPUT_ENCODING = C.ENCODING_PCM_16BIT;
|
||||
|
||||
private boolean isActive;
|
||||
private int trimStartFrames;
|
||||
|
Loading…
x
Reference in New Issue
Block a user