-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeanCovertor.swift
More file actions
403 lines (379 loc) · 14.7 KB
/
BeanCovertor.swift
File metadata and controls
403 lines (379 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//
// BeanCovertor.swift
// RCTAgora
//
// Created by LXH on 2020/4/9.
// Copyright © 2020 Syan. All rights reserved.
//
import Foundation
import AgoraRtcKit
func mapToPoint(_ map: Dictionary<String, Any>) -> CGPoint {
var point = CGPoint()
if let x = map["x"] as? NSNumber {
point.x = CGFloat(truncating: x)
}
if let y = map["y"] as? NSNumber {
point.y = CGFloat(truncating: y)
}
return point
}
func mapToSize(_ map: Dictionary<String, Any>) -> CGSize {
var size = CGSize()
if let width = map["width"] as? NSNumber {
size.width = CGFloat(truncating: width)
}
if let height = map["height"] as? NSNumber {
size.height = CGFloat(truncating: height)
}
return size
}
func mapToRect(_ map: Dictionary<String, Any>) -> CGRect {
return CGRect(
origin: mapToPoint(map),
size: mapToSize(map)
)
}
func mapToVideoEncoderConfiguration(_ map: Dictionary<String, Any>) -> AgoraVideoEncoderConfiguration {
let config = AgoraVideoEncoderConfiguration()
if let dimensions = map["dimensions"] as? Dictionary<String, Any> {
config.dimensions = mapToSize(dimensions)
}
if let frameRate = map["frameRate"] as? NSNumber {
config.frameRate = frameRate.intValue
}
if let minFrameRate = map["minFrameRate"] as? NSNumber {
config.minFrameRate = minFrameRate.intValue
}
if let bitrate = map["bitrate"] as? NSNumber {
config.bitrate = bitrate.intValue
}
if let minBitrate = map["minBitrate"] as? NSNumber {
config.minBitrate = minBitrate.intValue
}
if let orientationMode = map["orientationMode"] as? NSNumber {
if let orientationMode = AgoraVideoOutputOrientationMode(rawValue: orientationMode.intValue) {
config.orientationMode = orientationMode
}
}
if let degradationPreference = map["degradationPrefer"] as? NSNumber {
if let degradationPreference = AgoraDegradationPreference(rawValue: degradationPreference.intValue) {
config.degradationPreference = degradationPreference
}
}
if let mirrorMode = map["mirrorMode"] as? NSNumber {
if let mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode.uintValue) {
config.mirrorMode = mirrorMode
}
}
return config
}
func mapToBeautyOptions(_ map: Dictionary<String, Any>) -> AgoraBeautyOptions {
let options = AgoraBeautyOptions()
if let lighteningContrastLevel = map["lighteningContrastLevel"] as? NSNumber {
if let lighteningContrastLevel = AgoraLighteningContrastLevel(rawValue: lighteningContrastLevel.uintValue) {
options.lighteningContrastLevel = lighteningContrastLevel
}
}
if let lighteningLevel = map["lighteningLevel"] as? NSNumber {
options.lighteningLevel = lighteningLevel.floatValue
}
if let smoothnessLevel = map["smoothnessLevel"] as? NSNumber {
options.smoothnessLevel = smoothnessLevel.floatValue
}
if let rednessLevel = map["rednessLevel"] as? NSNumber {
options.rednessLevel = rednessLevel.floatValue
}
return options
}
func mapToAgoraImage(_ map: Dictionary<String, Any>) -> AgoraImage {
let image = AgoraImage()
if let url = map["url"] as? String {
if let url = URL(string: url) {
image.url = url
}
}
image.rect = mapToRect(map)
return image
}
func mapToTranscodingUser(_ map: Dictionary<String, Any>) -> AgoraLiveTranscodingUser {
let user = AgoraLiveTranscodingUser()
if let uid = map["uid"] as? NSNumber {
user.uid = uid.uintValue
}
user.rect = mapToRect(map)
if let zOrder = map["zOrder"] as? NSNumber {
user.zOrder = zOrder.intValue
}
if let alpha = map["alpha"] as? NSNumber {
user.alpha = alpha.doubleValue
}
if let audioChannel = map["audioChannel"] as? NSNumber {
user.audioChannel = audioChannel.intValue
}
return user
}
func mapToColor(_ map: Dictionary<String, Any>) -> UIColor {
return UIColor(
red: CGFloat((map["red"] as! NSNumber).intValue),
green: CGFloat((map["green"] as! NSNumber).intValue),
blue: CGFloat((map["blue"] as! NSNumber).intValue),
alpha: 1.0
)
}
func mapToLiveTranscoding(_ map: Dictionary<String, Any>) -> AgoraLiveTranscoding {
let transcoding = AgoraLiveTranscoding.default()
transcoding.size = mapToSize(map)
if let videoBitrate = map["videoBitrate"] as? NSNumber {
transcoding.videoBitrate = videoBitrate.intValue
}
if let videoFramerate = map["videoFramerate"] as? NSNumber {
transcoding.videoFramerate = videoFramerate.intValue
}
if let lowLatency = map["lowLatency"] as? Bool {
transcoding.lowLatency = lowLatency
}
if let videoGop = map["videoGop"] as? NSNumber {
transcoding.videoGop = videoGop.intValue
}
if let watermark = map["watermark"] as? Dictionary<String, Any> {
transcoding.watermark = mapToAgoraImage(watermark)
}
if let backgroundImage = map["backgroundImage"] as? Dictionary<String, Any> {
transcoding.backgroundImage = mapToAgoraImage(backgroundImage)
}
if let audioSampleRate = map["audioSampleRate"] as? NSNumber {
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) {
transcoding.audioSampleRate = audioSampleRate
}
}
if let audioBitrate = map["audioBitrate"] as? NSNumber {
transcoding.audioBitrate = audioBitrate.intValue
}
if let audioChannels = map["audioChannels"] as? NSNumber {
transcoding.audioChannels = audioChannels.intValue
}
if let audioCodecProfile = map["audioCodecProfile"] as? NSNumber {
if let audioCodecProfile = AgoraAudioCodecProfileType(rawValue: audioCodecProfile.intValue) {
transcoding.audioCodecProfile = audioCodecProfile
}
}
if let videoCodecProfile = map["videoCodecProfile"] as? NSNumber {
if let videoCodecProfile = AgoraVideoCodecProfileType(rawValue: videoCodecProfile.intValue) {
transcoding.videoCodecProfile = videoCodecProfile
}
}
if let backgroundColor = map["backgroundColor"] as? Dictionary<String, Any> {
transcoding.backgroundColor = mapToColor(backgroundColor)
}
if let userConfigExtraInfo = map["userConfigExtraInfo"] as? String {
transcoding.transcodingExtraInfo = userConfigExtraInfo
}
if let transcodingUsers = map["transcodingUsers"] as? Array<Any> {
transcodingUsers.forEach {
if let item = $0 as? Dictionary<String, Any> {
transcoding.add(mapToTranscodingUser(item))
}
}
}
return transcoding
}
func mapToChannelMediaInfo(_ map: Dictionary<String, Any>) -> AgoraChannelMediaRelayInfo {
let info = AgoraChannelMediaRelayInfo()
if let channelName = map["channelName"] as? String {
info.channelName = channelName
}
if let token = map["token"] as? String {
info.token = token
}
if let uid = map["uid"] as? NSNumber {
info.uid = uid.uintValue
}
return info
}
func mapToChannelMediaRelayConfiguration(_ map: Dictionary<String, Any>) -> AgoraChannelMediaRelayConfiguration {
let config = AgoraChannelMediaRelayConfiguration()
if let srcInfo = map["srcInfo"] as? Dictionary<String, Any> {
config.sourceInfo = mapToChannelMediaInfo(srcInfo)
}
if let destInfos = map["destInfos"] as? Array<Any> {
destInfos.forEach {
if let item = $0 as? Dictionary<String, Any> {
let info = mapToChannelMediaInfo(item)
config.setDestinationInfo(info, forChannelName: info.channelName ?? "")
}
}
}
return config
}
func mapToLastmileProbeConfig(_ map: Dictionary<String, Any>) -> AgoraLastmileProbeConfig {
let config = AgoraLastmileProbeConfig()
if let probeUplink = map["probeUplink"] as? Bool {
config.probeUplink = probeUplink
}
if let probeDownlink = map["probeDownlink"] as? Bool {
config.probeDownlink = probeDownlink
}
if let expectedUplinkBitrate = map["expectedUplinkBitrate"] as? NSNumber {
config.expectedUplinkBitrate = expectedUplinkBitrate.uintValue
}
if let expectedDownlinkBitrate = map["expectedDownlinkBitrate"] as? NSNumber {
config.expectedDownlinkBitrate = expectedDownlinkBitrate.uintValue
}
return config
}
func mapToWatermarkOptions(_ map: Dictionary<String, Any>) -> WatermarkOptions {
let options = WatermarkOptions()
if let visibleInPreview = map["visibleInPreview"] as? Bool {
options.visibleInPreview = visibleInPreview
}
if let positionInLandscapeMode = map["positionInLandscapeMode"] as? Dictionary<String, Any> {
options.positionInLandscapeMode = mapToRect(positionInLandscapeMode)
}
if let positionInPortraitMode = map["positionInPortraitMode"] as? Dictionary<String, Any> {
options.positionInPortraitMode = mapToRect(positionInPortraitMode)
}
return options
}
func mapToLiveInjectStreamConfig(_ map: Dictionary<String, Any>) -> AgoraLiveInjectStreamConfig {
let config = AgoraLiveInjectStreamConfig.default()
config.size = mapToSize(map)
if let videoGop = map["videoGop"] as? NSNumber {
config.videoGop = videoGop.intValue
}
if let videoFramerate = map["videoFramerate"] as? NSNumber {
config.videoFramerate = videoFramerate.intValue
}
if let videoBitrate = map["videoBitrate"] as? NSNumber {
config.videoBitrate = videoBitrate.intValue
}
if let audioSampleRate = map["audioSampleRate"] as? NSNumber {
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) {
config.audioSampleRate = audioSampleRate
}
}
if let audioBitrate = map["audioBitrate"] as? NSNumber {
config.audioBitrate = audioBitrate.intValue
}
if let audioChannels = map["audioChannels"] as? NSNumber {
config.audioChannels = audioChannels.intValue
}
return config
}
func mapToCameraCapturerConfiguration(_ map: Dictionary<String, Any>) -> AgoraCameraCapturerConfiguration {
let config = AgoraCameraCapturerConfiguration()
if let preference = map["preference"] as? NSNumber {
if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference.intValue) {
config.preference = preference
}
}
if let captureWidth = map["captureWidth"] as? NSNumber {
config.captureWidth = captureWidth.int32Value
}
if let captureHeight = map["captureHeight"] as? NSNumber {
config.captureHeight = captureHeight.int32Value
}
if let cameraDirection = map["cameraDirection"] as? NSNumber {
if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection.intValue) {
config.cameraDirection = cameraDirection
}
}
return config
}
func mapToChannelMediaOptions(_ map: Dictionary<String, Any>) -> AgoraRtcChannelMediaOptions {
let options = AgoraRtcChannelMediaOptions()
if let autoSubscribeAudio = map["autoSubscribeAudio"] as? Bool {
options.autoSubscribeAudio = autoSubscribeAudio
}
if let autoSubscribeVideo = map["autoSubscribeVideo"] as? Bool {
options.autoSubscribeVideo = autoSubscribeVideo
}
return options
}
func mapToRtcEngineConfig(_ map: Dictionary<String, Any>) -> AgoraRtcEngineConfig {
let config = AgoraRtcEngineConfig()
config.appId = map["appId"] as? String
if let areaCode = map["areaCode"] as? NSNumber {
config.areaCode = areaCode.uintValue
}
if let logConfig = map["logConfig"] as? Dictionary<String, Any> {
config.logConfig = mapToLogConfig(logConfig)
}
return config
}
func mapToAudioRecordingConfiguration(_ map: Dictionary<String, Any>) -> AgoraAudioRecordingConfiguration {
let config = AgoraAudioRecordingConfiguration()
if let filePath = map["filePath"] as? String {
config.filePath = filePath
}
if let recordingQuality = map["quality"] as? NSNumber {
if let recordingQuality = AgoraAudioRecordingQuality.init(rawValue: recordingQuality.intValue) {
config.recordingQuality = recordingQuality
}
}
if let recordingPosition = map["recordingPosition"] as? NSNumber {
if let recordingPosition = AgoraAudioRecordingPosition.init(rawValue: recordingPosition.intValue) {
config.recordingPosition = recordingPosition
}
}
if let recordingSampleRate = map["sampleRate"] as? NSNumber {
config.recordingSampleRate = recordingSampleRate.intValue
}
return config
}
func mapToEncryptionConfig(_ map: Dictionary<String, Any>) -> AgoraEncryptionConfig {
let config = AgoraEncryptionConfig()
if let encryptionMode = map["encryptionMode"] as? NSNumber {
if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode.intValue) {
config.encryptionMode = encryptionMode
}
}
if let encryptionKey = map["encryptionKey"] as? String {
config.encryptionKey = encryptionKey
}
return config
}
func mapToRhythmPlayerConfig(_ map: Dictionary<String, Any>) -> AgoraRtcRhythmPlayerConfig {
let config = AgoraRtcRhythmPlayerConfig()
if let beatsPerMeasure = map["beatsPerMeasure"] as? NSNumber {
config.beatsPerMeasure = beatsPerMeasure.uintValue;
}
if let beatsPerMinute = map["beatsPerMinute"] as? NSNumber {
config.beatsPerMinute = beatsPerMinute.uintValue;
}
if let publish = map["publish"] as? NSNumber {
config.publish = publish.boolValue;
}
return config
}
func mapToClientRoleOptions(_ map: Dictionary<String, Any>) -> AgoraClientRoleOptions {
let options = AgoraClientRoleOptions()
if let audienceLatencyLevel = map["audienceLatencyLevel"] as? NSNumber {
if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel.intValue) {
options.audienceLatencyLevel = audienceLatencyLevel
}
}
return options
}
func mapToLogConfig(_ map: Dictionary<String, Any>) -> AgoraLogConfig {
let config = AgoraLogConfig()
config.filePath = map["filePath"] as? String
if let fileSize = map["fileSize"] as? NSNumber {
config.fileSize = fileSize.intValue
}
if let level = map["level"] as? NSNumber {
if let level = AgoraLogLevel.init(rawValue: level.intValue) {
config.level = level;
}
}
return config
}
func mapToDataStreamConfig(_ map: Dictionary<String, Any>) -> AgoraDataStreamConfig {
let config = AgoraDataStreamConfig()
if let syncWithAudio = map["syncWithAudio"] as? Bool {
config.syncWithAudio = syncWithAudio
}
if let ordered = map["ordered"] as? Bool {
config.ordered = ordered
}
return config
}