From d3d661ec7f6a4486d16e27160b13bbf889f8e3e9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 8 Jun 2009 16:41:58 +0200 Subject: [PATCH] examples: add stepping example in PLAYING Add stepping example in PLAYING, audio is a bit distorted because basesink does not provide good clipping info yet. --- tests/examples/seek/.gitignore | 1 + tests/examples/seek/stepping2.c | 140 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 tests/examples/seek/stepping2.c diff --git a/tests/examples/seek/.gitignore b/tests/examples/seek/.gitignore index 7fa03d9..e64781b 100644 --- a/tests/examples/seek/.gitignore +++ b/tests/examples/seek/.gitignore @@ -1,3 +1,4 @@ scrubby seek stepping +stepping2 diff --git a/tests/examples/seek/stepping2.c b/tests/examples/seek/stepping2.c new file mode 100644 index 0000000..a664a6a --- /dev/null +++ b/tests/examples/seek/stepping2.c @@ -0,0 +1,140 @@ +/* GStreamer + * + * stepping.c: stepping sample application + * + * Copyright (C) 2009 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include + +static GMainLoop *loop; + +static gdouble period = 0.0; + +static void +do_step (GstElement * bin) +{ + gdouble rate; + + rate = sin (period); + + period += M_PI / 150; + + rate += 1.2; + + gst_element_send_event (bin, + gst_event_new_step (GST_FORMAT_TIME, 40 * GST_MSECOND, rate, FALSE, + FALSE)); +} + +static void +handle_sync_message (GstBus * bus, GstMessage * message, gpointer data) +{ + GstElement *bin = GST_ELEMENT_CAST (data); + + switch (message->type) { + case GST_MESSAGE_STEP_DONE: + do_step (bin); + break; + default: + break; + } +} + +static void +handle_message (GstBus * bus, GstMessage * message, gpointer data) +{ + switch (message->type) { + case GST_MESSAGE_EOS: + g_message ("got EOS"); + g_main_loop_quit (loop); + break; + case GST_MESSAGE_WARNING: + case GST_MESSAGE_ERROR: + { + GError *gerror; + gchar *debug; + + if (message->type == GST_MESSAGE_ERROR) + gst_message_parse_error (message, &gerror, &debug); + else + gst_message_parse_warning (message, &gerror, &debug); + + gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); + g_error_free (gerror); + g_free (debug); + if (message->type == GST_MESSAGE_ERROR) + g_main_loop_quit (loop); + break; + } + default: + break; + } +} + +int +main (int argc, char *argv[]) +{ + GstElement *bin; + GstBus *bus; + + gst_init (&argc, &argv); + + if (argc < 2) { + g_print ("usage: %s \n", argv[0]); + return -1; + } + + /* create a new bin to hold the elements */ + bin = gst_element_factory_make ("playbin2", "bin"); + g_assert (bin); + g_object_set (bin, "uri", argv[1], NULL); + + bus = gst_pipeline_get_bus (GST_PIPELINE (bin)); + gst_bus_add_signal_watch (bus); + gst_bus_enable_sync_message_emission (bus); + + g_signal_connect (bus, "message", (GCallback) handle_message, bin); + g_signal_connect (bus, "sync-message", (GCallback) handle_sync_message, bin); + + /* 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); + + /* queue step */ + do_step (bin); + + gst_element_set_state (bin, GST_STATE_PLAYING); + + loop = g_main_loop_new (NULL, TRUE); + g_main_loop_run (loop); + + g_message ("finished"); + + /* stop the bin */ + gst_element_set_state (bin, GST_STATE_NULL); + + g_main_loop_unref (loop); + gst_object_unref (bus); + + exit (0); +} -- 2.7.4