# GenericCamera2

@RequiresApi(api = 21)
class GenericCamera2 : Camera2Base

Created by Ernovation on 9/11/21.

## Constructors

GenericCamera2
Link copied to clipboard
constructor(openGlView: OpenGlView, connectChecker: ConnectChecker)
constructor(context: Context, connectChecker: ConnectChecker)

## Properties

autoWhiteBalanceModesAvailable
Link copied to clipboard
open val autoWhiteBalanceModesAvailable: List<Int?>?
bitrate
Link copied to clipboard
open val bitrate: Int
cameraCharacteristics
Link copied to clipboard
open val cameraCharacteristics: CameraCharacteristics?
cameraFacing
Link copied to clipboard
open val cameraFacing: CameraHelper.Facing?
camerasAvailable
Link copied to clipboard
open val camerasAvailable: Array<out String?>?
currentCameraId
Link copied to clipboard
open val currentCameraId: String?
exposure
Link copied to clipboard
open var exposure: Int
glInterface
Link copied to clipboard
open val glInterface: GlInterface?
isAudioMuted
Link copied to clipboard
open val isAudioMuted: Boolean
isAutoExposureEnabled
Link copied to clipboard
open val isAutoExposureEnabled: Boolean
isAutoFocusEnabled
Link copied to clipboard
open val isAutoFocusEnabled: Boolean
isAutoWhiteBalanceEnabled
Link copied to clipboard
open val isAutoWhiteBalanceEnabled: Boolean
isFaceDetectionEnabled
Link copied to clipboard
open val isFaceDetectionEnabled: Boolean
isFrontCamera
Link copied to clipboard
open val isFrontCamera: Boolean
isLanternEnabled
Link copied to clipboard
open val isLanternEnabled: Boolean
isLanternSupported
Link copied to clipboard
open val isLanternSupported: Boolean
isOnPreview
Link copied to clipboard
open val isOnPreview: Boolean
isOpticalVideoStabilizationEnabled
Link copied to clipboard
open val isOpticalVideoStabilizationEnabled: Boolean
isRecording
Link copied to clipboard
open val isRecording: Boolean
isStreaming
Link copied to clipboard
open val isStreaming: Boolean
isVideoStabilizationEnabled
Link copied to clipboard
open val isVideoStabilizationEnabled: Boolean
maxExposure
Link copied to clipboard
open val maxExposure: Int
minExposure
Link copied to clipboard
open val minExposure: Int
opticalZooms
Link copied to clipboard
open val opticalZooms: Array<out Float?>?
recordStatus
Link copied to clipboard
open val recordStatus: RecordController.Status?
resolutionsBack
Link copied to clipboard
open val resolutionsBack: List<Size?>?
resolutionsFront
Link copied to clipboard
open val resolutionsFront: List<Size?>?
resolutionValue
Link copied to clipboard
open val resolutionValue: Int
streamClient
Link copied to clipboard
open override val streamClient: GenericStreamClient
streamHeight
Link copied to clipboard
open val streamHeight: Int
streamWidth
Link copied to clipboard
open val streamWidth: Int
supportedFps
Link copied to clipboard
open val supportedFps: List<Range<Int?>?>?
whiteBalance
Link copied to clipboard
open val whiteBalance: Int
zoom
Link copied to clipboard
open var zoom: Float
zoomRange
Link copied to clipboard
open val zoomRange: Range<Float?>?

## Functions

addImageListener
Link copied to clipboard
open fun addImageListener(format: Int, maxImages: Int, listener: Camera2ApiManager.ImageCallback?)
open fun addImageListener(width: Int, height: Int, format: Int, maxImages: Int, listener: Camera2ApiManager.ImageCallback?)
open fun addImageListener(width: Int, height: Int, format: Int, maxImages: Int, autoClose: Boolean, listener: Camera2ApiManager.ImageCallback?)
disableAudio
Link copied to clipboard
open fun disableAudio()

Mute microphone, can be called before, while and after stream.

disableAutoExposure
Link copied to clipboard
open fun disableAutoExposure()
disableAutoFocus
Link copied to clipboard
open fun disableAutoFocus(): Boolean
disableAutoWhiteBalance
Link copied to clipboard
open fun disableAutoWhiteBalance()
disableFaceDetection
Link copied to clipboard
open fun disableFaceDetection()
disableLantern
Link copied to clipboard
open fun disableLantern()
disableOpticalVideoStabilization
Link copied to clipboard
open fun disableOpticalVideoStabilization()
disableVideoStabilization
Link copied to clipboard
open fun disableVideoStabilization()
enableAudio
Link copied to clipboard
open fun enableAudio()

Enable a muted microphone, can be called before, while and after stream.

enableAutoExposure
Link copied to clipboard
open fun enableAutoExposure(): Boolean
enableAutoFocus
Link copied to clipboard
open fun enableAutoFocus(): Boolean
enableAutoWhiteBalance
Link copied to clipboard
open fun enableAutoWhiteBalance(mode: Int): Boolean
enableFaceDetection
Link copied to clipboard
open fun enableFaceDetection(faceDetectorCallback: FaceDetectorCallback?): Boolean
enableFrameCaptureCallback
Link copied to clipboard
open fun enableFrameCaptureCallback(frameCapturedCallback: FrameCapturedCallback?)
enableLantern
Link copied to clipboard
open fun enableLantern()
enableOpticalVideoStabilization
Link copied to clipboard
open fun enableOpticalVideoStabilization(): Boolean

Enable OIS video stabilization Warning: Turning both OIS and EIS modes on may produce undesirable interaction, so it is recommended not to enable both at the same time.

enableVideoStabilization
Link copied to clipboard
open fun enableVideoStabilization(): Boolean

Enable EIS video stabilization Warning: Turning both OIS and EIS modes on may produce undesirable interaction, so it is recommended not to enable both at the same time.

forceBt709Color
Link copied to clipboard
open fun forceBt709Color(enabled: Boolean)
forceCodecType
Link copied to clipboard
open fun forceCodecType(codecTypeVideo: CodecUtil.CodecType?, codecTypeAudio: CodecUtil.CodecType?)
forceFpsLimit
Link copied to clipboard
open fun forceFpsLimit(enabled: Boolean)

Force stream to work with fps selected in prepareVideo method. Must be called before prepareVideo. This is not recommend because could produce fps problems.

getResolutions
Link copied to clipboard
open fun getResolutions(cameraId: String?): List<Size?>?

Get supported resolutions of cameraId in px.

getStreamClient
Link copied to clipboard
open override fun getStreamClient(): GenericStreamClient
openPhysicalCamera
Link copied to clipboard
@RequiresApi(value = 28)
open fun openPhysicalCamera(id: String?)
pauseRecord
Link copied to clipboard
open fun pauseRecord()
physicalCamerasAvailable
Link copied to clipboard
@RequiresApi(value = 28)
open fun physicalCamerasAvailable(): List<String?>?
prepareAudio
Link copied to clipboard
open fun prepareAudio(): Boolean

Same to call: prepareAudio(64 * 1024, 32000, true, false, false);

open fun prepareAudio(bitrate: Int, sampleRate: Int, isStereo: Boolean): Boolean
open fun prepareAudio(bitrate: Int, sampleRate: Int, isStereo: Boolean, echoCanceler: Boolean, noiseSuppressor: Boolean): Boolean
open fun prepareAudio(audioSource: Int, bitrate: Int, sampleRate: Int, isStereo: Boolean, echoCanceler: Boolean, noiseSuppressor: Boolean): Boolean

Call this method before use @startStream. If not you will do a stream without audio.

prepareVideo
Link copied to clipboard
open fun prepareVideo(): Boolean

Same to call: isHardwareRotation = true; if (openGlVIew) isHardwareRotation = false; prepareVideo(640, 480, 30, 1200 * 1024, isHardwareRotation, 90);

open fun prepareVideo(width: Int, height: Int, bitrate: Int): Boolean
open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, iFrameInterval: Int, rotation: Int): Boolean
open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, iFrameInterval: Int, rotation: Int, profile: Int, level: Int): Boolean
open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, rotation: Int): Boolean

backward compatibility reason

open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, iFrameInterval: Int, rotation: Int, profile: Int, level: Int, recordWidth: Int, recordHeight: Int, recordBitrate: Int): Boolean

Call this method before use @startStream. If not you will do a stream without video.

removeImageListener
Link copied to clipboard
open fun removeImageListener()
replaceView
Link copied to clipboard
open fun replaceView(context: Context?)
open fun replaceView(openGlView: OpenGlView?)
requestKeyFrame
Link copied to clipboard
open fun requestKeyFrame()
resetAudioEncoder
Link copied to clipboard
open fun resetAudioEncoder(): Boolean
resetVideoEncoder
Link copied to clipboard
open fun resetVideoEncoder(): Boolean
resumeRecord
Link copied to clipboard
open fun resumeRecord()
setAudioCodec
Link copied to clipboard
open fun setAudioCodec(codec: AudioCodec?)
setCameraCallbacks
Link copied to clipboard
open fun setCameraCallbacks(callbacks: CameraCallbacks?)
setColorCorrectionGains
Link copied to clipboard
open fun setColorCorrectionGains(red: Float, greenEven: Float, greenOdd: Float, blue: Float): Boolean
setCustomAudioEffect
Link copied to clipboard
open fun setCustomAudioEffect(customAudioEffect: CustomAudioEffect?)

Set an audio effect modifying microphone's PCM buffer.

setEncoderErrorCallback
Link copied to clipboard
open fun setEncoderErrorCallback(encoderErrorCallback: CodecErrorCallback?)

Set a callback to know errors related with Video/Audio encoders

setFocusDistance
Link copied to clipboard
open fun setFocusDistance(distance: Float)
setFpsListener
Link copied to clipboard
open fun setFpsListener(callback: FpsListener.Callback?)
setOpticalZoom
Link copied to clipboard
open fun setOpticalZoom(level: Float)
setRecordController
Link copied to clipboard
open fun setRecordController(recordController: RecordController?)
setTimestampMode
Link copied to clipboard
open fun setTimestampMode(timestampModeVideo: TimestampMode?, timestampModeAudio: TimestampMode?)

Set the mode to calculate timestamp. By default CLOCK. Must be called before startRecord/startStream or it will be ignored.

setVideoBitrateOnFly
Link copied to clipboard
open fun setVideoBitrateOnFly(bitrate: Int)

Set video bitrate of H264 in bits per second while stream.

setVideoCodec
Link copied to clipboard
open fun setVideoCodec(codec: VideoCodec?)
startPreview
Link copied to clipboard
open fun startPreview()
open fun startPreview(cameraFacing: CameraHelper.Facing?)
open fun startPreview(cameraId: String?)
open fun startPreview(cameraFacing: CameraHelper.Facing?, rotation: Int)
open fun startPreview(width: Int, height: Int)
open fun startPreview(cameraId: String?, rotation: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int)
open fun startPreview(cameraId: String?, width: Int, height: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int, rotation: Int)
open fun startPreview(cameraId: String?, width: Int, height: Int, rotation: Int)
open fun startPreview(cameraId: String?, width: Int, height: Int, fps: Int, rotation: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int, fps: Int, rotation: Int)

Start camera preview. Ignored, if stream or preview is started.

startRecord
Link copied to clipboard
@RequiresApi(api = 26)
open fun startRecord(@NonNull fd: FileDescriptor)
open fun startRecord(@NonNull path: String)
@RequiresApi(api = 26)
open fun startRecord(@NonNull fd: FileDescriptor, @Nullable listener: RecordController.Listener?)
open fun startRecord(@NonNull path: String, @Nullable listener: RecordController.Listener?)

Starts recording a MP4 video.

startStream
Link copied to clipboard
open fun startStream(url: String?)

Need be called after @prepareVideo or/and @prepareAudio. This method override resolution of

startStreamAndRecord
Link copied to clipboard
open fun startStreamAndRecord(url: String?, path: String?)
open fun startStreamAndRecord(url: String?, path: String?, listener: RecordController.Listener?)
stopCamera
Link copied to clipboard
open fun stopCamera()

Similar to stopPreview but you can do it while streaming or recording.

stopPreview
Link copied to clipboard
open fun stopPreview()

Stop camera preview. Ignored if streaming or already stopped. You need call it after

stopRecord
Link copied to clipboard
open fun stopRecord()

Stop record MP4 video started with @startRecord. If you don't call it file will be unreadable.

stopStream
Link copied to clipboard
open fun stopStream()

Stop stream started with @startStream.

switchCamera
Link copied to clipboard
open fun switchCamera()

Switch camera used. Can be called anytime

open fun switchCamera(cameraId: String?)

Choose a specific camera to use. Can be called anytime.

tapToFocus
Link copied to clipboard
open fun tapToFocus(view: View?, event: MotionEvent?): Boolean