Package 

Class CameraEngine

  • All Implemented Interfaces:
    com.otaliastudios.cameraview.picture.PictureRecorder.PictureResultListener , com.otaliastudios.cameraview.preview.CameraPreview.SurfaceCallback , com.otaliastudios.cameraview.video.VideoRecorder.VideoResultListener

    
    public abstract class CameraEngine
     implements CameraPreview.SurfaceCallback, PictureRecorder.PictureResultListener, VideoRecorder.VideoResultListener
                        

    PROCESS Setting up the Camera is usually a 4 steps process: 1. Setting up the Surface. Done by CameraPreview. 2. Starting the camera. Done by us. See startEngine, onStartEngine. 3. Binding the camera to the surface. Done by us. See startBind, onStartBind 4. Streaming the camera preview. Done by us. See startPreview, onStartPreview The first two steps can actually happen at the same time, anyway the order is not guaranteed, we just get a callback from the Preview when 1 happens. So at the end of both step 1 and 2, the engine should check if both have been performed and trigger the steps 3 and 4. STATE We only expose generic start and stop calls to the outside. The external users of this class are most likely interested in whether we have completed step 2 or not, since that tells us if we can act on the camera or not, rather than knowing about steps 3 and 4. So in the CameraEngine notation, - start: ASYNC - starts the engine (S2). When possible, at a later time, S3 and S4 are also performed. - stop: ASYNC - stops everything: undoes S4, then S3, then S2. - restart: ASYNC - completes a stop then a start. - destroy: SYNC - performs a stop that will go on no matter what, without throwing. Makes the engine unusable and clears resources. THREADING Subclasses should always execute code on the thread given by mHandler. For convenience, all the setup and tear down methods are called on this engine thread: onStartEngine, onStartBind, onStartPreview to setup and onStopEngine, onStopBind, onStopPreview to tear down. However, these methods are not forced to be synchronous and then can simply return a Google's Task. Other setters are executed on the callers thread so subclasses should make sure they post to the engine handler before acting on themselves. ERROR HANDLING THe mHandler thread has a special Thread.UncaughtExceptionHandler that handles exceptions and dispatches error to the callback (instead of crashing the app). This lets subclasses run code safely and directly throw CameraExceptions when needed. For convenience, the two main method onStartEngine and onStopEngine are already called on the engine thread, but they can still be asynchronous by returning a Google's com.google.android.gms.tasks.Task.