Introducing GStreamer: Initialization

image

A little over a year ago, a POPSuL user published a series of articles ( 1 , 2, and 3 ) about the GStreamer multimedia framework (for which many thanks to him). I would like to continue his undertaking, with more emphasis on the code component than on the command line tools that are part of GStreamer.

In this article I will talk about the very first operation when working with the framework - initialization. And as a pin, we’ll print a version of GStreamer.

Development environment


An example from the article was made in Ubuntu 14.04 with installed GStreamer version 1.2.4. Compilation is performed as follows:

$ gcc -Wall -o source source.c $(pkg-config --cflags --libs gstreamer-1.0)

Also, the header file must be included in the source file:

#include 

Initialization


Before using the GStreamer libraries, they must be initialized. There are two functions for this:

void gst_init (int *argc, char **argv[])
gboolean gst_init_check (int *argc, char **argv[], GError **err)

Both of them prepare the internal structure of libraries for use and load standard plugins. The only difference is that if it is impossible to initialize, gst_init () will interrupt the execution of your program, and gst_init_check () will return FALSE and send a report to the GError structure.

Deinitialization


In general, the process of de-initialization (i.e., the release of resources) occurs automatically when the program finishes its work. However, it will be useful to know that you can do this manually, using the function:

void gst_deinit (void)

This may be necessary when debugging an application, for example, to find leaks.

Important! After de-initialization, there should not be any calls to the GStreamer library (except, of course, reinitialization).

Practice


To consolidate the theoretical material, we will write an application that displays the version of the GStreamer library. In this context, there are two concepts of version:

  • version of GStreamer with which the application is currently linked (runtime version)
  • version of GStreamer used when compiling the application (compile-time-version)

For the first option, the functions are used:

void gst_version (guint *major, guint *minor, guint *micro, guint *nano)
gchar * gst_version_string (void)

For the second option, the following macros are used:

GST_VERSION_MAJOR
GST_VERSION_MINOR
GST_VERSION_MICRO
GST_VERSION_NANO

As for nano : 0 - these are releases, 1 - GIT-versions, 2 - ... - pre-releases.

All of the above is summarized in the following example:

#include 
int main (int argc, char * argv[])
{
	const gchar *nano;
	guint major, minor, micro, nano_int;
	/* Инициализация GStreamer, игнорируя любые аргументы */
	gst_init (NULL, NULL);
	if (gst_is_initialized())
		g_print ("GStreamer library successfully initialized\n");
	/* Выводим версию при компиляции */
	if (GST_VERSION_NANO == 0)
		nano = "";
	else if (GST_VERSION_NANO == 1)
		nano = "(GIT)";
	else
		nano = "(Prerelease)";
	g_print ("Compile time version:   %d.%d.%d %s\n", GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO, nano);
	/* Выводим runtime-версию */
	gst_version (&major, &minor, µ, &nano_int);	
	if (nano_int == 0)
		nano = "";
	else if (nano_int == 1)
		nano = "(GIT)";
	else
		nano = "(Prerelease)";
	g_print ("Runtime version:        %d.%d.%d %s\n", major, minor, micro, nano);
	/* Выводим runtime-версию в виде готовой строки */
	g_print ("String runtime version: %s\n", gst_version_string());
	return 0;
}

Compile and run:

$ gcc -Wall -o source source.c $(pkg-config --cflags --libs gstreamer-1.0)
$ ./source

Result:

GStreamer library successfully initialized
Compile time version:   1.2.4 
Runtime version:        1.2.4 
String runtime version: GStreamer 1.2.4

Conclusion


In the next article I will try to describe in detail the process of creating elements and assembling a pipeline from them, and in the practical section we will try to create something more interesting.

Related Materials


GStreamer Application Development Manual
GStreamer 1.0 Core Reference Manual

Also popular now: