1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
28 #include <glib/gstdio.h>
30 #include <gst/pbutils/encoding-profile.h>
34 static guint repeat = 0;
35 GESTimelinePipeline *pipeline = NULL;
37 static gboolean thumbnail_cb (gpointer pipeline);
39 #define TEST_PATH "test_thumbnail.jpg"
42 thumbnail_cb (gpointer user)
46 GESTimelinePipeline *p;
48 p = GES_TIMELINE_PIPELINE (user);
50 caps = gst_caps_from_string ("image/jpeg");
51 GST_INFO ("getting thumbnails");
53 /* check raw rgb use-case with scaling */
54 b = ges_timeline_pipeline_get_thumbnail_rgb24 (p, 320, 240);
58 /* check encoding use-case from caps */
60 b = ges_timeline_pipeline_get_thumbnail_buffer (p, caps);
64 g_assert (ges_timeline_pipeline_save_thumbnail (p, -1, -1, (gchar *)
65 "image/jpeg", (gchar *) TEST_PATH));
66 g_assert (g_file_test (TEST_PATH, G_FILE_TEST_EXISTS));
69 gst_caps_unref (caps);
73 static GESTimelinePipeline *
74 create_timeline (void)
76 GESTimelinePipeline *pipeline;
77 GESTimelineLayer *layer;
78 GESTrack *tracka, *trackv;
79 GESTimeline *timeline;
80 GESTimelineObject *src;
82 timeline = ges_timeline_new ();
84 tracka = ges_track_audio_raw_new ();
85 trackv = ges_track_video_raw_new ();
87 layer = (GESTimelineLayer *) ges_simple_timeline_layer_new ();
89 /* Add the tracks and the layer to the timeline */
90 if (!ges_timeline_add_layer (timeline, layer) ||
91 !ges_timeline_add_track (timeline, tracka) ||
92 !ges_timeline_add_track (timeline, trackv))
95 /* Add the main audio/video file */
96 src = GES_TIMELINE_OBJECT (ges_timeline_test_source_new ());
98 "vpattern", GES_VIDEO_TEST_PATTERN_SNOW,
99 "duration", 10 * GST_SECOND, NULL);
101 ges_simple_timeline_layer_add_object ((GESSimpleTimelineLayer *) layer,
102 GES_TIMELINE_OBJECT (src), 0);
104 pipeline = ges_timeline_pipeline_new ();
106 if (!ges_timeline_pipeline_add_timeline (pipeline, timeline))
113 bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
115 switch (GST_MESSAGE_TYPE (message)) {
116 case GST_MESSAGE_ERROR:
118 g_main_loop_quit (mainloop);
120 case GST_MESSAGE_EOS:
122 g_print ("Looping again\n");
123 /* No need to change state before */
124 gst_element_seek_simple (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
125 GST_SEEK_FLAG_FLUSH, 0);
126 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
130 g_main_loop_quit (mainloop);
139 main (int argc, gchar ** argv)
142 GOptionEntry options[] = {
149 if (!g_thread_supported ())
150 g_thread_init (NULL);
152 ctx = g_option_context_new ("tests thumbnail supoprt (produces no output)");
153 g_option_context_set_summary (ctx, "");
154 g_option_context_add_main_entries (ctx, options, NULL);
155 g_option_context_add_group (ctx, gst_init_get_option_group ());
157 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
158 g_print ("Error initializing: %s\n", err->message);
159 g_option_context_free (ctx);
163 g_option_context_free (ctx);
164 /* Initialize the GStreamer Editing Services */
167 /* Create the pipeline */
168 pipeline = create_timeline ();
172 ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW);
174 /* Play the pipeline */
175 mainloop = g_main_loop_new (NULL, FALSE);
177 g_print ("thumbnailing every 1 seconds\n");
178 g_timeout_add (1000, thumbnail_cb, pipeline);
180 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
181 gst_bus_add_signal_watch (bus);
182 g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop);
184 if (gst_element_set_state (GST_ELEMENT (pipeline),
185 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
186 g_print ("Failed to start the encoding\n");
189 g_main_loop_run (mainloop);
191 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
192 gst_object_unref (pipeline);