当前位置:网站首页>Practical guide to GStreamer application development (III)

Practical guide to GStreamer application development (III)

2022-06-09 05:35:00 Geek. Fan

One 、 be based on GStreamer Application initialization for

         Elements ,pad And buffer is GStreamer The basic concepts and the most commonly used objects . We use visual representations of these objects , So that more complex pipelines can be simply built later . A preliminary understanding GStreamer API in the future , Basically enough for us to build basic applications , The following is an introduction based on GStreamer The building process of the application .

1、 initialization GStreamer

Writing GStreamer Application time , We just need to simply include gst/gst.h To access library functions . besides , We also need to initialize GStreamer library .

When available GStreamer Before Library , Must be called from the main application gst_init Perform the necessary initialization of the library , And parse specific to GStreamer Command line options for .

A typical GStreamer Application initialization GStreamer Code for , As shown below :

#include <stdio.h>
#include <gst/gst.h>


int main (int argc, char *argv[])

{

const gchar *nano_str;
guint major, minor, micro, nano;

gst_init (&argc, &argv);

gst_version (&major, &minor, &micro, &nano);


if (nano == 1)
nano_str = "(CVS)";
else if (nano == 2)
nano_str = "(Prerelease)";
else
nano_str = "";

printf ("This program is linked against GStreamer %d.%d.%d %s\n",
major, minor, micro, nano_str);

return 0;

}

         Use GST_VERSION_MAJOR, GST_VERSION_MINOR and GST_VERSION_MICRO The macro gets the GStreamer edition , Or use functions gst_version Get the version that your application links to .

GStreamer In the current scheme , Versions with the same major and minor versions are the same as API and ABI compatible .

         You can also call... With two empty arguments gst_init function , under these circumstances ,GStreamer No command line options will be parsed .

2、GOption Interface

         In addition to the above methods , We can also use GoOption Table initializes its own parameters , As shown in the following example :

#include <gst/gst.h>


int main (int argc, char *argv[])

{

gboolean silent = FALSE;

gchar *savefile = NULL;

GOptionContext *ctx;

GError *err = NULL;

GOptionEntry entries[] = {

{ "silent", 's', 0, G_OPTION_ARG_NONE, &silent, "do not output status information", NULL },

{ "output", 'o', 0, G_OPTION_ARG_STRING, &savefile, "save xml representation of pipeline to FILE and exit", "FILE" },

{ NULL }

};


ctx = g_option_context_new ("- Your application");

g_option_context_add_main_entries (ctx, entries, NULL);

g_option_context_add_group (ctx, gst_init_get_option_group ());

if (!g_option_context_parse (ctx, &argc, &argv, &err)) {

g_print ("Failed to initialize: %s\n", err->message);

g_clear_error (&err);

g_option_context_free (ctx);

return 1;

}

g_option_context_free (ctx);

printf ("Run me with --help to see the Application options appended.\n");



return 0;

}

         As shown in this procedure , We can use GOption Table to define application specific command line options , And compare this table with the gst_init_get_option_group The option group returned by the function is passed to GLib Initialization function . In addition to standard GStreamer Beyond the options , It will also parse your application options .

         The code for this example is automatically extracted from the document , And in GStreamer tarball Medium tests/examples/manual Next build .

原网站

版权声明
本文为[Geek. Fan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090522316650.html