def message_rcvd(bus, message, pipeline, resolution): t = message.type if t == gst.MESSAGE_STATE_CHANGED: if message.src == pipeline: old, new, pending = message.parse_state_changed() if new == gst.STATE_PLAYING: run_check(pipeline, resolution) elif t == gst.MESSAGE_ERROR: gerror, debug = message.parse_error() # set pipeline state to NULL so worker does not consume # unnecessary resources pipeline.set_state(gst.STATE_NULL) resolution.errback( errors.GStreamerGstError(message.src, gerror, debug)) elif t == gst.MESSAGE_EOS: resolution.errback( errors.GStreamerError("Unexpected end of stream")) else: log.debug( 'check', 'message: %s: %s:' % (message.src.get_path_string(), message.type.value_nicks[1])) if message.structure: log.debug('check', 'message: %s' % message.structure.to_string()) else: log.debug('check', 'message: (no structure)') return True
def do_check(demux): pad = demux.get_pad('video') if not pad or pad.get_negotiated_caps() == None: raise errors.GStreamerError('Pipeline failed to negotiate?') caps = pad.get_negotiated_caps() s = caps.get_structure(0) w = s['width'] h = s['height'] par = s['pixel-aspect-ratio'] # FIXME: not a good idea to reuse the result name which # also exists in the parent context. # pychecker should warn; however it looks like # the parent result doesn't get stored as name, # but instead with STORE_DEREF result = dict(width=w, height=h, par=(par.num, par.denom)) log.debug('check', 'returning dict %r' % result) return result
(message.src.get_path_string(), message.type.value_nicks[1])) if message.structure: log.debug('check', 'message: %s' % message.structure.to_string()) else: log.debug('check', 'message: (no structure)') return True resolution = BusResolution() log.debug('check', 'parsing pipeline %s' % pipeline_str) try: pipeline = gst.parse_launch(pipeline_str) log.debug('check', 'parsed pipeline %s' % pipeline_str) except gobject.GError, e: resolution.errback(errors.GStreamerError(e.message)) return resolution.d bus = pipeline.get_bus() bus.add_signal_watch() signal_id = bus.connect('message', message_rcvd, pipeline, resolution) resolution.signal_id = signal_id resolution.pipeline = pipeline log.debug('check', 'setting state to playing') if set_state_deferred: d = deferToThread(pipeline.set_state, gst.STATE_PLAYING) def stateChanged(res): return resolution.d