examples/: Updated some examples to 0.9
Original commit message from CVS: * examples/bps.py: * examples/f2f.py: * examples/gstfile.py: Updated some examples to 0.9
This commit is contained in:
parent
ce4e6304a2
commit
2488b32b07
@ -1,3 +1,10 @@
|
|||||||
|
2005-07-13 Edward Hervey <edward@fluendo.com>
|
||||||
|
|
||||||
|
* examples/bps.py:
|
||||||
|
* examples/f2f.py:
|
||||||
|
* examples/gstfile.py:
|
||||||
|
Updated some examples to 0.9
|
||||||
|
|
||||||
2005-07-13 Andy Wingo <wingo@pobox.com>
|
2005-07-13 Andy Wingo <wingo@pobox.com>
|
||||||
|
|
||||||
* examples/vumeter.py: New file, a VU meter application that reads
|
* examples/vumeter.py: New file, a VU meter application that reads
|
||||||
|
@ -28,6 +28,10 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
|
|
||||||
|
import pygst
|
||||||
|
pygst.require('0.9')
|
||||||
|
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
class BPS(object):
|
class BPS(object):
|
||||||
@ -42,11 +46,6 @@ class BPS(object):
|
|||||||
spb = dt/self.buffers
|
spb = dt/self.buffers
|
||||||
print '\t%d buffers / %fs\t= %f bps\t= %f spb' % (self.buffers, dt, bps, spb)
|
print '\t%d buffers / %fs\t= %f bps\t= %f spb' % (self.buffers, dt, bps, spb)
|
||||||
|
|
||||||
def eos(self, sink):
|
|
||||||
self.done()
|
|
||||||
if self.method in ('gtk', 'c'):
|
|
||||||
gst.main_quit()
|
|
||||||
|
|
||||||
def fakesrc(self, buffers):
|
def fakesrc(self, buffers):
|
||||||
src = gst.element_factory_make('fakesrc','src')
|
src = gst.element_factory_make('fakesrc','src')
|
||||||
src.set_property('silent', 1)
|
src.set_property('silent', 1)
|
||||||
@ -65,78 +64,55 @@ class BPS(object):
|
|||||||
pipeline.add(src)
|
pipeline.add(src)
|
||||||
sink = self.fakesink()
|
sink = self.fakesink()
|
||||||
pipeline.add(sink)
|
pipeline.add(sink)
|
||||||
sink.connect('eos', self.eos)
|
|
||||||
src.link(sink)
|
src.link(sink)
|
||||||
|
|
||||||
return pipeline
|
return pipeline
|
||||||
|
|
||||||
def notify(self, sender, obj, arg):
|
|
||||||
prop = obj.get_property(arg.name)
|
|
||||||
print 'notify', sender, arg.name, prop
|
|
||||||
print prop
|
|
||||||
|
|
||||||
def idle(self, pipeline):
|
def idle(self, pipeline):
|
||||||
return pipeline.iterate()
|
return pipeline.iterate()
|
||||||
|
|
||||||
def test(self, method):
|
def test(self):
|
||||||
print '%s:' % (method,),
|
self.bus = self.pipeline.get_bus()
|
||||||
self.method = method
|
|
||||||
|
|
||||||
print self.pipeline.get_state()
|
|
||||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
|
||||||
print self.pipeline.get_state()
|
|
||||||
|
|
||||||
if method == 'py':
|
self.start = time.time()
|
||||||
self.start = time.time()
|
|
||||||
while self.pipeline.iterate():
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||||
pass
|
|
||||||
elif method == 'c':
|
while 1:
|
||||||
self.start = time.time()
|
msg = self.bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)
|
||||||
gobject.idle_add(self.pipeline.iterate)
|
if msg:
|
||||||
gst.main()
|
break
|
||||||
#elif method == 'gst':
|
|
||||||
# self.start = time.time()
|
|
||||||
# gtk.idle_add(self.idle, self.pipeline)
|
|
||||||
# gtk.main()
|
|
||||||
|
|
||||||
self.pipeline.set_state(gst.STATE_NULL)
|
self.pipeline.set_state(gst.STATE_NULL)
|
||||||
|
self.done()
|
||||||
|
|
||||||
def run(self, buffers, methods):
|
def run(self, buffers):
|
||||||
self.buffers = buffers
|
self.buffers = buffers
|
||||||
|
|
||||||
print '# Testing buffer processing rate for "fakesrc ! fakesink"'
|
print '# Testing buffer processing rate for "fakesrc ! fakesink"'
|
||||||
#print '# gst = gtk idle loop function in python'
|
|
||||||
print '# c = gtk idle loop function in C'
|
|
||||||
print '# py = full iterate loop in python'
|
|
||||||
print '# all = full iterate loop in C'
|
|
||||||
print '# bps = buffers per second'
|
print '# bps = buffers per second'
|
||||||
print '# spb = seconds per buffer'
|
print '# spb = seconds per buffer'
|
||||||
|
|
||||||
self.pipeline = self.build_pipeline(buffers)
|
self.pipeline = self.build_pipeline(buffers)
|
||||||
assert self.pipeline
|
assert self.pipeline
|
||||||
#self.pipeline.connect('deep-notify', self.notify)
|
|
||||||
|
self.test()
|
||||||
map(self.test, methods)
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
"GStreamer Buffers-Per-Second tester"
|
"GStreamer Buffers-Per-Second tester"
|
||||||
|
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
print 'usage: %s buffers [method method ...]' % args[0]
|
print 'usage: %s buffers' % args[0]
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
bps = BPS()
|
bps = BPS()
|
||||||
|
|
||||||
buffers = int(args[1])
|
buffers = int(args[1])
|
||||||
if buffers < 0:
|
if buffers < 1:
|
||||||
print 'buffers must be higher than 0'
|
print 'buffers must be higher than 0'
|
||||||
return
|
return
|
||||||
|
|
||||||
methods = args[2:]
|
bps.run(buffers)
|
||||||
if not methods:
|
|
||||||
methods = ('gtk', 'c', 'py', 'all')
|
|
||||||
|
|
||||||
bps.run(buffers, methods)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv))
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import pygst
|
||||||
|
pygst.require('0.9')
|
||||||
|
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
def handoff_cb(sender, *args):
|
def handoff_cb(sender, *args):
|
||||||
@ -31,18 +34,26 @@ def handoff_cb(sender, *args):
|
|||||||
def main(args):
|
def main(args):
|
||||||
# create a new bin to hold the elements
|
# create a new bin to hold the elements
|
||||||
#gst_debug_set_categories(-1)
|
#gst_debug_set_categories(-1)
|
||||||
bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 ! ' +
|
bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 signal-handoffs=true ! ' +
|
||||||
'fakesink name=sink silent=1')
|
'fakesink name=sink silent=1 signal-handoffs=true')
|
||||||
source = bin.get_by_name('source')
|
source = bin.get_by_name('source')
|
||||||
source.connect('handoff', handoff_cb)
|
source.connect('handoff', handoff_cb)
|
||||||
sink = bin.get_by_name('source')
|
source.get_pad("src").connect("have-data", handoff_cb)
|
||||||
|
sink = bin.get_by_name('sink')
|
||||||
sink.connect('handoff', handoff_cb)
|
sink.connect('handoff', handoff_cb)
|
||||||
|
sink.get_pad("sink").connect('have-data', handoff_cb)
|
||||||
|
|
||||||
|
print source, sink
|
||||||
|
|
||||||
|
bus = bin.get_bus()
|
||||||
|
|
||||||
res = bin.set_state(gst.STATE_PLAYING);
|
res = bin.set_state(gst.STATE_PLAYING);
|
||||||
assert res
|
assert res
|
||||||
|
|
||||||
while bin.iterate():
|
while 1:
|
||||||
pass
|
msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)
|
||||||
|
if msg:
|
||||||
|
break
|
||||||
|
|
||||||
res = bin.set_state(gst.STATE_NULL)
|
res = bin.set_state(gst.STATE_NULL)
|
||||||
assert res
|
assert res
|
||||||
|
@ -13,6 +13,10 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
|
import pygst
|
||||||
|
pygst.require('0.9')
|
||||||
|
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
def time_to_string(value):
|
def time_to_string(value):
|
||||||
@ -104,7 +108,7 @@ class Discoverer(gst.Pipeline):
|
|||||||
self.typefind.connect("have-type", self._have_type_cb)
|
self.typefind.connect("have-type", self._have_type_cb)
|
||||||
self.dbin.connect("new-decoded-pad", self._new_decoded_pad_cb)
|
self.dbin.connect("new-decoded-pad", self._new_decoded_pad_cb)
|
||||||
self.dbin.connect("unknown-type", self._unknown_type_cb)
|
self.dbin.connect("unknown-type", self._unknown_type_cb)
|
||||||
self.dbin.connect("found-tag", self._found_tag_cb)
|
#self.dbin.connect("found-tag", self._found_tag_cb)
|
||||||
|
|
||||||
self.discover()
|
self.discover()
|
||||||
|
|
||||||
@ -112,11 +116,41 @@ class Discoverer(gst.Pipeline):
|
|||||||
"""iterate on ourself to find the information on the given file"""
|
"""iterate on ourself to find the information on the given file"""
|
||||||
if self.finished:
|
if self.finished:
|
||||||
return
|
return
|
||||||
self.set_state(gst.STATE_PLAYING)
|
if not self.set_state(gst.STATE_PLAYING):
|
||||||
|
# the pipeline wasn't able to be set to playing
|
||||||
|
self.finished = True
|
||||||
|
return
|
||||||
|
bus = self.get_bus()
|
||||||
while 1:
|
while 1:
|
||||||
if not self.iterate():
|
if self.finished:
|
||||||
|
#print "self.finished, stopping"
|
||||||
break
|
break
|
||||||
self.set_state(gst.STATE_NULL)
|
msg = bus.poll(gst.MESSAGE_ANY, gst.SECOND)
|
||||||
|
if msg:
|
||||||
|
msg = bus.pop()
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
if msg.type & gst.MESSAGE_STATE_CHANGED:
|
||||||
|
#print "state changed", msg.src.get_name()
|
||||||
|
#print msg.parse_state_changed()
|
||||||
|
pass
|
||||||
|
elif msg.type & gst.MESSAGE_EOS:
|
||||||
|
break
|
||||||
|
elif msg.type & gst.MESSAGE_TAG:
|
||||||
|
for key in msg.parse_tag().keys():
|
||||||
|
self.tags[key] = msg.structure[key]
|
||||||
|
print msg.structure.to_string()
|
||||||
|
elif msg.type & gst.MESSAGE_ERROR:
|
||||||
|
print "whooops, error"
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print "unknown message type"
|
||||||
|
|
||||||
|
print "going to PAUSED"
|
||||||
|
#self.set_state(gst.STATE_PAUSED)
|
||||||
|
print "going to ready"
|
||||||
|
#self.set_state(gst.STATE_READY)
|
||||||
|
print "now in ready"
|
||||||
self.finished = True
|
self.finished = True
|
||||||
|
|
||||||
def print_info(self):
|
def print_info(self):
|
||||||
@ -159,18 +193,34 @@ class Discoverer(gst.Pipeline):
|
|||||||
print "%20s :\t" % tag, self.tags[tag]
|
print "%20s :\t" % tag, self.tags[tag]
|
||||||
|
|
||||||
def _unknown_type_cb(self, dbin, pad, caps):
|
def _unknown_type_cb(self, dbin, pad, caps):
|
||||||
|
print "unknown type", caps.to_string()
|
||||||
|
# if we get an unknown type and we don't already have an
|
||||||
|
# audio or video pad, we are finished !
|
||||||
self.otherstreams.append(caps.to_string())
|
self.otherstreams.append(caps.to_string())
|
||||||
|
if not self.is_video and not self.is_audio:
|
||||||
|
self.finished = True
|
||||||
|
|
||||||
def _have_type_cb(self, typefind, prob, caps):
|
def _have_type_cb(self, typefind, prob, caps):
|
||||||
self.mimetype = caps.to_string()
|
self.mimetype = caps.to_string()
|
||||||
|
|
||||||
def _notify_caps_cb(self, pad, args):
|
def _notify_caps_cb(self, pad, args):
|
||||||
caps = pad.get_negotiated_caps()
|
caps = pad.get_negotiated_caps()
|
||||||
|
print "caps notify on", pad, ":", caps
|
||||||
if not caps:
|
if not caps:
|
||||||
return
|
return
|
||||||
# the caps are fixed
|
# the caps are fixed
|
||||||
# We now get the total length of that stream
|
# We now get the total length of that stream
|
||||||
length = pad.get_peer().query(gst.QUERY_TOTAL, gst.FORMAT_TIME)
|
q = gst.query_new_position(gst.FORMAT_TIME)
|
||||||
|
#print "query refcount", q.__grefcount__
|
||||||
|
if pad.get_peer().query(q):
|
||||||
|
#print "query refcount", q.__grefcount__
|
||||||
|
length = q.structure["end"]
|
||||||
|
pos = q.structure["cur"]
|
||||||
|
format = q.structure["format"]
|
||||||
|
#print "got length", time_to_string(pos), time_to_string(length), format
|
||||||
|
else:
|
||||||
|
print "query didn't work"
|
||||||
|
#length = pad.get_peer().query(gst.QUERY_TOTAL, gst.FORMAT_TIME)
|
||||||
# We store the caps and length in the proper location
|
# We store the caps and length in the proper location
|
||||||
if "audio" in caps.to_string():
|
if "audio" in caps.to_string():
|
||||||
self.audiocaps = caps
|
self.audiocaps = caps
|
||||||
@ -195,10 +245,23 @@ class Discoverer(gst.Pipeline):
|
|||||||
|
|
||||||
def _new_decoded_pad_cb(self, dbin, pad, is_last):
|
def _new_decoded_pad_cb(self, dbin, pad, is_last):
|
||||||
# Does the file contain got audio or video ?
|
# Does the file contain got audio or video ?
|
||||||
if "audio" in pad.get_caps().to_string():
|
caps = pad.get_caps()
|
||||||
|
print "new decoded pad", caps.to_string()
|
||||||
|
if "audio" in caps.to_string():
|
||||||
self.is_audio = True
|
self.is_audio = True
|
||||||
elif "video" in pad.get_caps().to_string():
|
if caps.is_fixed():
|
||||||
|
print "have negotiated caps", caps
|
||||||
|
self.audiocaps = caps
|
||||||
|
return
|
||||||
|
elif "video" in caps.to_string():
|
||||||
self.is_video = True
|
self.is_video = True
|
||||||
|
if caps.is_fixed():
|
||||||
|
print "have negotiated caps", caps
|
||||||
|
self.videocaps = caps
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print "got a different caps..", caps
|
||||||
|
return
|
||||||
if is_last and not self.is_video and not self.is_audio:
|
if is_last and not self.is_video and not self.is_audio:
|
||||||
self.finished = True
|
self.finished = True
|
||||||
return
|
return
|
||||||
@ -208,20 +271,13 @@ class Discoverer(gst.Pipeline):
|
|||||||
sinkpad = fakesink.get_pad("sink")
|
sinkpad = fakesink.get_pad("sink")
|
||||||
# ... and connect a callback for when the caps are fixed
|
# ... and connect a callback for when the caps are fixed
|
||||||
sinkpad.connect("notify::caps", self._notify_caps_cb)
|
sinkpad.connect("notify::caps", self._notify_caps_cb)
|
||||||
pad.link(sinkpad)
|
if pad.link(sinkpad):
|
||||||
fakesink.set_state(gst.STATE_PLAYING)
|
print "##### Couldn't link pad to fakesink"
|
||||||
|
#fakesink.set_state(gst.STATE_PLAYING)
|
||||||
|
|
||||||
def _found_tag_cb(self, dbin, source, tags):
|
def _found_tag_cb(self, dbin, source, tags):
|
||||||
self.tags.update(tags)
|
self.tags.update(tags)
|
||||||
|
|
||||||
def do_iterate(self):
|
|
||||||
# this overrides the GstBin 'iterate' method
|
|
||||||
# if we have finished discovering we stop the iteration
|
|
||||||
if self.finished:
|
|
||||||
return False
|
|
||||||
# else we call the parent class method
|
|
||||||
return gst.Pipeline.do_iterate(self)
|
|
||||||
|
|
||||||
gobject.type_register(Discoverer)
|
gobject.type_register(Discoverer)
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user