diff options
-rw-r--r-- | gst/mpegtsdemux/mpegtsbase.c | 3 | ||||
-rw-r--r-- | gst/mpegtsdemux/mpegtspacketizer.c | 21 | ||||
-rw-r--r-- | gst/mpegtsdemux/tsdemux.c | 41 |
3 files changed, 54 insertions, 11 deletions
diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index 0ca72538c..a2fe39c17 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -169,6 +169,8 @@ mpegts_base_reset (MpegTSBase * base) { MpegTSBaseClass *klass = GST_MPEGTS_BASE_GET_CLASS (base); + GST_DEBUG_OBJECT (base, "Resetting"); + mpegts_packetizer_clear (base->packetizer); memset (base->is_pes, 0, 1024); memset (base->known_psi, 0, 1024); @@ -1088,6 +1090,7 @@ mpegts_base_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) hard = (base->mode != BASE_MODE_SEEKING); mpegts_packetizer_flush (base->packetizer, hard); mpegts_base_flush (base, hard); + GST_DEBUG_OBJECT (base, "Resetting base->segment"); gst_segment_init (&base->segment, GST_FORMAT_UNDEFINED); base->seen_pat = FALSE; break; diff --git a/gst/mpegtsdemux/mpegtspacketizer.c b/gst/mpegtsdemux/mpegtspacketizer.c index 7889c7e60..162e1ac4f 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.c +++ b/gst/mpegtsdemux/mpegtspacketizer.c @@ -648,8 +648,9 @@ mpegts_packetizer_push (MpegTSPacketizer2 * packetizer, GstBuffer * buffer) } GST_DEBUG ("Pushing %" G_GSIZE_FORMAT " byte from offset %" - G_GUINT64_FORMAT, gst_buffer_get_size (buffer), - GST_BUFFER_OFFSET (buffer)); + G_GUINT64_FORMAT " With ts:%" GST_TIME_FORMAT, + gst_buffer_get_size (buffer), GST_BUFFER_OFFSET (buffer), + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); gst_adapter_push (packetizer->adapter, buffer); /* If buffer timestamp is valid, store it */ if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) @@ -2168,15 +2169,19 @@ mpegts_packetizer_pts_to_ts (MpegTSPacketizer2 * packetizer, GST_TIME_ARGS (pcrtable->base_pcrtime), GST_TIME_ARGS (pcrtable->base_time), GST_TIME_ARGS (pcrtable->pcroffset)); + GST_DEBUG ("last_pcrtime %" GST_TIME_FORMAT, + GST_TIME_ARGS (pcrtable->last_pcrtime)); res = pts + pcrtable->pcroffset; - /* Don't return anything if we differ too much against last seen PCR */ - /* FIXME : Ideally we want to figure out whether we have a wraparound or - * a reset so we can provide actual values. - * That being said, this will only happen for the small interval of time - * where PTS/DTS are wrapping just before we see the first reset/wrap PCR - */ if (G_UNLIKELY (ABSDIFF (res, pcrtable->last_pcrtime) > 15 * GST_SECOND)) + /* Don't return anything if we differ too much against last seen PCR */ + /* FIXME : Ideally we want to figure out whether we have a wraparound or + * a reset so we can provide actual values. + * That being said, this will only happen for the small interval of time + * where PTS/DTS are wrapping just before we see the first reset/wrap PCR + */ + res = GST_CLOCK_TIME_NONE; + else if (res < pcrtable->base_pcrtime) res = GST_CLOCK_TIME_NONE; else res += pcrtable->base_time + pcrtable->skew - pcrtable->base_pcrtime; diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index 7f2d25519..2c499e825 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -1901,6 +1901,7 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream) { MpegTSBase *base = (MpegTSBase *) demux; GstClockTime lowest_pts = GST_CLOCK_TIME_NONE; + GstClockTime highest_pts = GST_CLOCK_TIME_NONE; GstClockTime firstts = 0; GList *tmp; @@ -1923,12 +1924,19 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream) if (!GST_CLOCK_TIME_IS_VALID (lowest_pts) || pstream->first_dts < lowest_pts) lowest_pts = pstream->first_dts; + if (!GST_CLOCK_TIME_IS_VALID (highest_pts) + || pstream->first_dts > highest_pts) + highest_pts = pstream->first_dts; } } - if (GST_CLOCK_TIME_IS_VALID (lowest_pts)) - firstts = lowest_pts; GST_DEBUG ("lowest_pts %" G_GUINT64_FORMAT " => clocktime %" GST_TIME_FORMAT, - lowest_pts, GST_TIME_ARGS (firstts)); + lowest_pts, GST_TIME_ARGS (lowest_pts)); + GST_DEBUG ("highest pts %" G_GUINT64_FORMAT " => clocktime %" GST_TIME_FORMAT, + highest_pts, GST_TIME_ARGS (highest_pts)); + if (GST_CLOCK_TIME_IS_VALID (highest_pts)) + firstts = highest_pts; + else if (GST_CLOCK_TIME_IS_VALID (lowest_pts)) + firstts = lowest_pts; if (demux->calculate_update_segment) { GST_DEBUG ("Calculating update segment"); @@ -1950,8 +1958,25 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream) if (base->segment.format == GST_FORMAT_TIME) { /* Try to recover segment info from base if it's in TIME format */ demux->segment = base->segment; + /* $#*@($%(#@*FDJSLK JFWIUR#(@I */ + GST_DEBUG ("Re-using upstream segment"); + if (!base->upstream_live) { + GstClockTime segdiff = GST_CLOCK_TIME_NONE; + if (GST_CLOCK_TIME_IS_VALID (demux->segment.stop)) + segdiff = demux->segment.stop - demux->segment.start; + GST_DEBUG ("Not live, setting segment start to %" GST_TIME_FORMAT, + GST_TIME_ARGS (firstts)); + demux->segment.start = firstts; + demux->segment.time = firstts; + if (GST_CLOCK_TIME_IS_VALID (segdiff)) { + GST_DEBUG ("Not live, setting segment stop to %" GST_TIME_FORMAT, + GST_TIME_ARGS (firstts + segdiff)); + demux->segment.stop = firstts + segdiff; + } + } } else { /* Start from the first ts/pts */ + GST_DEBUG ("Calculating new segment based on firstts"); gst_segment_init (&demux->segment, GST_FORMAT_TIME); demux->segment.start = firstts; demux->segment.stop = GST_CLOCK_TIME_NONE; @@ -1960,13 +1985,23 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream) demux->segment.rate = demux->rate; } } else if (demux->segment.start < firstts) { + GST_DEBUG ("Adjustments"); /* Take into account the offset to the first buffer timestamp */ if (GST_CLOCK_TIME_IS_VALID (demux->segment.stop)) demux->segment.stop += firstts - demux->segment.start; demux->segment.position = firstts; demux->segment.start = firstts; + /* Upstream base segment might have changed */ + if (base->segment.format == GST_FORMAT_TIME) + demux->segment.base = base->segment.base; } + GST_DEBUG ("demux->segment is now " SEGMENT_FORMAT, + SEGMENT_ARGS (demux->segment)); + GST_DEBUG ("diff lowts - start : %" GST_TIME_FORMAT " diff hights - lowts : %" + GST_TIME_FORMAT, GST_TIME_ARGS (firstts - demux->segment.start), + GST_TIME_ARGS (highest_pts - firstts)); + if (!demux->segment_event) { demux->segment_event = gst_event_new_segment (&demux->segment); GST_EVENT_SEQNUM (demux->segment_event) = base->last_seek_seqnum; |