📜 ⬆️ ⬇️

Introduction to GStreamer: Initialization

image

A little more than a year ago, the user of POPSul published a series of articles ( 1 , 2 and 3 ) about the GStreamer multimedia framework (for which he thanks a lot). I would like to continue his undertaking, putting more emphasis on the code component, rather than on the command line tools that make up GStreamer.

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

Development environment


The example from the article is made in Ubuntu 14.04 with the installed GStreamer version 1.2.4. Compilation is 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 <gst/gst.h> 

Initialization


Before using the GStreamer libraries they need to 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 deinitialization process (i.e., the release of resources) occurs automatically when the program completes its work. However, it is useful to know that you can do it manually, using the function:

 void gst_deinit (void) 

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

Important! After deinitialization, there should be no calls to the GStreamer library (except, of course, re-initialization).

Practice


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


For the first option 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 are releases, 1 is GIT versions, 2 is ... prereleases.

All of the above is summarized in the following example:

 #include <gst/gst.h> 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, &micro, &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.

Materials on the topic


GStreamer Application Development Manual
GStreamer 1.0 Core Reference Manual

Source: https://habr.com/ru/post/251049/


All Articles