Adaptive Demuxer baseclass

If you haven't read yet, Sebastian has a good overview of adaptive streaming support (client-side) in GStreamer: https://coaxion.net/blog/2014/05/http-adaptive-streaming-with-gstreamer/

Currently, GStreamer works with all 3 adaptive formats out there: HLS with hlsdemux, SmoothStreaming with mssdemux and DASH with dashdemux. And while it all works quite well for the most common scenarios, all 3 elements are very similar and share a lot of code. Large portions of code were actually copy and pasted from one to another while they were being developed and in early stages of stabilization. At the moment it is common to have to fix the same issue or implement the same feature and copy over for the other elements. This is not nice.

The Solution

As most of the code is actually the same, the obvious solution is to write a base class: GstAdaptiveDemux. It will handle the common logic that is now copied on all 3 elements:

  • Receive the manifest from upstream and merge it into a single buffer
  • Start a thread for each stream available in the manifest and create the source element that will fetch the fragments and push downstream
  • Calculate the download rate of fragments to select the best bitrate for the context
  • Fragment download retry attempts
  • Disabling not-linked streams to save bandwidth (multi-audio media)
  • Standard query and event handling for streams
  • Manifest updates for live streams
  • Thread locking

On the other hand, the subclass is responsible for parsing the received manifest and maintaining the data structures for the streams. Most of the implementation will focus on extracting the fragments' URLs from the manifest and providing the metadata for the streams (duration, timestamps, formats).

As there doesn't seem to be any other adaptive format, this baseclass is going to be private API. This actually gives us an advantage of not needing to stabilize it before merging as we can change the API if needed without worrying about API/ABI breaks.

Where is it?

The latest implementation can be found at http://cgit.freedesktop.org/~thiagoss/gst-plugins-bad/log/?h=adaptivedemux while it is not merged upstream.

What's keeping it from usptream?

More testing. Unfortunatelly I don't have a full setup that would allow me to test all scenarios. Live streams is the hardest to test at the moment and likely where regressions are still to be discovered. A bug has already been filed to start the merge discussion: https://bugzilla.gnome.org/show_bug.cgi?id=735848
If you've been using adaptive formats with GStreamer, please give it a go and report regressions/issues at the bug. Thanks!