Add MediaTek H264 and VP8 HW Codec Support with field trial
Bug: webrtc:8761
Change-Id: I06cdff086b624afaf3533ced3e5e4eaf3a862720
Reviewed-on: https://webrtc-review.googlesource.com/39980
Commit-Queue: Alex Leung <alexleung@google.com>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Alex Glaznev <glaznev@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21699}
diff --git a/sdk/android/api/org/webrtc/MediaCodecVideoDecoder.java b/sdk/android/api/org/webrtc/MediaCodecVideoDecoder.java
index 57682ab..cc014fa 100644
--- a/sdk/android/api/org/webrtc/MediaCodecVideoDecoder.java
+++ b/sdk/android/api/org/webrtc/MediaCodecVideoDecoder.java
@@ -20,6 +20,7 @@
import android.view.Surface;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -82,16 +83,37 @@
private static final String VP9_MIME_TYPE = "video/x-vnd.on2.vp9";
private static final String H264_MIME_TYPE = "video/avc";
// List of supported HW VP8 decoders.
- private static final String[] supportedVp8HwCodecPrefixes = {
- "OMX.qcom.", "OMX.Nvidia.", "OMX.Exynos.", "OMX.Intel."};
+ private static final String[] supportedVp8HwCodecPrefixes() {
+ ArrayList<String> supportedPrefixes = new ArrayList<String>();
+ supportedPrefixes.add("OMX.qcom.");
+ supportedPrefixes.add("OMX.Nvidia.");
+ supportedPrefixes.add("OMX.Exynos.");
+ supportedPrefixes.add("OMX.Intel.");
+ if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTC-MediaTekVP8").equals("Enabled")
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ supportedPrefixes.add("OMX.MTK.");
+ }
+ return supportedPrefixes.toArray(new String[supportedPrefixes.size()]);
+ }
// List of supported HW VP9 decoders.
private static final String[] supportedVp9HwCodecPrefixes = {"OMX.qcom.", "OMX.Exynos."};
// List of supported HW H.264 decoders.
- private static final String[] supportedH264HwCodecPrefixes = {
- "OMX.qcom.", "OMX.Intel.", "OMX.Exynos."};
+ private static final String[] supportedH264HwCodecPrefixes() {
+ ArrayList<String> supportedPrefixes = new ArrayList<String>();
+ supportedPrefixes.add("OMX.qcom.");
+ supportedPrefixes.add("OMX.Intel.");
+ supportedPrefixes.add("OMX.Exynos.");
+ if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTC-MediaTekH264").equals("Enabled")
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ supportedPrefixes.add("OMX.MTK.");
+ }
+ return supportedPrefixes.toArray(new String[supportedPrefixes.size()]);
+ }
+
// List of supported HW H.264 high profile decoders.
private static final String supportedQcomH264HighProfileHwCodecPrefix = "OMX.qcom.";
private static final String supportedExynosH264HighProfileHwCodecPrefix = "OMX.Exynos.";
+ private static final String supportedMediaTekH264HighProfileHwCodecPrefix = "OMX.MTK.";
// NV12 color format supported by QCOM codec, but not declared in MediaCodec -
// see /hardware/qcom/media/mm-core/inc/OMX_QCOMExtns.h
@@ -156,7 +178,7 @@
@CalledByNativeUnchecked
public static boolean isVp8HwSupported() {
return !hwDecoderDisabledTypes.contains(VP8_MIME_TYPE)
- && (findDecoder(VP8_MIME_TYPE, supportedVp8HwCodecPrefixes) != null);
+ && (findDecoder(VP8_MIME_TYPE, supportedVp8HwCodecPrefixes()) != null);
}
@CalledByNativeUnchecked
@@ -168,7 +190,7 @@
@CalledByNativeUnchecked
public static boolean isH264HwSupported() {
return !hwDecoderDisabledTypes.contains(H264_MIME_TYPE)
- && (findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes) != null);
+ && (findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes()) != null);
}
@CalledByNative
@@ -188,6 +210,13 @@
!= null) {
return true;
}
+ // Support H.264 HP decoding on MediaTek chips for Android O and above
+ if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTC-MediaTekH264").equals("Enabled")
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ && findDecoder(H264_MIME_TYPE, new String[] {supportedMediaTekH264HighProfileHwCodecPrefix})
+ != null) {
+ return true;
+ }
return false;
}
@@ -301,13 +330,13 @@
String[] supportedCodecPrefixes = null;
if (type == VideoCodecType.VIDEO_CODEC_VP8) {
mime = VP8_MIME_TYPE;
- supportedCodecPrefixes = supportedVp8HwCodecPrefixes;
+ supportedCodecPrefixes = supportedVp8HwCodecPrefixes();
} else if (type == VideoCodecType.VIDEO_CODEC_VP9) {
mime = VP9_MIME_TYPE;
supportedCodecPrefixes = supportedVp9HwCodecPrefixes;
} else if (type == VideoCodecType.VIDEO_CODEC_H264) {
mime = H264_MIME_TYPE;
- supportedCodecPrefixes = supportedH264HwCodecPrefixes;
+ supportedCodecPrefixes = supportedH264HwCodecPrefixes();
} else {
throw new RuntimeException("initDecode: Non-supported codec " + type);
}