Gstreamer如何从总线的STATE_CHANGED消息中获取元素信息
Gstreamer how to get element information from STATE_CHANGED message from the bus
我正在使用 Gstreamer 及其 Python 绑定。考虑以下 bus_call
函数:
import sys
from gi.repository import Gst
def bus_call(bus, message, loop):
t = message.type
if t == Gst.MessageType.EOS:
print("Bus call: End-of-stream\n")
# loop.quit()
elif t == Gst.MessageType.WARNING:
err, debug = message.parse_warning()
sys.stderr.write("Bus call: Warning: %s: %s\n" % (err, debug))
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
sys.stderr.write("Bus call: Error: %s: %s\n" % (err, debug))
# loop.quit()
elif t == Gst.MessageType.BUFFERING:
print("Bus call: Buffering\n")
elif t == Gst.MessageType.STATE_CHANGED:
old_state, new_state, pending_state = message.parse_state_changed()
print((
f"Bus call: Pipeline state changed from {old_state.value_nick} to {new_state.value_nick} "
f"(pending {pending_state.value_nick})"
))
else:
print(f"Bus call: {message}\n")
return True
当消息类型为Gst.MessageType.STATE_CHANGED
时,如何获取状态改变的元素?
不确定我是否理解正确,但您可以尝试类似的操作:
old_state, new_state, pending_state = message.parse_state_changed()
print('%s : State changed from %s to %s' % (message.src.get_name(), old_state, new_state))
我正在使用 Gstreamer 及其 Python 绑定。考虑以下 bus_call
函数:
import sys
from gi.repository import Gst
def bus_call(bus, message, loop):
t = message.type
if t == Gst.MessageType.EOS:
print("Bus call: End-of-stream\n")
# loop.quit()
elif t == Gst.MessageType.WARNING:
err, debug = message.parse_warning()
sys.stderr.write("Bus call: Warning: %s: %s\n" % (err, debug))
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
sys.stderr.write("Bus call: Error: %s: %s\n" % (err, debug))
# loop.quit()
elif t == Gst.MessageType.BUFFERING:
print("Bus call: Buffering\n")
elif t == Gst.MessageType.STATE_CHANGED:
old_state, new_state, pending_state = message.parse_state_changed()
print((
f"Bus call: Pipeline state changed from {old_state.value_nick} to {new_state.value_nick} "
f"(pending {pending_state.value_nick})"
))
else:
print(f"Bus call: {message}\n")
return True
当消息类型为Gst.MessageType.STATE_CHANGED
时,如何获取状态改变的元素?
不确定我是否理解正确,但您可以尝试类似的操作:
old_state, new_state, pending_state = message.parse_state_changed()
print('%s : State changed from %s to %s' % (message.src.get_name(), old_state, new_state))