# UdpStream

@RequiresApi(value = 21)
class UdpStream(context: Context, connectChecker: ConnectChecker, videoSource: VideoSource, audioSource: AudioSource) : StreamBase

Created by pedro on 6/3/24.

If you use VideoManager.Source.SCREEN/AudioManager.Source.INTERNAL. Call changeVideoSourceScreen/changeAudioSourceInternal is necessary to start it.

## Constructors

UdpStream
Link copied to clipboard
constructor(context: Context, connectChecker: ConnectChecker, videoSource: VideoSource, audioSource: AudioSource)
constructor(context: Context, connectChecker: ConnectChecker)

## Properties

audioSource
Link copied to clipboard
var audioSource: AudioSource
isOnPreview
Link copied to clipboard
var isOnPreview: Boolean
isRecording
Link copied to clipboard
val isRecording: Boolean
isStreaming
Link copied to clipboard
var isStreaming: Boolean
videoSource
Link copied to clipboard
var videoSource: VideoSource

## Functions

addPreviewSurface
Link copied to clipboard
fun addPreviewSurface(surface: Surface, config: MultiPreviewConfig)
changeAudioSource
Link copied to clipboard
fun changeAudioSource(source: AudioSource)

Change audio source. Must be called after prepareAudio.

changeVideoSource
Link copied to clipboard
fun changeVideoSource(source: VideoSource)

Change video source to Camera1 or Camera2. Must be called after prepareVideo.

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

Force stream to work with fps selected in prepareVideo method. Must be called before prepareVideo. Must be called after prepareVideo

getGlInterface
Link copied to clipboard
fun getGlInterface(): GlStreamInterface

Get glInterface used to render video. This is useful to send filters to stream. Must be called after prepareVideo.

getMultiPreviewSurfaceCount
Link copied to clipboard
fun getMultiPreviewSurfaceCount(): Int
getStreamClient
Link copied to clipboard
open override fun getStreamClient(): UdpStreamClient
getSurfaceTexture
Link copied to clipboard
fun getSurfaceTexture(): SurfaceTexture

return surface texture that can be used to render and encode custom data. Return null if video not prepared. start and stop rendering must be managed by the user.

hasMultiPreviewSurface
Link copied to clipboard
fun hasMultiPreviewSurface(surface: Surface): Boolean
pauseRecord
Link copied to clipboard
fun pauseRecord()

Pause record. Ignored if you are not recording.

prepareAudio
Link copied to clipboard
@JvmOverloads
fun prepareAudio(sampleRate: Int, isStereo: Boolean, bitrate: Int, echoCanceler: Boolean = false, noiseSuppressor: Boolean = false): Boolean

Necessary only one time before start stream or record. If you want change values stop stream and record is necessary.

prepareVideo
Link copied to clipboard
@JvmOverloads
fun prepareVideo(width: Int, height: Int, bitrate: Int, fps: Int = 30, iFrameInterval: Int = 2, rotation: Int = 0, profile: Int = -1, level: Int = -1, recordWidth: Int = 0, recordHeight: Int = 0, recordBitrate: Int = bitrate): Boolean

Necessary only one time before start preview, stream or record. If you want change values stop preview, stream and record is necessary.

release
Link copied to clipboard
fun release()

Stop stream, record and preview and then release all resources. You must call it after finish all the work.

removeAllMultiPreviewSurfaces
Link copied to clipboard
fun removeAllMultiPreviewSurfaces()
removeMultiPreviewSurface
Link copied to clipboard
fun removeMultiPreviewSurface(surface: Surface)
requestKeyframe
Link copied to clipboard
fun requestKeyframe()

Force VideoEncoder to produce a keyframe. Ignored if not recording or streaming. This could be ignored depend of the Codec implementation in each device.

resetAudioEncoder
Link copied to clipboard
fun resetAudioEncoder(): Boolean

Reset AudioEncoder. Only recommended if an AudioEncoder class error is received in the EncoderErrorCallback

resetVideoEncoder
Link copied to clipboard
fun resetVideoEncoder(): Boolean

Reset VideoEncoder. Only recommended if a VideoEncoder class error is received in the EncoderErrorCallback

resumeRecord
Link copied to clipboard
fun resumeRecord()

Resume record. Ignored if you are not recording and in pause mode.

setAudioCodec
Link copied to clipboard
fun setAudioCodec(codec: AudioCodec)

Change AudioCodec used. This could fail depend of the Codec supported in each Protocol. For example G711 is not supported in SRT

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

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

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

Change stream orientation depend of activity orientation. This method affect to preview and stream. Must be called after prepareVideo.

setRecordController
Link copied to clipboard
fun setRecordController(recordController: RecordController)

Replace the current BaseRecordController. This method allow record in other format or even create your custom implementation and record in a new format.

setTimestampMode
Link copied to clipboard
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
fun setVideoBitrateOnFly(bitrate: Int)

Set video bitrate in bits per second while streaming.

setVideoCodec
Link copied to clipboard
fun setVideoCodec(codec: VideoCodec)

Change VideoCodec used. This could fail depend of the Codec supported in each Protocol. For example AV1 is not supported in SRT

startPreview
Link copied to clipboard
@JvmOverloads
fun startPreview(surfaceView: SurfaceView, autoHandle: Boolean = false)

Start preview in the selected SurfaceView. Must be called after prepareVideo.

@JvmOverloads
fun startPreview(textureView: TextureView, autoHandle: Boolean = false)

Start preview in the selected TextureView. Must be called after prepareVideo.

fun startPreview(surfaceTexture: SurfaceTexture, width: Int, height: Int)

Start preview in the selected SurfaceTexture. Must be called after prepareVideo.

fun startPreview(surface: Surface, width: Int, height: Int)

Start preview in the selected Surface. Must be called after prepareVideo.

startRecord
Link copied to clipboard
@JvmOverloads
fun startRecord(path: String, tracks: RecordController.RecordTracks? = null, listener: RecordController.Listener)

Start record.

startStream
Link copied to clipboard
fun startStream(endPoint: String)

Start stream.

stopPreview
Link copied to clipboard
@JvmOverloads
fun stopPreview(removeCallbacks: Boolean = false)

Stop preview. Must be called after prepareVideo.

stopRecord
Link copied to clipboard
fun stopRecord(): Boolean
stopStream
Link copied to clipboard
fun stopStream(): Boolean

Stop stream.

updateMultiPreviewConfig
Link copied to clipboard
fun updateMultiPreviewConfig(surface: Surface, config: MultiPreviewConfig): Boolean