Add unit tests for hardware video codecs.
Bug: webrtc:9594 Change-Id: I4529a5123997e0309bde1b931bb6d99bea8c0dfd Reviewed-on: https://webrtc-review.googlesource.com/92399 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24223}
This commit is contained in:

committed by
Commit Bot

parent
39a44b2134
commit
a381871dbf
@ -53,6 +53,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
private static final int DEQUEUE_OUTPUT_BUFFER_TIMEOUT_US = 100000;
|
||||
|
||||
// --- Initialized on construction.
|
||||
private final MediaCodecWrapperFactory mediaCodecWrapperFactory;
|
||||
private final String codecName;
|
||||
private final VideoCodecType codecType;
|
||||
private final Integer surfaceColorFormat;
|
||||
@ -82,7 +83,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
private boolean automaticResizeOn;
|
||||
|
||||
// --- Valid and immutable while an encoding session is running.
|
||||
@Nullable private MediaCodec codec;
|
||||
@Nullable private MediaCodecWrapper codec;
|
||||
// Thread that delivers encoded frames to the user callback.
|
||||
@Nullable private Thread outputThread;
|
||||
|
||||
@ -128,10 +129,11 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
* desired bitrates
|
||||
* @throws IllegalArgumentException if colorFormat is unsupported
|
||||
*/
|
||||
public HardwareVideoEncoder(String codecName, VideoCodecType codecType,
|
||||
Integer surfaceColorFormat, Integer yuvColorFormat, Map<String, String> params,
|
||||
int keyFrameIntervalSec, int forceKeyFrameIntervalMs, BitrateAdjuster bitrateAdjuster,
|
||||
EglBase14.Context sharedContext) {
|
||||
public HardwareVideoEncoder(MediaCodecWrapperFactory mediaCodecWrapperFactory, String codecName,
|
||||
VideoCodecType codecType, Integer surfaceColorFormat, Integer yuvColorFormat,
|
||||
Map<String, String> params, int keyFrameIntervalSec, int forceKeyFrameIntervalMs,
|
||||
BitrateAdjuster bitrateAdjuster, EglBase14.Context sharedContext) {
|
||||
this.mediaCodecWrapperFactory = mediaCodecWrapperFactory;
|
||||
this.codecName = codecName;
|
||||
this.codecType = codecType;
|
||||
this.surfaceColorFormat = surfaceColorFormat;
|
||||
@ -174,7 +176,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
lastKeyFrameNs = -1;
|
||||
|
||||
try {
|
||||
codec = MediaCodec.createByCodecName(codecName);
|
||||
codec = mediaCodecWrapperFactory.createByCodecName(codecName);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Logging.e(TAG, "Cannot create media encoder " + codecName);
|
||||
return VideoCodecStatus.FALLBACK_SOFTWARE;
|
||||
@ -384,7 +386,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
Logging.e(TAG, "getInputBuffers failed", e);
|
||||
return VideoCodecStatus.ERROR;
|
||||
}
|
||||
yuvFormat.fillBuffer(buffer, videoFrameBuffer);
|
||||
fillInputBuffer(buffer, videoFrameBuffer);
|
||||
|
||||
try {
|
||||
codec.queueInputBuffer(
|
||||
@ -481,7 +483,8 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
};
|
||||
}
|
||||
|
||||
private void deliverEncodedImage() {
|
||||
// Visible for testing.
|
||||
protected void deliverEncodedImage() {
|
||||
outputThreadChecker.checkIsOnValidThread();
|
||||
try {
|
||||
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
|
||||
@ -576,6 +579,11 @@ class HardwareVideoEncoder implements VideoEncoder {
|
||||
return sharedContext != null && surfaceColorFormat != null;
|
||||
}
|
||||
|
||||
// Visible for testing.
|
||||
protected void fillInputBuffer(ByteBuffer buffer, VideoFrame.Buffer videoFrameBuffer) {
|
||||
yuvFormat.fillBuffer(buffer, videoFrameBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumeration of supported YUV color formats used for MediaCodec's input.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user