<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>You didn't really specify what goes wrong in the second attempt,
      you get some error message?</p>
    <p>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.<br>
      However, if I recall correctly that only happens the first time
      the pipeline is played.<br>
      If you want it to be done every time you need to use ':' instead
      of '!'<br>
    </p>
    <p data-sourcepos="20:1-21:103" dir="auto">Use <code>:</code>
      instead of <code>!</code> when building pipelines in order to
      make <code>gst_parse_launch()</code> keep the <code>pad-added</code>
      listeners forever.<br>
      So that it auto re-links elements like <code>tsdemux</code> and <code>decodebin</code>
      when going from PLAYING->NULL->PLAYING</p>
    <div class="gl-relative markdown-code-block js-markdown-code">
      <pre data-sourcepos="23:1-25:3" class="code highlight js-syntax-highlight language-plaintext monokai" data-canonical-lang="" id="code-1" lang="plaintext"><code><span id="LC1" class="line" lang="plaintext">"multifilesrc name=replay location=/home/msb/test.ts ! decodebin : identity sync=true ! videoconvert ! ximagesink sync=0"</span></code></pre>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Best Regards</div>
    <div class="moz-cite-prefix">Marianna</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">On 19.07.2022 14.00,
      <a class="moz-txt-link-abbreviated" href="mailto:gstreamer-devel-request@lists.freedesktop.org">gstreamer-devel-request@lists.freedesktop.org</a> wrote:
    </div>
    <blockquote type="cite"
cite="mid:mailman.47.1658232004.32144.gstreamer-devel@lists.freedesktop.org">
      <pre class="moz-quote-pre" wrap="">Message: 1
Date: Mon, 18 Jul 2022 21:57:31 +0200
From: jack <a class="moz-txt-link-rfc2396E" href="mailto:jack@rybn.org"><jack@rybn.org></a>
To: Discussion of the development of and with GStreamer
        <a class="moz-txt-link-rfc2396E" href="mailto:gstreamer-devel@lists.freedesktop.org"><gstreamer-devel@lists.freedesktop.org></a>
Subject: Re: Restart pipeline with Python on Error
Message-ID: <a class="moz-txt-link-rfc2396E" href="mailto:5cb9929faa48bf00dbb1740947dd8094a7570f15.camel@rybn.org"><5cb9929faa48bf00dbb1740947dd8094a7570f15.camel@rybn.org></a>
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 :
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">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=
<a class="moz-txt-link-freetext" href="http://stream.p-node.org/billiejean.mp3">http://stream.p-node.org/billiejean.mp3</a> ! '
                            '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



</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">


------------------------------

Subject: Digest Footer

_______________________________________________
gstreamer-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a>


------------------------------

End of gstreamer-devel Digest, Vol 138, Issue 26
************************************************
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Best regards / Med venlig hilsen
“Marianna Smidth Buschle”</pre>
  </body>
</html>