-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add DefaultBlacklistedVideoDecoderFactory (#40)
* add DefaultBlacklistedVideoDecoderFactory * use decoder.implementationName * fix compilation * fix logging * fix logging func call * fix imports + package
- Loading branch information
1 parent
332cb33
commit 94f79ec
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
sdk/android/api/org/webrtc/DefaultBlacklistedVideoDecoderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.webrtc; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
public class DefaultBlacklistedVideoDecoderFactory implements VideoDecoderFactory { | ||
|
||
private static final String TAG = "DefaultBlacklistedVideoDecoderFactory"; | ||
|
||
private static final Predicate<VideoDecoder> defaultBlacklistedPredicate = | ||
new Predicate<VideoDecoder>() { | ||
@Override | ||
public boolean test(@Nullable VideoDecoder decoder) { | ||
// if the decoder is Exynos VP9, then blacklist it | ||
return isExynosVP9(decoder); | ||
} | ||
}; | ||
|
||
private final VideoDecoderFactory hardwareVideoDecoderFactory; | ||
private final VideoDecoderFactory softwareVideoDecoderFactory; | ||
private final VideoDecoderFactory platformSoftwareVideoDecoderFactory; | ||
private final Predicate<VideoDecoder> isHardwareDecoderBlacklisted; | ||
|
||
public DefaultBlacklistedVideoDecoderFactory(@Nullable EglBase.Context eglContext) { | ||
this(eglContext, null); | ||
} | ||
|
||
public DefaultBlacklistedVideoDecoderFactory( | ||
@Nullable EglBase.Context eglContext, | ||
@Nullable Predicate<VideoDecoder> decoderBlacklistedPredicate) { | ||
this.hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory(eglContext); | ||
this.softwareVideoDecoderFactory = new SoftwareVideoDecoderFactory(); | ||
this.platformSoftwareVideoDecoderFactory = new PlatformSoftwareVideoDecoderFactory(eglContext); | ||
this.isHardwareDecoderBlacklisted = decoderBlacklistedPredicate == null | ||
? defaultBlacklistedPredicate | ||
: decoderBlacklistedPredicate.or(defaultBlacklistedPredicate); | ||
} | ||
|
||
@Override | ||
public VideoDecoder createDecoder(VideoCodecInfo codecType) { | ||
VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType); | ||
VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType); | ||
if (softwareDecoder == null) { | ||
softwareDecoder = platformSoftwareVideoDecoderFactory.createDecoder(codecType); | ||
} | ||
|
||
if (isHardwareDecoderBlacklisted.test(hardwareDecoder)) { | ||
Logging.d(TAG, "Hardware decoder is blacklisted: " + hardwareDecoder.getImplementationName()); | ||
return softwareDecoder; | ||
} | ||
|
||
if (hardwareDecoder != null && softwareDecoder != null) { | ||
return new VideoDecoderFallback(softwareDecoder, hardwareDecoder); | ||
} else { | ||
return hardwareDecoder != null ? hardwareDecoder : softwareDecoder; | ||
} | ||
} | ||
|
||
@Override | ||
public VideoCodecInfo[] getSupportedCodecs() { | ||
Set<VideoCodecInfo> supportedCodecInfos = new HashSet<>(); | ||
supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs())); | ||
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs())); | ||
supportedCodecInfos.addAll(Arrays.asList(platformSoftwareVideoDecoderFactory.getSupportedCodecs())); | ||
return supportedCodecInfos.toArray(new VideoCodecInfo[0]); | ||
} | ||
|
||
private static boolean isExynosVP9(@Nullable VideoDecoder decoder) { | ||
if (decoder == null) { | ||
return false; | ||
} | ||
final String name = decoder.getImplementationName().toLowerCase(); | ||
return name.contains("exynos") && name.contains("vp9"); | ||
} | ||
} |