GStreamer based tutorial learning 1 - Hello World (GStreamer Basic tutorial 1 - Hello World)

https://gstreamer.freedesktop.org/documentation/tutorials/basic/hello-world.html?gi-language=c

Important points: 

1. gst_init()

/* Initialize GStreamer */
gst_init (&argc, &argv);

This must always be your first GStreamer command. Among other things, gst_init():

  • Initializes all internal structures

  • Checks what plug-ins are available

  • Executes any command-line option intended for GStreamer

2. gst_parse_launch() and playbin

gst_parse_launch

GStreamer is a framework designed to handle multimedia flows. Media travels from the “source” elements (the producers), down to the “sink” elements (the consumers), passing through a series of intermediate elements performing all kinds of tasks. The set of all the interconnected elements is called a “pipeline”.

Multimedia elements from the stream known as the "source" (or called producers) departure until called "SInk" elements (or called consumers), the middle will undergo a series of links intermediate processing, which is all interconnected It is called a "pipe" on the whole element.

In GStreamer you usually build the pipeline by manually assembling the individual elements, but, when the pipeline is easy enough, and you do not need any advanced features, you can take the shortcut: gst_parse_launch().

When using GStreamer, typically require manual assembly of the individual elements to form a pipeline, but when the pipeline itself is very simple words, they also do not need some of the advanced features, then you can use the convenient way: gst_parse_launch ()

This function takes a textual representation of a pipeline and turns it into an actual pipeline, which is very handy. In fact, this function is so handy there is a tool built completely around it which you will get very acquainted with (see Basic tutorial 10: GStreamer tools to learn about gst-launch-1.0 and the gst-launch-1.0 syntax).

This function takes a text description of the conduit into an actual pipeline, it is convenient. 

playbin

So, what kind of pipeline are we asking gst_parse_launch() to build for us? Here enters the second key point: We are building a pipeline composed of a single element called playbin.

/* Build the pipeline */
pipeline =
    gst_parse_launch
    ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",
    NULL);

playbin is a special element which acts as a source and as a sink, and is a whole pipeline. Internally, it creates and connects all the necessary elements to play your media, so you do not have to worry about it.

playbin is a special element, which has both a source and a Sink attributes as a whole piping. 

It does not allow the control granularity that a manual pipeline does, but, still, it permits enough customization to suffice for a wide range of applications. Including this tutorial.

In this example, we are only passing one parameter to playbin, which is the URI of the media we want to play. Try changing it to something else! Whether it is an http:// or file:// URI, playbin will instantiate the appropriate GStreamer source transparently!

In this case, only one parameter transferred to playbin, he is a media URI.

If you mistype the URI, or the file does not exist, or you are missing a plug-in, GStreamer provides several notification mechanisms, but the only thing we are doing in this example is exiting on error, so do not expect much feedback.

3. gst_element_set_state

/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);

This line highlights another interesting concept: the state. Every GStreamer element has an associated state, which you can more or less think of as the Play/Pause button in your regular DVD player. For now, suffice to say that playback will not start unless you set the pipeline to the PLAYING state.

In this line, gst_element_set_state() is setting pipeline (our only element, remember) to the PLAYING state, thus initiating playback.

This line emphasizes another interesting concept: the state. GStreamer elements each have an associated state, it is conceivable for the DVD player, play / stop button. This code is provided to playback pipeline state.

4. Wait for feedback

/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg =
    gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
    GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

These lines will wait until an error occurs or the end of the stream is found. gst_element_get_bus() retrieves the pipeline's bus, and gst_bus_timed_pop_filtered() will block until you receive either an ERROR or an EOS (End-Of-Stream) through that bus. Do not worry much about this line, the GStreamer bus is explained in Basic tutorial 2: GStreamer concepts.

This is a few lines of code will wait until the fault has occurred or the end of the media stream. gst_element_get_bus () to get the bus duct.

gst_bus_timed_pop_filtered (), execute the function program will block until receiving from a bus to a Error or the EOS (end flag flow).

 

Conclusion

And so ends your first tutorial with GStreamer. We hope its brevity serves as an example of how powerful this framework is!

Let's recap a bit. Today we have learned:

The next tutorial will keep introducing more basic GStreamer elements, and show you how to build a pipeline manually.

Published 11 original articles · won praise 5 · views 20000 +

Guess you like

Origin blog.csdn.net/gsymichael/article/details/104429111
Recommended