// Path: app/src/main/java/org/yeshen/video/librtmp/App.java
// public class App extends Application {
// 
//     public static App ins;
// 
//     public static App getInstance() {
//         return ins;
//     }
// 
//     public static Context getContext() {
//         return ins.getApplicationContext();
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ins = this;
//     }
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/Cameras.java
// public static class CameraMessage {
// 
//     public static final int FACING_FRONT = 1;
//     public static final int FACING_BACK = 2;
// 
//     public int cameraID;            //camera的id
//     public int cameraFacing;        //区分前后摄像头
//     public int cameraWidth;         //camera的宽度
//     public int cameraHeight;        //camera的高度
//     public boolean hasLight;
//     public int orientation;
//     public boolean supportTouchFocus;
//     public boolean touchFocusMode;
// 
//     public CameraMessage(int id, int facing) {
//         cameraID = id;
//         cameraFacing = facing;
//     }
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/CameraDisabledException.java
// public class CameraDisabledException extends Exception{
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/CameraNotSupportException.java
// public class CameraNotSupportException extends Exception {
// 
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/NoCameraException.java
// public class NoCameraException extends Exception {
// }


import android.annotation.TargetApi;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaFormat;
import android.media.MediaRecorder;
import android.opengl.EGL14;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.os.Build;
import org.yeshen.video.librtmp.App;
import org.yeshen.video.librtmp.unstable.Cameras.CameraMessage;
import org.yeshen.video.librtmp.unstable.exception.CameraDisabledException;
import org.yeshen.video.librtmp.unstable.exception.CameraNotSupportException;
import org.yeshen.video.librtmp.unstable.exception.NoCameraException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
                    cameraDatas.add(cameraData);
                } else {
                    cameraDatas.add(0, cameraData);
                }
            } else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                CameraMessage cameraData = new CameraMessage(i, CameraMessage.FACING_BACK);
                if(isBackFirst) {
                    cameraDatas.add(0, cameraData);
                } else {
                    cameraDatas.add(cameraData);
                }
            }
        }
        return cameraDatas;
    }

    public static void initCameraParams(Camera camera, CameraMessage cameraData, boolean isTouchMode)
            throws CameraNotSupportException {
        boolean isLandscape = (Options.getInstance().camera.orientation != Options.Orientation.PORTRAIT);
        int cameraWidth = Math.max(Options.getInstance().camera.height, Options.getInstance().camera.width);
        int cameraHeight = Math.min(Options.getInstance().camera.height, Options.getInstance().camera.width);
        Camera.Parameters parameters = camera.getParameters();
        setPreviewFormat(camera, parameters);
        setPreviewFps(camera, Options.getInstance().camera.fps, parameters);
        setPreviewSize(camera, cameraData, cameraWidth, cameraHeight, parameters);
        cameraData.hasLight = supportFlash(camera);
        setOrientation(cameraData, isLandscape, camera);
        setFocusMode(camera, cameraData, isTouchMode);
    }

// Path: app/src/main/java/org/yeshen/video/librtmp/App.java
// public class App extends Application {
// 
//     public static App ins;
// 
//     public static App getInstance() {
//         return ins;
//     }
// 
//     public static Context getContext() {
//         return ins.getApplicationContext();
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ins = this;
//     }
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/Cameras.java
// public static class CameraMessage {
// 
//     public static final int FACING_FRONT = 1;
//     public static final int FACING_BACK = 2;
// 
//     public int cameraID;            //camera的id
//     public int cameraFacing;        //区分前后摄像头
//     public int cameraWidth;         //camera的宽度
//     public int cameraHeight;        //camera的高度
//     public boolean hasLight;
//     public int orientation;
//     public boolean supportTouchFocus;
//     public boolean touchFocusMode;
// 
//     public CameraMessage(int id, int facing) {
//         cameraID = id;
//         cameraFacing = facing;
//     }
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/CameraDisabledException.java
// public class CameraDisabledException extends Exception{
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/CameraNotSupportException.java
// public class CameraNotSupportException extends Exception {
// 
// }
// 
// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/exception/NoCameraException.java
// public class NoCameraException extends Exception {
// }


// Path: app/src/main/java/org/yeshen/video/librtmp/unstable/tools/AndroidUntil.java
import android.annotation.TargetApi;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaFormat;
import android.media.MediaRecorder;
import android.opengl.EGL14;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.os.Build;
import org.yeshen.video.librtmp.App;
import org.yeshen.video.librtmp.unstable.Cameras.CameraMessage;
import org.yeshen.video.librtmp.unstable.exception.CameraDisabledException;
import org.yeshen.video.librtmp.unstable.exception.CameraNotSupportException;
import org.yeshen.video.librtmp.unstable.exception.NoCameraException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;

                    cameraDatas.add(cameraData);
                } else {
                    cameraDatas.add(0, cameraData);
                }
            } else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                CameraMessage cameraData = new CameraMessage(i, CameraMessage.FACING_BACK);
                if(isBackFirst) {
                    cameraDatas.add(0, cameraData);
                } else {
                    cameraDatas.add(cameraData);
                }
            }
        }
        return cameraDatas;
    }

    public static void initCameraParams(Camera camera, CameraMessage cameraData, boolean isTouchMode)
            throws CameraNotSupportException {
        boolean isLandscape = (Options.getInstance().camera.orientation != Options.Orientation.PORTRAIT);
        int cameraWidth = Math.max(Options.getInstance().camera.height, Options.getInstance().camera.width);
        int cameraHeight = Math.min(Options.getInstance().camera.height, Options.getInstance().camera.width);
        Camera.Parameters parameters = camera.getParameters();
        setPreviewFormat(camera, parameters);
        setPreviewFps(camera, Options.getInstance().camera.fps, parameters);
        setPreviewSize(camera, cameraData, cameraWidth, cameraHeight, parameters);
        cameraData.hasLight = supportFlash(camera);
        setOrientation(cameraData, isLandscape, camera);
        setFocusMode(camera, cameraData, isTouchMode);
    }

    public static void setPreviewFormat(Camera camera, Camera.Parameters parameters) throws CameraNotSupportException{