@Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            Size cameraResolution = resolution;
            PreviewCallback callback = this.callback;
            if (cameraResolution != null && callback != null) {
                try {
                    if (data == null) {
                        throw new NullPointerException("No preview data received");
                    }
                    int format = camera.getParameters().getPreviewFormat();
                    SourceData source = new SourceData(data, cameraResolution.width, cameraResolution.height, format, getCameraRotation());

                    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                        source.setPreviewMirrored(true);
                    }
                    callback.onPreview(source);
                } catch (RuntimeException e) {
                    // Could be:
                    // java.lang.RuntimeException: getParameters failed (empty parameters)
                    // IllegalArgumentException: Image data does not match the resolution
                    Log.e(TAG, "Camera preview failed", e);
                    callback.onPreviewError(e);
                }
            } else {
                Log.d(TAG, "Got preview callback, but no handler or resolution available");
                if (callback != null) {
                    // Should generally not happen
                    callback.onPreviewError(new Exception("No resolution available"));
                }
            }
        }
Wrapper to manage the Camera. This is not thread-safe, and the methods must always be called
from the same thread.


Call order:

1. setCameraSettings()
2. open(), set desired preview size (any order)
3. configure(), setPreviewDisplay(holder) (any order)
4. startPreview()
5. requestPreviewFrame (repeat)
6. stopPreview()
7. close()
zxing-android-embedded/src/com/journeyapps/barcodescanner/camera/CameraManager.java