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 / f2f.py < prev    next >
Encoding:
Python Source  |  2006-07-31  |  1.9 KB  |  65 lines

  1. #!/usr/bin/env python
  2. # -*- Mode: Python -*-
  3. # vi:si:et:sw=4:sts=4:ts=4
  4.  
  5. # gst-python
  6. # Copyright (C) 2002 David I. Lehn
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Library General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2 of the License, or (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. # Library General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Library General Public
  19. # License along with this library; if not, write to the
  20. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. # Boston, MA 02111-1307, USA.
  22. # Author: David I. Lehn <dlehn@users.sourceforge.net>
  23. #
  24.  
  25. import sys
  26.  
  27. import pygst
  28. pygst.require('0.10')
  29.  
  30. import gst
  31.  
  32. def handoff_cb(sender, *args):
  33.    print sender.get_name(), args
  34.  
  35. def main(args):
  36.    # create a new bin to hold the elements
  37.    #gst_debug_set_categories(-1)
  38.    bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 signal-handoffs=true ! ' +
  39.                           'fakesink name=sink silent=1 signal-handoffs=true')
  40.    source = bin.get_by_name('source')
  41.    source.connect('handoff', handoff_cb)
  42.    source.get_pad("src").connect("have-data", handoff_cb)
  43.    sink = bin.get_by_name('sink')
  44.    sink.connect('handoff', handoff_cb)
  45.    sink.get_pad("sink").connect('have-data', handoff_cb)
  46.  
  47.    print source, sink
  48.  
  49.    bus = bin.get_bus()
  50.    
  51.    res = bin.set_state(gst.STATE_PLAYING);
  52.    assert res
  53.  
  54.    while 1:
  55.       msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)
  56.       if msg:
  57.          break
  58.  
  59.    res = bin.set_state(gst.STATE_NULL)
  60.    assert res
  61.  
  62. if __name__ == '__main__':
  63.    sys.exit(main(sys.argv))
  64.