mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
tsdemux: convert packet PTS/DTS as soon as possible
We let the mpegtspacketizer deal with pcr wraparound/resets. https://bugzilla.gnome.org/show_bug.cgi?id=674536
This commit is contained in:
parent
05b51dfec0
commit
65ba9b4756
1 changed files with 13 additions and 76 deletions
|
@ -137,15 +137,6 @@ struct _TSDemuxStream
|
|||
/* Current PTS/DTS for this stream */
|
||||
GstClockTime pts;
|
||||
GstClockTime dts;
|
||||
/* Raw value of current PTS/DTS */
|
||||
guint64 raw_pts;
|
||||
guint64 raw_dts;
|
||||
/* PTS/DTS with rollover fixed */
|
||||
guint64 fixed_pts;
|
||||
guint64 fixed_dts;
|
||||
/* Number of rollover seen for PTS/DTS (default:0) */
|
||||
guint nb_pts_rollover;
|
||||
guint nb_dts_rollover;
|
||||
|
||||
/* Whether this stream needs to send a newsegment */
|
||||
gboolean need_newsegment;
|
||||
|
@ -1043,12 +1034,6 @@ gst_ts_demux_stream_added (MpegTSBase * base, MpegTSBaseStream * bstream,
|
|||
stream->need_newsegment = TRUE;
|
||||
stream->pts = GST_CLOCK_TIME_NONE;
|
||||
stream->dts = GST_CLOCK_TIME_NONE;
|
||||
stream->raw_pts = 0;
|
||||
stream->raw_dts = 0;
|
||||
stream->fixed_pts = 0;
|
||||
stream->fixed_dts = 0;
|
||||
stream->nb_pts_rollover = 0;
|
||||
stream->nb_dts_rollover = 0;
|
||||
stream->continuity_counter = CONTINUITY_UNSET;
|
||||
}
|
||||
stream->flow_return = GST_FLOW_OK;
|
||||
|
@ -1125,12 +1110,6 @@ gst_ts_demux_stream_flush (TSDemuxStream * stream)
|
|||
stream->need_newsegment = TRUE;
|
||||
stream->pts = GST_CLOCK_TIME_NONE;
|
||||
stream->dts = GST_CLOCK_TIME_NONE;
|
||||
stream->raw_pts = 0;
|
||||
stream->raw_dts = 0;
|
||||
stream->fixed_pts = 0;
|
||||
stream->fixed_dts = 0;
|
||||
stream->nb_pts_rollover = 0;
|
||||
stream->nb_dts_rollover = 0;
|
||||
if (stream->flow_return == GST_FLOW_FLUSHING) {
|
||||
stream->flow_return = GST_FLOW_OK;
|
||||
}
|
||||
|
@ -1190,33 +1169,15 @@ gst_ts_demux_record_pts (GstTSDemux * demux, TSDemuxStream * stream,
|
|||
return;
|
||||
}
|
||||
|
||||
GST_LOG ("pid 0x%04x pts:%" G_GUINT64_FORMAT " at offset %"
|
||||
GST_LOG ("pid 0x%04x raw pts:%" G_GUINT64_FORMAT " at offset %"
|
||||
G_GUINT64_FORMAT, bs->pid, pts, offset);
|
||||
|
||||
if (G_UNLIKELY (GST_CLOCK_TIME_IS_VALID (stream->pts) &&
|
||||
ABSDIFF (stream->raw_pts, pts) > 900000)) {
|
||||
/* Detect rollover if diff > 10s */
|
||||
GST_LOG ("Detected rollover (previous:%" G_GUINT64_FORMAT " new:%"
|
||||
G_GUINT64_FORMAT ")", stream->raw_pts, pts);
|
||||
if (pts < stream->raw_pts) {
|
||||
/* Forward rollover */
|
||||
GST_LOG ("Forward rollover, incrementing nb_pts_rollover");
|
||||
stream->nb_pts_rollover++;
|
||||
} else {
|
||||
/* Reverse rollover */
|
||||
GST_LOG ("Reverse rollover, decrementing nb_pts_rollover");
|
||||
stream->nb_pts_rollover--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute PTS in GstClockTime */
|
||||
stream->raw_pts = pts;
|
||||
stream->fixed_pts = pts + stream->nb_pts_rollover * PTS_DTS_MAX_VALUE;
|
||||
stream->pts = MPEGTIME_TO_GSTTIME (stream->fixed_pts);
|
||||
|
||||
GST_LOG ("pid 0x%04x Stored PTS %" G_GUINT64_FORMAT " (%" GST_TIME_FORMAT ")",
|
||||
bs->pid, stream->raw_pts, GST_TIME_ARGS (stream->pts));
|
||||
stream->pts =
|
||||
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
||||
MPEGTIME_TO_GSTTIME (pts), demux->program->pcr_pid);
|
||||
|
||||
GST_LOG ("pid 0x%04x Stored PTS %" G_GUINT64_FORMAT, bs->pid, stream->pts);
|
||||
|
||||
if (G_UNLIKELY (demux->emit_statistics)) {
|
||||
GstStructure *st;
|
||||
|
@ -1241,32 +1202,15 @@ gst_ts_demux_record_dts (GstTSDemux * demux, TSDemuxStream * stream,
|
|||
return;
|
||||
}
|
||||
|
||||
GST_LOG ("pid 0x%04x dts:%" G_GUINT64_FORMAT " at offset %"
|
||||
GST_LOG ("pid 0x%04x raw dts:%" G_GUINT64_FORMAT " at offset %"
|
||||
G_GUINT64_FORMAT, bs->pid, dts, offset);
|
||||
|
||||
if (G_UNLIKELY (GST_CLOCK_TIME_IS_VALID (stream->dts) &&
|
||||
ABSDIFF (stream->raw_dts, dts) > 900000)) {
|
||||
/* Detect rollover if diff > 10s */
|
||||
GST_LOG ("Detected rollover (previous:%" G_GUINT64_FORMAT " new:%"
|
||||
G_GUINT64_FORMAT ")", stream->raw_dts, dts);
|
||||
if (dts < stream->raw_dts) {
|
||||
/* Forward rollover */
|
||||
GST_LOG ("Forward rollover, incrementing nb_dts_rollover");
|
||||
stream->nb_dts_rollover++;
|
||||
} else {
|
||||
/* Reverse rollover */
|
||||
GST_LOG ("Reverse rollover, decrementing nb_dts_rollover");
|
||||
stream->nb_dts_rollover--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute DTS in GstClockTime */
|
||||
stream->raw_dts = dts;
|
||||
stream->fixed_dts = dts + stream->nb_dts_rollover * PTS_DTS_MAX_VALUE;
|
||||
stream->dts = MPEGTIME_TO_GSTTIME (stream->fixed_dts);
|
||||
stream->dts =
|
||||
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
||||
MPEGTIME_TO_GSTTIME (dts), demux->program->pcr_pid);
|
||||
|
||||
GST_LOG ("pid 0x%04x Stored DTS %" G_GUINT64_FORMAT " (%" GST_TIME_FORMAT ")",
|
||||
bs->pid, stream->raw_dts, GST_TIME_ARGS (stream->dts));
|
||||
GST_LOG ("pid 0x%04x Stored DTS %" G_GUINT64_FORMAT, bs->pid, stream->dts);
|
||||
|
||||
if (G_UNLIKELY (demux->emit_statistics)) {
|
||||
GstStructure *st;
|
||||
|
@ -1466,9 +1410,7 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream)
|
|||
}
|
||||
}
|
||||
if (GST_CLOCK_TIME_IS_VALID (lowest_pts))
|
||||
firstts =
|
||||
mpegts_packetizer_pts_to_ts (base->packetizer, lowest_pts,
|
||||
demux->program->pcr_pid);
|
||||
firstts = lowest_pts;
|
||||
GST_DEBUG ("lowest_pts %" G_GUINT64_FORMAT " => clocktime %" GST_TIME_FORMAT,
|
||||
lowest_pts, GST_TIME_ARGS (firstts));
|
||||
|
||||
|
@ -1532,7 +1474,6 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream)
|
|||
GstFlowReturn res = GST_FLOW_OK;
|
||||
MpegTSBaseStream *bs = (MpegTSBaseStream *) stream;
|
||||
GstBuffer *buffer = NULL;
|
||||
MpegTSPacketizer2 *packetizer = MPEG_TS_BASE_PACKETIZER (demux);
|
||||
|
||||
GST_DEBUG_OBJECT (stream->pad,
|
||||
"stream:%p, pid:0x%04x stream_type:%d state:%d", stream, bs->pid,
|
||||
|
@ -1575,13 +1516,9 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream)
|
|||
GST_DEBUG_OBJECT (stream->pad, "stream->pts %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (stream->pts));
|
||||
if (GST_CLOCK_TIME_IS_VALID (stream->pts))
|
||||
GST_BUFFER_PTS (buffer) =
|
||||
mpegts_packetizer_pts_to_ts (packetizer, stream->pts,
|
||||
demux->program->pcr_pid);
|
||||
GST_BUFFER_PTS (buffer) = stream->pts;
|
||||
if (GST_CLOCK_TIME_IS_VALID (stream->dts))
|
||||
GST_BUFFER_DTS (buffer) =
|
||||
mpegts_packetizer_pts_to_ts (packetizer, stream->dts,
|
||||
demux->program->pcr_pid);
|
||||
GST_BUFFER_DTS (buffer) = stream->dts;
|
||||
|
||||
GST_DEBUG_OBJECT (stream->pad,
|
||||
"Pushing buffer with PTS: %" GST_TIME_FORMAT " , DTS: %" GST_TIME_FORMAT,
|
||||
|
|
Loading…
Reference in a new issue