32 gi.require_version(
'Gst',
'1.0')
33 from gi.repository
import Gst
41 +-------------------------------------------------+------------------------------------------+------------+ 42 | Names | Hash | Date | 43 +=================================================+==========================================+============+ 44 | Florent, Sathya, Duncan Me., Jolien, Kipp, Chad | b3ef077fe87b597578000f140e4aa780f3a227aa | 2014-05-01 | 45 +-------------------------------------------------+------------------------------------------+------------+ 61 A simple handler that prints pipeline error messages to stderr, and 62 stops the pipeline and terminates the mainloop at EOS. Complex 63 applications will need to write their own pipeline handler, but for 64 most simple applications this will suffice, and it's easier than 65 copy-and-pasting this all over the place. 67 def __init__(self, mainloop, pipeline):
71 bus = pipeline.get_bus()
72 bus.add_signal_watch()
75 def excepthook(*args):
85 sys.__excepthook__(*args)
88 sys.excepthook = excepthook
93 Decouple this object from the Bus object to allow the Bus' 94 reference count to drop to 0, and .quit() the mainloop 95 object. This method is invoked by the default EOS and 96 ERROR message handlers. 100 bus.remove_signal_watch()
105 Add extra message handling by overriding this in your 106 subclass. If this method returns True, no further message 107 handling is performed. If this method returns False, 108 message handling continues with default cases or EOS, INFO, 109 WARNING and ERROR messages. 113 def on_message(self, bus, message):
116 elif message.type == Gst.MessageType.EOS:
117 self.
pipeline.set_state(Gst.State.NULL)
119 elif message.type == Gst.MessageType.INFO:
120 gerr, dbgmsg = message.parse_info()
121 print >>sys.stderr,
"info (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg)
122 elif message.type == Gst.MessageType.WARNING:
123 gerr, dbgmsg = message.parse_warning()
124 print >>sys.stderr,
"warning (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg)
125 elif message.type == Gst.MessageType.ERROR:
126 gerr, dbgmsg = message.parse_error()
130 sys.exit(
"error (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg))
135 A helper class for application signal handling. Use this to help your 136 application to cleanly shutdown gstreamer pipelines when responding to e.g., 139 def __init__(self, pipeline, signals = [signal.SIGINT, signal.SIGTERM]):
143 signal.signal(sig, self)
147 Over ride this for your subclass 151 def __call__(self, signum, frame):
154 print >>sys.stderr,
"*** SIG %d attempting graceful shutdown (this might take several minutes) ... ***" % signum
156 self.do_on_call(signum, frame)
157 if not self.pipeline.send_event(Gst.Event.new_eos()):
158 raise Exception(
"pipeline.send_event(EOS) returned failure")
160 print >>sys.stderr,
"graceful shutdown failed: %s\naborting." % str(e)
163 print >>sys.stderr,
"*** received SIG %d %d times... ***" % (signum, self.count)
def do_on_call(self, signum, frame)
def do_on_message(self, bus, message)
def on_message(self, bus, message)