<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Timothée Le Borgne on Medium]]></title>
        <description><![CDATA[Stories by Timothée Le Borgne on Medium]]></description>
        <link>https://medium.com/@timleborgne?source=rss-d048d03b03bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BuwBJoxZKH-2QHKc10iVxA.jpeg</url>
            <title>Stories by Timothée Le Borgne on Medium</title>
            <link>https://medium.com/@timleborgne?source=rss-d048d03b03bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:11:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@timleborgne/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Playing with RTCP REMB #WebRTC]]></title>
            <link>https://medium.com/tribe-staff/playing-with-rtcp-remb-webrtc-746f565f750f?source=rss-d048d03b03bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/746f565f750f</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[remb]]></category>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[crpt]]></category>
            <category><![CDATA[webrtc]]></category>
            <dc:creator><![CDATA[Timothée Le Borgne]]></dc:creator>
            <pubDate>Thu, 01 Feb 2018 21:25:55 GMT</pubDate>
            <atom:updated>2018-02-01T22:52:08.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-OPLONPMA26mkzBpSXCSHA.jpeg" /></figure><h4>Controlling &amp; fine-tuning stream quality using REMB</h4><p>So, by now, you should already know we’ve been working on building a custom WebRTC MCU for Tribe — <em>if not, you should check out </em><a href="https://medium.com/tribe-staff/why-were-coding-a-mcu-from-scratch-webrtc-45a9b3ca72db"><em>why we decided to do it</em></a><em>, and </em><a href="https://medium.com/tribe-staff/down-the-mcu-road-with-gstreamer-webrtc-d1df48a93492"><em>how we’re proceeding</em></a><em> :-)</em></p><p>Let’s get a bit more ‘hands-on’ now, and see what actually happens behind the curtains.</p><ol><li>A WebRTC communication starts with an exchange mechanism called “SDP offer/answer” — it’s an exchange of capabilities — supported codecs and associated parameters — between participating peers, to set up the session up.</li><li>Once the exchange is set, peers will try to communicate directly with each other: they’ll start listening to UDP ports, and use ICE, STUN and eventually TURN to establish a UDP connection.</li><li>Once the UDP connection is established, peers will use it to exchange cryptographic parameters using the DTLS-SRTP protocol. Once they’re sent, they’ll use both:</li></ol><ul><li>the SRTP protocol (Secure RTP, on top of UDP) to <strong>send and receive media</strong></li><li>the SRTCP protocol (Secure RTCP, on top of UDP) to <strong>exchange flow control and </strong><a href="https://en.wikipedia.org/wiki/Out-of-band_data"><strong>out-of-band statistics</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*usnfeQYk2Orx2-xv." /><figcaption><em>WebRTC protocol stack • (image modified. Original at: </em><a href="http://webrtc-security.github.io/"><em>http://webrtc-security.github.io/</em></a><em> )</em></figcaption></figure><p><strong>Focus on RTCP</strong></p><p>As said, RTP &amp; RTCP packets are securely contained in SRTP &amp; SRTCP. What are they used for?</p><p>Well, RTP provides end-to-end network transport functions for transmitting real-time data: audio &amp; video. In a way, RTCP is the “sister protocol of RTP”: it’s used alongside RTP and enhances the data transport protocol with monitoring of the data delivery, as well as control and identification capabilities.</p><p>During a WebRTC session, the MCU acts as a substitute for a peer: all peers actually connect to the MCU, and not directly to each other (≠ mesh).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*psj6M43vAzrd01QG." /><figcaption>WebRTC — basic MCU Topology</figcaption></figure><p>Let’s take a 2-peer session, as an example. The MCU receives a media stream (audio/video) from FOO, decodes it, encodes it and sends it to BAR. It does exactly the same thing at the same time, with the media stream received from BAR, to FOO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*L2HiLNV6hulZUphY." /><figcaption><em>Media transport protocol &amp; RTP control protocol</em></figcaption></figure><p>Now, we know it’s a perfectly symmetrical situation, so let’s just focus on one side, to see what happens there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*iKPCf64DSNpJMOCC." /><figcaption>Focus on one side</figcaption></figure><p>When BAR’s browser receives a media stream from the MCU, it also receives at the same time stats from RTCP Sender Reports (SR). BAR’s browser will use the RTP packet sequence numbers, RTP Packet timestamps, its own clock time, and the Sender Reports to compute what we call RTCP Receiver reports (RR).</p><p>BAR’s browser will use all these stats to compute a maximum estimated bitrate, and will then send this info to the MCU using RTCP REMB (Remote Estimate Maximum Bitrate).</p><p><strong>Making (good!) use of REMB</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5aD9c0AugI1DIFGxN--OEA.jpeg" /><figcaption><em>RTCP REMB packet format • </em><a href="https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-00#section-2.2"><em>https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-00#section-2.2</em></a></figcaption></figure><p>The estimated maximum bitrate value is encoded in BR Exp &amp; BR Mantissa fields.</p><blockquote>You can see an example implementation looking at chromium code: <a href="https://cs.chromium.org/chromium/src/third_party/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc">https://cs.chromium.org/chromium/src/third_party/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc</a></blockquote><p>In golang, we mapped this message to a PacketALFBRemb struct:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2854b2be744b5ff051488437a334d7d2/href">https://medium.com/media/2854b2be744b5ff051488437a334d7d2/href</a></iframe><p>In such case where you want to read the bitrate from that structure, you can do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/deb195fa5654dd3d65ab4f710057d322/href">https://medium.com/media/deb195fa5654dd3d65ab4f710057d322/href</a></iframe><p>If instead, you have the bitrate value and want to write the Exp and Mantissa fields into into a PacketALFBRemb struct, you’ll do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9569dfa8a5d7a0a9211dfbe1005833b/href">https://medium.com/media/e9569dfa8a5d7a0a9211dfbe1005833b/href</a></iframe><p><strong>Optimizing bandwidth using RTCP REMB</strong></p><p>That’s one of the perks of using an MCU: it can forge a REMB RTCP packet to take control over the browser’s output bitrate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*nDMIPf-RuSwkD-K8." /><figcaption><em>MCU sending a RTCP REMB to control FOO’s browser bitrate output</em></figcaption></figure><p>Also, the MCU can use the receiver browser’s estimation to change its own encoder parameters to match the maximum estimate bitrate, and optimize the MCU output bandwidth:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*fhLWgVWkCqC63SdL." /><figcaption><em>MCU modulating its encoder output using BAR’s RTCP REMB stats</em></figcaption></figure><p><strong>Controlling the bitrate</strong></p><p>So, how to can you actually test the impact of RTCP REMB packet on FOO’s bitrate? Well, simply enough: simply send REMB packets with alternate bitrates of, let’s say, 64kb &amp; 128kb every 10 seconds, and have a look to <strong>chrome://webrtc-internals</strong> graphs to see how it behaves.</p><p>Implementing this using Go would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e5460fa95c8b44b0ad8323820107861/href">https://medium.com/media/3e5460fa95c8b44b0ad8323820107861/href</a></iframe><p>Open <strong>chrome://webrtc-internals</strong> and you should see something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*0fh8WGhL7yWYiBxT." /></figure><p>…which will definitely confirm that you’re able to monitor and manipulate your peer’s stream bitrate, real-time. It’s up to you to find out what parameters will best fit your use cases, and help optimize bandwidth and stream quality :-)</p><p>Now, you’ll have probably noticed that RTCP REMB is now <em>deprecated. </em>There’s this idea that bandwidth management should be done by the publisher himself (instead of a remote peer) — well, the goal here was to show that it’s certainly still possible to make good use of it, as just demonstrated.</p><p>In our case, we found it really useful to gain granular control over both bandwidth consumption and peers stream quality :-)</p><p><em>(With ❤️ from Tim, Sébastien, Marc &amp; Germ</em>á<em>n @Tribe Video)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=746f565f750f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tribe-staff/playing-with-rtcp-remb-webrtc-746f565f750f">Playing with RTCP REMB #WebRTC</a> was originally published in <a href="https://medium.com/tribe-staff">Inside Tribe</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Down the MCU road with GStreamer #WebRTC]]></title>
            <link>https://medium.com/tribe-staff/down-the-mcu-road-with-gstreamer-webrtc-d1df48a93492?source=rss-d048d03b03bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1df48a93492</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[gstreamer]]></category>
            <category><![CDATA[rtpbin]]></category>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[live-streaming]]></category>
            <dc:creator><![CDATA[Timothée Le Borgne]]></dc:creator>
            <pubDate>Fri, 26 Jan 2018 20:30:43 GMT</pubDate>
            <atom:updated>2018-01-27T11:17:22.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2_pCfBRIO0CzRfEKG3FUA.jpeg" /></figure><h4>Replacing <strong>rtpbin</strong> with an in-house solution</h4><p><em>(Disclaimer: without some network/webRTC knowledge, you might struggle a bit with this post)</em></p><p>If you’re building your own MCU — <a href="https://medium.com/tribe-staff/why-were-coding-a-mcu-from-scratch-webrtc-45a9b3ca72db">just like us, at Tribe</a> — then at one point you’ll need to handle RTP/RTCP. And if you chose to build upon GStreamer, it’s very likely you’ll be introducing <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good/html/gst-plugins-good-plugins-rtpbin.html"><strong>rtpbin</strong></a> in your pipeline at some point.</p><p>rtpbin is a meta-plugin of sorts, that:</p><blockquote>[…] combines the functions of GstRtpSession, GstRtpSsrcDemux, GstRtpJitterBuffer and GstRtpPtDemux in one element.</blockquote><p>Specifically (and amongst other things, because it also takes handles the demuxing part), it takes care of re-ordering successfully received RTP packets and handling lost ones, which is all good when it works fine — but in our case, it unfortunately didn’t.</p><p>Or rather, we didn’t manage to tweak it the way we wanted, and started getting serious headaches as to why!</p><p>We found out rtpbin would send, for no reason, a<strong> disproportionate amount of </strong><a href="https://webrtcglossary.com/nack/"><strong>NACKs</strong></a> leading to a <strong>drastic decrease in stream quality</strong>: not only did it actually have the packets, but asking for them again consumed much bandwidth, for nothing.</p><p>After a few days spent trying to tweak rtpbin in every possible way, we found out we had 3 options:</p><ul><li>dig deep into the code / rebuilt it to understand precisely what went wrong, in our case</li><li>try and implement a workaround solution by directly using the sub-plugins rtpbin comprises (i.e, still use the GStreamer pipeline)</li><li>implement our own solution</li></ul><p>We did the maths, and realized patching it would require more work than simply <strong>re-coding our own</strong>, because we had already done all the RTCP parsing work previously, using Golang, so we figured out the “only” remaining part would be handling the jitter-buffer, so… that’s what we did.</p><p>I should point out that it’s really NOT easy. It’s a lot of work, but it’s also very beneficial: you end up knowing every nook and cranny of the protocols and you get to choose the language (in our case Go, and not C).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ptXCK5IpP3RY2DRfizezlw.jpeg" /><figcaption>Tribe MCU, quick glimpse at the generic structure</figcaption></figure><p><strong>But most of all, it enables deep and full control over how quality is going to be managed</strong>, mostly through packet reordering &amp; jitter-buffer calculation/monitoring.</p><p>Here’s how we calculated the <strong>dynamic jitter</strong>:</p><blockquote>Jitter = [<a href="https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Round-trip_delay_time.html">RTT</a>] + [3 * avgTimeBetweenRTPPackets]</blockquote><p>In case of a NACK, the second part of the formula enables enough time to ask clients for missing packets, receive them and re-order them so as to send a consistent stream back to whatever peer the MCU was serving.</p><p>Let’s take an example : a 25 FPS stream typically has a 20ms spacing between RTP packets. So if your RTT is 100ms, that means your jitter is about 160ms, and you can put together quality control mechanisms, like:</p><ul><li>whenever you think a packet is late, if delay &gt; 20 ms (for instance) then you send a NACK (because you’ll still have 40s left to squeeze it in)</li><li>If packet is still not received, no need to NACK again: not enough buffer left to take it in anyway (but if you happened to have a shorter RTT, you could have sent several more NACKs, and maybe get that missing packet back)</li><li>If that happens too frequently (you decide the frequency), it either means that your client struggles with encoding, or the network experiences congestion — in which case, you’ll probably send a <a href="https://webrtcglossary.com/pli/">PLI</a> and request a whole keyframe, as well as lower bitrate expectations a bit, to smoothen things out until it gets better</li></ul><p>What happens if you don’t handle that part? As I said before, pretty blatant quality loss: you miss packets, so intra-frames can’t be correctly predicted, and you end up with artefacts, that will last until you send PLI requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*tDqAzJWDqJq8Nha7Q5QBsw.jpeg" /><figcaption><em>Artefacts, due to (a lot of!) packet loss</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9hhMmoVVONN_n04uwyOFg.jpeg" /><figcaption><em>All is in order! Delayed packets correctly trigger PLIs, image is good</em></figcaption></figure><p>Sometimes, it’s paradoxically faster to take the long road, and do without easy-to-use, all-in-one bundle of plugins that you don’t really master nor own.</p><p>Sure, you spend some time doing it but you’ll also drastically increase both your knowledge of underlying mechanisms, and your ability to tweak and optimize them, so as to best suit your product or business.</p><p>At least, that’s the way we see things! What about you?</p><p><em>(With ❤️ from Tim, Sébastien, Marc &amp; Germ</em>á<em>n @Tribe Video)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1df48a93492" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tribe-staff/down-the-mcu-road-with-gstreamer-webrtc-d1df48a93492">Down the MCU road with GStreamer #WebRTC</a> was originally published in <a href="https://medium.com/tribe-staff">Inside Tribe</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we’re coding a MCU from scratch #WebRTC]]></title>
            <link>https://medium.com/tribe-staff/why-were-coding-a-mcu-from-scratch-webrtc-45a9b3ca72db?source=rss-d048d03b03bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/45a9b3ca72db</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[mcu]]></category>
            <dc:creator><![CDATA[Timothée Le Borgne]]></dc:creator>
            <pubDate>Tue, 23 Jan 2018 09:34:13 GMT</pubDate>
            <atom:updated>2018-01-23T15:46:34.879Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-aF03E4U222Y3UMLyC9SQ.jpeg" /></figure><h4>What we’ve learned after a year doing advanced video at Tribe</h4><p>When we joined <a href="https://www.tribe.pm/">Tribe</a>, a year ago, after quite a lot of time spent building 1-to-many HA video backends for people like <a href="https://techcrunch.com/2015/06/30/vivendi-buys-80-of-frances-dailymotion-valuing-the-youtube-rival-at-295m/">Dailymotion</a>, <a href="https://techcrunch.com/2011/01/31/exclusive-kit-digital-acquires-kickapps-kewego-and-kyte-for-77-2-million/">Kewego</a>, <a href="https://techcrunch.com/2016/11/03/afrostream-launches-its-video-streaming-service-in-24-new-countries/">Afrostream</a> or <a href="https://techcrunch.com/2015/08/10/nomadcast-is-a-powerful-live-streaming-app-with-embeddable-player/">NomadCast</a> (to name a few), we were faced with a new challenge: build real-time video conferencing capabilities into an async app.</p><p>It goes without saying that traditional HLS/Dash streaming was a no-go, given the mandatory delay those techniques imply.</p><p>So naturally, we started looking into WebRTC.</p><p>Now, <strong>setting a proof of concept using WebRTC is really simple</strong>. It’s actually a matter of hours; you can get some pretty decent P2P video chat up and running in no time.</p><p><strong>Building video to scale, though, is a whole different matter</strong>!</p><h3>We quickly ruled out P2P</h3><p>The immediate POC option is to consider creating a mesh:</p><ul><li>Virtually <strong>no cost</strong>s: peers in a call actually connect directly with each other, so no bandwidth costs involved; signaling is super lightweight and can run on small VMs</li><li>By default, <strong>WebRTC takes care of quality control</strong> in a crude but efficient manner, maximizes the quality per bandwidth available, so great quality with minimum tweaking</li><li>Peers automatically adapt their publisher stream’s bitrate/resolution/FPS to match other peer’s network conditions — individually</li></ul><p>But while it’s great to iterate on a concept very fast, the downsides absolutely forbid (at least, for us) deploying to production:</p><ul><li>Individually matching everyone’s quality needs in a <em>n</em>-peers convo means <strong>the device has to encode up to <em>n</em>-1 different outbound streams</strong> (<em>publishers</em>), which is definitely too CPU-intensive for most devices (mobiles, for Tribe) out there ; especially if <em>n</em> is high. And well, the device also has to decode n-1 inbound streams (<em>listeners</em>)… all of this leading to burning phones, as well as batteries drained in no time</li><li><strong>No on-the-fly fine-tuning of quality</strong>: once the SDP negotiation with the signaling server is done, you can’t modify/force the bitrate/quality given specific conditions (say, you have more peers joining and you want to lower overall quality for publishers, for instance)</li><li>Can’t record or process the streams server-side, so… limited added-value developments further down the road</li></ul><h3>Our first approach: setting up a SFU</h3><p><em>If you need a WebRTC crash course, head out to </em><a href="https://bloggeek.me/webrtc-multiparty-video-alternatives"><em>bloggeekme</em></a><em> and check out the excellent articles about mesh/SFU/MCU, etc.!</em></p><p>Our first concern was to enable many peers calls, on relatively modest devices (iPhones 5). Turns out the best way to do that is by setting up a SFU (Selective Forwarding Unit).</p><p>After a quick benchmark of different open source solutions, <a href="https://janus.conf.meetecho.com/"><strong>Janus</strong></a> seemed both the most powerful and flexible one to adapt, so we started customizing it. I.e, bridging our signaling and tweaking settings (a lot).</p><p>That gave very satisfying result — as a matter of fact, <strong>we’re still using a SFU at the moment</strong>:</p><ul><li>It works fine with up to 8 peers (can actually handle way more in a single room, it’s just a product limitation we set), even on slow devices</li><li>CPU consumption and battery usage client-side is way better, since there’s only 1 stream to encode (instead of n-1, in a n-peers call)</li><li>Since a SFU merely forwards any incoming stream to other connected peers, its CPU consumption is very low, so you can have it run on relatively small VMs</li></ul><p>The real complex part here is to actually <strong>design your video backend so that it scales massively and automatically</strong> — this last part is especially important if your audience is worldwide; you do NOT want to wake up in the middle of the night every time there’s a bug/glitch/need for scaling up :)</p><p>Without being too specific, ours is mostly made of a CoreOS / Docker Swarm cluster of unit groups, each comprising a signaling server, a Redis Database (for co-turn) and a Janus instance; all of these have a heartbeat container, a CoTURN cluster is available for all unitgroups and respond in STUN/TURN mode. A clustered GoLang micro-service (in-memory database based on protected maps, heartbeats, etc.) acts as both proxy and “orchestrator” and basically:</p><ul><li>Directs all incoming streams to the correct unit group</li><li>Checks unit groups’ health, and reboot them if one of the sub-servers somehow failed</li><li>Monitor &amp; forecast global activity and spawn/remove unitgroups whenever needed</li><li>Spawn new VMs in the CoreOS cluster if necessary</li></ul><p>This setup covers “the basics” (you might want to set up a STUN server as well, to bypass firewalls, and of course, look into making all that stuff global and multi-GEOs, etc.) in a nice and (almost!) worry-free way, and should look like what most other platforms/apps use.</p><p>While it’s the most cost-efficient solution for a mainstream audience, we found out it did not entirely match our product ambitions, mostly because of tech limitations:</p><ul><li>Janus has a ‘lip-sync’ issue (audio/video delay) — probably due to RTP timestamping error. Not the end of the world, but it can be really annoying, as call lasts</li><li>Streams are merely being forwarded: so if peers have different bandwidth capacities, you’ll need to make a choice: fixed “average” quality settings that should more or less fit everyone in the call, high quality that will look great — but you might end up losing struggling peers — or to the lowest — and it’ll run smoothly everywhere but with degraded picture quality</li><li>You can’t have a ‘multi-codecs’ room: all peers of a room have to be using the same codec. That’s annoying when you have both iOS/Android users in the same call as both support for H264/VP8 and hardware encoding varies from one device to another…</li><li>Because a SFU merely forwards and does not decode incoming streams, you can’t ‘modify’ them (like: process audio or video to add fun effects, etc.)</li></ul><h3>Now switching to building our own MCU</h3><p>Our main reason for looking into an MCU is product-driven: the Tribe app features a lot of cool stuff including pretty resource-intensive masks, filters, games. Couple this with high quality video encoding — and decoding — and you get yourself a phone that tends to get burning hot pretty fast ;)</p><p>So we needed a way to both <strong>reduce stream encoding/decoding overhead and maintain cross-device compatibility</strong> (iOS/Android/Browser), as well as tweak quality so as to get the best of what all connected devices can handle.</p><p>Last but not least, the idea was also to <strong>allow for cool/exclusive future product enhancements</strong>: server-side face detection/tracking/recognition and machine learning on UGC, masks &amp; filters processed with and burnt to the feed, support for a full-’web’ (using react, for instance) pivot, fun voice-swapping feature, etc.</p><p>That’s a set of requirements best met with a MCU (Multi Conferencing Unit). Now, MCUs have been around for a while now, so nothing new here, but we needed something that would be fully integrated with Tribe products — with no overhead whatsoever. Something we’d deeply understand, and would be able to tweak at each and every level — which is why we set out to build our very own MCU, from scratch.</p><p><em>We’ll probably share more about the steps in a coming post, because it’s a long — and somewhat painful — process, with a lot of missteps to avoid, but it’s also exciting and challenging :-)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*jEicSl6BTJ_O3UudmNg4PQ.jpeg" /><figcaption>The MCU ensures all listener streams output with the best possible quality</figcaption></figure><p><strong>Contrary to a SFU, a MCU is able to transcode the ingested streams</strong>, and output them in a different (or not) quality/format. For us at Tribe, it means that we can:</p><ul><li>Send a <strong>hardware encoded</strong> VP8 stream from an Android device, and hardware-decode a H264 transcode of that stream on an iOS device, resulting in a huge performance increase and battery savings, device-wise. So: multi-codecs and hardware acceleration</li><li><strong>Fine-tune the stream quality</strong>: publisher streams (can) get transcoded to exactly match each listener’s max capacity. So basically, connected peers will get always get the highest possible stream quality, whatever the setup</li><li>Enable <strong>stream ‘stitching</strong>’. This is especially exciting, since it means you’ll only get one single listener stream to decode, whatever the number of people in the call… and it’s always much easier to decode one heavy stream, than <em>n </em>smaller ones</li></ul><p>Other cool things include:</p><ul><li><strong>Manipulating the audio-video stream</strong>. We can for instance isolate the audio channel, do some neat voice conversion using RNN/CNN (neural networks), and re-attach it during transcoding so you get a whole different voice</li><li>Process images for specific <strong>shape detection</strong> (you know… ), and automatically kick/ban improper behavior, for advanced moderation</li><li>Process the video stream to play some fun <strong>gesture-based</strong> games, without burdening the devices</li><li>And actually, the “codec-agnostic calls” allow for really, really cool things like using the (newly) built-in WebRTC capabilities on iOS 11 Safari &amp; Android chrome to initiate calls without <em>even a need for an app</em>. <strong>This really paves the way for progressive apps</strong> (vs native apps), where one code base efficiently serves all platforms (ios/android/<a href="https://web.tribe.pm/">desktop</a>)</li></ul><p>That being said, there are obvious downsides to maintaining a MCU, the first one being: it’s <strong>super CPU-intensive </strong>(meaning, it’s really going to cost you a LOT 💵)<strong> </strong>and much harder to scale than a SFU.</p><blockquote>Just consider this for a moment: a <em>n</em>-peers call means your publisher stream will be transcoded <em>n</em>-1 times, to match the custom requirements of all other peers. This scenario means, your MCU will spawn (<em>n</em>-1)*<em>n</em> encoders, for a single room. Not very scalable if you don’t work out some sort of mutualization or stitching! ;-)</blockquote><p>So you need to be prepared and ask yourself: does my product really benefit from this? Do I need that much quality control (or just quality, for that matter)? Do I know how to scale? Will my product make use of transcoding?</p><p>For us, it was an instant <em>go</em> 👊</p><p>But if it’s a <em>no</em>, know you’re way better off with a SFU. If yes, well, hop on the train and start digging the <a href="https://tools.ietf.org/wg/rtcweb/">WebRTC RFCs</a>: it’s a long and challenging road, but the possibilities are amazing ;-)</p><p><em>(With ❤️ from Tim, Sébastien, Marc &amp; Germ</em>á<em>n @Tribe Video)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45a9b3ca72db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tribe-staff/why-were-coding-a-mcu-from-scratch-webrtc-45a9b3ca72db">Why we’re coding a MCU from scratch #WebRTC</a> was originally published in <a href="https://medium.com/tribe-staff">Inside Tribe</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>