meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.23k stars 2.48k forks source link

"old format" datachannel SDP not compatible with gstreamer webrtcbin #2112

Closed petergerten closed 4 years ago

petergerten commented 4 years ago

Janus: master(today) GStreamer: 1.16.2

Connecting to the Janus streaming plugin with datachannel enabled using gstreamer, I get an ICE failure. Without datachannel there is no problem.

Relevant messages in gstreamer log:

0:00:00.259345377   361 0x7f99e8002920 INFO               webrtcbin gstwebrtcbin.c:2696:_create_answer_task:<sendrecv> media 1 rejected
0:00:00.299125377   263 0x7f9c98002920 ERROR              webrtcbin gstwebrtcbin.c:3540:_set_description_task:<sendrecv> Fingerprint in media 1 differs from previous fingerprint. 'sha-256 DE:6C:9F:12:C1:35:C0:80:BE:29:54:64:AB:6E:34:D6:8D:46:00:FE:FC:06:FE:26:7B:C7:F5:A6:6A:92:17:D6' != 'sha-256 FA:A1:91:73:AD:95:99:76:18:3B:5A:1B:3F:FA:C8:86:CE:96:4F:41:B6:C8:75:50:36:EA:38:D8:18:80:3D:B3'

This issue has been observed before (though not with Janus), but not solved. The poster in the below thread disabled datachannels: https://github.com/centricular/gstwebrtc-demos/issues/113

The conclusion in that thread was: "The datachannel format used in that SDP is the old format that is not supported by webrtcbin which is hinted at by the 0 port in the sdp answer and the log line '0:00:12.855077000 82505 0x7fb402c50320 INFO webrtcbin gstwebrtcbin.c:2168:_create_answer_task: media 2 rejected'"

Now I am not sure what the "old format" SDP that is not supported by webrtcbin is. This is the SDP from janus in question: https://pastebin.com/MhanpECW

petergerten commented 4 years ago

Debugging this further I found: 0:00:01.060533443 546 0x7f5cd8002920 WARN webrtcbin gstwebrtcbin.c:2516:_create_answer_task:<sendrecv> format field of data channel m= line is not 'webrtc-datachannel'

The root cause seems to be this (but with Janus instead of Chrome) https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/commit/831b12497613a33ae578c529569402118c392ac9

Apparently there is a workaround for old SDP format in gstreamer master but not in the latest release (1.16.2).

lminiero commented 4 years ago

We support both old and new format in the core, since at least some time ago Chrome and Firefox had different kind of supports. Typically, when it's the browser offering, we reply using the format that was offered, for better compatibility. When it's Janus offering, it's different of course, as we don't know in advance what will be supported: it's usually up to plugins, and good chances are the Streaming plugin is still using the old syntax in its template.

The template to generate the datachannel m-line is here, so you can try tweaking that to use the new syntax instead: https://github.com/meetecho/janus-gateway/blob/master/plugins/janus_streaming.c#L4782-L4784

If you can confirm it works with gstreamer, we can check if browsers are known to all use the new approach and possibly stick to it.

petergerten commented 4 years ago

Thanks Lorenzo. After I changed the relevant lines in janus_streaming.c to:

g_snprintf(buffer, 512,
"m=application 54111 UDP/DTLS/SCTP webrtc-datachannel\r\n"
"a=sctp-port:5000\r\n"
"c=IN IP4 1.1.1.1\r\n");

everything works.

lminiero commented 4 years ago

Changed both Streaming and TextRoom plugins so that they use the proper way of negotiating datachannels: https://github.com/meetecho/janus-gateway/commit/f8cc4f70c8dbaccc71d69207e4b32da5c19b7c95. I tested this briefly with recent versions of Chrome and Firefox and it seemed to work as expected.