diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c
old mode 100644
new mode 100755
index 89dc466..b83ec3b
--- a/gst/rtsp-server/rtsp-media.c
+++ b/gst/rtsp-server/rtsp-media.c
@@ -17,6 +17,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <stdlib.h>
 #include <string.h>
 
 #include <gst/app/gstappsrc.h>
@@ -1526,6 +1527,45 @@ default_unprepare (GstRTSPMedia * media)
   return TRUE;
 }
 
+static void
+pipelines_send_eos(GstElement *in) {
+  GstIterator *it = gst_bin_iterate_elements(GST_BIN(in));
+  gboolean done = FALSE;
+  void *item;
+  while (!done) {
+    switch (gst_iterator_next(it, &item)) {
+    case GST_ITERATOR_OK:
+      {
+        GstElement *e = (GstElement *)item;
+        if (GST_IS_BIN(item)) {
+          char *name = (char*)gst_element_get_name(e);
+          gst_element_send_event (e, gst_event_new_eos ());
+          GST_INFO("bin: %s->\n", name);
+          pipelines_send_eos(e);
+          g_free((gpointer)name);
+        } else {
+          char *name = (char*)gst_element_get_name(e);
+          GST_INFO("element: %s\n", name);
+          g_free((gpointer)name);
+        }
+
+        gst_object_unref(item);
+        break;
+      }
+    case GST_ITERATOR_RESYNC:
+      gst_iterator_resync(it);
+      break;
+    case GST_ITERATOR_ERROR:
+      done = TRUE;
+      break;
+    case GST_ITERATOR_DONE:
+      done = TRUE;
+      break;
+    }
+  }
+  gst_iterator_free(it);
+}
+
 /**
  * gst_rtsp_media_set_state:
  * @media: a #GstRTSPMedia
@@ -1564,8 +1604,36 @@ gst_rtsp_media_set_state (GstRTSPMedia * media, GstState state,
       /* fallthrough */
     case GST_STATE_PAUSED:
       /* we're going from PLAYING to PAUSED, READY or NULL, remove */
-      if (media->target_state == GST_STATE_PLAYING)
+      if (media->target_state == GST_STATE_PLAYING) {
+        GstMessage *message;
+        GstBus *bus;
+
+        /* send EOS down pipelines in case there are elements that need and EOS
+           such as the 'filesink' element */
+        pipelines_send_eos(media->pipeline);
+
+        /* get the bus */
+        bus = gst_element_get_bus (media->pipeline);
+
+        /* wait until we see the EOS otherwise process bus messages */
+        while (TRUE) {
+          message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
+
+          if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS) {
+            GST_INFO ("Got EOS from element \"%s\".\n",
+                      GST_MESSAGE_SRC_NAME (message));
+            break;
+          } else {
+            bus_message(bus, message, media);
+          }
+        }
+
         remove = TRUE;
+
+        if (message)
+            gst_message_unref (message);
+        gst_object_unref (bus);
+      }
       break;
     case GST_STATE_PLAYING:
       /* we're going to PLAYING, add */
