Injectable software codecs for Android.

This is similar to https://webrtc-review.googlesource.com/c/src/+/3620
for iOS.

Using the new WebRtcMediaEngineFactory::Create API, the built-in
software video codecs are no longer appended to the injected codecs.

To be able to use the software codecs, they are exposed as Java
classes through SoftwareVideoEncoderFactory etc.

There is also a new DefaultVideoEncoderFactory used by AppRTCMobile.
This factory tries to use hardware implementations where available,
but falls back to using the injected software codecs.

The HardwareVideoEncoderFactory is temporarily also falling back on
the software codecs in its default configuration in order to
maintain backwards compatibility.

Bug: webrtc:7925
Change-Id: I3e8c5ed492ccd160aca968986ad217d7978a951c
Reviewed-on: https://webrtc-review.googlesource.com/17480
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20647}
This commit is contained in:
Anders Carlsson
2017-11-10 13:15:04 +01:00
committed by Commit Bot
parent 45bbc8ac19
commit dc1b9f179a
39 changed files with 1171 additions and 170 deletions

View File

@ -42,9 +42,16 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
private final EglBase14.Context sharedContext;
private final boolean enableIntelVp8Encoder;
private final boolean enableH264HighProfile;
private final boolean fallbackToSoftware;
public HardwareVideoEncoderFactory(
EglBase.Context sharedContext, boolean enableIntelVp8Encoder, boolean enableH264HighProfile) {
this(
sharedContext, enableIntelVp8Encoder, enableH264HighProfile, true /* fallbackToSoftware */);
}
HardwareVideoEncoderFactory(EglBase.Context sharedContext, boolean enableIntelVp8Encoder,
boolean enableH264HighProfile, boolean fallbackToSoftware) {
// Texture mode requires EglBase14.
if (sharedContext instanceof EglBase14.Context) {
this.sharedContext = (EglBase14.Context) sharedContext;
@ -54,6 +61,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
}
this.enableIntelVp8Encoder = enableIntelVp8Encoder;
this.enableH264HighProfile = enableH264HighProfile;
this.fallbackToSoftware = fallbackToSoftware;
}
@Deprecated
@ -67,7 +75,15 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
MediaCodecInfo info = findCodecForType(type);
if (info == null) {
return null; // No support for this type.
// No hardware support for this type.
// TODO(andersc): This is for backwards compatibility. Remove when clients have migrated to
// new DefaultVideoEncoderFactory.
if (fallbackToSoftware) {
SoftwareVideoEncoderFactory softwareVideoEncoderFactory = new SoftwareVideoEncoderFactory();
return softwareVideoEncoderFactory.createEncoder(input);
} else {
return null;
}
}
String codecName = info.getName();
@ -93,12 +109,23 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
if (codec != null) {
String name = type.name();
if (type == VideoCodecType.H264 && isH264HighProfileSupported(codec)) {
supportedCodecInfos.add(new VideoCodecInfo(0, name, getCodecProperties(type, true)));
supportedCodecInfos.add(new VideoCodecInfo(name, getCodecProperties(type, true)));
}
supportedCodecInfos.add(new VideoCodecInfo(0, name, getCodecProperties(type, false)));
supportedCodecInfos.add(new VideoCodecInfo(name, getCodecProperties(type, false)));
}
}
// TODO(andersc): This is for backwards compatibility. Remove when clients have migrated to
// new DefaultVideoEncoderFactory.
if (fallbackToSoftware) {
for (VideoCodecInfo info : SoftwareVideoEncoderFactory.supportedCodecs()) {
if (!supportedCodecInfos.contains(info)) {
supportedCodecInfos.add(info);
}
}
}
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
}