Index: libs/gst/base/gstbaseparse.c
===================================================================
--- libs/gst/base/gstbaseparse.c	(revision 6950)
+++ libs/gst/base/gstbaseparse.c	(working copy)
@@ -244,7 +244,7 @@
 static void gst_base_parse_loop (GstPad * pad);
 
 static gboolean gst_base_parse_check_frame (GstBaseParse *parse,
-    GstBuffer *buffer, guint *framesize, guint *skipsize);
+    GstBuffer *buffer, guint *framesize, gint *skipsize);
 
 static gboolean gst_base_parse_parse_frame (GstBaseParse *parse,
     GstBuffer *buffer);
@@ -372,8 +372,9 @@
  * gst_base_parse_check_frame:
  * @parse: #GstBaseParse.
  * @buffer: GstBuffer.
- * @framesize:
- * @skipsize:
+ * @framesize: This will be set to tell the found frame size in bytes.
+ * @skipsize: Output parameter that tells how much data needs to be skipped
+ *            in order to find the following frame header.
  *
  * Default callback for check_valid_frame.
  * 
@@ -383,7 +384,7 @@
 gst_base_parse_check_frame (GstBaseParse *parse,
                             GstBuffer *buffer,
                             guint *framesize,
-                            guint *skipsize)
+                            gint *skipsize)
 {
   *framesize = GST_BUFFER_SIZE (buffer);
   *skipsize = 0;
@@ -393,9 +394,10 @@
 
 /**
  * gst_base_parse_parse_frame:
- * @parse: #GstBaseParse
- * @buffer: #GstBuffer
+ * @parse: #GstBaseParse.
+ * @buffer: #GstBuffer.
  *
+ * Default callback for parse_frame.
  */
 static gboolean
 gst_base_parse_parse_frame (GstBaseParse *parse, GstBuffer *buffer)
@@ -437,8 +439,8 @@
 
 /**
  * gst_base_parse_sink_event:
- * @pad: #GstPad.
- * @event: #GstEvent.
+ * @pad: #GstPad that received the event.
+ * @event: #GstEvent to be handled.
  *
  * Handler for sink pad events.
  *
@@ -484,8 +486,10 @@
 /**
  * gst_base_parse_sink_eventfunc:
  * @parse: #GstBaseParse.
- * @event: #GstEvent.
+ * @event: #GstEvent to be handled.
  *
+ * Element-level event handler function.
+ *
  * Returns: TRUE if the event was handled and not need forwarding.
  */
 static gboolean
@@ -585,8 +589,8 @@
 
 /**
  * gst_base_parse_src_event:
- * @pad: #GstPad.
- * @event: #GstEvent.
+ * @pad: #GstPad that received the event.
+ * @event: #GstEvent that was received.
  *
  * Handler for source pad events.
  *
@@ -620,8 +624,10 @@
 /**
  * gst_base_parse_src_eventfunc:
  * @parse: #GstBaseParse.
- * @event: #GstEvent
+ * @event: #GstEvent that was received.
  *
+ * Default srcpad event handler.
+ *
  * Returns: TRUE if the event was handled and can be dropped.
  */
 static gboolean
@@ -652,6 +658,8 @@
  * gst_base_parse_is_seekable:
  * @parse: #GstBaseParse.
  *
+ * Default handler for is_seekable.
+ *
  * Returns: Always TRUE.
  */
 static gboolean
@@ -667,8 +675,11 @@
  * @klass: #GstBaseParseClass.
  * @buffer: #GstBuffer.
  *
+ * Parses the frame from given buffer and pushes it forward. Also performs
+ * timestamp handling and checks the segment limits.
+ *
  * This is called with srcpad STREAM_LOCK held.
- * 
+ *
  * Returns: #GstFlowReturn
  */
 static GstFlowReturn
@@ -737,7 +748,9 @@
  * gst_base_parse_drain:
  * @parse: #GstBaseParse.
  *
- * Drains the adapter until it is empty.
+ * Drains the adapter until it is empty. It decreases the min_frame_size to
+ * match the current adapter size and calls chain method until the adapter
+ * is emptied or chain returns with error.
  */
 static void
 gst_base_parse_drain (GstBaseParse *parse)
@@ -771,7 +784,8 @@
   GstFlowReturn ret = GST_FLOW_OK;
   GstBuffer *outbuf = NULL;
   GstBuffer *tmpbuf = NULL;
-  guint fsize = 0, skip = 0;
+  guint fsize = 0;
+  gint skip = -1;
   const guint8 *data;
   guint min_size;
 
@@ -838,24 +852,35 @@
       GST_BUFFER_OFFSET (tmpbuf) = parse->priv->offset;
       GST_BUFFER_FLAG_SET (tmpbuf, GST_MINI_OBJECT_FLAG_READONLY);
 
-      skip = 0;
+      if (parse->priv->discont) {
+        GST_DEBUG_OBJECT (parse, "marking DISCONT");
+        GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
+      }
+
+      skip = -1;
       if (bclass->check_valid_frame (parse, tmpbuf, &fsize, &skip)) {
         break;
       }
-      if (skip) {
+      if (skip > 0) {
         GST_LOG ("finding sync, skipping %d bytes", skip);
         gst_adapter_flush (parse->adapter, skip);
         parse->priv->offset += skip;
-      } else {
+      }
+      else if (skip == -1) {
+        /* subclass didn't touch this value. By default we skip 1 byte */
         GST_LOG ("finding sync, skipping 1 byte");
         gst_adapter_flush (parse->adapter, 1);
         parse->priv->offset++;
       }
+      /* There is a possibility that subclass set the skip value to zero.
+         This means that it has probably found a frame but wants to ask
+         more data (by increasing the min_size) to be sure of this. */
     }
     gst_buffer_unref (tmpbuf);
     tmpbuf = NULL;
 
-    if (skip) {
+    if (skip > 0) {
+      /* Subclass found the sync, but still wants to skip some data */
       GST_LOG ("skipping %d bytes", skip);
       gst_adapter_flush (parse->adapter, skip);
       parse->priv->offset += skip;
@@ -893,11 +918,11 @@
 }
 
 
-
 /**
  * gst_base_parse_loop:
  * @pad: GstPad
  *
+ * Loop that is used in pull mode to retrieve data from upstream.
  */
 static void
 gst_base_parse_loop (GstPad * pad)
@@ -906,7 +931,8 @@
   GstBaseParseClass *klass;
   GstBuffer *buffer, *outbuf;
   gboolean ret = FALSE;
-  guint fsize = 0, skip = 0, min_size;
+  guint fsize = 0, min_size;
+  gint skip = 0;
 
   parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
   klass = GST_BASE_PARSE_GET_CLASS (parse);
@@ -923,13 +949,16 @@
     parse->pending_segment = NULL;
   }
 
-  GST_BASE_PARSE_LOCK (parse);
-  min_size = parse->priv->min_frame_size;
-  GST_BASE_PARSE_UNLOCK (parse);
-
   /* TODO: Check if we reach segment stop limit */
 
   while (TRUE) {
+
+    GST_BASE_PARSE_LOCK (parse);
+    min_size = parse->priv->min_frame_size;
+    GST_BASE_PARSE_UNLOCK (parse);
+
+    /* TODO:  Pull large chunk and consume it instead of performing
+              a lot of small pulls */
     ret = gst_pad_pull_range (parse->sinkpad, parse->priv->offset,
                               min_size, &buffer);
 
@@ -939,19 +968,27 @@
       goto need_pause;
 
     /* EOS */
+
+    /* FIXME: Do we still need to feed the buffer to subclass? */
     if (GST_BUFFER_SIZE (buffer) < min_size) {
       gst_buffer_unref (buffer);
       goto eos;
     }
 
-    skip = 0;
+    if (parse->priv->discont) {
+      GST_DEBUG_OBJECT (parse, "marking DISCONT");
+      GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
+    }
+
+    skip = -1;
     if (klass->check_valid_frame (parse, buffer, &fsize, &skip)) {
       break;
     }
-    if (skip) {
+    if (skip > 0) {
       GST_LOG ("finding sync, skipping %d bytes", skip);
       parse->priv->offset += skip;
-    } else {
+    }
+    else if (skip == -1) {
       GST_LOG ("finding sync, skipping 1 byte");
       parse->priv->offset++;
     }
@@ -967,8 +1004,11 @@
     outbuf = buffer;
   }
 
-  parse->priv->offset += fsize + skip;
+  parse->priv->offset += fsize;
 
+  /* Does the subclass want to skip too? */
+  if (skip > 0) parse->priv->offset += skip;
+
   /* This always unrefs the outbuf, even if error occurs */
   ret = gst_base_parse_handle_and_push_buffer (parse, klass, outbuf);
 
@@ -1085,10 +1125,10 @@
 
 /**
  * gst_base_parse_sink_activate_push:
- * @pad: #GstPad.
- * @active:
+ * @pad: #GstPad to be (de)activated.
+ * @active: TRUE when activating, FALSE when deactivating.
  *
- * Returns: TRUE if activation succeeded.
+ * Returns: TRUE if (de)activation succeeded.
  */
 static gboolean
 gst_base_parse_sink_activate_push (GstPad * pad, gboolean active)
@@ -1113,10 +1153,10 @@
 
 /**
  * gst_base_parse_sink_activate_pull:
- * @sinkpad: #GstPad to be activated.
- * @active:
+ * @sinkpad: #GstPad to be (de)activated.
+ * @active: TRUE when activating, FALSE when deactivating.
  *
- * Returns: TRUE if activation succeeded.
+ * Returns: TRUE if (de)activation succeeded.
  */
 static gboolean
 gst_base_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
@@ -1155,7 +1195,8 @@
  * @fmt: #GstFormat.
  * @duration: duration value.
  *
- * Sets the duration of the currently playing media.
+ * Sets the duration of the currently playing media. Subclass can use this
+ * when it notices a change in the media duration.
  */
 void gst_base_parse_set_duration (GstBaseParse *parse,
                                   GstFormat fmt,
Index: libs/gst/base/gstbaseparse.h
===================================================================
--- libs/gst/base/gstbaseparse.h	(revision 6950)
+++ libs/gst/base/gstbaseparse.h	(working copy)
@@ -192,7 +192,7 @@
   gboolean      (*check_valid_frame)  (GstBaseParse *parse,
                                        GstBuffer *buffer,
                                        guint *framesize,
-                                       guint *skipsize);
+                                       gint *skipsize);
 
   GstFlowReturn (*parse_frame)        (GstBaseParse *parse,
                                        GstBuffer *buffer);
