Added user-defined predicate to filter video codec implementations.

Ability to provide user defined predicate to disable particular
codec in particular circumstances was added. This could help
addressing mysterious crashes on specific Android devices.

Bug: webrtc:10029
Change-Id: I7ad81f4b1351aa68f036c0ee3b6d32fbf0f697ed
Reviewed-on: https://webrtc-review.googlesource.com/c/111781
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25820}
This commit is contained in:
Yura Yaroshevich
2018-11-28 15:41:17 +03:00
committed by Commit Bot
parent 7f7e973362
commit 68478b8287
6 changed files with 179 additions and 30 deletions

View File

@ -42,9 +42,34 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
@Nullable private final EglBase14.Context sharedContext;
private final boolean enableIntelVp8Encoder;
private final boolean enableH264HighProfile;
@Nullable private final Predicate<MediaCodecInfo> codecAllowedPredicate;
/**
* Creates a HardwareVideoEncoderFactory that supports surface texture encoding.
*
* @param sharedContext The textures generated will be accessible from this context. May be null,
* this disables texture support.
* @param enableIntelVp8Encoder true if Intel's VP8 encoder enabled.
* @param enableH264HighProfile true if H264 High Profile enabled.
*/
public HardwareVideoEncoderFactory(
EglBase.Context sharedContext, boolean enableIntelVp8Encoder, boolean enableH264HighProfile) {
this(sharedContext, enableIntelVp8Encoder, enableH264HighProfile,
/* codecAllowedPredicate= */ null);
}
/**
* Creates a HardwareVideoEncoderFactory that supports surface texture encoding.
*
* @param sharedContext The textures generated will be accessible from this context. May be null,
* this disables texture support.
* @param enableIntelVp8Encoder true if Intel's VP8 encoder enabled.
* @param enableH264HighProfile true if H264 High Profile enabled.
* @param codecAllowedPredicate optional predicate to filter codecs. All codecs are allowed
* when predicate is not provided.
*/
public HardwareVideoEncoderFactory(EglBase.Context sharedContext, boolean enableIntelVp8Encoder,
boolean enableH264HighProfile, @Nullable Predicate<MediaCodecInfo> codecAllowedPredicate) {
// Texture mode requires EglBase14.
if (sharedContext instanceof EglBase14.Context) {
this.sharedContext = (EglBase14.Context) sharedContext;
@ -54,6 +79,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
}
this.enableIntelVp8Encoder = enableIntelVp8Encoder;
this.enableH264HighProfile = enableH264HighProfile;
this.codecAllowedPredicate = codecAllowedPredicate;
}
@Deprecated
@ -164,7 +190,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
== null) {
return false;
}
return isHardwareSupportedInCurrentSdk(info, type);
return isHardwareSupportedInCurrentSdk(info, type) && isMediaCodecAllowed(info);
}
// Returns true if the given MediaCodecInfo indicates a hardware module that is supported on the
@ -212,6 +238,13 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
}
private boolean isMediaCodecAllowed(MediaCodecInfo info) {
if (codecAllowedPredicate == null) {
return true;
}
return codecAllowedPredicate.test(info);
}
private int getKeyFrameIntervalSec(VideoCodecType type) {
switch (type) {
case VP8: // Fallthrough intended.