Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/util/DebugTextViewHelper.java

120 lines
5.3 KiB
Java
Raw Permalink Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.exoplayer.util;
import android.os.Looper;
import android.widget.TextView;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format;
import androidx.media3.common.Player;
import androidx.media3.common.util.Assertions;
import androidx.media3.exoplayer.DecoderCounters;
import androidx.media3.exoplayer.ExoPlayer;
import io.sentry.protocol.ViewHierarchyNode;
import java.util.Locale;
/* loaded from: classes2.dex */
public class DebugTextViewHelper {
private static final int REFRESH_INTERVAL_MS = 1000;
private final ExoPlayer player;
private boolean started;
private final TextView textView;
private final Updater updater;
public DebugTextViewHelper(ExoPlayer exoPlayer, TextView textView) {
Assertions.checkArgument(exoPlayer.getApplicationLooper() == Looper.getMainLooper());
this.player = exoPlayer;
this.textView = textView;
this.updater = new Updater();
}
public final void start() {
if (this.started) {
return;
}
this.started = true;
this.player.addListener(this.updater);
updateAndPost();
}
public final void stop() {
if (this.started) {
this.started = false;
this.player.removeListener(this.updater);
this.textView.removeCallbacks(this.updater);
}
}
protected final void updateAndPost() {
this.textView.setText(getDebugString());
this.textView.removeCallbacks(this.updater);
this.textView.postDelayed(this.updater, 1000L);
}
protected String getDebugString() {
return getPlayerStateString() + getVideoString() + getAudioString();
}
protected String getPlayerStateString() {
int playbackState = this.player.getPlaybackState();
return String.format("playWhenReady:%s playbackState:%s item:%s", Boolean.valueOf(this.player.getPlayWhenReady()), playbackState != 1 ? playbackState != 2 ? playbackState != 3 ? playbackState != 4 ? "unknown" : "ended" : "ready" : "buffering" : "idle", Integer.valueOf(this.player.getCurrentMediaItemIndex()));
}
protected String getVideoString() {
Format videoFormat = this.player.getVideoFormat();
DecoderCounters videoDecoderCounters = this.player.getVideoDecoderCounters();
return (videoFormat == null || videoDecoderCounters == null) ? "" : "\n" + videoFormat.sampleMimeType + "(id:" + videoFormat.id + " r:" + videoFormat.width + ViewHierarchyNode.JsonKeys.X + videoFormat.height + getColorInfoString(videoFormat.colorInfo) + getPixelAspectRatioString(videoFormat.pixelWidthHeightRatio) + getDecoderCountersBufferCountString(videoDecoderCounters) + " vfpo: " + getVideoFrameProcessingOffsetAverageString(videoDecoderCounters.totalVideoFrameProcessingOffsetUs, videoDecoderCounters.videoFrameProcessingOffsetCount) + ")";
}
protected String getAudioString() {
Format audioFormat = this.player.getAudioFormat();
DecoderCounters audioDecoderCounters = this.player.getAudioDecoderCounters();
return (audioFormat == null || audioDecoderCounters == null) ? "" : "\n" + audioFormat.sampleMimeType + "(id:" + audioFormat.id + " hz:" + audioFormat.sampleRate + " ch:" + audioFormat.channelCount + getDecoderCountersBufferCountString(audioDecoderCounters) + ")";
}
private static String getDecoderCountersBufferCountString(DecoderCounters decoderCounters) {
if (decoderCounters == null) {
return "";
}
decoderCounters.ensureUpdated();
return " sib:" + decoderCounters.skippedInputBufferCount + " sb:" + decoderCounters.skippedOutputBufferCount + " rb:" + decoderCounters.renderedOutputBufferCount + " db:" + decoderCounters.droppedBufferCount + " mcdb:" + decoderCounters.maxConsecutiveDroppedBufferCount + " dk:" + decoderCounters.droppedToKeyframeCount;
}
private static String getColorInfoString(ColorInfo colorInfo) {
return (colorInfo == null || !colorInfo.isValid()) ? "" : " colr:" + colorInfo.toLogString();
}
private static String getPixelAspectRatioString(float f) {
return (f == -1.0f || f == 1.0f) ? "" : " par:" + String.format(Locale.US, "%.02f", Float.valueOf(f));
}
private static String getVideoFrameProcessingOffsetAverageString(long j, int i) {
return i == 0 ? "N/A" : String.valueOf((long) (j / i));
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public final class Updater implements Player.Listener, Runnable {
private Updater() {
}
@Override // androidx.media3.common.Player.Listener
public void onPlaybackStateChanged(int i) {
DebugTextViewHelper.this.updateAndPost();
}
@Override // androidx.media3.common.Player.Listener
public void onPlayWhenReadyChanged(boolean z, int i) {
DebugTextViewHelper.this.updateAndPost();
}
@Override // androidx.media3.common.Player.Listener
public void onPositionDiscontinuity(Player.PositionInfo positionInfo, Player.PositionInfo positionInfo2, int i) {
DebugTextViewHelper.this.updateAndPost();
}
@Override // java.lang.Runnable
public void run() {
DebugTextViewHelper.this.updateAndPost();
}
}
}