MultiCamera2

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)

MultiCamera2 multiCamera2 = new MultiCamera2(openGlView, new ConnectChecker[]{ stream1, stream2 }, new ConnectChecker[]{ stream3 });

You can set an empty array or null if you don't want use a protocol new MultiCamera2(openGlView, 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):

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

NOTE: If you call this methods nothing is executed:

multiCamera2.startStream(endpoint); multiCamera2.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

Link copied to clipboard
constructor(openGlView: OpenGlView, connectCheckerRtmpList: Array<ConnectChecker>?, connectCheckerRtspList: Array<ConnectChecker>?, connectCheckerSrtList: Array<ConnectChecker>?, connectCheckerUdpList: Array<ConnectChecker>?)
constructor(context: Context, connectCheckerRtmpList: Array<ConnectChecker>?, connectCheckerRtspList: Array<ConnectChecker>?, connectCheckerSrtList: Array<ConnectChecker>?, connectCheckerUdpList: Array<ConnectChecker>?)

Properties

Link copied to clipboard
open val bitrate: Int
Link copied to clipboard
Link copied to clipboard
open val camerasAvailable: Array<out String?>?
Link copied to clipboard
Link copied to clipboard
open var exposure: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val maxExposure: Int
Link copied to clipboard
open val minExposure: Int
Link copied to clipboard
open val opticalZooms: Array<out Float?>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val streamClient: StreamBaseClient
Link copied to clipboard
open val streamHeight: Int
Link copied to clipboard
open val streamWidth: Int
Link copied to clipboard
open val supportedFps: List<Range<Int?>?>?
Link copied to clipboard
open val whiteBalance: Int
Link copied to clipboard
open var zoom: Float
Link copied to clipboard
open val zoomRange: Range<Float?>?

Functions

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?)
Link copied to clipboard
open fun disableAudio()

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

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun disableLantern()
Link copied to clipboard
Link copied to clipboard
open fun enableAudio()

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

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun enableFaceDetection(faceDetectorCallback: FaceDetectorCallback?): Boolean
Link copied to clipboard
open fun enableFrameCaptureCallback(frameCapturedCallback: FrameCapturedCallback?)
Link copied to clipboard
open fun enableLantern()
Link copied to clipboard

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.

Link copied to clipboard

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.

Link copied to clipboard
open fun forceCodecType(codecTypeVideo: CodecUtil.CodecType?, codecTypeAudio: CodecUtil.CodecType?)
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.

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

Get supported resolutions of cameraId in px.

Link copied to clipboard
Link copied to clipboard
@RequiresApi(value = 28)
open fun openPhysicalCamera(id: String?)
Link copied to clipboard
open fun pauseRecord()
Link copied to clipboard
@RequiresApi(value = 28)
open fun physicalCamerasAvailable(): List<String?>?
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.

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.

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

Set an audio effect modifying microphone's PCM buffer.

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

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

Link copied to clipboard
open fun setFocusDistance(distance: Float)
Link copied to clipboard
Link copied to clipboard
open fun setOpticalZoom(level: Float)
Link copied to clipboard
open fun setRecordController(recordController: BaseRecordController?)
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.

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

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

Link copied to clipboard
open fun setVideoCodec(codec: VideoCodec?)
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.

Link copied to clipboard
@RequiresApi(api = 26)
open fun startRecord(@NonNull fd: FileDescriptor)
open fun startRecord(@NonNull path: String)

Starts recording a MP4 video.

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?)
Link copied to clipboard
open fun startStreamAndRecord(url: String?, path: String?)
open fun startStreamAndRecord(url: String?, path: String?, listener: RecordController.Listener?)
Link copied to clipboard
open fun stopCamera()

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

Link copied to clipboard
open fun stopPreview()

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

Link copied to clipboard
open fun stopRecord()

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

Link copied to clipboard
open fun stopStream()

Stop stream started with @startStream.

fun stopStream(type: MultiType, index: Int)
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.

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