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.
|
* Queues an input buffer to the decoder. No buffers may be queued after an {@link
|
||||||
*
|
* DecoderInputBuffer#isEndOfStream() end of stream} buffer has been queued.
|
||||||
* @param inputBuffer The buffer to be queued.
|
|
||||||
* @return Whether more input buffers can be queued.
|
|
||||||
*/
|
*/
|
||||||
public boolean queueInputBuffer(DecoderInputBuffer inputBuffer) {
|
public void queueInputBuffer(DecoderInputBuffer inputBuffer) {
|
||||||
checkState(
|
checkState(
|
||||||
!inputStreamEnded, "Input buffer can not be queued after the input stream has ended.");
|
!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);
|
codec.queueInputBuffer(inputBufferIndex, offset, size, inputBuffer.timeUs, flags);
|
||||||
inputBufferIndex = C.INDEX_UNSET;
|
inputBufferIndex = C.INDEX_UNSET;
|
||||||
inputBuffer.data = null;
|
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:
|
case C.RESULT_BUFFER_READ:
|
||||||
mediaClock.updateTimeForTrackType(getTrackType(), decoderInputBuffer.timeUs);
|
mediaClock.updateTimeForTrackType(getTrackType(), decoderInputBuffer.timeUs);
|
||||||
decoderInputBuffer.flip();
|
decoderInputBuffer.flip();
|
||||||
return decoder.queueInputBuffer(decoderInputBuffer);
|
decoder.queueInputBuffer(decoderInputBuffer);
|
||||||
|
return !decoderInputBuffer.isEndOfStream();
|
||||||
case C.RESULT_FORMAT_READ:
|
case C.RESULT_FORMAT_READ:
|
||||||
throw new IllegalStateException("Format changes are not supported.");
|
throw new IllegalStateException("Format changes are not supported.");
|
||||||
case C.RESULT_NOTHING_READ:
|
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
|
* Feeds as much data as possible between the current position and limit of the specified {@link
|
||||||
* returns whether it may be possible to write more data.
|
* 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);
|
AudioFormat encoderInputAudioFormat = checkNotNull(this.encoderInputAudioFormat);
|
||||||
MediaCodecAdapterWrapper encoder = checkNotNull(this.encoder);
|
MediaCodecAdapterWrapper encoder = checkNotNull(this.encoder);
|
||||||
ByteBuffer encoderInputBufferData = checkNotNull(encoderInputBuffer.data);
|
ByteBuffer encoderInputBufferData = checkNotNull(encoderInputBuffer.data);
|
||||||
int bufferLimit = inputBuffer.limit();
|
int bufferLimit = inputBuffer.limit();
|
||||||
inputBuffer.limit(min(bufferLimit, inputBuffer.position() + encoderInputBufferData.capacity()));
|
inputBuffer.limit(min(bufferLimit, inputBuffer.position() + encoderInputBufferData.capacity()));
|
||||||
|
|
||||||
encoderInputBufferData.put(inputBuffer);
|
encoderInputBufferData.put(inputBuffer);
|
||||||
encoderInputBuffer.timeUs = nextEncoderInputBufferTimeUs;
|
encoderInputBuffer.timeUs = nextEncoderInputBufferTimeUs;
|
||||||
nextEncoderInputBufferTimeUs +=
|
nextEncoderInputBufferTimeUs +=
|
||||||
@ -320,12 +321,10 @@ import java.nio.ByteBuffer;
|
|||||||
/* bytesWritten= */ encoderInputBufferData.position(),
|
/* bytesWritten= */ encoderInputBufferData.position(),
|
||||||
encoderInputAudioFormat.bytesPerFrame,
|
encoderInputAudioFormat.bytesPerFrame,
|
||||||
encoderInputAudioFormat.sampleRate);
|
encoderInputAudioFormat.sampleRate);
|
||||||
|
|
||||||
encoderInputBuffer.setFlags(0);
|
encoderInputBuffer.setFlags(0);
|
||||||
encoderInputBuffer.flip();
|
encoderInputBuffer.flip();
|
||||||
inputBuffer.limit(bufferLimit);
|
inputBuffer.limit(bufferLimit);
|
||||||
|
encoder.queueInputBuffer(encoderInputBuffer);
|
||||||
return encoder.queueInputBuffer(encoderInputBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueEndOfStreamToEncoder() {
|
private void queueEndOfStreamToEncoder() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user