package defpackage;

import android.content.Context;
import android.content.IntentFilter;
import android.media.AudioAttributes;
import android.media.AudioDeviceInfo;
import android.media.AudioFormat;
import android.media.AudioTrack;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Pair;
import androidx.media3.exoplayer.audio.AudioOutputProvider$ConfigurationException;
import androidx.media3.exoplayer.audio.AudioOutputProvider$InitializationException;
import j$.util.Objects;
import java.math.RoundingMode;

/* JADX INFO: renamed from: ʿᵦ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0453 implements InterfaceC4099 {

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

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public C5015 f2467;

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

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final float f2469;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public Looper f2470;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final Context f2471;

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

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public Context f2473;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final ᵟˑʽ f2474;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public C2939 f2475;

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

    public C0453(C1590 c1590) {
        Context context = c1590.f6390;
        this.f2471 = context;
        C1801 c1801 = c1590.f6387;
        c1801.getClass();
        this.f2468 = c1801;
        this.f2466 = c1590.f6388;
        this.f2467 = c1590.f6391;
        this.f2474 = context == null ? null : new ᵟˑʽ(this);
        this.f2469 = c1590.f6389;
        this.f2472 = C2353.f9226;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x008e  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0165  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0167  */
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C2558 m1885(C4741 c4741) {
        int iIntValue;
        int iM3227;
        boolean z;
        char c;
        boolean z2;
        int i;
        int iMax;
        double d;
        boolean z3;
        int iM3261;
        int i2;
        C5286 c5286 = c4741.f18038;
        boolean z4 = c4741.f18040;
        C4683 c4683 = c4741.f18034;
        m1886(c4741);
        String str = c5286.f19987;
        int i3 = c5286.f19966;
        int iIntValue2 = c5286.f19962;
        int i4 = c5286.f19984;
        if (Objects.equals(str, "audio/raw")) {
            ᵻᵪ.ᵱᵽʡᵚ(AbstractC0956.m3253(iIntValue2));
            iIntValue = AbstractC0956.m3235(i4);
            iM3227 = AbstractC0956.m3227(iIntValue2) * i4;
            z = false;
            c = 0;
        } else {
            C0977 c0977M4950 = z4 ? this.f2468.m4950(c4683, c5286) : C0977.f4270;
            if (z4 && c0977M4950.f4273) {
                str.getClass();
                int iM9140 = AbstractC4208.m9140(str, c5286.f19996);
                int iM3235 = AbstractC0956.m3235(i4);
                boolean z5 = c0977M4950.f4271;
                iIntValue2 = iM9140;
                iIntValue = iM3235;
                z = z5;
                iM3227 = -1;
                c = 1;
                z2 = true;
                i = c5286.f19991;
                if (Objects.equals(str, "audio/vnd.dts.hd;profile=lbr") && i == -1) {
                    i = 768000;
                }
                iMax = c4741.f18035;
                if (iMax == -1) {
                    z3 = true;
                } else {
                    int minBufferSize = AudioTrack.getMinBufferSize(i3, iIntValue, iIntValue2);
                    ᵻᵪ.ˌᴵ(minBufferSize != -2);
                    if (iM3227 == -1) {
                        iM3227 = 1;
                    }
                    double d2 = z2 ? this.f2469 : 1.0d;
                    this.f2466.getClass();
                    if (c == 0) {
                        d = d2;
                        z3 = true;
                        long j = i3;
                        long j2 = 250000 * j;
                        long j3 = iM3227;
                        iM3261 = AbstractC0956.m3261(minBufferSize * 4, ᵝˉː.ᵷᵺʾᵖ((j2 * j3) / 1000000), ᵝˉː.ᵷᵺʾᵖ(((750000 * j) * j3) / 1000000));
                    } else if (c == 1) {
                        d = d2;
                        z3 = true;
                        int i5 = ᵽˊᵘᵬ.ᵶᵥᵝ(iIntValue2);
                        ᵻᵪ.ˌᴵ(i5 != -2147483647);
                        iM3261 = ᵝˉː.ᵷᵺʾᵖ((50000000 * ((long) i5)) / 1000000);
                    } else {
                        if (c != 2) {
                            ᵷᵝˎ.ᵷᵺʾᵖ();
                            return null;
                        }
                        z3 = true;
                        int i6 = iIntValue2 == 5 ? 500000 : iIntValue2 == 8 ? 1000000 : 250000;
                        if (i != -1) {
                            RoundingMode roundingMode = RoundingMode.CEILING;
                            i2 = ᵸˊʾᵜ.ᵝᵶ(i, 8);
                        } else {
                            i2 = ᵽˊᵘᵬ.ᵶᵥᵝ(iIntValue2);
                            ᵻᵪ.ˌᴵ(i2 != -2147483647);
                        }
                        d = d2;
                        iM3261 = ᵝˉː.ᵷᵺʾᵖ((((long) i6) * ((long) i2)) / 1000000);
                    }
                    iMax = (((Math.max(minBufferSize, (int) (((double) iM3261) * d)) + iM3227) - 1) / iM3227) * iM3227;
                }
                C1239 c1239 = new C1239();
                C4683 c46832 = C4683.f17774;
                c1239.f5228 = -1;
                c1239.f5219 = i3;
                c1239.f5221 = iIntValue;
                c1239.f5224 = iIntValue2;
                c1239.f5229 = iMax;
                c1239.f5220 = c4741.f18037;
                c1239.f5225 = c4683;
                boolean z6 = z3;
                c1239.f5222 = c != z6 ? z6 : false;
                c1239.f5227 = c4741.f18039;
                c1239.f5223 = z2;
                c1239.f5226 = z;
                c1239.f5228 = c4741.f18041;
                return new C2558(c1239);
            }
            Pair pairM10348 = this.f2467.m10348(c4683, c5286);
            if (pairM10348 == null) {
                throw new AudioOutputProvider$ConfigurationException("Unable to configure passthrough for: " + c5286);
            }
            iIntValue2 = ((Integer) pairM10348.first).intValue();
            iIntValue = ((Integer) pairM10348.second).intValue();
            iM3227 = -1;
            z = false;
            c = 2;
        }
        z2 = false;
        i = c5286.f19991;
        if (Objects.equals(str, "audio/vnd.dts.hd;profile=lbr")) {
            i = 768000;
        }
        iMax = c4741.f18035;
        if (iMax == -1) {
        }
        C1239 c12392 = new C1239();
        C4683 c468322 = C4683.f17774;
        c12392.f5228 = -1;
        c12392.f5219 = i3;
        c12392.f5221 = iIntValue;
        c12392.f5224 = iIntValue2;
        c12392.f5229 = iMax;
        c12392.f5220 = c4741.f18037;
        c12392.f5225 = c4683;
        boolean z62 = z3;
        c12392.f5222 = c != z62 ? z62 : false;
        c12392.f5227 = c4741.f18039;
        c12392.f5223 = z2;
        c12392.f5226 = z;
        c12392.f5228 = c4741.f18041;
        return new C2558(c12392);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m1886(C4741 c4741) {
        Context context;
        C5015 c5015M10346;
        AudioDeviceInfo audioDeviceInfo = c4741.f18036;
        C4683 c4683 = c4741.f18034;
        m1888();
        C2939 c2939 = this.f2475;
        if (c2939 == null && (context = this.f2471) != null) {
            C2939 c29392 = new C2939(context, new ᵳᵢᵺ(1, this), c4683, audioDeviceInfo);
            this.f2475 = c29392;
            Handler handler = (Handler) c29392.f11325;
            Context context2 = (Context) c29392.f11317;
            if (c29392.f11322) {
                c5015M10346 = (C5015) c29392.f11326;
                c5015M10346.getClass();
            } else {
                c29392.f11322 = true;
                C3779 c3779 = (C3779) c29392.f11323;
                if (c3779 != null) {
                    c3779.f14373.registerContentObserver(c3779.f14371, false, c3779);
                }
                ˁᵨᵦ.ᵨᵣ(context2).registerAudioDeviceCallback((C2066) c29392.f11320, handler);
                if (Build.VERSION.SDK_INT >= 32 && ((C5304) c29392.f11318) == null) {
                    c29392.f11318 = new C5304(context2, new RunnableC2846(5, c29392), Boolean.valueOf(AbstractC0956.m3216(context2)));
                }
                c5015M10346 = C5015.m10346(context2, context2.registerReceiver((C2911) c29392.f11327, new IntentFilter("android.media.action.HDMI_AUDIO_PLUG"), null, handler), (C4683) c29392.f11324, (AudioDeviceInfo) c29392.f11321, c29392.m7030());
                c29392.f11326 = c5015M10346;
            }
            this.f2467 = c5015M10346;
        } else if (c2939 != null) {
            if (audioDeviceInfo != null && !audioDeviceInfo.equals((AudioDeviceInfo) c2939.f11321)) {
                c2939.f11321 = audioDeviceInfo;
                c2939.m7034(C5015.m10345((Context) c2939.f11317, (C4683) c2939.f11324, audioDeviceInfo, c2939.m7030()));
            }
            C2939 c29393 = this.f2475;
            if (!Objects.equals(c4683, (C4683) c29393.f11324)) {
                c29393.f11324 = c4683;
                c29393.m7034(C5015.m10345((Context) c29393.f11317, c4683, (AudioDeviceInfo) c29393.f11321, c29393.m7030()));
            }
        }
        this.f2467.getClass();
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C4000 m1887(C2558 c2558) throws AudioOutputProvider$InitializationException {
        Context context;
        Context context2;
        try {
            int i = c2558.f9891;
            int i2 = c2558.f9899;
            if (i2 == -1 || (context2 = this.f2471) == null || Build.VERSION.SDK_INT < 34) {
                context = null;
            } else {
                Context context3 = this.f2473;
                if (context3 == null || context3.getDeviceId() != i2) {
                    this.f2473 = context2.createDeviceContext(i2);
                }
                context = this.f2473;
                i = 0;
            }
            try {
                AudioTrack.Builder sessionId = new AudioTrack.Builder().setAudioAttributes(c2558.f9898 ? new AudioAttributes.Builder().setContentType(3).setFlags(16).setUsage(1).build() : c2558.f9896.m9808()).setAudioFormat(new AudioFormat.Builder().setSampleRate(c2558.f9890).setChannelMask(c2558.f9892).setEncoding(c2558.f9895).build()).setTransferMode(1).setBufferSizeInBytes(c2558.f9900).setSessionId(i);
                int i3 = Build.VERSION.SDK_INT;
                if (i3 >= 29) {
                    sessionId.setOffloadedPlayback(c2558.f9893);
                }
                if (i3 >= 34 && context != null) {
                    sessionId.setContext(context);
                }
                AudioTrack audioTrackBuild = sessionId.build();
                if (audioTrackBuild.getState() == 1) {
                    return new C4000(audioTrackBuild, c2558, this.f2474, this.f2469, this.f2472);
                }
                try {
                    audioTrackBuild.release();
                } catch (Exception unused) {
                }
                throw new AudioOutputProvider$InitializationException();
            } catch (IllegalArgumentException e) {
                e = e;
                throw new AudioOutputProvider$InitializationException(e);
            }
        } catch (IllegalArgumentException | UnsupportedOperationException e2) {
            e = e2;
        }
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m1888() {
        if (this.f2471 == null) {
            return;
        }
        Looper looperMyLooper = Looper.myLooper();
        Looper looper = this.f2470;
        boolean z = looper == null || looper == looperMyLooper;
        String name = looper == null ? "null" : looper.getThread().getName();
        String name2 = looperMyLooper != null ? looperMyLooper.getThread().getName() : "null";
        if (z) {
            this.f2470 = looperMyLooper;
        } else {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ(ᵱˉˈ.ᵸˆˁ("AudioTrackAudioOutputProvider accessed on multiple threads: %s and %s", new Object[]{name, name2}));
        }
    }
}
