102 lines
4.4 KiB
Java
102 lines
4.4 KiB
Java
package org.webrtc;
|
|
|
|
import android.media.MediaCodecInfo;
|
|
import android.media.MediaCodecList;
|
|
import android.os.Build;
|
|
import androidx.annotation.Nullable;
|
|
import h0.c.q0;
|
|
import java.util.ArrayList;
|
|
import org.webrtc.EglBase;
|
|
/* loaded from: classes3.dex */
|
|
public class MediaCodecVideoDecoderFactory implements VideoDecoderFactory {
|
|
private static final String TAG = "MediaCodecVideoDecoderFactory";
|
|
@Nullable
|
|
private final Predicate<MediaCodecInfo> codecAllowedPredicate;
|
|
@Nullable
|
|
private final EglBase.Context sharedContext;
|
|
|
|
public MediaCodecVideoDecoderFactory(@Nullable EglBase.Context context, @Nullable Predicate<MediaCodecInfo> predicate) {
|
|
this.sharedContext = context;
|
|
this.codecAllowedPredicate = predicate;
|
|
}
|
|
|
|
@Nullable
|
|
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 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();
|
|
int i = Build.VERSION.SDK_INT;
|
|
if (name.startsWith(MediaCodecUtils.QCOM_PREFIX)) {
|
|
return true;
|
|
}
|
|
return i >= 23 && name.startsWith(MediaCodecUtils.EXYNOS_PREFIX);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
@Override // org.webrtc.VideoDecoderFactory
|
|
public /* synthetic */ VideoDecoder createDecoder(String str) {
|
|
return q0.a(this, str);
|
|
}
|
|
|
|
@Override // org.webrtc.VideoDecoderFactory
|
|
@Nullable
|
|
public VideoDecoder createDecoder(VideoCodecInfo videoCodecInfo) {
|
|
VideoCodecMimeType valueOf = VideoCodecMimeType.valueOf(videoCodecInfo.getName());
|
|
MediaCodecInfo findCodecForType = findCodecForType(valueOf);
|
|
if (findCodecForType == null) {
|
|
return null;
|
|
}
|
|
return new AndroidVideoDecoder(new MediaCodecWrapperFactoryImpl(), findCodecForType.getName(), valueOf, MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS, findCodecForType.getCapabilitiesForType(valueOf.mimeType())).intValue(), this.sharedContext);
|
|
}
|
|
|
|
@Override // org.webrtc.VideoDecoderFactory
|
|
public VideoCodecInfo[] getSupportedCodecs() {
|
|
ArrayList arrayList = new ArrayList();
|
|
VideoCodecMimeType[] videoCodecMimeTypeArr = {VideoCodecMimeType.VP8, VideoCodecMimeType.VP9, VideoCodecMimeType.H264};
|
|
for (int i = 0; i < 3; i++) {
|
|
VideoCodecMimeType videoCodecMimeType = videoCodecMimeTypeArr[i];
|
|
MediaCodecInfo findCodecForType = findCodecForType(videoCodecMimeType);
|
|
if (findCodecForType != null) {
|
|
String name = videoCodecMimeType.name();
|
|
if (videoCodecMimeType == VideoCodecMimeType.H264 && isH264HighProfileSupported(findCodecForType)) {
|
|
arrayList.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(videoCodecMimeType, true)));
|
|
}
|
|
arrayList.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(videoCodecMimeType, false)));
|
|
}
|
|
}
|
|
return (VideoCodecInfo[]) arrayList.toArray(new VideoCodecInfo[arrayList.size()]);
|
|
}
|
|
}
|