summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Sousa Santos <thiagoss@redmoon.(none)>2009-11-17 17:25:14 -0300
committerThiago Sousa Santos <thiagoss@redmoon.(none)>2009-11-17 23:04:54 -0300
commit48a2bbd6ad982d92bfe797b18dcf99320dc99b21 (patch)
tree206715d06ee316a6afed501c8cb1ce2fd98f2f52
parentd70afdccd19dafe19575dbe9e58e552f51ee1a41 (diff)
asfmux: handle streams with different start times
Prevents losing sync when remuxing streams with different start times. The smallest start time is selected as the base time and all timestamps are subtracted from it to get the actual time to be used when muxing and building indexes Fixes #586848
-rw-r--r--gst/asfmux/gstasfmux.c24
-rw-r--r--gst/asfmux/gstasfmux.h3
2 files changed, 26 insertions, 1 deletions
diff --git a/gst/asfmux/gstasfmux.c b/gst/asfmux/gstasfmux.c
index 4d4fa2e5a..3afc936c9 100644
--- a/gst/asfmux/gstasfmux.c
+++ b/gst/asfmux/gstasfmux.c
@@ -216,6 +216,7 @@ gst_asf_mux_reset (GstAsfMux * asfmux)
asfmux->total_data_packets = 0;
asfmux->file_size = 0;
asfmux->packet_size = 0;
+ asfmux->first_ts = GST_CLOCK_TIME_NONE;
if (asfmux->payloads) {
GSList *walk;
@@ -1763,8 +1764,12 @@ gst_asf_mux_process_buffer (GstAsfMux * asfmux, GstAsfPad * pad,
gst_asf_payload_free (payload);
return GST_FLOW_ERROR;
}
+
+ g_assert (GST_CLOCK_TIME_IS_VALID (asfmux->first_ts));
+ g_assert (GST_CLOCK_TIME_IS_VALID (pad->first_ts));
+
payload->presentation_time = asfmux->preroll +
- (GST_BUFFER_TIMESTAMP (buf) / GST_MSECOND);
+ ((GST_BUFFER_TIMESTAMP (buf) - asfmux->first_ts) / GST_MSECOND);
/* update counting values */
pad->media_object_number = (pad->media_object_number + 1) % 256;
@@ -1833,6 +1838,21 @@ gst_asf_mux_collected (GstCollectPads * collect, gpointer data)
continue;
}
time = GST_BUFFER_TIMESTAMP (buf);
+
+ /* check the ts for getting the first time */
+ if (!GST_CLOCK_TIME_IS_VALID (pad->first_ts) &&
+ GST_CLOCK_TIME_IS_VALID (time)) {
+ GST_DEBUG_OBJECT (asfmux, "First ts for stream number %" G_GUINT16_FORMAT
+ ": %" GST_TIME_FORMAT, pad->stream_number, GST_TIME_ARGS (time));
+ pad->first_ts = time;
+ if (!GST_CLOCK_TIME_IS_VALID (asfmux->first_ts) ||
+ time < asfmux->first_ts) {
+ GST_DEBUG_OBJECT (asfmux, "New first ts for file %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (time));
+ asfmux->first_ts = time;
+ }
+ }
+
gst_buffer_unref (buf);
if (best_pad == NULL || !GST_CLOCK_TIME_IS_VALID (time) ||
@@ -1887,6 +1907,8 @@ gst_asf_mux_pad_reset (GstAsfPad * pad)
gst_tag_list_free (pad->taglist);
pad->taglist = NULL;
+ pad->first_ts = GST_CLOCK_TIME_NONE;
+
if (pad->is_audio) {
GstAsfAudioPad *audiopad = (GstAsfAudioPad *) pad;
audiopad->audioinfo.rate = 0;
diff --git a/gst/asfmux/gstasfmux.h b/gst/asfmux/gstasfmux.h
index 4e13b36a6..015c8b9ab 100644
--- a/gst/asfmux/gstasfmux.h
+++ b/gst/asfmux/gstasfmux.h
@@ -65,6 +65,7 @@ struct _GstAsfPad
guint32 bitrate;
GstClockTime play_duration;
+ GstClockTime first_ts;
GstBuffer *codec_data;
@@ -136,6 +137,8 @@ struct _GstAsfMux
guint64 preroll; /* milisecs */
gboolean merge_stream_tags;
+ GstClockTime first_ts;
+
/* pads */
GstPad *srcpad;