# Camera2Base

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
abstract class Camera2Base

Wrapper to stream with camera2 api and microphone. Support stream with SurfaceView, TextureView, OpenGlView(Custom SurfaceView that use OpenGl) and Context(background mode). All views use Surface to buffer encoding mode for H264. API requirements: API 21+. Created by pedro on 7/07/17.

#### Inheritors

GenericCamera2
MultiCamera2
RtmpCamera2
RtspCamera2
SrtCamera2
UdpCamera2

## Constructors

Camera2Base
Link copied to clipboard
constructor(openGlView: OpenGlView)
constructor(context: Context)

## Properties

glInterface
Link copied to clipboard
open val glInterface: GlInterface

## 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.
getAutoWhiteBalanceModesAvailable
Link copied to clipboard
open fun getAutoWhiteBalanceModesAvailable(): List<Integer>
getBitrate
Link copied to clipboard
open fun getBitrate(): Int
getCameraCharacteristics
Link copied to clipboard
open fun getCameraCharacteristics(): CameraCharacteristics
Get supported properties of the camera
getCameraFacing
Link copied to clipboard
open fun getCameraFacing(): CameraHelper.Facing
getCamerasAvailable
Link copied to clipboard
open fun getCamerasAvailable(): Array<String>
getCurrentCameraId
Link copied to clipboard
open fun getCurrentCameraId(): String
getExposure
Link copied to clipboard
open fun getExposure(): Int
getMaxExposure
Link copied to clipboard
open fun getMaxExposure(): Int
getMinExposure
Link copied to clipboard
open fun getMinExposure(): Int
getOpticalZooms
Link copied to clipboard
open fun getOpticalZooms(): Array<Float>
getRecordStatus
Link copied to clipboard
open fun getRecordStatus(): RecordController.Status
getResolutions
Link copied to clipboard
open fun getResolutions(cameraId: String): List<Size>
Get supported resolutions of cameraId in px.
getResolutionsBack
Link copied to clipboard
open fun getResolutionsBack(): List<Size>
Get supported resolutions of back camera in px.
getResolutionsFront
Link copied to clipboard
open fun getResolutionsFront(): List<Size>
Get supported resolutions of front camera in px.
getResolutionValue
Link copied to clipboard
open fun getResolutionValue(): Int
getStreamClient
Link copied to clipboard
abstract fun getStreamClient(): StreamBaseClient
getStreamHeight
Link copied to clipboard
open fun getStreamHeight(): Int
getStreamWidth
Link copied to clipboard
open fun getStreamWidth(): Int
getSupportedFps
Link copied to clipboard
open fun getSupportedFps(): List<Range<Integer>>
open fun getSupportedFps(size: Size, facing: CameraHelper.Facing): List<Range<Integer>>
getWhiteBalance
Link copied to clipboard
open fun getWhiteBalance(): Int
getZoom
Link copied to clipboard
open fun getZoom(): Float
Return current zoom level
getZoomRange
Link copied to clipboard
open fun getZoomRange(): Range<Float>
Return zoom level range
isAudioMuted
Link copied to clipboard
open fun isAudioMuted(): Boolean
Get mute state of microphone.
isAutoExposureEnabled
Link copied to clipboard
open fun isAutoExposureEnabled(): Boolean
isAutoFocusEnabled
Link copied to clipboard
open fun isAutoFocusEnabled(): Boolean
isAutoWhiteBalanceEnabled
Link copied to clipboard
open fun isAutoWhiteBalanceEnabled(): Boolean
isFaceDetectionEnabled
Link copied to clipboard
open fun isFaceDetectionEnabled(): Boolean
isFrontCamera
Link copied to clipboard
open fun isFrontCamera(): Boolean
Use getCameraFacing instead
isLanternEnabled
Link copied to clipboard
open fun isLanternEnabled(): Boolean
isLanternSupported
Link copied to clipboard
open fun isLanternSupported(): Boolean
isOnPreview
Link copied to clipboard
open fun isOnPreview(): Boolean
Get preview state.
isOpticalVideoStabilizationEnabled
Link copied to clipboard
open fun isOpticalVideoStabilizationEnabled(): Boolean
isRecording
Link copied to clipboard
open fun isRecording(): Boolean
Get record state.
isStreaming
Link copied to clipboard
open fun isStreaming(): Boolean
Get stream state.
isVideoStabilizationEnabled
Link copied to clipboard
open fun isVideoStabilizationEnabled(): Boolean
openPhysicalCamera
Link copied to clipboard
@RequiresApi(value = Build.VERSION_CODES.P)
open fun openPhysicalCamera(id: String)
pauseRecord
Link copied to clipboard
open fun pauseRecord()
physicalCamerasAvailable
Link copied to clipboard
@RequiresApi(value = Build.VERSION_CODES.P)
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.
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.
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
setExposure
Link copied to clipboard
open fun setExposure(value: Int)
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.
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)
setZoom
Link copied to clipboard
open fun setZoom(event: MotionEvent)
open fun setZoom(level: Float)
Set zoomIn or zoomOut to camera.
open fun setZoom(event: MotionEvent, delta: Float)
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.
startRecord
Link copied to clipboard
@RequiresApi(api = Build.VERSION_CODES.O)
open fun startRecord(@NonNull fd: FileDescriptor)
open fun startRecord(@NonNull path: String)
@RequiresApi(api = Build.VERSION_CODES.O)
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.
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.
stopRecord
Link copied to clipboard
open fun stopRecord()
Stop record MP4 video started with @startRecord.
stopStream
Link copied to clipboard
open fun stopStream()
Stop stream started with @startStream.
switchCamera
Link copied to clipboard
open fun switchCamera()
Switch camera used.
open fun switchCamera(cameraId: String)
Choose a specific camera to use.
tapToFocus
Link copied to clipboard
open fun tapToFocus(view: View, event: MotionEvent): Boolean