package p138.p176.p177.p190.p226;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import java.util.Collections;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p190.AbstractC3413;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.C3433;
import p138.p176.p177.p190.p193.C3511;
import p138.p176.p177.p190.p194.InterfaceC3532;
import p138.p176.p177.p190.p226.InterfaceC3951;
import p138.p176.p177.p190.p239.C4131;
import p138.p176.p177.p190.p239.C4134;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໟ.ވ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3956 extends AbstractC3413 implements Handler.Callback {

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public final Handler f12395;

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

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public final InterfaceC3951 f12397;

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

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

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

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

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

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C3956(InterfaceC3955 interfaceC3955, Looper looper) {
        super(3);
        InterfaceC3951 interfaceC3951 = InterfaceC3951.f12391;
        if (interfaceC3955 == null) {
            throw null;
        }
        this.f12396 = interfaceC3955;
        this.f12395 = looper != null ? C4150.m6754(looper, (Handler.Callback) this) : null;
        this.f12397 = interfaceC3951;
        this.f12398 = new C3433();
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(Message message) {
        if (message.what != 0) {
            throw new IllegalStateException();
        }
        this.f12396.mo1278((List) message.obj);
        return true;
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    public int mo1145(C3431 c3431) {
        if (((InterfaceC3951.C3952) this.f12397) == null) {
            throw null;
        }
        String str = c3431.f10090;
        if ("text/vtt".equals(str) || "text/x-ssa".equals(str) || "application/ttml+xml".equals(str) || "application/x-mp4-vtt".equals(str) || "application/x-subrip".equals(str) || "application/x-quicktime-tx3g".equals(str) || "application/cea-608".equals(str) || "application/x-mp4-cea-608".equals(str) || "application/cea-708".equals(str) || "application/dvbsubs".equals(str) || "application/pgs".equals(str)) {
            return (AbstractC3413.m5437((InterfaceC3532<?>) null, c3431.f10093) ? 4 : 2) | 0 | 0;
        }
        return C4134.m6658(c3431.f10090) ? 1 : 0;
    }

    @Override // p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ֏ */
    public void mo1149(long j, long j2) {
        boolean z;
        if (this.f12400) {
            return;
        }
        if (this.f12406 == null) {
            this.f12403.mo6373(j);
            try {
                this.f12406 = this.f12403.mo5807();
            } catch (SubtitleDecoderException e) {
                m6380(e);
                return;
            }
        }
        if (this.f9965 != 2) {
            return;
        }
        if (this.f12405 != null) {
            long jM6382 = m6382();
            z = false;
            while (jM6382 <= j) {
                this.f12407++;
                jM6382 = m6382();
                z = true;
            }
        } else {
            z = false;
        }
        AbstractC3954 abstractC3954 = this.f12406;
        if (abstractC3954 != null) {
            if (abstractC3954.m5805()) {
                if (!z && m6382() == Long.MAX_VALUE) {
                    if (this.f12401 == 2) {
                        m6384();
                    } else {
                        m6383();
                        this.f12400 = true;
                    }
                }
            } else if (this.f12406.f10466 <= j) {
                AbstractC3954 abstractC39542 = this.f12405;
                if (abstractC39542 != null) {
                    abstractC39542.mo5814();
                }
                AbstractC3954 abstractC39543 = this.f12406;
                this.f12405 = abstractC39543;
                this.f12406 = null;
                InterfaceC3949 interfaceC3949 = abstractC39543.f12393;
                C0567.m1856(interfaceC3949);
                this.f12407 = interfaceC3949.mo6375(j - abstractC39543.f12394);
                z = true;
            }
        }
        if (z) {
            AbstractC3954 abstractC39544 = this.f12405;
            InterfaceC3949 interfaceC39492 = abstractC39544.f12393;
            C0567.m1856(interfaceC39492);
            List<C3946> listMo6377 = interfaceC39492.mo6377(j - abstractC39544.f12394);
            Handler handler = this.f12395;
            if (handler != null) {
                handler.obtainMessage(0, listMo6377).sendToTarget();
            } else {
                this.f12396.mo1278(listMo6377);
            }
        }
        if (this.f12401 == 2) {
            return;
        }
        while (!this.f12399) {
            try {
                if (this.f12404 == null) {
                    C3953 c3953Mo5808 = this.f12403.mo5808();
                    this.f12404 = c3953Mo5808;
                    if (c3953Mo5808 == null) {
                        return;
                    }
                }
                if (this.f12401 == 1) {
                    this.f12404.f10443 = 4;
                    this.f12403.mo5806(this.f12404);
                    this.f12404 = null;
                    this.f12401 = 2;
                    return;
                }
                int iM5438 = m5438(this.f12398, (C3511) this.f12404, false);
                if (iM5438 == -4) {
                    if (this.f12404.m5805()) {
                        this.f12399 = true;
                    } else {
                        this.f12404.f12392 = this.f12398.f10114.f10094;
                        this.f12404.m5812();
                    }
                    this.f12403.mo5806(this.f12404);
                    this.f12404 = null;
                } else if (iM5438 == -3) {
                    return;
                }
            } catch (SubtitleDecoderException e2) {
                m6380(e2);
                return;
            }
        }
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    public void mo1150(long j, boolean z) {
        this.f12399 = false;
        this.f12400 = false;
        m6381();
        if (this.f12401 != 0) {
            m6384();
        } else {
            m6383();
            this.f12403.flush();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m6380(SubtitleDecoderException subtitleDecoderException) {
        StringBuilder sbM4889 = C2803.m4889("Subtitle decoding failed. streamFormat=");
        sbM4889.append(this.f12402);
        C4131.m6645("TextRenderer", sbM4889.toString(), subtitleDecoderException);
        m6381();
        if (this.f12401 != 0) {
            m6384();
        } else {
            m6383();
            this.f12403.flush();
        }
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ֏ */
    public void mo1315(C3431[] c3431Arr, long j) {
        C3431 c3431 = c3431Arr[0];
        this.f12402 = c3431;
        if (this.f12403 != null) {
            this.f12401 = 1;
        } else {
            this.f12403 = ((InterfaceC3951.C3952) this.f12397).m6379(c3431);
        }
    }

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

    @Override // p138.p176.p177.p190.InterfaceC3450
    /* JADX INFO: renamed from: ރ */
    public boolean mo1169() {
        return true;
    }

    @Override // p138.p176.p177.p190.AbstractC3413
    /* JADX INFO: renamed from: ޏ */
    public void mo1170() {
        this.f12402 = null;
        m6381();
        m6383();
        this.f12403.mo1134();
        this.f12403 = null;
        this.f12401 = 0;
    }

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public final void m6381() {
        List<C3946> listEmptyList = Collections.emptyList();
        Handler handler = this.f12395;
        if (handler != null) {
            handler.obtainMessage(0, listEmptyList).sendToTarget();
        } else {
            this.f12396.mo1278(listEmptyList);
        }
    }

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public final long m6382() {
        int i = this.f12407;
        if (i != -1) {
            InterfaceC3949 interfaceC3949 = this.f12405.f12393;
            C0567.m1856(interfaceC3949);
            if (i < interfaceC3949.mo6378()) {
                AbstractC3954 abstractC3954 = this.f12405;
                int i2 = this.f12407;
                InterfaceC3949 interfaceC39492 = abstractC3954.f12393;
                C0567.m1856(interfaceC39492);
                return interfaceC39492.mo6376(i2) + abstractC3954.f12394;
            }
        }
        return Long.MAX_VALUE;
    }

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public final void m6383() {
        this.f12404 = null;
        this.f12407 = -1;
        AbstractC3954 abstractC3954 = this.f12405;
        if (abstractC3954 != null) {
            abstractC3954.mo5814();
            this.f12405 = null;
        }
        AbstractC3954 abstractC39542 = this.f12406;
        if (abstractC39542 != null) {
            abstractC39542.mo5814();
            this.f12406 = null;
        }
    }

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public final void m6384() {
        m6383();
        this.f12403.mo1134();
        this.f12403 = null;
        this.f12401 = 0;
        this.f12403 = ((InterfaceC3951.C3952) this.f12397).m6379(this.f12402);
    }
}
