package com.tencent.mm.plugin.facedetectlight.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.SurfaceTexture;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.Size;
import android.os.Build.VERSION;
import android.os.HandlerThread;
import android.os.Looper;
import android.support.v4.widget.j;
import android.view.TextureView.SurfaceTextureListener;
import android.widget.ImageView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.compatible.e.d.a.a;
import com.tencent.mm.compatible.e.q;
import com.tencent.mm.compatible.e.t;
import com.tencent.mm.plugin.facedetect.model.c;
import com.tencent.mm.plugin.facedetectaction.ui.FaceActionMask;
import com.tencent.mm.plugin.facedetectaction.ui.FaceActionUI;
import com.tencent.mm.sdk.g.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
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.ui.base.MMTextureView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class b implements SurfaceTextureListener {
    public String edV;
    private Bitmap faceBitmap;
    private a fbb;
    private boolean isFrontCamera;
    private Point lUF;
    private Point lUG;
    private Point lUH;
    private boolean lUI;
    private int lUJ;
    private Point lUM;
    public byte[] lWX;
    public boolean lXB;
    public String mAppId;
    private Context mContext;
    int mDesiredPreviewHeight;
    int mDesiredPreviewWidth;
    private boolean mIsCameraOpened;
    private PreviewCallback man;
    com.tencent.mm.plugin.facedetect.model.d.b mao;
    public int mbW;
    public String mbX;
    private FaceActionUI mbY;
    public FaceActionMask mcP;
    private com.tencent.mm.plugin.facedetectaction.b.a.a mca;
    public PreviewFrameLayout mdA;
    private int mdB;
    public String mdC;
    public ImageView mdD;
    public ImageView mdE;
    private boolean mdF;
    private int mdG;
    private al mdH;
    private com.tencent.mm.plugin.facedetectlight.ui.a.b mdI;
    private MMTextureView mdt;
    private HandlerThread mdu;
    private ak mdv;
    public t mdw;
    public boolean mdx;
    public TextView mdy;
    public FaceReflectMask mdz;

    static /* synthetic */ boolean d(b bVar) {
        AppMethodBeat.i(785);
        boolean btV = bVar.btV();
        AppMethodBeat.o(785);
        return btV;
    }

    public b(Context context, com.tencent.mm.plugin.facedetectlight.ui.a.b bVar) {
        AppMethodBeat.i(772);
        this.lUF = null;
        this.lUG = null;
        this.lUH = null;
        this.lUM = null;
        this.mdB = 0;
        this.mdH = new al("mPreviewHandlerThread");
        this.mao = new com.tencent.mm.plugin.facedetect.model.d.b() {
            public final void aT(byte[] bArr) {
                AppMethodBeat.i(771);
                c.lTA.g(bArr);
                AppMethodBeat.o(771);
            }

            public final com.tencent.mm.memory.a<byte[]> bsr() {
                return c.lTA;
            }
        };
        this.man = new 2(this);
        this.mdI = bVar;
        this.mdG = 1;
        this.mContext = context;
        this.mIsCameraOpened = false;
        this.lXB = false;
        this.mdu = null;
        this.mIsCameraOpened = false;
        AppMethodBeat.o(772);
    }

    public b(FaceActionUI faceActionUI, com.tencent.mm.plugin.facedetectaction.b.a.a aVar) {
        AppMethodBeat.i(773);
        this.lUF = null;
        this.lUG = null;
        this.lUH = null;
        this.lUM = null;
        this.mdB = 0;
        this.mdH = new al("mPreviewHandlerThread");
        this.mao = /* anonymous class already generated */;
        this.man = new 2(this);
        this.mdG = 2;
        this.mbY = faceActionUI;
        this.mIsCameraOpened = false;
        this.lXB = false;
        this.mdu = null;
        this.mIsCameraOpened = false;
        this.mdF = false;
        this.mca = aVar;
        AppMethodBeat.o(773);
    }

    public final void a(MMTextureView mMTextureView) {
        AppMethodBeat.i(774);
        this.mdt = mMTextureView;
        if (this.mdt.isAvailable()) {
            g(mMTextureView.getSurfaceTexture());
        }
        this.mdt.setSurfaceTextureListener(this);
        this.mdt.setVisibility(0);
        this.mdt.setAlpha(0.0f);
        if (this.mdG == 2 && !this.mdF) {
            al.n(new Runnable() {
                public final void run() {
                    AppMethodBeat.i(758);
                    b.this.mdD.setVisibility(8);
                    b.this.mdE.setVisibility(8);
                    b.this.mdF = true;
                    AppMethodBeat.o(758);
                }
            }, 700);
        }
        AppMethodBeat.o(774);
    }

    private void g(SurfaceTexture surfaceTexture) {
        AppMethodBeat.i(775);
        ab.i("MicroMsg.FaceReflectCam", "openCameraForSurfaceTexture");
        if (this.mdG == 1) {
            this.mdz.setVisibility(0);
        } else {
            this.mcP.setVisibility(0);
        }
        btX();
        if (this.mdv != null) {
            this.mdv.post(new 3(this));
            this.mdv.post(new 4(this, surfaceTexture));
            AppMethodBeat.o(775);
            return;
        }
        ab.i("MicroMsg.FaceReflectCam", "back thread is not running");
        AppMethodBeat.o(775);
    }

    public final boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        AppMethodBeat.i(776);
        ab.i("MicroMsg.FaceReflectCam", "surfaceDestroyed");
        if (this.mdv != null) {
            this.mdv.post(new 5(this));
            if (this.mdu != null) {
                ab.i("MicroMsg.FaceReflectCam", "stop camera thread");
                try {
                    Thread.sleep(500, 0);
                } catch (InterruptedException e) {
                    ab.i("MicroMsg.FaceReflectCam", "background thread sleep error：" + e.getMessage());
                }
                if (VERSION.SDK_INT >= 18) {
                    this.mdu.quitSafely();
                } else {
                    this.mdu.quit();
                }
                try {
                    this.mdu.join();
                    this.mdu = null;
                    this.mdv = null;
                } catch (InterruptedException e2) {
                    ab.i("MicroMsg.FaceReflectCam", "stop background thread error：" + e2.getMessage());
                }
                ab.i("MicroMsg.FaceReflectCam", "stop camera thread finish");
            }
        } else {
            ab.i("MicroMsg.FaceReflectCam", "back thread is not running");
        }
        AppMethodBeat.o(776);
        return false;
    }

    public final void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
        AppMethodBeat.i(777);
        ab.i("MicroMsg.FaceReflectCam", "onSurfaceTextureAvailable, width: %s, height: %s", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
        g(surfaceTexture);
        AppMethodBeat.o(777);
    }

    public final void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
    }

    public final void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
    }

    /* JADX WARNING: Removed duplicated region for block: B:60:0x026f  */
    /* JADX WARNING: Removed duplicated region for block: B:90:0x037b  */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x028f  */
    /* JADX WARNING: Removed duplicated region for block: B:67:0x0296  */
    /* JADX WARNING: Removed duplicated region for block: B:93:0x03ae  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x02ce  */
    /* JADX WARNING: Removed duplicated region for block: B:74:0x02ff  */
    private boolean btV() {
        /*
        r12 = this;
        r10 = 17;
        r4 = 0;
        r11 = 778; // 0x30a float:1.09E-42 double:3.844E-321;
        r2 = 1;
        r3 = 0;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r11);
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "start open camera";
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);
        r12.mIsCameraOpened = r3;
        r12.isFrontCamera = r2;
        r1 = -1;
        r5 = android.hardware.Camera.getNumberOfCameras();
        r0 = r3;
    L_0x001d:
        if (r0 >= r5) goto L_0x0415;
    L_0x001f:
        r6 = new android.hardware.Camera$CameraInfo;
        r6.<init>();
        android.hardware.Camera.getCameraInfo(r0, r6);
        r7 = r6.facing;
        if (r7 != r2) goto L_0x00ad;
    L_0x002b:
        r7 = r12.isFrontCamera;
        if (r7 == 0) goto L_0x00ad;
    L_0x002f:
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "hy: front Camera found";
        com.tencent.mm.sdk.platformtools.ab.d(r1, r5);
    L_0x0038:
        r6 = com.tencent.mm.sdk.platformtools.bo.yz();
        r1 = "MicroMsg.FaceReflectCam";
        r5 = new java.lang.StringBuilder;
        r8 = "openCameraRes：";
        r5.<init>(r8);
        r8 = r12.fbb;
        r5 = r5.append(r8);
        r5 = r5.toString();
        com.tencent.mm.sdk.platformtools.ab.i(r1, r5);
        r1 = r12.fbb;
        if (r1 != 0) goto L_0x0076;
    L_0x0058:
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "openCameraRes is null";
        com.tencent.mm.sdk.platformtools.ab.i(r1, r5);
        r1 = r12.mdG;
        if (r1 != r2) goto L_0x00c4;
    L_0x0065:
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "mFaceReflectController openCameraRe";
        com.tencent.mm.sdk.platformtools.ab.i(r1, r5);
        r1 = r12.mContext;
        r1 = com.tencent.mm.compatible.e.d.a(r1, r0, r4);
        r12.fbb = r1;
    L_0x0076:
        r1 = r12.fbb;
        if (r1 != 0) goto L_0x00da;
    L_0x007a:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "in open(), openCameraRes == null";
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);
        r0 = new java.io.IOException;	 Catch:{ IOException -> 0x008e }
        r0.<init>();	 Catch:{ IOException -> 0x008e }
        r1 = 778; // 0x30a float:1.09E-42 double:3.844E-321;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);	 Catch:{ IOException -> 0x008e }
        throw r0;	 Catch:{ IOException -> 0x008e }
    L_0x008e:
        r0 = move-exception;
        r1 = "MicroMsg.FaceReflectCam";
        r2 = new java.lang.StringBuilder;
        r4 = "set cameraRes exception";
        r2.<init>(r4);
        r0 = r0.getMessage();
        r0 = r2.append(r0);
        r0 = r0.toString();
        com.tencent.mm.sdk.platformtools.ab.i(r1, r0);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r11);
    L_0x00ac:
        return r3;
    L_0x00ad:
        r6 = r6.facing;
        if (r6 != 0) goto L_0x00c0;
    L_0x00b1:
        r6 = r12.isFrontCamera;
        if (r6 != 0) goto L_0x00c0;
    L_0x00b5:
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "hy: front Camera found";
        com.tencent.mm.sdk.platformtools.ab.d(r1, r5);
        goto L_0x0038;
    L_0x00c0:
        r0 = r0 + 1;
        goto L_0x001d;
    L_0x00c4:
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "mFaceActionUI openCameraRe";
        com.tencent.mm.sdk.platformtools.ab.i(r1, r5);
        r1 = r12.mbY;
        r1 = r1.mController;
        r1 = r1.ylL;
        r1 = com.tencent.mm.compatible.e.d.a(r1, r0, r4);
        r12.fbb = r1;
        goto L_0x0076;
    L_0x00da:
        r12.mdB = r0;
        r12.mIsCameraOpened = r2;
        r1 = "MicroMsg.FaceReflectCam";
        r5 = "openCamera done, cameraId=[%s] costTime=[%s]";
        r8 = 2;
        r8 = new java.lang.Object[r8];
        r0 = java.lang.Integer.valueOf(r0);
        r8[r3] = r0;
        r6 = com.tencent.mm.sdk.platformtools.bo.az(r6);
        r0 = java.lang.Long.valueOf(r6);
        r8[r2] = r0;
        com.tencent.mm.sdk.platformtools.ab.d(r1, r5, r8);
        r0 = r12.fbb;
        r0 = r0.rotate;
        r12.lUJ = r0;
        r0 = r12.fbb;
        r0 = r0.rotate;
        r0 = r0 % 180;
        if (r0 == 0) goto L_0x031f;
    L_0x0108:
        r0 = r2;
    L_0x0109:
        r12.lUI = r0;
        r0 = r12.fbb;
        r0 = r0.erH;
        r12.mdw = r0;
        r0 = r12.mdw;
        if (r0 != 0) goto L_0x014e;
    L_0x0115:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "in open(), camera == null, bNeedRotate=[%s]";
        r5 = new java.lang.Object[r2];
        r6 = r12.lUI;
        r6 = java.lang.Boolean.valueOf(r6);
        r5[r3] = r6;
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1, r5);
        r0 = new java.io.IOException;	 Catch:{ IOException -> 0x0133 }
        r0.<init>();	 Catch:{ IOException -> 0x0133 }
        r1 = 778; // 0x30a float:1.09E-42 double:3.844E-321;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);	 Catch:{ IOException -> 0x0133 }
        throw r0;	 Catch:{ IOException -> 0x0133 }
    L_0x0133:
        r0 = move-exception;
        r1 = "MicroMsg.FaceReflectCam";
        r5 = new java.lang.StringBuilder;
        r6 = "set cameraRotation exception";
        r5.<init>(r6);
        r0 = r0.getMessage();
        r0 = r5.append(r0);
        r0 = r0.toString();
        com.tencent.mm.sdk.platformtools.ab.i(r1, r0);
    L_0x014e:
        r0 = r12.mdw;	 Catch:{ Exception -> 0x0322 }
        r5 = r0.getParameters();	 Catch:{ Exception -> 0x0322 }
        r0 = r12.mdG;
        if (r0 != r2) goto L_0x0339;
    L_0x0158:
        r0 = r12.mContext;
        r0 = r0.getResources();
        r0 = r0.getDisplayMetrics();
        r1 = r0.widthPixels;
        r0 = r12.mContext;
        r0 = r0.getResources();
        r0 = r0.getDisplayMetrics();
        r0 = r0.heightPixels;
    L_0x0170:
        r6 = new android.graphics.Point;
        r6.<init>(r1, r0);
        r12.lUG = r6;
        r1 = r12.lUG;
        r6 = r12.lUH;
        r0 = "preview-size-values";
        r0 = r5.get(r0);
        if (r0 != 0) goto L_0x018b;
    L_0x0184:
        r0 = "preview-size-value";
        r0 = r5.get(r0);
    L_0x018b:
        if (r0 == 0) goto L_0x0412;
    L_0x018d:
        r4 = "MicroMsg.FaceReflectCam";
        r7 = "preview-size-values parameter: ";
        r0 = java.lang.String.valueOf(r0);
        r0 = r7.concat(r0);
        com.tencent.mm.sdk.platformtools.ab.d(r4, r0);
        r0 = a(r5, r1);
    L_0x01a2:
        if (r0 != 0) goto L_0x01b5;
    L_0x01a4:
        r0 = new android.graphics.Point;
        r1 = r6.x;
        r1 = r1 >> 3;
        r1 = r1 << 3;
        r4 = r6.y;
        r4 = r4 >> 3;
        r4 = r4 << 3;
        r0.<init>(r1, r4);
    L_0x01b5:
        r12.lUF = r0;
        r0 = new android.graphics.Point;
        r1 = r12.lUF;
        r0.<init>(r1);
        r12.lUM = r0;
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r4 = "getCameraResolution: ";
        r1.<init>(r4);
        r4 = r12.lUG;
        r1 = r1.append(r4);
        r4 = " camera:";
        r1 = r1.append(r4);
        r4 = r12.lUF;
        r1 = r1.append(r4);
        r4 = "bestVideoEncodeSize: ";
        r1 = r1.append(r4);
        r4 = r12.lUM;
        r1 = r1.append(r4);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.d(r0, r1);
        r0 = r12.lUF;
        r0 = r0.x;
        r12.mDesiredPreviewWidth = r0;
        r0 = r12.lUF;
        r0 = r0.y;
        r12.mDesiredPreviewHeight = r0;
        r0 = r12.mDesiredPreviewWidth;
        r1 = r12.mDesiredPreviewHeight;
        r5.setPreviewSize(r0, r1);
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r4 = "mDesiredPreviewWidth：";
        r1.<init>(r4);
        r4 = r12.mDesiredPreviewWidth;
        r1 = r1.append(r4);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1);
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r4 = "mDesiredPreviewHeight：";
        r1.<init>(r4);
        r4 = r12.mDesiredPreviewHeight;
        r1 = r1.append(r4);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1);
        r5.setZoom(r3);
        r0 = "auto";
        r5.setSceneMode(r0);
        r0 = r5.getSupportedFocusModes();	 Catch:{ Exception -> 0x035e }
        if (r0 == 0) goto L_0x0353;
    L_0x0244:
        r0 = r5.getSupportedFocusModes();	 Catch:{ Exception -> 0x035e }
        r1 = "auto";
        r0 = r0.contains(r1);	 Catch:{ Exception -> 0x035e }
        if (r0 == 0) goto L_0x0353;
    L_0x0251:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "set FocusMode to FOCUS_MODE_AUTO";
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);	 Catch:{ Exception -> 0x035e }
        r0 = "auto";
        r5.setFocusMode(r0);	 Catch:{ Exception -> 0x035e }
    L_0x0260:
        r4 = r5.getSupportedPreviewFormats();
        r6 = r4.iterator();
        r1 = r3;
    L_0x0269:
        r0 = r6.hasNext();
        if (r0 == 0) goto L_0x040f;
    L_0x026f:
        r0 = r6.next();
        r0 = (java.lang.Integer) r0;
        r0 = r0.intValue();
        r7 = "MicroMsg.FaceReflectCam";
        r8 = "supportedPreviewFormat: ";
        r9 = java.lang.String.valueOf(r0);
        r8 = r8.concat(r9);
        com.tencent.mm.sdk.platformtools.ab.d(r7, r8);
        if (r0 != r10) goto L_0x0372;
    L_0x028c:
        r0 = r2;
    L_0x028d:
        if (r0 == 0) goto L_0x037b;
    L_0x028f:
        r5.setPreviewFormat(r10);
    L_0x0292:
        r0 = r12.lUI;
        if (r0 == 0) goto L_0x029b;
    L_0x0296:
        r0 = r12.lUJ;
        r5.setRotation(r0);
    L_0x029b:
        r0 = r12.mdA;
        r0 = r0.getmAspectRatio();
        r4 = "MicroMsg.FaceReflectCam";
        r6 = "original ratio=";
        r7 = java.lang.String.valueOf(r0);
        r6 = r6.concat(r7);
        com.tencent.mm.sdk.platformtools.ab.d(r4, r6);
        r4 = r12.mDesiredPreviewWidth;
        r6 = (double) r4;
        r4 = r12.mDesiredPreviewHeight;
        r8 = (double) r4;
        r6 = r6 / r8;
        r4 = "MicroMsg.FaceReflectCam";
        r8 = "new ratio=";
        r9 = java.lang.String.valueOf(r6);
        r8 = r8.concat(r9);
        com.tencent.mm.sdk.platformtools.ab.d(r4, r8);
        r0 = (r0 > r6 ? 1 : (r0 == r6 ? 0 : -1));
        if (r0 != 0) goto L_0x03ae;
    L_0x02ce:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "NO NEED reset ratio";
        com.tencent.mm.sdk.platformtools.ab.d(r0, r1);
    L_0x02d7:
        b(r5);
        r6 = r5.getSupportedPreviewFpsRange();
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r4 = "range:";
        r1.<init>(r4);
        r4 = r6.size();
        r1 = r1.append(r4);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.d(r0, r1);
        r4 = r3;
    L_0x02f9:
        r0 = r6.size();
        if (r4 >= r0) goto L_0x03c6;
    L_0x02ff:
        r0 = r6.get(r4);
        r0 = (int[]) r0;
        r1 = r3;
    L_0x0306:
        r7 = r0.length;
        if (r1 >= r7) goto L_0x03c1;
    L_0x0309:
        r7 = "MicroMsg.FaceReflectCam";
        r8 = "Camera SupportedPreviewFpsRange：";
        r9 = new java.lang.Object[r2];
        r10 = r0[r1];
        r10 = java.lang.Integer.valueOf(r10);
        r9[r3] = r10;
        com.tencent.mm.sdk.platformtools.ab.i(r7, r8, r9);
        r1 = r1 + 1;
        goto L_0x0306;
    L_0x031f:
        r0 = r3;
        goto L_0x0109;
    L_0x0322:
        r0 = move-exception;
        r1 = "MicroMsg.FaceReflectCam";
        r4 = "camera getParameters error: %s";
        r2 = new java.lang.Object[r2];
        r5 = r0.getMessage();
        r2[r3] = r5;
        com.tencent.mm.sdk.platformtools.ab.printErrStackTrace(r1, r0, r4, r2);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r11);
        goto L_0x00ac;
    L_0x0339:
        r0 = r12.mbY;
        r0 = r0.getResources();
        r0 = r0.getDisplayMetrics();
        r1 = r0.widthPixels;
        r0 = r12.mbY;
        r0 = r0.getResources();
        r0 = r0.getDisplayMetrics();
        r0 = r0.heightPixels;
        goto L_0x0170;
    L_0x0353:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "camera not support FOCUS_MODE_AUTO";
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);	 Catch:{ Exception -> 0x035e }
        goto L_0x0260;
    L_0x035e:
        r0 = move-exception;
        r1 = "MicroMsg.FaceReflectCam";
        r4 = "set focus mode error: %s";
        r6 = new java.lang.Object[r2];
        r0 = r0.getMessage();
        r6[r3] = r0;
        com.tencent.mm.sdk.platformtools.ab.e(r1, r4, r6);
        goto L_0x0260;
    L_0x0372:
        r7 = 842094169; // 0x32315659 float:1.0322389E-8 double:4.160497995E-315;
        if (r0 != r7) goto L_0x040c;
    L_0x0377:
        r0 = r2;
    L_0x0378:
        r1 = r0;
        goto L_0x0269;
    L_0x037b:
        if (r1 == 0) goto L_0x038e;
    L_0x037d:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "Preview not support PixelFormat.YCbCr_420_SP, but hasYU12";
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1);
        r0 = 842094169; // 0x32315659 float:1.0322389E-8 double:4.160497995E-315;
        r5.setPreviewFormat(r0);
        goto L_0x0292;
    L_0x038e:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "Preview not support PixelFormat.YCbCr_420_SP. Use format: %s";
        r6 = new java.lang.Object[r2];
        r7 = r4.get(r3);
        r6[r3] = r7;
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1, r6);
        r0 = r4.get(r3);
        r0 = (java.lang.Integer) r0;
        r0 = r0.intValue();
        r5.setPreviewFormat(r0);
        goto L_0x0292;
    L_0x03ae:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = "start reset ratio";
        com.tencent.mm.sdk.platformtools.ab.d(r0, r1);
        r0 = new com.tencent.mm.plugin.facedetectlight.ui.b$6;
        r0.<init>(r12, r6);
        com.tencent.mm.sdk.platformtools.al.d(r0);
        goto L_0x02d7;
    L_0x03c1:
        r0 = r4 + 1;
        r4 = r0;
        goto L_0x02f9;
    L_0x03c6:
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r2 = "Camera preview-fps-range：";
        r1.<init>(r2);
        r2 = "preview-fps-range";
        r2 = r5.get(r2);
        r1 = r1.append(r2);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);
        r0 = "MicroMsg.FaceReflectCam";
        r1 = new java.lang.StringBuilder;
        r2 = "Camera preview-fps-range：";
        r1.<init>(r2);
        r2 = "preview-frame-rate";
        r2 = r5.get(r2);
        r1 = r1.append(r2);
        r1 = r1.toString();
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1);
        r0 = r12.mdw;
        r0.setParameters(r5);
        r3 = r12.mIsCameraOpened;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r11);
        goto L_0x00ac;
    L_0x040c:
        r0 = r1;
        goto L_0x0378;
    L_0x040f:
        r0 = r3;
        goto L_0x028d;
    L_0x0412:
        r0 = r4;
        goto L_0x01a2;
    L_0x0415:
        r0 = r1;
        goto L_0x0038;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.facedetectlight.ui.b.btV():boolean");
    }

    public final void stopPreview() {
        AppMethodBeat.i(779);
        ab.i("MicroMsg.FaceReflectCam", "stopPreview, isPreviewing: %s", new Object[]{Boolean.valueOf(this.mdx)});
        if (this.mdw != null) {
            this.mdw.stopPreview();
            this.mdx = false;
            c.lTA.WY();
        }
        AppMethodBeat.o(779);
    }

    public final void btW() {
        AppMethodBeat.i(780);
        ab.i("MicroMsg.FaceReflectCam", "closeCamera start");
        if (this.mdw != null) {
            try {
                if (this.lXB) {
                    this.lXB = false;
                    this.mdw.stopPreview();
                    this.mdw.setPreviewCallback(null);
                    ab.i("MicroMsg.FaceReflectCam", "stop preview, not previewing");
                }
            } catch (Exception e) {
                ab.i("MicroMsg.FaceReflectCam", "Error setting camera preview: " + e.getMessage());
            }
            try {
                this.mdw.release();
                this.mdw = null;
                this.mdw = null;
            } catch (Exception e2) {
                ab.i("MicroMsg.FaceReflectCam", "Error setting camera preview: " + e2.getMessage());
                this.mdw = null;
            } catch (Throwable th) {
                this.mdw = null;
                AppMethodBeat.o(780);
            }
        }
        ab.i("MicroMsg.FaceReflectCam", "closeCamera end");
        AppMethodBeat.o(780);
    }

    public final void btX() {
        AppMethodBeat.i(781);
        if (this.mdu == null) {
            ab.i("MicroMsg.FaceReflectCam", "start camera thread");
            this.mdu = d.anM("cameraBackground");
            this.mdu.start();
            this.mdv = new ak(this.mdu.getLooper());
        }
        AppMethodBeat.o(781);
    }

    private static Point a(Parameters parameters, Point point) {
        Size previewSize;
        AppMethodBeat.i(782);
        ArrayList<Size> arrayList = new ArrayList(parameters.getSupportedPreviewSizes());
        Collections.sort(arrayList, new a((byte) 0));
        Point point2 = null;
        ab.d("MicroMsg.FaceReflectCam", "screen.x: %d, screen.y: %d, ratio: %f", new Object[]{Integer.valueOf(point.x), Integer.valueOf(point.y), Float.valueOf(((float) point.x) / ((float) point.y))});
        long gO = bo.gO(ah.getContext());
        ab.d("MicroMsg.FaceReflectCam", "systemAvailableMemInMB: %d", new Object[]{Long.valueOf(gO)});
        int i = point.x;
        i = point.y;
        float f = Float.POSITIVE_INFINITY;
        for (Size previewSize2 : arrayList) {
            int i2 = previewSize2.width;
            int i3 = previewSize2.height;
            ab.i("MicroMsg.FaceReflectCam", "realWidth: %d, realHeight: %d", new Object[]{Integer.valueOf(i2), Integer.valueOf(i3)});
            int i4 = i2 * i3;
            if (i4 >= 150400 && i4 <= 983040) {
                Object obj = i2 > i3 ? 1 : null;
                if (obj != null) {
                    i = i3;
                } else {
                    i = i2;
                }
                if (obj != null) {
                    i4 = i2;
                } else {
                    i4 = i3;
                }
                ab.d("MicroMsg.FaceReflectCam", "maybeFlippedWidth: %d, maybeFlippedHeight: %d", new Object[]{Integer.valueOf(i), Integer.valueOf(i4)});
                if (i == point.x && i4 == point.y && f(i, i4, gO)) {
                    point2 = new Point(i2, i3);
                    ab.i("MicroMsg.FaceReflectCam", "Found preview size exactly matching screen size: ".concat(String.valueOf(point2)));
                    AppMethodBeat.o(782);
                    return point2;
                }
                float abs = Math.abs((((float) i) / ((float) i4)) - r8);
                if (i2 % 10 == 0) {
                    float f2;
                    if (abs >= f || !f(i2, i3, gO)) {
                        f2 = f;
                    } else {
                        f2 = abs;
                        point2 = new Point(i2, i3);
                    }
                    ab.i("MicroMsg.FaceReflectCam", "diff:[%s] newdiff:[%s] w:[%s] h:[%s]", new Object[]{Float.valueOf(f2), Float.valueOf(abs), Integer.valueOf(i2), Integer.valueOf(i3)});
                    f = f2;
                }
            }
        }
        if (point2 == null) {
            previewSize2 = parameters.getPreviewSize();
            if (previewSize2 != null) {
                point2 = new Point(previewSize2.width, previewSize2.height);
                ab.i("MicroMsg.FaceReflectCam", "No suitable preview sizes, using default: ".concat(String.valueOf(point2)));
            } else {
                ab.e("MicroMsg.FaceReflectCam", "hy: can not find default size!!");
            }
        }
        ab.i("MicroMsg.FaceReflectCam", "Found best approximate preview size: ".concat(String.valueOf(point2)));
        AppMethodBeat.o(782);
        return point2;
    }

    private static void b(Parameters parameters) {
        AppMethodBeat.i(783);
        if (q.etc.eri > 0) {
            ab.i("MicroMsg.FaceReflectCam", "set frame rate > 0, do not try set preview fps range");
            AppMethodBeat.o(783);
            return;
        }
        List supportedPreviewFpsRange = parameters.getSupportedPreviewFpsRange();
        if (supportedPreviewFpsRange == null || supportedPreviewFpsRange.size() == 0) {
            AppMethodBeat.o(783);
            return;
        }
        int i = j.INVALID_ID;
        int i2 = j.INVALID_ID;
        Object obj = null;
        int size = supportedPreviewFpsRange.size();
        int i3 = 0;
        while (i3 < size) {
            Object obj2;
            int[] iArr = (int[]) supportedPreviewFpsRange.get(i3);
            if (iArr != null && iArr.length > 1) {
                int i4 = iArr[0];
                int i5 = iArr[1];
                ab.i("MicroMsg.FaceReflectCam", "dkfps %d:[%d %d]", new Object[]{Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i5)});
                if (i4 >= 0 && i5 >= i4) {
                    if (i5 >= i2 && obj == null) {
                        i2 = i5;
                        i = i4;
                    }
                    if (i5 >= 30000) {
                        obj2 = 1;
                        i3++;
                        obj = obj2;
                    }
                }
            }
            obj2 = obj;
            i3++;
            obj = obj2;
        }
        ab.i("MicroMsg.FaceReflectCam", "dkfps get fit  [%d %d], max target fps %d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(30)});
        if (i == Integer.MAX_VALUE || i2 == Integer.MAX_VALUE) {
            AppMethodBeat.o(783);
            return;
        }
        try {
            parameters.setPreviewFpsRange(i, i2);
            ab.i("MicroMsg.FaceReflectCam", "set fps range %d %d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
            AppMethodBeat.o(783);
        } catch (Exception e) {
            ab.i("MicroMsg.FaceReflectCam", "trySetPreviewFpsRangeParameters Exception, %s, %s", new Object[]{Looper.myLooper(), e.getMessage()});
            AppMethodBeat.o(783);
        }
    }

    private static boolean f(int i, int i2, long j) {
        AppMethodBeat.i(784);
        ab.d("MicroMsg.FaceReflectCam", "dataSizeInMB: %f, availableMemInMb: %d", new Object[]{Double.valueOf(((((((double) i) * ((double) i2)) * 3.0d) / 2.0d) / 1024.0d) / 1024.0d), Long.valueOf(j)});
        if (((double) j) / (((((((double) i) * ((double) i2)) * 3.0d) / 2.0d) / 1024.0d) / 1024.0d) >= 5.0d) {
            AppMethodBeat.o(784);
            return true;
        }
        AppMethodBeat.o(784);
        return false;
    }

    static /* synthetic */ void w(b bVar) {
        AppMethodBeat.i(787);
        bVar.faceBitmap = bVar.mdt.getBitmap();
        d.post(new 8(bVar), "saveFaceBitmap");
        AppMethodBeat.o(787);
    }
}
