@@ -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
0 commit comments