Commit 963e604f by Oliver Woodman

Misc cleanup.

- Remove some unnecessary condition checking.
- Rename variable to a better name.
parent dc94e44b
...@@ -450,9 +450,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer ...@@ -450,9 +450,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
if (format == null) { if (format == null) {
readFormat(positionUs); readFormat(positionUs);
} }
if (codec == null && shouldInitCodec()) {
maybeInitCodec(); maybeInitCodec();
}
if (codec != null) { if (codec != null) {
TraceUtil.beginSection("drainAndFeed"); TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {} while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
......
...@@ -221,7 +221,7 @@ public final class AudioTrack { ...@@ -221,7 +221,7 @@ public final class AudioTrack {
private byte[] temporaryBuffer; private byte[] temporaryBuffer;
private int temporaryBufferOffset; private int temporaryBufferOffset;
private int temporaryBufferSize; private int bufferBytesRemaining;
/** /**
* Creates an audio track with default audio capabilities (no encoded audio passthrough support). * Creates an audio track with default audio capabilities (no encoded audio passthrough support).
...@@ -553,9 +553,10 @@ public final class AudioTrack { ...@@ -553,9 +553,10 @@ public final class AudioTrack {
} }
int result = 0; int result = 0;
if (temporaryBufferSize == 0) { if (bufferBytesRemaining == 0) {
// This is the first time we've seen this {@code buffer}. // The previous buffer (if there was one) was fully written to the audio track. We're now
temporaryBufferSize = size; // seeing a new buffer for the first time.
bufferBytesRemaining = size;
buffer.position(offset); buffer.position(offset);
if (passthrough && framesPerEncodedSample == 0) { if (passthrough && framesPerEncodedSample == 0) {
// If this is the first encoded sample, calculate the sample size in frames. // If this is the first encoded sample, calculate the sample size in frames.
...@@ -602,25 +603,25 @@ public final class AudioTrack { ...@@ -602,25 +603,25 @@ public final class AudioTrack {
(int) (submittedPcmBytes - (audioTrackUtil.getPlaybackHeadPosition() * pcmFrameSize)); (int) (submittedPcmBytes - (audioTrackUtil.getPlaybackHeadPosition() * pcmFrameSize));
int bytesToWrite = bufferSize - bytesPending; int bytesToWrite = bufferSize - bytesPending;
if (bytesToWrite > 0) { if (bytesToWrite > 0) {
bytesToWrite = Math.min(temporaryBufferSize, bytesToWrite); bytesToWrite = Math.min(bufferBytesRemaining, bytesToWrite);
bytesWritten = audioTrack.write(temporaryBuffer, temporaryBufferOffset, bytesToWrite); bytesWritten = audioTrack.write(temporaryBuffer, temporaryBufferOffset, bytesToWrite);
if (bytesWritten >= 0) { if (bytesWritten >= 0) {
temporaryBufferOffset += bytesWritten; temporaryBufferOffset += bytesWritten;
} }
} }
} else { } else {
bytesWritten = writeNonBlockingV21(audioTrack, buffer, temporaryBufferSize); bytesWritten = writeNonBlockingV21(audioTrack, buffer, bufferBytesRemaining);
} }
if (bytesWritten < 0) { if (bytesWritten < 0) {
throw new WriteException(bytesWritten); throw new WriteException(bytesWritten);
} }
temporaryBufferSize -= bytesWritten; bufferBytesRemaining -= bytesWritten;
if (!passthrough) { if (!passthrough) {
submittedPcmBytes += bytesWritten; submittedPcmBytes += bytesWritten;
} }
if (temporaryBufferSize == 0) { if (bufferBytesRemaining == 0) {
if (passthrough) { if (passthrough) {
submittedEncodedFrames += framesPerEncodedSample; submittedEncodedFrames += framesPerEncodedSample;
} }
...@@ -704,7 +705,7 @@ public final class AudioTrack { ...@@ -704,7 +705,7 @@ public final class AudioTrack {
submittedPcmBytes = 0; submittedPcmBytes = 0;
submittedEncodedFrames = 0; submittedEncodedFrames = 0;
framesPerEncodedSample = 0; framesPerEncodedSample = 0;
temporaryBufferSize = 0; bufferBytesRemaining = 0;
startMediaTimeState = START_NOT_SET; startMediaTimeState = START_NOT_SET;
latencyUs = 0; latencyUs = 0;
resetSyncParams(); resetSyncParams();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment