avwait: Fix clipping of audio buffers at the start of recording
authorSebastian Dröge <sebastian@centricular.com>
Fri, 12 Jul 2019 09:28:59 +0000 (12:28 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 12 Jul 2019 09:54:02 +0000 (12:54 +0300)
gst/timecode/gstavwait.c

index 4d6a8fed674ddd4f66e87611d61907bb0da4a8a4..73d03bb86d37500cf1f998d6db276168d030a65e 100644 (file)
@@ -1202,9 +1202,23 @@ gst_avwait_asink_chain (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
           self->audio_running_time_to_end_at) == -1) {
     /* Audio ends after start, but before end: clip */
     GstSegment asegment2 = self->asegment;
+    guint64 start;
+    gint ssign;
+
+    ssign = gst_segment_position_from_running_time_full (&asegment2,
+        GST_FORMAT_TIME, self->audio_running_time_to_wait_for, &start);
+    if (ssign > 0) {
+      asegment2.start = start;
+    } else {
+      /* Starting before the start of the audio segment?! */
+      /* This shouldn't happen: we already know that the current audio is
+       * inside the segment, and that the end is after the current audio
+       * position */
+      GST_ELEMENT_ERROR (self, CORE, FAILED,
+          ("Failed to clip audio: it should have started before the current segment"),
+          NULL);
+    }
 
-    gst_segment_set_running_time (&asegment2, GST_FORMAT_TIME,
-        self->audio_running_time_to_wait_for);
     inbuf =
         gst_audio_buffer_clip (inbuf, &asegment2, self->ainfo.rate,
         self->ainfo.bpf);