Restart pipeline with Python on Error
jack
jack at rybn.org
Sun Jul 17 19:24:37 UTC 2022
Hello !
I would like to restart a very simple pipeline on error using Python.
I tried but I failed.
My pipeline :
pipeline = Gst.parse_launch('souphttpsrc name=toto location=
http://stream.p-node.org/billiejean.mp3 ! '
'decodebin ! '
'audioconvert ! '
'audioresample ! '
'autoaudiosink')
My fist attempt was :
bus.connect("sync-message::error", _on_sync_bus_message_error)
def _on_sync_bus_message_error(bus, message):
print(f'Error for stream', bus, message)
print('Restarting')
pipeline.set_state(Gst.State.NULL)
pipeline.set_state(Gst.State.PLAYING)
Then i get :
(python:903853): GStreamer-WARNING **: 21:07:57.021:
Trying to join task 0x166a290 from its thread would deadlock.
You cannot change the state of an element from its streaming
thread. Use g_idle_add() or post a GstMessage on the bus to
schedule the state change from the main thread.
OK, so let's go with "post a GstMessage on the bus to
schedule the state change from the main thread"
Here my second attempt :
bus.connect("sync-message::error", _on_sync_bus_message_error)
def _on_sync_bus_message_error(bus, message):
print(f'Error for stream', bus, message)
print('Restarting')
custom_structure = Gst.Structure.new_empty("iserror")
custom_message = Gst.Message.new_application(None,
custom_structure)
bus.post(custom_message) # here i post message on the bus...
Then I have a loop while to get message on the bus :
while True:
try:
message = bus.timed_pop(Gst.SECOND)
if message == None:
pass
elif message.type == Gst.MessageType.APPLICATION:
if message.get_structure().get_name() == "iserror":
print('There is an error...')
pipeline.set_state(Gst.State.NULL)
pipeline.set_state(Gst.State.PLAYING)
except KeyboardInterrupt:
break
I was expecting to have my pipeline to restart but unfortnutely it
didn't.
What is the next step to to restart my pipeline ?
Best!
++
Jack
More information about the gstreamer-devel
mailing list