package com.tencent.mm.media.g;

import a.f.a.b;
import a.f.b.k;
import a.l;
import a.y;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.graphics.SurfaceTexture.OnFrameAvailableListener;
import android.opengl.EGLExt;
import android.os.HandlerThread;
import android.view.Surface;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.media.i.b$b;
import com.tencent.mm.media.i.c;
import com.tencent.mm.sdk.g.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.ytcommon.BuildConfig;

@l(dWo = {1, 1, 13}, dWp = {"\u0000\u0001\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u000b\n\u0002\u0010\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0007\n\u0002\u0010\u0012\n\u0002\b\u0014\b\u0016\u0018\u0000 Z2\u00020\u0001:\u0001ZB\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0006\u00104\u001a\u00020-J5\u00105\u001a\u00020\u000e2\u0006\u0010,\u001a\u00020-2%\b\u0002\u00106\u001a\u001f\u0012\u0013\u0012\u00110\r¢\u0006\f\b7\u0012\b\b8\u0012\u0004\b\b(9\u0012\u0004\u0012\u00020\u000e\u0018\u00010\nJ\b\u0010:\u001a\u00020\u000eH\u0002JM\u0010;\u001a\u00020\u000e2\n\b\u0002\u0010<\u001a\u0004\u0018\u00010=2\b\b\u0002\u0010>\u001a\u00020?2\b\b\u0002\u0010@\u001a\u00020?2#\u00106\u001a\u001f\u0012\u0013\u0012\u00110\r¢\u0006\f\b7\u0012\b\b8\u0012\u0004\b\b(9\u0012\u0004\u0012\u00020\u000e\u0018\u00010\nH\u0016JK\u0010A\u001a\u00020\u000e2\u0006\u0010,\u001a\u00020-2\n\b\u0002\u0010<\u001a\u0004\u0018\u00010=2\b\b\u0002\u0010B\u001a\u00020\r2%\b\u0002\u00106\u001a\u001f\u0012\u0013\u0012\u00110\r¢\u0006\f\b7\u0012\b\b8\u0012\u0004\b\b(9\u0012\u0004\u0012\u00020\u000e\u0018\u00010\nJ\u0016\u0010C\u001a\u00020\u000e2\u000e\u00106\u001a\n\u0012\u0004\u0012\u00020\u000e\u0018\u00010\"J\u0006\u0010D\u001a\u00020\u000eJ\u000e\u0010E\u001a\u00020\u000e2\u0006\u00102\u001a\u000203J9\u0010E\u001a\u00020\u000e2\u0006\u0010F\u001a\u00020G2\u0006\u0010H\u001a\u00020\u000b2!\u0010I\u001a\u001d\u0012\u0013\u0012\u00110G¢\u0006\f\b7\u0012\b\b8\u0012\u0004\b\b(F\u0012\u0004\u0012\u00020\u000e0\nJ\u0016\u0010E\u001a\u00020\u000e2\u0006\u0010J\u001a\u00020?2\u0006\u0010H\u001a\u00020\u000bJ\"\u0010E\u001a\u00020\u000e2\u0006\u0010H\u001a\u00020\u000b2\b\u0010K\u001a\u0004\u0018\u00010\b2\b\b\u0002\u0010L\u001a\u00020\rJ\u001a\u0010M\u001a\u00020\u000e2\u0006\u0010H\u001a\u00020\u000b2\b\u0010K\u001a\u0004\u0018\u00010\bH\u0002J\u0014\u0010N\u001a\u00020\u000e2\f\u00106\u001a\b\u0012\u0004\u0012\u00020\u000e0\"J\u0012\u0010O\u001a\u00020\u000e2\n\b\u0002\u0010\u0007\u001a\u0004\u0018\u00010\bJ \u0010P\u001a\u00020\u000e2\u0018\b\u0002\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\u000b\u0012\u0006\u0012\u0004\u0018\u00010\b\u0018\u00010\nJ\b\u0010Q\u001a\u00020\u000eH\u0002J\u0018\u0010R\u001a\u00020\u000e2\u0010\b\u0002\u00106\u001a\n\u0012\u0004\u0012\u00020\u000e\u0018\u00010\"J\b\u0010S\u001a\u00020\u000eH\u0002J\u0010\u0010T\u001a\u00020\u000e2\u0006\u0010U\u001a\u00020\u000bH\u0004J\u000e\u0010V\u001a\u00020\u000e2\u0006\u0010W\u001a\u00020?J\u0016\u0010X\u001a\u00020\u000e2\u0006\u0010>\u001a\u00020?2\u0006\u0010@\u001a\u00020?J\u0016\u0010Y\u001a\u00020\u000e2\u0006\u0010>\u001a\u00020?2\u0006\u0010@\u001a\u00020?J\b\u0010B\u001a\u00020\u000eH\u0002R\u000e\u0010\u0005\u001a\u00020\u0006XD¢\u0006\u0002\n\u0000R\u0010\u0010\u0007\u001a\u0004\u0018\u00010\bX\u000e¢\u0006\u0002\n\u0000R\u001e\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\u000b\u0012\u0006\u0012\u0004\u0018\u00010\b\u0018\u00010\nX\u000e¢\u0006\u0002\n\u0000R(\u0010\f\u001a\u0010\u0012\u0004\u0012\u00020\r\u0012\u0004\u0012\u00020\u000e\u0018\u00010\nX\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\u0010\"\u0004\b\u0011\u0010\u0012R\u000e\u0010\u0013\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u001c\u0010\u0014\u001a\u0004\u0018\u00010\u0015X\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0017\"\u0004\b\u0018\u0010\u0019R\u000e\u0010\u001a\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001b\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001c\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001d\u001a\u00020\u000bX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001e\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u001f\u001a\u00020 X\u0004¢\u0006\u0002\n\u0000R\u0016\u0010!\u001a\n\u0012\u0004\u0012\u00020\u000e\u0018\u00010\"X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010#\u001a\u00020$X\u000e¢\u0006\u0002\n\u0000R\u0016\u0010%\u001a\n '*\u0004\u0018\u00010&0&X\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\u0002\u001a\u00020\u0003X\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b(\u0010)\"\u0004\b*\u0010\u0004R\u000e\u0010+\u001a\u00020\rX\u000e¢\u0006\u0002\n\u0000R\u001c\u0010,\u001a\u0004\u0018\u00010-X\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b.\u0010/\"\u0004\b0\u00101R\u0010\u00102\u001a\u0004\u0018\u000103X\u000e¢\u0006\u0002\n\u0000¨\u0006["}, dWq = {"Lcom/tencent/mm/media/remuxer/CodecInputSurface;", "", "renderer", "Lcom/tencent/mm/media/render/AbsSurfaceRenderer;", "(Lcom/tencent/mm/media/render/AbsSurfaceRenderer;)V", "TAG", "", "blendBitmap", "Landroid/graphics/Bitmap;", "blendBitmapProvider", "Lkotlin/Function1;", "", "drawCallback", "", "", "getDrawCallback", "()Lkotlin/jvm/functions/Function1;", "setDrawCallback", "(Lkotlin/jvm/functions/Function1;)V", "drawInOnFrameAvailable", "eglEnvironment", "Lcom/tencent/mm/media/util/GLEnvironmentUtil$EGLEnvironment;", "getEglEnvironment", "()Lcom/tencent/mm/media/util/GLEnvironmentUtil$EGLEnvironment;", "setEglEnvironment", "(Lcom/tencent/mm/media/util/GLEnvironmentUtil$EGLEnvironment;)V", "firstFrame", "isFirstFrameAvailable", "isReleased", "lastFrameTimestamp", "newFrameAvailable", "newFrameLock", "Ljava/lang/Object;", "onDrawFrameOnFrameAvailableFailed", "Lkotlin/Function0;", "renderHandler", "Lcom/tencent/mm/sdk/platformtools/MMHandler;", "renderThread", "Landroid/os/HandlerThread;", "kotlin.jvm.PlatformType", "getRenderer", "()Lcom/tencent/mm/media/render/AbsSurfaceRenderer;", "setRenderer", "setUpEnvWithShareContext", "surface", "Landroid/view/Surface;", "getSurface", "()Landroid/view/Surface;", "setSurface", "(Landroid/view/Surface;)V", "surfaceTexture", "Landroid/graphics/SurfaceTexture;", "getOutputSurface", "initForRemuxer", "callback", "Lkotlin/ParameterName;", "name", "success", "initSurfaceTexture", "initWithSize", "eglContext", "Landroid/opengl/EGLContext;", "width", "", "height", "initWithSurface", "waitNewFrame", "queue", "release", "requestDraw", "data", "", "pts", "inputCallback", "textureId", "bitmap", "waitFistFrameAvailable", "requestDrawInGLThread", "runInGlesThread", "setDrawBlendBitmap", "setDrawBlendBitmapProvider", "setFirstFrameAvailable", "setOnDrawFrameOnFrameAvailableFailed", "setOnFrameAvailable", "setPresentationTime", "nsecs", "setRotate", "degree", "updateDrawSize", "updateTextureSize", "Companion", "plugin-mediaeditor_release"})
public final class a {
    public static final a eXn = new a((byte) 0);
    public final String TAG = "MicroMsg.CodecInputSurface";
    private volatile boolean aAP;
    public Surface aOO;
    private SurfaceTexture bsb;
    private final HandlerThread eXa = d.anM("CodecInputSurface_renderThread");
    private ak eXb;
    b$b eXc;
    public b<? super Boolean, y> eXd;
    private final Object eXe = new Object();
    private boolean eXf;
    private volatile boolean eXg;
    public b<? super Long, Bitmap> eXh;
    Bitmap eXi;
    boolean eXj;
    a.f.a.a<y> eXk;
    private boolean eXl;
    com.tencent.mm.media.h.a eXm;
    private long lastFrameTimestamp;

    @l(dWo = {1, 1, 13}, dWp = {"\u0000\b\n\u0000\n\u0002\u0010\u0002\n\u0000\u0010\u0000\u001a\u00020\u0001H\n¢\u0006\u0002\b\u0002"}, dWq = {"<anonymous>", "", "invoke"})
    static final class h extends k implements a.f.a.a<y> {
        final /* synthetic */ a eXo;
        final /* synthetic */ long eXu;
        final /* synthetic */ int eXx;

        h(a aVar, int i, long j) {
            this.eXo = aVar;
            this.eXx = i;
            this.eXu = j;
            super(0);
        }

        public final /* synthetic */ Object invoke() {
            AppMethodBeat.i(13013);
            b bVar;
            try {
                this.eXo.eXm.input(this.eXx);
                this.eXo.eXm.Vd();
                if (this.eXo.aOO != null) {
                    this.eXo.setPresentationTime(this.eXu);
                    b$b b_b = this.eXo.eXc;
                    if (b_b != null) {
                        com.tencent.mm.media.i.b.a aVar = com.tencent.mm.media.i.b.fad;
                        com.tencent.mm.media.i.b.a.a(b_b.fae, b_b.faf);
                    }
                }
                bVar = this.eXo.eXd;
                if (bVar != null) {
                    bVar.am(Boolean.TRUE);
                }
            } catch (Exception e) {
                ab.printErrStackTrace(this.eXo.TAG, e, BuildConfig.FLAVOR, new Object[0]);
                bVar = this.eXo.eXd;
                if (bVar != null) {
                    bVar.am(Boolean.FALSE);
                }
            }
            y yVar = y.AUy;
            AppMethodBeat.o(13013);
            return yVar;
        }
    }

    @l(dWo = {1, 1, 13}, dWp = {"\u0000\u0010\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0000\u001a\u00020\u00012\u000e\u0010\u0002\u001a\n \u0004*\u0004\u0018\u00010\u00030\u0003H\n¢\u0006\u0002\b\u0005"}, dWq = {"<anonymous>", "", "it", "Landroid/graphics/SurfaceTexture;", "kotlin.jvm.PlatformType", "onFrameAvailable"})
    static final class j implements OnFrameAvailableListener {
        final /* synthetic */ a eXo;

        j(a aVar) {
            this.eXo = aVar;
        }

        public final void onFrameAvailable(SurfaceTexture surfaceTexture) {
            Object valueOf;
            AppMethodBeat.i(13016);
            String b = this.eXo.TAG;
            StringBuilder append = new StringBuilder("onFrameAvailable, thread:").append(Thread.currentThread()).append(", surface timestamp:");
            SurfaceTexture f = this.eXo.bsb;
            if (f != null) {
                valueOf = Long.valueOf(f.getTimestamp());
            } else {
                valueOf = null;
            }
            ab.i(b, append.append(valueOf).append(", drawInOnFrameAvailable:").append(this.eXo.eXj).toString());
            f = this.eXo.bsb;
            if (f == null) {
                AppMethodBeat.o(13016);
            } else if (!this.eXo.eXg || f.getTimestamp() > 0) {
                if (!this.eXo.eXg) {
                    this.eXo.eXg = true;
                }
                if (this.eXo.eXj) {
                    long timestamp;
                    Bitmap j;
                    a aVar;
                    if (this.eXo.eXi != null) {
                        a aVar2 = this.eXo;
                        timestamp = f.getTimestamp();
                        j = this.eXo.eXi;
                        aVar = aVar2;
                    } else {
                        aVar = this.eXo;
                        timestamp = f.getTimestamp();
                        b k = this.eXo.eXh;
                        j = k != null ? (Bitmap) k.am(Long.valueOf(f.getTimestamp() / 1000)) : null;
                    }
                    a.a(aVar, timestamp, j);
                }
                AppMethodBeat.o(13016);
            } else {
                this.eXo.eXj = false;
                c cVar = c.faj;
                c.We();
                a.f.a.a i = this.eXo.eXk;
                if (i != null) {
                    i.invoke();
                    AppMethodBeat.o(13016);
                    return;
                }
                AppMethodBeat.o(13016);
            }
        }
    }

    static {
        AppMethodBeat.i(13028);
        AppMethodBeat.o(13028);
    }

    public a(com.tencent.mm.media.h.a aVar) {
        a.f.b.j.p(aVar, "renderer");
        AppMethodBeat.i(13027);
        this.eXm = aVar;
        this.eXa.start();
        HandlerThread handlerThread = this.eXa;
        a.f.b.j.o(handlerThread, "renderThread");
        this.eXb = new ak(handlerThread.getLooper());
        this.eXl = true;
        AppMethodBeat.o(13027);
    }

    public static final /* synthetic */ void a(a aVar) {
        AppMethodBeat.i(13029);
        aVar.UZ();
        AppMethodBeat.o(13029);
    }

    public final void a(long j, Bitmap bitmap) {
        AppMethodBeat.i(13017);
        b((a.f.a.a) new f(this, j, bitmap));
        AppMethodBeat.o(13017);
    }

    public final void a(byte[] bArr, long j, b<? super byte[], y> bVar) {
        AppMethodBeat.i(13018);
        a.f.b.j.p(bArr, "data");
        a.f.b.j.p(bVar, "inputCallback");
        ab.d(this.TAG, "ByteArray length : " + bArr.length);
        b((a.f.a.a) new g(this, bArr, j, bVar));
        AppMethodBeat.o(13018);
    }

    public final void s(int i, long j) {
        AppMethodBeat.i(13019);
        b((a.f.a.a) new h(this, i, j));
        AppMethodBeat.o(13019);
    }

    public final Surface UY() {
        AppMethodBeat.i(13020);
        if (this.bsb == null) {
            UZ();
        }
        Surface surface = new Surface(this.bsb);
        AppMethodBeat.o(13020);
        return surface;
    }

    public final void cg(int i, int i2) {
        AppMethodBeat.i(13021);
        this.eXm.ci(i, i2);
        AppMethodBeat.o(13021);
    }

    public final void ch(int i, int i2) {
        AppMethodBeat.i(13022);
        this.eXm.ch(i, i2);
        AppMethodBeat.o(13022);
    }

    public final void ka(int i) {
        AppMethodBeat.i(13023);
        this.eXm.ka(i);
        AppMethodBeat.o(13023);
    }

    public final void b(a.f.a.a<y> aVar) {
        AppMethodBeat.i(13024);
        HandlerThread handlerThread = this.eXa;
        a.f.b.j.o(handlerThread, "renderThread");
        if (handlerThread.isAlive() && !this.aAP) {
            this.eXb.post((Runnable) new b(aVar));
        }
        AppMethodBeat.o(13024);
    }

    private final void UZ() {
        this.bsb = this.eXm.bsb;
    }

    public final void release() {
        AppMethodBeat.i(13025);
        ab.i(this.TAG, hashCode() + " release resources");
        b((a.f.a.a) new e(this));
        AppMethodBeat.o(13025);
    }

    /* Access modifiers changed, original: protected|final */
    public final void setPresentationTime(long j) {
        AppMethodBeat.i(13026);
        b$b b_b = this.eXc;
        if (b_b != null) {
            EGLExt.eglPresentationTimeANDROID(b_b.fae, b_b.faf, j);
        }
        com.tencent.mm.media.i.b.a aVar = com.tencent.mm.media.i.b.fad;
        com.tencent.mm.media.i.b.a.lZ("eglPresentationTimeANDROID");
        AppMethodBeat.o(13026);
    }

    public static final /* synthetic */ void c(a aVar) {
        AppMethodBeat.i(13030);
        SurfaceTexture surfaceTexture = aVar.bsb;
        if (surfaceTexture != null) {
            surfaceTexture.setOnFrameAvailableListener(new j(aVar));
            AppMethodBeat.o(13030);
            return;
        }
        AppMethodBeat.o(13030);
    }
}
