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

Commit 05893df

Browse files
authored
Add extra config for white list codec. (#107)
1 parent e7fb378 commit 05893df

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed

sdk/android/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ if (is_android) {
391391
rtc_android_library("hwcodecs_java") {
392392
visibility = [ "*" ]
393393
sources = [
394+
"api/org/webrtc/VideoCapabilityParser.java",
394395
"api/org/webrtc/HardwareVideoDecoderFactory.java",
395396
"api/org/webrtc/HardwareVideoEncoderFactory.java",
396397
"api/org/webrtc/PlatformSoftwareVideoDecoderFactory.java",

sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.webrtc.MediaCodecUtils.INTEL_PREFIX;
1515
import static org.webrtc.MediaCodecUtils.QCOM_PREFIX;
1616
import static org.webrtc.MediaCodecUtils.HISI_PREFIX;
17+
import static org.webrtc.MediaCodecUtils.IMG_PREFIX;
1718

1819
import android.media.MediaCodecInfo;
1920
import android.media.MediaCodecList;
@@ -42,6 +43,9 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
4243
@Nullable private final EglBase14.Context sharedContext;
4344
private final boolean enableIntelVp8Encoder;
4445
private final boolean enableH264HighProfile;
46+
private final String extraMediaCodecFile = "sdcard/mediaCodec.xml";
47+
private final VideoCapabilityParser vcp = new VideoCapabilityParser();
48+
4549
@Nullable private final Predicate<MediaCodecInfo> codecAllowedPredicate;
4650

4751
/**
@@ -216,16 +220,20 @@ private boolean isHardwareSupportedInCurrentSdkVp8(MediaCodecInfo info) {
216220
return (name.startsWith(QCOM_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
217221
// Hisi VP8 encoder seems to be supported. Needs more testing.
218222
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
223+
|| (name.startsWith(IMG_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
219224
// Exynos VP8 encoder is supported in M or later.
220225
|| (name.startsWith(EXYNOS_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
221226
// Intel Vp8 encoder is supported in LOLLIPOP or later, with the intel encoder enabled.
222227
|| (name.startsWith(INTEL_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
223-
&& enableIntelVp8Encoder);
228+
&& enableIntelVp8Encoder)
229+
|| vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp8", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
224230
}
225231

226232
private boolean isHardwareSupportedInCurrentSdkVp9(MediaCodecInfo info) {
227233
String name = info.getName();
228-
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX))
234+
return (name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX) || name.startsWith(HISI_PREFIX)
235+
|| name.startsWith(IMG_PREFIX)
236+
|| vcp.isExtraHardwareSupported(name, "video/x-vnd.on2.vp9", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders")))
229237
// Both QCOM and Exynos VP9 encoders are supported in N or later.
230238
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
231239
}
@@ -240,7 +248,10 @@ private boolean isHardwareSupportedInCurrentSdkH264(MediaCodecInfo info) {
240248
return (name.startsWith(QCOM_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
241249
// Exynos H264 encoder is supported in LOLLIPOP or later.
242250
|| (name.startsWith(EXYNOS_PREFIX)
243-
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
251+
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
252+
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
253+
|| (name.startsWith(IMG_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
254+
|| vcp.isExtraHardwareSupported(name, "video/avc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));;
244255
}
245256

246257
private boolean isHardwareSupportedInCurrentSdkH265(MediaCodecInfo info) {
@@ -251,7 +262,9 @@ private boolean isHardwareSupportedInCurrentSdkH265(MediaCodecInfo info) {
251262
|| (name.startsWith(EXYNOS_PREFIX)
252263
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
253264
// Hisi VP8 encoder seems to be supported. Needs more testing.
254-
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
265+
|| (name.startsWith(HISI_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
266+
|| (name.startsWith(IMG_PREFIX) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
267+
|| vcp.isExtraHardwareSupported(name, "video/hevc", vcp.parseWithTag(vcp.loadWithDom(extraMediaCodecFile), "Decoders"));
255268
}
256269

257270
private boolean isMediaCodecAllowed(MediaCodecInfo info) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
package org.webrtc;
12+
13+
import org.w3c.dom.Document;
14+
import org.w3c.dom.Element;
15+
import org.w3c.dom.Node;
16+
import org.w3c.dom.NodeList;
17+
import org.webrtc.Logging;
18+
import org.xml.sax.SAXException;
19+
20+
import java.io.File;
21+
import java.io.FileInputStream;
22+
import java.io.FileNotFoundException;
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.util.ArrayList;
26+
import java.util.HashMap;
27+
28+
import javax.xml.parsers.DocumentBuilder;
29+
import javax.xml.parsers.DocumentBuilderFactory;
30+
import javax.xml.parsers.ParserConfigurationException;
31+
32+
public class VideoCapabilityParser {
33+
34+
public Document loadWithDom(String xmlFilePath) {
35+
Document document = null;
36+
File file = new File(xmlFilePath);
37+
if (file.exists()) {
38+
try {
39+
InputStream inputStream = new FileInputStream(file);
40+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
41+
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
42+
document = documentBuilder.parse(inputStream);
43+
} catch (FileNotFoundException e) {
44+
} catch (ParserConfigurationException e) {
45+
} catch (IOException e) {
46+
} catch (SAXException e) {
47+
}
48+
}
49+
return document;
50+
}
51+
52+
public ArrayList<HashMap<String, String>> parseWithTag(Document document, String tag) {
53+
if (document == null) {
54+
return null;
55+
}
56+
ArrayList<HashMap<String, String>> extraMediaCodecList = new ArrayList<>();
57+
NodeList sList = document.getElementsByTagName(tag);
58+
for (int i = 0; i < sList.getLength(); i++) {
59+
Element encoded = (Element) sList.item(i);
60+
NodeList nodeList = encoded.getElementsByTagName("MediaCodec");
61+
for (i = 0; i < nodeList.getLength(); i++) {
62+
HashMap<String, String> map = new HashMap<>();
63+
Node node = nodeList.item(i);
64+
map.put("name", node.getAttributes().getNamedItem("name").getNodeValue());
65+
map.put("type", node.getAttributes().getNamedItem("type").getNodeValue());
66+
extraMediaCodecList.add(map);
67+
}
68+
}
69+
return extraMediaCodecList;
70+
}
71+
72+
public boolean isExtraHardwareSupported(String name , String type, ArrayList<HashMap<String, String>> extraMediaCodecMap){
73+
boolean result = false;
74+
if (extraMediaCodecMap != null) {
75+
for (HashMap<String, String> item : extraMediaCodecMap){
76+
if (name.startsWith(item.get("name")) && type.startsWith(item.get("type"))){
77+
result=true;
78+
break;
79+
}
80+
}
81+
}
82+
return result;
83+
}
84+
}

sdk/android/src/java/org/webrtc/MediaCodecUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MediaCodecUtils {
2929
static final String NVIDIA_PREFIX = "OMX.Nvidia.";
3030
static final String QCOM_PREFIX = "OMX.qcom.";
3131
static final String HISI_PREFIX = "OMX.hisi.";
32+
static final String IMG_PREFIX = "OMX.IMG.";
3233
static final String[] SOFTWARE_IMPLEMENTATION_PREFIXES = {"OMX.google.", "OMX.SEC."};
3334

3435
// NV12 color format supported by QCOM codec, but not declared in MediaCodec -

0 commit comments

Comments
 (0)