Skip to content

Commit ba9663a

Browse files
kanatipavlidakis
authored andcommitted
add DefaultBlacklistedVideoDecoderFactory (#40)
* add DefaultBlacklistedVideoDecoderFactory * use decoder.implementationName * fix compilation * fix logging * fix logging func call * fix imports + package
1 parent 2da8d72 commit ba9663a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

sdk/android/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ if (is_android) {
386386
"api/org/webrtc/DefaultVideoDecoderFactory.java",
387387
"api/org/webrtc/DefaultVideoEncoderFactory.java",
388388
"api/org/webrtc/WrappedVideoDecoderFactory.java",
389+
"api/org/webrtc/DefaultBlacklistedVideoDecoderFactory.java",
389390
"api/org/webrtc/DefaultAlignedVideoEncoderFactory.java",
390391
"api/org/webrtc/SimulcastAlignedVideoEncoderFactory.java",
391392
]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.webrtc;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import java.util.Arrays;
6+
import java.util.HashSet;
7+
import java.util.Set;
8+
import java.util.function.Predicate;
9+
10+
public class DefaultBlacklistedVideoDecoderFactory implements VideoDecoderFactory {
11+
12+
private static final String TAG = "DefaultBlacklistedVideoDecoderFactory";
13+
14+
private static final Predicate<VideoDecoder> defaultBlacklistedPredicate =
15+
new Predicate<VideoDecoder>() {
16+
@Override
17+
public boolean test(@Nullable VideoDecoder decoder) {
18+
// if the decoder is Exynos VP9, then blacklist it
19+
return isExynosVP9(decoder);
20+
}
21+
};
22+
23+
private final VideoDecoderFactory hardwareVideoDecoderFactory;
24+
private final VideoDecoderFactory softwareVideoDecoderFactory;
25+
private final VideoDecoderFactory platformSoftwareVideoDecoderFactory;
26+
private final Predicate<VideoDecoder> isHardwareDecoderBlacklisted;
27+
28+
public DefaultBlacklistedVideoDecoderFactory(@Nullable EglBase.Context eglContext) {
29+
this(eglContext, null);
30+
}
31+
32+
public DefaultBlacklistedVideoDecoderFactory(
33+
@Nullable EglBase.Context eglContext,
34+
@Nullable Predicate<VideoDecoder> decoderBlacklistedPredicate) {
35+
this.hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory(eglContext);
36+
this.softwareVideoDecoderFactory = new SoftwareVideoDecoderFactory();
37+
this.platformSoftwareVideoDecoderFactory = new PlatformSoftwareVideoDecoderFactory(eglContext);
38+
this.isHardwareDecoderBlacklisted = decoderBlacklistedPredicate == null
39+
? defaultBlacklistedPredicate
40+
: decoderBlacklistedPredicate.or(defaultBlacklistedPredicate);
41+
}
42+
43+
@Override
44+
public VideoDecoder createDecoder(VideoCodecInfo codecType) {
45+
VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType);
46+
VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType);
47+
if (softwareDecoder == null) {
48+
softwareDecoder = platformSoftwareVideoDecoderFactory.createDecoder(codecType);
49+
}
50+
51+
if (isHardwareDecoderBlacklisted.test(hardwareDecoder)) {
52+
Logging.d(TAG, "Hardware decoder is blacklisted: " + hardwareDecoder.getImplementationName());
53+
return softwareDecoder;
54+
}
55+
56+
if (hardwareDecoder != null && softwareDecoder != null) {
57+
return new VideoDecoderFallback(softwareDecoder, hardwareDecoder);
58+
} else {
59+
return hardwareDecoder != null ? hardwareDecoder : softwareDecoder;
60+
}
61+
}
62+
63+
@Override
64+
public VideoCodecInfo[] getSupportedCodecs() {
65+
Set<VideoCodecInfo> supportedCodecInfos = new HashSet<>();
66+
supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs()));
67+
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs()));
68+
supportedCodecInfos.addAll(Arrays.asList(platformSoftwareVideoDecoderFactory.getSupportedCodecs()));
69+
return supportedCodecInfos.toArray(new VideoCodecInfo[0]);
70+
}
71+
72+
private static boolean isExynosVP9(@Nullable VideoDecoder decoder) {
73+
if (decoder == null) {
74+
return false;
75+
}
76+
final String name = decoder.getImplementationName().toLowerCase();
77+
return name.contains("exynos") && name.contains("vp9");
78+
}
79+
}

0 commit comments

Comments
 (0)