making _set_property warn on unknown properties use GST_TIME_FORMAT for timestamp...
[platform/upstream/gstreamer.git] / gst / elements / gstfilesrc.c
index a99553f..6ef3783 100644 (file)
@@ -31,7 +31,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#ifdef HAVE_MMAP
 #include <sys/mman.h>
+#endif
 #include <errno.h>
 #include <string.h>
 
@@ -228,7 +230,9 @@ gst_filesrc_init (GstFileSrc * src)
   gst_pad_set_formats_function (src->srcpad, gst_filesrc_get_formats);
   gst_element_add_pad (GST_ELEMENT (src), src->srcpad);
 
+#ifdef HAVE_MMAP
   src->pagesize = getpagesize ();
+#endif
 
   src->filename = NULL;
   src->fd = 0;
@@ -241,8 +245,6 @@ gst_filesrc_init (GstFileSrc * src)
 
   src->mapbuf = NULL;
   src->mapsize = DEFAULT_MMAPSIZE;      /* default is 4MB */
-
-  src->seek_happened = FALSE;
 }
 
 static void
@@ -320,6 +322,7 @@ gst_filesrc_set_property (GObject * object, guint prop_id, const GValue * value,
       g_object_notify (G_OBJECT (src), "touch");
       break;
     default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
   }
 }
@@ -357,6 +360,7 @@ gst_filesrc_get_property (GObject * object, guint prop_id, GValue * value,
   }
 }
 
+#ifdef HAVE_MMAP
 static void
 gst_filesrc_free_parent_mmap (GstBuffer * buf)
 {
@@ -377,7 +381,9 @@ gst_filesrc_free_parent_mmap (GstBuffer * buf)
 
   GST_BUFFER_DATA (buf) = NULL;
 }
+#endif
 
+#ifdef HAVE_MMAP
 static GstBuffer *
 gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size)
 {
@@ -425,7 +431,9 @@ gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size)
 
   return buf;
 }
+#endif
 
+#ifdef HAVE_MMAP
 static GstBuffer *
 gst_filesrc_map_small_region (GstFileSrc * src, off_t offset, size_t size)
 {
@@ -457,7 +465,9 @@ gst_filesrc_map_small_region (GstFileSrc * src, off_t offset, size_t size)
 
   return gst_filesrc_map_region (src, offset, size);
 }
+#endif
 
+#ifdef HAVE_MMAP
 /**
  * gst_filesrc_get_mmap:
  * @pad: #GstPad to push a buffer from
@@ -593,6 +603,7 @@ gst_filesrc_get_mmap (GstFileSrc * src)
   src->curoffset += GST_BUFFER_SIZE (buf);
   return buf;
 }
+#endif
 
 static GstBuffer *
 gst_filesrc_get_read (GstFileSrc * src)
@@ -648,10 +659,10 @@ gst_filesrc_get (GstPad * pad)
     return GST_DATA (gst_event_new_flush ());
   }
   /* check for seek */
-  if (src->seek_happened) {
+  if (src->need_discont) {
     GstEvent *event;
 
-    src->seek_happened = FALSE;
+    src->need_discont = FALSE;
     GST_DEBUG_OBJECT (src, "sending discont");
     event =
         gst_event_new_discontinuous (FALSE, GST_FORMAT_BYTES, src->curoffset,
@@ -669,12 +680,15 @@ gst_filesrc_get (GstPad * pad)
       return GST_DATA (gst_event_new (GST_EVENT_EOS));
     }
   }
-
+#ifdef HAVE_MMAP
   if (src->using_mmap) {
     return GST_DATA (gst_filesrc_get_mmap (src));
   } else {
     return GST_DATA (gst_filesrc_get_read (src));
   }
+#else
+  return GST_DATA (gst_filesrc_get_read (src));
+#endif
 }
 
 /* TRUE if the filesize of the file was updated */
@@ -736,13 +750,15 @@ gst_filesrc_open_file (GstFileSrc * src)
     /* find the file length */
     src->filelen = stat_results.st_size;
 
+    src->using_mmap = FALSE;
+#ifdef HAVE_MMAP
     /* allocate the first mmap'd region */
     src->mapbuf = gst_filesrc_map_region (src, 0, src->mapsize);
-    if (src->mapbuf == NULL) {
-      src->using_mmap = FALSE;
-    } else {
+    if (src->mapbuf != NULL) {
       src->using_mmap = TRUE;
     }
+#endif
+
 
     src->curoffset = 0;
 
@@ -789,11 +805,12 @@ gst_filesrc_change_state (GstElement * element)
         if (!gst_filesrc_open_file (GST_FILESRC (element)))
           return GST_STATE_FAILURE;
       }
+      src->need_discont = TRUE;
       break;
     case GST_STATE_PAUSED_TO_READY:
       if (GST_FLAG_IS_SET (element, GST_FILESRC_OPEN))
         gst_filesrc_close_file (GST_FILESRC (element));
-      src->seek_happened = TRUE;
+      src->need_discont = TRUE;
       break;
     default:
       break;
@@ -860,8 +877,9 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
 
       switch (GST_EVENT_SEEK_METHOD (event)) {
         case GST_SEEK_METHOD_SET:
-          if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
-                  || offset > src->filelen)) {
+          if (offset < 0 ||
+              (offset > src->filelen && (!gst_filesrc_check_filesize (src)
+                      || offset > src->filelen))) {
             goto error;
           }
           src->curoffset = offset;
@@ -892,7 +910,7 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
           goto error;
           break;
       }
-      src->seek_happened = TRUE;
+      src->need_discont = TRUE;
       src->need_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
       break;
     }