Restart pipeline with Python on Error

Marianna Smidth Buschle msb at qtec.com
Tue Aug 9 13:25:28 UTC 2022


You didn't really specify what goes wrong in the second attempt, you get 
some error message?

But I expect that one of the problems will be that you have a lot of 
elements which are dynamically linked (like decodebin) and that is done 
automatically by the parse_launch.
However, if I recall correctly that only happens the first time the 
pipeline is played.
If you want it to be done every time you need to use ':' instead of '!'

Use |:| instead of |!| when building pipelines in order to make 
|gst_parse_launch()| keep the |pad-added| listeners forever.
So that it auto re-links elements like |tsdemux| and |decodebin| when 
going from PLAYING->NULL->PLAYING

|"multifilesrc name=replay location=/home/msb/test.ts ! decodebin : 
identity sync=true ! videoconvert ! ximagesink sync=0"|


Best Regards
Marianna

On 19.07.2022 14.00, gstreamer-devel-request at lists.freedesktop.org wrote:
> Message: 1
> Date: Mon, 18 Jul 2022 21:57:31 +0200
> From: jack<jack at rybn.org>
> To: Discussion of the development of and with GStreamer
> 	<gstreamer-devel at lists.freedesktop.org>
> Subject: Re: Restart pipeline with Python on Error
> Message-ID:<5cb9929faa48bf00dbb1740947dd8094a7570f15.camel at rybn.org>
> Content-Type: text/plain; charset="UTF-8"
>
> 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
>>
>>
>>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>
> ------------------------------
>
> End of gstreamer-devel Digest, Vol 138, Issue 26
> ************************************************

-- 
Best regards / Med venlig hilsen
“Marianna Smidth Buschle”
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220809/5d9347ce/attachment.htm>


More information about the gstreamer-devel mailing list