GStreamer は、GNOME-2.2 以降、GNOME デスクトップのメディアバックエンドになっています。現在では数多くの GNOME アプリケーションがメディア処理に GStreamer を使用しています。主なものに、Rhythmbox、Totem、Sound Juicer などがあります。
こうした GNOME アプリケーションのほとんどは、いくつか固有のテクニックを使って、可能な限り密接な GNOME デスクトップとの統合を実現しています。
通常、GNOME アプリケーションは gtk_init () を呼び出してコマンドラインオプションの解析と GTK の初期化を行います。GStreamer アプリケーションの場合、通常は gst_init () を呼び出して、GStreamer 用に同様のことを行います。したがって、コマンドラインオプションを解析できるのは、これら 2 つの方法のうちいずれか 1 つだけということになります。この問題を回避するため、GStreamer では GLib の GOptionGroup を用意できるようになっており、これを gnome_program_init () に渡すことができます。次に示す例では、GTK 2.6 以上が必要です (それ以前のバージョンの GTK では、GOption を介したコマンドラインの解析をまだサポートしていません)。
#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;
/* 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);
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);
exit (1);
}
/* 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 は、デフォルトの動画と音声のソースおよびシンクを GConf に格納します。GStreamer では、これらの GConf の設定に基づいて、音声と動画のソースおよびシンクを直接作成する一連のエレメントを用意しています。具体的には、gconfaudiosink、gconfvideosink、gconfaudiosrc、gconfvideosrc の各エレメントがそれです。エレメントは gst_element_factory_make () を使って作成することができ、作成したエレメントはほかのソースエレメントやシンクエレメントと同様に直接使うことができます。これらのエレメントについては、すべての GNOME アプリケーションで利用することを推奨します。
GStreamer には、GIO VFS システムで使用するためのデータ入力/出力エレメントが用意されています。具体的には、"giosrc" と "giosink" がそれです。非推奨の GNOME-VFS システムもサポートされていますが、新しいアプリケーションでは使用しないでください。