2002-10-03 22:11:37 +00:00
|
|
|
#!/usr/bin/env python
|
2002-03-27 11:14:04 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
#
|
2002-12-17 17:40:42 +00:00
|
|
|
# Author: David I. Lehn <dlehn@users.sourceforge.net>
|
2002-03-27 11:14:04 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2004-02-24 18:40:21 +00:00
|
|
|
import gst
|
2002-03-27 11:14:04 +00:00
|
|
|
import time
|
|
|
|
from identity import Identity
|
|
|
|
|
|
|
|
def update(sender, *args):
|
2003-10-10 03:48:18 +00:00
|
|
|
print sender.get_name(), args
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
def build(filters, b):
|
2003-10-10 03:48:18 +00:00
|
|
|
# create a new bin to hold the elements
|
2004-02-24 18:40:21 +00:00
|
|
|
bin = gst.Pipeline('pipeline')
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
src = gst.Element('fakesrc', 'source');
|
2003-10-10 03:48:18 +00:00
|
|
|
src.set_property('silent', 1)
|
|
|
|
src.set_property('num_buffers', b)
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
sink = gst.Element('fakesink', 'sink')
|
2003-10-10 03:48:18 +00:00
|
|
|
sink.set_property('silent', 1)
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2003-10-10 03:48:18 +00:00
|
|
|
elements = [src] + filters + [sink]
|
2004-02-24 18:40:21 +00:00
|
|
|
bin.add_many(*elements)
|
|
|
|
gst.element_link_many(*elements)
|
2003-10-10 03:48:18 +00:00
|
|
|
return bin
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
def filter(bin):
|
2004-02-24 18:40:21 +00:00
|
|
|
bin.set_state(gst.STATE_PLAYING);
|
|
|
|
while bin.iterate():
|
|
|
|
pass
|
|
|
|
bin.set_state(gst.STATE_NULL)
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
ccnt = 0
|
|
|
|
def c():
|
2003-10-10 03:48:18 +00:00
|
|
|
global ccnt
|
2004-02-24 18:40:21 +00:00
|
|
|
id = gst.Element('identity', 'c identity %d' % ccnt);
|
2003-10-10 03:48:18 +00:00
|
|
|
id.set_property('silent', 1)
|
|
|
|
id.set_property('loop_based', 0)
|
|
|
|
ccnt += 1
|
|
|
|
return id
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
pcnt = 0
|
|
|
|
def py():
|
2003-10-10 03:48:18 +00:00
|
|
|
id = Identity()
|
|
|
|
assert id
|
|
|
|
global pcnt
|
|
|
|
id.set_name('py identity %d' % pcnt)
|
|
|
|
pcnt += 1
|
|
|
|
return id
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
def check(f, n, b):
|
2003-10-10 03:48:18 +00:00
|
|
|
fs = []
|
|
|
|
for i in range(n):
|
|
|
|
fs.append(f())
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2003-10-10 03:48:18 +00:00
|
|
|
pipe = build(fs, b)
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2003-10-10 03:48:18 +00:00
|
|
|
start = time.time()
|
|
|
|
ret = filter(pipe)
|
|
|
|
end = time.time()
|
|
|
|
print '%s b:%d i:%d t:%f' % (f, b, n, end - start)
|
|
|
|
return ret
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
def main(args):
|
2003-10-10 03:48:18 +00:00
|
|
|
"Identity timer and latency check"
|
2002-03-27 11:14:04 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
if len(args) < 3:
|
|
|
|
print 'usage: %s identites buffers' % args[0]
|
2003-10-10 03:48:18 +00:00
|
|
|
return -1
|
2004-02-24 18:40:21 +00:00
|
|
|
n = int(args[1])
|
|
|
|
b = int(args[2])
|
|
|
|
|
2003-10-10 03:48:18 +00:00
|
|
|
for f in (c, py):
|
|
|
|
check(f, n, b)
|
2002-03-27 11:14:04 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2004-02-24 18:40:21 +00:00
|
|
|
sys.exit(main(sys.argv))
|