Restart pipeline with Python on Error
jack
jack at rybn.org
Mon Jul 18 19:57:31 UTC 2022
I forgot, my configuration :
Ubuntu 20.04
GStreamer 1.16.2
I expected using pipeline.set_state(Gst.State.NULL) followed
by pipeline.set_state(Gst.State.PLAYING) will be enough to restart my
pipeline. But I am wrong.
If someone can explain what to do it would be very much appreciated !
A link would be nice. I can't find an example on the web about this
subject (for Python).
Best!
++
Jack
Le dimanche 17 juillet 2022 à 21:24 +0200, jack via gstreamer-devel a
écrit :
> 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