Skip to content

Commit be92bff

Browse files
committedFeb 2, 2025
feat(Project): fix retain
- fix retain
1 parent 58b90d2 commit be92bff

8 files changed

+58
-78
lines changed
 

‎WebRTC-Sample-App/ConferenceViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension ConferenceViewController: AntMediaClientDelegate
9797
}
9898
public func playStarted(streamId: String) {
9999
print("play started");
100-
AntMediaClient.speakerOn();
100+
conferenceClient?.speakerOn()
101101
}
102102

103103
public func trackAdded(track: RTCMediaStreamTrack, stream: [RTCMediaStream]) {

‎WebRTC-Sample-App/VideoViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extension VideoViewController: AntMediaClientDelegate {
307307
}
308308

309309
func audioSessionDidStartPlayOrRecord(streamId: String) {
310-
AntMediaClient.speakerOn()
310+
client?.speakerOn()
311311
}
312312

313313
func dataReceivedFromDataChannel(streamId: String, data: Data, binary: Bool) {

‎WebRTCiOSSDK/api/AntMediaClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ extension AntMediaClient {
14671467

14681468
/// - Activates the audio session
14691469
private func activateAudioSession() {
1470-
DispatchQueue(label: "audio").async {() in
1470+
DispatchQueue(label: "audio").async {
14711471
self.rtcAudioSession.lockForConfiguration()
14721472
self.rtcAudioSession.isAudioEnabled = true
14731473
self.rtcAudioSession.unlockForConfiguration()

‎WebRTCiOSSDK/api/AntMediaClientDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class StreamInformation {
2323
self.videoCodec = json["videoCodec"] as! String
2424
}
2525
}
26+
2627
public protocol AntMediaClientDelegate: AnyObject {
2728

2829
/**

‎WebRTCiOSSDK/api/webrtc/Config.swift

+12-15
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,40 @@ import WebRTC
1111

1212
public class Config: NSObject {
1313

14-
private static let stunServer : String = "stun:stun.l.google.com:19302"
15-
private static let constraints: [String: String] = ["OfferToReceiveAudio": "true",
16-
"OfferToReceiveVideo": "true",]
14+
private static var stunServer: String = "stun:stun.l.google.com:19302"
15+
private static let constraints: [String: String] = ["OfferToReceiveAudio": "true", "OfferToReceiveVideo": "true"]
1716
private static let defaultConstraints: [String: String] = ["DtlsSrtpKeyAgreement": "true"]
1817

19-
private static var rtcSdpSemantics = RTCSdpSemantics.unifiedPlan;
18+
private static var rtcSdpSemantics = RTCSdpSemantics.unifiedPlan
2019

21-
static var iceServer:RTCIceServer = RTCIceServer.init(urlStrings: [stunServer], username: "", credential: "")
22-
23-
public static func setDefaultStunServer(server: RTCIceServer) {
24-
iceServer = server;
20+
public static func setDefaultStunServer(server: String) {
21+
stunServer = server
2522
}
2623

27-
public static func setSdpSemantics(sdpSemantics:RTCSdpSemantics) {
28-
rtcSdpSemantics = sdpSemantics;
24+
public static func setSdpSemantics(sdpSemantics: RTCSdpSemantics) {
25+
rtcSdpSemantics = sdpSemantics
2926
}
3027

3128
static func defaultStunServer() -> RTCIceServer {
32-
return iceServer
29+
return RTCIceServer(urlStrings: [stunServer], username: "", credential: "")
3330
}
3431

3532
static func createAudioVideoConstraints() -> RTCMediaConstraints {
36-
return RTCMediaConstraints.init(mandatoryConstraints: constraints, optionalConstraints: defaultConstraints)
33+
return RTCMediaConstraints(mandatoryConstraints: constraints, optionalConstraints: defaultConstraints)
3734
}
3835

3936
static func createDefaultConstraint() -> RTCMediaConstraints {
40-
return RTCMediaConstraints.init(mandatoryConstraints: nil, optionalConstraints: defaultConstraints)
37+
return RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: defaultConstraints)
4138
}
4239

4340
static func createTestConstraints() -> RTCMediaConstraints {
4441
return RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: constraints)
4542
}
4643

4744
static func createConfiguration(server: RTCIceServer) -> RTCConfiguration {
48-
let config = RTCConfiguration.init()
45+
let config = RTCConfiguration()
4946
config.iceServers = [server]
50-
config.sdpSemantics = rtcSdpSemantics;
47+
config.sdpSemantics = rtcSdpSemantics
5148
return config
5249
}
5350
}

‎WebRTCiOSSDK/api/webrtc/RTCCustomFrameCapturer.swift

+41-57
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ReplayKit
1212

1313
class RTCCustomFrameCapturer: RTCVideoCapturer {
1414

15-
let kNanosecondsPerSecond: Float64 = 1000000000
15+
let kNanosecondsPerSecond: Float64 = 1_000_000_000
1616
var nanoseconds: Float64 = 0
1717
var lastSentFrameTimeStampNanoSeconds: Int64 = 0
1818
private var targetHeight: Int
@@ -34,10 +34,10 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
3434
self.targetHeight = height
3535
self.externalCapture = externalCapture
3636

37-
//if external capture is enabled videoEnabled and audioEnabled are ignored
37+
// if external capture is enabled videoEnabled and audioEnabled are ignored
3838
self.videoEnabled = videoEnabled
3939
self.audioEnabled = audioEnabled
40-
self.frameRateIntervalNanoSeconds = kNanosecondsPerSecond/Double(fps)
40+
self.frameRateIntervalNanoSeconds = kNanosecondsPerSecond / Double(fps)
4141
self.fps = fps
4242

4343
super.init(delegate: delegate)
@@ -48,8 +48,8 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
4848
}
4949

5050
public func capture(_ pixelBuffer: CVPixelBuffer, rotation: RTCVideoRotation, timeStampNs: Int64 ) {
51-
if ((Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds ) {
52-
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)");
51+
if (Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds {
52+
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)")
5353
return
5454
}
5555

@@ -64,7 +64,7 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
6464

6565
let rtcPixelBuffer = RTCCVPixelBuffer(
6666
pixelBuffer: pixelBuffer,
67-
adaptedWidth:scaledWidth,
67+
adaptedWidth: scaledWidth,
6868
adaptedHeight: Int32(self.targetHeight),
6969
cropWidth: width,
7070
cropHeight: height,
@@ -84,90 +84,74 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
8484

8585
public func capture(_ sampleBuffer: CMSampleBuffer, externalRotation: Int = -1) {
8686

87-
if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || !CMSampleBufferIsValid(sampleBuffer) ||
88-
!CMSampleBufferDataIsReady(sampleBuffer))
89-
{
90-
NSLog("Buffer is not ready and dropping");
91-
return;
87+
if CMSampleBufferGetNumSamples(sampleBuffer) != 1 || !CMSampleBufferIsValid(sampleBuffer) || !CMSampleBufferDataIsReady(sampleBuffer) {
88+
NSLog("Buffer is not ready and dropping")
89+
return
9290
}
9391

9492
let timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * kNanosecondsPerSecond
9593

96-
if ((Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds ) {
97-
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)");
94+
if (Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds {
95+
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)")
9896
return
9997
}
10098

10199
let _pixelBuffer: CVPixelBuffer? = CMSampleBufferGetImageBuffer(sampleBuffer)
102100

103101
if let pixelBuffer = _pixelBuffer {
104-
//NSLog("Incoming frame width:\(width) height:\(height) adapted width:\(scaledWidth) height:\(self.targetHeight)")
102+
// NSLog("Incoming frame width:\(width) height:\(height) adapted width:\(scaledWidth) height:\(self.targetHeight)")
103+
104+
var rotation = RTCVideoRotation._0
105105

106-
var rotation = RTCVideoRotation._0;
107-
if (externalRotation == -1) {
106+
if externalRotation == -1 {
108107
if #available(iOS 11.0, *) {
109-
if let orientationAttachment = CMGetAttachment(sampleBuffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber
110-
{
108+
if let orientationAttachment = CMGetAttachment(sampleBuffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber {
111109
let orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value)
112110
switch orientation {
113111
case .up:
114-
rotation = RTCVideoRotation._0;
115-
break;
112+
rotation = RTCVideoRotation._0
116113
case .down:
117-
rotation = RTCVideoRotation._180;
118-
break;
114+
rotation = RTCVideoRotation._180
119115
case .left:
120-
rotation = RTCVideoRotation._90;
121-
break;
116+
rotation = RTCVideoRotation._90
122117
case .right:
123-
rotation = RTCVideoRotation._270;
124-
break;
125-
118+
rotation = RTCVideoRotation._270
126119
default:
127-
NSLog("orientation NOT FOUND");
120+
NSLog("orientation NOT FOUND")
128121
}
129-
}
130-
else {
122+
} else {
131123
NSLog("CANNOT get image rotation")
132-
133124
}
134125
} else {
135126
NSLog("CANNOT get image rotation becaue iOS version is older than 11")
136127
}
137-
}
138-
else {
139-
rotation = RTCVideoRotation(rawValue:externalRotation) ?? RTCVideoRotation._0;
128+
} else {
129+
rotation = RTCVideoRotation(rawValue: externalRotation) ?? RTCVideoRotation._0
140130
}
141131

142-
143132
capture(pixelBuffer, rotation: rotation, timeStampNs: Int64(timeStampNs))
144-
//NSLog("Device orientation width: %d, height:%d ", width, height);
145-
}
146-
else {
147-
NSLog("Cannot get image buffer");
133+
// NSLog("Device orientation width: %d, height:%d ", width, height);
134+
} else {
135+
NSLog("Cannot get image buffer")
148136
}
149137
}
150138

151-
public func startCapture()
152-
{
153-
if !externalCapture
154-
{
155-
let recorder = RPScreenRecorder.shared();
139+
public func startCapture() {
140+
if !externalCapture {
141+
let recorder = RPScreenRecorder.shared()
156142

157143
if #available(iOS 11.0, *) {
158-
recorder.startCapture { (buffer, bufferType, error) in
159-
if bufferType == RPSampleBufferType.video && self.videoEnabled
160-
{
144+
recorder.startCapture { buffer, bufferType, _ in
145+
if bufferType == RPSampleBufferType.video && self.videoEnabled {
161146
self.capture(buffer)
162-
}
163-
else if bufferType == RPSampleBufferType.audioApp && self.audioEnabled {
164-
self.webRTCClient?.deliverExternalAudio(sampleBuffer: buffer);
147+
} else if bufferType == RPSampleBufferType.audioApp && self.audioEnabled {
148+
self.webRTCClient?.deliverExternalAudio(sampleBuffer: buffer)
165149

166150
}
167-
} completionHandler: { (error) in
151+
} completionHandler: { error in
168152
guard error == nil else {
169153
AntMediaClient.printf("Screen capturer is not started")
170-
return;
154+
return
171155
}
172156
}
173157
} else {
@@ -178,13 +162,13 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
178162

179163
public func stopCapture() {
180164
if !externalCapture {
181-
let recorder = RPScreenRecorder.shared();
182-
if (recorder.isRecording) {
165+
let recorder = RPScreenRecorder.shared()
166+
if recorder.isRecording {
183167
if #available(iOS 11.0, *) {
184-
recorder.stopCapture { (error) in
168+
recorder.stopCapture { error in
185169
guard error == nil else {
186-
AntMediaClient.printf("Cannot stop capture \(String(describing: error))");
187-
return;
170+
AntMediaClient.printf("Cannot stop capture \(String(describing: error))")
171+
return
188172
}
189173
}
190174
} else {

‎WebRTCiOSSDK/api/webrtc/String.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension String {
1515
func toJSON() -> [String: Any]? {
1616
let data = self.data(using: .utf8)!
1717
do {
18-
if let jsonArray = try JSONSerialization.jsonObject(with: data, options : .allowFragments) as? Dictionary<String,Any> {
18+
if let jsonArray = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] {
1919
return jsonArray
2020
} else {
2121
return nil

‎WebRTCiOSSDK/api/webrtc/WebRTCClient.swift

-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ class WebRTCClient: NSObject {
326326

327327
public func disconnect() {
328328
AntMediaClient.printf("disconnecting and releasing resources for \(streamId)")
329-
//TODO: how to clear all resources
330329

331330
if let view = self.localVideoView {
332331
self.localVideoTrack?.remove(view)
@@ -532,7 +531,6 @@ class WebRTCClient: NSObject {
532531
public func getVideoCapturer() -> RTCVideoCapturer? {
533532
return videoCapturer
534533
}
535-
536534
}
537535

538536
extension WebRTCClient: RTCDataChannelDelegate {

0 commit comments

Comments
 (0)
Please sign in to comment.