package com.tencent.mm.audio.mix.e;

import android.os.Process;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.audio.mix.f.d;
import com.tencent.mm.audio.mix.h.b;
import java.util.List;

class c$1 implements Runnable {
    final /* synthetic */ c cmN;

    c$1(c cVar) {
        this.cmN = cVar;
    }

    public final void run() {
        AppMethodBeat.i(137087);
        Process.setThreadPriority(-19);
        if (this.cmN.DB()) {
            b.e("MicroMsg.Mix.AudioMixController", "stop and exit");
            AppMethodBeat.o(137087);
            return;
        }
        while (!this.cmN.DB()) {
            this.cmN.DV();
            if (this.cmN.DB()) {
                AppMethodBeat.o(137087);
                return;
            }
            System.nanoTime();
            List DY = this.cmN.DY();
            if (DY.size() > 0) {
                long nanoTime = System.nanoTime();
                com.tencent.mm.audio.mix.a.b I = this.cmN.cmq.I(DY);
                long nanoTime2 = System.nanoTime();
                c cVar = this.cmN;
                cVar.cmI++;
                this.cmN.cmJ = (nanoTime2 - nanoTime) + this.cmN.cmJ;
                if (I != null) {
                    cVar = this.cmN;
                    I.ckw.addAll(cVar.ckw);
                    cVar.ckw.clear();
                    d dVar = cVar.cmr;
                    if (dVar.cnw.get()) {
                        b.e("MicroMsg.Mix.AudioMixPlayerImpl", "exit, not to add MixBuff queue");
                    } else {
                        synchronized (dVar.cny) {
                            while (dVar.cnx.size() >= 2 && !dVar.cnw.get()) {
                                try {
                                    dVar.cny.wait();
                                } catch (InterruptedException e) {
                                    b.printErrStackTrace("MicroMsg.Mix.AudioMixPlayerImpl", e, "enqueueMixBuffer", new Object[0]);
                                } catch (Throwable th) {
                                    AppMethodBeat.o(137087);
                                }
                            }
                            dVar.cnx.add(I);
                            dVar.cny.notifyAll();
                        }
                    }
                }
                c.H(DY);
                DY.clear();
            }
        }
        b.i("MicroMsg.Mix.AudioMixController", "mix thread stop and exit");
        AppMethodBeat.o(137087);
    }
}
