mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-05 11:59:30 +01:00
270 lines
13 KiB
Java
270 lines
13 KiB
Java
package androidx.camera.video.internal;
|
|
|
|
import android.media.MediaCodec;
|
|
import android.media.MediaCodecInfo;
|
|
import android.media.MediaCodecList;
|
|
import android.media.MediaFormat;
|
|
import android.os.Build;
|
|
import android.text.TextUtils;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import androidx.camera.core.Logger;
|
|
import androidx.camera.video.internal.compat.Api28Impl;
|
|
import androidx.camera.video.internal.compat.Api31Impl;
|
|
import androidx.core.util.Preconditions;
|
|
import com.amazon.alexa.ra.core.ui.markdown.parser.formatter.MarkdownConstants;
|
|
import defpackage.a$$ExternalSyntheticOutline0;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Locale;
|
|
import java.util.Scanner;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes.dex */
|
|
public final class DebugUtils {
|
|
private static final String AUDIO_CAPS_PREFIX = "[AudioCaps] ";
|
|
private static final String CODEC_CAPS_PREFIX = "[CodecCaps] ";
|
|
private static final String ENCODER_CAPS_PREFIX = "[EncoderCaps] ";
|
|
private static final String TAG = "DebugUtils";
|
|
private static final String VIDEO_CAPS_PREFIX = "[VideoCaps] ";
|
|
|
|
private DebugUtils() {
|
|
}
|
|
|
|
private static void dumpAudioCapabilities(@NonNull StringBuilder sb, @NonNull MediaCodecInfo.AudioCapabilities audioCapabilities, @NonNull MediaFormat mediaFormat) {
|
|
logToString(sb, "[AudioCaps] getBitrateRange = " + audioCapabilities.getBitrateRange());
|
|
logToString(sb, "[AudioCaps] getMaxInputChannelCount = " + audioCapabilities.getMaxInputChannelCount());
|
|
if (Build.VERSION.SDK_INT >= 31) {
|
|
logToString(sb, "[AudioCaps] getMinInputChannelCount = " + Api31Impl.getMinInputChannelCount(audioCapabilities));
|
|
logToString(sb, "[AudioCaps] getInputChannelCountRanges = " + Arrays.toString(Api31Impl.getInputChannelCountRanges(audioCapabilities)));
|
|
}
|
|
logToString(sb, "[AudioCaps] getSupportedSampleRateRanges = " + Arrays.toString(audioCapabilities.getSupportedSampleRateRanges()));
|
|
logToString(sb, "[AudioCaps] getSupportedSampleRates = " + Arrays.toString(audioCapabilities.getSupportedSampleRates()));
|
|
try {
|
|
int integer = mediaFormat.getInteger("sample-rate");
|
|
logToString(sb, "[AudioCaps] isSampleRateSupported for " + integer + " = " + audioCapabilities.isSampleRateSupported(integer));
|
|
} catch (IllegalArgumentException | NullPointerException unused) {
|
|
logToString(sb, "[AudioCaps] mediaFormat does not contain sample rate");
|
|
}
|
|
}
|
|
|
|
private static void dumpCodecCapabilities(@NonNull StringBuilder sb, @NonNull MediaCodecInfo.CodecCapabilities codecCapabilities, @NonNull MediaFormat mediaFormat) {
|
|
try {
|
|
logToString(sb, "[CodecCaps] isFormatSupported = " + codecCapabilities.isFormatSupported(mediaFormat));
|
|
} catch (ClassCastException unused) {
|
|
logToString(sb, "[CodecCaps] isFormatSupported=false");
|
|
}
|
|
logToString(sb, "[CodecCaps] getDefaultFormat = " + codecCapabilities.getDefaultFormat());
|
|
if (codecCapabilities.profileLevels != null) {
|
|
StringBuilder sb2 = new StringBuilder(MarkdownConstants.LEFT_BRACKET);
|
|
ArrayList arrayList = new ArrayList();
|
|
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel : codecCapabilities.profileLevels) {
|
|
arrayList.add(toString(codecProfileLevel));
|
|
}
|
|
sb2.append(TextUtils.join(", ", arrayList));
|
|
sb2.append(MarkdownConstants.RIGHT_BRACKET);
|
|
logToString(sb, "[CodecCaps] profileLevels = " + ((Object) sb2));
|
|
}
|
|
if (codecCapabilities.colorFormats != null) {
|
|
logToString(sb, "[CodecCaps] colorFormats = " + Arrays.toString(codecCapabilities.colorFormats));
|
|
}
|
|
MediaCodecInfo.VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
|
|
if (videoCapabilities != null) {
|
|
dumpVideoCapabilities(sb, videoCapabilities, mediaFormat);
|
|
}
|
|
MediaCodecInfo.AudioCapabilities audioCapabilities = codecCapabilities.getAudioCapabilities();
|
|
if (audioCapabilities != null) {
|
|
dumpAudioCapabilities(sb, audioCapabilities, mediaFormat);
|
|
}
|
|
MediaCodecInfo.EncoderCapabilities encoderCapabilities = codecCapabilities.getEncoderCapabilities();
|
|
if (encoderCapabilities != null) {
|
|
dumpEncoderCapabilities(sb, encoderCapabilities, mediaFormat);
|
|
}
|
|
}
|
|
|
|
private static void dumpEncoderCapabilities(@NonNull StringBuilder sb, @NonNull MediaCodecInfo.EncoderCapabilities encoderCapabilities, @NonNull MediaFormat mediaFormat) {
|
|
logToString(sb, "[EncoderCaps] getComplexityRange = " + encoderCapabilities.getComplexityRange());
|
|
logToString(sb, "[EncoderCaps] getQualityRange = " + Api28Impl.getQualityRange(encoderCapabilities));
|
|
try {
|
|
logToString(sb, "[EncoderCaps] isBitrateModeSupported = " + encoderCapabilities.isBitrateModeSupported(mediaFormat.getInteger("bitrate-mode")));
|
|
} catch (IllegalArgumentException | NullPointerException unused) {
|
|
logToString(sb, "[EncoderCaps] mediaFormat does not contain bitrate mode");
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static String dumpMediaCodecListForFormat(@NonNull MediaCodecList mediaCodecList, @NonNull MediaFormat mediaFormat) {
|
|
StringBuilder sb = new StringBuilder();
|
|
logToString(sb, "[Start] Dump MediaCodecList for mediaFormat " + mediaFormat);
|
|
String string = mediaFormat.getString("mime");
|
|
for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
|
|
if (mediaCodecInfo.isEncoder()) {
|
|
boolean z = true;
|
|
try {
|
|
Preconditions.checkArgument(string != null);
|
|
MediaCodecInfo.CodecCapabilities capabilitiesForType = mediaCodecInfo.getCapabilitiesForType(string);
|
|
if (capabilitiesForType == null) {
|
|
z = false;
|
|
}
|
|
Preconditions.checkArgument(z);
|
|
logToString(sb, "[Start] [" + mediaCodecInfo.getName() + MarkdownConstants.RIGHT_BRACKET);
|
|
dumpCodecCapabilities(sb, capabilitiesForType, mediaFormat);
|
|
logToString(sb, "[End] [" + mediaCodecInfo.getName() + MarkdownConstants.RIGHT_BRACKET);
|
|
} catch (IllegalArgumentException unused) {
|
|
logToString(sb, MarkdownConstants.LEFT_BRACKET + mediaCodecInfo.getName() + "] does not support mime " + string);
|
|
}
|
|
}
|
|
}
|
|
logToString(sb, "[End] Dump MediaCodecList");
|
|
String sb2 = sb.toString();
|
|
stringToLog(sb2);
|
|
return sb2;
|
|
}
|
|
|
|
private static void dumpVideoCapabilities(@NonNull StringBuilder sb, @NonNull MediaCodecInfo.VideoCapabilities videoCapabilities, @NonNull MediaFormat mediaFormat) {
|
|
int i;
|
|
int i2;
|
|
boolean z;
|
|
logToString(sb, "[VideoCaps] getBitrateRange = " + videoCapabilities.getBitrateRange());
|
|
logToString(sb, "[VideoCaps] getSupportedWidths = " + videoCapabilities.getSupportedWidths() + ", getWidthAlignment = " + videoCapabilities.getWidthAlignment());
|
|
logToString(sb, "[VideoCaps] getSupportedHeights = " + videoCapabilities.getSupportedHeights() + ", getHeightAlignment = " + videoCapabilities.getHeightAlignment());
|
|
int i3 = 0;
|
|
boolean z2 = true;
|
|
try {
|
|
i = mediaFormat.getInteger("width");
|
|
i2 = mediaFormat.getInteger("height");
|
|
Preconditions.checkArgument(i > 0 && i2 > 0);
|
|
z = true;
|
|
} catch (IllegalArgumentException | NullPointerException unused) {
|
|
logToString(sb, "[VideoCaps] mediaFormat does not contain valid width and height");
|
|
i = 0;
|
|
i2 = 0;
|
|
z = false;
|
|
}
|
|
if (z) {
|
|
try {
|
|
logToString(sb, "[VideoCaps] getSupportedHeightsFor " + i + " = " + videoCapabilities.getSupportedHeightsFor(i));
|
|
} catch (IllegalArgumentException unused2) {
|
|
logToString(sb, a$$ExternalSyntheticOutline0.m(i, "[VideoCaps] could not getSupportedHeightsFor "));
|
|
}
|
|
try {
|
|
logToString(sb, "[VideoCaps] getSupportedWidthsFor " + i2 + " = " + videoCapabilities.getSupportedWidthsFor(i2));
|
|
} catch (IllegalArgumentException unused3) {
|
|
logToString(sb, a$$ExternalSyntheticOutline0.m(i2, "[VideoCaps] could not getSupportedWidthsFor "));
|
|
}
|
|
StringBuilder m29m = ErrorUtils$$ExternalSyntheticOutline0.m29m(i, i2, "[VideoCaps] isSizeSupported for ", "x", " = ");
|
|
m29m.append(videoCapabilities.isSizeSupported(i, i2));
|
|
logToString(sb, m29m.toString());
|
|
}
|
|
logToString(sb, "[VideoCaps] getSupportedFrameRates = " + videoCapabilities.getSupportedFrameRates());
|
|
try {
|
|
int integer = mediaFormat.getInteger("frame-rate");
|
|
if (integer <= 0) {
|
|
z2 = false;
|
|
}
|
|
Preconditions.checkArgument(z2);
|
|
i3 = integer;
|
|
} catch (IllegalArgumentException | NullPointerException unused4) {
|
|
logToString(sb, "[VideoCaps] mediaFormat does not contain frame rate");
|
|
}
|
|
if (z) {
|
|
StringBuilder m29m2 = ErrorUtils$$ExternalSyntheticOutline0.m29m(i, i2, "[VideoCaps] getSupportedFrameRatesFor ", "x", " = ");
|
|
m29m2.append(videoCapabilities.getSupportedFrameRatesFor(i, i2));
|
|
logToString(sb, m29m2.toString());
|
|
}
|
|
if (!z || i3 <= 0) {
|
|
return;
|
|
}
|
|
StringBuilder m29m3 = ErrorUtils$$ExternalSyntheticOutline0.m29m(i, i2, "[VideoCaps] areSizeAndRateSupported for ", "x", ", ");
|
|
m29m3.append(i3);
|
|
m29m3.append(" = ");
|
|
m29m3.append(videoCapabilities.areSizeAndRateSupported(i, i2, i3));
|
|
logToString(sb, m29m3.toString());
|
|
}
|
|
|
|
private static String formatInterval(long j) {
|
|
long j2 = j / 3600000;
|
|
TimeUnit timeUnit = TimeUnit.HOURS;
|
|
long millis = (j - timeUnit.toMillis(j2)) / 60000;
|
|
long millis2 = j - timeUnit.toMillis(j2);
|
|
TimeUnit timeUnit2 = TimeUnit.MINUTES;
|
|
long millis3 = (millis2 - timeUnit2.toMillis(millis)) / 1000;
|
|
return String.format(Locale.US, "%02d:%02d:%02d.%03d", Long.valueOf(j2), Long.valueOf(millis), Long.valueOf(millis3), Long.valueOf(((j - timeUnit.toMillis(j2)) - timeUnit2.toMillis(millis)) - TimeUnit.SECONDS.toMillis(millis3)));
|
|
}
|
|
|
|
private static void logToString(@NonNull StringBuilder sb, @NonNull String str) {
|
|
sb.append(str);
|
|
sb.append("\n");
|
|
}
|
|
|
|
@NonNull
|
|
public static String readableBufferInfo(@NonNull MediaCodec.BufferInfo bufferInfo) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Dump BufferInfo: " + bufferInfo.toString() + "\n");
|
|
sb.append("\toffset: " + bufferInfo.offset + "\n");
|
|
sb.append("\tsize: " + bufferInfo.size + "\n");
|
|
StringBuilder sb2 = new StringBuilder("\tflag: ");
|
|
sb2.append(bufferInfo.flags);
|
|
sb.append(sb2.toString());
|
|
ArrayList arrayList = new ArrayList();
|
|
if ((bufferInfo.flags & 4) != 0) {
|
|
arrayList.add("EOS");
|
|
}
|
|
if ((bufferInfo.flags & 2) != 0) {
|
|
arrayList.add("CODEC_CONFIG");
|
|
}
|
|
if ((bufferInfo.flags & 1) != 0) {
|
|
arrayList.add("KEY_FRAME");
|
|
}
|
|
if ((bufferInfo.flags & 8) != 0) {
|
|
arrayList.add("PARTIAL_FRAME");
|
|
}
|
|
if (!arrayList.isEmpty()) {
|
|
sb.append(" (");
|
|
sb.append(TextUtils.join(" | ", arrayList));
|
|
sb.append(MarkdownConstants.RIGHT_PARENTHESIS);
|
|
}
|
|
sb.append("\n");
|
|
sb.append("\tpresentationTime: " + bufferInfo.presentationTimeUs + " (" + readableUs(bufferInfo.presentationTimeUs) + ")\n");
|
|
return sb.toString();
|
|
}
|
|
|
|
@NonNull
|
|
public static String readableMs(long j) {
|
|
return formatInterval(j);
|
|
}
|
|
|
|
@NonNull
|
|
public static String readableUs(long j) {
|
|
return readableMs(j / 1000);
|
|
}
|
|
|
|
private static void stringToLog(@NonNull String str) {
|
|
if (Logger.isInfoEnabled(TAG)) {
|
|
Scanner scanner = new Scanner(str);
|
|
while (scanner.hasNextLine()) {
|
|
Logger.i(TAG, scanner.nextLine());
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
private static String toString(@Nullable MediaCodecInfo.CodecProfileLevel codecProfileLevel) {
|
|
return codecProfileLevel == null ? "null" : String.format("{level=%d, profile=%d}", Integer.valueOf(codecProfileLevel.level), Integer.valueOf(codecProfileLevel.profile));
|
|
}
|
|
|
|
@NonNull
|
|
public static String dumpCodecCapabilities(@NonNull String str, @NonNull MediaCodec mediaCodec, @NonNull MediaFormat mediaFormat) {
|
|
StringBuilder sb = new StringBuilder();
|
|
try {
|
|
MediaCodecInfo.CodecCapabilities capabilitiesForType = mediaCodec.getCodecInfo().getCapabilitiesForType(str);
|
|
Preconditions.checkArgument(capabilitiesForType != null);
|
|
dumpCodecCapabilities(sb, capabilitiesForType, mediaFormat);
|
|
} catch (IllegalArgumentException unused) {
|
|
logToString(sb, MarkdownConstants.LEFT_BRACKET + mediaCodec.getName() + "] does not support mime " + str);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|