Index: gst/rtsp-server/rtsp-media.c
===================================================================
--- gst/rtsp-server/rtsp-media.c	(revision 63607)
+++ gst/rtsp-server/rtsp-media.c	(working copy)
@@ -1884,11 +1884,12 @@
       break;
     case GST_MESSAGE_EOS:
       GST_INFO ("%p: got EOS", media);
-
+      g_rec_mutex_lock (&priv->state_lock);
       if (priv->status == GST_RTSP_MEDIA_STATUS_UNPREPARING) {
         GST_DEBUG ("shutting down after EOS");
         finish_unprepare (media);
       }
+      g_rec_mutex_unlock (&priv->state_lock);
       break;
     default:
       GST_INFO ("%p: got message type %d (%s)", media, type,
@@ -2396,6 +2397,7 @@
   GList *walk;
 
   GST_DEBUG ("shutting down");
+  gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_UNPREPARED);
 
   /* release the lock on shutdown, otherwise pad_added_cb might try to
    * acquire the lock and then we deadlock */
@@ -2440,7 +2442,6 @@
   priv->nettime = NULL;
 
   priv->reused = TRUE;
-  gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_UNPREPARED);
 
   /* when the media is not reusable, this will effectively unref the media and
    * recreate it */
