title: GStreamer dynamic recording pipeline with valve element
body: <p>I have a gstreamer pipeline that does some processing on stream and based on this processing it generates recording event to another GStreamer recording pipeline on a tee branch.</p>
  <p>The whole pipeline is as the following:</p>
  <pre><code>rtsp-source-&gt; h264-depay -&gt; tee-&gt; h264-parser -&gt; decoder -&gt;some-processing-plugin
                                |-&gt; h264-parser -&gt; recordbin
  </code></pre>
  <p><code>recordbin</code> is my recording pipeline and it is as the following:</p>
  <pre><code>valve-&gt; queue-&gt; avimux-&gt; filesink
  </code></pre>
  <p>I have start and stop functions this is the important part of my start function where I set a new file location in the filesink and start the recording pipeline:</p>
  <pre><code>gst_element_set_locked_state(filesink,TRUE);
  gst_element_set_state(filesink,GST_STATE_NULL);
  g_object_set(G_OBJECT(filesink), &quot;location&quot;, fileName, NULL);
  g_object_set(G_OBJECT(pre_muxer_valve), &quot;drop&quot;, FALSE, NULL);
  g_print(&quot;After opening pre queue valve\n&quot;);
  gst_element_set_state(filesink,GST_STATE_PLAYING);
  gst_element_set_locked_state(filesink,FALSE);
  gst_element_sync_state_with_parent(filesink);
  </code></pre>
  <p>and this is a part of my stop function where I am stop the recording after some amount of time:</p>
  <pre><code>g_object_set(G_OBJECT(pre_muxer_valve), &quot;drop&quot;, TRUE, NULL);
  g_print(&quot;Recording stopped\n&quot;);
  gst_element_send_event(muxer,gst_event_new_eos());
  gst_element_send_event(muxer,gst_event_new_flush_stop(TRUE));
  </code></pre>
  <p>I know that I need to send <code>EOS</code> event to the <code>muxer</code> and the <code>filesink</code> to close the file correctly and get a playable file. My problem is after first time I call the stop function if I sent <code>EOS</code> event only on the next start when I open the <code>valve</code> the pipeline immediately receive an <code>EOS</code> and stops if I send an <code>EOS</code> then a <code>FLUSH_STOP</code> event I get the following message and all the output files is 0 bytes not corrupted it doesn't contain any data as if the <code>filesink</code> didn't write any thing in the file but the pipeline doesn't stop:</p>
  <pre><code>(recording-test:30341): GStreamer-CRITICAL **: 16:22:10.433: gst_segment_to_running_time: assertion 'segment-&gt;format == format' failed
  </code></pre>
  <p>any help would be appreciated.</p>