ges: Port to gst_print*
[platform/upstream/gst-editing-services.git] / examples / c / test3.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
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 #include <ges/ges.h>
21
22 int
23 main (int argc, gchar ** argv)
24 {
25   GESPipeline *pipeline;
26   GESTimeline *timeline;
27   GESTrack *tracka;
28   GESLayer *layer;
29   GMainLoop *mainloop;
30   guint i;
31
32   if (argc < 2) {
33     gst_print ("Usage: %s <list of audio files>\n", argv[0]);
34     return -1;
35   }
36
37   /* Initialize GStreamer (this will parse environment variables and commandline
38    * arguments. */
39   gst_init (&argc, &argv);
40
41   /* Initialize the GStreamer Editing Services */
42   ges_init ();
43
44   /* Setup of an audio timeline */
45
46   /* This is our main GESTimeline */
47   timeline = ges_timeline_new ();
48
49   tracka = GES_TRACK (ges_audio_track_new ());
50
51   /* We are only going to be doing one layer of clips */
52   layer = ges_layer_new ();
53
54   /* Add the tracks and the layer to the timeline */
55   if (!ges_timeline_add_layer (timeline, layer))
56     return -1;
57   if (!ges_timeline_add_track (timeline, tracka))
58     return -1;
59
60   /* Here we've finished initializing our timeline, we're
61    * ready to start using it... by solely working with the layer ! */
62
63   for (i = 1; i < argc; i++) {
64     gchar *uri = gst_filename_to_uri (argv[i], NULL);
65     GESUriClip *src = ges_uri_clip_new (uri);
66
67     g_assert (src);
68     g_free (uri);
69
70     g_object_set (src, "start", ges_layer_get_duration (layer),
71         "duration", GST_SECOND, NULL);
72     ges_layer_add_clip (layer, (GESClip *) src);
73   }
74
75   /* In order to view our timeline, let's grab a convenience pipeline to put
76    * our timeline in. */
77   pipeline = ges_pipeline_new ();
78
79   /* Add the timeline to that pipeline */
80   if (!ges_pipeline_set_timeline (pipeline, timeline))
81     return -1;
82
83   /* The following is standard usage of a GStreamer pipeline (note how you haven't
84    * had to care about GStreamer so far ?).
85    *
86    * We set the pipeline to playing ... */
87   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
88
89   /* .. and we start a GMainLoop. GES **REQUIRES** a GMainLoop to be running in
90    * order to function properly ! */
91   mainloop = g_main_loop_new (NULL, FALSE);
92
93   /* Simple code to have the mainloop shutdown after 4s */
94   g_timeout_add_seconds (argc - 1, (GSourceFunc) g_main_loop_quit, mainloop);
95   g_main_loop_run (mainloop);
96
97   return 0;
98 }