package androidx.media3.session;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Player;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
final class SessionPositionInfo {
    public static final SessionPositionInfo DEFAULT;
    public static final Player.PositionInfo DEFAULT_POSITION_INFO;
    private static final String FIELD_BUFFERED_PERCENTAGE;

    @VisibleForTesting
    static final String FIELD_BUFFERED_POSITION_MS;

    @VisibleForTesting
    static final String FIELD_CONTENT_BUFFERED_POSITION_MS;
    private static final String FIELD_CONTENT_DURATION_MS;
    private static final String FIELD_CURRENT_LIVE_OFFSET_MS;
    private static final String FIELD_DURATION_MS;
    private static final String FIELD_EVENT_TIME_MS;
    private static final String FIELD_IS_PLAYING_AD;

    @VisibleForTesting
    static final String FIELD_POSITION_INFO;
    private static final String FIELD_TOTAL_BUFFERED_DURATION_MS;
    public final int bufferedPercentage;
    public final long bufferedPositionMs;
    public final long contentBufferedPositionMs;
    public final long contentDurationMs;
    public final long currentLiveOffsetMs;
    public final long durationMs;
    public final long eventTimeMs;
    public final boolean isPlayingAd;
    public final Player.PositionInfo positionInfo;
    public final long totalBufferedDurationMs;

    static {
        Player.PositionInfo positionInfo = new Player.PositionInfo((Object) null, 0, (MediaItem) null, (Object) null, 0, 0L, 0L, -1, -1);
        DEFAULT_POSITION_INFO = positionInfo;
        DEFAULT = new SessionPositionInfo(positionInfo, false, -9223372036854775807L, -9223372036854775807L, 0L, 0, 0L, -9223372036854775807L, -9223372036854775807L, 0L);
        FIELD_POSITION_INFO = Util.intToStringMaxRadix(0);
        FIELD_IS_PLAYING_AD = Util.intToStringMaxRadix(1);
        FIELD_EVENT_TIME_MS = Util.intToStringMaxRadix(2);
        FIELD_DURATION_MS = Util.intToStringMaxRadix(3);
        FIELD_BUFFERED_POSITION_MS = Util.intToStringMaxRadix(4);
        FIELD_BUFFERED_PERCENTAGE = Util.intToStringMaxRadix(5);
        FIELD_TOTAL_BUFFERED_DURATION_MS = Util.intToStringMaxRadix(6);
        FIELD_CURRENT_LIVE_OFFSET_MS = Util.intToStringMaxRadix(7);
        FIELD_CONTENT_DURATION_MS = Util.intToStringMaxRadix(8);
        FIELD_CONTENT_BUFFERED_POSITION_MS = Util.intToStringMaxRadix(9);
    }

    public SessionPositionInfo(Player.PositionInfo positionInfo, boolean z2, long j2, long j3, long j4, int i2, long j5, long j6, long j7, long j8) {
        Assertions.checkArgument(z2 == (positionInfo.adGroupIndex != -1));
        this.positionInfo = positionInfo;
        this.isPlayingAd = z2;
        this.eventTimeMs = j2;
        this.durationMs = j3;
        this.bufferedPositionMs = j4;
        this.bufferedPercentage = i2;
        this.totalBufferedDurationMs = j5;
        this.currentLiveOffsetMs = j6;
        this.contentDurationMs = j7;
        this.contentBufferedPositionMs = j8;
    }

    public static SessionPositionInfo fromBundle(Bundle bundle) {
        Bundle bundle2 = bundle.getBundle(FIELD_POSITION_INFO);
        return new SessionPositionInfo(bundle2 == null ? DEFAULT_POSITION_INFO : Player.PositionInfo.fromBundle(bundle2), bundle.getBoolean(FIELD_IS_PLAYING_AD, false), bundle.getLong(FIELD_EVENT_TIME_MS, -9223372036854775807L), bundle.getLong(FIELD_DURATION_MS, -9223372036854775807L), bundle.getLong(FIELD_BUFFERED_POSITION_MS, 0L), bundle.getInt(FIELD_BUFFERED_PERCENTAGE, 0), bundle.getLong(FIELD_TOTAL_BUFFERED_DURATION_MS, 0L), bundle.getLong(FIELD_CURRENT_LIVE_OFFSET_MS, -9223372036854775807L), bundle.getLong(FIELD_CONTENT_DURATION_MS, -9223372036854775807L), bundle.getLong(FIELD_CONTENT_BUFFERED_POSITION_MS, 0L));
    }

    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || SessionPositionInfo.class != obj.getClass()) {
            return false;
        }
        SessionPositionInfo sessionPositionInfo = (SessionPositionInfo) obj;
        return this.eventTimeMs == sessionPositionInfo.eventTimeMs && this.positionInfo.equals(sessionPositionInfo.positionInfo) && this.isPlayingAd == sessionPositionInfo.isPlayingAd && this.durationMs == sessionPositionInfo.durationMs && this.bufferedPositionMs == sessionPositionInfo.bufferedPositionMs && this.bufferedPercentage == sessionPositionInfo.bufferedPercentage && this.totalBufferedDurationMs == sessionPositionInfo.totalBufferedDurationMs && this.currentLiveOffsetMs == sessionPositionInfo.currentLiveOffsetMs && this.contentDurationMs == sessionPositionInfo.contentDurationMs && this.contentBufferedPositionMs == sessionPositionInfo.contentBufferedPositionMs;
    }

    public SessionPositionInfo filterByAvailableCommands(boolean z2, boolean z3) {
        if (z2 && z3) {
            return this;
        }
        return new SessionPositionInfo(this.positionInfo.filterByAvailableCommands(z2, z3), z2 && this.isPlayingAd, this.eventTimeMs, z2 ? this.durationMs : -9223372036854775807L, z2 ? this.bufferedPositionMs : 0L, z2 ? this.bufferedPercentage : 0, z2 ? this.totalBufferedDurationMs : 0L, z2 ? this.currentLiveOffsetMs : -9223372036854775807L, z2 ? this.contentDurationMs : -9223372036854775807L, z2 ? this.contentBufferedPositionMs : 0L);
    }

    public int hashCode() {
        return Objects.hash(this.positionInfo, Boolean.valueOf(this.isPlayingAd));
    }

    public Bundle toBundle(int i2) {
        Bundle bundle = new Bundle();
        if (i2 < 3 || !DEFAULT_POSITION_INFO.equalsForBundling(this.positionInfo)) {
            bundle.putBundle(FIELD_POSITION_INFO, this.positionInfo.toBundle(i2));
        }
        boolean z2 = this.isPlayingAd;
        if (z2) {
            bundle.putBoolean(FIELD_IS_PLAYING_AD, z2);
        }
        long j2 = this.eventTimeMs;
        if (j2 != -9223372036854775807L) {
            bundle.putLong(FIELD_EVENT_TIME_MS, j2);
        }
        long j3 = this.durationMs;
        if (j3 != -9223372036854775807L) {
            bundle.putLong(FIELD_DURATION_MS, j3);
        }
        if (i2 < 3 || this.bufferedPositionMs != 0) {
            bundle.putLong(FIELD_BUFFERED_POSITION_MS, this.bufferedPositionMs);
        }
        int i3 = this.bufferedPercentage;
        if (i3 != 0) {
            bundle.putInt(FIELD_BUFFERED_PERCENTAGE, i3);
        }
        long j4 = this.totalBufferedDurationMs;
        if (j4 != 0) {
            bundle.putLong(FIELD_TOTAL_BUFFERED_DURATION_MS, j4);
        }
        long j5 = this.currentLiveOffsetMs;
        if (j5 != -9223372036854775807L) {
            bundle.putLong(FIELD_CURRENT_LIVE_OFFSET_MS, j5);
        }
        long j6 = this.contentDurationMs;
        if (j6 != -9223372036854775807L) {
            bundle.putLong(FIELD_CONTENT_DURATION_MS, j6);
        }
        if (i2 < 3 || this.contentBufferedPositionMs != 0) {
            bundle.putLong(FIELD_CONTENT_BUFFERED_POSITION_MS, this.contentBufferedPositionMs);
        }
        return bundle;
    }

    public String toString() {
        return "SessionPositionInfo {PositionInfo {mediaItemIndex=" + this.positionInfo.mediaItemIndex + ", periodIndex=" + this.positionInfo.periodIndex + ", positionMs=" + this.positionInfo.positionMs + ", contentPositionMs=" + this.positionInfo.contentPositionMs + ", adGroupIndex=" + this.positionInfo.adGroupIndex + ", adIndexInAdGroup=" + this.positionInfo.adIndexInAdGroup + "}, isPlayingAd=" + this.isPlayingAd + ", eventTimeMs=" + this.eventTimeMs + ", durationMs=" + this.durationMs + ", bufferedPositionMs=" + this.bufferedPositionMs + ", bufferedPercentage=" + this.bufferedPercentage + ", totalBufferedDurationMs=" + this.totalBufferedDurationMs + ", currentLiveOffsetMs=" + this.currentLiveOffsetMs + ", contentDurationMs=" + this.contentDurationMs + ", contentBufferedPositionMs=" + this.contentBufferedPositionMs + "}";
    }
}
