mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Misc cleanup.
- Remove some unnecessary condition checking. - Rename variable to a better name.
This commit is contained in:
parent
dc94e44b1f
commit
963e604ffd
2 changed files with 11 additions and 12 deletions
|
|
@ -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 {
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
(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 {
|
||||||
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();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue