MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Using GStreamer

GStreamer is a multimedia framework that uses GLib as its core library. GStreamer uses a pipeline design in which a collection of related elements are executed in sync with each other. This allows combining flexible media handling as the early parts of the pipeline can handle audio and video decoding and latter parts playback or editing functions, for example. GStreamer allows you to develop audio and video playback, recording, streaming and editing features in your applications

In most cases, Qt Mobility Multimedia module is sufficient for creating multimedia applications. However, GStreamer is very useful for more specialised situations, such as live streaming applications.

Applying GStreamer in the project file

In Qt Creator, GStreamer is not automatically recognised when working on your project. Therefore, you need to edit the project file (.pro) manually with a text editor, and add the following lines in it:

unix {
   CONFIG += link_pkgconfig
   PKGCONFIG += gstreamer-0.10
}

GStreamer example: video stream playback

To use GStreamer in your application, include its headers:

#include <gst/gst.h>

Within the main loop, initialize the GStreamer library with gst_init:

gst_init (NULL,NULL);

The next rows create a new pipeline (bin), a new video signal test stream (testSrc) and a sink element for the video stream (videoOut), which is the end point for the media pipeline. Every step is followed by a g_assert test macro that terminates the application if the previous step has not been completed successfully.

GstElement *bin = gst_pipeline_new ("pipeline");
g_assert(bin);
GstElement *testSrc = gst_element_factory_make("videotestsrc", "source");
g_assert(testSrc);
GstElement *videoOut = gst_element_factory_make("autovideosink", "video out");
g_assert(videoOut);

The next step is to add and link the test stream and sink element to the pipeline. After that is done, the state of the element is set as PLAYING in the gst_element_set_state function.

gst_bin_add_many(GST_BIN(bin), testSrc, videoOut, NULL);
gst_element_link_many(testSrc, videoOut, NULL);
gst_element_set_state(GST_ELEMENT(bin), GST_STATE_PLAYING);