package defpackage;

import android.media.MediaCodec;
import android.os.Build;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;

/* JADX INFO: renamed from: ᵵᴵʞˀ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4730 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final int f17984;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C4545 f17985;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public C1889 f17986;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final ᵣˊˈᵪ f17987;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public long f17988;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public C1889 f17989;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public C1889 f17990;

    public C4730(ᵣˊˈᵪ r4) {
        int i;
        this.f17987 = r4;
        synchronized (r4) {
            i = ((C2577) r4.ᵨᵼⁱ).f9955.f8731;
        }
        this.f17984 = i;
        this.f17985 = new C4545(32);
        C1889 c1889 = new C1889(0L, i);
        this.f17989 = c1889;
        this.f17986 = c1889;
        this.f17990 = c1889;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static C1889 m9887(C1889 c1889, long j, byte[] bArr, int i) {
        while (j >= c1889.f7487) {
            c1889 = (C1889) c1889.f7488;
        }
        int i2 = i;
        while (i2 > 0) {
            int iMin = Math.min(i2, (int) (c1889.f7487 - j));
            C1196 c1196 = (C1196) c1889.f7486;
            System.arraycopy(c1196.f5091, ((int) (j - c1889.f7485)) + c1196.f5090, bArr, i - i2, iMin);
            i2 -= iMin;
            j += (long) iMin;
            if (j == c1889.f7487) {
                c1889 = (C1889) c1889.f7488;
            }
        }
        return c1889;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static C1889 m9888(C1889 c1889, long j, ByteBuffer byteBuffer, int i) {
        while (j >= c1889.f7487) {
            c1889 = (C1889) c1889.f7488;
        }
        while (i > 0) {
            int iMin = Math.min(i, (int) (c1889.f7487 - j));
            C1196 c1196 = (C1196) c1889.f7486;
            byteBuffer.put(c1196.f5091, ((int) (j - c1889.f7485)) + c1196.f5090, iMin);
            i -= iMin;
            j += (long) iMin;
            if (j == c1889.f7487) {
                c1889 = (C1889) c1889.f7488;
            }
        }
        return c1889;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static C1889 m9889(C1889 c1889, C3008 c3008, C5019 c5019, C4545 c4545) {
        if (c3008.m6278(1073741824)) {
            long j = c5019.f19018;
            int iM9598 = 1;
            c4545.m9603(1);
            C1889 c1889M9887 = m9887(c1889, j, c4545.f17284, 1);
            long j2 = j + 1;
            byte b = c4545.f17284[0];
            boolean z = (b & 128) != 0;
            int i = b & 127;
            C1243 c1243 = c3008.f11581;
            byte[] bArr = c1243.f5255;
            if (bArr == null) {
                c1243.f5255 = new byte[16];
            } else {
                Arrays.fill(bArr, (byte) 0);
            }
            c1889 = m9887(c1889M9887, j2, c1243.f5255, i);
            long j3 = j2 + ((long) i);
            if (z) {
                c4545.m9603(2);
                c1889 = m9887(c1889, j3, c4545.f17284, 2);
                j3 += 2;
                iM9598 = c4545.m9598();
            }
            int[] iArr = c1243.f5257;
            if (iArr == null || iArr.length < iM9598) {
                iArr = new int[iM9598];
            }
            int[] iArr2 = c1243.f5253;
            if (iArr2 == null || iArr2.length < iM9598) {
                iArr2 = new int[iM9598];
            }
            if (z) {
                int i2 = iM9598 * 6;
                c4545.m9603(i2);
                c1889 = m9887(c1889, j3, c4545.f17284, i2);
                j3 += (long) i2;
                c4545.m9624(0);
                for (int i3 = 0; i3 < iM9598; i3++) {
                    iArr[i3] = c4545.m9598();
                    iArr2[i3] = c4545.m9610();
                }
            } else {
                iArr[0] = 0;
                iArr2[0] = c5019.f19020 - ((int) (j3 - c5019.f19018));
            }
            C1688 c1688 = (C1688) c5019.f19019;
            String str = AbstractC0956.f4222;
            byte[] bArr2 = c1688.f6661;
            byte[] bArr3 = c1243.f5255;
            int i4 = c1688.f6663;
            int i5 = c1688.f6662;
            int i6 = c1688.f6664;
            c1243.f5259 = iM9598;
            c1243.f5257 = iArr;
            c1243.f5253 = iArr2;
            c1243.f5250 = bArr2;
            c1243.f5255 = bArr3;
            c1243.f5252 = i4;
            c1243.f5256 = i5;
            c1243.f5251 = i6;
            MediaCodec.CryptoInfo cryptoInfo = c1243.f5258;
            cryptoInfo.numSubSamples = iM9598;
            cryptoInfo.numBytesOfClearData = iArr;
            cryptoInfo.numBytesOfEncryptedData = iArr2;
            cryptoInfo.key = bArr2;
            cryptoInfo.iv = bArr3;
            cryptoInfo.mode = i4;
            if (Build.VERSION.SDK_INT >= 24) {
                C4491 c4491 = c1243.f5254;
                c4491.getClass();
                C4491.m9542(c4491, i5, i6);
            }
            long j4 = c5019.f19018;
            int i7 = (int) (j3 - j4);
            c5019.f19018 = j4 + ((long) i7);
            c5019.f19020 -= i7;
        }
        if (!c3008.m6278(268435456)) {
            c3008.m7093(c5019.f19020);
            return m9888(c1889, c5019.f19018, c3008.f11582, c5019.f19020);
        }
        c4545.m9603(4);
        C1889 c1889M98872 = m9887(c1889, c5019.f19018, c4545.f17284, 4);
        int iM9610 = c4545.m9610();
        c5019.f19018 += 4;
        c5019.f19020 -= 4;
        c3008.m7093(iM9610);
        C1889 c1889M9888 = m9888(c1889M98872, c5019.f19018, c3008.f11582, iM9610);
        c5019.f19018 += (long) iM9610;
        int i8 = c5019.f19020 - iM9610;
        c5019.f19020 = i8;
        ByteBuffer byteBuffer = c3008.f11578;
        if (byteBuffer == null || byteBuffer.capacity() < i8) {
            c3008.f11578 = ByteBuffer.allocate(i8);
        } else {
            c3008.f11578.clear();
        }
        return m9888(c1889M9888, c5019.f19018, c3008.f11578, c5019.f19020);
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void m9890(long j) {
        C1889 c1889;
        if (j == -1) {
            return;
        }
        while (true) {
            c1889 = this.f17989;
            if (j < c1889.f7487) {
                break;
            }
            ᵣˊˈᵪ r1 = this.f17987;
            C1196 c1196 = (C1196) c1889.f7486;
            synchronized (r1) {
                ((C2577) r1.ᵨᵼⁱ).f9955.m5752(c1196);
                r1.ˊᵡᵗʨ(c1196);
            }
            C1889 c18892 = this.f17989;
            c18892.f7486 = null;
            C1889 c18893 = (C1889) c18892.f7488;
            c18892.f7488 = null;
            this.f17989 = c18893;
        }
        if (this.f17986.f7485 < c1889.f7485) {
            this.f17986 = c1889;
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final int m9891(int i) {
        C1196 c1196M5755;
        C1889 c1889 = this.f17990;
        if (((C1196) c1889.f7486) == null) {
            ᵣˊˈᵪ r1 = this.f17987;
            synchronized (r1) {
                c1196M5755 = ((C2577) r1.ᵨᵼⁱ).f9955.m5755();
                ((HashMap) r1.ᵜᵪʾ).put(c1196M5755, (C2136) r1.ᵔᵖᵹᵫ);
                C2937 c2937 = (C2937) ((C2577) r1.ᵨᵼⁱ).f9957.get((C2136) r1.ᵔᵖᵹᵫ);
                if (c2937 != null) {
                    c2937.m7008();
                }
            }
            C1889 c18892 = new C1889(this.f17990.f7487, this.f17984);
            c1889.f7486 = c1196M5755;
            c1889.f7488 = c18892;
        }
        return Math.min(i, (int) (this.f17990.f7487 - this.f17988));
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m9892(C1889 c1889) {
        if (((C1196) c1889.f7486) == null) {
            return;
        }
        ᵣˊˈᵪ r3 = this.f17987;
        synchronized (r3) {
            ((C2577) r3.ᵨᵼⁱ).f9955.m5753(c1889);
            C1889 c18892 = c1889;
            while (c18892 != null) {
                C1196 c1196 = (C1196) c18892.f7486;
                c1196.getClass();
                r3.ˊᵡᵗʨ(c1196);
                c18892 = (C1889) c18892.f7488;
                if (c18892 == null || ((C1196) c18892.f7486) == null) {
                    c18892 = null;
                }
            }
        }
        c1889.f7486 = null;
        c1889.f7488 = null;
    }
}
