Skip to content

Commit

Permalink
Add set degradation preference method
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed May 21, 2024
1 parent 32b8f7e commit 88ae3f3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Podfile.lock
Release-iphoneos.xcarchive
Release-iphonesimulator.xcarchive
Release*
Package.resolved
20 changes: 19 additions & 1 deletion WebRTCiOSSDK/api/AntMediaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,15 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {

private var cameraSourceFPS: Int = 30;

/**
Degradation preference when publishing streams. By default its values is maintainResolution because when resolution changes HLS playback does not play in safari
*/
private var degradationPreference: RTCDegradationPreference = RTCDegradationPreference.maintainResolution;

var pingTimer: Timer?

var disableTrackId:String?


var reconnectIfRequiresScheduled: Bool = false;

struct HandshakeMessage:Codable {
Expand Down Expand Up @@ -533,6 +537,7 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
self.webRTCClientMap[id] = WebRTCClient.init(remoteVideoView: remoteView, localVideoView: localView, delegate: self, mode: mode != .unspecified ? mode : self.mode , cameraPosition: self.cameraPosition, targetWidth: self.targetWidth, targetHeight: self.targetHeight, videoEnabled: self.videoEnable, enableDataChannel: self.enableDataChannel, useExternalCameraSource: self.useExternalCameraSource, externalAudio: self.externalAudioEnabled, externalVideoCapture: self.externalVideoCapture, cameraSourceFPS: self.cameraSourceFPS, streamId:id);

self.webRTCClientMap[id]?.setToken(token)
self.webRTCClientMap[id]?.setDegradationPreference(degradationPreference: self.degradationPreference);

AntMediaClient.rtcAudioSession.add(self);
}
Expand Down Expand Up @@ -1180,6 +1185,19 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
}
}

public func setDegradationPreference(_ degradationPreference: RTCDegradationPreference)
{
self.degradationPreference = degradationPreference;
let rtc = self.webRTCClientMap[self.getPublisherStreamId()]

guard let params = rtc?.videoSender?.parameters else {
return
}

params.degradationPreference = (degradationPreference.rawValue) as NSNumber
rtc?.videoSender?.parameters = params
}

public func disconnect() {
for (streamId, webrtcClient) in self.webRTCClientMap {
webrtcClient.disconnect()
Expand Down
5 changes: 5 additions & 0 deletions WebRTCiOSSDK/api/AntMediaClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ public protocol AntMediaClientProtocol {
*/
func join(streamId:String)

/**
Set the degradation prefernece in publishing streams. It can be called before the stream starts or while it's streaming.
*/
func setDegradationPreference(_ degradationPreference: RTCDegradationPreference);

/**
Disconnects websocket connection
*/
Expand Down
18 changes: 16 additions & 2 deletions WebRTCiOSSDK/api/webrtc/WebRTCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class WebRTCClient: NSObject {
State of the connection
*/
var iceConnectionState:RTCIceConnectionState = .new;

private var degradationPreference:RTCDegradationPreference = .maintainResolution;

public init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, externalAudio:Bool) {
super.init()
Expand Down Expand Up @@ -405,10 +407,9 @@ class WebRTCClient: NSObject {
let videoTrack = WebRTCClient.factory.videoTrack(with: videoSource, trackId: "video0")
return videoTrack
}


}


private func addLocalMediaStream() -> Bool {


Expand All @@ -418,6 +419,15 @@ class WebRTCClient: NSObject {
self.localVideoTrack = createVideoTrack();

self.videoSender = self.peerConnection?.add(self.localVideoTrack, streamIds: [LOCAL_MEDIA_STREAM_ID])

if let params = videoSender?.parameters
{
params.degradationPreference = (self.degradationPreference.rawValue) as NSNumber
videoSender?.parameters = params
}
else {
AntMediaClient.printf("DegradationPreference cannot be set");
}
}

let audioSource = WebRTCClient.factory.audioSource(with: Config.createTestConstraints())
Expand All @@ -432,6 +442,10 @@ class WebRTCClient: NSObject {
return true
}

public func setDegradationPreference(degradationPreference:RTCDegradationPreference) {
self.degradationPreference = degradationPreference
}

public func switchCamera() {

let cameraVideoCapturer = self.videoCapturer as? RTCCameraVideoCapturer;
Expand Down

0 comments on commit 88ae3f3

Please sign in to comment.