Let HardwareVideoEncoder cache result from codec.getOutputBuffers()
Bug: webrtc:9378 Change-Id: I27d6fa9780a0fbb4607ad4d05dabf4414fe6b091 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/142173 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28288}
This commit is contained in:
@ -88,6 +88,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
|
||||
// --- Valid and immutable while an encoding session is running.
|
||||
@Nullable private MediaCodecWrapper codec;
|
||||
@Nullable private ByteBuffer[] outputBuffers;
|
||||
// Thread that delivers encoded frames to the user callback.
|
||||
@Nullable private Thread outputThread;
|
||||
|
||||
@ -222,6 +223,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
}
|
||||
|
||||
codec.start();
|
||||
outputBuffers = codec.getOutputBuffers();
|
||||
} catch (IllegalStateException e) {
|
||||
Logging.e(TAG, "initEncodeInternal failed", e);
|
||||
release();
|
||||
@ -271,6 +273,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
outputBuilders.clear();
|
||||
|
||||
codec = null;
|
||||
outputBuffers = null;
|
||||
outputThread = null;
|
||||
|
||||
// Allow changing thread after release.
|
||||
@ -488,10 +491,13 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
|
||||
int index = codec.dequeueOutputBuffer(info, DEQUEUE_OUTPUT_BUFFER_TIMEOUT_US);
|
||||
if (index < 0) {
|
||||
if (index == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
|
||||
outputBuffers = codec.getOutputBuffers();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuffer codecOutputBuffer = codec.getOutputBuffers()[index];
|
||||
ByteBuffer codecOutputBuffer = outputBuffers[index];
|
||||
codecOutputBuffer.position(info.offset);
|
||||
codecOutputBuffer.limit(info.offset + info.size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user