package defpackage;

import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Build;
import android.os.HandlerThread;
import android.os.Trace;
import android.util.Pair;
import android.view.Surface;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.ILoggerFactory;

/* JADX INFO: renamed from: ᵻʚᵸ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C5172 implements InterfaceC2865, ILoggerFactory {

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public static volatile C5172 f19472;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final /* synthetic */ int f19473;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public Object f19474;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public boolean f19475;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public Object f19476;

    public C5172(int i) {
        this.f19473 = i;
        switch (i) {
            case C5224.DOUBLE_FIELD_NUMBER /* 7 */:
                this.f19475 = false;
                this.f19474 = new HashMap();
                this.f19476 = new LinkedBlockingQueue();
                break;
            case C5224.BYTES_FIELD_NUMBER /* 8 */:
            case 9:
            default:
                this.f19474 = Collections.newSetFromMap(new WeakHashMap());
                this.f19476 = new HashSet();
                break;
            case 10:
                this.f19474 = new Object();
                break;
        }
    }

    public /* synthetic */ C5172(int i, boolean z) {
        this.f19473 = i;
    }

    public C5172(Context context) {
        this.f19473 = 0;
        this.f19476 = new HashSet();
        C4923 c4923 = new C4923(new C2926(context, 2));
        C0761 c0761 = new C0761(this);
        this.f19474 = Build.VERSION.SDK_INT >= 24 ? new C3530(c4923, c0761) : new C5255(context, c4923, c0761);
    }

    public C5172(C0576 c0576, C0576 c05762) {
        this.f19473 = 1;
        this.f19474 = c0576;
        this.f19476 = c05762;
        this.f19475 = true;
    }

    public C5172(ˁˌᵩ r1) {
        this.f19473 = 3;
        this.f19474 = new Object();
        this.f19476 = new ArrayList();
    }

    public C5172(InterfaceC1479 interfaceC1479) {
        this.f19473 = 2;
        this.f19474 = interfaceC1479;
        this.f19476 = new ᵱᵻᵧᵷ();
    }

    public C5172(C5172 c5172, C4625[] c4625Arr, boolean z) {
        this.f19473 = 9;
        this.f19476 = c5172;
        this.f19474 = c4625Arr;
        boolean z2 = false;
        if (c4625Arr != null && z) {
            z2 = true;
        }
        this.f19475 = z2;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static C5172 m10696() {
        C5172 c5172 = new C5172(8, false);
        c5172.f19475 = true;
        return c5172;
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static void m10697(C2418 c2418, TextView textView) {
        C3369 c3369 = c2418.f9425;
        if (textView == c2418.f9433) {
            if (c3369.f12905 != null) {
                c3369.f12905 = textView.getText();
                return;
            } else {
                c3369.f12907 = textView.getText();
                return;
            }
        }
        if (textView == c2418.f9435) {
            if (c3369.f12909 != null) {
                c3369.f12909 = textView.getText();
            } else {
                c3369.f12899 = textView.getText();
            }
        }
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public static C5172 m10698(Context context) {
        if (f19472 == null) {
            synchronized (C5172.class) {
                try {
                    if (f19472 == null) {
                        f19472 = new C5172(context.getApplicationContext());
                    }
                } finally {
                }
            }
        }
        return f19472;
    }

    public String toString() {
        switch (this.f19473) {
            case C5224.STRING_SET_FIELD_NUMBER /* 6 */:
                return super.toString() + "{numRequests=" + ((Set) this.f19474).size() + ", isPaused=" + this.f19475 + "}";
            default:
                return super.toString();
        }
    }

    @Override // org.slf4j.ILoggerFactory
    /* JADX INFO: renamed from: ˊᵫᵗ */
    public synchronized InterfaceC5025 mo1015(String str) {
        C4552 c4552;
        c4552 = (C4552) ((HashMap) this.f19474).get(str);
        if (c4552 == null) {
            c4552 = new C4552(str, (LinkedBlockingQueue) this.f19476, this.f19475);
            ((HashMap) this.f19474).put(str, c4552);
        }
        return c4552;
    }

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public void m10699(C1300 c1300) {
        InterfaceC3602 interfaceC3602;
        synchronized (this.f19474) {
            if (((ArrayDeque) this.f19476) != null && !this.f19475) {
                this.f19475 = true;
                while (true) {
                    synchronized (this.f19474) {
                        try {
                            interfaceC3602 = (InterfaceC3602) ((ArrayDeque) this.f19476).poll();
                            if (interfaceC3602 == null) {
                                this.f19475 = false;
                                return;
                            }
                        } finally {
                        }
                    }
                    interfaceC3602.mo1712(c1300);
                }
            }
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public boolean m10700(InterfaceC2653 interfaceC2653) {
        boolean z = true;
        if (interfaceC2653 == null) {
            return true;
        }
        boolean zRemove = ((Set) this.f19474).remove(interfaceC2653);
        if (!((HashSet) this.f19476).remove(interfaceC2653) && !zRemove) {
            z = false;
        }
        if (z) {
            interfaceC2653.clear();
        }
        return z;
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public void m10701(InterfaceC3602 interfaceC3602) {
        synchronized (this.f19474) {
            try {
                if (((ArrayDeque) this.f19476) == null) {
                    this.f19476 = new ArrayDeque();
                }
                ((ArrayDeque) this.f19476).add(interfaceC3602);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public void m10702(View view) {
        if (this.f19475) {
            this.f19475 = false;
            ((InputMethodManager) view.getContext().getSystemService("input_method")).hideSoftInputFromWindow(view.getWindowToken(), 0);
            ((C1438) this.f19476).f5874.m6551(false);
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public C5172 m10703() {
        ᵘᵞʿⁱ.ᵨᵣ("execute parameter required", ((InterfaceC2272) this.f19474) != null);
        return new C5172(this, (C4625[]) this.f19476, this.f19475);
    }

    /* JADX WARN: Code restructure failed: missing block: B:50:0x0044, code lost:
    
        r3 = 0;
     */
    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m10704(C3898 c3898, TextView textView) {
        int i;
        C2418 c2418M8624 = c3898.m8624(textView);
        m10697(c2418M8624, textView);
        InterfaceC1557 interfaceC1557 = c3898.f14898;
        if (interfaceC1557 != null) {
            interfaceC1557.mo4112(c2418M8624.f9425);
        }
        long jM6555 = ((C1438) this.f19476).f5874.m6555(c2418M8624.f9425);
        c3898.f14895.m3390(c2418M8624, false, true);
        if (jM6555 != -3) {
            C3369 c3369 = c2418M8624.f9425;
            if (jM6555 != c3369.f12904) {
                if (jM6555 == -2) {
                    int iIndexOf = c3898.f14896.indexOf(c3369);
                    if (iIndexOf >= 0) {
                        i = iIndexOf + 1;
                        while (true) {
                            ArrayList arrayList = c3898.f14896;
                            int size = arrayList.size();
                            if (jM6555 == -2) {
                                while (i < size && (((C3369) arrayList.get(i)).f12901 & 32) != 32) {
                                    i++;
                                }
                            } else {
                                while (i < size && ((C3369) arrayList.get(i)).f12904 != jM6555) {
                                    i++;
                                }
                            }
                            if (i >= size) {
                                ArrayList arrayList2 = (ArrayList) this.f19474;
                                int i2 = 0;
                                while (true) {
                                    if (i2 >= arrayList2.size()) {
                                        c3898 = null;
                                        break;
                                    }
                                    Pair pair = (Pair) arrayList2.get(i2);
                                    if (pair.first == c3898) {
                                        c3898 = (C3898) pair.second;
                                        break;
                                    }
                                    i2++;
                                }
                                if (c3898 == null) {
                                    break;
                                }
                            } else {
                                C2418 c2418 = (C2418) c3898.f14895.f4451.m556(i, false);
                                if (c2418 != null) {
                                    View view = c2418.f18236;
                                    int i3 = c2418.f9425.f12898;
                                    if (i3 == 1 || i3 == 2) {
                                        m10705(c3898, c2418);
                                        return;
                                    } else {
                                        m10702(view);
                                        view.requestFocus();
                                        return;
                                    }
                                }
                            }
                            i = 0;
                        }
                    }
                }
                i = 0;
            }
        }
        m10702(textView);
        c2418M8624.f18236.requestFocus();
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public void m10705(C3898 c3898, C2418 c2418) {
        c3898.f14895.m3390(c2418, true, true);
        int i = c2418.f9432;
        View view = i != 1 ? i != 2 ? i != 3 ? null : c2418.f9430 : c2418.f9433 : c2418.f9435;
        if (view != null) {
            if (i == 1 || i == 2) {
                InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService("input_method");
                view.setFocusable(true);
                view.requestFocus();
                inputMethodManager.showSoftInput(view, 0);
                if (this.f19475) {
                    return;
                }
                this.f19475 = true;
                ((C1438) this.f19476).f5874.m6551(true);
            }
        }
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public void m10706(C3898 c3898, TextView textView) {
        C2418 c2418M8624 = c3898.m8624(textView);
        m10697(c2418M8624, textView);
        C2705 c2705 = ((C1438) this.f19476).f5874;
        c3898.f14895.m3390(c2418M8624, false, true);
        m10702(textView);
        c2418M8624.f18236.requestFocus();
    }

    @Override // defpackage.InterfaceC2865
    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public C0859 mo4937(C2781 c2781) throws Exception {
        MediaCodec mediaCodecCreateByCodecName;
        int i;
        InterfaceC1872 c2077;
        C0859 c0859;
        String str = ((C1354) c2781.f10705).f5600;
        C0859 c08592 = null;
        try {
            Trace.beginSection("createCodec:" + str);
            mediaCodecCreateByCodecName = MediaCodec.createByCodecName(str);
            try {
                i = 0;
                if (!this.f19475 || Build.VERSION.SDK_INT < 36) {
                    c2077 = new C2077(mediaCodecCreateByCodecName, (HandlerThread) ((C0576) this.f19476).get());
                } else {
                    c2077 = new C2198(i, mediaCodecCreateByCodecName);
                    i = 4;
                }
                c0859 = new C0859(mediaCodecCreateByCodecName, (HandlerThread) ((C0576) this.f19474).get(), c2077, (C1199) c2781.f10703);
            } catch (Exception e) {
                e = e;
            }
            try {
                Trace.endSection();
                Surface surface = (Surface) c2781.f10707;
                if (surface == null && ((C1354) c2781.f10705).f5595 && Build.VERSION.SDK_INT >= 35) {
                    i |= 8;
                }
                C0859.m3026(c0859, (MediaFormat) c2781.f10704, surface, (MediaCrypto) c2781.f10708, i);
                return c0859;
            } catch (Exception e2) {
                e = e2;
                c08592 = c0859;
                if (c08592 != null) {
                    c08592.mo3040();
                } else if (mediaCodecCreateByCodecName != null) {
                    mediaCodecCreateByCodecName.release();
                }
                throw e;
            }
        } catch (Exception e3) {
            e = e3;
            mediaCodecCreateByCodecName = null;
        }
    }
}
