• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2006> Zaheer Abbas Merali <zaheerabbas at merali dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <gst/gst.h>
25 
26 static GMainLoop *loop;
27 
28 static gboolean
terminate_playback(GstElement * pipeline)29 terminate_playback (GstElement * pipeline)
30 {
31   g_print ("Terminating playback\n");
32   g_main_loop_quit (loop);
33   return FALSE;
34 }
35 
36 int
main(int argc,char ** argv)37 main (int argc, char **argv)
38 {
39   GstElement *pipeline;
40   GstState state;
41   GError *error = NULL;
42 
43   gst_init (&argc, &argv);
44 
45   pipeline = gst_parse_launch ("ximagesrc ! fakesink", &error);
46   if (error) {
47     g_print ("Error while parsing pipeline description: %s\n", error->message);
48     return -1;
49   }
50 
51   loop = g_main_loop_new (NULL, FALSE);
52 
53   gst_element_set_state (pipeline, GST_STATE_PLAYING);
54 
55   /* lets check it gets to PLAYING */
56   if (gst_element_get_state (pipeline, &state, NULL,
57           GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_FAILURE ||
58       state != GST_STATE_PLAYING) {
59     g_warning ("State change to playing failed");
60   }
61 
62   /* We want to get out after 5 seconds */
63   g_timeout_add_seconds (5, (GSourceFunc) terminate_playback, pipeline);
64 
65   g_main_loop_run (loop);
66 
67   g_main_loop_unref (loop);
68 
69   return 0;
70 }
71