First commit, progress so far
authorEinar Jørgen Haraldseid <einar@haraldseid.net>
Wed, 18 Jun 2014 13:53:11 +0000 (15:53 +0200)
committerEinar Jørgen Haraldseid <einar@haraldseid.net>
Wed, 18 Jun 2014 13:53:11 +0000 (15:53 +0200)
README.md [new file with mode: 0644]
example1.py [new file with mode: 0755]
example2.glade [new file with mode: 0644]
example2.py [new file with mode: 0755]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..0cd5581
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+Python/GStreamer examples
+=========================
+This is my first foray into Gstreamer programming with Python, I'm working from this tutorial:
+
+http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
+
+I know little to no Python before starting on this, and the tutorial is nearly eight years old, so this ought to be interesting …
diff --git a/example1.py b/example1.py
new file mode 100755 (executable)
index 0000000..d69135a
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# This is a reworked version of the example from Jono Bacon's Python+Gstreamer
+# primer: http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
+# 
+# It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and
+# drops the use of the GTK main loop, since we're not bothered with a GUI
+# Info on porting python scripts to Gstreamer 1.0 can be found here:
+# https://wiki.ubuntu.com/Novacut/GStreamer1.0
+
+
+import gi
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst
+import gobject
+
+class Main:
+  def __init__(self):
+    # Initiate the pipeline
+    Gst.init(None)
+    self.pipeline = Gst.Pipeline("mypipeline")
+
+    # Add an audiotestsrc element to the pipeline
+    self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio")
+    self.pipeline.add(self.audiotestsrc)
+
+    # Add a pulsesink element to the pipeline
+    self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink")
+    self.pipeline.add(self.pulsesink)
+
+    # Link the two elements together
+    self.audiotestsrc.link(self.pulsesink)
+
+    # Set the pipeline to the playing state
+    self.pipeline.set_state(Gst.State.PLAYING)
+
+# Create the pipelie and enter main loop, quit with ctrl+c
+start = Main()
+mainloop = gobject.MainLoop()
+mainloop.run()
diff --git a/example2.glade b/example2.glade
new file mode 100644 (file)
index 0000000..dec56c2
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <object class="GtkWindow" id="mainwindow">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Gstreamer-test</property>
+    <property name="icon_name">audio-volume-high</property>
+    <child>
+      <object class="GtkButtonBox" id="hbuttonbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">20</property>
+        <property name="margin_right">20</property>
+        <property name="margin_top">20</property>
+        <property name="margin_bottom">10</property>
+        <property name="spacing">10</property>
+        <property name="homogeneous">True</property>
+        <property name="layout_style">center</property>
+        <child>
+          <object class="GtkButton" id="button1">
+            <property name="label">gtk-media-play</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_stock">True</property>
+            <property name="always_show_image">True</property>
+            <signal name="clicked" handler="on_play_clicked" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="button2">
+            <property name="label">gtk-stop</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_stock">True</property>
+            <property name="always_show_image">True</property>
+            <signal name="clicked" handler="on_stop_clicked" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="button3">
+            <property name="label">gtk-quit</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_stock">True</property>
+            <property name="always_show_image">True</property>
+            <signal name="clicked" handler="on_quit_clicked" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/example2.py b/example2.py
new file mode 100755 (executable)
index 0000000..21d4dbb
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+# This is a reworked version of the example from Jono Bacon's Python+Gstreamer primer:
+# http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
+# 
+# It uses Gstreamer 1.0, GTK3, and replaces alsa with pulse for audio output
+# Info on porting python scripts to GStreamer 1.0 can be found here:
+# https://wiki.ubuntu.com/Novacut/GStreamer1.0
+
+from gi.repository import Gtk, Gst
+import signal
+
+class Main:
+    def __init__(self):
+        
+        # Create gui bits and bobs
+
+        self.wTree = Gtk.Builder()
+        self.wTree.add_from_file("example2.glade")
+        
+        signals = {
+            "on_play_clicked" : self.OnPlay,
+            "on_stop_clicked" : self.OnStop,
+            "on_quit_clicked" : self.OnQuit,
+        }
+
+        self.wTree.connect_signals(signals)
+
+        # Create GStreamer bits and bobs
+
+        # Initiate the pipeline
+        Gst.init(None)
+        self.pipeline = Gst.Pipeline("mypipeline")
+
+        # Add an audiotestsrc element to the pipeline
+        self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio")
+        self.audiotestsrc.set_property("freq", 200)
+        self.pipeline.add(self.audiotestsrc)
+
+        # Add a pulsesink element to the pipeline
+        self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink")
+        self.pipeline.add(self.pulsesink)
+
+        # Link the two elements together
+        self.audiotestsrc.link(self.pulsesink)
+
+        # Summon the window and connect the window's close button to Quit
+        self.window = self.wTree.get_object("mainwindow")
+        self.window.connect("delete-event", Gtk.main_quit)
+        self.window.show_all()
+
+
+    def OnPlay(self, widget):
+        print "play"
+        self.pipeline.set_state(Gst.State.PLAYING)
+
+    def OnStop(self, widget):
+        print "stop"
+        self.pipeline.set_state(Gst.State.READY)
+        
+    def OnQuit(self, widget):
+        print "quit"
+        Gtk.main_quit()
+
+    # Workaround to get Ctrl+C to terminate from command line
+    # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+start = Main()
+Gtk.main()