mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
86 lines
4 KiB
Java
86 lines
4 KiB
Java
package org.webrtc;
|
|
|
|
import android.media.MediaCodecInfo;
|
|
import android.media.MediaCodecList;
|
|
import java.util.ArrayList;
|
|
import org.webrtc.EglBase;
|
|
|
|
/* loaded from: classes3.dex */
|
|
class MediaCodecVideoDecoderFactory implements VideoDecoderFactory {
|
|
private static final String TAG = "MediaCodecVideoDecoderFactory";
|
|
private final Predicate<MediaCodecInfo> codecAllowedPredicate;
|
|
private final EglBase.Context sharedContext;
|
|
|
|
public MediaCodecVideoDecoderFactory(EglBase.Context context, Predicate<MediaCodecInfo> predicate) {
|
|
this.sharedContext = context;
|
|
this.codecAllowedPredicate = predicate;
|
|
}
|
|
|
|
@Override // org.webrtc.VideoDecoderFactory
|
|
public VideoDecoder createDecoder(VideoCodecInfo videoCodecInfo) {
|
|
VideoCodecMimeType fromSdpCodecName = VideoCodecMimeType.fromSdpCodecName(videoCodecInfo.getName());
|
|
MediaCodecInfo findCodecForType = findCodecForType(fromSdpCodecName);
|
|
if (findCodecForType == null) {
|
|
return null;
|
|
}
|
|
return new AndroidVideoDecoder(new MediaCodecWrapperFactoryImpl(), findCodecForType.getName(), fromSdpCodecName, MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS, findCodecForType.getCapabilitiesForType(fromSdpCodecName.mimeType())).intValue(), this.sharedContext);
|
|
}
|
|
|
|
@Override // org.webrtc.VideoDecoderFactory
|
|
public VideoCodecInfo[] getSupportedCodecs() {
|
|
ArrayList arrayList = new ArrayList();
|
|
VideoCodecMimeType[] videoCodecMimeTypeArr = {VideoCodecMimeType.VP8, VideoCodecMimeType.VP9, VideoCodecMimeType.H264, VideoCodecMimeType.AV1};
|
|
for (int i = 0; i < 4; i++) {
|
|
VideoCodecMimeType videoCodecMimeType = videoCodecMimeTypeArr[i];
|
|
MediaCodecInfo findCodecForType = findCodecForType(videoCodecMimeType);
|
|
if (findCodecForType != null) {
|
|
String sdpCodecName = videoCodecMimeType.toSdpCodecName();
|
|
if (videoCodecMimeType == VideoCodecMimeType.H264 && isH264HighProfileSupported(findCodecForType)) {
|
|
arrayList.add(new VideoCodecInfo(sdpCodecName, MediaCodecUtils.getCodecProperties(videoCodecMimeType, true)));
|
|
}
|
|
arrayList.add(new VideoCodecInfo(sdpCodecName, MediaCodecUtils.getCodecProperties(videoCodecMimeType, false)));
|
|
}
|
|
}
|
|
return (VideoCodecInfo[]) arrayList.toArray(new VideoCodecInfo[arrayList.size()]);
|
|
}
|
|
|
|
private MediaCodecInfo findCodecForType(VideoCodecMimeType videoCodecMimeType) {
|
|
int i = 0;
|
|
while (true) {
|
|
MediaCodecInfo mediaCodecInfo = null;
|
|
if (i >= MediaCodecList.getCodecCount()) {
|
|
return null;
|
|
}
|
|
try {
|
|
mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
|
|
} catch (IllegalArgumentException e) {
|
|
Logging.e(TAG, "Cannot retrieve decoder codec info", e);
|
|
}
|
|
if (mediaCodecInfo != null && !mediaCodecInfo.isEncoder() && isSupportedCodec(mediaCodecInfo, videoCodecMimeType)) {
|
|
return mediaCodecInfo;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private boolean isSupportedCodec(MediaCodecInfo mediaCodecInfo, VideoCodecMimeType videoCodecMimeType) {
|
|
mediaCodecInfo.getName();
|
|
if (MediaCodecUtils.codecSupportsType(mediaCodecInfo, videoCodecMimeType) && MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS, mediaCodecInfo.getCapabilitiesForType(videoCodecMimeType.mimeType())) != null) {
|
|
return isCodecAllowed(mediaCodecInfo);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private boolean isCodecAllowed(MediaCodecInfo mediaCodecInfo) {
|
|
Predicate<MediaCodecInfo> predicate = this.codecAllowedPredicate;
|
|
if (predicate == null) {
|
|
return true;
|
|
}
|
|
return predicate.test(mediaCodecInfo);
|
|
}
|
|
|
|
private boolean isH264HighProfileSupported(MediaCodecInfo mediaCodecInfo) {
|
|
String name = mediaCodecInfo.getName();
|
|
return name.startsWith("OMX.qcom.") || name.startsWith("OMX.Exynos.");
|
|
}
|
|
}
|