Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/util/EventLogger.java
2024-05-21 17:08:36 -04:00

441 lines
20 KiB
Java

package androidx.media3.exoplayer.util;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Metadata;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.Timeline;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.DecoderCounters;
import androidx.media3.exoplayer.DecoderReuseEvaluation;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import androidx.media3.exoplayer.source.LoadEventInfo;
import androidx.media3.exoplayer.source.MediaLoadData;
import androidx.media3.exoplayer.trackselection.MappingTrackSelector;
import com.google.common.collect.ImmutableList;
import io.sentry.protocol.SentryThread;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Locale;
/* loaded from: classes2.dex */
public class EventLogger implements AnalyticsListener {
private static final String DEFAULT_TAG = "EventLogger";
private static final int MAX_TIMELINE_ITEM_LINES = 3;
private static final NumberFormat TIME_FORMAT;
private final Timeline.Period period;
private final long startTimeMs;
private final String tag;
private final Timeline.Window window;
private static String getDiscontinuityReasonString(int i) {
return i != 0 ? i != 1 ? i != 2 ? i != 3 ? i != 4 ? i != 5 ? "?" : "INTERNAL" : "REMOVE" : "SKIP" : "SEEK_ADJUSTMENT" : "SEEK" : "AUTO_TRANSITION";
}
private static String getMediaItemTransitionReasonString(int i) {
return i != 0 ? i != 1 ? i != 2 ? i != 3 ? "?" : "PLAYLIST_CHANGED" : "SEEK" : "AUTO" : "REPEAT";
}
private static String getPlayWhenReadyChangeReasonString(int i) {
return i != 1 ? i != 2 ? i != 3 ? i != 4 ? i != 5 ? "?" : "END_OF_MEDIA_ITEM" : "REMOTE" : "AUDIO_BECOMING_NOISY" : "AUDIO_FOCUS_LOSS" : "USER_REQUEST";
}
private static String getPlaybackSuppressionReasonString(int i) {
return i != 0 ? i != 1 ? "?" : "TRANSIENT_AUDIO_FOCUS_LOSS" : "NONE";
}
private static String getRepeatModeString(int i) {
return i != 0 ? i != 1 ? i != 2 ? "?" : "ALL" : "ONE" : "OFF";
}
private static String getStateString(int i) {
return i != 1 ? i != 2 ? i != 3 ? i != 4 ? "?" : "ENDED" : "READY" : "BUFFERING" : "IDLE";
}
private static String getTimelineChangeReasonString(int i) {
return i != 0 ? i != 1 ? "?" : "SOURCE_UPDATE" : "PLAYLIST_CHANGED";
}
private static String getTrackStatusString(boolean z) {
return z ? "[X]" : "[ ]";
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onBandwidthEstimate(AnalyticsListener.EventTime eventTime, int i, long j, long j2) {
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onLoadCanceled(AnalyticsListener.EventTime eventTime, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onLoadCompleted(AnalyticsListener.EventTime eventTime, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onLoadStarted(AnalyticsListener.EventTime eventTime, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
}
static {
NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
TIME_FORMAT = numberFormat;
numberFormat.setMinimumFractionDigits(2);
numberFormat.setMaximumFractionDigits(2);
numberFormat.setGroupingUsed(false);
}
public EventLogger() {
this(DEFAULT_TAG);
}
public EventLogger(String str) {
this.tag = str;
this.window = new Timeline.Window();
this.period = new Timeline.Period();
this.startTimeMs = SystemClock.elapsedRealtime();
}
@Deprecated
public EventLogger(MappingTrackSelector mappingTrackSelector) {
this(DEFAULT_TAG);
}
@Deprecated
public EventLogger(MappingTrackSelector mappingTrackSelector, String str) {
this(str);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onIsLoadingChanged(AnalyticsListener.EventTime eventTime, boolean z) {
logd(eventTime, "loading", Boolean.toString(z));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPlaybackStateChanged(AnalyticsListener.EventTime eventTime, int i) {
logd(eventTime, SentryThread.JsonKeys.STATE, getStateString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPlayWhenReadyChanged(AnalyticsListener.EventTime eventTime, boolean z, int i) {
logd(eventTime, "playWhenReady", z + ", " + getPlayWhenReadyChangeReasonString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPlaybackSuppressionReasonChanged(AnalyticsListener.EventTime eventTime, int i) {
logd(eventTime, "playbackSuppressionReason", getPlaybackSuppressionReasonString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onIsPlayingChanged(AnalyticsListener.EventTime eventTime, boolean z) {
logd(eventTime, "isPlaying", Boolean.toString(z));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onRepeatModeChanged(AnalyticsListener.EventTime eventTime, int i) {
logd(eventTime, "repeatMode", getRepeatModeString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onShuffleModeChanged(AnalyticsListener.EventTime eventTime, boolean z) {
logd(eventTime, "shuffleModeEnabled", Boolean.toString(z));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPositionDiscontinuity(AnalyticsListener.EventTime eventTime, Player.PositionInfo positionInfo, Player.PositionInfo positionInfo2, int i) {
StringBuilder sb = new StringBuilder("reason=");
sb.append(getDiscontinuityReasonString(i)).append(", PositionInfo:old [mediaItem=").append(positionInfo.mediaItemIndex).append(", period=").append(positionInfo.periodIndex).append(", pos=").append(positionInfo.positionMs);
if (positionInfo.adGroupIndex != -1) {
sb.append(", contentPos=").append(positionInfo.contentPositionMs).append(", adGroup=").append(positionInfo.adGroupIndex).append(", ad=").append(positionInfo.adIndexInAdGroup);
}
sb.append("], PositionInfo:new [mediaItem=").append(positionInfo2.mediaItemIndex).append(", period=").append(positionInfo2.periodIndex).append(", pos=").append(positionInfo2.positionMs);
if (positionInfo2.adGroupIndex != -1) {
sb.append(", contentPos=").append(positionInfo2.contentPositionMs).append(", adGroup=").append(positionInfo2.adGroupIndex).append(", ad=").append(positionInfo2.adIndexInAdGroup);
}
sb.append("]");
logd(eventTime, "positionDiscontinuity", sb.toString());
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPlaybackParametersChanged(AnalyticsListener.EventTime eventTime, PlaybackParameters playbackParameters) {
logd(eventTime, "playbackParameters", playbackParameters.toString());
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onTimelineChanged(AnalyticsListener.EventTime eventTime, int i) {
int periodCount = eventTime.timeline.getPeriodCount();
int windowCount = eventTime.timeline.getWindowCount();
logd("timeline [" + getEventTimeString(eventTime) + ", periodCount=" + periodCount + ", windowCount=" + windowCount + ", reason=" + getTimelineChangeReasonString(i));
for (int i2 = 0; i2 < Math.min(periodCount, 3); i2++) {
eventTime.timeline.getPeriod(i2, this.period);
logd(" period [" + getTimeString(this.period.getDurationMs()) + "]");
}
if (periodCount > 3) {
logd(" ...");
}
for (int i3 = 0; i3 < Math.min(windowCount, 3); i3++) {
eventTime.timeline.getWindow(i3, this.window);
logd(" window [" + getTimeString(this.window.getDurationMs()) + ", seekable=" + this.window.isSeekable + ", dynamic=" + this.window.isDynamic + "]");
}
if (windowCount > 3) {
logd(" ...");
}
logd("]");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onMediaItemTransition(AnalyticsListener.EventTime eventTime, MediaItem mediaItem, int i) {
logd("mediaItem [" + getEventTimeString(eventTime) + ", reason=" + getMediaItemTransitionReasonString(i) + "]");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onPlayerError(AnalyticsListener.EventTime eventTime, PlaybackException playbackException) {
loge(eventTime, "playerFailed", playbackException);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onTracksChanged(AnalyticsListener.EventTime eventTime, Tracks tracks) {
Metadata metadata;
logd("tracks [" + getEventTimeString(eventTime));
ImmutableList<Tracks.Group> groups = tracks.getGroups();
for (int i = 0; i < groups.size(); i++) {
Tracks.Group group = groups.get(i);
logd(" group [");
for (int i2 = 0; i2 < group.length; i2++) {
logd(" " + getTrackStatusString(group.isTrackSelected(i2)) + " Track:" + i2 + ", " + Format.toLogString(group.getTrackFormat(i2)) + ", supported=" + Util.getFormatSupportString(group.getTrackSupport(i2)));
}
logd(" ]");
}
boolean z = false;
for (int i3 = 0; !z && i3 < groups.size(); i3++) {
Tracks.Group group2 = groups.get(i3);
for (int i4 = 0; !z && i4 < group2.length; i4++) {
if (group2.isTrackSelected(i4) && (metadata = group2.getTrackFormat(i4).metadata) != null && metadata.length() > 0) {
logd(" Metadata [");
printMetadata(metadata, " ");
logd(" ]");
z = true;
}
}
}
logd("]");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onMetadata(AnalyticsListener.EventTime eventTime, Metadata metadata) {
logd("metadata [" + getEventTimeString(eventTime));
printMetadata(metadata, " ");
logd("]");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioEnabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters) {
logd(eventTime, "audioEnabled");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioDecoderInitialized(AnalyticsListener.EventTime eventTime, String str, long j) {
logd(eventTime, "audioDecoderInitialized", str);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioInputFormatChanged(AnalyticsListener.EventTime eventTime, Format format, DecoderReuseEvaluation decoderReuseEvaluation) {
logd(eventTime, "audioInputFormat", Format.toLogString(format));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioUnderrun(AnalyticsListener.EventTime eventTime, int i, long j, long j2) {
loge(eventTime, "audioTrackUnderrun", i + ", " + j + ", " + j2, null);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioDecoderReleased(AnalyticsListener.EventTime eventTime, String str) {
logd(eventTime, "audioDecoderReleased", str);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters) {
logd(eventTime, "audioDisabled");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioSessionIdChanged(AnalyticsListener.EventTime eventTime, int i) {
logd(eventTime, "audioSessionId", Integer.toString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onAudioAttributesChanged(AnalyticsListener.EventTime eventTime, AudioAttributes audioAttributes) {
logd(eventTime, "audioAttributes", audioAttributes.contentType + "," + audioAttributes.flags + "," + audioAttributes.usage + "," + audioAttributes.allowedCapturePolicy);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onSkipSilenceEnabledChanged(AnalyticsListener.EventTime eventTime, boolean z) {
logd(eventTime, "skipSilenceEnabled", Boolean.toString(z));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVolumeChanged(AnalyticsListener.EventTime eventTime, float f) {
logd(eventTime, "volume", Float.toString(f));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoEnabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters) {
logd(eventTime, "videoEnabled");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoDecoderInitialized(AnalyticsListener.EventTime eventTime, String str, long j) {
logd(eventTime, "videoDecoderInitialized", str);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoInputFormatChanged(AnalyticsListener.EventTime eventTime, Format format, DecoderReuseEvaluation decoderReuseEvaluation) {
logd(eventTime, "videoInputFormat", Format.toLogString(format));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDroppedVideoFrames(AnalyticsListener.EventTime eventTime, int i, long j) {
logd(eventTime, "droppedFrames", Integer.toString(i));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoDecoderReleased(AnalyticsListener.EventTime eventTime, String str) {
logd(eventTime, "videoDecoderReleased", str);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoDisabled(AnalyticsListener.EventTime eventTime, DecoderCounters decoderCounters) {
logd(eventTime, "videoDisabled");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onRenderedFirstFrame(AnalyticsListener.EventTime eventTime, Object obj, long j) {
logd(eventTime, "renderedFirstFrame", String.valueOf(obj));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onVideoSizeChanged(AnalyticsListener.EventTime eventTime, VideoSize videoSize) {
logd(eventTime, "videoSize", videoSize.width + ", " + videoSize.height);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onLoadError(AnalyticsListener.EventTime eventTime, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData, IOException iOException, boolean z) {
printInternalError(eventTime, "loadError", iOException);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onSurfaceSizeChanged(AnalyticsListener.EventTime eventTime, int i, int i2) {
logd(eventTime, "surfaceSize", i + ", " + i2);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onUpstreamDiscarded(AnalyticsListener.EventTime eventTime, MediaLoadData mediaLoadData) {
logd(eventTime, "upstreamDiscarded", Format.toLogString(mediaLoadData.trackFormat));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDownstreamFormatChanged(AnalyticsListener.EventTime eventTime, MediaLoadData mediaLoadData) {
logd(eventTime, "downstreamFormat", Format.toLogString(mediaLoadData.trackFormat));
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmSessionAcquired(AnalyticsListener.EventTime eventTime, int i) {
logd(eventTime, "drmSessionAcquired", "state=" + i);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmSessionManagerError(AnalyticsListener.EventTime eventTime, Exception exc) {
printInternalError(eventTime, "drmSessionManagerError", exc);
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmKeysRestored(AnalyticsListener.EventTime eventTime) {
logd(eventTime, "drmKeysRestored");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmKeysRemoved(AnalyticsListener.EventTime eventTime) {
logd(eventTime, "drmKeysRemoved");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmKeysLoaded(AnalyticsListener.EventTime eventTime) {
logd(eventTime, "drmKeysLoaded");
}
@Override // androidx.media3.exoplayer.analytics.AnalyticsListener
public void onDrmSessionReleased(AnalyticsListener.EventTime eventTime) {
logd(eventTime, "drmSessionReleased");
}
protected void logd(String str) {
Log.d(this.tag, str);
}
protected void loge(String str) {
Log.e(this.tag, str);
}
private void logd(AnalyticsListener.EventTime eventTime, String str) {
logd(getEventString(eventTime, str, null, null));
}
private void logd(AnalyticsListener.EventTime eventTime, String str, String str2) {
logd(getEventString(eventTime, str, str2, null));
}
private void loge(AnalyticsListener.EventTime eventTime, String str, Throwable th) {
loge(getEventString(eventTime, str, null, th));
}
private void loge(AnalyticsListener.EventTime eventTime, String str, String str2, Throwable th) {
loge(getEventString(eventTime, str, str2, th));
}
private void printInternalError(AnalyticsListener.EventTime eventTime, String str, Exception exc) {
loge(eventTime, "internalError", str, exc);
}
private void printMetadata(Metadata metadata, String str) {
for (int i = 0; i < metadata.length(); i++) {
logd(str + metadata.get(i));
}
}
private String getEventString(AnalyticsListener.EventTime eventTime, String str, String str2, Throwable th) {
String str3 = str + " [" + getEventTimeString(eventTime);
if (th instanceof PlaybackException) {
str3 = str3 + ", errorCode=" + ((PlaybackException) th).getErrorCodeName();
}
if (str2 != null) {
str3 = str3 + ", " + str2;
}
String throwableString = Log.getThrowableString(th);
if (!TextUtils.isEmpty(throwableString)) {
str3 = str3 + "\n " + throwableString.replace("\n", "\n ") + '\n';
}
return str3 + "]";
}
private String getEventTimeString(AnalyticsListener.EventTime eventTime) {
String str = "window=" + eventTime.windowIndex;
if (eventTime.mediaPeriodId != null) {
str = str + ", period=" + eventTime.timeline.getIndexOfPeriod(eventTime.mediaPeriodId.periodUid);
if (eventTime.mediaPeriodId.isAd()) {
str = (str + ", adGroup=" + eventTime.mediaPeriodId.adGroupIndex) + ", ad=" + eventTime.mediaPeriodId.adIndexInAdGroup;
}
}
return "eventTime=" + getTimeString(eventTime.realtimeMs - this.startTimeMs) + ", mediaPos=" + getTimeString(eventTime.eventPlaybackPositionMs) + ", " + str;
}
private static String getTimeString(long j) {
return j == -9223372036854775807L ? "?" : TIME_FORMAT.format(((float) j) / 1000.0f);
}
}