f2f.py 1.86 KB
Newer Older
1
#!/usr/bin/env python
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
2 3 4
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

David I. Lehn's avatar
David I. Lehn committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# gst-python
# Copyright (C) 2002 David I. Lehn
#
# 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
Simon Farnsworth's avatar
Simon Farnsworth committed
20
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
# Boston, MA 02110-1301, USA.
David I. Lehn's avatar
David I. Lehn committed
22
# 
David I. Lehn's avatar
David I. Lehn committed
23
# Author: David I. Lehn <dlehn@users.sourceforge.net>
David I. Lehn's avatar
David I. Lehn committed
24
#
David I. Lehn's avatar
David I. Lehn committed
25

26 27
import sys

28
import pygst
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
29
pygst.require('0.10')
30

31
import gst
David I. Lehn's avatar
David I. Lehn committed
32

33
def handoff_cb(sender, *args):
David I. Lehn's avatar
David I. Lehn committed
34 35
   print sender.get_name(), args

36
def main(args):
David I. Lehn's avatar
David I. Lehn committed
37 38
   # create a new bin to hold the elements
   #gst_debug_set_categories(-1)
39 40
   bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 signal-handoffs=true ! ' +
                          'fakesink name=sink silent=1 signal-handoffs=true')
41 42
   source = bin.get_by_name('source')
   source.connect('handoff', handoff_cb)
43 44
   source.get_pad("src").connect("have-data", handoff_cb)
   sink = bin.get_by_name('sink')
45
   sink.connect('handoff', handoff_cb)
46 47 48 49 50
   sink.get_pad("sink").connect('have-data', handoff_cb)

   print source, sink

   bus = bin.get_bus()
51
   
52
   res = bin.set_state(gst.STATE_PLAYING);
David I. Lehn's avatar
David I. Lehn committed
53 54
   assert res

55 56 57 58
   while 1:
      msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)
      if msg:
         break
David I. Lehn's avatar
David I. Lehn committed
59

60
   res = bin.set_state(gst.STATE_NULL)
David I. Lehn's avatar
David I. Lehn committed
61 62 63
   assert res

if __name__ == '__main__':
64
   sys.exit(main(sys.argv))