examples: Move all examples to the root dir and create foldersdir per language
authorThibault Saunier <tsaunier@gnome.org>
Thu, 12 Mar 2015 12:57:28 +0000 (13:57 +0100)
committerThibault Saunier <tsaunier@gnome.org>
Mon, 21 Dec 2015 14:35:17 +0000 (15:35 +0100)
+ Add some markdown files to link between languages
+ Add a simple 'play timeline with one clip" example in C and python

24 files changed:
Makefile.am
bindings/python/Makefile.am
bindings/python/examples/Makefile.am [deleted file]
configure.ac
examples/.gitignore [moved from tests/examples/.gitignore with 100% similarity]
examples/Makefile.am [new file with mode: 0644]
examples/c/Makefile.am [moved from tests/examples/Makefile.am with 93% similarity]
examples/c/assets.c [moved from tests/examples/assets.c with 100% similarity]
examples/c/concatenate.c [moved from tests/examples/concatenate.c with 100% similarity]
examples/c/ges-ui.c [moved from tests/examples/ges-ui.c with 100% similarity]
examples/c/ges-ui.glade [moved from tests/examples/ges-ui.glade with 100% similarity]
examples/c/multifilesrc.c [moved from tests/examples/multifilesrc.c with 100% similarity]
examples/c/overlays.c [moved from tests/examples/overlays.c with 100% similarity]
examples/c/play_timeline_with_one_clip.c [new file with mode: 0644]
examples/c/simple1.c [moved from tests/examples/simple1.c with 100% similarity]
examples/c/test1.c [moved from tests/examples/test1.c with 100% similarity]
examples/c/test2.c [moved from tests/examples/test2.c with 100% similarity]
examples/c/test3.c [moved from tests/examples/test3.c with 100% similarity]
examples/c/test4.c [moved from tests/examples/test4.c with 100% similarity]
examples/c/text_properties.c [moved from tests/examples/text_properties.c with 100% similarity]
examples/c/thumbnails.c [moved from tests/examples/thumbnails.c with 100% similarity]
examples/c/transition.c [moved from tests/examples/transition.c with 100% similarity]
examples/python/simple.py [new file with mode: 0755]
tests/Makefile.am

index e33bfd2..979caa6 100644 (file)
@@ -1,6 +1,12 @@
 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc --with-bash-completion-dir=no
 
-SUBDIRS = ges tests tools common m4 pkgconfig docs bindings plugins
+if BUILD_EXAMPLES
+EXAMPLES_SUBDIRS= examples
+else
+EXAMPLES_SUBDIRS=
+endif
+
+SUBDIRS = ges tests tools common m4 pkgconfig docs bindings plugins $(EXAMPLES_SUBDIRS)
 
 DIST_SUBDIRS = $(SUBDIRS)
 
index 22bf444..14602de 100644 (file)
@@ -1,5 +1 @@
 SUBDIRS = gi
-
-if BUILD_EXAMPLES
-SUBDIRS += examples
-endif
diff --git a/bindings/python/examples/Makefile.am b/bindings/python/examples/Makefile.am
deleted file mode 100644 (file)
index e69de29..0000000
index 6e36dc6..77a38b1 100644 (file)
@@ -460,7 +460,8 @@ ges/Makefile
 tests/Makefile
 tests/check/Makefile
 tests/benchmarks/Makefile
-tests/examples/Makefile
+examples/Makefile
+examples/c/Makefile
 tests/validate/Makefile
 tests/validate/scenarios/Makefile
 tools/Makefile
@@ -476,6 +477,5 @@ bindings/Makefile
 bindings/python/Makefile
 bindings/python/gi/Makefile
 bindings/python/gi/overrides/Makefile
-bindings/python/examples/Makefile
 )
 AC_OUTPUT
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644 (file)
index 0000000..a328175
--- /dev/null
@@ -0,0 +1,5 @@
+SUBDIRS = c
+
+AM_CFLAGS =  -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS)
+AM_LDFLAGS = -export-dynamic
+LDADD = $(top_builddir)/ges/libges-@GST_API_VERSION@.la $(GST_PBUTILS_LIBS) $(GST_LIBS) $(GTK_LIBS)
similarity index 93%
rename from tests/examples/Makefile.am
rename to examples/c/Makefile.am
index 4d55a94..35c9d0e 100644 (file)
@@ -17,8 +17,10 @@ noinst_PROGRAMS =    \
        text_properties \
        assets \
        multifilesrc \
+       play_timeline_with_one_clip \
        $(graphical)
 
 AM_CFLAGS =  -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS)
 AM_LDFLAGS = -export-dynamic
 LDADD = $(top_builddir)/ges/libges-@GST_API_VERSION@.la $(GST_PBUTILS_LIBS) $(GST_LIBS) $(GTK_LIBS)
+
similarity index 100%
rename from tests/examples/assets.c
rename to examples/c/assets.c
similarity index 100%
rename from tests/examples/ges-ui.c
rename to examples/c/ges-ui.c
diff --git a/examples/c/play_timeline_with_one_clip.c b/examples/c/play_timeline_with_one_clip.c
new file mode 100644 (file)
index 0000000..745def4
--- /dev/null
@@ -0,0 +1,62 @@
+/* This example can be found in the GStreamer Editing Services git repository in:
+ * examples/c/play_timeline_with_one_clip.c
+ */
+#include <ges/ges.h>
+
+int
+main (int argc, char **argv)
+{
+  GESLayer *layer;
+  GESTimeline *timeline;
+
+  if (argc == 1) {
+    g_printerr ("Usage: play_timeline_with_one_clip file:///clip/uri\n");
+
+    return 1;
+  }
+
+  gst_init (NULL, NULL);
+  ges_init ();
+
+  timeline = ges_timeline_new_audio_video ();
+  layer = ges_timeline_append_layer (timeline);
+
+  {
+    /* Add a clip with a duration of 5 seconds */
+    GESClip *clip = GES_CLIP (ges_uri_clip_new (argv[1]));
+
+    if (clip == NULL) {
+      g_printerr ("%s can not be used, make sure it is a supported media file",
+              argv[1]);
+
+      return 1;
+    }
+
+    g_object_set (clip, "duration", 5 * GST_SECOND, "start", 0, NULL);
+    ges_layer_add_clip (layer, clip);
+  }
+
+  /* Commiting the timeline is always necessary for changes
+   * inside it to be taken into account by the Non Linear Engine */
+  ges_timeline_commit (timeline);
+
+  {
+    /* Play the timeline */
+    GESPipeline *pipeline = ges_pipeline_new ();
+    GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+
+    ges_pipeline_set_timeline (pipeline, timeline);
+    gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
+
+    /* Simple way to just play the pipeline until EOS or an error pops on the bus */
+    gst_bus_timed_pop_filtered (bus, 10 * GST_SECOND,
+        GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
+
+    gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+    gst_object_unref (bus);
+    gst_object_unref (pipeline);
+  }
+
+
+  return 0;
+}
similarity index 100%
rename from tests/examples/test1.c
rename to examples/c/test1.c
similarity index 100%
rename from tests/examples/test2.c
rename to examples/c/test2.c
similarity index 100%
rename from tests/examples/test3.c
rename to examples/c/test3.c
similarity index 100%
rename from tests/examples/test4.c
rename to examples/c/test4.c
diff --git a/examples/python/simple.py b/examples/python/simple.py
new file mode 100755 (executable)
index 0000000..1de9f6e
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+#
+# GStreamer
+#
+# Copyright (C) 2013 Thibault Saunier <tsaunier@gnome.org
+#
+# 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., 51 Franklin Street, Suite 500,
+# Boston, MA 02110-1335, USA.
+
+import os
+import gi
+
+gi.require_version('Gst', '1.0')
+gi.require_version('GES', '1.0')
+
+from gi.repository import Gst, GES, GLib  # noqa
+
+
+class Simple:
+    def __init__(self, uri):
+        timeline = GES.Timeline.new_audio_video()
+        self.project = timeline.get_asset()
+
+        self.project.connect("asset-added", self._asset_added_cb)
+        self.project.connect("error-loading-asset", self._error_loading_asset_cb)
+        self.project.create_asset(uri, GES.UriClip)
+        self.layer = timeline.append_layer()
+        self._create_pipeline(timeline)
+        self.loop = GLib.MainLoop()
+
+    def _create_pipeline(self, timeline):
+        self.pipeline = GES.Pipeline()
+        self.pipeline.set_timeline(timeline)
+        bus = self.pipeline.get_bus()
+        bus.add_signal_watch()
+        bus.connect("message", self.bus_message_cb)
+
+    def bus_message_cb(self, unused_bus, message):
+        if message.type == Gst.MessageType.EOS:
+            print("eos")
+            self.loop.quit()
+        elif message.type == Gst.MessageType.ERROR:
+            error = message.parse_error()
+            print("error %s" % error[1])
+            self.loop.quit()
+
+    def start(self):
+        self.loop.run()
+
+    def _asset_added_cb(self, project, asset):
+        self.layer.add_asset(asset, 0, 0, Gst.SECOND * 5, GES.TrackType.UNKNOWN)
+        self.pipeline.set_state(Gst.State.PLAYING)
+
+    def _error_loading_asset_cb(self, project, error, asset_id, type):
+        print("Could not load asset %s: %s" % (asset_id, error))
+        self.loop.quit()
+
+if __name__ == "__main__":
+    if len(os.sys.argv) != 2:
+        print("You must specify a file URI")
+        exit(-1)
+
+    Gst.init(None)
+    GES.init()
+    simple = Simple(os.sys.argv[1])
+    simple.start()
index 3b1d741..349ec3c 100644 (file)
@@ -4,12 +4,6 @@ else
 CHECK_SUBDIRS=
 endif
 
-if BUILD_EXAMPLES
-EXAMPLES_SUBDIRS= examples
-else
-EXAMPLES_SUBDIRS=
-endif
-
 if BUILD_BENCHMARKS
 BENCHMARKS_SUBDIR=benchmarks
 else
@@ -22,7 +16,7 @@ else
 VALIDATE_SUBDIRS=
 endif
 
-SUBDIRS= $(CHECK_SUBDIRS) $(EXAMPLES_SUBDIRS) $(BENCHMARKS_SUBDIR) $(VALIDATE_SUBDIRS)
+SUBDIRS= $(CHECK_SUBDIRS) $(BENCHMARKS_SUBDIR) $(VALIDATE_SUBDIRS)
 
-DIST_SUBDIRS = check examples benchmarks validate
+DIST_SUBDIRS = check benchmarks validate