nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.05k stars 307 forks source link

Generalised Realtime Stream Protocol #166

Open mitchmindtree opened 6 years ago

mitchmindtree commented 6 years ago

It would be incredibly useful to have a general way of establishing realtime streams of data over a network. Use cases might include streaming audio, video, laser data, lighting data, etc over a network without requiring the need for proprietary or 3rd party software.

It seems that there are several common requirements between different kinds of realtime streams:

I can picture a low-level realtime stream protocol which handles each of these lower level properties, allowing developers to build higher-level stream APIs (e.g. audio, laser, video) with far greater ease on top.

Perhaps a protocol like this already exists? It would be great if there was already a protocol like this in use that we could provide an implementation for. If not, I imagine it would not be too difficult to implement something like this. Perhaps a crate along the lines of rttcp, standing for "Realtime TCP".

Background

Recently I have been thinking about beginning work on an open-source, free networked audio crate inspired by Dante, but with an MIT license and less of the arbitrary restrictions. I had not considered working on my own networked audio until writing the ether-dream crate (a protocol for interacting with a networked laser DAC). Seeing how the layout of laser data is so similar to audio data, it made it much clearer to me on how it might be possible to work on a real-time audio crate. After thinking a little more on the topic I started wondering whether a more generalised, "realtime" data stream crate might be a better approach.

mitchmindtree commented 6 years ago

Research

This stackoverflow comment provides a nice breakdown of how these three protocols could be used together for generalised realtime streams.

Thoughts

RTCP seems like it may be unnecessary for many creative coding applications. The primary purpose seems to be monitoring quality of service, useful for making adaptive streams which can account for changes in quality or congestion in the network. That said, it could be useful for larger, more sophisticated setups.

RTSP also may be a little too high-level for what we're looking for - it seems to be a more opinionated set of messages of high-level control like "get parameter", "set parameter", "play", "pause", "record", etc - many of which are irrelevant for many kinds of realtime streams, but may be more useful for controlling remote setups (e.g. over the non-local internet).

One major benefit of using the protocols above is that they are widely used standards. As a benefit, we may not only unveil a simple way of establishing realtime streams, but also unlock interaction with many other applications that already implement these protocols.

mitchmindtree commented 6 years ago

Stream Synchronisation Across Destinations

An extended goal after getting reliable networked realtime streams going would be to also allow for some way of synchronising the playback across the destination applications. I'm still searching for a standard protocol designed to solve this, but it looks like many people recommend simply using a combination of RTP (mentioned above) and NTP (Network Time Protocol). Roughly, this involves synchronising the clocks of the systems on the network and using NTP markers to ensure certain data is delivered at the same time.

Related links:

Related Rust crates:

freesig commented 6 years ago

This is a really good idea. I wonder if removing Nagle's Algorithm completely, might result in the loss of more packets. I imagine there some probability of packet loss for each packet and also a cost associated with having to resend / wait for the lost packet.

There must be a nice balance that could be found with batch size depending on how unstable the network is. I guess most of the use cases would be on LAN's so they would probably be quiet stable anyway.

mitchmindtree commented 6 years ago

I did some hunting for more research and info on RTP, RTCP, NTP and also PTP last night:

rtp-and-rtcp-protocol-overview.pdf Short paper with an RTP and RTCP overview

IEEE_1588_Precise_Time_Protocol.pdf Fancy PDF with PTP Overview from symmetricom

rtp-rtcp-rtsp-interent-protocols-for-realtime-multimedia-communication.pdf Paper with a thorough overview of RTP, RTCP and RTSP

avb-stanton-rtp-over-avb-aka-ieee1733-0309.pdf Slides discussing RTP over AVB

avbtp-olsen-RTP_Synchronization-2007-11-5.pdf Slides discussing synchronisation of RTP destinations using NTP

mitchmindtree commented 6 years ago

A really nice youtube video giving an overview of NTP. https://www.youtube.com/watch?v=EkQPkQb2D3g

mitchmindtree commented 6 years ago

RFC 3551 - RTP Profile for Audio and Video Conferences With Minimal Control defines some standards for working with certain audio and visual formats over RTP.

This wikipedia entry enumerates loads of audio/video profiles that have been standardised for transport over RTP along with their specification RFCs https://en.wikipedia.org/wiki/RTP_audio_video_profile