vorbisenc: Ensure output buffers fall within the segment
authorJan Schmidt <thaytan@noraisin.net>
Wed, 29 Apr 2009 15:45:27 +0000 (16:45 +0100)
committerJan Schmidt <thaytan@noraisin.net>
Wed, 29 Apr 2009 15:48:45 +0000 (16:48 +0100)
Add the start position of the first segment to the running time
used to generate buffer timestamps in vorbisenc. This avoids generating
buffers which fall outside the initial segment. The element segment
handling requires more extensive fixing, but this at least prevents
regressions. Fixes: #580020

ext/vorbis/gstvorbisenc.h
ext/vorbis/vorbisenc.c

index 840f2bd..9375a16 100644 (file)
@@ -81,6 +81,7 @@ struct _GstVorbisEnc {
   guint64          granulepos_offset;
   gint64           subgranule_offset;
   GstSegment       segment;
+  GstClockTime     initial_ts;
 
   GstTagList *     tags;
 
index 049d957..55bf849 100644 (file)
@@ -1036,9 +1036,15 @@ gst_vorbis_enc_sink_event (GstPad * pad, GstEvent * event)
 
       gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
           &format, &start, &stop, &position);
-      if (format == GST_FORMAT_TIME)
+      if (format == GST_FORMAT_TIME) {
         gst_segment_set_newsegment (&vorbisenc->segment, update, rate, format,
             start, stop, position);
+        if (vorbisenc->initial_ts == GST_CLOCK_TIME_NONE) {
+          GST_DEBUG_OBJECT (vorbisenc, "Initial segment %" GST_SEGMENT_FORMAT,
+              &vorbisenc->segment);
+          vorbisenc->initial_ts = start;
+        }
+      }
     }
       /* fall through */
     default:
@@ -1099,7 +1105,9 @@ gst_vorbis_enc_chain (GstPad * pad, GstBuffer * buffer)
 
   timestamp =
       gst_segment_to_running_time (&vorbisenc->segment, GST_FORMAT_TIME,
-      GST_BUFFER_TIMESTAMP (buffer));
+      GST_BUFFER_TIMESTAMP (buffer)) + vorbisenc->initial_ts;
+  GST_DEBUG_OBJECT (vorbisenc, "Initial ts is %" GST_TIME_FORMAT,
+      GST_TIME_ARGS (vorbisenc->initial_ts));
 
   if (!vorbisenc->header_sent) {
     /* Vorbis streams begin with three headers; the initial header (with
@@ -1428,6 +1436,7 @@ gst_vorbis_enc_change_state (GstElement * element, GstStateChange transition)
       vorbisenc->next_discont = FALSE;
       vorbisenc->header_sent = FALSE;
       gst_segment_init (&vorbisenc->segment, GST_FORMAT_TIME);
+      vorbisenc->initial_ts = GST_CLOCK_TIME_NONE;
       break;
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
       break;