# MultiCamera1

class MultiCamera1 : Camera1Base

Created by pedro on 21/5/21.

Experiment class.

Support multiple streams in rtmp and rtsp at same time. You must set the same number of ConnectChecker that you want use.

For example. 2 RTMP and 1 RTSP: stream1, stream2, stream3 (stream1 and stream2 are ConnectChecker for RTMP. stream3 is ConnectChecker for RTSP)

MultiCamera1 multiCamera1 = new MultiCamera1(surfaceView, new ConnectChecker[]{ stream1, stream2 }, new ConnectChecker[]{ stream3 });

You can set an empty array or null if you don't want use a protocol new MultiCamera1(surfaceView, new ConnectChecker[]{ stream1, stream2 }, null); //RTSP protocol is not used

In order to use start, stop and other calls you must send type of stream and index to execute it. Example (using previous example interfaces):

multiCamera1.startStream(MultiType.RTMP, 1, endpoint); //stream2 is started multiCamera1.stopStream(MultiType.RTSP, 0); //stream3 is stopped multiCamera1.getStreamClient(MultiType.RTMP, 0).retry(delay, reason, backupUrl) //retry stream1

NOTE: If you call this methods nothing is executed:

multiCamera1.startStream(endpoint); multiCamera1.stopStream();

The rest of methods without MultiType and index means that you will execute that command in all streams. Read class code if you need info about any method.

## Constructors

MultiCamera1
Link copied to clipboard
constructor(surfaceView: SurfaceView, connectCheckerRtmpList: Array<ConnectChecker>? = null, connectCheckerRtspList: Array<ConnectChecker>? = null, connectCheckerSrtList: Array<ConnectChecker>? = null, connectCheckerUdpList: Array<ConnectChecker>? = null)
constructor(textureView: TextureView, connectCheckerRtmpList: Array<ConnectChecker>? = null, connectCheckerRtspList: Array<ConnectChecker>? = null, connectCheckerSrtList: Array<ConnectChecker>? = null, connectCheckerUdpList: Array<ConnectChecker>? = null)
@RequiresApi(value = 18)
constructor(openGlView: OpenGlView, connectCheckerRtmpList: Array<ConnectChecker>? = null, connectCheckerRtspList: Array<ConnectChecker>? = null, connectCheckerSrtList: Array<ConnectChecker>? = null, connectCheckerUdpList: Array<ConnectChecker>? = null)
@RequiresApi(value = 18)
constructor(context: Context, connectCheckerRtmpList: Array<ConnectChecker>? = null, connectCheckerRtspList: Array<ConnectChecker>? = null, connectCheckerSrtList: Array<ConnectChecker>? = null, connectCheckerUdpList: Array<ConnectChecker>? = null)

## Properties

autoWhiteBalanceModesAvailable
Link copied to clipboard
open val autoWhiteBalanceModesAvailable: List<String?>?
bitrate
Link copied to clipboard
open val bitrate: Int
cameraFacing
Link copied to clipboard
open val cameraFacing: CameraHelper.Facing?
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
isAutoFocusEnabled
Link copied to clipboard
open val isAutoFocusEnabled: 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
isOnPreview
Link copied to clipboard
open val isOnPreview: 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
maxZoom
Link copied to clipboard
open val maxZoom: Int
minExposure
Link copied to clipboard
open val minExposure: Int
minZoom
Link copied to clipboard
open val minZoom: Int
recordStatus
Link copied to clipboard
open val recordStatus: RecordController.Status?
resolutionsBack
Link copied to clipboard
open val resolutionsBack: List<Camera.Size?>?
resolutionsFront
Link copied to clipboard
open val resolutionsFront: List<Camera.Size?>?
resolutionValue
Link copied to clipboard
open val resolutionValue: Int
streamClient
Link copied to clipboard
open override val streamClient: StreamBaseClient
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<IntArray?>?
whiteBalance
Link copied to clipboard
open val whiteBalance: String?
zoom
Link copied to clipboard
open val zoom: Float

## Functions

disableAudio
Link copied to clipboard
open fun disableAudio()

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

disableAutoFocus
Link copied to clipboard
open fun disableAutoFocus(): Boolean
disableFaceDetection
Link copied to clipboard
open fun disableFaceDetection()
disableLantern
Link copied to clipboard
open fun disableLantern()
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.

enableAutoFocus
Link copied to clipboard
open fun enableAutoFocus(): Boolean
enableAutoWhiteBalance
Link copied to clipboard
open fun enableAutoWhiteBalance(mode: String?): Boolean
enableFaceDetection
Link copied to clipboard
open fun enableFaceDetection(faceDetectorCallback: FaceDetectorCallback?): Boolean
enableLantern
Link copied to clipboard
open fun enableLantern()
enableVideoStabilization
Link copied to clipboard
open fun enableVideoStabilization(): Boolean
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.

getStreamClient
Link copied to clipboard
open override fun getStreamClient(): StreamBaseClient
fun getStreamClient(type: MultiType, index: Int): StreamBaseClient
pauseRecord
Link copied to clipboard
open fun pauseRecord()
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: rotation = 0; if (Portrait) rotation = 90; prepareVideo(640, 480, 30, 1200 * 1024, false, rotation);

open fun prepareVideo(width: Int, height: Int, bitrate: Int): Boolean
open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, rotation: Int): Boolean
open fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, iFrameInterval: 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): Boolean

Call this method before use @startStream. If not you will do a stream without video. NOTE: Rotation with encoder is silence ignored in some devices.

replaceView
Link copied to clipboard
@RequiresApi(api = 18)
open fun replaceView(context: Context?)
@RequiresApi(api = 18)
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?)
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

setFpsListener
Link copied to clipboard
open fun setFpsListener(callback: FpsListener.Callback?)
setPreviewOrientation
Link copied to clipboard
open fun setPreviewOrientation(orientation: Int)

Change preview orientation can be called while stream.

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
@RequiresApi(api = 19)
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?)

Set zoomIn or zoomOut to camera.

open fun setZoom(level: Int)

Set zoomIn or zoomOut to camera. Use this method if you use a zoom slider.

open fun setZoom(event: MotionEvent?, delta: Int)
startPreview
Link copied to clipboard
open fun startPreview()
open fun startPreview(cameraFacing: CameraHelper.Facing?)
open fun startPreview(cameraFacing: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, rotation: Int)
open fun startPreview(width: Int, height: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int)
open fun startPreview(cameraFacing: Int, width: Int, height: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int, rotation: Int)
open fun startPreview(cameraFacing: Int, width: Int, height: Int, rotation: Int)
open fun startPreview(cameraFacing: CameraHelper.Facing?, width: Int, height: Int, fps: Int, rotation: Int)
open fun startPreview(cameraId: Int, 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)
@RequiresApi(api = 18)
open fun startRecord(@NonNull path: String)
@RequiresApi(api = 26)
open fun startRecord(@NonNull fd: FileDescriptor, @Nullable listener: RecordController.Listener?)
@RequiresApi(api = 18)
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

fun startStream(type: MultiType, index: Int, url: String?)
startStreamAndRecord
Link copied to clipboard
@RequiresApi(api = 18)
open fun startStreamAndRecord(url: String?, path: String?)
@RequiresApi(api = 18)
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
@RequiresApi(api = 18)
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.

fun stopStream(type: MultiType, index: Int)
switchCamera
Link copied to clipboard
open fun switchCamera()

Switch camera used. Can be called anytime

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