Skip to content

Commit 5c98e9c

Browse files
author
xianing
committed
adapt 3.6.0 for macos
1 parent f8ec233 commit 5c98e9c

6 files changed

Lines changed: 57 additions & 45 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import static io.agora.rtc.Constants.ERR_TIMEDOUT;
4343
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT;
4444
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR;
45+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_NET_DOWN;
4546
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_OK;
47+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND;
4648
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
4749
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
4850
import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
@@ -525,7 +527,9 @@ public void onRtmpStreamingStateChanged(String url, int state, int errorType) {
525527
} else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_FAILURE) {
526528
engine.stopRtmpStream(et_url.getText().toString());
527529
if((errorType == RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT
528-
|| errorType == RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR))
530+
|| errorType == RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR
531+
|| errorType == RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND
532+
|| errorType == RTMP_STREAM_PUBLISH_ERROR_NET_DOWN))
529533
{
530534
/**if failed, make changes to the UI.*/
531535
retryTask.cancel(true);

iOS/APIExample/Examples/Advanced/CustomPcmAudioSource/CustomPcmAudioSource.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ extension CustomPcmAudioSourceMain: AgoraPcmSourcePushDelegate {
156156
frame.bytesPerSample = 32 * 8
157157
frame.samplesPerChannel = self.samples / 2
158158
let ret = agoraKit.pushExternalAudioFrameRawData(pushPos, frame: frame)
159-
agoraKit.pushExternalAudioFrameRawData(data, samples: samples, timestamp: 0)
160159
print("push result: \(ret)")
161160
}
162161
}

iOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ extension RTMPStreamingMain: AgoraRtcEngineDelegate {
331331
}
332332
} else if state == .failure {
333333
agoraKit.stopRtmpStream(rtmpURL)
334-
if errorCode == .streamingErrorCodeInternalServerError || errorCode == .streamingErrorCodeConnectionTimeout {
334+
if errorCode == .streamingErrorCodeInternalServerError
335+
|| errorCode == .streamingErrorCodeStreamNotFound
336+
|| errorCode == .streamPublishErrorNetDown
337+
|| errorCode == .streamingErrorCodeConnectionTimeout {
335338
self.showAlert(title: "Error", message: "RTMP Publish Failed: \(errorCode.rawValue)")
336339
stopRetryTimer()
337340
unpublishing = true

macOS/APIExample/Examples/Advanced/JoinMultiChannel/JoinMultiChannel.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class JoinMultipleChannel: BaseViewController {
7575
}
7676
} else {
7777
channel1?.leave()
78-
if let channelName = channel1?.getId() {
78+
if let channelName = channel1?.getChannelId() {
7979
if isPublished && channelName == selectedChannel {
8080
if let channel = getChannelByName(selectedChannel) {
8181
channel.setClientRole(.audience)
@@ -147,7 +147,7 @@ class JoinMultipleChannel: BaseViewController {
147147
}
148148
} else {
149149
channel2?.leave()
150-
if let channelName = channel2?.getId() {
150+
if let channelName = channel2?.getChannelId() {
151151
if isPublished && channelName == selectedChannel {
152152
if let channel = getChannelByName(selectedChannel) {
153153
channel.setClientRole(.audience)
@@ -258,9 +258,9 @@ class JoinMultipleChannel: BaseViewController {
258258
}
259259

260260
func getChannelByName(_ channelName: String?) -> AgoraRtcChannel? {
261-
if channel1?.getId() == channelName {
261+
if channel1?.getChannelId() == channelName {
262262
return channel1
263-
} else if channel2?.getId() == channelName {
263+
} else if channel2?.getChannelId() == channelName {
264264
return channel2
265265
}
266266
return nil
@@ -305,8 +305,8 @@ extension JoinMultipleChannel: AgoraRtcEngineDelegate {
305305

306306
extension JoinMultipleChannel: AgoraRtcChannelDelegate {
307307
func rtcChannelDidJoin(_ rtcChannel: AgoraRtcChannel, withUid uid: UInt, elapsed: Int) {
308-
LogUtils.log(message: "Join \(rtcChannel.getId() ?? "") with uid \(uid) elapsed \(elapsed)ms", level: .info)
309-
selectChannelsPicker.picker.addItem(withTitle: rtcChannel.getId()!)
308+
LogUtils.log(message: "Join \(rtcChannel.getChannelId() ?? "") with uid \(uid) elapsed \(elapsed)ms", level: .info)
309+
selectChannelsPicker.picker.addItem(withTitle: rtcChannel.getChannelId()!)
310310
if (channel1 == rtcChannel) {
311311
isJoined = true
312312
} else {
@@ -320,7 +320,7 @@ extension JoinMultipleChannel: AgoraRtcChannelDelegate {
320320
/// cn: https://docs.agora.io/cn/Voice/API%20Reference/oc/Constants/AgoraWarningCode.html
321321
/// @param warningCode warning code of the problem
322322
func rtcChannel(_ rtcChannel: AgoraRtcChannel, didOccurWarning warningCode: AgoraWarningCode) {
323-
LogUtils.log(message: "channel: \(rtcChannel.getId() ?? ""), warning: \(warningCode.rawValue)", level: .warning)
323+
LogUtils.log(message: "channel: \(rtcChannel.getChannelId() ?? ""), warning: \(warningCode.rawValue)", level: .warning)
324324
}
325325

326326
/// callback when error occured for a channel, you are recommended to display the error descriptions on demand
@@ -349,7 +349,7 @@ extension JoinMultipleChannel: AgoraRtcChannelDelegate {
349349
videoCanvas.view = channel1 == rtcChannel ? videos2[0].videocanvas : videos2[1].videocanvas
350350
videoCanvas.renderMode = .hidden
351351
// set channelId so that it knows which channel the video belongs to
352-
videoCanvas.channelId = rtcChannel.getId()
352+
videoCanvas.channelId = rtcChannel.getChannelId()
353353
agoraKit.setupRemoteVideo(videoCanvas)
354354
}
355355

@@ -369,7 +369,7 @@ extension JoinMultipleChannel: AgoraRtcChannelDelegate {
369369
videoCanvas.view = nil
370370
videoCanvas.renderMode = .hidden
371371
// set channelId so that it knows which channel the video belongs to
372-
videoCanvas.channelId = rtcChannel.getId()
372+
videoCanvas.channelId = rtcChannel.getChannelId()
373373
agoraKit.setupRemoteVideo(videoCanvas)
374374
}
375375
}

macOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RTMPStreaming: BaseViewController {
2020
var agoraKit: AgoraRtcEngineKit!
2121

2222
var transcoding = AgoraLiveTranscoding.default()
23-
23+
2424
/**
2525
--- rtmpUrls Picker ---
2626
*/
@@ -47,7 +47,7 @@ class RTMPStreaming: BaseViewController {
4747
rtmpURLs.remove(at: selectRtmpUrlsPicker.indexOfSelectedItem)
4848
selectRtmpUrlsPicker.picker.removeItem(at: selectRtmpUrlsPicker.indexOfSelectedItem)
4949
}
50-
50+
5151
/// callback when remove all streaming url button hit
5252
@IBAction func onRemoveAllStreamingURL(_ sender: Any) {
5353
for url in rtmpURLs {
@@ -56,7 +56,7 @@ class RTMPStreaming: BaseViewController {
5656
rtmpURLs = []
5757
selectRtmpUrlsPicker.picker.removeAllItems()
5858
}
59-
59+
6060
/**
6161
--- Channel TextField ---
6262
*/
@@ -65,7 +65,7 @@ class RTMPStreaming: BaseViewController {
6565
channelField.label.stringValue = "Channel".localized
6666
channelField.field.placeholderString = "Channel Name".localized
6767
}
68-
68+
6969
/**
7070
--- rtmp TextField ---
7171
*/
@@ -89,44 +89,49 @@ class RTMPStreaming: BaseViewController {
8989
showAlert(title: "Add Streaming URL Failed", message: "RTMP URL cannot be empty or not start with 'rtmp://'")
9090
return
9191
}
92-
92+
9393
if transcodingEnabled {
9494
// we will use transcoding to composite multiple hosts' video
9595
// therefore we have to create a livetranscoding object and call before addPublishStreamUrl
9696
transcoding.size = CGSize(width: CANVAS_WIDTH, height: CANVAS_HEIGHT)
97-
agoraKit.setLiveTranscoding(transcoding)
97+
agoraKit.updateRtmpTranscoding(transcoding)
9898
}
99-
99+
100100
// start publishing to this URL
101-
agoraKit.addPublishStreamUrl(rtmpURL, transcodingEnabled: transcodingEnabled)
101+
if transcodingEnabled {
102+
agoraKit.startRtmpStreamWithTranscoding(rtmpURL, transcoding: transcoding)
103+
}
104+
else {
105+
agoraKit.startRtmpStreamWithoutTranscoding(rtmpURL)
106+
}
102107
// update properties and UI
103108
rtmpURLs.append(rtmpURL)
104109
selectRtmpUrlsPicker.picker.addItem(withTitle: rtmpURL)
105110
}
106-
111+
107112
/**
108113
--- Button ---
109114
*/
110115
@IBOutlet weak var joinChannelButton: NSButton!
111116
func initJoinChannelButton() {
112117
joinChannelButton.title = isJoined ? "Leave Channel".localized : "Join Channel".localized
113118
}
114-
119+
115120
// indicate if current instance has joined channel
116121
var isJoined: Bool = false {
117122
didSet {
118123
channelField.isEnabled = !isJoined
119124
initJoinChannelButton()
120125
}
121126
}
122-
127+
123128
// indicate for doing something
124129
var isProcessing: Bool = false {
125130
didSet {
126131
joinChannelButton.isEnabled = !isProcessing
127132
}
128133
}
129-
134+
130135
override func viewDidLoad() {
131136
super.viewDidLoad()
132137
layoutVideos(2)
@@ -136,13 +141,13 @@ class RTMPStreaming: BaseViewController {
136141
config.areaCode = GlobalSettings.shared.area.rawValue
137142
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
138143
agoraKit.enableVideo()
139-
144+
140145
initSelectRtmpUrlsPicker()
141146
initRtmpURLField()
142147
initChannelField()
143148
initJoinChannelButton()
144149
}
145-
150+
146151
override func viewWillBeRemovedFromSplitView() {
147152
if isJoined {
148153
agoraKit.leaveChannel { (stats:AgoraChannelStats) in
@@ -151,7 +156,7 @@ class RTMPStreaming: BaseViewController {
151156
}
152157
AgoraRtcEngineKit.destroy()
153158
}
154-
159+
155160
@IBAction func onJoinPressed(_ sender:Any) {
156161
if !isJoined {
157162
// check configuration
@@ -180,7 +185,7 @@ class RTMPStreaming: BaseViewController {
180185
videoCanvas.view = localVideo.videocanvas
181186
videoCanvas.renderMode = .hidden
182187
agoraKit.setupLocalVideo(videoCanvas)
183-
188+
184189
// start joining channel
185190
// 1. Users can only see each other after they join the
186191
// same channel successfully using the same app id.
@@ -240,7 +245,7 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
240245
func rtcEngine(_ engine: AgoraRtcEngineKit, didOccurWarning warningCode: AgoraWarningCode) {
241246
LogUtils.log(message: "warning: \(warningCode.rawValue)", level: .warning)
242247
}
243-
248+
244249
/// callback when error occured for agora sdk, you are recommended to display the error descriptions on demand
245250
/// to let user know something wrong is happening
246251
/// Error code description can be found at:
@@ -254,7 +259,7 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
254259
}
255260
self.showAlert(title: "Error", message: "Error \(errorCode.rawValue) occur")
256261
}
257-
262+
258263
/// callback when the local user joins a specified channel.
259264
/// @param channel
260265
/// @param uid uid of local user
@@ -265,21 +270,21 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
265270
let localVideo = videos[0]
266271
localVideo.uid = uid
267272
LogUtils.log(message: "Join \(channel) with uid \(uid) elapsed \(elapsed)ms", level: .info)
268-
273+
269274
// add transcoding user so the video stream will be involved
270275
// in future RTMP Stream
271276
let user = AgoraLiveTranscodingUser()
272277
user.rect = CGRect(x: 0, y: 0, width: CANVAS_WIDTH / 2, height: CANVAS_HEIGHT)
273278
user.uid = uid
274279
transcoding.add(user)
275280
}
276-
281+
277282
/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
278283
/// @param uid uid of remote joined user
279284
/// @param elapsed time elapse since current sdk instance join the channel in ms
280285
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
281286
LogUtils.log(message: "remote user join: \(uid) \(elapsed)ms", level: .info)
282-
287+
283288
// find a VideoView w/o uid assigned
284289
if let remoteVideo = videos.first(where: { $0.uid == nil }) {
285290
let videoCanvas = AgoraRtcVideoCanvas()
@@ -292,24 +297,24 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
292297
} else {
293298
LogUtils.log(message: "no video canvas available for \(uid), cancel bind", level: .warning)
294299
}
295-
300+
296301
// update live transcoding
297302
// add new user onto the canvas
298303
let user = AgoraLiveTranscodingUser()
299304
user.rect = CGRect(x: CANVAS_WIDTH / 2, y: 0, width: CANVAS_WIDTH / 2, height: CANVAS_HEIGHT)
300305
user.uid = uid
301306
self.transcoding.add(user)
302307
// remember you need to call setLiveTranscoding again if you changed the layout
303-
agoraKit.setLiveTranscoding(transcoding)
308+
agoraKit.updateRtmpTranscoding(transcoding)
304309
}
305-
310+
306311
/// callback when a remote user is leaving the channel, note audience in live broadcast mode will NOT trigger this event
307312
/// @param uid uid of remote joined user
308313
/// @param reason reason why this user left, note this event may be triggered when the remote user
309314
/// become an audience in live broadcasting profile
310315
func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
311316
LogUtils.log(message: "remote user left: \(uid) reason \(reason)", level: .info)
312-
317+
313318
// to unlink your view from sdk, so that your view reference will be released
314319
// note the video will stay at its last frame, to completely remove it
315320
// you will need to remove the EAGL sublayer from your binded view
@@ -324,13 +329,13 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
324329
} else {
325330
LogUtils.log(message: "no matching video canvas for \(uid), cancel unbind", level: .warning)
326331
}
327-
332+
328333
// remove user from canvas if current cohost left channel
329334
transcoding.removeUser(uid)
330335
// remember you need to call setLiveTranscoding again if you changed the layout
331-
agoraKit.setLiveTranscoding(transcoding)
336+
agoraKit.updateRtmpTranscoding(transcoding)
332337
}
333-
338+
334339
/// callback for state of rtmp streaming, for both good and bad state
335340
/// @param url rtmp streaming url
336341
/// @param state state of rtmp streaming

macOS/APIExample/Examples/Advanced/ScreenShare/ScreenShare.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ScreenShare: BaseViewController {
7171
let params = AgoraScreenCaptureParameters()
7272
params.frameRate = fps
7373
params.dimensions = resolution.size()
74-
self.agoraKit.update(params)
74+
self.agoraKit.updateScreenCaptureParameters(params)
7575
} else {
7676
self.agoraKit.setVideoEncoderConfiguration(
7777
AgoraVideoEncoderConfiguration(
@@ -114,7 +114,7 @@ class ScreenShare: BaseViewController {
114114
let params = AgoraScreenCaptureParameters()
115115
params.frameRate = fps
116116
params.dimensions = resolution.size()
117-
self.agoraKit.update(params)
117+
self.agoraKit.updateScreenCaptureParameters(params)
118118
} else {
119119
self.agoraKit.setVideoEncoderConfiguration(
120120
AgoraVideoEncoderConfiguration(
@@ -151,7 +151,7 @@ class ScreenShare: BaseViewController {
151151
}
152152
guard let displayHint = self.selectedDisplayHint else { return }
153153
print("setScreenCapture")
154-
self.agoraKit.setScreenCapture(displayHint)
154+
self.agoraKit.setScreenCaptureContentHint(displayHint)
155155
}
156156
}
157157

@@ -203,7 +203,8 @@ class ScreenShare: BaseViewController {
203203
let params = AgoraScreenCaptureParameters()
204204
params.frameRate = fps
205205
params.dimensions = resolution.size()
206-
let result = agoraKit.startScreenCapture(byDisplayId: UInt(screen.sourceId), rectangle: .zero, parameters: params)
206+
let result = agoraKit.startScreenCaptureByDisplayId(UInt(screen.sourceId), rectangle: .zero, parameters: params)
207+
207208
if result != 0 {
208209
// Usually happens with invalid parameters
209210
// Error code description can be found at:
@@ -261,7 +262,7 @@ class ScreenShare: BaseViewController {
261262
let params = AgoraScreenCaptureParameters()
262263
params.frameRate = fps
263264
params.dimensions = resolution.size()
264-
let result = agoraKit.startScreenCapture(byWindowId: UInt(window.id), rectangle: .zero, parameters: params)
265+
let result = agoraKit.startScreenCaptureByWindowId(UInt(window.id), rectangle: .zero, parameters: params)
265266
if result != 0 {
266267
// Usually happens with invalid parameters
267268
// Error code description can be found at:

0 commit comments

Comments
 (0)