title: gstreamer not flushing to the filesink
body: <p>I have this gstreamer pipeline which works from the coomand line as:</p>
  
  <pre><code>gst-launch-1.0 autovideosrc ! tee name = t ! queue ! omxh264enc ! 
  'video/x-h264, stream-format=(string)byte-stream' ! h264parse ! qtmux 
  ! filesink name=fileSink location=test.mp4 t. ! queue ! videoscale ! 
  video/x-raw, width=480,height=270 ! xvimagesink name=displaySink -e
  </code></pre>
  
  <p>Now, I am replicating this on the C++ side as follows:</p>
  
  <pre><code>GstElement * pipeline = gst_parse_launch("autovideosrc ! tee name = t ! "
                      "queue ! omxh264enc ! video/x-h264, "
                      "stream-format=(string)byte-stream ! h264parse ! "
                      "qtmux ! filesink name=fileSink location=test.mp4 t. "
                      "! queue ! videoscale ! video/x-raw, width=480,height=270 ! "
                      "xvimagesink name=displaySink", &amp;error);&lt;/raw&gt;
  </code></pre>
  
  <p>I connect this to a QT window and play as follows:</p>
  
  <pre><code>GstElement * displaySink = gst_bin_get_by_name (GST_BIN (pipeline), "displaySink");
  qDebug() &lt;&lt; displaySink;
  // prepare the ui
  QWidget window;
  window.resize(480, 270);
  window.show();
  
  WId xwinid = window.winId();
  gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY(displaySink), xwinid);
  
  // run the pipeline
  qDebug() &lt;&lt; "Calling run...";
  
  GstStateChangeReturn sret = gst_element_set_state (pipeline,
                                                     GST_STATE_PLAYING);
  if (sret == GST_STATE_CHANGE_FAILURE) {
      gst_element_set_state (pipeline, GST_STATE_NULL);
      gst_object_unref (pipeline);
      // Exit application
      QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
  }
  
  int ret = app.exec();
  
  window.hide();
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  </code></pre>
  
  <p>This starts displaying the video stream onto my Qt window and the file <code>test.mp4</code> gets created and it starts to grow in size. However, when I quit the application, the file is not playable. I have a feeling this is because the last bits or some header information is not written due to me calling:</p>
  
  <pre><code>gst_element_set_state (pipeline, GST_STATE_NULL);
  </code></pre>
  
  <p>I am speculating that this perhaps closes the pipeline without ensuring that the file is correctly created and finalized. Is there a way to ensure that EOF or EOS is called on the pipeline before closing and ensuring that the file is written properly? This is also a speculation at the moment from my part but something else could be wrong...</p>