Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > f0a9f2b9c81d34eadc43f527947c0b70 > files > 195

libgstreamer0.7-devel-0.7.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Adding Arguments</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GStreamer Plugin Writer's Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Building a Filter"
HREF="part-building.html"><LINK
REL="PREVIOUS"
TITLE="
    What are states?
  "
HREF="chapter-statemanage-states.html"><LINK
REL="NEXT"
TITLE="Signals"
HREF="chapter-building-signals.html"></HEAD
><BODY
CLASS="chapter"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
><SPAN
CLASS="application"
>GStreamer</SPAN
> Plugin Writer's Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="chapter-statemanage-states.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="chapter-building-signals.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="chapter-building-args"
></A
>Chapter 7. Adding Arguments</H1
><P
>&#13;    The primary and most important way of controlling how an element behaves,
    is through GObject properties. GObject properties are defined in the
    <CODE
CLASS="function"
>_class_init ()</CODE
> function. The element optionally
    implements a <CODE
CLASS="function"
>_get_property ()</CODE
> and a
    <CODE
CLASS="function"
>_set_property ()</CODE
> function. These functions will be
    notified if an application changes or requests the value of a property,
    and can then fill in the value or take action required for that property
    to change value internally.
  </P
><PRE
CLASS="programlisting"
>&#13;/* properties */
enum {
  ARG_0,
  ARG_SILENT
  /* FILL ME */
};

static void	gst_my_filter_set_property	(GObject      *object,
						 guint         prop_id,
						 const GValue *value,
						 GParamSpec   *pspec);
static void	gst_my_filter_get_property	(GObject      *object,
						 guint         prop_id,
						 GValue       *value,
						 GParamSpec   *pspec);

static void
gst_my_filter_class_init (GstMyFilterClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  /* define properties */
  g_object_class_install_property (object_class, ARG_SILENT,
    g_param_spec_boolean ("silent", "Silent",
			  "Whether to be very verbose or not",
			  FALSE, G_PARAM_READWRITE));

  /* define virtual function pointers */
  object_class-&#62;set_property = gst_my_filter_set_property;
  object_class-&#62;get_property = gst_my_filter_get_property;
}

static void
gst_my_filter_set_property (GObject      *object,
			    guint         prop_id,
			    const GValue *value,
			    GParamSpec   *pspec)
{
  GstMyFilter *filter = GST_MY_FILTER (object);

  switch (prop_id) {
    case ARG_SILENT:
      filter-&#62;silent = g_value_get_boolean (value);
      g_print ("Silent argument was changed to %s\n",
	       filter-&#62;silent ? "true" : "false");
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gst_my_filter_get_property (GObject    *object,
			    guint       prop_id,
			    GValue     *value,
			    GParamSpec *pspec)
{
  GstMyFilter *filter = GST_MY_FILTER (object);
                                                                                
  switch (prop_id) {
    case ARG_SILENT:
      g_value_set_boolean (value, filter-&#62;silent);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
  </PRE
><P
>&#13;    The above is a very simple example of how arguments are used. Graphical
    applications - for example GStreamer Editor - will use these properties
    and will display a user-controlleable widget with which these properties
    can be changed. This means that - for the property to be as user-friendly
    as possible - you should be as exact as possible in the definition of the
    property. Not only in defining ranges in between which valid properties
    can be located (for integers, floats, etc.), but also in using very
    descriptive (better yet: internationalized) strings in the definition of
    the property, and if possible using enums and flags instead of integers.
    The GObject documentation describes these in a very complete way, but
    below, we'll give a short example of where this is useful. Note that using
    integers here would probably completely confuse the user, because they
    make no sense in this context. The example is stolen from videotestsrc.
  </P
><PRE
CLASS="programlisting"
>&#13;typedef enum {
  GST_VIDEOTESTSRC_SMPTE,
  GST_VIDEOTESTSRC_SNOW,
  GST_VIDEOTESTSRC_BLACK
} GstVideotestsrcPattern;

[..]

#define GST_TYPE_VIDEOTESTSRC_PATTERN (gst_videotestsrc_pattern_get_type ())
static GType
gst_videotestsrc_pattern_get_type (void)
{
  static GType videotestsrc_pattern_type = 0;

  if (!videotestsrc_pattern_type) {
    static GEnumValue pattern_types[] = {
      { GST_VIDEOTESTSRC_SMPTE, "smpte", "SMPTE 100% color bars" },
      { GST_VIDEOTESTSRC_SNOW,  "snow",  "Random (television snow)" },
      { GST_VIDEOTESTSRC_BLACK, "black", "0% Black" },
      { 0, NULL, NULL },
    };

    videotestsrc_pattern_type =
	g_enum_register_static ("GstVideotestsrcPattern",
				pattern_types);
  }

  return videotestsrc_pattern_type;
}

[..]

static void
gst_videotestsrc_class_init (GstvideotestsrcClass *klass)
{
[..]
  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
    g_param_spec_enum ("pattern", "Pattern",
		       "Type of test pattern to generate",
		       GST_TYPE_VIDEOTESTSRC_PATTERN, 1, G_PARAM_READWRITE));
[..]
}
  </PRE
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="chapter-statemanage-states.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="chapter-building-signals.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>What are states?</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="part-building.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Signals</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>