What is the proper order of operations for starting and ending WebRTC sessions?

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:

  1. Create webrtc connection - MLWebRTC.PeerConnection.CreateRemote()
  2. Create and connect to camera - MLCamera.CreateAndConnect()
  3. Create local video source - MLWebRTC.MLCameraVideoSource.CreateLocal()
  4. Create local media stream - MLWebRTC.MediaStream.CreateWithAppDefinedVideoTrack()
  5. Add audio/video tracks to webrtc connection - MLWebRTC.PeerConnection.AddLocalTrack()
  6. Create and add data channel to webrtc connection - MLWebRTC.DataChannel.CreateLocal()
  7. Create offers - MLWebRTC.PeerConnection.CreateOffer()
  8. Wait for answers...
  9. Set remote answer - MLWebRTC.PeerConnection.SetRemoteAnswer
  10. Consume ices candidates - MLWebRTC.PeerConnection.AddRemoteIceCandidate()
  11. Wait for connection complete event...
  12. Enable audio/video tracks - MLWebRTC.MediaStream.Track.SetEnabled(true)

Shutdown:

  1. Disable audio/video tracks - MLWebRTC.MediaStream.Track.SetEnabled(false)
  2. Destroy local video source - MLWebRTC.MLCameraVideoSource.DestroyLocal()
  3. Wait for local video source to stop capturing...
  4. Disconnect camera - MLCamera.Disconnect()
  5. Destroy local media stream - MLWebRTC.MediaStream.DestroyLocal()
  6. Destroy data channel - MLWebRTC.DataChannel.Destroy()
  7. 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

1 Like

Hi @colden.prime,

That sequence looks correct to me. I asked for an additional pair of eyes to investigate the problem you are having. I'll report back as soon as I get more information.

1 Like

@colden.prime we are investigating an issue on the OS level that prevents applications from receiving the Application Quit or Application Focus events. I will let you know as soon as I have more information.

1 Like