# Basic tutorial 12: Streaming # Goal Playing media straight from the Internet without storing it locally is known as Streaming. We have been doing it throughout the tutorials whenever we used a URI starting with `http://`. This tutorial shows a couple of additional points to keep in mind when streaming. In particular: - How to enable buffering (to alleviate network problems) - How to recover from interruptions (lost clock) # Introduction When streaming, media chunks are decoded and queued for presentation as soon as they arrive form the network. This means that if a chunk is delayed (which is not an uncommon situation at all on the Internet) the presentation queue might run dry and media playback could stall. The universal solution is to build a “buffer”, this is, allow a certain number of media chunks to be queued before starting playback. In this way, playback start is delayed a bit, but, if some chunks are late, reproduction is not impacted as there are more chunks in the queue, waiting. As it turns out, this solution is already implemented in GStreamer, but the previous tutorials have not been benefiting from it. Some elements, like the `queue2` and `multiqueue` found inside `playbin2`, are capable of building this buffer and post bus messages regarding the buffer level (the state of the queue). An application wanting to have more network resilience, then, should listen to these messages and pause playback if the buffer level is not high enough (usually, whenever it is below 100%). To achieve synchronization among multiple sinks (for example and audio and a video sink) a global clock is used. This clock is selected by GStreamer among all elements which can provide one. Under some circumstances, for example, an RTP source switching streams or changing the output device, this clock can be lost and a new one needs to be selected. This happens mostly when dealing with streaming, so the process is explained in this tutorial. When the clock is lost, the application receives a message on the bus; to select a new one, the application just needs to set the pipeline to PAUSED and then to PLAYING again. # A network-resilient example Copy this code into a text file named `basic-tutorial-12.c`.
This tutorial is included in the SDK since release 2012.7. If you cannot find it in the downloaded code, please install the latest release of the GStreamer SDK. |