-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceCameraEngine.Callback
-
Method Summary
Modifier and Type Method Description final CameraStategetState()final CameraStategetTargetState()final booleanisChangingState()voiddestroy(boolean unrecoverably)Calls stop and waits for it.Not final due to mockito requirements.If unrecoverably is true, this also releases resources and the engine will not be in afunctional state after. voidrestart()Task<Void>start()Task<Void>stop(boolean swallowExceptions)final voidonSurfaceAvailable()The surface is now available, which means that step 1 has completed.If we have also completed step 2, go on with binding and streaming. final voidonSurfaceDestroyed()Called when the surface was destroyed. abstract AnglesgetAngles()abstract FrameManagergetFrameManager()abstract CameraOptionsgetCameraOptions()abstract SizegetPictureSize(@NonNull() Reference reference)abstract SizegetVideoSize(@NonNull() Reference reference)abstract SizegetPreviewStreamSize(@NonNull() Reference reference)abstract SizegetUncroppedSnapshotSize(@NonNull() Reference reference)abstract voidsetPreview(@NonNull() CameraPreview cameraPreview)abstract CameraPreviewgetPreview()abstract voidsetOverlay(@Nullable() Overlay overlay)abstract OverlaygetOverlay()abstract voidsetPreviewStreamSizeSelector(@Nullable() SizeSelector selector)abstract SizeSelectorgetPreviewStreamSizeSelector()abstract voidsetPictureSizeSelector(@NonNull() SizeSelector selector)abstract SizeSelectorgetPictureSizeSelector()abstract voidsetVideoSizeSelector(@NonNull() SizeSelector selector)abstract SizeSelectorgetVideoSizeSelector()abstract voidsetVideoMaxSize(long videoMaxSizeBytes)abstract longgetVideoMaxSize()abstract voidsetVideoMaxDuration(int videoMaxDurationMillis)abstract intgetVideoMaxDuration()abstract voidsetVideoCodec(@NonNull() VideoCodec codec)abstract VideoCodecgetVideoCodec()abstract voidsetVideoBitRate(int videoBitRate)abstract intgetVideoBitRate()abstract voidsetAudioBitRate(int audioBitRate)abstract intgetAudioBitRate()abstract voidsetAudioCodec(@NonNull() AudioCodec codec)abstract AudioCodecgetAudioCodec()abstract voidsetSnapshotMaxWidth(int maxWidth)abstract intgetSnapshotMaxWidth()abstract voidsetSnapshotMaxHeight(int maxHeight)abstract intgetSnapshotMaxHeight()abstract voidsetFrameProcessingMaxWidth(int maxWidth)abstract intgetFrameProcessingMaxWidth()abstract voidsetFrameProcessingMaxHeight(int maxHeight)abstract intgetFrameProcessingMaxHeight()abstract voidsetFrameProcessingFormat(int format)abstract intgetFrameProcessingFormat()abstract voidsetFrameProcessingPoolSize(int poolSize)abstract intgetFrameProcessingPoolSize()abstract voidsetAutoFocusResetDelay(long delayMillis)abstract longgetAutoFocusResetDelay()abstract voidsetFacing(@NonNull() Facing facing)abstract FacinggetFacing()abstract voidsetAudio(@NonNull() Audio audio)abstract AudiogetAudio()abstract voidsetMode(@NonNull() Mode mode)abstract ModegetMode()abstract voidsetZoom(float zoom, @Nullable() Array<PointF> points, boolean notify)abstract floatgetZoomValue()abstract voidsetExposureCorrection(float EVvalue, @NonNull() Array<float> bounds, @Nullable() Array<PointF> points, boolean notify)abstract floatgetExposureCorrectionValue()abstract voidsetFlash(@NonNull() Flash flash)abstract FlashgetFlash()abstract voidsetWhiteBalance(@NonNull() WhiteBalance whiteBalance)abstract WhiteBalancegetWhiteBalance()abstract voidsetHdr(@NonNull() Hdr hdr)abstract HdrgetHdr()abstract voidsetLocation(@Nullable() Location location)abstract LocationgetLocation()abstract voidsetPictureFormat(@NonNull() PictureFormat pictureFormat)abstract PictureFormatgetPictureFormat()abstract voidsetPreviewFrameRateExact(boolean previewFrameRateExact)abstract booleangetPreviewFrameRateExact()abstract voidsetPreviewFrameRate(float previewFrameRate)abstract floatgetPreviewFrameRate()abstract voidsetHasFrameProcessors(boolean hasFrameProcessors)abstract booleanhasFrameProcessors()abstract voidsetPictureMetering(boolean enable)abstract booleangetPictureMetering()abstract voidsetPictureSnapshotMetering(boolean enable)abstract booleangetPictureSnapshotMetering()abstract voidstartAutoFocus(@Nullable() Gesture gesture, @NonNull() MeteringRegions regions, @NonNull() PointF legacyPoint)abstract voidsetPlaySounds(boolean playSounds)abstract booleanisTakingPicture()abstract voidtakePicture(@NonNull() PictureResult.Stub stub)abstract voidtakePictureSnapshot(@NonNull() PictureResult.Stub stub)abstract booleanisTakingVideo()abstract voidtakeVideo(@NonNull() VideoResult.Stub stub, @Nullable() File file, @Nullable() FileDescriptor fileDescriptor)abstract voidtakeVideoSnapshot(@NonNull() VideoResult.Stub stub, @NonNull() File file)abstract voidstopVideo()-
Methods inherited from class com.otaliastudios.cameraview.preview.CameraPreview.SurfaceCallback
onSurfaceChanged -
Methods inherited from class com.otaliastudios.cameraview.picture.PictureRecorder.PictureResultListener
onPictureResult, onPictureShutter -
Methods inherited from class com.otaliastudios.cameraview.video.VideoRecorder.VideoResultListener
onVideoRecordingEnd, onVideoRecordingStart, onVideoResult -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getState
@NonNull() final CameraState getState()
-
getTargetState
@NonNull() final CameraState getTargetState()
-
isChangingState
final boolean isChangingState()
-
destroy
void destroy(boolean unrecoverably)
Calls stop and waits for it.Not final due to mockito requirements.If unrecoverably is true, this also releases resources and the engine will not be in afunctional state after. If forever is false, this really is just a synchronous stop.NOTE: Should not be called on the orchestrator thread! This would cause deadlocks due to usawaiting for stop to return.
-
restart
void restart()
-
onSurfaceAvailable
final void onSurfaceAvailable()
The surface is now available, which means that step 1 has completed.If we have also completed step 2, go on with binding and streaming.
-
onSurfaceDestroyed
final void onSurfaceDestroyed()
Called when the surface was destroyed.
-
getFrameManager
@NonNull() abstract FrameManager getFrameManager()
-
getCameraOptions
@Nullable() abstract CameraOptions getCameraOptions()
-
getPictureSize
@Nullable() abstract Size getPictureSize(@NonNull() Reference reference)
-
getVideoSize
@Nullable() abstract Size getVideoSize(@NonNull() Reference reference)
-
getPreviewStreamSize
@Nullable() abstract Size getPreviewStreamSize(@NonNull() Reference reference)
-
getUncroppedSnapshotSize
@Nullable() abstract Size getUncroppedSnapshotSize(@NonNull() Reference reference)
-
setPreview
abstract void setPreview(@NonNull() CameraPreview cameraPreview)
-
getPreview
@Nullable() abstract CameraPreview getPreview()
-
setOverlay
abstract void setOverlay(@Nullable() Overlay overlay)
-
getOverlay
@Nullable() abstract Overlay getOverlay()
-
setPreviewStreamSizeSelector
abstract void setPreviewStreamSizeSelector(@Nullable() SizeSelector selector)
-
getPreviewStreamSizeSelector
@Nullable() abstract SizeSelector getPreviewStreamSizeSelector()
-
setPictureSizeSelector
abstract void setPictureSizeSelector(@NonNull() SizeSelector selector)
-
getPictureSizeSelector
@NonNull() abstract SizeSelector getPictureSizeSelector()
-
setVideoSizeSelector
abstract void setVideoSizeSelector(@NonNull() SizeSelector selector)
-
getVideoSizeSelector
@NonNull() abstract SizeSelector getVideoSizeSelector()
-
setVideoMaxSize
abstract void setVideoMaxSize(long videoMaxSizeBytes)
-
getVideoMaxSize
abstract long getVideoMaxSize()
-
setVideoMaxDuration
abstract void setVideoMaxDuration(int videoMaxDurationMillis)
-
getVideoMaxDuration
abstract int getVideoMaxDuration()
-
setVideoCodec
abstract void setVideoCodec(@NonNull() VideoCodec codec)
-
getVideoCodec
@NonNull() abstract VideoCodec getVideoCodec()
-
setVideoBitRate
abstract void setVideoBitRate(int videoBitRate)
-
getVideoBitRate
abstract int getVideoBitRate()
-
setAudioBitRate
abstract void setAudioBitRate(int audioBitRate)
-
getAudioBitRate
abstract int getAudioBitRate()
-
setAudioCodec
abstract void setAudioCodec(@NonNull() AudioCodec codec)
-
getAudioCodec
@NonNull() abstract AudioCodec getAudioCodec()
-
setSnapshotMaxWidth
abstract void setSnapshotMaxWidth(int maxWidth)
-
getSnapshotMaxWidth
abstract int getSnapshotMaxWidth()
-
setSnapshotMaxHeight
abstract void setSnapshotMaxHeight(int maxHeight)
-
getSnapshotMaxHeight
abstract int getSnapshotMaxHeight()
-
setFrameProcessingMaxWidth
abstract void setFrameProcessingMaxWidth(int maxWidth)
-
getFrameProcessingMaxWidth
abstract int getFrameProcessingMaxWidth()
-
setFrameProcessingMaxHeight
abstract void setFrameProcessingMaxHeight(int maxHeight)
-
getFrameProcessingMaxHeight
abstract int getFrameProcessingMaxHeight()
-
setFrameProcessingFormat
abstract void setFrameProcessingFormat(int format)
-
getFrameProcessingFormat
abstract int getFrameProcessingFormat()
-
setFrameProcessingPoolSize
abstract void setFrameProcessingPoolSize(int poolSize)
-
getFrameProcessingPoolSize
abstract int getFrameProcessingPoolSize()
-
setAutoFocusResetDelay
abstract void setAutoFocusResetDelay(long delayMillis)
-
getAutoFocusResetDelay
abstract long getAutoFocusResetDelay()
-
getZoomValue
abstract float getZoomValue()
-
setExposureCorrection
abstract void setExposureCorrection(float EVvalue, @NonNull() Array<float> bounds, @Nullable() Array<PointF> points, boolean notify)
-
getExposureCorrectionValue
abstract float getExposureCorrectionValue()
-
setWhiteBalance
abstract void setWhiteBalance(@NonNull() WhiteBalance whiteBalance)
-
getWhiteBalance
@NonNull() abstract WhiteBalance getWhiteBalance()
-
setLocation
abstract void setLocation(@Nullable() Location location)
-
getLocation
@Nullable() abstract Location getLocation()
-
setPictureFormat
abstract void setPictureFormat(@NonNull() PictureFormat pictureFormat)
-
getPictureFormat
@NonNull() abstract PictureFormat getPictureFormat()
-
setPreviewFrameRateExact
abstract void setPreviewFrameRateExact(boolean previewFrameRateExact)
-
getPreviewFrameRateExact
abstract boolean getPreviewFrameRateExact()
-
setPreviewFrameRate
abstract void setPreviewFrameRate(float previewFrameRate)
-
getPreviewFrameRate
abstract float getPreviewFrameRate()
-
setHasFrameProcessors
abstract void setHasFrameProcessors(boolean hasFrameProcessors)
-
hasFrameProcessors
abstract boolean hasFrameProcessors()
-
setPictureMetering
abstract void setPictureMetering(boolean enable)
-
getPictureMetering
abstract boolean getPictureMetering()
-
setPictureSnapshotMetering
abstract void setPictureSnapshotMetering(boolean enable)
-
getPictureSnapshotMetering
abstract boolean getPictureSnapshotMetering()
-
startAutoFocus
abstract void startAutoFocus(@Nullable() Gesture gesture, @NonNull() MeteringRegions regions, @NonNull() PointF legacyPoint)
-
setPlaySounds
abstract void setPlaySounds(boolean playSounds)
-
isTakingPicture
abstract boolean isTakingPicture()
-
takePicture
abstract void takePicture(@NonNull() PictureResult.Stub stub)
-
takePictureSnapshot
abstract void takePictureSnapshot(@NonNull() PictureResult.Stub stub)
-
isTakingVideo
abstract boolean isTakingVideo()
-
takeVideo
abstract void takeVideo(@NonNull() VideoResult.Stub stub, @Nullable() File file, @Nullable() FileDescriptor fileDescriptor)
-
takeVideoSnapshot
abstract void takeVideoSnapshot(@NonNull() VideoResult.Stub stub, @NonNull() File file)
-
stopVideo
abstract void stopVideo()
-
-
-
-