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() {
|
private void maybeReleaseGvrAudioSurround() {
|
||||||
if (this.gvrAudioSurround != null) {
|
if (gvrAudioSurround != null) {
|
||||||
GvrAudioSurround gvrAudioSurround = this.gvrAudioSurround;
|
|
||||||
this.gvrAudioSurround = null;
|
|
||||||
gvrAudioSurround.release();
|
gvrAudioSurround.release();
|
||||||
|
gvrAudioSurround = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
private int channelCount;
|
private int channelCount;
|
||||||
private int sampleRateHz;
|
private int sampleRateHz;
|
||||||
private @Nullable int[] pendingOutputChannels;
|
@Nullable private int[] pendingOutputChannels;
|
||||||
|
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private @Nullable int[] outputChannels;
|
@Nullable private int[] outputChannels;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private ByteBuffer outputBuffer;
|
private ByteBuffer outputBuffer;
|
||||||
private boolean inputEnded;
|
private boolean inputEnded;
|
||||||
@ -112,7 +112,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueInput(ByteBuffer inputBuffer) {
|
public void queueInput(ByteBuffer inputBuffer) {
|
||||||
Assertions.checkState(outputChannels != null);
|
int[] outputChannels = Assertions.checkNotNull(this.outputChannels);
|
||||||
int position = inputBuffer.position();
|
int position = inputBuffer.position();
|
||||||
int limit = inputBuffer.limit();
|
int limit = inputBuffer.limit();
|
||||||
int frameCount = (limit - position) / (2 * channelCount);
|
int frameCount = (limit - position) / (2 * channelCount);
|
||||||
|
@ -32,7 +32,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
private int sampleRateHz;
|
private int sampleRateHz;
|
||||||
private int channelCount;
|
private int channelCount;
|
||||||
private @C.PcmEncoding int sourceEncoding;
|
@C.PcmEncoding private int sourceEncoding;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private ByteBuffer outputBuffer;
|
private ByteBuffer outputBuffer;
|
||||||
private boolean inputEnded;
|
private boolean inputEnded;
|
||||||
|
@ -28,7 +28,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
private int sampleRateHz;
|
private int sampleRateHz;
|
||||||
private int channelCount;
|
private int channelCount;
|
||||||
private @C.PcmEncoding int encoding;
|
@C.PcmEncoding private int encoding;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private ByteBuffer outputBuffer;
|
private ByteBuffer outputBuffer;
|
||||||
private boolean inputEnded;
|
private boolean inputEnded;
|
||||||
|
@ -93,7 +93,7 @@ public final class SilenceSkippingAudioProcessor implements AudioProcessor {
|
|||||||
*/
|
*/
|
||||||
private byte[] paddingBuffer;
|
private byte[] paddingBuffer;
|
||||||
|
|
||||||
private @State int state;
|
@State private int state;
|
||||||
private int maybeSilenceBufferSize;
|
private int maybeSilenceBufferSize;
|
||||||
private int paddingSize;
|
private int paddingSize;
|
||||||
private boolean hasOutputNoise;
|
private boolean hasOutputNoise;
|
||||||
|
@ -69,7 +69,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
|||||||
private int outputSampleRateHz;
|
private int outputSampleRateHz;
|
||||||
private int pendingOutputSampleRateHz;
|
private int pendingOutputSampleRateHz;
|
||||||
|
|
||||||
private @Nullable Sonic sonic;
|
@Nullable private Sonic sonic;
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private ShortBuffer shortBuffer;
|
private ShortBuffer shortBuffer;
|
||||||
private ByteBuffer outputBuffer;
|
private ByteBuffer outputBuffer;
|
||||||
@ -201,7 +201,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueInput(ByteBuffer inputBuffer) {
|
public void queueInput(ByteBuffer inputBuffer) {
|
||||||
Assertions.checkState(sonic != null);
|
Sonic sonic = Assertions.checkNotNull(this.sonic);
|
||||||
if (inputBuffer.hasRemaining()) {
|
if (inputBuffer.hasRemaining()) {
|
||||||
ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
|
ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
|
||||||
int inputSize = inputBuffer.remaining();
|
int inputSize = inputBuffer.remaining();
|
||||||
@ -227,8 +227,7 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueEndOfStream() {
|
public void queueEndOfStream() {
|
||||||
Assertions.checkState(sonic != null);
|
Assertions.checkNotNull(sonic).queueEndOfStream();
|
||||||
sonic.queueEndOfStream();
|
|
||||||
inputEnded = true;
|
inputEnded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
private int sampleRateHz;
|
private int sampleRateHz;
|
||||||
private int channelCount;
|
private int channelCount;
|
||||||
private @C.Encoding int encoding;
|
@C.Encoding private int encoding;
|
||||||
private boolean isActive;
|
|
||||||
|
|
||||||
private ByteBuffer buffer;
|
private ByteBuffer buffer;
|
||||||
private ByteBuffer outputBuffer;
|
private ByteBuffer outputBuffer;
|
||||||
@ -79,19 +78,21 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean configure(int sampleRateHz, int channelCount, @C.Encoding int encoding)
|
public boolean configure(int sampleRateHz, int channelCount, @C.Encoding int encoding) {
|
||||||
throws UnhandledFormatException {
|
boolean formatChanged =
|
||||||
|
sampleRateHz != this.sampleRateHz
|
||||||
|
|| channelCount != this.channelCount
|
||||||
|
|| encoding != this.encoding;
|
||||||
this.sampleRateHz = sampleRateHz;
|
this.sampleRateHz = sampleRateHz;
|
||||||
this.channelCount = channelCount;
|
this.channelCount = channelCount;
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
boolean wasActive = isActive;
|
// The sink always needs to be flushed if the format is changing.
|
||||||
isActive = true;
|
return formatChanged;
|
||||||
return !wasActive;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return isActive;
|
return sampleRateHz != Format.NO_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -145,7 +146,7 @@ public final class TeeAudioProcessor implements AudioProcessor {
|
|||||||
@SuppressWarnings("ReferenceEquality")
|
@SuppressWarnings("ReferenceEquality")
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnded() {
|
public boolean isEnded() {
|
||||||
return inputEnded && buffer == EMPTY_BUFFER;
|
return inputEnded && outputBuffer == EMPTY_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@ import java.nio.ByteOrder;
|
|||||||
/** Audio processor for trimming samples from the start/end of data. */
|
/** Audio processor for trimming samples from the start/end of data. */
|
||||||
/* package */ final class TrimmingAudioProcessor implements AudioProcessor {
|
/* 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 boolean isActive;
|
||||||
private int trimStartFrames;
|
private int trimStartFrames;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user