package com.tencent.mm.plugin.mmsight.model.a;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.os.HandlerThread;
import android.os.Message;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.c.g;
import com.tencent.mm.graphics.MMBitmapFactory;
import com.tencent.mm.modelcontrol.VideoTransPara;
import com.tencent.mm.plugin.mmsight.model.CaptureMMProxy;
import com.tencent.mm.plugin.mmsight.model.a.d.c;
import com.tencent.mm.plugin.mmsight.model.b;
import com.tencent.mm.plugin.mmsight.model.f;
import com.tencent.mm.plugin.mmsight.model.j;
import com.tencent.mm.plugin.mmsight.model.k;
import com.tencent.mm.plugin.sight.base.SightVideoJNI;
import com.tencent.mm.plugin.sight.base.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.ac.a;
import com.tencent.mm.vfs.e;
import com.tencent.ytcommon.BuildConfig;
import java.io.ByteArrayOutputStream;
import java.io.File;

public final class n implements d {
    protected String cvZ = BuildConfig.FLAVOR;
    protected boolean eNa = false;
    protected int eTa;
    protected Point fbc = null;
    private final Object fcD = new Object();
    protected String fcE = BuildConfig.FLAVOR;
    protected int fcF = 0;
    protected float fcG = 0.0f;
    private int fcH = -1;
    private float fcI = -1.0f;
    protected c fcJ;
    protected int fcL = 480;
    protected int fcM = 640;
    protected int fcN = 1600000;
    protected int fcO = 480;
    protected int fcP = 640;
    protected s fcQ;
    protected int fcR;
    protected String fcS = null;
    protected boolean fcT = false;
    protected String fcU = null;
    protected boolean fcV = false;
    protected b fcW = new b("yuvRecorderWriteData");
    protected b fcX = new b("frameCountCallback");
    protected VideoTransPara fcY;
    protected m fcZ;
    protected boolean fda = false;
    protected boolean fdb = false;
    protected int fdc = 0;
    protected d$a fdd;
    protected Runnable fde = null;
    protected boolean fdf = false;
    protected boolean fdg = true;
    protected boolean fdh = false;
    protected f fdk = new 1(this);
    protected String mFileName;
    protected boolean ouL = false;
    protected volatile q owH;
    protected HandlerThread owI;
    protected ak owJ;
    protected int owK = 0;
    protected String thumbPath = null;

    public n(VideoTransPara videoTransPara) {
        AppMethodBeat.i(76639);
        this.fcY = videoTransPara;
        this.fcL = videoTransPara.width;
        this.fcM = videoTransPara.height;
        this.fcN = videoTransPara.videoBitrate;
        k.bPR();
        int bPT = k.bPT();
        if (bPT == -1) {
            this.fcN = videoTransPara.videoBitrate;
        } else {
            this.fcN = bPT;
        }
        this.fcQ = new s();
        ab.d("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "create MMSightMediaCodecMP4MuxRecorder, targetWidth: %s, targetHeight: %s, targetRate: %s", new Object[]{Integer.valueOf(this.fcL), Integer.valueOf(this.fcM), Integer.valueOf(this.fcN)});
        AppMethodBeat.o(76639);
    }

    private boolean kn(int i) {
        AppMethodBeat.i(76640);
        long yz = bo.yz();
        this.ouL = j.ouz.ouL;
        int i2 = this.fcN;
        this.eTa = SightVideoJNI.initDataBufferForMMSightLock(this.fcO, this.fcP, i, this.fcL, this.fcM, (float) this.fcY.fps, i2, this.fcY.fzV, 8, this.fcY.fzU, 23.0f, false, false, this.fcY.duration, false);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "init, bufId: %s", new Object[]{Integer.valueOf(this.eTa)});
        if (this.eTa < 0) {
            ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "init failed!");
            k.bPz();
            AppMethodBeat.o(76640);
            return false;
        }
        this.fcR = i;
        this.owH = new q(this.fcO, this.fcP, this.fcL, this.fcM, this.fcN, this.fcY.fzT, this.fcY.fps, this.ouL);
        int ew = this.owH.ew(this.eTa, i);
        int i3 = 0;
        if (!this.fdh) {
            int i4 = -1;
            if (CaptureMMProxy.getInstance() != null) {
                i4 = CaptureMMProxy.getInstance().getInt(a.xPo, -1);
            }
            if (i4 < 0) {
                this.fcJ = new g(this.fcY.audioSampleRate, this.fcY.fzS);
                this.fcJ.iW(this.fdf);
                i3 = this.fcJ.q(this.eTa, d.WP(this.fcE));
                if (ew < 0 || i3 < 0) {
                    ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "init yuv or aac recorder error!! %d %d", new Object[]{Integer.valueOf(ew), Integer.valueOf(i3)});
                    if (i3 < 0 && ew >= 0) {
                        ab.w("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "aac init error, try mediarecorder now");
                        this.fcJ.clear();
                        this.fcJ = new i(this.fcY.audioSampleRate, this.fcY.fzS);
                        this.fcJ.iW(this.fdf);
                        ab.w("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "MMSightAACMediaRecorder init ret: %s", new Object[]{Integer.valueOf(this.fcJ.q(this.eTa, d.WP(this.fcE)))});
                        if (this.fcJ.q(this.eTa, d.WP(this.fcE)) >= 0) {
                            AppMethodBeat.o(76640);
                            return true;
                        }
                    }
                    SightVideoJNI.releaseBigSightDataBufferLock(this.eTa);
                    k.bPz();
                    AppMethodBeat.o(76640);
                    return false;
                }
            }
            if (i4 == 1) {
                this.fcJ = new g(this.fcY.audioSampleRate, this.fcY.fzS);
                this.fcJ.iW(this.fdf);
                i3 = this.fcJ.q(this.eTa, d.WP(this.fcE));
            } else if (i4 == 2) {
                this.fcJ = new i(this.fcY.audioSampleRate, this.fcY.fzS);
                this.fcJ.iW(this.fdf);
                i3 = this.fcJ.q(this.eTa, d.WP(this.fcE));
            }
            if (ew < 0 || i3 < 0) {
                ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "init yuv or aac recorder error!! %d %d", new Object[]{Integer.valueOf(ew), Integer.valueOf(i3)});
                SightVideoJNI.releaseBigSightDataBufferLock(this.eTa);
                k.bPz();
                AppMethodBeat.o(76640);
                return false;
            }
        } else if (ew < 0) {
            ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "mute init yuv recorder error!! %d %d", new Object[]{Integer.valueOf(ew), Integer.valueOf(0)});
            SightVideoJNI.releaseBigSightDataBuffer(this.eTa);
            k.bPz();
            AppMethodBeat.o(76640);
            return false;
        }
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "initImpl used %sms", new Object[]{Long.valueOf(bo.az(yz))});
        AppMethodBeat.o(76640);
        return true;
    }

    /* Access modifiers changed, original: protected|final */
    public final void aZ(byte[] bArr) {
        AppMethodBeat.i(76641);
        if (this.owH != null) {
            Message obtain = Message.obtain();
            obtain.what = 1;
            obtain.obj = bArr;
            if (this.owJ != null) {
                this.owJ.sendMessage(obtain);
            }
        }
        AppMethodBeat.o(76641);
    }

    public final boolean ko(int i) {
        AppMethodBeat.i(76642);
        if (this.eNa) {
            AppMethodBeat.o(76642);
            return true;
        }
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "preInit, cameraOrientation");
        boolean kn = kn(i);
        this.eNa = true;
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "initImpl result: %s", new Object[]{Boolean.valueOf(kn)});
        AppMethodBeat.o(76642);
        return kn;
    }

    public final int b(int i, boolean z, int i2) {
        int i3 = -1;
        AppMethodBeat.i(76643);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "start, cameraOrientation: %s, isLandscape: %s, degree: %s", new Object[]{Integer.valueOf(i), Boolean.valueOf(z), Integer.valueOf(i2)});
        this.fcW.reset();
        this.fcF = 0;
        this.fcX.reset();
        this.fcT = false;
        this.fdb = z;
        this.fdc = i2;
        this.fcQ.a(c.ovA);
        if (bo.isNullOrNil(this.fcE)) {
            ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "start error, mCurRecordPath is null!!");
            AppMethodBeat.o(76643);
        } else {
            try {
                this.mFileName = e.atd(this.fcE);
                String atb = e.atb(this.fcE);
                if (!atb.endsWith("/")) {
                    atb = atb + "/";
                }
                this.fcS = atb + "tempRotate.mp4";
            } catch (Exception e) {
                ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "retrieve file name error: %s", new Object[]{e.getMessage()});
            }
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "mCurRecordPath: %s, tempRotateFilePath: %s", new Object[]{this.fcE, this.fcS});
            this.fcR = i;
            this.owI = com.tencent.mm.sdk.g.d.ek("BigSightMediaCodecMP4MuxRecorder_writeYuvData_" + hashCode(), -1);
            this.owI.start();
            this.owJ = new 2(this, this.owI.getLooper());
            if (!this.eNa) {
                kn(i);
                this.eNa = true;
            }
            if (this.fdh || this.fdf) {
                ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "start yuvRecorder with mute");
                this.owH.start();
                this.fcQ.a(c.ovB);
                this.fda = false;
                k.bPx();
                k.Vv();
                i3 = 0;
            } else {
                i3 = this.fcJ.a(new 3(this));
                ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "start aacRecorder ret: %s", new Object[]{Integer.valueOf(i3)});
                this.fda = false;
                if (i3 != 0) {
                    this.fcQ.a(c.ovH);
                } else {
                    this.fcQ.a(c.ovI);
                }
                k.bPx();
                k.Vv();
            }
            AppMethodBeat.o(76643);
        }
        return i3;
    }

    public final void v(Runnable runnable) {
        AppMethodBeat.i(76644);
        this.fde = runnable;
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "!!!!!stop, stopCallback: %s!!!", new Object[]{runnable});
        if (this.owH == null || (this.fcJ == null && !this.fdh)) {
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "error, yuvRecorder or aacRecorder is null");
            if (runnable != null) {
                al.d(runnable);
            }
            AppMethodBeat.o(76644);
        } else if (this.fcQ == null || this.fcQ.oxa != c.ovE) {
            this.fdk = null;
            this.fcF = (int) this.owH.UQ();
            if (this.fcQ != null) {
                this.fcQ.a(c.ovC);
            }
            if (this.owH != null) {
                this.owH.a(new 4(this));
            }
            if (this.fcJ != null) {
                this.fcJ.a(new 5(this));
            }
            AppMethodBeat.o(76644);
        } else {
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "stop, already in stop status");
            if (this.fcJ != null) {
                this.fcJ.clear();
            }
            if (this.owH != null) {
                this.owH.clear();
            }
            if (runnable != null) {
                al.d(runnable);
            }
            AppMethodBeat.o(76644);
        }
    }

    /* Access modifiers changed, original: final */
    public final boolean bPW() {
        AppMethodBeat.i(76645);
        long yz = bo.yz();
        if (!(this.owI == null || this.owJ == null)) {
            if (com.tencent.mm.compatible.util.d.iW(18)) {
                this.owI.quitSafely();
            } else {
                this.owI.quit();
            }
            this.owJ = null;
        }
        this.fcG = (((float) this.owH.frameCount) * 1000.0f) / ((float) this.fcF);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "stop, frameCount: %s, fps: %s, duration: %s, file: %s handlerrunning %s, overrideDurationMs: %s, overrideFps: %s", new Object[]{Integer.valueOf(r2), Float.valueOf(this.fcG), Integer.valueOf(this.fcF), this.fcE, Long.valueOf(bo.az(yz)), Integer.valueOf(this.fcH), Float.valueOf(this.fcI)});
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "frameCountCallback %s", new Object[]{this.fcX.getValue()});
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "yuvRecorderWriteDataCallback %s", new Object[]{this.fcW.getValue()});
        String str = null;
        if (CaptureMMProxy.getInstance() != null) {
            str = CaptureMMProxy.getInstance().getAccVideoPath();
        } else if (!bo.isNullOrNil(this.fcE)) {
            str = new File(this.fcE).getParentFile().getAbsolutePath();
        }
        String RJ = !bo.isNullOrNil(str) ? com.tencent.mm.plugin.mmsight.d.RJ(str) : this.fcE;
        int i = this.fcF;
        if (this.fcH > 0) {
            i = this.fcH;
        }
        float f = this.fcG;
        if (this.fcI > 0.0f) {
            f = this.fcI;
        }
        this.fcZ = new m(this.eTa, RJ, f, this.fcN, i, this.fcY.audioSampleRate, this.fdh);
        yz = bo.yz();
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "mux used %sms, success: %s", new Object[]{Long.valueOf(bo.az(yz)), Boolean.valueOf(this.fcZ.bPO())});
        if (this.fcZ.bPO()) {
            if ((this.fdb && this.ouL) || (!(this.ouL || this.fdb) || ((this.fdb && Math.abs(this.fcR - this.fdc) == 0) || this.fdc == 180))) {
                long yz2 = bo.yz();
                int i2 = (this.ouL || this.fdb) ? this.ouL ? this.fdc : 180 : this.fcR;
                if (this.fdc == 180 && !this.ouL) {
                    i2 += 180;
                    if (i2 > 360) {
                        i2 -= 360;
                    }
                }
                if (i2 > 0) {
                    SightVideoJNI.tagRotateVideo(RJ, this.fcS, i2);
                    this.fcV = true;
                    ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "tagRotateVideo used %sms, cameraOrientation: %s, isLandscape: %s, deviceDegree: %s, rotateDegree: %s", new Object[]{Long.valueOf(bo.az(yz2)), Integer.valueOf(this.fcR), Boolean.valueOf(this.fdb), Integer.valueOf(this.fdc), Integer.valueOf(i2)});
                    yz = bo.yz();
                    try {
                        e.deleteFile(RJ);
                        e.aQ(this.fcS, RJ);
                        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "copyFile cost %s", new Object[]{Long.valueOf(bo.az(yz))});
                        com.tencent.mm.sdk.g.d.post(new 7(this, this.fcS), "BigSightMediaCodecMP4MuxRecorder_tagRotate_after_process");
                    } catch (Exception e) {
                        ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "stop, copy file error");
                        AppMethodBeat.o(76645);
                        return false;
                    }
                }
            }
            SightVideoJNI.releaseBigSightDataBufferLock(this.eTa);
            this.fcQ.a(c.ovE);
            this.cvZ = g.cz(RJ);
            if (!(bo.isNullOrNil(RJ) || RJ.equals(this.fcE))) {
                e.aQ(RJ, this.fcE);
                e.deleteFile(RJ);
            }
            AppMethodBeat.o(76645);
            return true;
        }
        ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "mux failed!");
        k.bPC();
        AppMethodBeat.o(76645);
        return false;
    }

    public final String Aq() {
        AppMethodBeat.i(76646);
        String bc = bo.bc(this.cvZ, BuildConfig.FLAVOR);
        AppMethodBeat.o(76646);
        return bc;
    }

    public final void cancel() {
        AppMethodBeat.i(76647);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "cancel record");
        if (this.owH == null || (this.fcJ == null && !this.fdh)) {
            ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "error, yuvRecorder or aacRecorder is null");
            AppMethodBeat.o(76647);
            return;
        }
        this.fcQ.a(c.ovD);
        this.owH.a(null);
        if (this.fcJ != null) {
            this.fcJ.a(new 8(this));
        }
        if (!(this.owI == null || this.owJ == null)) {
            this.owJ.removeMessages(0);
            this.owI.quit();
            this.owJ = null;
        }
        SightVideoJNI.releaseBigSightDataBufferLock(this.eTa);
        this.fcQ.a(c.ovE);
        reset();
        AppMethodBeat.o(76647);
    }

    public final void clear() {
        AppMethodBeat.i(76648);
        try {
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "clear");
            if (this.fcJ != null) {
                this.fcJ.clear();
            }
            if (this.owH != null) {
                this.owH.clear();
            }
            AppMethodBeat.o(76648);
        } catch (Exception e) {
            ab.printErrStackTrace("MicroMsg.MMSightMediaCodecMP4MuxRecorder", e, "clear error: %s", new Object[]{e.getMessage()});
            AppMethodBeat.o(76648);
        }
    }

    public final void setFilePath(String str) {
        this.fcE = str;
    }

    public final void mb(String str) {
        this.thumbPath = str;
    }

    public final void mc(String str) {
        this.fcU = str;
    }

    public final String WI() {
        return this.fcU;
    }

    public final String getFilePath() {
        return this.fcE;
    }

    public final String getFileName() {
        return this.mFileName;
    }

    public final float WJ() {
        return this.fcG;
    }

    public final void reset() {
        AppMethodBeat.i(76649);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "reset, yuvRecorder: %s, aacRecorder: %s, muxer: %s", new Object[]{this.owH, this.fcJ, this.fcZ});
        synchronized (this.fcD) {
            try {
                this.owH = null;
            } finally {
                while (true) {
                }
                AppMethodBeat.o(76649);
            }
        }
        this.fcJ = null;
        this.fcZ = null;
        this.eNa = false;
        this.fda = false;
    }

    public final long WK() {
        AppMethodBeat.i(76650);
        if (this.owH != null) {
            long UQ = this.owH.UQ();
            AppMethodBeat.o(76650);
            return UQ;
        }
        AppMethodBeat.o(76650);
        return 0;
    }

    public final f getFrameDataCallback() {
        return this.fdk;
    }

    public final void s(int i, int i2, int i3, int i4) {
        AppMethodBeat.i(76651);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "setSize, width: %s, height: %s, targetWidth: %s, targetHeight: %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4)});
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "setSize, after align, targetWidth: %d, targetHeight: %d", new Object[]{Integer.valueOf(i3), Integer.valueOf(i4)});
        this.fcL = i3;
        this.fcM = i4;
        this.fcO = i;
        this.fcP = i2;
        if (j.owk.g(Integer.valueOf(((i * i2) * 3) / 2)) == null) {
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "preloadCameraData, width: %s, height: %s, count: %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(3)});
            long yz = bo.yz();
            for (int i5 = 0; i5 < 3; i5++) {
                j.owk.g(new byte[(((i * i2) * 3) / 2)]);
            }
            ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "preloadCameraData used %sms", new Object[]{Long.valueOf(bo.az(yz))});
        }
        AppMethodBeat.o(76651);
    }

    public final String Wy() {
        return this.thumbPath;
    }

    public final c WL() {
        return this.fcQ.oxa;
    }

    public final int WM() {
        AppMethodBeat.i(76652);
        int round = Math.round(((float) this.fcF) / 1000.0f);
        AppMethodBeat.o(76652);
        return round;
    }

    public final Point WN() {
        AppMethodBeat.i(76653);
        Point point = new Point(this.fcO, this.fcP);
        AppMethodBeat.o(76653);
        return point;
    }

    public final int WO() {
        return this.fcR;
    }

    public final void pause() {
        AppMethodBeat.i(76654);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "pause");
        if (this.fcQ != null && this.fcQ.oxa == c.ovB) {
            this.fcQ.a(c.ovJ);
        }
        AppMethodBeat.o(76654);
    }

    public final void G(int i, int i2, int i3) {
        AppMethodBeat.i(76655);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "resume, cameraOrientation: %s", new Object[]{Integer.valueOf(i)});
        if (this.fcQ != null && this.fcQ.oxa == c.ovJ) {
            if (this.owH != null) {
                q qVar = this.owH;
                qVar.owT = i;
                qVar.owU = i2;
                qVar.owV = i3;
                ab.i("MicroMsg.MMSightYUVMediaCodecRecorder", "resume, newRotation: %s, newFrameWidth: %s, newFrameHeight: %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3)});
            }
            this.fcQ.a(c.ovB);
        }
        AppMethodBeat.o(76655);
    }

    public final boolean WP() {
        return this.fda;
    }

    public final void a(d$a d_a) {
        this.fdd = d_a;
    }

    public final boolean isLandscape() {
        return this.fdb;
    }

    public final void cv(boolean z) {
        this.fdf = z;
    }

    public final com.tencent.mm.audio.b.c.a WQ() {
        AppMethodBeat.i(76656);
        if (this.fcJ != null) {
            com.tencent.mm.audio.b.c.a bPN = this.fcJ.bPN();
            AppMethodBeat.o(76656);
            return bPN;
        }
        AppMethodBeat.o(76656);
        return null;
    }

    public final void WR() {
        this.fdg = false;
    }

    public final void setMute(boolean z) {
        this.fdh = z;
    }

    public final void kp(int i) {
        AppMethodBeat.i(76657);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "overrideDurationMs: %s", new Object[]{Integer.valueOf(i)});
        this.fcH = i;
        AppMethodBeat.o(76657);
    }

    public final void af(float f) {
        AppMethodBeat.i(76658);
        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "overrideFps: %s", new Object[]{Float.valueOf(f)});
        this.fcI = f;
        AppMethodBeat.o(76658);
    }

    /* JADX WARNING: Removed duplicated region for block: B:47:0x0123 A:{Catch:{ all -> 0x01f7 }} */
    /* JADX WARNING: Removed duplicated region for block: B:24:0x008a A:{Catch:{ all -> 0x01f7 }} */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0091 A:{Catch:{ all -> 0x01f7 }} */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x009a A:{Catch:{ all -> 0x01f7 }} */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x0123 A:{Catch:{ all -> 0x01f7 }} */
    static /* synthetic */ void a(com.tencent.mm.plugin.mmsight.model.a.n r19, byte[] r20) {
        /*
        r2 = 76659; // 0x12b73 float:1.07422E-40 double:3.78746E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r2);
        r2 = "MicroMsg.MMSightMediaCodecMP4MuxRecorder";
        r3 = "writeYuvDataImpl";
        com.tencent.mm.sdk.platformtools.ab.d(r2, r3);
        r2 = "MicroMsg.MMSightMediaCodecMP4MuxRecorder";
        r3 = new java.lang.StringBuilder;
        r4 = "yuvRecorder";
        r3.<init>(r4);
        r0 = r19;
        r4 = r0.owH;
        r3 = r3.append(r4);
        r3 = r3.toString();
        com.tencent.mm.sdk.platformtools.ab.d(r2, r3);
        r0 = r19;
        r12 = r0.fcD;
        monitor-enter(r12);
        r0 = r19;
        r2 = r0.owH;	 Catch:{ all -> 0x01f7 }
        if (r2 == 0) goto L_0x01ce;
    L_0x0034:
        r0 = r19;
        r2 = r0.fcW;	 Catch:{ all -> 0x01f7 }
        r4 = 1;
        r2.jl(r4);	 Catch:{ all -> 0x01f7 }
        r14 = com.tencent.mm.sdk.platformtools.bo.yz();	 Catch:{ all -> 0x01f7 }
        r0 = r19;
        r13 = r0.owH;	 Catch:{ all -> 0x01f7 }
        r0 = r19;
        r5 = r0.fcO;	 Catch:{ all -> 0x01f7 }
        r0 = r19;
        r6 = r0.fcP;	 Catch:{ all -> 0x01f7 }
        com.tencent.mm.sdk.platformtools.bo.yz();	 Catch:{ all -> 0x01f7 }
        r10 = r13.owS;	 Catch:{ all -> 0x01f7 }
        r3 = r13.ouL;	 Catch:{ all -> 0x01f7 }
        if (r3 != 0) goto L_0x01e1;
    L_0x0056:
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r3 = -1;
        if (r2 == r3) goto L_0x01dd;
    L_0x005b:
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r3 = r13.owS;	 Catch:{ all -> 0x01f7 }
        if (r2 == r3) goto L_0x01dd;
    L_0x0061:
        r3 = 1;
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r4 = r13.owS;	 Catch:{ all -> 0x01f7 }
        r7 = 180; // 0xb4 float:2.52E-43 double:8.9E-322;
        if (r4 > r7) goto L_0x01d6;
    L_0x006a:
        r4 = r13.owS;	 Catch:{ all -> 0x01f7 }
        r2 = r2 - r4;
    L_0x006d:
        r4 = 0;
        r10 = java.lang.Math.max(r4, r2);	 Catch:{ all -> 0x01f7 }
        r2 = 360; // 0x168 float:5.04E-43 double:1.78E-321;
        if (r10 < r2) goto L_0x0200;
    L_0x0076:
        r2 = 0;
    L_0x0077:
        r9 = r3;
        r10 = r2;
    L_0x0079:
        r2 = r13.owS;	 Catch:{ all -> 0x01f7 }
        r3 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r4 = -1;
        if (r3 == r4) goto L_0x0088;
    L_0x0080:
        r3 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r4 = r13.owS;	 Catch:{ all -> 0x01f7 }
        if (r3 == r4) goto L_0x0088;
    L_0x0086:
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
    L_0x0088:
        if (r2 == 0) goto L_0x008e;
    L_0x008a:
        r3 = 180; // 0xb4 float:2.52E-43 double:8.9E-322;
        if (r2 != r3) goto L_0x01ee;
    L_0x008e:
        r3 = r5;
    L_0x008f:
        if (r2 == 0) goto L_0x0095;
    L_0x0091:
        r4 = 180; // 0xb4 float:2.52E-43 double:8.9E-322;
        if (r2 != r4) goto L_0x01f1;
    L_0x0095:
        r4 = r6;
    L_0x0096:
        r7 = r13.eTi;	 Catch:{ all -> 0x01f7 }
        if (r3 != r7) goto L_0x01f4;
    L_0x009a:
        r7 = r13.eTj;	 Catch:{ all -> 0x01f7 }
        if (r4 != r7) goto L_0x01f4;
    L_0x009e:
        r8 = 0;
    L_0x009f:
        r7 = r13.owU;	 Catch:{ all -> 0x01f7 }
        r11 = -1;
        if (r7 == r11) goto L_0x00b6;
    L_0x00a4:
        r7 = r13.owV;	 Catch:{ all -> 0x01f7 }
        r11 = -1;
        if (r7 == r11) goto L_0x00b6;
    L_0x00a9:
        r7 = r13.owU;	 Catch:{ all -> 0x01f7 }
        r11 = r13.eTi;	 Catch:{ all -> 0x01f7 }
        if (r7 != r11) goto L_0x00b5;
    L_0x00af:
        r7 = r13.owV;	 Catch:{ all -> 0x01f7 }
        r11 = r13.eTj;	 Catch:{ all -> 0x01f7 }
        if (r7 == r11) goto L_0x00b6;
    L_0x00b5:
        r8 = 1;
    L_0x00b6:
        r7 = "MicroMsg.MMSightYUVMediaCodecRecorder";
        r11 = "writeData, needRotateEachFrame: %s, needScale: %s, width: %s, height: %s, rotate: %s, needRotate %s srcWidth %d srcHeight %d determinRotate %d";
        r16 = 9;
        r0 = r16;
        r0 = new java.lang.Object[r0];	 Catch:{ all -> 0x01f7 }
        r16 = r0;
        r17 = 0;
        r0 = r13.ouL;	 Catch:{ all -> 0x01f7 }
        r18 = r0;
        r18 = java.lang.Boolean.valueOf(r18);	 Catch:{ all -> 0x01f7 }
        r16[r17] = r18;	 Catch:{ all -> 0x01f7 }
        r17 = 1;
        r18 = java.lang.Boolean.valueOf(r8);	 Catch:{ all -> 0x01f7 }
        r16[r17] = r18;	 Catch:{ all -> 0x01f7 }
        r17 = 2;
        r5 = java.lang.Integer.valueOf(r5);	 Catch:{ all -> 0x01f7 }
        r16[r17] = r5;	 Catch:{ all -> 0x01f7 }
        r5 = 3;
        r6 = java.lang.Integer.valueOf(r6);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r6;	 Catch:{ all -> 0x01f7 }
        r5 = 4;
        r6 = java.lang.Integer.valueOf(r10);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r6;	 Catch:{ all -> 0x01f7 }
        r5 = 5;
        r6 = java.lang.Boolean.valueOf(r9);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r6;	 Catch:{ all -> 0x01f7 }
        r5 = 6;
        r6 = java.lang.Integer.valueOf(r3);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r6;	 Catch:{ all -> 0x01f7 }
        r5 = 7;
        r6 = java.lang.Integer.valueOf(r4);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r6;	 Catch:{ all -> 0x01f7 }
        r5 = 8;
        r2 = java.lang.Integer.valueOf(r2);	 Catch:{ all -> 0x01f7 }
        r16[r5] = r2;	 Catch:{ all -> 0x01f7 }
        r0 = r16;
        com.tencent.mm.sdk.platformtools.ab.d(r7, r11, r0);	 Catch:{ all -> 0x01f7 }
        r2 = new com.tencent.mm.plugin.mmsight.model.a.b;	 Catch:{ all -> 0x01f7 }
        r5 = r13.eTl;	 Catch:{ all -> 0x01f7 }
        r6 = r13.eTi;	 Catch:{ all -> 0x01f7 }
        r7 = r13.eTj;	 Catch:{ all -> 0x01f7 }
        r11 = r20;
        r2.<init>(r3, r4, r5, r6, r7, r8, r9, r10, r11);	 Catch:{ all -> 0x01f7 }
        r3 = r13.owW;	 Catch:{ all -> 0x01f7 }
        r4 = r3.ovl;	 Catch:{ all -> 0x01f7 }
        if (r4 != 0) goto L_0x0185;
    L_0x0123:
        r4 = r3.handler;	 Catch:{ all -> 0x01f7 }
        if (r4 != 0) goto L_0x0132;
    L_0x0127:
        r4 = new com.tencent.mm.sdk.platformtools.ak;	 Catch:{ all -> 0x01f7 }
        r5 = android.os.Looper.myLooper();	 Catch:{ all -> 0x01f7 }
        r4.<init>(r5);	 Catch:{ all -> 0x01f7 }
        r3.handler = r4;	 Catch:{ all -> 0x01f7 }
    L_0x0132:
        r4 = r3.ovh;	 Catch:{ all -> 0x01f7 }
        r5 = com.tencent.mm.plugin.mmsight.model.a.a.ovf;	 Catch:{ all -> 0x01f7 }
        r4 = r4 % r5;
        r5 = r3.ovg;	 Catch:{ all -> 0x01f7 }
        r5 = r5[r4];	 Catch:{ all -> 0x01f7 }
        if (r5 == 0) goto L_0x0185;
    L_0x013d:
        r5 = r3.ovh;	 Catch:{ all -> 0x01f7 }
        r6 = r3.ovg;	 Catch:{ all -> 0x01f7 }
        r6 = r6[r4];	 Catch:{ all -> 0x01f7 }
        r6 = r6.getLooper();	 Catch:{ all -> 0x01f7 }
        r7 = r3.ovm;	 Catch:{ all -> 0x01f7 }
        r2.ovt = r5;	 Catch:{ all -> 0x01f7 }
        r2.ovv = r4;	 Catch:{ all -> 0x01f7 }
        r4 = com.tencent.mm.sdk.platformtools.bo.yz();	 Catch:{ all -> 0x01f7 }
        r2.ovu = r4;	 Catch:{ all -> 0x01f7 }
        r4 = "MicroMsg.FrameBufProcessor";
        r5 = "create framebuf %d %d";
        r8 = 2;
        r8 = new java.lang.Object[r8];	 Catch:{ all -> 0x01f7 }
        r9 = 0;
        r10 = r2.ovq;	 Catch:{ all -> 0x01f7 }
        r10 = r10.length;	 Catch:{ all -> 0x01f7 }
        r10 = java.lang.Integer.valueOf(r10);	 Catch:{ all -> 0x01f7 }
        r8[r9] = r10;	 Catch:{ all -> 0x01f7 }
        r9 = 1;
        r10 = r2.ovt;	 Catch:{ all -> 0x01f7 }
        r10 = java.lang.Integer.valueOf(r10);	 Catch:{ all -> 0x01f7 }
        r8[r9] = r10;	 Catch:{ all -> 0x01f7 }
        com.tencent.mm.sdk.platformtools.ab.i(r4, r5, r8);	 Catch:{ all -> 0x01f7 }
        r4 = new com.tencent.mm.sdk.platformtools.ak;	 Catch:{ all -> 0x01f7 }
        r4.<init>(r6);	 Catch:{ all -> 0x01f7 }
        r5 = new com.tencent.mm.plugin.mmsight.model.a.b$1;	 Catch:{ all -> 0x01f7 }
        r5.<init>(r2, r7);	 Catch:{ all -> 0x01f7 }
        r4.post(r5);	 Catch:{ all -> 0x01f7 }
        r2 = r3.ovh;	 Catch:{ all -> 0x01f7 }
        r2 = r2 + 1;
        r3.ovh = r2;	 Catch:{ all -> 0x01f7 }
    L_0x0185:
        r2 = "MicroMsg.MMSightMediaCodecMP4MuxRecorder";
        r3 = "writeYuvData used %sms";
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x01f7 }
        r5 = 0;
        r6 = com.tencent.mm.sdk.platformtools.bo.az(r14);	 Catch:{ all -> 0x01f7 }
        r6 = java.lang.Long.valueOf(r6);	 Catch:{ all -> 0x01f7 }
        r4[r5] = r6;	 Catch:{ all -> 0x01f7 }
        com.tencent.mm.sdk.platformtools.ab.d(r2, r3, r4);	 Catch:{ all -> 0x01f7 }
        r0 = r19;
        r2 = r0.fcT;	 Catch:{ all -> 0x01f7 }
        if (r2 != 0) goto L_0x01c9;
    L_0x01a2:
        r0 = r19;
        r2 = r0.fdg;	 Catch:{ all -> 0x01f7 }
        if (r2 == 0) goto L_0x01c9;
    L_0x01a8:
        r2 = 1;
        r0 = r19;
        r0.fcT = r2;	 Catch:{ all -> 0x01f7 }
        r0 = r20;
        r2 = r0.length;	 Catch:{ all -> 0x01f7 }
        r2 = new byte[r2];	 Catch:{ all -> 0x01f7 }
        r3 = 0;
        r4 = 0;
        r0 = r20;
        r5 = r0.length;	 Catch:{ all -> 0x01f7 }
        r0 = r20;
        java.lang.System.arraycopy(r0, r3, r2, r4, r5);	 Catch:{ all -> 0x01f7 }
        r3 = new com.tencent.mm.plugin.mmsight.model.a.n$9;	 Catch:{ all -> 0x01f7 }
        r0 = r19;
        r3.<init>(r0, r2);	 Catch:{ all -> 0x01f7 }
        r2 = "BigSightMediaCodecMP4MuxRecorder_saveThumb";
        com.tencent.mm.sdk.g.d.post(r3, r2);	 Catch:{ all -> 0x01f7 }
    L_0x01c9:
        r2 = 1;
        r0 = r19;
        r0.fda = r2;	 Catch:{ all -> 0x01f7 }
    L_0x01ce:
        monitor-exit(r12);	 Catch:{ all -> 0x01f7 }
        r2 = 76659; // 0x12b73 float:1.07422E-40 double:3.78746E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r2);
        return;
    L_0x01d6:
        r4 = r13.owS;	 Catch:{ all -> 0x01f7 }
        r4 = 360 - r4;
        r2 = r2 + r4;
        goto L_0x006d;
    L_0x01dd:
        r3 = 0;
        r9 = r3;
        goto L_0x0079;
    L_0x01e1:
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
        r4 = -1;
        if (r2 != r4) goto L_0x01ea;
    L_0x01e6:
        r2 = r13.owS;	 Catch:{ all -> 0x01f7 }
        goto L_0x0077;
    L_0x01ea:
        r2 = r13.owT;	 Catch:{ all -> 0x01f7 }
        goto L_0x0077;
    L_0x01ee:
        r3 = r6;
        goto L_0x008f;
    L_0x01f1:
        r4 = r5;
        goto L_0x0096;
    L_0x01f4:
        r8 = 1;
        goto L_0x009f;
    L_0x01f7:
        r2 = move-exception;
        monitor-exit(r12);	 Catch:{ all -> 0x01f7 }
        r3 = 76659; // 0x12b73 float:1.07422E-40 double:3.78746E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        throw r2;
    L_0x0200:
        r9 = r3;
        goto L_0x0079;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.mmsight.model.a.n.a(com.tencent.mm.plugin.mmsight.model.a.n, byte[]):void");
    }

    static /* synthetic */ void b(n nVar, byte[] bArr) {
        AppMethodBeat.i(76660);
        if (bArr != null) {
            try {
                if (bArr.length != 0) {
                    if (bo.isNullOrNil(nVar.thumbPath)) {
                        ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "saveVideoThumbImpl, thumbpath is null");
                        nVar.fcT = false;
                        AppMethodBeat.o(76660);
                        return;
                    }
                    int width;
                    Bitmap b;
                    int i = (nVar.fcR == 0 || nVar.fcR == 180) ? nVar.fcO : nVar.fcP;
                    int i2 = (nVar.fcR == 0 || nVar.fcR == 180) ? nVar.fcP : nVar.fcO;
                    YuvImage yuvImage = new YuvImage(bArr, 17, i, i2, null);
                    Rect rect = new Rect(0, 0, i, i2);
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    yuvImage.compressToJpeg(rect, 100, byteArrayOutputStream);
                    byte[] toByteArray = byteArrayOutputStream.toByteArray();
                    Bitmap decodeByteArray = MMBitmapFactory.decodeByteArray(toByteArray, 0, toByteArray.length);
                    if (nVar.fcY != null && Math.min(decodeByteArray.getWidth(), decodeByteArray.getHeight()) > nVar.fcY.fAf) {
                        width = decodeByteArray.getWidth();
                        i = decodeByteArray.getHeight();
                        int i3 = nVar.fcY.fAf > 0 ? nVar.fcY.fAf : nVar.fcY.width;
                        if (width < i) {
                            width = (int) (((float) i) / ((((float) width) * 1.0f) / ((float) i3)));
                            i = i3;
                        } else {
                            i = (int) (((float) width) / ((((float) i) * 1.0f) / ((float) i3)));
                            width = i3;
                        }
                        decodeByteArray = Bitmap.createScaledBitmap(decodeByteArray, i, width, true);
                    }
                    if (!nVar.fdb || nVar.fdc == 180) {
                        width = nVar.fcR;
                        if (nVar.fdc == 180) {
                            width += 180;
                            if (width > 360) {
                                width -= 360;
                            }
                        }
                        b = com.tencent.mm.sdk.platformtools.d.b(decodeByteArray, (float) width);
                    } else if (Math.abs(nVar.fcR - nVar.fdc) == 0) {
                        b = com.tencent.mm.sdk.platformtools.d.b(decodeByteArray, 180.0f);
                        ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "bitmap recycle %s", new Object[]{decodeByteArray.toString()});
                        decodeByteArray.recycle();
                    } else {
                        b = decodeByteArray;
                    }
                    com.tencent.mm.sdk.platformtools.d.a(b, 60, CompressFormat.JPEG, nVar.thumbPath, true);
                    ab.i("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "saveVideoThumb to: %s, cameraOrientation: %s, width: %s, height: %s %s", new Object[]{nVar.thumbPath, Integer.valueOf(nVar.fcR), Integer.valueOf(b.getWidth()), Integer.valueOf(b.getHeight()), Long.valueOf(e.asZ(nVar.thumbPath))});
                    AppMethodBeat.o(76660);
                    return;
                }
            } catch (Exception e) {
                ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "saveVideoThumb error: %s", new Object[]{e.getMessage()});
                nVar.fcT = false;
                AppMethodBeat.o(76660);
                return;
            }
        }
        ab.e("MicroMsg.MMSightMediaCodecMP4MuxRecorder", "saveVideoThumbImpl, data is null");
        nVar.fcT = false;
        AppMethodBeat.o(76660);
    }
}
