Skip to content

Instantly share code, notes, and snippets.

@iamyogish
Last active February 19, 2018 09:11
Show Gist options
  • Save iamyogish/aafef75c891dd0ee8ecde90b82bd4b3a to your computer and use it in GitHub Desktop.
Save iamyogish/aafef75c891dd0ee8ecde90b82bd4b3a to your computer and use it in GitHub Desktop.
Reducing the Video Quality of the WebRTC Call
static let LOCAL_VIDEO_TRACK_ID = "Your Local Video Track ID here"
static let AUDIO_TRACK_ID = "Your Local Audio Track ID here"
//...
func createLocalMediaStream() {
//...
let peerConnectionFactory = RTCPeerConnectionFactory()
let localMediaStream = peerConnectionFactory.mediaStream(withStreamId: LOCAL_VIDEO_TRACK_ID)
var mandatoryConstraints: [String: String]?
//Add audio track to the stream
let localAudioTrack = peerConnectionFactory.audioTrack(withTrackId: AUDIO_TRACK_ID)
localMediaStream.addAudioTrack(localAudioTrack)
if lowDataModeEnabled {
//If low data mode is enabled,
mandatoryConstraints = ["minFrameRate": "1", "maxFrameRate": "15"]
}
//Create the video source
let constraints = RTCMediaConstraints(mandatoryConstraints: mandatoryConstraints, optionalConstraints: nil)
let videoSource = peerConnectionFactory.avFoundationVideoSource(with: constraints)
//Create the video track from the video source
let localVideoTrack = peerConnectionFactory.videoTrack(with: videoSource, trackId: LOCAL_VIDEO_TRACK_ID)
localMediaStream.addVideoTrack(localVideoTrack)
//...
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment