Skip to content

Commit 58b90d2

Browse files
committedFeb 2, 2025
feat(Project): fix retain
- fix retain - lint project
1 parent 395dfbc commit 58b90d2

5 files changed

+312
-291
lines changed
 

‎WebRTCiOSSDK/api/AntMediaClientDelegate.swift

+19-21
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public class StreamInformation {
1616
public let videoCodec: String
1717

1818
init(json: [String: Any]!) {
19-
self.streamWidth = json["streamWidth"] as! Int;
20-
self.streamHeight = json["streamHeight"] as! Int;
21-
self.videoBitrate = json["videoBitrate"] as! Int;
22-
self.audioBitrate = json["audioBitrate"] as! Int;
23-
self.videoCodec = json["videoCodec"] as! String;
19+
self.streamWidth = json["streamWidth"] as! Int
20+
self.streamHeight = json["streamHeight"] as! Int
21+
self.videoBitrate = json["videoBitrate"] as! Int
22+
self.audioBitrate = json["audioBitrate"] as! Int
23+
self.videoCodec = json["videoCodec"] as! String
2424
}
2525
}
2626
public protocol AntMediaClientDelegate: AnyObject {
@@ -55,7 +55,6 @@ public protocol AntMediaClientDelegate: AnyObject {
5555
*/
5656
func localStreamStarted(streamId: String)
5757

58-
5958
/**
6059
Called when playing is started.
6160
Triggered by server.
@@ -121,7 +120,7 @@ public protocol AntMediaClientDelegate: AnyObject {
121120
- evenType: The type of the event
122121
*/
123122
@available(*, deprecated, message: "Will be removed soon. Use eventHappened(streamId, eventType, payload)")
124-
func eventHappened(streamId:String, eventType:String);
123+
func eventHappened(streamId: String, eventType: String)
125124

126125
/**
127126
It's called when there is an event happen such microphone is muted or unmuted for the specific streamId
@@ -130,17 +129,17 @@ public protocol AntMediaClientDelegate: AnyObject {
130129
- evenType: The type of the event
131130
- payload: The payload of the event
132131
*/
133-
func eventHappened(streamId:String, eventType:String, payload: [String:Any]?)
132+
func eventHappened(streamId: String, eventType: String, payload: [String: Any]?)
134133

135134
/**
136135
It's called when a new track is added to the stream. It works both on multirack streaming and conferencing
137136
*/
138-
func trackAdded(track:RTCMediaStreamTrack, stream:[RTCMediaStream])
137+
func trackAdded(track: RTCMediaStreamTrack, stream: [RTCMediaStream])
139138

140139
/**
141140
It's called when a tack is removed. It works both on multitrack streaming and conferencing
142141
*/
143-
func trackRemoved(track:RTCMediaStreamTrack)
142+
func trackRemoved(track: RTCMediaStreamTrack)
144143

145144
/**
146145
It's called when server responses to getBroadcastObject method in AntMediaClient.
@@ -150,28 +149,28 @@ public protocol AntMediaClientDelegate: AnyObject {
150149
/**
151150
It's called after`registerStatsListener`is `AntMediaClient` is called
152151
*/
153-
func onStats(streamId:String, statistics:RTCStatisticsReport);
152+
func onStats(streamId: String, statistics: RTCStatisticsReport)
154153

155154
/**
156155
It's called after join to the room.
157156
- streamId: the id of the stream tha can be used to publish stream.
158157
It's not an obligation to publish a stream. It changes according to the project
159158
*/
160-
func streamIdToPublish(streamId: String);
159+
func streamIdToPublish(streamId: String)
161160

162161
/**
163162
Called when new streams join to the room
164163
- streams: stream id array of the streams that join to the room
165164
*/
166165
@available(*, deprecated, message: "No need to use. New streams are added automatically. trackAdded is called automatically")
167-
func newStreamsJoined(streams: [String]);
166+
func newStreamsJoined(streams: [String])
168167

169168
/**
170169
Called when some streams leaves from the room. So that players can be removed from the user interface
171170
- streams: stream id array of the stream that leaves from the room
172171
*/
173172
@available(*, deprecated, message: "No need to use. New streams are removed automatically. trackRemoved is called automatically")
174-
func streamsLeft(streams: [String]);
173+
func streamsLeft(streams: [String])
175174

176175
/**
177176
The delegate method that sends audio level of the microphone. , audioLeve is between 0 and 1.
@@ -196,14 +195,14 @@ public extension AntMediaClientDelegate {
196195
}
197196

198197
func clientDidDisconnect(_ message: String) {
199-
AntMediaClient.printf("Websocket is disconnected with this problem:\(message)");
198+
AntMediaClient.printf("Websocket is disconnected with this problem:\(message)")
200199
}
201200

202-
func trackAdded(track:RTCMediaStreamTrack, stream:[RTCMediaStream]) {
201+
func trackAdded(track: RTCMediaStreamTrack, stream: [RTCMediaStream]) {
203202
AntMediaClient.printf("Track is added with id:\(track.trackId) and kind:\(track.kind)")
204203
}
205204

206-
func trackRemoved(track:RTCMediaStreamTrack) {
205+
func trackRemoved(track: RTCMediaStreamTrack) {
207206
AntMediaClient.printf("Track is removed with id:\(track.trackId) and kind:\(track.kind)")
208207
}
209208

@@ -238,7 +237,7 @@ public extension AntMediaClientDelegate {
238237
func streamInformation(streamInfo: [StreamInformation]) {
239238
AntMediaClient.printf("Stream information has received")
240239
for result in streamInfo {
241-
AntMediaClient.printf("resolution width:\(result.streamWidth) heigh:\(result.streamHeight) video " + "bitrate:\(result.videoBitrate) audio bitrate:\(result.audioBitrate) codec:\(result.videoCodec)");
240+
AntMediaClient.printf("resolution width:\(result.streamWidth) heigh:\(result.streamHeight) video " + "bitrate:\(result.videoBitrate) audio bitrate:\(result.audioBitrate) codec:\(result.videoCodec)")
242241
}
243242
}
244243

@@ -270,14 +269,13 @@ public extension AntMediaClientDelegate {
270269
AntMediaClient.printf("onLoadBroadcastObject is called for \(streamId) and incoming response: \(message)")
271270
}
272271

273-
func eventHappened(streamId:String, eventType:String, payload: [String:Any]?) {
272+
func eventHappened(streamId: String, eventType: String, payload: [String: Any]?) {
274273
AntMediaClient.printf("\(streamId) \(eventType) with")
275274
AntMediaClient.printf(payload?.json ?? "")
276275
}
277276

278-
func onStats(streamId:String, statistics:RTCStatisticsReport) {
277+
func onStats(streamId: String, statistics: RTCStatisticsReport) {
279278
AntMediaClient.printf("streamId: \(streamId) stats received")
280279
}
281280

282281
}
283-

‎WebRTCiOSSDK/api/AntMediaError.swift

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class AntMediaError {
1515
return "No stream exists on server."
1616
case "unauthorized_access":
1717
return "Unauthorized access: Check your token"
18-
1918
default:
2019
return "An error occured: " + message
2120
}

‎WebRTCiOSSDK/api/webrtc/RTCCustomFrameCapturer.swift

+28-41
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,52 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
1414

1515
let kNanosecondsPerSecond: Float64 = 1000000000
1616
var nanoseconds: Float64 = 0
17-
var lastSentFrameTimeStampNanoSeconds: Int64 = 0;
17+
var lastSentFrameTimeStampNanoSeconds: Int64 = 0
1818
private var targetHeight: Int
1919

20-
private var videoEnabled: Bool = true;
21-
private var audioEnabled: Bool = true;
20+
private var videoEnabled: Bool = true
21+
private var audioEnabled: Bool = true
2222

23-
private var webRTCClient: WebRTCClient?;
24-
25-
private var frameRateIntervalNanoSeconds : Float64 = 0;
23+
private var webRTCClient: WebRTCClient?
2624

25+
private var frameRateIntervalNanoSeconds: Float64 = 0
2726

2827
// if externalCapture is true, it means that capture method is called from an external component.
2928
// externalComponent is the BroadcastExtension
30-
private var externalCapture: Bool;
31-
32-
private var fps: Int;
29+
private var externalCapture: Bool
3330

31+
private var fps: Int
3432

35-
init(delegate: RTCVideoCapturerDelegate, height: Int, externalCapture: Bool = false, videoEnabled: Bool = true, audioEnabled: Bool = false, fps: Int = 30)
36-
{
33+
init(delegate: RTCVideoCapturerDelegate, height: Int, externalCapture: Bool = false, videoEnabled: Bool = true, audioEnabled: Bool = false, fps: Int = 30) {
3734
self.targetHeight = height
38-
self.externalCapture = externalCapture;
35+
self.externalCapture = externalCapture
3936

4037
//if external capture is enabled videoEnabled and audioEnabled are ignored
41-
self.videoEnabled = videoEnabled;
42-
self.audioEnabled = audioEnabled;
43-
self.frameRateIntervalNanoSeconds = kNanosecondsPerSecond/Double(fps);
44-
self.fps = fps;
38+
self.videoEnabled = videoEnabled
39+
self.audioEnabled = audioEnabled
40+
self.frameRateIntervalNanoSeconds = kNanosecondsPerSecond/Double(fps)
41+
self.fps = fps
4542

4643
super.init(delegate: delegate)
47-
4844
}
4945

5046
public func setWebRTCClient(webRTCClient: WebRTCClient) {
5147
self.webRTCClient = webRTCClient
5248
}
5349

54-
public func capture(_ pixelBuffer: CVPixelBuffer, rotation:RTCVideoRotation, timeStampNs: Int64 )
55-
{
50+
public func capture(_ pixelBuffer: CVPixelBuffer, rotation: RTCVideoRotation, timeStampNs: Int64 ) {
5651
if ((Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds ) {
5752
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)");
58-
return;
59-
53+
return
6054
}
6155

6256
let width = Int32(CVPixelBufferGetWidth(pixelBuffer))
6357
let height = Int32(CVPixelBufferGetHeight(pixelBuffer))
6458

65-
var scaledWidth = (width * Int32(self.targetHeight)) / height;
66-
if (scaledWidth % 2 == 1) {
67-
scaledWidth+=1;
59+
var scaledWidth = (width * Int32(self.targetHeight)) / height
60+
61+
if scaledWidth % 2 == 1 {
62+
scaledWidth += 1
6863
}
6964

7065
let rtcPixelBuffer = RTCCVPixelBuffer(
@@ -74,7 +69,8 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
7469
cropWidth: width,
7570
cropHeight: height,
7671
cropX: 0,
77-
cropY: 0)
72+
cropY: 0
73+
)
7874

7975
let rtcVideoFrame = RTCVideoFrame(
8076
buffer: rtcPixelBuffer,
@@ -83,10 +79,10 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
8379
)
8480

8581
self.delegate?.capturer(self, didCapture: rtcVideoFrame.newI420())
86-
lastSentFrameTimeStampNanoSeconds = Int64(timeStampNs);
82+
lastSentFrameTimeStampNanoSeconds = Int64(timeStampNs)
8783
}
8884

89-
public func capture(_ sampleBuffer: CMSampleBuffer, externalRotation:Int = -1) {
85+
public func capture(_ sampleBuffer: CMSampleBuffer, externalRotation: Int = -1) {
9086

9187
if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || !CMSampleBufferIsValid(sampleBuffer) ||
9288
!CMSampleBufferDataIsReady(sampleBuffer))
@@ -95,20 +91,16 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
9591
return;
9692
}
9793

98-
let timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) *
99-
kNanosecondsPerSecond;
94+
let timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * kNanosecondsPerSecond
10095

10196
if ((Double(timeStampNs) - Double(lastSentFrameTimeStampNanoSeconds)) < frameRateIntervalNanoSeconds ) {
10297
AntMediaClient.verbose("Dropping frame because high fps than the configured fps: \(fps). Incoming timestampNs:\(timeStampNs) last sent timestampNs:\(lastSentFrameTimeStampNanoSeconds) frameRateIntervalNs:\(frameRateIntervalNanoSeconds)");
103-
return;
104-
98+
return
10599
}
106100

107-
let _pixelBuffer:CVPixelBuffer? = CMSampleBufferGetImageBuffer(sampleBuffer);
101+
let _pixelBuffer: CVPixelBuffer? = CMSampleBufferGetImageBuffer(sampleBuffer)
108102

109-
110-
if let pixelBuffer = _pixelBuffer
111-
{
103+
if let pixelBuffer = _pixelBuffer {
112104
//NSLog("Incoming frame width:\(width) height:\(height) adapted width:\(scaledWidth) height:\(self.targetHeight)")
113105

114106
var rotation = RTCVideoRotation._0;
@@ -154,7 +146,6 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
154146
else {
155147
NSLog("Cannot get image buffer");
156148
}
157-
158149
}
159150

160151
public func startCapture()
@@ -185,8 +176,7 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
185176
}
186177
}
187178

188-
public func stopCapture()
189-
{
179+
public func stopCapture() {
190180
if !externalCapture {
191181
let recorder = RPScreenRecorder.shared();
192182
if (recorder.isRecording) {
@@ -203,7 +193,4 @@ class RTCCustomFrameCapturer: RTCVideoCapturer {
203193
}
204194
}
205195
}
206-
207-
208196
}
209-

‎WebRTCiOSSDK/api/webrtc/WebRTCClient.swift

+257-220
Large diffs are not rendered by default.

‎WebRTCiOSSDK/api/webrtc/WebRTCClientDelegate.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
import Foundation
99
import WebRTC
1010

11-
internal protocol WebRTCClientDelegate {
11+
internal protocol WebRTCClientDelegate: AnyObject {
1212

1313
func sendMessage(_ message: [String: Any])
1414

1515
/**
1616
It's triggered when remote stream is added to the peer connection.
1717
*/
18-
func remoteStreamAdded(streamId:String)
18+
func remoteStreamAdded(streamId: String)
1919

2020
/**
2121
It's called when remote steram is removed from the peer connection
2222
*/
23-
func remoteStreamRemoved(streamId:String)
23+
func remoteStreamRemoved(streamId: String)
2424

2525
/**
2626
It's called when a new track is added to the stream
2727
*/
28-
func trackAdded(track:RTCMediaStreamTrack, stream:[RTCMediaStream])
28+
func trackAdded(track: RTCMediaStreamTrack, stream: [RTCMediaStream])
2929

3030
/**
3131
It's called when a tack is removed
3232
*/
33-
func trackRemoved(track:RTCMediaStreamTrack)
33+
func trackRemoved(track: RTCMediaStreamTrack)
3434

35-
func addLocalStream(streamId:String)
35+
func addLocalStream(streamId: String)
3636

37-
func connectionStateChanged(newState: RTCIceConnectionState, streamId:String);
37+
func connectionStateChanged(newState: RTCIceConnectionState, streamId: String)
3838

39-
func dataReceivedFromDataChannel(didReceiveData data: RTCDataBuffer, streamId:String);
39+
func dataReceivedFromDataChannel(didReceiveData data: RTCDataBuffer, streamId: String)
4040
}

0 commit comments

Comments
 (0)
Please sign in to comment.