mirror of
https://github.com/androidx/media.git
synced 2025-05-11 09:39:52 +08:00
Simplify feeding codec input in transformer
The caller knows whether it's queued end-of-stream, so we can remove the return value of the method. #minor-release PiperOrigin-RevId: 354888298
This commit is contained in:
parent
35b99d634f
commit
91dcf39db5
@ -159,12 +159,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues an input buffer.
|
||||
*
|
||||
* @param inputBuffer The buffer to be queued.
|
||||
* @return Whether more input buffers can be queued.
|
||||
* Queues an input buffer to the decoder. No buffers may be queued after an {@link
|
||||
* DecoderInputBuffer#isEndOfStream() end of stream} buffer has been queued.
|
||||
*/
|
||||
public boolean queueInputBuffer(DecoderInputBuffer inputBuffer) {
|
||||
public void queueInputBuffer(DecoderInputBuffer inputBuffer) {
|
||||
checkState(
|
||||
!inputStreamEnded, "Input buffer can not be queued after the input stream has ended.");
|
||||
|
||||
@ -182,7 +180,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
codec.queueInputBuffer(inputBufferIndex, offset, size, inputBuffer.timeUs, flags);
|
||||
inputBufferIndex = C.INDEX_UNSET;
|
||||
inputBuffer.data = null;
|
||||
return !inputStreamEnded;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +226,8 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return feedEncoder(sonicOutputBuffer);
|
||||
feedEncoder(sonicOutputBuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,7 +294,8 @@ import java.nio.ByteBuffer;
|
||||
case C.RESULT_BUFFER_READ:
|
||||
mediaClock.updateTimeForTrackType(getTrackType(), decoderInputBuffer.timeUs);
|
||||
decoderInputBuffer.flip();
|
||||
return decoder.queueInputBuffer(decoderInputBuffer);
|
||||
decoder.queueInputBuffer(decoderInputBuffer);
|
||||
return !decoderInputBuffer.isEndOfStream();
|
||||
case C.RESULT_FORMAT_READ:
|
||||
throw new IllegalStateException("Format changes are not supported.");
|
||||
case C.RESULT_NOTHING_READ:
|
||||
@ -303,16 +305,15 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds the encoder the {@link ByteBuffer inputBuffer} with the correct {@code timeUs}, and
|
||||
* returns whether it may be possible to write more data.
|
||||
* Feeds as much data as possible between the current position and limit of the specified {@link
|
||||
* ByteBuffer} to the encoder, and advances its position by the number of bytes fed.
|
||||
*/
|
||||
private boolean feedEncoder(ByteBuffer inputBuffer) {
|
||||
private void feedEncoder(ByteBuffer inputBuffer) {
|
||||
AudioFormat encoderInputAudioFormat = checkNotNull(this.encoderInputAudioFormat);
|
||||
MediaCodecAdapterWrapper encoder = checkNotNull(this.encoder);
|
||||
ByteBuffer encoderInputBufferData = checkNotNull(encoderInputBuffer.data);
|
||||
int bufferLimit = inputBuffer.limit();
|
||||
inputBuffer.limit(min(bufferLimit, inputBuffer.position() + encoderInputBufferData.capacity()));
|
||||
|
||||
encoderInputBufferData.put(inputBuffer);
|
||||
encoderInputBuffer.timeUs = nextEncoderInputBufferTimeUs;
|
||||
nextEncoderInputBufferTimeUs +=
|
||||
@ -320,12 +321,10 @@ import java.nio.ByteBuffer;
|
||||
/* bytesWritten= */ encoderInputBufferData.position(),
|
||||
encoderInputAudioFormat.bytesPerFrame,
|
||||
encoderInputAudioFormat.sampleRate);
|
||||
|
||||
encoderInputBuffer.setFlags(0);
|
||||
encoderInputBuffer.flip();
|
||||
inputBuffer.limit(bufferLimit);
|
||||
|
||||
return encoder.queueInputBuffer(encoderInputBuffer);
|
||||
encoder.queueInputBuffer(encoderInputBuffer);
|
||||
}
|
||||
|
||||
private void queueEndOfStreamToEncoder() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user