次の例のように、GOption テーブルを使って独自のパラメータを初期化することもできます。
例 4-2. GOption インタフェースを使った初期化
#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 }
};
/* we must initialise the threading system before using any
* other GLib funtion, such as g_option_context_new() */
if (!g_thread_supported ())
g_thread_init (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_error_free (err);
return 1;
}
printf ("Run me with --help to see the Application options appended.\n");
return 0;
}
上のコードに示したように、GOption テーブルを使ってアプリケーション固有のコマンドラインオプションを定義し、このテーブルを関数 gst_init_get_option_group から返されたオプショングループと一緒に GLib 初期化関数に渡すことができます。この場合、GStreamer 標準のオプションに加えて、アプリケーションのオプションも解析されます。