title: Restarting GStreamer Pipeline in Python on EOS
body: <p>I am working on a Python script running on RPi3, and using gstreamer to connect to RTSP feed of my IP Camera, and serve decoded H264 frames to my Python script.</p>
  
  <p>Here is the gstreamear pipeline used to get frames from camera:</p>
  
  <pre><code>rtspsrc location=rtsp://ip:port/path ! rtph264depay ! h264parse ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink name=sink
  </code></pre>
  
  <p><strong>Problem:</strong> Since the camera is on a slow/unreliable internet connection, I get dropped frames every now and then, which causes an EOS signal to be generated. The internet connection bandwidth can be a problem sometimes causing a hick up with the stream.</p>
  
  <p><strong>Goal</strong>: On EOS signal, I would like to restart the pipeline so gstreamer can keep serving frames to my program.</p>
  
  <p><strong>What I have tried:</strong> I have a callback function attached to the bus that listens for messages by using </p>
  
  <pre><code>bus.connect("message", on_message)
  </code></pre>
  
  <p>Inside the "on_message" function, I am able to successfully determine if the message is an EOS signal. If I detect an EOS signal, I try to restart the pipeline by doing:</p>
  
  <pre><code>pipline.set_state(Gst.State.NULL)
  pipline.set_state(Gst.State.PAUSED)
  pipline.set_state(Gst.State.PLAYING)
  </code></pre>
  
  <p>Unfortunately this does not work. Once my scipt attemps to restart the pipeline using the snippet above, I get the following errors appearing on the bus. And I know the camera is online so that's not the problem.</p>
  
  <pre><code>('ERROR!!!:', 'source', '!:!', 'Could not read from resource.')
  ('Debug info:', 'gstrtspsrc.c(5583): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstRTSPSrc:source:\nGot error response: 400 (Bad Request).')
  ('ERROR!!!:', 'source', '!:!', 'Could not write to resource.')
  ('Debug info:', 'gstrtspsrc.c(6933): gst_rtspsrc_close (): /GstPipeline:pipeline0/GstRTSPSrc:source:\nCould not send message. (Generic error)')
  ('ERROR!!!:', 'udpsrc2', '!:!', 'Internal data stream error.')
  ('Debug info:', 'gstbasesrc.c(2951): gst_base_src_loop (): /GstPipeline:pipeline0/GstRTSPSrc:source/GstUDPSrc:udpsrc2:\nstreaming stopped, reason not-linked (-1)')
  </code></pre>
  
  <p>In case the problem was with rtspsrc, I also tried using a short local video using filesrc, and using the EOS signal generated when gstreamer reaches end of the video file to test whether I am able to restart the pipeline. Here is an example pipeline I used to play local video:</p>
  
  <pre><code>filesrc location=file.mp4 ! qtdemux ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink name=sink
  </code></pre>
  
  <p>If it is successful, it should start going through the video again, but no luck... Instead I am getting the following error, which makes me think that filesrc somehow needs to be reset. Same with the rtsp example, where there is an error being generated by rtspsrc</p>
  
  <pre><code>('ERROR!!!:', 'qtdemux0', '!:!', 'Internal data stream error.')
  ('Debug info:', 'qtdemux.c(5847): gst_qtdemux_loop (): /GstPipeline:pipeline0/GstQTDemux:qtdemux0:\nstreaming stopped, reason not-linked (-1)')
  </code></pre>
  
  <p>Can anybody shed any light on this problem? Thanks!</p>