home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-gst0.10 / examples / sinkelement.py < prev    next >
Encoding:
Python Source  |  2006-07-31  |  1.6 KB  |  68 lines

  1. #!/usr/bin/env python
  2. # -*- Mode: Python -*-
  3. # vi:si:et:sw=4:sts=4:ts=4
  4.  
  5. # sinkelement.py
  6. # (c) 2005 Edward Hervey <edward@fluendo.com>
  7. # Licensed under LGPL
  8. #
  9. # Small test application to show how to write a sink element
  10. # in 20 lines in python
  11. #
  12. # Run this script with GST_DEBUG=python:5 to see the debug
  13. # messages
  14.  
  15. import pygst
  16. pygst.require('0.10')
  17. import gst
  18. import gobject
  19.  
  20. #
  21. # Simple Sink element created entirely in python
  22. #
  23.  
  24. class MySink(gst.Element):
  25.  
  26.     _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
  27.                                         gst.PAD_SINK,
  28.                                         gst.PAD_ALWAYS,
  29.                                         gst.caps_new_any())
  30.  
  31.     def __init__(self):
  32.         gst.Element.__init__(self)
  33.         gst.info('creating sinkpad')
  34.         self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink")
  35.         gst.info('adding sinkpad to self')
  36.         self.add_pad(self.sinkpad)
  37.  
  38.         gst.info('setting chain/event functions')
  39.         self.sinkpad.set_chain_function(self.chainfunc)
  40.         self.sinkpad.set_event_function(self.eventfunc)
  41.         
  42.     def chainfunc(self, pad, buffer):
  43.         self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
  44.         return gst.FLOW_OK
  45.  
  46.     def eventfunc(self, pad, event):
  47.         self.info("%s event:%r" % (pad, event.type))
  48.         return True
  49.  
  50. gobject.type_register(MySink)
  51.  
  52. #
  53. # Code to test the MySink class
  54. #
  55.  
  56. src = gst.element_factory_make('fakesrc')
  57. gst.info('About to create MySink')
  58. sink = MySink()
  59.  
  60. pipeline = gst.Pipeline()
  61. pipeline.add(src, sink)
  62.  
  63. src.link(sink)
  64.  
  65. pipeline.set_state(gst.STATE_PLAYING)
  66.  
  67. gobject.MainLoop().run()
  68.