34 gobject.threads_init()
72 A simple handler that prints pipeline error messages to stderr, and
73 stops the pipeline and terminates the mainloop at EOS. Complex
74 applications will need to write their own pipeline handler, but for
75 most simple applications this will suffice, and it's easier than
76 copy-and-pasting this all over the place.
78 def __init__(self, mainloop, pipeline):
82 bus = pipeline.get_bus()
83 bus.add_signal_watch()
86 def excepthook(*args):
96 sys.__excepthook__(*args)
99 sys.excepthook = excepthook
104 Decouple this object from the Bus object to allow the Bus'
105 reference count to drop to 0, and .quit() the mainloop
106 object. This method is invoked by the default EOS and
107 ERROR message handlers.
111 bus.remove_signal_watch()
116 Add extra message handling by overriding this in your
117 subclass. If this method returns True, no further message
118 handling is performed. If this method returns False,
119 message handling continues with default cases or EOS, INFO,
120 WARNING and ERROR messages.
124 def on_message(self, bus, message):
127 elif message.type == gst.MESSAGE_EOS:
128 self.pipeline.set_state(gst.STATE_NULL)
130 elif message.type == gst.MESSAGE_INFO:
131 gerr, dbgmsg = message.parse_info()
132 print >>sys.stderr,
"info (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg)
133 elif message.type == gst.MESSAGE_WARNING:
134 gerr, dbgmsg = message.parse_warning()
135 print >>sys.stderr,
"warning (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg)
136 elif message.type == gst.MESSAGE_ERROR:
137 gerr, dbgmsg = message.parse_error()
141 sys.exit(
"error (%s:%d '%s'): %s" % (gerr.domain, gerr.code, gerr.message, dbgmsg))
146 A helper class for application signal handling. Use this to help your
147 application to cleanly shutdown gstreamer pipelines when responding to e.g.,
150 def __init__(self, pipeline, signals = [signal.SIGINT, signal.SIGTERM]):
154 signal.signal(sig, self)
158 Over ride this for your subclass
162 def __call__(self, signum, frame):
165 print >>sys.stderr,
"*** SIG %d attempting graceful shutdown (this might take several minutes) ... ***" % signum
167 self.do_on_call(signum, frame)
168 if not self.pipeline.send_event(gst.event_new_eos()):
169 raise Exception(
"pipeline.send_event(EOS) returned failure")
171 print >>sys.stderr,
"graceful shutdown failed: %s\naborting." % str(e)
174 print >>sys.stderr,
"*** received SIG %d %d times... ***" % (signum, self.count)