package g0;

import a1.C0148a;
import android.util.Log;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: renamed from: g0.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0483g implements InterfaceC0480d {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final a f4045c = new a(null);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final AtomicBoolean f4046a = new AtomicBoolean(false);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private C0479c f4047b = new C0479c(409600);

    /* JADX INFO: renamed from: g0.g$a */
    public static final class a {
        public /* synthetic */ a(kotlin.jvm.internal.g gVar) {
            this();
        }

        private a() {
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void b(C0483g this$0, int i2, byte[] bArr) {
        kotlin.jvm.internal.l.e(this$0, "this$0");
        Log.i("MTKAudioRecorder", "startRecord: " + i2);
        if (i2 > 0) {
            o0.g.I.saveData(bArr, 1);
            C0479c c0479c = this$0.f4047b;
            if (c0479c != null) {
                kotlin.jvm.internal.l.b(bArr);
                c0479c.d(bArr, i2);
            }
        }
    }

    @Override // g0.InterfaceC0480d
    public int configure(int i2, int i3, int i4) {
        return -11;
    }

    @Override // g0.InterfaceC0480d
    public int read(byte[] audioData, int i2, int i3) throws InterruptedException {
        kotlin.jvm.internal.l.e(audioData, "audioData");
        while (this.f4046a.get()) {
            C0479c c0479c = this.f4047b;
            if (i3 <= (c0479c != null ? c0479c.e() : 0)) {
                C0479c c0479c2 = this.f4047b;
                if (c0479c2 != null) {
                    return c0479c2.b(audioData, i2, i3);
                }
                return 0;
            }
            Log.i("MTKAudioRecorder", "read: wait...");
            if (this.f4046a.get()) {
                Thread.sleep(10L);
            }
        }
        Y0.c.a("MTKAudioRecorder", "read: end");
        return -1;
    }

    @Override // g0.InterfaceC0480d
    public int release() {
        Y0.c.a("MTKAudioRecorder", "release: ");
        this.f4046a.set(false);
        C0479c c0479c = this.f4047b;
        if (c0479c != null) {
            c0479c.a();
        }
        this.f4047b = null;
        Y0.c.a("MTKAudioRecorder", "release: end");
        return 0;
    }

    @Override // g0.InterfaceC0480d
    public int startRecording() {
        try {
            o0.g.I.start(1);
            if (this.f4047b == null) {
                this.f4047b = new C0479c(409600);
            }
            C0148a.f2045c.c(new C0148a.b() { // from class: g0.f
                @Override // a1.C0148a.b
                public final void a(int i2, byte[] bArr) {
                    C0483g.b(this.f4044a, i2, bArr);
                }
            });
            this.f4046a.set(true);
            Y0.c.a("MTKAudioRecorder", "startRecording: end");
            return 0;
        } catch (Throwable th) {
            Y0.c.c("MTKAudioRecorder", "startRecording: ", th);
            return -1;
        }
    }

    @Override // g0.InterfaceC0480d
    public int stop() {
        try {
            Y0.c.a("MTKAudioRecorder", "stop: start");
            this.f4046a.set(false);
            o0.g.I.stop(1);
            C0148a.f2045c.d();
            Y0.c.a("MTKAudioRecorder", "stop: end");
            return 0;
        } catch (Throwable th) {
            Y0.c.c("MTKAudioRecorder", "stop: ", th);
            return -1;
        }
    }
}
