I am wondering what is the proper order of operations for starting and ending WebRTC sessions so that the camera/connection are properly instantiated and disposed.
From the example code and my own implementations, the order appears to be:
Startup:
- Create webrtc connection - MLWebRTC.PeerConnection.CreateRemote()
- Create and connect to camera - MLCamera.CreateAndConnect()
- Create local video source - MLWebRTC.MLCameraVideoSource.CreateLocal()
- Create local media stream - MLWebRTC.MediaStream.CreateWithAppDefinedVideoTrack()
- Add audio/video tracks to webrtc connection - MLWebRTC.PeerConnection.AddLocalTrack()
- Create and add data channel to webrtc connection - MLWebRTC.DataChannel.CreateLocal()
- Create offers - MLWebRTC.PeerConnection.CreateOffer()
- Wait for answers...
- Set remote answer - MLWebRTC.PeerConnection.SetRemoteAnswer
- Consume ices candidates - MLWebRTC.PeerConnection.AddRemoteIceCandidate()
- Wait for connection complete event...
- Enable audio/video tracks - MLWebRTC.MediaStream.Track.SetEnabled(true)
Shutdown:
- Disable audio/video tracks - MLWebRTC.MediaStream.Track.SetEnabled(false)
- Destroy local video source - MLWebRTC.MLCameraVideoSource.DestroyLocal()
- Wait for local video source to stop capturing...
- Disconnect camera - MLCamera.Disconnect()
- Destroy local media stream - MLWebRTC.MediaStream.DestroyLocal()
- Destroy data channel - MLWebRTC.DataChannel.Destroy()
- Destroy webrtc connection - MLWebRTC.PeerConnection.Destroy()
Note: Occasionally, when shutting down a session, the green camera indicator in the upper left remains active and I am unable to start future sessions until I kill my application and/or restart the device.
So my questions are:
- Are all of these operations necessary for startup/shutdown?
- Is this the correct order for operations?
- Are any additional wait intervals required to prevent these operations for conflicting with each other?
ML2 OS version: B3E.220818.12-R.085
MLSDK version: 0.53.3