package com.google.android.exoplayer2.audio;

import android.media.AudioAttributes;
import android.media.AudioFormat;
import android.media.AudioTrack;
import android.os.ConditionVariable;
import android.os.SystemClock;
import android.util.Log;
import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioSink;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import p000.p001.p002.p003.p004.C0567;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p190.C3414;
import p138.p176.p177.p190.C3439;
import p138.p176.p177.p190.p192.C3474;
import p138.p176.p177.p190.p192.C3475;
import p138.p176.p177.p190.p192.C3478;
import p138.p176.p177.p190.p192.C3480;
import p138.p176.p177.p190.p192.C3484;
import p138.p176.p177.p190.p192.C3486;
import p138.p176.p177.p190.p192.C3488;
import p138.p176.p177.p190.p192.C3490;
import p138.p176.p177.p190.p192.C3491;
import p138.p176.p177.p190.p192.C3493;
import p138.p176.p177.p190.p192.C3497;
import p138.p176.p177.p190.p192.C3498;
import p138.p176.p177.p190.p192.C3503;
import p138.p176.p177.p190.p192.C3504;
import p138.p176.p177.p190.p198.C3569;
import p138.p176.p177.p190.p239.C4139;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: loaded from: classes.dex */
public final class DefaultAudioSink implements AudioSink {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C3480 f1542;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC0271 f1543;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean f1544;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C3490 f1545;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C3504 f1546;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final AudioProcessor[] f1547;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final AudioProcessor[] f1548;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final ConditionVariable f1549;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final C3486 f1550;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final ArrayDeque<C0274> f1551;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public AudioSink.InterfaceC0269 f1552;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public AudioTrack f1553;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public C0272 f1554;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public C0272 f1555;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public AudioTrack f1556;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public C3478 f1557;

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public C3439 f1558;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public C3439 f1559;

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public long f1560;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public long f1561;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public ByteBuffer f1562;

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public int f1563;

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public long f1564;

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public long f1565;

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public long f1566;

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public long f1567;

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public int f1568;

    /* JADX INFO: renamed from: ޙ, reason: contains not printable characters */
    public int f1569;

    /* JADX INFO: renamed from: ޚ, reason: contains not printable characters */
    public long f1570;

    /* JADX INFO: renamed from: ޛ, reason: contains not printable characters */
    public float f1571;

    /* JADX INFO: renamed from: ޜ, reason: contains not printable characters */
    public AudioProcessor[] f1572;

    /* JADX INFO: renamed from: ޝ, reason: contains not printable characters */
    public ByteBuffer[] f1573;

    /* JADX INFO: renamed from: ޞ, reason: contains not printable characters */
    public ByteBuffer f1574;

    /* JADX INFO: renamed from: ޟ, reason: contains not printable characters */
    public ByteBuffer f1575;

    /* JADX INFO: renamed from: ޠ, reason: contains not printable characters */
    public byte[] f1576;

    /* JADX INFO: renamed from: ޡ, reason: contains not printable characters */
    public int f1577;

    /* JADX INFO: renamed from: ޢ, reason: contains not printable characters */
    public int f1578;

    /* JADX INFO: renamed from: ޣ, reason: contains not printable characters */
    public boolean f1579;

    /* JADX INFO: renamed from: ޤ, reason: contains not printable characters */
    public boolean f1580;

    /* JADX INFO: renamed from: ޥ, reason: contains not printable characters */
    public boolean f1581;

    /* JADX INFO: renamed from: ޱ, reason: contains not printable characters */
    public int f1582;

    /* JADX INFO: renamed from: ࢠ, reason: contains not printable characters */
    public C3488 f1583;

    /* JADX INFO: renamed from: ࢢ, reason: contains not printable characters */
    public boolean f1584;

    /* JADX INFO: renamed from: ࢣ, reason: contains not printable characters */
    public long f1585;

    public static final class InvalidAudioTrackTimestampException extends RuntimeException {
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$֏, reason: contains not printable characters */
    public class C0270 extends Thread {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final /* synthetic */ AudioTrack f1586;

        public C0270(AudioTrack audioTrack) {
            this.f1586 = audioTrack;
        }

        @Override // java.lang.Thread, java.lang.Runnable
        public void run() {
            try {
                this.f1586.flush();
                this.f1586.release();
            } finally {
                DefaultAudioSink.this.f1549.open();
            }
        }
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$ؠ, reason: contains not printable characters */
    public interface InterfaceC0271 {
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        long mo1095();

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        long mo1096(long j);

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        C3439 mo1097(C3439 c3439);

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        AudioProcessor[] mo1098();
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$ހ, reason: contains not printable characters */
    public static final class C0272 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final boolean f1588;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final int f1589;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final int f1590;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final int f1591;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final int f1592;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final int f1593;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public final int f1594;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public final int f1595;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public final boolean f1596;

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public final boolean f1597;

        /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
        public final AudioProcessor[] f1598;

        public C0272(boolean z, int i, int i2, int i3, int i4, int i5, int i6, int i7, boolean z2, boolean z3, AudioProcessor[] audioProcessorArr) {
            int i8;
            int iM6743;
            this.f1588 = z;
            this.f1589 = i;
            this.f1590 = i2;
            this.f1591 = i3;
            this.f1592 = i4;
            this.f1593 = i5;
            this.f1594 = i6;
            if (i7 == 0) {
                if (z) {
                    int minBufferSize = AudioTrack.getMinBufferSize(i4, i5, i6);
                    C0567.m1932(minBufferSize != -2);
                    long j = this.f1592;
                    int i9 = this.f1591;
                    iM6743 = C4150.m6743(minBufferSize * 4, ((int) ((250000 * j) / 1000000)) * i9, (int) Math.max(minBufferSize, ((j * 750000) / 1000000) * ((long) i9)));
                } else {
                    if (i6 == 5) {
                        i8 = 80000;
                    } else if (i6 == 6) {
                        i8 = 768000;
                    } else if (i6 == 7) {
                        i8 = 192000;
                    } else if (i6 == 8) {
                        i8 = 2250000;
                    } else if (i6 == 14) {
                        i8 = 3062500;
                    } else if (i6 != 17) {
                        if (i6 != 18) {
                            throw new IllegalArgumentException();
                        }
                        i8 = 768000;
                    } else {
                        i8 = 336000;
                    }
                    iM6743 = (int) ((((long) (this.f1594 == 5 ? i8 * 2 : i8)) * 250000) / 1000000);
                }
                i7 = iM6743;
            }
            this.f1595 = i7;
            this.f1596 = z2;
            this.f1597 = z3;
            this.f1598 = audioProcessorArr;
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public long m1099(long j) {
            return (j * 1000000) / ((long) this.f1592);
        }
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$ށ, reason: contains not printable characters */
    public static class C0273 implements InterfaceC0271 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final AudioProcessor[] f1599;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final C3498 f1600;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final C3503 f1601;

        public C0273(AudioProcessor... audioProcessorArr) {
            AudioProcessor[] audioProcessorArr2 = new AudioProcessor[audioProcessorArr.length + 2];
            this.f1599 = audioProcessorArr2;
            System.arraycopy(audioProcessorArr, 0, audioProcessorArr2, 0, audioProcessorArr.length);
            this.f1600 = new C3498();
            C3503 c3503 = new C3503();
            this.f1601 = c3503;
            AudioProcessor[] audioProcessorArr3 = this.f1599;
            audioProcessorArr3[audioProcessorArr.length] = this.f1600;
            audioProcessorArr3[audioProcessorArr.length + 1] = c3503;
        }

        @Override // com.google.android.exoplayer2.audio.DefaultAudioSink.InterfaceC0271
        /* JADX INFO: renamed from: ֏ */
        public long mo1095() {
            return this.f1600.f10373;
        }

        @Override // com.google.android.exoplayer2.audio.DefaultAudioSink.InterfaceC0271
        /* JADX INFO: renamed from: ֏ */
        public long mo1096(long j) {
            C3503 c3503 = this.f1601;
            long j2 = c3503.f10434;
            if (j2 < 1024) {
                return (long) (((double) c3503.f10422) * j);
            }
            int i = c3503.f10427.f1538;
            int i2 = c3503.f10426.f1538;
            return i == i2 ? C4150.m6797(j, c3503.f10433, j2) : C4150.m6797(j, c3503.f10433 * ((long) i), j2 * ((long) i2));
        }

        @Override // com.google.android.exoplayer2.audio.DefaultAudioSink.InterfaceC0271
        /* JADX INFO: renamed from: ֏ */
        public C3439 mo1097(C3439 c3439) {
            this.f1600.f10366 = c3439.f10165;
            C3503 c3503 = this.f1601;
            float f = c3439.f10163;
            if (c3503 == null) {
                throw null;
            }
            float fM6740 = C4150.m6740(f, 0.1f, 8.0f);
            if (c3503.f10422 != fM6740) {
                c3503.f10422 = fM6740;
                c3503.f10428 = true;
            }
            C3503 c35032 = this.f1601;
            float f2 = c3439.f10164;
            if (c35032 == null) {
                throw null;
            }
            float fM67402 = C4150.m6740(f2, 0.1f, 8.0f);
            if (c35032.f10423 != fM67402) {
                c35032.f10423 = fM67402;
                c35032.f10428 = true;
            }
            return new C3439(fM6740, fM67402, c3439.f10165);
        }

        @Override // com.google.android.exoplayer2.audio.DefaultAudioSink.InterfaceC0271
        /* JADX INFO: renamed from: ؠ */
        public AudioProcessor[] mo1098() {
            return this.f1599;
        }
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$ނ, reason: contains not printable characters */
    public static final class C0274 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C3439 f1602;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final long f1603;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final long f1604;

        public /* synthetic */ C0274(C3439 c3439, long j, long j2, C0270 c0270) {
            this.f1602 = c3439;
            this.f1603 = j;
            this.f1604 = j2;
        }
    }

    /* JADX INFO: renamed from: com.google.android.exoplayer2.audio.DefaultAudioSink$ރ, reason: contains not printable characters */
    public final class C0275 implements C3486.InterfaceC3487 {
        public /* synthetic */ C0275(C0270 c0270) {
        }

        @Override // p138.p176.p177.p190.p192.C3486.InterfaceC3487
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo1100(int i, long j) {
            if (DefaultAudioSink.this.f1552 != null) {
                long jElapsedRealtime = SystemClock.elapsedRealtime();
                DefaultAudioSink defaultAudioSink = DefaultAudioSink.this;
                defaultAudioSink.f1552.mo1084(i, j, jElapsedRealtime - defaultAudioSink.f1585);
            }
        }

        @Override // p138.p176.p177.p190.p192.C3486.InterfaceC3487
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo1101(long j) {
            Log.w("AudioTrack", "Ignoring impossibly large audio latency: " + j);
        }

        @Override // p138.p176.p177.p190.p192.C3486.InterfaceC3487
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo1102(long j, long j2, long j3, long j4) {
            StringBuilder sb = new StringBuilder();
            sb.append("Spurious audio timestamp (frame position mismatch): ");
            sb.append(j);
            sb.append(", ");
            sb.append(j2);
            sb.append(", ");
            sb.append(j3);
            sb.append(", ");
            sb.append(j4);
            sb.append(", ");
            DefaultAudioSink defaultAudioSink = DefaultAudioSink.this;
            C0272 c0272 = defaultAudioSink.f1555;
            sb.append(c0272.f1588 ? defaultAudioSink.f1564 / ((long) c0272.f1589) : defaultAudioSink.f1565);
            sb.append(", ");
            sb.append(DefaultAudioSink.this.m1091());
            Log.w("AudioTrack", sb.toString());
        }

        @Override // p138.p176.p177.p190.p192.C3486.InterfaceC3487
        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public void mo1103(long j, long j2, long j3, long j4) {
            StringBuilder sb = new StringBuilder();
            sb.append("Spurious audio timestamp (system clock mismatch): ");
            sb.append(j);
            sb.append(", ");
            sb.append(j2);
            sb.append(", ");
            sb.append(j3);
            sb.append(", ");
            sb.append(j4);
            sb.append(", ");
            DefaultAudioSink defaultAudioSink = DefaultAudioSink.this;
            C0272 c0272 = defaultAudioSink.f1555;
            sb.append(c0272.f1588 ? defaultAudioSink.f1564 / ((long) c0272.f1589) : defaultAudioSink.f1565);
            sb.append(", ");
            sb.append(DefaultAudioSink.this.m1091());
            Log.w("AudioTrack", sb.toString());
        }
    }

    public DefaultAudioSink(C3480 c3480, AudioProcessor[] audioProcessorArr) {
        C0273 c0273 = new C0273(audioProcessorArr);
        this.f1542 = c3480;
        this.f1543 = c0273;
        this.f1544 = false;
        this.f1549 = new ConditionVariable(true);
        this.f1550 = new C3486(new C0275(null));
        this.f1545 = new C3490();
        this.f1546 = new C3504();
        ArrayList arrayList = new ArrayList();
        Collections.addAll(arrayList, new C3497(), this.f1545, this.f1546);
        Collections.addAll(arrayList, c0273.mo1098());
        this.f1547 = (AudioProcessor[]) arrayList.toArray(new AudioProcessor[0]);
        this.f1548 = new AudioProcessor[]{new C3493()};
        this.f1571 = 1.0f;
        this.f1569 = 0;
        this.f1557 = C3478.f10285;
        this.f1582 = 0;
        this.f1583 = new C3488(0, 0.0f);
        this.f1559 = C3439.f10162;
        this.f1578 = -1;
        this.f1572 = new AudioProcessor[0];
        this.f1573 = new ByteBuffer[0];
        this.f1551 = new ArrayDeque<>();
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    public void flush() {
        if (m1092()) {
            this.f1564 = 0L;
            this.f1565 = 0L;
            this.f1566 = 0L;
            this.f1567 = 0L;
            this.f1568 = 0;
            C3439 c3439 = this.f1558;
            if (c3439 != null) {
                this.f1559 = c3439;
                this.f1558 = null;
            } else if (!this.f1551.isEmpty()) {
                this.f1559 = this.f1551.getLast().f1602;
            }
            this.f1551.clear();
            this.f1560 = 0L;
            this.f1561 = 0L;
            this.f1546.f10442 = 0L;
            m1090();
            this.f1574 = null;
            this.f1575 = null;
            this.f1580 = false;
            this.f1579 = false;
            this.f1578 = -1;
            this.f1562 = null;
            this.f1563 = 0;
            this.f1569 = 0;
            AudioTrack audioTrack = this.f1550.f10310;
            C0567.m1856(audioTrack);
            if (audioTrack.getPlayState() == 3) {
                this.f1556.pause();
            }
            AudioTrack audioTrack2 = this.f1556;
            this.f1556 = null;
            C0272 c0272 = this.f1554;
            if (c0272 != null) {
                this.f1555 = c0272;
                this.f1554 = null;
            }
            C3486 c3486 = this.f1550;
            c3486.f10317 = 0L;
            c3486.f10328 = 0;
            c3486.f10327 = 0;
            c3486.f10318 = 0L;
            c3486.f10310 = null;
            c3486.f10313 = null;
            this.f1549.close();
            new C0270(audioTrack2).start();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:60:0x0111  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x0118  */
    /* JADX WARN: Removed duplicated region for block: B:96:0x01be  */
    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public long mo1064(boolean z) {
        long jM5773;
        long j;
        long jM6749;
        long j2;
        boolean timestamp;
        Method method;
        if (!m1092() || this.f1569 == 0) {
            return Long.MIN_VALUE;
        }
        C3486 c3486 = this.f1550;
        AudioTrack audioTrack = c3486.f10310;
        C0567.m1856(audioTrack);
        C0274 c0274Remove = null;
        if (audioTrack.getPlayState() == 3) {
            long jM57732 = c3486.m5773(c3486.m5772());
            if (jM57732 != 0) {
                long jNanoTime = System.nanoTime() / 1000;
                if (jNanoTime - c3486.f10318 >= 30000) {
                    long[] jArr = c3486.f10309;
                    int i = c3486.f10327;
                    jArr[i] = jM57732 - jNanoTime;
                    c3486.f10327 = (i + 1) % 10;
                    int i2 = c3486.f10328;
                    if (i2 < 10) {
                        c3486.f10328 = i2 + 1;
                    }
                    c3486.f10318 = jNanoTime;
                    c3486.f10317 = 0L;
                    int i3 = 0;
                    while (true) {
                        int i4 = c3486.f10328;
                        if (i3 >= i4) {
                            break;
                        }
                        c3486.f10317 = (c3486.f10309[i3] / ((long) i4)) + c3486.f10317;
                        i3++;
                    }
                }
                if (!c3486.f10315) {
                    C3484 c3484 = c3486.f10313;
                    C0567.m1856(c3484);
                    C3484.C3485 c3485 = c3484.f10297;
                    if (c3485 == null || jNanoTime - c3484.f10301 < c3484.f10300) {
                        timestamp = false;
                        if (timestamp) {
                            C3484.C3485 c34852 = c3484.f10297;
                            long j3 = c34852 != null ? c34852.f10304.nanoTime / 1000 : -9223372036854775807L;
                            C3484.C3485 c34853 = c3484.f10297;
                            long j4 = c34853 != null ? c34853.f10307 : -1L;
                            if (Math.abs(j3 - jNanoTime) > 5000000) {
                                c3486.f10308.mo1103(j4, j3, jNanoTime, jM57732);
                                c3484.m5771(4);
                            } else if (Math.abs(c3486.m5773(j4) - jM57732) > 5000000) {
                                c3486.f10308.mo1102(j4, j3, jNanoTime, jM57732);
                                c3484.m5771(4);
                            } else if (c3484.f10298 == 4) {
                                c3484.m5770();
                            }
                        }
                        if (!c3486.f10322 && (method = c3486.f10319) != null && jNanoTime - c3486.f10323 >= 500000) {
                            try {
                                AudioTrack audioTrack2 = c3486.f10310;
                                C0567.m1856(audioTrack2);
                                try {
                                    Integer num = (Integer) method.invoke(audioTrack2, new Object[0]);
                                    C4150.m6755(num);
                                    long jIntValue = (((long) num.intValue()) * 1000) - c3486.f10316;
                                    c3486.f10320 = jIntValue;
                                    long jMax = Math.max(jIntValue, 0L);
                                    c3486.f10320 = jMax;
                                    if (jMax > 5000000) {
                                        c3486.f10308.mo1101(jMax);
                                        c3486.f10320 = 0L;
                                    }
                                } catch (Exception unused) {
                                    c3486.f10319 = null;
                                }
                            } catch (Exception unused2) {
                            }
                            c3486.f10323 = jNanoTime;
                        }
                    } else {
                        c3484.f10301 = jNanoTime;
                        timestamp = c3485.f10303.getTimestamp(c3485.f10304);
                        if (timestamp) {
                            long j5 = c3485.f10304.framePosition;
                            if (c3485.f10306 > j5) {
                                c3485.f10305++;
                            }
                            c3485.f10306 = j5;
                            c3485.f10307 = j5 + (c3485.f10305 << 32);
                        }
                        int i5 = c3484.f10298;
                        if (i5 != 0) {
                            if (i5 != 1) {
                                if (i5 != 2) {
                                    if (i5 != 3) {
                                        if (i5 != 4) {
                                            throw new IllegalStateException();
                                        }
                                    } else if (timestamp) {
                                        c3484.m5770();
                                    }
                                } else if (!timestamp) {
                                    c3484.m5770();
                                }
                            } else if (!timestamp) {
                                c3484.m5770();
                            } else if (c3484.f10297.f10307 > c3484.f10302) {
                                c3484.m5771(2);
                            }
                        } else if (timestamp) {
                            C3484.C3485 c34854 = c3484.f10297;
                            if (c34854.f10304.nanoTime / 1000 >= c3484.f10299) {
                                c3484.f10302 = c34854.f10307;
                                c3484.m5771(1);
                            }
                        } else if (jNanoTime - c3484.f10299 > 500000) {
                            c3484.m5771(3);
                        }
                        if (timestamp) {
                        }
                        if (!c3486.f10322) {
                        }
                    }
                }
            }
        }
        long jNanoTime2 = System.nanoTime() / 1000;
        C3484 c34842 = c3486.f10313;
        C0567.m1856(c34842);
        int i6 = c34842.f10298;
        if (i6 == 1 || i6 == 2) {
            C3484.C3485 c34855 = c34842.f10297;
            jM5773 = c3486.m5773(c34855 != null ? c34855.f10307 : -1L);
            if (c34842.f10298 == 2) {
                C3484.C3485 c34856 = c34842.f10297;
                jM5773 += jNanoTime2 - (c34856 != null ? c34856.f10304.nanoTime / 1000 : -9223372036854775807L);
            }
        } else {
            long jM57733 = c3486.f10328 == 0 ? c3486.m5773(c3486.m5772()) : jNanoTime2 + c3486.f10317;
            if (!z) {
                jM57733 -= c3486.f10320;
            }
            jM5773 = jM57733;
        }
        long jMin = Math.min(jM5773, this.f1555.m1099(m1091()));
        long j6 = this.f1570;
        while (!this.f1551.isEmpty() && jMin >= this.f1551.getFirst().f1604) {
            c0274Remove = this.f1551.remove();
        }
        if (c0274Remove != null) {
            this.f1559 = c0274Remove.f1602;
            this.f1561 = c0274Remove.f1604;
            this.f1560 = c0274Remove.f1603 - this.f1570;
        }
        if (this.f1559.f10163 == 1.0f) {
            j2 = (jMin + this.f1560) - this.f1561;
        } else {
            if (this.f1551.isEmpty()) {
                j = this.f1560;
                jM6749 = this.f1543.mo1096(jMin - this.f1561);
            } else {
                j = this.f1560;
                jM6749 = C4150.m6749(jMin - this.f1561, this.f1559.f10163);
            }
            j2 = jM6749 + j;
        }
        return j6 + this.f1555.m1099(this.f1543.mo1095()) + j2;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1065() {
        flush();
        AudioTrack audioTrack = this.f1553;
        if (audioTrack != null) {
            this.f1553 = null;
            new C3491(this, audioTrack).start();
        }
        for (AudioProcessor audioProcessor : this.f1547) {
            audioProcessor.mo1058();
        }
        for (AudioProcessor audioProcessor2 : this.f1548) {
            audioProcessor2.mo1058();
        }
        this.f1582 = 0;
        this.f1581 = false;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1066(float f) {
        if (this.f1571 != f) {
            this.f1571 = f;
            m1094();
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1067(int i) {
        C0567.m1932(C4150.f13259 >= 21);
        if (this.f1584 && this.f1582 == i) {
            return;
        }
        this.f1584 = true;
        this.f1582 = i;
        flush();
    }

    /* JADX WARN: Removed duplicated region for block: B:47:0x0098  */
    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void mo1068(int i, int i2, int i3, int i4, int[] iArr, int i5, int i6) throws AudioSink.ConfigurationException {
        int[] iArr2;
        int i7;
        int i8;
        int i9;
        int i10;
        int i11 = 8;
        if (C4150.f13259 < 21 && i2 == 8 && iArr == null) {
            iArr2 = new int[6];
            for (int i12 = 0; i12 < 6; i12++) {
                iArr2[i12] = i12;
            }
        } else {
            iArr2 = iArr;
        }
        boolean zM6804 = C4150.m6804(i);
        boolean z = this.f1544 && mo1073(i2, 4) && C4150.m6801(i);
        AudioProcessor[] audioProcessorArr = z ? this.f1548 : this.f1547;
        if (zM6804) {
            C3504 c3504 = this.f1546;
            c3504.f10436 = i5;
            c3504.f10437 = i6;
            this.f1545.f10342 = iArr2;
            AudioProcessor.C0268 c0268 = new AudioProcessor.C0268(i3, i2, i);
            for (AudioProcessor audioProcessor : audioProcessorArr) {
                try {
                    AudioProcessor.C0268 c0268Mo1057 = audioProcessor.mo1057(c0268);
                    if (audioProcessor.mo1061()) {
                        c0268 = c0268Mo1057;
                    }
                } catch (AudioProcessor.UnhandledAudioFormatException e) {
                    throw new AudioSink.ConfigurationException(e);
                }
            }
            int i13 = c0268.f1538;
            i7 = c0268.f1539;
            i8 = c0268.f1540;
            i9 = i13;
        } else {
            i7 = i2;
            i8 = i;
            i9 = i3;
        }
        if (C4150.f13259 > 28 || zM6804) {
            i11 = i7;
        } else if (i7 != 7) {
            if (i7 == 3 || i7 == 4 || i7 == 5) {
                i11 = 6;
            }
        }
        if (C4150.f13259 <= 26 && "fugu".equals(C4150.f13260) && !zM6804 && i11 == 1) {
            i11 = 2;
        }
        switch (i11) {
            case 1:
                i10 = 4;
                break;
            case 2:
                i10 = 12;
                break;
            case 3:
                i10 = 28;
                break;
            case 4:
                i10 = 204;
                break;
            case 5:
                i10 = 220;
                break;
            case 6:
                i10 = 252;
                break;
            case 7:
                i10 = 1276;
                break;
            case 8:
                int i14 = C4150.f13259;
                if (i14 >= 23 || i14 >= 21) {
                    i10 = 6396;
                    break;
                }
            default:
                i10 = 0;
                break;
        }
        if (i10 == 0) {
            throw new AudioSink.ConfigurationException(C2803.m4871("Unsupported channel count: ", i7));
        }
        C0272 c0272 = new C0272(zM6804, zM6804 ? C4150.m6783(i, i2) : -1, i3, zM6804 ? C4150.m6783(i8, i7) : -1, i9, i10, i8, i4, zM6804, zM6804 && !z, audioProcessorArr);
        if (m1092()) {
            this.f1554 = c0272;
        } else {
            this.f1555 = c0272;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m1086(long j) throws AudioSink.WriteException {
        ByteBuffer byteBuffer;
        int length = this.f1572.length;
        int i = length;
        while (i >= 0) {
            if (i > 0) {
                byteBuffer = this.f1573[i - 1];
            } else {
                byteBuffer = this.f1574;
                if (byteBuffer == null) {
                    byteBuffer = AudioProcessor.f1536;
                }
            }
            if (i == length) {
                m1088(byteBuffer, j);
            } else {
                AudioProcessor audioProcessor = this.f1572[i];
                audioProcessor.mo1059(byteBuffer);
                ByteBuffer byteBufferMo1062 = audioProcessor.mo1062();
                this.f1573[i] = byteBufferMo1062;
                if (byteBufferMo1062.hasRemaining()) {
                    i++;
                }
            }
            if (byteBuffer.hasRemaining()) {
                return;
            } else {
                i--;
            }
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1069(AudioSink.InterfaceC0269 interfaceC0269) {
        this.f1552 = interfaceC0269;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1070(C3439 c3439) {
        C0272 c0272 = this.f1555;
        if (c0272 != null && !c0272.f1597) {
            this.f1559 = C3439.f10162;
        } else {
            if (c3439.equals(mo1076())) {
                return;
            }
            if (m1092()) {
                this.f1558 = c3439;
            } else {
                this.f1559 = c3439;
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m1087(C3439 c3439, long j) {
        this.f1551.add(new C0274(this.f1555.f1597 ? this.f1543.mo1097(c3439) : C3439.f10162, Math.max(0L, j), this.f1555.m1099(m1091()), null));
        AudioProcessor[] audioProcessorArr = this.f1555.f1598;
        ArrayList arrayList = new ArrayList();
        for (AudioProcessor audioProcessor : audioProcessorArr) {
            if (audioProcessor.mo1061()) {
                arrayList.add(audioProcessor);
            } else {
                audioProcessor.flush();
            }
        }
        int size = arrayList.size();
        this.f1572 = (AudioProcessor[]) arrayList.toArray(new AudioProcessor[size]);
        this.f1573 = new ByteBuffer[size];
        m1090();
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1071(C3478 c3478) {
        if (this.f1557.equals(c3478)) {
            return;
        }
        this.f1557 = c3478;
        if (this.f1584) {
            return;
        }
        flush();
        this.f1582 = 0;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public void mo1072(C3488 c3488) {
        if (this.f1583.equals(c3488)) {
            return;
        }
        int i = c3488.f10333;
        float f = c3488.f10334;
        AudioTrack audioTrack = this.f1556;
        if (audioTrack != null) {
            if (this.f1583.f10333 != i) {
                audioTrack.attachAuxEffect(i);
            }
            if (i != 0) {
                this.f1556.setAuxEffectSendLevel(f);
            }
        }
        this.f1583 = c3488;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    public boolean mo1073(int i, int i2) {
        if (C4150.m6804(i2)) {
            return i2 != 4 || C4150.f13259 >= 21;
        }
        C3480 c3480 = this.f1542;
        if (c3480 != null) {
            if ((Arrays.binarySearch(c3480.f10293, i2) >= 0) && (i == -1 || i <= this.f1542.f10294)) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:137:0x02bb  */
    /* JADX WARN: Removed duplicated region for block: B:170:0x036c A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:81:0x01d6  */
    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean mo1074(ByteBuffer byteBuffer, long j) throws AudioSink.WriteException, AudioSink.InitializationException {
        boolean z;
        C3486.InterfaceC3487 interfaceC3487;
        int i;
        int i2;
        int i3;
        byte b;
        int i4;
        byte b2;
        int i5;
        int i6;
        AudioTrack audioTrack;
        ByteBuffer byteBuffer2 = this.f1574;
        C0567.m1896(byteBuffer2 == null || byteBuffer == byteBuffer2);
        if (this.f1554 != null) {
            if (!m1089()) {
                return false;
            }
            C0272 c0272 = this.f1554;
            C0272 c02722 = this.f1555;
            if (c0272 == null) {
                throw null;
            }
            if (c02722.f1594 == c0272.f1594 && c02722.f1592 == c0272.f1592 && c02722.f1593 == c0272.f1593) {
                this.f1555 = this.f1554;
                this.f1554 = null;
            } else {
                m1093();
                if (mo1078()) {
                    return false;
                }
                flush();
            }
            m1087(this.f1559, j);
        }
        if (!m1092()) {
            this.f1549.block();
            C0272 c02723 = this.f1555;
            C0567.m1856(c02723);
            boolean z2 = this.f1584;
            C3478 c3478 = this.f1557;
            int i7 = this.f1582;
            if (C4150.f13259 >= 21) {
                audioTrack = new AudioTrack(z2 ? new AudioAttributes.Builder().setContentType(3).setFlags(16).setUsage(1).build() : c3478.m5758(), new AudioFormat.Builder().setChannelMask(c02723.f1593).setEncoding(c02723.f1594).setSampleRate(c02723.f1592).build(), c02723.f1595, 1, i7 != 0 ? i7 : 0);
            } else {
                int iM6782 = C4150.m6782(c3478.f10288);
                audioTrack = i7 == 0 ? new AudioTrack(iM6782, c02723.f1592, c02723.f1593, c02723.f1594, c02723.f1595, 1) : new AudioTrack(iM6782, c02723.f1592, c02723.f1593, c02723.f1594, c02723.f1595, 1, i7);
            }
            int state = audioTrack.getState();
            if (state != 1) {
                try {
                    audioTrack.release();
                } catch (Exception unused) {
                }
                throw new AudioSink.InitializationException(state, c02723.f1592, c02723.f1593, c02723.f1595);
            }
            this.f1556 = audioTrack;
            int audioSessionId = audioTrack.getAudioSessionId();
            if (this.f1582 != audioSessionId) {
                this.f1582 = audioSessionId;
                AudioSink.InterfaceC0269 interfaceC0269 = this.f1552;
                if (interfaceC0269 != null) {
                    interfaceC0269.mo1083(audioSessionId);
                }
            }
            m1087(this.f1559, j);
            C3486 c3486 = this.f1550;
            AudioTrack audioTrack2 = this.f1556;
            C0272 c02724 = this.f1555;
            int i8 = c02724.f1594;
            int i9 = c02724.f1591;
            int i10 = c02724.f1595;
            c3486.f10310 = audioTrack2;
            c3486.f10311 = i9;
            c3486.f10312 = i10;
            c3486.f10313 = new C3484(audioTrack2);
            c3486.f10314 = audioTrack2.getSampleRate();
            c3486.f10315 = C4150.f13259 < 23 && (i8 == 5 || i8 == 6);
            boolean zM6804 = C4150.m6804(i8);
            c3486.f10322 = zM6804;
            c3486.f10316 = zM6804 ? c3486.m5773(i10 / i9) : -9223372036854775807L;
            c3486.f10324 = 0L;
            c3486.f10325 = 0L;
            c3486.f10326 = 0L;
            c3486.f10321 = false;
            c3486.f10329 = -9223372036854775807L;
            c3486.f10330 = -9223372036854775807L;
            c3486.f10320 = 0L;
            m1094();
            int i11 = this.f1583.f10333;
            if (i11 != 0) {
                this.f1556.attachAuxEffect(i11);
                this.f1556.setAuxEffectSendLevel(this.f1583.f10334);
            }
            if (this.f1581) {
                mo1082();
            }
        }
        C3486 c34862 = this.f1550;
        long jM1091 = m1091();
        AudioTrack audioTrack3 = c34862.f10310;
        C0567.m1856(audioTrack3);
        int playState = audioTrack3.getPlayState();
        if (c34862.f10315) {
            if (playState == 2) {
                c34862.f10321 = false;
            } else if (playState != 1 || c34862.m5772() != 0) {
            }
            z = false;
        } else {
            boolean z3 = c34862.f10321;
            boolean zM5774 = c34862.m5774(jM1091);
            c34862.f10321 = zM5774;
            if (z3 && !zM5774 && playState != 1 && (interfaceC3487 = c34862.f10308) != null) {
                interfaceC3487.mo1100(c34862.f10312, C3414.m5459(c34862.f10316));
            }
            z = true;
        }
        if (!z) {
            return false;
        }
        if (this.f1574 == null) {
            if (!byteBuffer.hasRemaining()) {
                return true;
            }
            C0272 c02725 = this.f1555;
            if (!c02725.f1588 && this.f1568 == 0) {
                int i12 = c02725.f1594;
                int iM5902 = -1;
                if (i12 != 14) {
                    if (i12 == 17) {
                        byte[] bArr = new byte[16];
                        int iPosition = byteBuffer.position();
                        byteBuffer.get(bArr);
                        byteBuffer.position(iPosition);
                        iM5902 = C3475.m5756(new C4139(bArr)).f10284;
                    } else if (i12 != 18) {
                        switch (i12) {
                            case 5:
                            case 6:
                                if (!(((byteBuffer.get(byteBuffer.position() + 5) & 248) >> 3) > 10)) {
                                    iM5902 = 1536;
                                } else {
                                    i2 = C3474.f10274[((byteBuffer.get(byteBuffer.position() + 4) & 192) >> 6) != 3 ? (byteBuffer.get(byteBuffer.position() + 4) & 48) >> 4 : 3] * 256;
                                    iM5902 = i2;
                                }
                                break;
                            case 7:
                            case 8:
                                int iPosition2 = byteBuffer.position();
                                byte b3 = byteBuffer.get(iPosition2);
                                if (b3 != -2) {
                                    if (b3 == -1) {
                                        i3 = (byteBuffer.get(iPosition2 + 4) & 7) << 4;
                                        b2 = byteBuffer.get(iPosition2 + 7);
                                    } else if (b3 != 31) {
                                        i3 = (byteBuffer.get(iPosition2 + 4) & 1) << 6;
                                        b = byteBuffer.get(iPosition2 + 5);
                                    } else {
                                        i3 = (byteBuffer.get(iPosition2 + 5) & 7) << 4;
                                        b2 = byteBuffer.get(iPosition2 + 6);
                                    }
                                    i4 = b2 & 60;
                                    iM5902 = (((i4 >> 2) | i3) + 1) * 32;
                                } else {
                                    i3 = (byteBuffer.get(iPosition2 + 5) & 1) << 6;
                                    b = byteBuffer.get(iPosition2 + 4);
                                }
                                i4 = b & 252;
                                iM5902 = (((i4 >> 2) | i3) + 1) * 32;
                                break;
                            case 9:
                                byte b4 = byteBuffer.get(byteBuffer.position());
                                if (C3569.m5904(b4) && (i5 = (b4 >>> 19) & 3) != 1 && (i6 = (b4 >>> 17) & 3) != 0) {
                                    int i13 = (b4 >>> 12) & 15;
                                    int i14 = (b4 >>> 10) & 3;
                                    if (i13 != 0 && i13 != 15 && i14 != 3) {
                                        iM5902 = C3569.m5902(i5, i6);
                                    }
                                }
                                break;
                            default:
                                throw new IllegalStateException(C2803.m4871("Unexpected audio encoding: ", i12));
                        }
                    }
                    this.f1568 = iM5902;
                    if (iM5902 == 0) {
                        return true;
                    }
                } else {
                    int iPosition3 = byteBuffer.position();
                    int iLimit = byteBuffer.limit() - 10;
                    int i15 = iPosition3;
                    while (true) {
                        if (i15 > iLimit) {
                            i = -1;
                            break;
                        }
                        if ((byteBuffer.getInt(i15 + 4) & (-16777217)) == -1167101192) {
                            i = i15 - iPosition3;
                            break;
                        }
                        i15++;
                    }
                    if (i == -1) {
                        iM5902 = 0;
                        this.f1568 = iM5902;
                        if (iM5902 == 0) {
                        }
                    } else {
                        i2 = (40 << ((byteBuffer.get((byteBuffer.position() + i) + ((byteBuffer.get((byteBuffer.position() + i) + 7) & 255) == 187 ? 9 : 8)) >> 4) & 7)) * 16;
                        iM5902 = i2;
                        this.f1568 = iM5902;
                        if (iM5902 == 0) {
                        }
                    }
                }
            }
            if (this.f1558 != null) {
                if (!m1089()) {
                    return false;
                }
                C3439 c3439 = this.f1558;
                this.f1558 = null;
                m1087(c3439, j);
            }
            if (this.f1569 == 0) {
                this.f1570 = Math.max(0L, j);
                this.f1569 = 1;
            } else {
                long j2 = this.f1570;
                C0272 c02726 = this.f1555;
                long j3 = ((((c02726.f1588 ? this.f1564 / ((long) c02726.f1589) : this.f1565) - this.f1546.f10442) * 1000000) / ((long) c02726.f1590)) + j2;
                if (this.f1569 == 1 && Math.abs(j3 - j) > 200000) {
                    Log.e("AudioTrack", "Discontinuity detected [expected " + j3 + ", got " + j + "]");
                    this.f1569 = 2;
                }
                if (this.f1569 == 2) {
                    long j4 = j - j3;
                    this.f1570 += j4;
                    this.f1569 = 1;
                    AudioSink.InterfaceC0269 interfaceC02692 = this.f1552;
                    if (interfaceC02692 != null && j4 != 0) {
                        interfaceC02692.mo1085();
                    }
                }
            }
            if (this.f1555.f1588) {
                this.f1564 += (long) byteBuffer.remaining();
            } else {
                this.f1565 += (long) this.f1568;
            }
            this.f1574 = byteBuffer;
        }
        if (this.f1555.f1596) {
            m1086(j);
        } else {
            m1088(this.f1574, j);
        }
        if (!this.f1574.hasRemaining()) {
            this.f1574 = null;
            return true;
        }
        C3486 c34863 = this.f1550;
        if (!(c34863.f10330 != -9223372036854775807L && m1091() > 0 && SystemClock.elapsedRealtime() - c34863.f10330 >= 200)) {
            return false;
        }
        Log.w("AudioTrack", "Resetting stalled audio track");
        flush();
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:48:0x00e7  */
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m1088(ByteBuffer byteBuffer, long j) throws AudioSink.WriteException {
        if (byteBuffer.hasRemaining()) {
            ByteBuffer byteBuffer2 = this.f1575;
            int iWrite = 0;
            if (byteBuffer2 != null) {
                C0567.m1896(byteBuffer2 == byteBuffer);
            } else {
                this.f1575 = byteBuffer;
                if (C4150.f13259 < 21) {
                    int iRemaining = byteBuffer.remaining();
                    byte[] bArr = this.f1576;
                    if (bArr == null || bArr.length < iRemaining) {
                        this.f1576 = new byte[iRemaining];
                    }
                    int iPosition = byteBuffer.position();
                    byteBuffer.get(this.f1576, 0, iRemaining);
                    byteBuffer.position(iPosition);
                    this.f1577 = 0;
                }
            }
            int iRemaining2 = byteBuffer.remaining();
            if (C4150.f13259 < 21) {
                C3486 c3486 = this.f1550;
                int iM5772 = c3486.f10312 - ((int) (this.f1566 - (c3486.m5772() * ((long) c3486.f10311))));
                if (iM5772 > 0) {
                    iWrite = this.f1556.write(this.f1576, this.f1577, Math.min(iRemaining2, iM5772));
                    if (iWrite > 0) {
                        this.f1577 += iWrite;
                        byteBuffer.position(byteBuffer.position() + iWrite);
                    }
                }
            } else if (this.f1584) {
                C0567.m1932(j != -9223372036854775807L);
                AudioTrack audioTrack = this.f1556;
                if (C4150.f13259 >= 26) {
                    iWrite = audioTrack.write(byteBuffer, iRemaining2, 1, j * 1000);
                } else {
                    if (this.f1562 == null) {
                        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(16);
                        this.f1562 = byteBufferAllocate;
                        byteBufferAllocate.order(ByteOrder.BIG_ENDIAN);
                        this.f1562.putInt(1431633921);
                    }
                    if (this.f1563 == 0) {
                        this.f1562.putInt(4, iRemaining2);
                        this.f1562.putLong(8, j * 1000);
                        this.f1562.position(0);
                        this.f1563 = iRemaining2;
                    }
                    int iRemaining3 = this.f1562.remaining();
                    if (iRemaining3 <= 0) {
                        int iWrite2 = audioTrack.write(byteBuffer, iRemaining2, 1);
                        if (iWrite2 < 0) {
                            this.f1563 = 0;
                        } else {
                            this.f1563 -= iWrite2;
                        }
                        iWrite = iWrite2;
                    } else {
                        int iWrite3 = audioTrack.write(this.f1562, iRemaining3, 1);
                        if (iWrite3 < 0) {
                            this.f1563 = 0;
                            iWrite = iWrite3;
                        } else if (iWrite3 >= iRemaining3) {
                        }
                    }
                }
            } else {
                iWrite = this.f1556.write(byteBuffer, iRemaining2, 1);
            }
            this.f1585 = SystemClock.elapsedRealtime();
            if (iWrite < 0) {
                throw new AudioSink.WriteException(iWrite);
            }
            if (this.f1555.f1588) {
                this.f1566 += (long) iWrite;
            }
            if (iWrite == iRemaining2) {
                if (!this.f1555.f1588) {
                    this.f1567 += (long) this.f1568;
                }
                this.f1575 = null;
            }
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ؠ */
    public boolean mo1075() {
        return !m1092() || (this.f1579 && !mo1078());
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ހ */
    public C3439 mo1076() {
        C3439 c3439 = this.f1558;
        return c3439 != null ? c3439 : !this.f1551.isEmpty() ? this.f1551.getLast().f1602 : this.f1559;
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ށ */
    public void mo1077() {
        if (!this.f1579 && m1092() && m1089()) {
            m1093();
            this.f1579 = true;
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ނ */
    public boolean mo1078() {
        return m1092() && this.f1550.m5774(m1091());
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ރ */
    public void mo1079() {
        boolean z = false;
        this.f1581 = false;
        if (m1092()) {
            C3486 c3486 = this.f1550;
            c3486.f10317 = 0L;
            c3486.f10328 = 0;
            c3486.f10327 = 0;
            c3486.f10318 = 0L;
            if (c3486.f10329 == -9223372036854775807L) {
                C3484 c3484 = c3486.f10313;
                C0567.m1856(c3484);
                c3484.m5770();
                z = true;
            }
            if (z) {
                this.f1556.pause();
            }
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ބ */
    public void mo1080() {
        if (this.f1584) {
            this.f1584 = false;
            this.f1582 = 0;
            flush();
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ޅ */
    public void mo1081() {
        if (this.f1569 == 1) {
            this.f1569 = 2;
        }
    }

    @Override // com.google.android.exoplayer2.audio.AudioSink
    /* JADX INFO: renamed from: ކ */
    public void mo1082() {
        this.f1581 = true;
        if (m1092()) {
            C3484 c3484 = this.f1550.f10313;
            C0567.m1856(c3484);
            c3484.m5770();
            this.f1556.play();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0023  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x003a  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:19:0x0034 -> B:9:0x0014). Please report as a decompilation issue!!! */
    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m1089() throws AudioSink.WriteException {
        boolean z;
        int i;
        AudioProcessor[] audioProcessorArr;
        if (this.f1578 == -1) {
            this.f1578 = this.f1555.f1596 ? 0 : this.f1572.length;
            z = true;
            i = this.f1578;
            audioProcessorArr = this.f1572;
            if (i < audioProcessorArr.length) {
                AudioProcessor audioProcessor = audioProcessorArr[i];
                if (z) {
                    audioProcessor.mo1063();
                }
                m1086(-9223372036854775807L);
                if (!audioProcessor.mo1060()) {
                    return false;
                }
                this.f1578++;
                z = true;
                i = this.f1578;
                audioProcessorArr = this.f1572;
                if (i < audioProcessorArr.length) {
                    ByteBuffer byteBuffer = this.f1575;
                    if (byteBuffer != null) {
                        m1088(byteBuffer, -9223372036854775807L);
                        if (this.f1575 != null) {
                            return false;
                        }
                    }
                    this.f1578 = -1;
                    return true;
                }
            }
        } else {
            z = false;
            i = this.f1578;
            audioProcessorArr = this.f1572;
            if (i < audioProcessorArr.length) {
            }
        }
    }

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final void m1090() {
        int i = 0;
        while (true) {
            AudioProcessor[] audioProcessorArr = this.f1572;
            if (i >= audioProcessorArr.length) {
                return;
            }
            AudioProcessor audioProcessor = audioProcessorArr[i];
            audioProcessor.flush();
            this.f1573[i] = audioProcessor.mo1062();
            i++;
        }
    }

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public final long m1091() {
        C0272 c0272 = this.f1555;
        return c0272.f1588 ? this.f1566 / ((long) c0272.f1591) : this.f1567;
    }

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final boolean m1092() {
        return this.f1556 != null;
    }

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public final void m1093() {
        if (this.f1580) {
            return;
        }
        this.f1580 = true;
        C3486 c3486 = this.f1550;
        long jM1091 = m1091();
        c3486.f10331 = c3486.m5772();
        c3486.f10329 = SystemClock.elapsedRealtime() * 1000;
        c3486.f10332 = jM1091;
        this.f1556.stop();
        this.f1563 = 0;
    }

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public final void m1094() {
        if (m1092()) {
            if (C4150.f13259 >= 21) {
                this.f1556.setVolume(this.f1571);
                return;
            }
            AudioTrack audioTrack = this.f1556;
            float f = this.f1571;
            audioTrack.setStereoVolume(f, f);
        }
    }
}
