Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Add extra config for white list codec. #37

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ if (is_android) {

rtc_android_library("hwcodecs_java") {
java_files = [
"api/org/webrtc/VideoCapabilityParser.java",
"api/org/webrtc/HardwareVideoDecoderFactory.java",
"api/org/webrtc/HardwareVideoEncoderFactory.java",
"src/java/org/webrtc/BaseBitrateAdjuster.java",
Expand Down
15 changes: 10 additions & 5 deletions sdk/android/api/org/webrtc/HardwareVideoDecoderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
@SuppressWarnings("deprecation") // API level 16 requires use of deprecated methods.
public class HardwareVideoDecoderFactory implements VideoDecoderFactory {
private static final String TAG = "HardwareVideoDecoderFactory";

private final VideoCapabilityParser vcp = new VideoCapabilityParser();
private final String extraMediaCodecFile = "sdcard/mediaCodec.xml";
private final EglBase.Context sharedContext;

/** Creates a HardwareVideoDecoderFactory that does not use surface textures. */
Expand Down Expand Up @@ -132,21 +133,25 @@ private boolean isHardwareSupported(MediaCodecInfo info, VideoCodecType type) {
return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX)
|| name.startsWith(EXYNOS_PREFIX) || name.startsWith(NVIDIA_PREFIX)
// Hisi seems to support VP8.
|| name.startsWith(HISI_PREFIX);
|| name.startsWith(HISI_PREFIX)
|| vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp8", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
case VP9:
// QCOM and Exynos supported for VP9.
return name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX)
// Hisi seems to support VP9.
|| name.startsWith(HISI_PREFIX);
|| name.startsWith(HISI_PREFIX)
|| vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp9", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
case H264:
// QCOM, Intel, and Exynos supported for H264.
return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX)
// Hisi seems to support H264.
|| name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX);
|| name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX)
|| vcp.isExtraHardwareSupported(name, "video/avc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
case H265:
// H265 is copied from H264. More testing is needed.
return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX)
|| name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX);
|| name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX)
|| vcp.isExtraHardwareSupported(name, "video/hevc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
default:
return false;
}
Expand Down
22 changes: 17 additions & 5 deletions sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
@Nullable private final EglBase14.Context sharedContext;
private final boolean enableIntelVp8Encoder;
private final boolean enableH264HighProfile;
private final String extraMediaCodecFile = "sdcard/mediaCodec.xml";
private final VideoCapabilityParser vcp = new VideoCapabilityParser();

public HardwareVideoEncoderFactory(
EglBase.Context sharedContext, boolean enableIntelVp8Encoder, boolean enableH264HighProfile) {
Expand Down Expand Up @@ -185,12 +187,14 @@ private boolean isHardwareSupportedInCurrentSdkVp8(MediaCodecInfo info) {
|| (name.startsWith(INTEL_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& enableIntelVp8Encoder)
// Hisi Vp8 encoder seems to be supported. Needs more testing.
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|| (vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp8", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Encoders")) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
}

private boolean isHardwareSupportedInCurrentSdkVp9(MediaCodecInfo info) {
String name = info.getName();
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX))
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX) || vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp9", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Encoders")))

// Just redo an old change on MediaCodecVideoEncoder. Needs more testing.
// Both QCOM and Exynos VP9 encoders are supported in N or later.
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
Expand All @@ -208,12 +212,20 @@ private boolean isHardwareSupportedInCurrentSdkH264(MediaCodecInfo info) {
|| (name.startsWith(EXYNOS_PREFIX)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
// Hisi H264 encoder seems to be supported. Needs more testing.
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|| (vcp.isExtraHardwareSupported(name, "video/avc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Encoders")) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
}

private boolean isHardwareSupportedInCurrentSdkH265(MediaCodecInfo info) {
zhangyihui1 marked this conversation as resolved.
Show resolved Hide resolved
// We don't have too much data for H.265. Just use the same configuration for H.264.
return isHardwareSupportedInCurrentSdkH264(info);
String name = info.getName();
// QCOM H265 encoder is supported in KITKAT or later.
return (name.startsWith(QCOM_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
// Exynos H265 encoder is supported in LOLLIPOP or later.
|| (name.startsWith(EXYNOS_PREFIX)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
// Hisi H265 encoder seems to be supported. Needs more testing.
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|| (vcp.isExtraHardwareSupported(name, "video/hevc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Encoders")) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
}

private int getKeyFrameIntervalSec(VideoCodecType type) {
Expand Down
84 changes: 84 additions & 0 deletions sdk/android/api/org/webrtc/VideoCapabilityParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

package org.webrtc;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.webrtc.Logging;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class VideoCapabilityParser {

public Document loadWithDom(String xmlFilePath) {
Document document = null;
File file = new File(xmlFilePath);
if (file.exists()) {
try {
InputStream inputStream = new FileInputStream(file);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
document = documentBuilder.parse(inputStream);
} catch (FileNotFoundException e) {
} catch (ParserConfigurationException e) {
} catch (IOException e) {
} catch (SAXException e) {
}
}
return document;
}

public ArrayList<HashMap<String, String>> parseWithTag(Document document, String tag) {
if (document == null) {
return null;
}
ArrayList<HashMap<String, String>> extraMediaCodecList = new ArrayList<>();
NodeList sList = document.getElementsByTagName(tag);
for (int i = 0; i < sList.getLength(); i++) {
Element encoded = (Element) sList.item(i);
NodeList nodeList = encoded.getElementsByTagName("MediaCodec");
for (i = 0; i < nodeList.getLength(); i++) {
HashMap<String, String> map = new HashMap<>();
Node node = nodeList.item(i);
map.put("name", node.getAttributes().getNamedItem("name").getNodeValue());
map.put("type", node.getAttributes().getNamedItem("type").getNodeValue());
extraMediaCodecList.add(map);
}
}
return extraMediaCodecList;
}

public boolean isExtraHardwareSupported(String name , String type, ArrayList<HashMap<String, String>> extraMediaCodecMap){
boolean result = false;
if (extraMediaCodecMap != null) {
for (HashMap<String, String> item : extraMediaCodecMap){
if (name.startsWith(item.get("name")) && type.startsWith(item.get("type"))){
result=true;
break;
}
}
}
return result;
}
}