diff --git a/configure.ac b/configure.ac index 0959fb978f..9a6bec2856 100644 --- a/configure.ac +++ b/configure.ac @@ -654,6 +654,7 @@ tests/misc/Makefile tests/examples/Makefile tests/examples/adapter/Makefile tests/examples/controller/Makefile +tests/examples/stepping/Makefile tests/examples/helloworld/Makefile tests/examples/launch/Makefile tests/examples/manual/Makefile diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am index 87c13fe4d3..88fbe7db62 100644 --- a/tests/examples/Makefile.am +++ b/tests/examples/Makefile.am @@ -23,7 +23,8 @@ always_dirs = \ manual \ metadata \ streams \ - queue + queue \ + stepping #appreader #cutter diff --git a/tests/examples/stepping/.gitignore b/tests/examples/stepping/.gitignore new file mode 100644 index 0000000000..0b661c7ba6 --- /dev/null +++ b/tests/examples/stepping/.gitignore @@ -0,0 +1,5 @@ +framestep1 +*.bb +*.bbg +*.da +framestep1-framestep1.gcno diff --git a/tests/examples/stepping/Makefile.am b/tests/examples/stepping/Makefile.am new file mode 100644 index 0000000000..2a6fbc15c3 --- /dev/null +++ b/tests/examples/stepping/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = framestep1 + +framestep1_LDADD = $(GST_OBJ_LIBS) +framestep1_CFLAGS = $(GST_OBJ_CFLAGS) diff --git a/tests/examples/stepping/framestep1.c b/tests/examples/stepping/framestep1.c new file mode 100644 index 0000000000..6bf7dba027 --- /dev/null +++ b/tests/examples/stepping/framestep1.c @@ -0,0 +1,110 @@ +#include +#include + +static void +event_loop (GstElement * pipe) +{ + GstBus *bus; + GstMessage *message = NULL; + + bus = gst_element_get_bus (GST_ELEMENT (pipe)); + + while (TRUE) { + message = gst_bus_timed_pop_filtered (bus, GST_MESSAGE_ANY, -1); + + g_assert (message != NULL); + + switch (message->type) { + case GST_MESSAGE_EOS: + g_message ("got EOS"); + gst_message_unref (message); + return; + case GST_MESSAGE_WARNING: + case GST_MESSAGE_ERROR:{ + GError *gerror; + gchar *debug; + + gst_message_parse_error (message, &gerror, &debug); + gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); + gst_message_unref (message); + g_error_free (gerror); + g_free (debug); + return; + } + default: + gst_message_unref (message); + break; + } + } +} + +/* signalled when a new preroll buffer is available */ +static void +new_preroll (GstElement * appsink, gpointer user_data) +{ + GstBuffer *buffer; + + g_signal_emit_by_name (appsink, "pull-preroll", &buffer); + + g_message ("have new-preroll buffer %p, timestamp %" GST_TIME_FORMAT, buffer, + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); + + gst_buffer_unref (buffer); +} + +int +main (int argc, char *argv[]) +{ + GstElement *bin, *videotestsrc, *appsink; + + gst_init (&argc, &argv); + + /* create a new bin to hold the elements */ + bin = gst_pipeline_new ("pipeline"); + g_assert (bin); + + /* create a fake source */ + videotestsrc = gst_element_factory_make ("videotestsrc", "videotestsrc"); + g_assert (videotestsrc); + g_object_set (videotestsrc, "num-buffers", 10, NULL); + + /* and a fake sink */ + appsink = gst_element_factory_make ("appsink", "appsink"); + g_assert (appsink); + g_object_set (appsink, "emit-signals", TRUE, NULL); + g_object_set (appsink, "sync", FALSE, NULL); + g_signal_connect (appsink, "new-preroll", (GCallback) new_preroll, NULL); + + /* add objects to the main pipeline */ + gst_bin_add (GST_BIN (bin), videotestsrc); + gst_bin_add (GST_BIN (bin), appsink); + + /* link the elements */ + gst_element_link_many (videotestsrc, appsink, NULL); + + /* go to the PAUSED state and wait for preroll */ + g_message ("prerolling first frame"); + gst_element_set_state (bin, GST_STATE_PAUSED); + gst_element_get_state (bin, NULL, NULL, -1); + + /* step two frames, flush so that new preroll is queued */ + g_message ("stepping two frames"); + g_assert (gst_element_send_event (bin, + gst_event_new_step (GST_FORMAT_BUFFERS, 2, 1.0, TRUE, FALSE))); + + /* wait for step to complete */ + gst_element_get_state (bin, NULL, NULL, -1); + + g_message ("stepped two frames"); + + g_message ("playing until EOS"); + gst_element_set_state (bin, GST_STATE_PLAYING); + /* Run event loop listening for bus messages until EOS or ERROR */ + event_loop (bin); + g_message ("finished"); + + /* stop the bin */ + gst_element_set_state (bin, GST_STATE_NULL); + + exit (0); +}