Index: gst-libs/gst/audio/audio.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/audio.c,v
retrieving revision 1.30
diff -u -p -u -p -r1.30 audio.c
--- gst-libs/gst/audio/audio.c	16 Feb 2007 10:19:45 -0000	1.30
+++ gst-libs/gst/audio/audio.c	13 Jul 2007 17:02:54 -0000
@@ -251,3 +251,61 @@ gst_audio_structure_set_int (GstStructur
     _gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE,
         FALSE, NULL);
 }
+
+/**
+ * gst_audio_buffer_clip:
+ * @buffer: The buffer to clip.
+ * @segment: Segment in %GST_FORMAT_TIME to which the buffer should be clipped.
+ * @rate: sample rate.
+ * @frame_size: size of one audio frame in bytes.
+ *
+ * Clip the the buffer to the given %GstSegment.
+ *
+ * After calling this function do not reference @buffer anymore.
+ *
+ * Returns: %NULL if the buffer is completely outside the configured segment
+ * or the segment doesn't have %GST_FORMAT_TIME, otherwise the clipped buffer
+ * is returned.
+ *
+ * Since: 0.10.14
+ */
+GstBuffer *
+gst_audio_buffer_clip (GstBuffer *buffer, GstSegment *segment, gint rate, gint frame_size)
+{
+  gint64 start, stop, cstart, cstop, diff;
+
+  g_return_val_if_fail (segment->format == GST_FORMAT_TIME, buffer);
+
+  start = GST_BUFFER_TIMESTAMP (buffer);
+  stop = start + GST_BUFFER_DURATION (buffer);
+
+  if (gst_segment_clip (segment, GST_FORMAT_TIME,
+          start, stop, &cstart, &cstop)) {
+    GstBuffer *ret = gst_buffer_make_metadata_writable (buffer);
+
+    diff = cstart - start;
+    if (diff > 0) {
+      GST_BUFFER_TIMESTAMP (ret) = cstart;
+      GST_BUFFER_DURATION (ret) -= diff;
+
+      diff = frame_size
+          * GST_CLOCK_TIME_TO_FRAMES (diff, rate);
+      GST_BUFFER_DATA (ret) += diff;
+      GST_BUFFER_SIZE (ret) -= diff;
+    }
+
+    diff = cstop - stop;
+    if (diff > 0) {
+      GST_BUFFER_DURATION (ret) -= diff;
+
+      diff = frame_size
+          * GST_CLOCK_TIME_TO_FRAMES (diff, rate);
+      GST_BUFFER_SIZE (ret) -= diff;
+    }
+    return ret;
+  } else {
+    gst_buffer_unref (buffer);
+    return NULL;
+  }
+}
+
Index: gst-libs/gst/audio/audio.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/audio.h,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 audio.h
--- gst-libs/gst/audio/audio.h	15 Feb 2007 15:17:22 -0000	1.26
+++ gst-libs/gst/audio/audio.h	13 Jul 2007 17:02:55 -0000
@@ -143,7 +143,11 @@ typedef enum {
   GST_AUDIO_FIELD_SIGNED        = (1 << 5),
 } GstAudioFieldFlag;
 
+#ifndef GST_DISABLE_DEPRECATED
 void gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag);
+#endif /* GST_DISABLE_DEPRECATED */
+
+GstBuffer *gst_audio_buffer_clip (GstBuffer *buffer, GstSegment *segment, gint rate, gint frame_size);
 
 G_END_DECLS
 
Index: docs/libs/gst-plugins-base-libs-sections.txt
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/docs/libs/gst-plugins-base-libs-sections.txt,v
retrieving revision 1.33
diff -u -p -u -p -r1.33 gst-plugins-base-libs-sections.txt
--- docs/libs/gst-plugins-base-libs-sections.txt	6 Jul 2007 18:19:39 -0000	1.33
+++ docs/libs/gst-plugins-base-libs-sections.txt	13 Jul 2007 17:02:56 -0000
@@ -17,6 +17,7 @@ gst_audio_frame_length
 gst_audio_duration_from_pad_buffer
 gst_audio_is_buffer_framed
 gst_audio_structure_set_int
+gst_audio_buffer_clip
 </SECTION>
 
 <SECTION>
