Best way to determine Webrtc media is actually flowing using Peer Connection

447 views
Skip to first unread message

Antonis Tsakiridis

unread,
Mar 24, 2016, 10:17:11 AM3/24/16
to discuss...@googlegroups.com
Hello,

We are working on an a web SDK using webrtc for media and I'm trying to determine the best way to determine with certainty if a media channel has been established to indicate it to the user application. I see that there are multiple indications but some doesn't seem as robust as others. For example:
  • At first we used peerConnection.onaddstream event, but in some cases this event fires even though STUN pings aren't successful yet
  • Then we thought of peerConnection.onicechange event which seems more precise together with using peerConnectionState (http://w3c.github.io/webrtc-pc/#rtcpeerconnectionstate-enum) of 'connected', but again seems it shows up as 'established' even though again STUN pings aren't successful yet
  • Finally, we thought again of peerConnection.onicechange but using iceConnectionState (http://w3c.github.io/webrtc-pc/#rtciceconnectionstate-enum) instead, and compare it with either 'connected' or 'completed'. If so we deem that there is actual media flowing 
Is that the best way or am I missing something?

Best regards,
Antonis Tsakiridis

Alexandre GOUAILLARD

unread,
Mar 24, 2016, 12:31:35 PM3/24/16
to discuss...@googlegroups.com
sometimes, the connection seems OK, but the media is not flowing.
testing the <audio> or <video> elements and their event (metadataloaded, ..) is an added safety to your process.
some also check the media itself (push the audio to web-audio and check is not zero, render the video, capture a canvas, check if not black). It might be too heavy in production, but very useful for unit testing.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/CAM7er2OrktVvrQAOa%3D87gU_k%3DysPs1tShWdYTzfWcMEwPRuC4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
Principal Architect - Citrix, San Francisco
President - CoSMo Software Consulting, Singapore
------------------------------------------------------------------------------------

Lorenzo Miniero

unread,
Mar 24, 2016, 3:17:46 PM3/24/16
to discuss-webrtc
An easier check that doesn't involve all that might be to look at the in/out statistics via getStats, to see if they're > 0

L.

Alexandre GOUAILLARD

unread,
Mar 24, 2016, 5:09:18 PM3/24/16
to discuss...@googlegroups.com
eventually, I think gestats will be the preferred way. 

I was not aware that it was already providing all of that info, and in a consistent way across all webrtc-supporting browsers. I was under the impression that what was reported was still very browser dependent.


For more options, visit https://groups.google.com/d/optout.

Brian Baldino

unread,
Mar 24, 2016, 5:13:51 PM3/24/16
to discuss...@googlegroups.com
If you wait for getStats to show something (i.e.received bits shows up > 0) before notifying the user (and presumably before they attached it to a video element to render), will the initial IDR be missed?  I'd assume it'd get decoded and then the decoded frame would go nowhere since no renderer was attached?

Antonis Tsakiridis

unread,
Mar 25, 2016, 5:30:32 AM3/25/16
to discuss-webrtc
Thanks you all for the ideas. All these will surely be very helpful for testing/troubleshooting, but right now what I'm interested in is something a bit different. 

I just want to know when PeerConnection regards the channel ready to send/receive media so that I can tell the application that they are connected (i.e. when STUN checks are successful for a pair and to the best of PC knowledge media can flow). As an example imagine a voip client application that wants to know when it should show in the UI that the user is 'connected' and start a call timer. 

Which PC event best informs us of this? I'm getting the impression that the best way to do it is to wait for peerConnection.onicechange and checking if iceConnectionState is either 'connected' or 'completed'. Does this sound right?

Best regards,
Antonis

Lorenzo Miniero

unread,
Mar 25, 2016, 5:45:22 AM3/25/16
to discuss-webrtc
Il giorno giovedì 24 marzo 2016 22:09:18 UTC+1, Alexandre GOUAILLARD ha scritto:
eventually, I think gestats will be the preferred way. 

I was not aware that it was already providing all of that info, and in a consistent way across all webrtc-supporting browsers. I was under the impression that what was reported was still very browser dependent.



I think the format of the info still differs in most aspects (that is, you'll have to look for different stuff in Firefox and Chrome), or at least it was when I played with this a few months ago, but it seemed to work fine.

L.
Reply all
Reply to author
Forward
0 new messages