Rtsp stream, EOS event. Need to restart pipeline

Hi.

I have rtsp stream from camera, and eventually after sometime pipeline get Eos message and stops. I need to handle this event and restart pipeline. What is the best approach for this? Can I reuse existing pipeline or it is better to create new one and reconnect?

Here is chunk of code I have:

 var bus = pipeline.Bus;
 bus.Message += HandleBusMessage;
...
 protected virtual void HandleBusMessage(object o, MessageArgs args)
        {
            // handle interested events
            switch (args.Message.Type)
            {
                case MessageType.Unknown:
                    break;
                case MessageType.Eos:
                   //do smth here 
                   break;
                case MessageType.Error:
                    break;
                case MessageType.Warning:
                    break;
                case MessageType.Info:
                    break;

                case MessageType.StateChanged:
                    break;

                case MessageType.StreamStatus:
                    break;
            }
        }

Thanks in advance.

Usually cycling the pipeline through READY or NULL state is the simplest approach to restart after EOS was emitted by the server.

In the GStreamer Rust plugins module there’s a fallbacksrc element which can restart a source input automatically if it goes down, in case that looks useful for your use case.

1 Like

And it restart sources on EOS?

I see, please note this behaviour is under a property:

https://gstreamer.freedesktop.org/documentation/fallbackswitch/fallbacksrc.html?gi-language=c#fallbacksrc:restart-on-eos

Thank you for reply! But what should I do in case I got error msg? It seems that trying to restart:

  RtspPipeline.SetState(State.Null);
  RtspPipeline.SetState(State.Ready);
  RtspPipeline.SetState(State.Playing);

is useless, it simply looping in error state. Should I completely recreate pipeline from scratch or there is chance to save current pipeline?

Its depends what the error is. And you may want to pace the retries too.

Thank you.

Its depends what the error is. And you may want to pace the retries too.

How can I get error type, is it possible?

You may want to read the error message documentation:

https://gstreamer.freedesktop.org/documentation/gstreamer/gstmessage.html?gi-language=c

1 Like