package p138.p176.p177.p190.p192;

import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.audio.AudioDecoderException;
import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioSink;
import com.google.android.exoplayer2.audio.DefaultAudioSink;
import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.ext.ffmpeg.FfmpegDecoder;
import com.google.android.exoplayer2.ext.ffmpeg.FfmpegLibrary;
import java.util.Collections;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.AbstractC3413;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.C3433;
import p138.p176.p177.p190.C3439;
import p138.p176.p177.p190.p192.InterfaceC3482;
import p138.p176.p177.p190.p193.AbstractC3513;
import p138.p176.p177.p190.p193.C3510;
import p138.p176.p177.p190.p193.C3511;
import p138.p176.p177.p190.p193.C3515;
import p138.p176.p177.p190.p194.C3526;
import p138.p176.p177.p190.p194.C3530;
import p138.p176.p177.p190.p194.InterfaceC3532;
import p138.p176.p177.p190.p194.InterfaceC3536;
import p138.p176.p177.p190.p195.p196.C3546;
import p138.p176.p177.p190.p239.C4134;
import p138.p176.p177.p190.p239.C4150;
import p138.p176.p177.p190.p239.InterfaceC4133;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ࢪ.ޕ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC3499 extends AbstractC3413 implements InterfaceC4133 {

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public final InterfaceC3532<InterfaceC3536> f10374;

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

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public final InterfaceC3482.C3483 f10376;

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public final AudioSink f10377;

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public final C3511 f10378;

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

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

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

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

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

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public AbstractC3513<C3511, ? extends C3515, ? extends AudioDecoderException> f10384;

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

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

    /* JADX INFO: renamed from: ޛ, reason: contains not printable characters */
    public DrmSession<InterfaceC3536> f10387;

    /* JADX INFO: renamed from: ޜ, reason: contains not printable characters */
    public DrmSession<InterfaceC3536> f10388;

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ࢪ.ޕ$ؠ, reason: contains not printable characters */
    public final class C3501 implements AudioSink.InterfaceC0269 {
        public /* synthetic */ C3501(C3500 c3500) {
        }

        @Override // com.google.android.exoplayer2.audio.AudioSink.InterfaceC0269
        /* JADX INFO: renamed from: ֏ */
        public void mo1083(int i) {
            InterfaceC3482.C3483 c3483 = AbstractC3499.this.f10376;
            Handler handler = c3483.f10295;
            if (handler != null) {
                handler.post(new RunnableC3471(c3483, i));
            }
            if (AbstractC3499.this == null) {
                throw null;
            }
        }

        @Override // com.google.android.exoplayer2.audio.AudioSink.InterfaceC0269
        /* JADX INFO: renamed from: ֏ */
        public void mo1084(int i, long j, long j2) {
            AbstractC3499.this.f10376.m5762(i, j, j2);
            if (AbstractC3499.this == null) {
                throw null;
            }
        }

        @Override // com.google.android.exoplayer2.audio.AudioSink.InterfaceC0269
        /* JADX INFO: renamed from: ހ */
        public void mo1085() {
            AbstractC3499 abstractC3499 = AbstractC3499.this;
            if (abstractC3499 == null) {
                throw null;
            }
            abstractC3499.f10394 = true;
        }
    }

    public AbstractC3499(Handler handler, InterfaceC3482 interfaceC3482, InterfaceC3532<InterfaceC3536> interfaceC3532, boolean z, AudioSink audioSink) {
        super(1);
        this.f10374 = interfaceC3532;
        this.f10375 = z;
        this.f10376 = new InterfaceC3482.C3483(handler, interfaceC3482);
        this.f10377 = audioSink;
        audioSink.mo1069(new C3501(null));
        this.f10378 = new C3511(0);
        this.f10389 = 0;
        this.f10391 = true;
    }

    public AbstractC3499(Handler handler, InterfaceC3482 interfaceC3482, AudioProcessor... audioProcessorArr) {
        this(handler, interfaceC3482, null, false, new DefaultAudioSink(null, audioProcessorArr));
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0054  */
    /* JADX WARN: Removed duplicated region for block: B:26:0x0067  */
    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int mo1145(C3431 c3431) {
        boolean z;
        String strM1138;
        if (!C4134.m6657(c3431.f10090)) {
            return 0;
        }
        InterfaceC3532<InterfaceC3536> interfaceC3532 = this.f10374;
        C3546 c3546 = (C3546) this;
        C0567.m1856(c3431.f10090);
        int i = 1;
        if (FfmpegLibrary.m1139()) {
            String str = c3431.f10090;
            if (!FfmpegLibrary.m1139() || (strM1138 = FfmpegLibrary.m1138(str)) == null) {
                z = false;
                if (z) {
                }
            } else if (FfmpegLibrary.ffmpegHasDecoder(strM1138)) {
                z = true;
                if (z) {
                }
            } else {
                Log.w("FfmpegLibrary", "No " + strM1138 + " decoder available. Check the FFmpeg build configuration.");
                z = false;
                if (z) {
                    if (!c3546.m5850(c3431)) {
                        boolean z2 = c3546.f10377.mo1073(c3431.f10103, 2);
                        if (z2) {
                            i = !AbstractC3413.m5437(interfaceC3532, c3431.f10093) ? 2 : 4;
                        }
                    }
                }
            }
        } else {
            i = 0;
        }
        if (i <= 2) {
            return i | 0 | 0;
        }
        return i | 8 | (C4150.f13259 >= 21 ? 32 : 0);
    }

    @Override // p138.p176.p177.p190.AbstractC3413, p138.p176.p177.p190.C3446.InterfaceC3448
    /* JADX INFO: renamed from: ֏ */
    public void mo1309(int i, Object obj) {
        if (i == 2) {
            this.f10377.mo1066(((Float) obj).floatValue());
            return;
        }
        if (i == 3) {
            this.f10377.mo1071((C3478) obj);
        } else {
            if (i != 5) {
                return;
            }
            this.f10377.mo1072((C3488) obj);
        }
    }

    @Override // p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ֏ */
    public void mo1149(long j, long j2) throws ExoPlaybackException {
        if (this.f10396) {
            try {
                this.f10377.mo1077();
                return;
            } catch (AudioSink.WriteException e) {
                throw m5439(e, this.f10381);
            }
        }
        if (this.f10381 == null) {
            C3433 c3433M5457 = m5457();
            this.f10378.mo5803();
            int iM5438 = m5438(c3433M5457, this.f10378, true);
            if (iM5438 != -5) {
                if (iM5438 == -4) {
                    C0567.m1932(this.f10378.m5805());
                    this.f10395 = true;
                    this.f10396 = true;
                    try {
                        this.f10377.mo1077();
                        return;
                    } catch (AudioSink.WriteException e2) {
                        throw m5439(e2, this.f10381);
                    }
                }
                return;
            }
            m5788(c3433M5457);
        }
        m5792();
        if (this.f10384 != null) {
            try {
                C0567.m1892("drainAndFeed");
                while (m5790()) {
                }
                while (m5791()) {
                }
                C0567.m1913();
                this.f10380.m5809();
            } catch (AudioDecoderException | AudioSink.ConfigurationException | AudioSink.InitializationException | AudioSink.WriteException e3) {
                throw m5439(e3, this.f10381);
            }
        }
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    public void mo1150(long j, boolean z) throws ExoPlaybackException {
        this.f10377.flush();
        this.f10392 = j;
        this.f10393 = true;
        this.f10394 = true;
        this.f10395 = false;
        this.f10396 = false;
        if (this.f10384 != null) {
            this.f10397 = false;
            if (this.f10389 != 0) {
                m5793();
                m5792();
                return;
            }
            this.f10385 = null;
            C3515 c3515 = this.f10386;
            if (c3515 != null) {
                c3515.f10482.mo5817(c3515);
                this.f10386 = null;
            }
            this.f10384.flush();
            this.f10390 = false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m5787(DrmSession<InterfaceC3536> drmSession) {
        C3530.m5828(this.f10387, drmSession);
        this.f10387 = drmSession;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m5788(C3433 c3433) throws ExoPlaybackException {
        C3431 c3431 = c3433.f10114;
        C0567.m1856(c3431);
        if (c3433.f10112) {
            m5789(c3433.f10113);
        } else {
            this.f10388 = m5440(this.f10381, c3431, this.f10374, this.f10388);
        }
        this.f10381 = c3431;
        if (this.f10390) {
            this.f10389 = 1;
        } else {
            m5793();
            m5792();
            this.f10391 = true;
        }
        C3431 c34312 = this.f10381;
        this.f10382 = c34312.f10106;
        this.f10383 = c34312.f10107;
        InterfaceC3482.C3483 c3483 = this.f10376;
        Handler handler = c3483.f10295;
        if (handler != null) {
            handler.post(new RunnableC3468(c3483, c34312));
        }
    }

    @Override // p138.p176.p177.p190.p239.InterfaceC4133
    /* JADX INFO: renamed from: ֏ */
    public void mo5471(C3439 c3439) {
        this.f10377.mo1070(c3439);
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    public void mo1159(boolean z) {
        InterfaceC3532<InterfaceC3536> interfaceC3532 = this.f10374;
        if (interfaceC3532 != null && !this.f10379) {
            this.f10379 = true;
            interfaceC3532.mo1129();
        }
        C3510 c3510 = new C3510();
        this.f10380 = c3510;
        InterfaceC3482.C3483 c3483 = this.f10376;
        Handler handler = c3483.f10295;
        if (handler != null) {
            handler.post(new RunnableC3470(c3483, c3510));
        }
        int i = this.f9963.f10180;
        if (i != 0) {
            this.f10377.mo1067(i);
        } else {
            this.f10377.mo1080();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m5789(DrmSession<InterfaceC3536> drmSession) {
        C3530.m5828(this.f10388, drmSession);
        this.f10388 = drmSession;
    }

    @Override // p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ؠ */
    public boolean mo1166() {
        return this.f10396 && this.f10377.mo1075();
    }

    @Override // p138.p176.p177.p190.p239.InterfaceC4133
    /* JADX INFO: renamed from: ހ */
    public C3439 mo5472() {
        return this.f10377.mo1076();
    }

    @Override // p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ރ */
    public boolean mo1169() {
        if (!this.f10377.mo1078()) {
            if (this.f10381 != null && !this.f10397) {
                if ((mo5448() ? this.f9970 : this.f9966.mo6119()) || this.f10386 != null) {
                }
            }
            return false;
        }
        return true;
    }

    @Override // p138.p176.p177.p190.AbstractC3413, p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ފ */
    public InterfaceC4133 mo5454() {
        return this;
    }

    @Override // p138.p176.p177.p190.p239.InterfaceC4133
    /* JADX INFO: renamed from: ލ */
    public long mo5473() {
        if (this.f9965 == 2) {
            m5794();
        }
        return this.f10392;
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ޏ */
    public void mo1170() {
        this.f10381 = null;
        this.f10391 = true;
        this.f10397 = false;
        try {
            m5789(null);
            m5793();
            this.f10377.mo1065();
        } finally {
            this.f10376.m5765(this.f10380);
        }
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ސ */
    public void mo1171() {
        InterfaceC3532<InterfaceC3536> interfaceC3532 = this.f10374;
        if (interfaceC3532 == null || !this.f10379) {
            return;
        }
        this.f10379 = false;
        interfaceC3532.mo1126();
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ޑ */
    public void mo1321() {
        this.f10377.mo1082();
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ޒ */
    public void mo1322() {
        m5794();
        this.f10377.mo1079();
    }

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public final boolean m5790() throws ExoPlaybackException {
        if (this.f10386 == null) {
            C3515 c3515 = (C3515) this.f10384.mo5807();
            this.f10386 = c3515;
            if (c3515 == null) {
                return false;
            }
            int i = c3515.f10467;
            if (i > 0) {
                this.f10380.f10456 += i;
                this.f10377.mo1081();
            }
        }
        if (this.f10386.m5805()) {
            if (this.f10389 == 2) {
                m5793();
                m5792();
                this.f10391 = true;
            } else {
                C3515 c35152 = this.f10386;
                c35152.f10482.mo5817(c35152);
                this.f10386 = null;
                this.f10396 = true;
                try {
                    this.f10377.mo1077();
                } catch (AudioSink.WriteException e) {
                    throw m5439(e, this.f10381);
                }
            }
            return false;
        }
        if (this.f10391) {
            C3546 c3546 = (C3546) this;
            C0567.m1856(c3546.f10522);
            C3431 c3431M5584 = C3431.m5584((String) null, "audio/raw", (String) null, -1, -1, c3546.f10522.f1663, c3546.f10522.f1664, c3546.f10522.f1659, (List<byte[]>) Collections.emptyList(), (C3526) null, 0, (String) null);
            this.f10377.mo1068(c3431M5584.f10105, c3431M5584.f10103, c3431M5584.f10104, 0, null, this.f10382, this.f10383);
            this.f10391 = false;
        }
        AudioSink audioSink = this.f10377;
        C3515 c35153 = this.f10386;
        if (!audioSink.mo1074(c35153.f10483, c35153.f10466)) {
            return false;
        }
        this.f10380.f10455++;
        C3515 c35154 = this.f10386;
        c35154.f10482.mo5817(c35154);
        this.f10386 = null;
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:45:0x0084  */
    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m5791() throws ExoPlaybackException {
        boolean z;
        AbstractC3513<C3511, ? extends C3515, ? extends AudioDecoderException> abstractC3513 = this.f10384;
        if (abstractC3513 == null || this.f10389 == 2 || this.f10395) {
            return false;
        }
        if (this.f10385 == null) {
            C3511 c3511Mo5808 = abstractC3513.mo5808();
            this.f10385 = c3511Mo5808;
            if (c3511Mo5808 == null) {
                return false;
            }
        }
        if (this.f10389 == 1) {
            C3511 c3511 = this.f10385;
            c3511.f10443 = 4;
            this.f10384.mo5806(c3511);
            this.f10385 = null;
            this.f10389 = 2;
            return false;
        }
        C3433 c3433M5457 = m5457();
        int iM5438 = this.f10397 ? -4 : m5438(c3433M5457, this.f10385, false);
        if (iM5438 == -3) {
            return false;
        }
        if (iM5438 == -5) {
            m5788(c3433M5457);
            return true;
        }
        if (this.f10385.m5805()) {
            this.f10395 = true;
            this.f10384.mo5806(this.f10385);
            this.f10385 = null;
            return false;
        }
        boolean zM5813 = this.f10385.m5813();
        DrmSession<InterfaceC3536> drmSession = this.f10387;
        if (drmSession == null || (!zM5813 && (this.f10375 || drmSession.mo1111()))) {
            z = false;
        } else {
            int iMo1113 = this.f10387.mo1113();
            if (iMo1113 == 1) {
                throw m5439(this.f10387.mo1114(), this.f10381);
            }
            if (iMo1113 != 4) {
                z = true;
            }
        }
        this.f10397 = z;
        if (z) {
            return false;
        }
        this.f10385.m5812();
        C3511 c35112 = this.f10385;
        if (this.f10393 && !c35112.m5804()) {
            if (Math.abs(c35112.f10463 - this.f10392) > 500000) {
                this.f10392 = c35112.f10463;
            }
            this.f10393 = false;
        }
        this.f10384.mo5806(this.f10385);
        this.f10390 = true;
        this.f10380.f10453++;
        this.f10385 = null;
        return true;
    }

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public final void m5792() throws ExoPlaybackException {
        if (this.f10384 != null) {
            return;
        }
        m5787(this.f10388);
        DrmSession<InterfaceC3536> drmSession = this.f10387;
        if (drmSession != null && drmSession.mo1112() == null && this.f10387.mo1114() == null) {
            return;
        }
        try {
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            C0567.m1892("createAudioDecoder");
            C3431 c3431 = this.f10381;
            C3546 c3546 = (C3546) this;
            int i = c3431.f10091;
            FfmpegDecoder ffmpegDecoder = new FfmpegDecoder(16, 16, i != -1 ? i : 5760, c3431, c3546.m5850(c3431));
            c3546.f10522 = ffmpegDecoder;
            this.f10384 = ffmpegDecoder;
            C0567.m1913();
            long jElapsedRealtime2 = SystemClock.elapsedRealtime();
            this.f10376.m5763(this.f10384.mo1135(), jElapsedRealtime2, jElapsedRealtime2 - jElapsedRealtime);
            this.f10380.f10451++;
        } catch (AudioDecoderException e) {
            throw m5439(e, this.f10381);
        }
    }

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public final void m5793() {
        this.f10385 = null;
        this.f10386 = null;
        this.f10389 = 0;
        this.f10390 = false;
        AbstractC3513<C3511, ? extends C3515, ? extends AudioDecoderException> abstractC3513 = this.f10384;
        if (abstractC3513 != null) {
            abstractC3513.mo1134();
            this.f10384 = null;
            this.f10380.f10452++;
        }
        m5787((DrmSession<InterfaceC3536>) null);
    }

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public final void m5794() {
        long jMo1064 = this.f10377.mo1064(mo1166());
        if (jMo1064 != Long.MIN_VALUE) {
            if (!this.f10394) {
                jMo1064 = Math.max(this.f10392, jMo1064);
            }
            this.f10392 = jMo1064;
            this.f10394 = false;
        }
    }
}
