summaryrefslogtreecommitdiff
path: root/examples/filesrc.py
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2005-07-12 13:27:32 +0000
committerAndy Wingo <wingo@pobox.com>2005-07-12 13:27:32 +0000
commit74f550caf049f7234b0f3e921fe3af2d643b3e8e (patch)
tree80d3420bdc409e555a07c9f5c851a2179d7175b3 /examples/filesrc.py
parent8136f429105b401e6df9a06069ff76751ae81c0c (diff)
Moved all examples up from examples/gst/ into examples/.
Original commit message from CVS: 2005-07-12 Andy Wingo <wingo@pobox.com> * configure.ac (AC_CONFIG_FILES): * examples/: Moved all examples up from examples/gst/ into examples/.
Diffstat (limited to 'examples/filesrc.py')
-rwxr-xr-xexamples/filesrc.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/examples/filesrc.py b/examples/filesrc.py
new file mode 100755
index 0000000..b2e680b
--- /dev/null
+++ b/examples/filesrc.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+#
+# GStreamer python bindings
+# Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
+# 2004 Johan Dahlin <johan@gnome.org>
+#
+# filesrc.py: implements a file source element completely in python
+#
+# 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import sys
+import gobject
+import gst
+
+class FileSource(gst.Element):
+ blocksize = 4096
+ fd = None
+ def __init__(self, name):
+ self.__gobject_init__()
+ self.set_name(name)
+ self.srcpad = gst.Pad('src', gst.PAD_SRC)
+ self.srcpad.set_get_function(self.srcpad_get)
+ self.add_pad(self.srcpad)
+
+ def set_property(self, name, value):
+ if name == 'location':
+ self.fd = open(value, 'r')
+
+ def srcpad_get(self, pad):
+ data = self.fd.read(self.blocksize)
+ if data:
+ return gst.Buffer(data)
+ else:
+ self.set_eos()
+ return gst.Event(gst.EVENT_EOS)
+gobject.type_register(FileSource)
+
+def main(args):
+ print 'This example is not finished yet.'
+ return
+
+ if len(args) != 3:
+ print 'Usage: %s input output' % (args[0])
+ return -1
+
+ bin = gst.Pipeline('pipeline')
+
+ filesrc = FileSource('filesource')
+ #filesrc = gst.Element('filesrc', 'src')
+ assert filesrc
+ filesrc.set_property('location', args[1])
+
+ filesink = gst.element_factory_make('filesink', 'sink')
+ filesink.set_property('location', args[2])
+
+ bin.add_many(filesrc, filesink)
+ gst.element_link_many(filesrc, filesink)
+
+ bin.set_state(gst.STATE_PLAYING);
+
+ while bin.iterate():
+ pass
+
+ bin.set_state(gst.STATE_NULL)
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+