pythonstateelementgstreamerbus

Gstreamer how to get element information from STATE_CHANGED message from the bus


I am working with Gstreamer and its Python bindings. Consider the following bus_call function:

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

When the message type is Gst.MessageType.STATE_CHANGED, how can I retrieve the element that has changed the state?


Solution

  • Not sure I correctly understand, but you may try something like:

    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))