docs: Remove obselete appendix about parsing cli argumnets

It's a bad idea trying to mix the Options from GStramer and
GTK, in addition with cli argument being a bit wonky thing for
GUI applications in general. In the rare, now, occasion
that an application wants to parse arguments, its preferable
to parse them manually and use library apis afterwards
rather than trying to combine the option groups and hope it
works.

In addition, applications should be opening files using
`g_application_open` instead of parsing random arguments.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4788>
This commit is contained in:
Jordan Petridis 2023-06-07 01:57:43 +03:00 committed by GStreamer Marge Bot
parent 62ed87dec4
commit 7d64943b9d

View file

@ -42,87 +42,6 @@ Juicer](https://wiki.gnome.org/Apps/SoundJuicer).
Most of these GNOME applications make use of some specific techniques to
integrate as closely as possible with the GNOME desktop:
- GNOME applications usually call `gtk_init ()` to parse command-line
options and initialize GTK. GStreamer applications would normally
call `gst_init ()` to do the same for GStreamer. This would mean
that only one of the two can parse command-line options. To work
around this issue, GStreamer can provide a GLib `GOptionGroup` which
can be passed to `gnome_program_init ()`. The following example
requires GTK 2.6 or newer (previous GTK versions do not support
command line parsing via GOption yet)
``` c
#include <gtk/gtk.h>
#include <gst/gst.h>
static gchar **cmd_filenames = NULL;
static GOptionEntries cmd_options[] = {
/* here you can add command line options for your application. Check
* the GOption section in the GLib API reference for a more elaborate
* example of how to add your own command line options here */
/* at the end we have a special option that collects all remaining
* command line arguments (like filenames) for us. If you don't
* need this, you can safely remove it */
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &cmd_filenames,
"Special option that collects any remaining arguments for us" },
/* mark the end of the options array with a NULL option */
{ NULL, }
};
/* this should usually be defined in your config.h */
#define VERSION "0.0.1"
gint
main (gint argc, gchar **argv)
{
GOptionContext *context;
GOptionGroup *gstreamer_group, *gtk_group;
GError *err = NULL;
context = g_option_context_new ("gtk-demo-app");
/* get command line options from GStreamer and add them to the group */
gstreamer_group = gst_init_get_option_group ();
g_option_context_add_group (context, gstreamer_group);
gtk_group = gtk_get_option_group (TRUE);
g_option_context_add_group (context, gtk_group);
/* add our own options. If you are using gettext for translation of your
* strings, use GETTEXT_PACKAGE here instead of NULL */
g_option_context_add_main_entries (context, cmd_options, NULL);
/* now parse the commandline options, note that this already
* calls gtk_init() and gst_init() */
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
g_print ("Error initializing: %s\n", err->message);
g_clear_error (&err);
g_option_context_free (ctx);
exit (1);
}
g_option_context_free (ctx);
/* any filenames we got passed on the command line? parse them! */
if (cmd_filenames != NULL) {
guint i, num;
num = g_strv_length (cmd_filenames);
for (i = 0; i < num; ++i) {
/* do something with the filename ... */
g_print ("Adding to play queue: %s\n", cmd_filenames[i]);
}
g_strfreev (cmd_filenames);
cmd_filenames = NULL;
}
[..]
}
```
- GNOME uses Pulseaudio for audio, use the pulsesrc and pulsesink
elements to have access to all the features.