Enable Android H264 High profile decoder

Based on Magnus's
https://codereview.webrtc.org/2646423002/

BUG=webrtc:6337

Review-Url: https://codereview.webrtc.org/2654003005
Cr-Commit-Position: refs/heads/master@{#16332}
This commit is contained in:
glaznev
2017-01-27 12:24:24 -08:00
committed by Commit bot
parent 62a5dd2181
commit 0c1d060b24
3 changed files with 39 additions and 2 deletions

View File

@ -76,6 +76,8 @@ public class PeerConnectionClient {
private static final String VIDEO_CODEC_PARAM_START_BITRATE = "x-google-start-bitrate"; private static final String VIDEO_CODEC_PARAM_START_BITRATE = "x-google-start-bitrate";
private static final String VIDEO_FLEXFEC_FIELDTRIAL = "WebRTC-FlexFEC-03/Enabled/"; private static final String VIDEO_FLEXFEC_FIELDTRIAL = "WebRTC-FlexFEC-03/Enabled/";
private static final String VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL = "WebRTC-IntelVP8/Enabled/"; private static final String VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL = "WebRTC-IntelVP8/Enabled/";
private static final String VIDEO_H264_HIGH_PROFILE_FIELDTRIAL =
"WebRTC-H264HighProfile/Enabled/";
private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate"; private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate";
private static final String AUDIO_ECHO_CANCELLATION_CONSTRAINT = "googEchoCancellation"; private static final String AUDIO_ECHO_CANCELLATION_CONSTRAINT = "googEchoCancellation";
private static final String AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT = "googAutoGainControl"; private static final String AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT = "googAutoGainControl";
@ -378,6 +380,7 @@ public class PeerConnectionClient {
Log.d(TAG, "Enable FlexFEC field trial."); Log.d(TAG, "Enable FlexFEC field trial.");
} }
fieldTrials += VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL; fieldTrials += VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL;
fieldTrials += VIDEO_H264_HIGH_PROFILE_FIELDTRIAL;
PeerConnectionFactory.initializeFieldTrials(fieldTrials); PeerConnectionFactory.initializeFieldTrials(fieldTrials);
// Check preferred video codec. // Check preferred video codec.

View File

@ -73,6 +73,8 @@ public class MediaCodecVideoDecoder {
// List of supported HW H.264 decoders. // List of supported HW H.264 decoders.
private static final String[] supportedH264HwCodecPrefixes = { private static final String[] supportedH264HwCodecPrefixes = {
"OMX.qcom.", "OMX.Intel.", "OMX.Exynos."}; "OMX.qcom.", "OMX.Intel.", "OMX.Exynos."};
// List of supported HW H.264 high profile decoders.
private static final String[] supportedH264HighProfileHwCodecPrefixes = {"OMX.qcom."};
// NV12 color format supported by QCOM codec, but not declared in MediaCodec - // NV12 color format supported by QCOM codec, but not declared in MediaCodec -
// see /hardware/qcom/media/mm-core/inc/OMX_QCOMExtns.h // see /hardware/qcom/media/mm-core/inc/OMX_QCOMExtns.h
@ -149,6 +151,12 @@ public class MediaCodecVideoDecoder {
&& (findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes) != null); && (findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes) != null);
} }
public static boolean isH264HighProfileHwSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& !hwDecoderDisabledTypes.contains(H264_MIME_TYPE)
&& (findDecoder(H264_MIME_TYPE, supportedH264HighProfileHwCodecPrefixes) != null);
}
public static void printStackTrace() { public static void printStackTrace() {
if (runningInstance != null && runningInstance.mediaCodecThread != null) { if (runningInstance != null && runningInstance.mediaCodecThread != null) {
StackTraceElement[] mediaCodecStackTraces = runningInstance.mediaCodecThread.getStackTrace(); StackTraceElement[] mediaCodecStackTraces = runningInstance.mediaCodecThread.getStackTrace();

View File

@ -83,6 +83,7 @@ namespace {
// Maximum time limit between incoming frames before requesting a key frame. // Maximum time limit between incoming frames before requesting a key frame.
const size_t kFrameDiffThresholdMs = 350; const size_t kFrameDiffThresholdMs = 350;
const int kMinKeyFrameInterval = 6; const int kMinKeyFrameInterval = 6;
const char kH264HighProfileFieldTrial[] = "WebRTC-H264HighProfile";
} // namespace } // namespace
// MediaCodecVideoEncoder is a webrtc::VideoEncoder implementation that uses // MediaCodecVideoEncoder is a webrtc::VideoEncoder implementation that uses
@ -1193,6 +1194,7 @@ MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory()
JNIEnv* jni = AttachCurrentThreadIfNeeded(); JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedLocalRefFrame local_ref_frame(jni); ScopedLocalRefFrame local_ref_frame(jni);
jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder");
jclass j_decoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoDecoder");
supported_codecs_.clear(); supported_codecs_.clear();
bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( bool is_vp8_hw_supported = jni->CallStaticBooleanMethod(
@ -1213,6 +1215,32 @@ MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory()
supported_codecs_.push_back(cricket::VideoCodec("VP9")); supported_codecs_.push_back(cricket::VideoCodec("VP9"));
} }
// Check if high profile is supported by decoder. If yes, encoder can always
// fall back to baseline profile as a subset as high profile.
bool is_h264_high_profile_hw_supported = false;
if (webrtc::field_trial::FindFullName(kH264HighProfileFieldTrial) ==
"Enabled") {
is_h264_high_profile_hw_supported = jni->CallStaticBooleanMethod(
j_decoder_class,
GetStaticMethodID(jni, j_decoder_class, "isH264HighProfileHwSupported",
"()Z"));
CHECK_EXCEPTION(jni);
}
if (is_h264_high_profile_hw_supported) {
ALOGD << "H.264 High Profile HW Encoder supported.";
// TODO(magjed): Enumerate actual level instead of using hardcoded level
// 3.1. Level 3.1 is 1280x720@30fps which is enough for now.
cricket::VideoCodec constrained_high(cricket::kH264CodecName);
const webrtc::H264::ProfileLevelId constrained_high_profile(
webrtc::H264::kProfileConstrainedHigh, webrtc::H264::kLevel3_1);
constrained_high.SetParam(
cricket::kH264FmtpProfileLevelId,
*webrtc::H264::ProfileLevelIdToString(constrained_high_profile));
constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1");
supported_codecs_.push_back(constrained_high);
}
bool is_h264_hw_supported = jni->CallStaticBooleanMethod( bool is_h264_hw_supported = jni->CallStaticBooleanMethod(
j_encoder_class, j_encoder_class,
GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z")); GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z"));
@ -1224,8 +1252,6 @@ MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory()
// profile as long as we have decode support for it and still send Baseline // profile as long as we have decode support for it and still send Baseline
// since Baseline is a subset of the High profile. // since Baseline is a subset of the High profile.
cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); cricket::VideoCodec constrained_baseline(cricket::kH264CodecName);
// TODO(magjed): Enumerate actual level instead of using hardcoded level
// 3.1. Level 3.1 is 1280x720@30fps which is enough for now.
const webrtc::H264::ProfileLevelId constrained_baseline_profile( const webrtc::H264::ProfileLevelId constrained_baseline_profile(
webrtc::H264::kProfileConstrainedBaseline, webrtc::H264::kLevel3_1); webrtc::H264::kProfileConstrainedBaseline, webrtc::H264::kLevel3_1);
constrained_baseline.SetParam( constrained_baseline.SetParam(