|
Packit |
971217 |
/* GStreamer
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* stepping.c: stepping sample application
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
971217 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
971217 |
* License as published by the Free Software Foundation; either
|
|
Packit |
971217 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
971217 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
971217 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
971217 |
* Library General Public License for more details.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
971217 |
* License along with this library; if not, write to the
|
|
Packit |
971217 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
971217 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <stdlib.h>
|
|
Packit |
971217 |
#include <math.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gst/gst.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GMainLoop *loop;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gdouble period = 0.0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
do_step (GstElement * bin)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gdouble rate;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
rate = sin (period);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
period += G_PI / 150;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
rate += 1.2;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_element_send_event (bin,
|
|
Packit |
971217 |
gst_event_new_step (GST_FORMAT_TIME, 40 * GST_MSECOND, rate, FALSE,
|
|
Packit |
971217 |
FALSE));
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
handle_sync_message (GstBus * bus, GstMessage * message, gpointer data)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstElement *bin;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
bin = GST_ELEMENT_CAST (data);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
switch (message->type) {
|
|
Packit |
971217 |
case GST_MESSAGE_STEP_DONE:
|
|
Packit |
971217 |
do_step (bin);
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
default:
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
handle_message (GstBus * bus, GstMessage * message, gpointer data)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
switch (message->type) {
|
|
Packit |
971217 |
case GST_MESSAGE_EOS:
|
|
Packit |
971217 |
g_message ("got EOS");
|
|
Packit |
971217 |
g_main_loop_quit (loop);
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
case GST_MESSAGE_WARNING:
|
|
Packit |
971217 |
case GST_MESSAGE_ERROR:
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GError *gerror;
|
|
Packit |
971217 |
gchar *debug;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (message->type == GST_MESSAGE_ERROR)
|
|
Packit |
971217 |
gst_message_parse_error (message, &gerror, &debug);
|
|
Packit |
971217 |
else
|
|
Packit |
971217 |
gst_message_parse_warning (message, &gerror, &debug);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
|
Packit |
971217 |
g_error_free (gerror);
|
|
Packit |
971217 |
g_free (debug);
|
|
Packit |
971217 |
if (message->type == GST_MESSAGE_ERROR)
|
|
Packit |
971217 |
g_main_loop_quit (loop);
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
default:
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
int
|
|
Packit |
971217 |
main (int argc, char *argv[])
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstElement *bin;
|
|
Packit |
971217 |
GstBus *bus;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_init (&argc, &argv);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (argc < 2) {
|
|
Packit |
971217 |
g_print ("usage: %s <uri>\n", argv[0]);
|
|
Packit |
971217 |
return -1;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* create a new bin to hold the elements */
|
|
Packit |
971217 |
bin = gst_element_factory_make ("playbin", "bin");
|
|
Packit |
971217 |
g_assert (bin);
|
|
Packit |
971217 |
g_object_set (bin, "uri", argv[1], NULL);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
|
|
Packit |
971217 |
gst_bus_add_signal_watch (bus);
|
|
Packit |
971217 |
gst_bus_enable_sync_message_emission (bus);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_signal_connect (bus, "message", (GCallback) handle_message, bin);
|
|
Packit |
971217 |
g_signal_connect (bus, "sync-message", (GCallback) handle_sync_message, bin);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* go to the PAUSED state and wait for preroll */
|
|
Packit |
971217 |
g_message ("prerolling first frame");
|
|
Packit |
971217 |
gst_element_set_state (bin, GST_STATE_PAUSED);
|
|
Packit |
971217 |
gst_element_get_state (bin, NULL, NULL, -1);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* queue step */
|
|
Packit |
971217 |
do_step (bin);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_element_set_state (bin, GST_STATE_PLAYING);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
loop = g_main_loop_new (NULL, TRUE);
|
|
Packit |
971217 |
g_main_loop_run (loop);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_message ("finished");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* stop the bin */
|
|
Packit |
971217 |
gst_element_set_state (bin, GST_STATE_NULL);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_main_loop_unref (loop);
|
|
Packit |
971217 |
gst_object_unref (bus);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
exit (0);
|
|
Packit |
971217 |
}
|