package com.he.lynx;

import X.2FV;
import X.2He;
import X.3GY;
import X.4Sh;
import X.7s1;
import X.8e1;
import X.8e2;
import X.8eG;
import X.8eL;
import X.8jA;
import android.content.ClipboardManager;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Pair;
import android.util.Size;
import android.view.Surface;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.librarian.Librarian;
import com.he.lynx.HeliumApp;
import com.he.lynx.loader.MediaLoader;
import com.he.lynx.player.IHeliumPlayer;
import com.lynx.tasm.base.LLog;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;

public class Helium {
    public static final int AUDIO = 8;
    public static final int VIDEO = 4;
    public static boolean cameraPermission = true;
    public static double[] euler = new double[4];
    public static Sensor gyroscopeSensor;
    public static volatile boolean helium_loaded;
    public static SensorEventListener orientationListener = new 1();
    public static final Set<IHeliumPlayer> players = new CopyOnWriteArraySet();
    public static Sensor rotationSensor;
    public static SensorManager sensorManager;

    public static native void _screenshot(long j, int i, int i2, ByteBuffer byteBuffer);

    public static native long addView(long j, Surface surface);

    public static native void cleanup(long j);

    public static Sensor com_he_lynx_Helium_android_hardware_SensorManager_getDefaultSensor(SensorManager sensorManager2, int i) {
        3GY.LIZ(100703);
        SensorManager sensorManager3 = sensorManager2;
        Pair LIZ = 3GY.LIZ((Object) null, sensorManager3, new Object[]{Integer.valueOf(i)}, 100703, "android.hardware.Sensor", false, 138867210, 2);
        return ((Boolean) LIZ.first).booleanValue() ? (Sensor) LIZ.second : sensorManager3.getDefaultSensor(i);
    }

    public static native void dispatch(long j, ByteBuffer byteBuffer);

    public static native void doFrame(long j);

    public static native void flushRecord(long j, long j2);

    public static String getMiniAppSoPluginDir() {
        return null;
    }

    public static native void onMediaRequest(long j, Object obj, String str);

    public static native void onMediaStatusChange(long j, int i);

    public static native void onPause(long j);

    public static native void onRecordRequest(long j, Object obj);

    public static native void onResume(long j);

    public static native void onSurfaceChanged(long j, long j2, int i, int i2);

    public static native void onSurfaceCreated(long j, long j2, Surface surface);

    public static native void onSurfaceDestroyed(long j, long j2);

    public static native String preloadLiteEffectModules();

    public static native void sendGyroscopeData(float f, float f2, float f3, long j);

    public static native void sendOrientationData(float f, float f2, float f3, float f4, long j);

    public static native void setLiteExternalEffectLibraryPath(String str);

    public static native void setSensitivePermissionStatus(int i, boolean z);

    public static native void setupEngine(int i, int i2);

    public static native long setupLite(float f, HeliumApp heliumApp, long j, long[] jArr, AssetManager assetManager, String str, boolean z, boolean z2);

    public static native long startRecord(long j, long j2, Surface surface, int i, ByteBuffer byteBuffer, int i2, int i3, float f, float f2, float f3, float f4);

    public static void startRecord(HeliumApp heliumApp, BaseCameraContext baseCameraContext, String str, int i, int i2, boolean z) {
    }

    public static native void stopAudioCapture(long j);

    public static native void stopRecord(long j, long j2);

    public static class HostCameraContext extends BaseCameraContext {
        public final IPlatformCamera hostCamera;
        public int pageID;

        static {
            Covode.recordClassIndex(45628);
        }

        private void autoFocus() {
            IPlatformCamera iPlatformCamera = this.hostCamera;
            if (iPlatformCamera != null) {
                iPlatformCamera.autoFocus();
            }
        }

        public void release() {
            IPlatformCamera iPlatformCamera = this.hostCamera;
            if (iPlatformCamera != null) {
                iPlatformCamera.dispose();
            }
            if (this.texture != null) {
                this.texture.release();
                this.texture = null;
            }
        }

        private void onSurfaceTextureReady(SurfaceTexture surfaceTexture) {
            IPlatformCamera iPlatformCamera = this.hostCamera;
            if (iPlatformCamera != null) {
                iPlatformCamera.onSurfaceTextureReady(surfaceTexture);
            }
        }

        public void pause(HeliumApp.StateCallback.CallType callType) {
            IPlatformCamera iPlatformCamera = this.hostCamera;
            if (iPlatformCamera != null) {
                iPlatformCamera.pause(callType);
            }
        }

        public void resume(HeliumApp.StateCallback.CallType callType) {
            IPlatformCamera iPlatformCamera = this.hostCamera;
            if (iPlatformCamera != null) {
                iPlatformCamera.resume(callType);
            }
        }

        public static HostCameraContext requestHostCameraCtx(int i, HeliumApp.PlatformCameraFactory platformCameraFactory, int i2) {
            boolean z;
            boolean z2;
            boolean z3;
            if ((i & 1) != 0) {
                z = true;
            } else {
                z = false;
            }
            if ((i & 2) != 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            if ((i & 96) != 0) {
                z3 = true;
            } else {
                z3 = false;
            }
            IPlatformCamera createPlatformCamera = platformCameraFactory.createPlatformCamera();
            createPlatformCamera.request(z, z2, z3, 0, i2);
            Size cameraResolution = createPlatformCamera.getCameraResolution();
            return new HostCameraContext(cameraResolution.getWidth(), cameraResolution.getHeight(), createPlatformCamera, i2);
        }

        public void setMediaState(HeliumApp heliumApp, int i, long j) {
            int i2 = i & 15;
            if (i2 == 0) {
                release();
                heliumApp.resumables.remove(this);
            } else if (i2 == 1) {
                int i3 = (i >> 8) & 16777215;
                if (i3 != 0) {
                    this.texture = new SurfaceTexture(i3);
                    onSurfaceTextureReady(this.texture);
                }
                resume(HeliumApp.StateCallback.CallType.JSBridge);
                heliumApp.resumables.add(this);
            } else if (i2 == 2) {
                pause(HeliumApp.StateCallback.CallType.JSBridge);
                heliumApp.resumables.remove(this);
            } else if (i2 == 6) {
                this.texture.updateTexImage();
                this.s_timestamp = this.texture.getTimestamp();
            } else if (i2 == 7) {
                autoFocus();
            }
        }

        public HostCameraContext(int i, int i2, IPlatformCamera iPlatformCamera, int i3) {
            super(i, i2);
            this.hostCamera = iPlatformCamera;
            this.pageID = i3;
        }
    }

    public static void stopSensors() {
        sensorManager.unregisterListener(orientationListener);
    }

    public static void setupEngine() {
        MethodCollector.i(6622);
        setupEngine(0, 1);
        MethodCollector.o(6622);
    }

    public static class PlayerContext extends VideoContext implements IHeliumPlayer.IHeliumPlayerListener {
        public final HeliumApp app;
        public boolean isComplete;
        public boolean isPaused;
        public boolean loop;
        public IHeliumPlayer player;
        public Surface surface;
        public final Uri uri;
        public float volume;

        static {
            Covode.recordClassIndex(45629);
        }

        public boolean onError(IHeliumPlayer iHeliumPlayer, Object obj) {
            return false;
        }

        public float getCurrentTime() {
            IHeliumPlayer iHeliumPlayer = this.player;
            if (iHeliumPlayer != null && !this.isComplete) {
                return ((float) iHeliumPlayer.getCurrentPosition()) / 1000.0f;
            }
            return 0.0f;
        }

        public void release() {
            IHeliumPlayer iHeliumPlayer = this.player;
            if (iHeliumPlayer != null) {
                iHeliumPlayer.release();
                this.player = null;
            }
            Surface surface2 = this.surface;
            if (surface2 != null) {
                surface2.release();
                this.surface = null;
            }
            if (this.texture != null) {
                this.texture.release();
                this.texture = null;
            }
        }

        public void onPrepared(IHeliumPlayer iHeliumPlayer) {
            try {
                if (!this.isPaused) {
                    iHeliumPlayer.play();
                }
            } catch (IllegalStateException unused) {
            }
        }

        public void pause(HeliumApp.StateCallback.CallType callType) {
            this.isPaused = true;
            IHeliumPlayer iHeliumPlayer = this.player;
            if (iHeliumPlayer != null) {
                try {
                    iHeliumPlayer.pause();
                } catch (IllegalStateException unused) {
                }
            }
        }

        public void onRenderStart(IHeliumPlayer iHeliumPlayer) {
            MethodCollector.i(7508);
            if (this._ptr != 0) {
                Helium.onMediaStatusChange(this._ptr, 2);
            }
            MethodCollector.o(7508);
        }

        public void onSeekComplete(IHeliumPlayer iHeliumPlayer) {
            MethodCollector.i(7695);
            if (this._ptr != 0) {
                Helium.onMediaStatusChange(this._ptr, 3);
            }
            MethodCollector.o(7695);
        }

        public void onCompletion(IHeliumPlayer iHeliumPlayer) {
            MethodCollector.i(7697);
            if (this.loop) {
                try {
                    if (!iHeliumPlayer.isPlaying() && !this.isPaused) {
                        iHeliumPlayer.play();
                    }
                    iHeliumPlayer.seekTo(0);
                } catch (IllegalStateException unused) {
                }
            } else {
                this.isComplete = true;
            }
            if (this._ptr != 0) {
                Helium.onMediaStatusChange(this._ptr, 1);
            }
            MethodCollector.o(7697);
        }

        public void resume(HeliumApp.StateCallback.CallType callType) {
            this.isPaused = false;
            IHeliumPlayer iHeliumPlayer = this.player;
            if (iHeliumPlayer == null) {
                IHeliumPlayer createPlayer = this.app.createPlayer();
                this.player = createPlayer;
                try {
                    createPlayer.setDataSource(this.uri.toString());
                } catch (Exception unused) {
                }
                this.player.setListener(this);
                this.player.prepare();
                this.player.setSurface(this.surface);
                return;
            }
            iHeliumPlayer.setSurface(this.surface);
            IHeliumPlayer iHeliumPlayer2 = this.player;
            float f = this.volume;
            iHeliumPlayer2.setVolume(f, f);
            if (HeliumApp.StateCallback.CallType.SystemCall != callType || !this.isComplete || this.loop) {
                try {
                    this.player.play();
                } catch (IllegalStateException unused2) {
                }
                this.isComplete = false;
                this.player.setListener(this);
            }
        }

        public void setMediaState(HeliumApp heliumApp, int i, long j) {
            int i2 = i & 15;
            boolean z = false;
            if (i2 == 1) {
                this.isPaused = false;
                int i3 = i >> 8;
                if (i3 != 0) {
                    this.texture = new SurfaceTexture(i3 & 16777215);
                    this.surface = new Surface(this.texture);
                }
                if ((i & 128) != 0) {
                    z = true;
                }
                this.loop = z;
                this.volume = (float) Double.longBitsToDouble(j);
            } else if (i2 == 2) {
                this.isPaused = true;
            } else if (i2 == 4) {
                if ((i & 128) != 0) {
                    z = true;
                }
                this.loop = z;
                IHeliumPlayer iHeliumPlayer = this.player;
                if (iHeliumPlayer != null) {
                    try {
                        iHeliumPlayer.seekTo((int) (Double.longBitsToDouble(j) * 1000.0d));
                    } catch (IllegalStateException unused) {
                    }
                }
            } else if (i2 == 5) {
                float longBitsToDouble = (float) Double.longBitsToDouble(j);
                this.volume = longBitsToDouble;
                IHeliumPlayer iHeliumPlayer2 = this.player;
                if (iHeliumPlayer2 != null) {
                    iHeliumPlayer2.setVolume(longBitsToDouble, longBitsToDouble);
                }
            } else if (i2 == 11) {
                if ((i & 128) != 0) {
                    z = true;
                }
                this.loop = z;
            }
            super.setMediaState(heliumApp, i, j);
        }

        public PlayerContext(HeliumApp heliumApp, Uri uri2, IHeliumPlayer iHeliumPlayer, int i) {
            super(iHeliumPlayer.getVideoWidth(), iHeliumPlayer.getVideoHeight(), iHeliumPlayer.getDuration(), i);
            this.app = heliumApp;
            this.uri = uri2;
            this.player = iHeliumPlayer;
        }
    }

    static {
        Covode.recordClassIndex(45621);
    }

    public static ExecutorService INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newSingleThreadExecutor() {
        8e1 LIZ = 8e2.LIZ(8eG.FIXED);
        LIZ.LIZJ = 1;
        return 8eL.LIZ(LIZ.LIZ());
    }

    public static float getCurrentTime(PlayerContext playerContext) {
        return playerContext.getCurrentTime();
    }

    public static void INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_LoadSoLancet_loadLibrary(String str) {
        long uptimeMillis = SystemClock.uptimeMillis();
        Librarian.LIZ(str);
        4Sh.LIZ(uptimeMillis, str);
    }

    public static String getInstallPath(HeliumApp heliumApp) {
        return heliumApp.context.getApplicationInfo().nativeLibraryDir;
    }

    public static void initSensors(HeliumApp heliumApp) {
        SensorManager sensorManager2 = (SensorManager) INVOKEVIRTUAL_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_GetSystemServiceLancet_getSystemService(heliumApp.context, "sensor");
        sensorManager = sensorManager2;
        gyroscopeSensor = com_he_lynx_Helium_android_hardware_SensorManager_getDefaultSensor(sensorManager2, 4);
        rotationSensor = com_he_lynx_Helium_android_hardware_SensorManager_getDefaultSensor(sensorManager, 15);
    }

    public static void onFatalError(String str) {
        LLog.LIZ(6, "HeliumLynx", "onFatalError ".concat(String.valueOf(str)));
        if (HeliumApp.fatalErrorHandler != null) {
            HeliumApp.fatalErrorHandler.handle(str);
        }
    }

    public static void onUncaughtException(String str) {
        LLog.LIZ(6, "HeliumLynx", "onUncaughtException ".concat(String.valueOf(str)));
        if (HeliumApp.uncaughtExceptionHandler != null) {
            HeliumApp.uncaughtExceptionHandler.handle(str);
        }
    }

    public static long getTimeStamp(BaseCameraContext baseCameraContext) {
        long nanoTime = System.nanoTime();
        long abs = Math.abs(nanoTime - baseCameraContext.s_timestamp);
        long abs2 = Math.abs(SystemClock.elapsedRealtimeNanos() - baseCameraContext.s_timestamp);
        return nanoTime - Math.min(Math.min(abs, abs2), Math.abs((SystemClock.uptimeMillis() * 1000000) - baseCameraContext.s_timestamp));
    }

    public static boolean startSensors(int i) {
        sensorManager.unregisterListener(orientationListener);
        if (!sensorManager.registerListener(orientationListener, rotationSensor, i) || !sensorManager.registerListener(orientationListener, gyroscopeSensor, i)) {
            return false;
        }
        return true;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:11:0x0042, code lost:
        if (r3 != null) goto L_0x0044;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int getVideoRoration(java.lang.String r7) {
        /*
            java.lang.String r5 = "HeliumLynx"
            r6 = 0
            r4 = 0
            android.media.MediaMetadataRetriever r3 = new android.media.MediaMetadataRetriever     // Catch:{ Exception -> 0x002c }
            r3.<init>()     // Catch:{ Exception -> 0x002c }
            if (r7 == 0) goto L_0x0013
            java.util.HashMap r0 = new java.util.HashMap     // Catch:{ Exception -> 0x002e }
            r0.<init>()     // Catch:{ Exception -> 0x002e }
            r3.setDataSource(r7, r0)     // Catch:{ Exception -> 0x002e }
        L_0x0013:
            r0 = 24
            java.lang.String r0 = r3.extractMetadata(r0)     // Catch:{ Exception -> 0x002e }
            int r6 = java.lang.Integer.parseInt(r0)     // Catch:{ Exception -> 0x002e }
            java.lang.String r1 = "rotation = "
            java.lang.String r0 = java.lang.String.valueOf(r6)     // Catch:{ Exception -> 0x002e }
            java.lang.String r1 = r1.concat(r0)     // Catch:{ Exception -> 0x002e }
            r0 = 3
            com.lynx.tasm.base.LLog.LIZ(r0, r5, r1)     // Catch:{ Exception -> 0x002e }
            goto L_0x0044
        L_0x002c:
            r2 = move-exception
            goto L_0x0030
        L_0x002e:
            r2 = move-exception
            r4 = r3
        L_0x0030:
            java.lang.String r1 = java.lang.String.valueOf(r2)
            java.lang.String r0 = "getVideoRoration MediaMetadataRetriever exception "
            java.lang.String r1 = r0.concat(r1)
            r0 = 6
            com.lynx.tasm.base.LLog.LIZ(r0, r5, r1)
            X.0HH.LIZ(r2)
            r3 = r4
            if (r3 == 0) goto L_0x0047
        L_0x0044:
            r3.release()     // Catch:{ Exception -> 0x0047 }
        L_0x0047:
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: com.he.lynx.Helium.getVideoRoration(java.lang.String):int");
    }

    public static boolean loadHelium(String str) {
        boolean z;
        MethodCollector.i(6442);
        if (helium_loaded) {
            MethodCollector.o(6442);
            return true;
        }
        synchronized (Helium.class) {
            try {
                if (!helium_loaded) {
                    if (str != null) {
                        System.load(str);
                    } else {
                        INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_LoadSoLancet_loadLibrary("lynx_helium");
                    }
                    helium_loaded = true;
                }
            } catch (Throwable th) {
                MethodCollector.o(6442);
                throw th;
            }
            z = helium_loaded;
        }
        MethodCollector.o(6442);
        return z;
    }

    public static abstract class BaseCameraContext extends VideoContext {
        static {
            Covode.recordClassIndex(45627);
        }

        public boolean startRecord(HeliumApp heliumApp, String str, int i, int i2, boolean z) {
            return false;
        }

        public void stopRecord(long j, BaseCameraContext baseCameraContext) {
        }

        public BaseCameraContext(int i, int i2) {
            super(i, i2, 0, 0);
        }
    }

    public static void onMediaRequest(long j, Object obj) {
        MethodCollector.i(7249);
        onMediaRequest(j, obj, "");
        MethodCollector.o(7249);
    }

    public static Object INVOKEVIRTUAL_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_GetSystemServiceLancet_getSystemService(ContextWrapper contextWrapper, String str) {
        Object obj;
        MethodCollector.i(8025);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = contextWrapper.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = contextWrapper.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = contextWrapper.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(8025);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = contextWrapper.getSystemService(str);
        }
        MethodCollector.o(8025);
        return obj;
    }

    public static abstract class VideoContext implements HeliumApp.StateCallback {
        public long _ptr;
        public final int duration;
        public final int height;
        public final int rotation;
        public long s_timestamp;
        public SurfaceTexture texture;
        public final int width;

        static {
            Covode.recordClassIndex(45630);
        }

        public abstract void release();

        public void setMediaState(HeliumApp heliumApp, int i, long j) {
            int i2 = i & 15;
            if (i2 == 0) {
                release();
                heliumApp.resumables.remove(this);
            } else if (i2 == 1) {
                resume(HeliumApp.StateCallback.CallType.JSBridge);
                heliumApp.resumables.add(this);
            } else if (i2 == 2) {
                pause(HeliumApp.StateCallback.CallType.JSBridge);
                heliumApp.resumables.remove(this);
            } else if (i2 == 6) {
                this.texture.updateTexImage();
                this.s_timestamp = this.texture.getTimestamp();
            }
        }

        public VideoContext(int i, int i2, int i3, int i4) {
            this.width = i;
            this.height = i2;
            this.duration = i3;
            this.rotation = i4;
        }
    }

    public static void loadMedia(HeliumApp heliumApp, String str, long j) {
        final HeliumApp heliumApp2 = heliumApp;
        if (heliumApp2.mediaLoader != null) {
            final Uri loadMedia = heliumApp2.mediaLoader.loadMedia(str);
            final long j2 = j;
            if (loadMedia == null) {
                onMediaRequest(j2, (Object) null);
                return;
            }
            final IHeliumPlayer createPlayer = heliumApp2.createPlayer();
            players.add(createPlayer);
            final AnonymousClass1MediaListener r2 = new IHeliumPlayer.IHeliumPlayerListener() {
                public PlayerContext handle;
                public boolean hasCallbacked;
                public boolean hasRotation;
                public boolean prepared;
                public int rotation;

                static {
                    Covode.recordClassIndex(45624);
                }

                public final void onCompletion(IHeliumPlayer iHeliumPlayer) {
                }

                public final void onRenderStart(IHeliumPlayer iHeliumPlayer) {
                }

                public final void onSeekComplete(IHeliumPlayer iHeliumPlayer) {
                }

                private void checkPrepared() {
                    if (this.prepared && this.hasRotation) {
                        PlayerContext playerContext = new PlayerContext(heliumApp2, loadMedia, createPlayer, this.rotation);
                        this.handle = playerContext;
                        callback(j2, playerContext);
                    }
                }

                public final void setRotation(int i) {
                    if (!this.hasRotation) {
                        this.hasRotation = true;
                        this.rotation = i;
                        checkPrepared();
                    }
                }

                public final void onPrepared(IHeliumPlayer iHeliumPlayer) {
                    if (!this.prepared) {
                        iHeliumPlayer.setListener((IHeliumPlayer.IHeliumPlayerListener) null);
                        Helium.players.remove(iHeliumPlayer);
                        this.prepared = true;
                        checkPrepared();
                    }
                }

                private void callback(long j, Object obj) {
                    if (!this.hasCallbacked) {
                        Helium.onMediaRequest(j, obj);
                        this.hasCallbacked = true;
                    }
                }

                public final boolean onError(IHeliumPlayer iHeliumPlayer, Object obj) {
                    iHeliumPlayer.setListener((IHeliumPlayer.IHeliumPlayerListener) null);
                    Helium.players.remove(iHeliumPlayer);
                    iHeliumPlayer.release();
                    callback(j2, this.handle);
                    return true;
                }
            };
            ExecutorService INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newSingleThreadExecutor = INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newSingleThreadExecutor();
            INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newSingleThreadExecutor.execute(new Runnable() {
                static {
                    Covode.recordClassIndex(45625);
                }

                public final void run() {
                    final int videoRoration = Helium.getVideoRoration(loadMedia.toString());
                    heliumApp2.dispatchToJSThread(new Runnable() {
                        static {
                            Covode.recordClassIndex(45626);
                        }

                        public void run() {
                            r2.setRotation(videoRoration);
                        }
                    });
                }
            });
            INVOKESTATIC_com_he_lynx_Helium_com_ss_android_ugc_aweme_lancet_thread_ThreadPoolLancet_newSingleThreadExecutor.shutdown();
            createPlayer.setListener(r2);
            try {
                createPlayer.setDataSource(loadMedia.toString());
            } catch (Exception unused) {
            }
            createPlayer.prepare();
        }
    }

    public static void setMediaState(HeliumApp heliumApp, VideoContext videoContext, int i, long j) {
        videoContext.setMediaState(heliumApp, i, j);
    }

    public static void onMonitor(int i, int i2, int i3, String str) {
        if (i == 1) {
            LLog.LIZ(6, "HeliumLynx", "!!! Aurum init fail: ".concat(String.valueOf(str)));
        } else if (i == 2) {
            LLog.LIZ(6, "HeliumLynx", "!!! Effect load fail: ".concat(String.valueOf(str)));
        }
    }

    public static void requestMedia(HeliumApp heliumApp, int i, int i2, long j) {
        boolean z;
        boolean z2;
        MediaLoader.FacingMode facingMode;
        final HeliumApp heliumApp2 = heliumApp;
        if (heliumApp2.mediaLoader != null) {
            MediaLoader.RequestParams requestParams = new MediaLoader.RequestParams();
            final int i3 = i;
            boolean z3 = false;
            if ((i3 & 8) != 0) {
                z = true;
            } else {
                z = false;
            }
            requestParams.audio = z;
            if ((i3 & 4) != 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            requestParams.video = z2;
            if ((i3 & 272) != 0) {
                z3 = true;
            }
            requestParams.effect = z3;
            if ((i3 & 1) != 0) {
                facingMode = MediaLoader.FacingMode.ENVIRONMENT;
            } else {
                facingMode = MediaLoader.FacingMode.USER;
            }
            requestParams.facingMode = facingMode;
            final long j2 = j;
            final int i4 = i2;
            heliumApp2.mediaLoader.onRequest(requestParams, new MediaLoader.Responder() {
                public boolean called;

                static {
                    Covode.recordClassIndex(45623);
                }

                public void onResponse(boolean z) {
                    Object obj;
                    MethodCollector.i(7506);
                    if (this.called) {
                        MethodCollector.o(7506);
                        return;
                    }
                    this.called = true;
                    if (!z) {
                        Helium.onMediaRequest(j2, (Object) null, "no authorization");
                        MethodCollector.o(7506);
                    } else if ((i3 & 4) == 0) {
                        Helium.onMediaRequest(j2, heliumApp2);
                        MethodCollector.o(7506);
                    } else {
                        try {
                            HeliumApp.PlatformCameraFactory platformCameraFactory = heliumApp2.getPlatformCameraFactory();
                            if (platformCameraFactory != null) {
                                LLog.LIZ(5, "HeliumLynx", "Use Host Camera with pageID = " + i4);
                                obj = HostCameraContext.requestHostCameraCtx(i3, platformCameraFactory, i4);
                            } else {
                                LLog.LIZ(5, "HeliumLynx", "Use Helium Camera");
                                try {
                                    obj = (BaseCameraContext) Class.forName("com.he.lynx.player.HeliumCameraContext").getMethod("requestCamera", new Class[]{Integer.TYPE}).invoke((Object) null, new Object[]{Integer.valueOf(i3)});
                                } catch (Throwable th) {
                                    LLog.LIZ(5, "HeliumLynx", "No Helium Camera " + th.toString());
                                    Helium.onMediaRequest(j2, (Object) null, th.getMessage());
                                    MethodCollector.o(7506);
                                    return;
                                }
                            }
                            if (obj != null) {
                                heliumApp2.resumables.add(obj);
                                Helium.onMediaRequest(j2, obj);
                                MethodCollector.o(7506);
                                return;
                            }
                            Helium.onMediaRequest(j2, (Object) null, "unknown error");
                            MethodCollector.o(7506);
                        } catch (IllegalStateException e) {
                            Helium.onMediaRequest(j2, (Object) null, e.getMessage());
                            MethodCollector.o(7506);
                        } catch (Throwable th2) {
                            LLog.LIZ(5, "HeliumLynx", "No Helium Camera " + th2.toString());
                            Helium.onMediaRequest(j2, (Object) null, th2.getMessage());
                            MethodCollector.o(7506);
                        }
                    }
                }
            });
        }
    }

    public static byte[] encodeBitmap(ByteBuffer byteBuffer, int i, int i2, int i3, int i4) {
        Bitmap.CompressFormat compressFormat;
        MethodCollector.i(8248);
        Bitmap createBitmap = Bitmap.createBitmap(i2, i3, Bitmap.Config.ARGB_8888);
        createBitmap.copyPixelsFromBuffer(byteBuffer);
        if (i == 1) {
            compressFormat = Bitmap.CompressFormat.JPEG;
        } else if (i == 2) {
            compressFormat = Bitmap.CompressFormat.WEBP;
        } else {
            compressFormat = Bitmap.CompressFormat.PNG;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(((i2 * i3) / 4) + 256);
        if (createBitmap.compress(compressFormat, i4, byteArrayOutputStream)) {
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            MethodCollector.o(8248);
            return byteArray;
        }
        MethodCollector.o(8248);
        return null;
    }
}
