home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gst0.10 / examples / sinkelement.py < prev    next >
Encoding:
Python Source  |  2009-02-21  |  1.6 KB  |  69 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. gobject.threads_init ()
  20.  
  21. #
  22. # Simple Sink element created entirely in python
  23. #
  24.  
  25. class MySink(gst.Element):
  26.  
  27.     _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
  28.                                         gst.PAD_SINK,
  29.                                         gst.PAD_ALWAYS,
  30.                                         gst.caps_new_any())
  31.  
  32.     def __init__(self):
  33.         gst.Element.__init__(self)
  34.         gst.info('creating sinkpad')
  35.         self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink")
  36.         gst.info('adding sinkpad to self')
  37.         self.add_pad(self.sinkpad)
  38.  
  39.         gst.info('setting chain/event functions')
  40.         self.sinkpad.set_chain_function(self.chainfunc)
  41.         self.sinkpad.set_event_function(self.eventfunc)
  42.         
  43.     def chainfunc(self, pad, buffer):
  44.         self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
  45.         return gst.FLOW_OK
  46.  
  47.     def eventfunc(self, pad, event):
  48.         self.info("%s event:%r" % (pad, event.type))
  49.         return True
  50.  
  51. gobject.type_register(MySink)
  52.  
  53. #
  54. # Code to test the MySink class
  55. #
  56.  
  57. src = gst.element_factory_make('fakesrc')
  58. gst.info('About to create MySink')
  59. sink = MySink()
  60.  
  61. pipeline = gst.Pipeline()
  62. pipeline.add(src, sink)
  63.  
  64. src.link(sink)
  65.  
  66. pipeline.set_state(gst.STATE_PLAYING)
  67.  
  68. gobject.MainLoop().run()
  69.