SingleStreamer

open class SingleStreamer(val context: Context, val withAudio: Boolean = true, val withVideo: Boolean = true, endpointFactory: IEndpointInternal.Factory = DynamicEndpointFactory(), defaultRotation: Int = context.displayRotation) : ISingleStreamer, IAudioSingleStreamer, IVideoSingleStreamer

A ISingleStreamer implementation for audio and video.

Parameters

context

the application context

withAudio

Boolean.true to capture audio. It can't be changed after instantiation.

withVideo

Boolean.true to capture video. It can't be changed after instantiation.

endpointFactory

the IEndpointInternal.Factory implementation. By default, it is a DynamicEndpointFactory.

defaultRotation

the default rotation in Surface rotation (Surface.ROTATION_0, ...). By default, it is the current device orientation.

Constructors

Link copied to clipboard
constructor(context: Context, withAudio: Boolean = true, withVideo: Boolean = true, endpointFactory: IEndpointInternal.Factory = DynamicEndpointFactory(), defaultRotation: Int = context.displayRotation)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val audioConfigFlow: StateFlow<AudioConfig?>

The audio configuration flow.

Link copied to clipboard
open override val audioEncoder: IEncoder?

Advanced settings for the audio encoder.

Link copied to clipboard

Advanced settings for the audio processor.

Link copied to clipboard
open override val audioSourceFlow: StateFlow<IAudioSource?>

The audio source. It allows advanced audio source settings.

Link copied to clipboard
protected val context: Context
Link copied to clipboard
open override val endpoint: IEndpoint

Advanced settings for the endpoint.

Link copied to clipboard
open override val info: IConfigurationInfo

Gets configuration information.

Link copied to clipboard
open override val isOpenFlow: StateFlow<Boolean>

Returns true if output is opened. For example, if the streamer is connected to a server if the endpoint is SRT or RTMP.

Link copied to clipboard

Whether the video source has a preview.

Link copied to clipboard
open override val isStreamingFlow: StateFlow<Boolean>

Returns true if stream is running.

Link copied to clipboard
open override val throwableFlow: StateFlow<Throwable?>

Returns the last throwable that occurred.

Link copied to clipboard
open override val videoConfigFlow: StateFlow<VideoConfig?>

The video configuration flow.

Link copied to clipboard
open override val videoEncoder: IEncoder?

Advanced settings for the video encoder.

Link copied to clipboard
open override val videoSourceFlow: StateFlow<IVideoSource?>

The video source. It allows advanced video source settings.

Link copied to clipboard
val withAudio: Boolean = true
Link copied to clipboard
val withVideo: Boolean = true

Functions

Link copied to clipboard

Adds a bitrate regulator controller.

Link copied to clipboard
open suspend override fun close()

Closes the streamer endpoint.

Link copied to clipboard
open override fun getInfo(descriptor: MediaDescriptor): IConfigurationInfo

Gets configuration information from MediaDescriptor.

Link copied to clipboard
open suspend override fun open(descriptor: MediaDescriptor)

Opens the streamer endpoint.

Link copied to clipboard
suspend fun IOpenableStreamer.open(uri: Uri)
suspend fun IOpenableStreamer.open(uriString: String)

Opens the streamer endpoint.

Link copied to clipboard
open suspend override fun release()

Releases the streamer.

Link copied to clipboard

Clean and reset the streamer synchronously.

Link copied to clipboard

Removes the bitrate regulator controller.

Link copied to clipboard

Sets activity result from ComponentActivity.registerForActivityResult callback.

Link copied to clipboard
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
open suspend override fun setAudioConfig(audioConfig: AudioConfig)

Configures audio settings. It is the first method to call after a SingleStreamer instantiation. It must be call when both stream and audio capture are not running.

Link copied to clipboard
open suspend override fun setAudioSource(audioSourceFactory: IAudioSourceInternal.Factory)

Sets the audio source.

Link copied to clipboard
@RequiresPermission(value = "android.permission.CAMERA")
suspend fun IWithVideoSource.setCameraId(cameraId: String)

Sets the camera id.

Link copied to clipboard
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
suspend fun setConfig(audioConfig: AudioConfig, videoConfig: VideoConfig)

Configures both video and audio settings. It is the first method to call after a SingleStreamer instantiation. It must be call when both stream and audio and video capture are not running.

Link copied to clipboard
suspend fun IWithVideoSource.setPreview(surface: Surface)

Sets the preview surface.

suspend fun IWithVideoSource.setPreview(surfaceHolder: SurfaceHolder)

Sets a preview surface holder.

suspend fun IWithVideoSource.setPreview(surfaceView: SurfaceView)
suspend fun IWithVideoSource.setPreview(textureView: TextureView)

Sets a preview surface.

Link copied to clipboard
open suspend override fun setTargetRotation(rotation: Int)

Sets the target rotation.

Link copied to clipboard
open suspend override fun setVideoConfig(videoConfig: VideoConfig)

Configures video settings. It is the first method to call after a SingleStreamer instantiation. It must be call when both stream and video capture are not running.

Link copied to clipboard
open suspend override fun setVideoSource(videoSourceFactory: IVideoSourceInternal.Factory)

Sets the video source.

Link copied to clipboard

Starts video preview.

suspend fun IWithVideoSource.startPreview(surface: Surface)
@RequiresPermission(value = "android.permission.CAMERA")
suspend fun IWithVideoSource.startPreview(surfaceHolder: SurfaceHolder)
@RequiresPermission(value = "android.permission.CAMERA")
suspend fun IWithVideoSource.startPreview(surfaceView: SurfaceView)
@RequiresPermission(value = "android.permission.CAMERA")
suspend fun IWithVideoSource.startPreview(textureView: TextureView)

Sets preview surface and start video preview.

Link copied to clipboard
open suspend override fun startStream()

Starts audio/video stream. Stream depends of the endpoint: Audio/video could be write to a file or send to a remote device. To avoid creating an unresponsive UI, do not call on main thread.

Link copied to clipboard
suspend fun IOpenableStreamer.startStream(uriString: String)

Starts audio/video stream.

Link copied to clipboard

Stops video preview.

Link copied to clipboard
open suspend override fun stopStream()

Stops audio/video stream.