mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
manual: add dynamic capsfilter example
This commit is contained in:
parent
fc5849ef11
commit
e11ca04ae7
2 changed files with 91 additions and 1 deletions
|
@ -1050,14 +1050,99 @@ main (int argc, char *argv[])
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Below is an example of how you can change the caps of a pipeline
|
Below is an example of how you can change the caps of a pipeline
|
||||||
while in the PLAYING state.
|
while in the PLAYING state:
|
||||||
</para>
|
</para>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
<!-- example-begin dynformat.c -->
|
<!-- example-begin dynformat.c -->
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#define MAX_ROUND 100
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
GstElement *pipe, *filter;
|
||||||
|
GstCaps *caps;
|
||||||
|
gint width, height;
|
||||||
|
gint xdir, ydir;
|
||||||
|
gint round;
|
||||||
|
GstMessage *message;
|
||||||
|
|
||||||
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
|
pipe = gst_parse_launch_full ("videotestsrc ! capsfilter name=filter ! "
|
||||||
|
"ximagesink", NULL, GST_PARSE_FLAG_NONE, NULL);
|
||||||
|
g_assert (pipe != NULL);
|
||||||
|
|
||||||
|
filter = gst_bin_get_by_name (GST_BIN (pipe), "filter");
|
||||||
|
g_assert (filter);
|
||||||
|
|
||||||
|
width = 320;
|
||||||
|
height = 240;
|
||||||
|
xdir = ydir = -10;
|
||||||
|
|
||||||
|
for (round = 0; round < MAX_ROUND; round++) {
|
||||||
|
gchar *capsstr;
|
||||||
|
g_print ("resize to %dx%d (%d/%d) \r", width, height, round, MAX_ROUND);
|
||||||
|
|
||||||
|
/* we prefer our fixed width and height but allow other dimensions to pass
|
||||||
|
* as well */
|
||||||
|
capsstr = g_strdup_printf ("video/x-raw, width=(int)%d, height=(int)%d",
|
||||||
|
width, height);
|
||||||
|
|
||||||
|
caps = gst_caps_from_string (capsstr);
|
||||||
|
g_free (capsstr);
|
||||||
|
g_object_set (filter, "caps", caps, NULL);
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
|
if (round == 0)
|
||||||
|
gst_element_set_state (pipe, GST_STATE_PLAYING);
|
||||||
|
|
||||||
|
width += xdir;
|
||||||
|
if (width >= 320)
|
||||||
|
xdir = -10;
|
||||||
|
else if (width < 200)
|
||||||
|
xdir = 10;
|
||||||
|
|
||||||
|
height += ydir;
|
||||||
|
if (height >= 240)
|
||||||
|
ydir = -10;
|
||||||
|
else if (height < 150)
|
||||||
|
ydir = 10;
|
||||||
|
|
||||||
|
message =
|
||||||
|
gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR,
|
||||||
|
50 * GST_MSECOND);
|
||||||
|
if (message) {
|
||||||
|
g_print ("got error \n");
|
||||||
|
|
||||||
|
gst_message_unref (message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_print ("done \n");
|
||||||
|
|
||||||
|
gst_object_unref (filter);
|
||||||
|
gst_element_set_state (pipe, GST_STATE_NULL);
|
||||||
|
gst_object_unref (pipe);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
]]>
|
]]>
|
||||||
<!-- example-end dynformat.c -->
|
<!-- example-end dynformat.c -->
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
Note how we use <function>gst_bus_poll()</function> with a
|
||||||
|
small timeout to get messages and also introduce a short
|
||||||
|
sleep.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
It is possible to set multiple caps for the capsfilter separated
|
||||||
|
with a ;. The capsfilter will try to renegotiate to the first
|
||||||
|
possible format from the list.
|
||||||
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ EXAMPLES = \
|
||||||
probe \
|
probe \
|
||||||
appsrc \
|
appsrc \
|
||||||
appsink \
|
appsink \
|
||||||
|
dynformat \
|
||||||
playbin \
|
playbin \
|
||||||
decodebin
|
decodebin
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ BUILT_SOURCES = \
|
||||||
probe.c \
|
probe.c \
|
||||||
appsrc.c \
|
appsrc.c \
|
||||||
appsink.c \
|
appsink.c \
|
||||||
|
dynformat.c \
|
||||||
playbin.c decodebin.c
|
playbin.c decodebin.c
|
||||||
|
|
||||||
CLEANFILES = core core.* test-registry.* *.gcno *.gcda $(BUILT_SOURCES)
|
CLEANFILES = core core.* test-registry.* *.gcno *.gcda $(BUILT_SOURCES)
|
||||||
|
@ -99,6 +101,9 @@ appsrc.c: $(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
||||||
appsink.c: $(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
appsink.c: $(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
||||||
$(PERL_PATH) $(srcdir)/extract.pl $@ $<
|
$(PERL_PATH) $(srcdir)/extract.pl $@ $<
|
||||||
|
|
||||||
|
dynformat.c: $(top_srcdir)/docs/manual/advanced-dataaccess.xml
|
||||||
|
$(PERL_PATH) $(srcdir)/extract.pl $@ $<
|
||||||
|
|
||||||
playbin.c decodebin.c: $(top_srcdir)/docs/manual/highlevel-components.xml
|
playbin.c decodebin.c: $(top_srcdir)/docs/manual/highlevel-components.xml
|
||||||
$(PERL_PATH) $(srcdir)/extract.pl $@ $<
|
$(PERL_PATH) $(srcdir)/extract.pl $@ $<
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue