mpegpsdemux: fix accurate seek

In an accurate seek, the segment start should be
the same as the one requested in the seek.
The start should be kept as the one from the
segment if its inferior.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2048>
This commit is contained in:
Stéphane Cerveau 2021-03-03 16:03:07 +01:00
parent 497e88ae88
commit 176a00985a
2 changed files with 7 additions and 25 deletions

View file

@ -393,7 +393,6 @@ gst_ps_demux_reset (GstPsDemux * demux)
demux->next_pts = G_MAXUINT64;
demux->next_dts = G_MAXUINT64;
demux->need_no_more_pads = TRUE;
demux->adjust_segment = TRUE;
gst_ps_demux_reset_psm (demux);
gst_segment_init (&demux->sink_segment, GST_FORMAT_UNDEFINED);
gst_segment_init (&demux->src_segment, GST_FORMAT_TIME);
@ -654,20 +653,6 @@ gst_ps_demux_send_segment (GstPsDemux * demux, GstPsStream * stream,
GST_TIME_ARGS (demux->src_segment.start),
GST_TIME_ARGS (demux->src_segment.stop));
/* adjust segment start if estimating a seek was off quite a bit,
* make sure to do for all streams though to preserve a/v sync */
/* FIXME such adjustment tends to be frowned upon */
if (pts != GST_CLOCK_TIME_NONE && demux->adjust_segment) {
if (demux->src_segment.rate > 0) {
if (GST_CLOCK_DIFF (demux->src_segment.start, pts) > GST_SECOND)
demux->src_segment.start = pts - demux->base_time;
} else {
if (GST_CLOCK_DIFF (demux->src_segment.stop, pts) > GST_SECOND)
demux->src_segment.stop = pts - demux->base_time;
}
}
demux->adjust_segment = FALSE;
/* we should be in sync with downstream, so start from our segment notion,
* which also includes proper base_time etc, tweak it a bit and send */
gst_segment_copy_into (&demux->src_segment, &segment);
@ -790,7 +775,6 @@ gst_ps_demux_mark_discont (GstPsDemux * demux, gboolean discont,
if (G_LIKELY (stream)) {
stream->discont |= discont;
stream->need_segment |= need_segment;
demux->adjust_segment |= need_segment;
if (need_segment)
demux->segment_seqnum = 0;
GST_DEBUG_OBJECT (demux, "marked stream as discont %d, need_segment %d",
@ -1092,8 +1076,6 @@ gst_ps_demux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
/* we expect our timeline (SCR, PTS) to match the one from upstream,
* if not, will adjust with offset later on */
gst_segment_copy_into (segment, &demux->src_segment);
/* accept upstream segment without adjusting */
demux->adjust_segment = FALSE;
}
gst_event_unref (event);
@ -1297,7 +1279,7 @@ gst_ps_demux_handle_seek_pull (GstPsDemux * demux, GstEvent * event)
GstSeekType start_type, stop_type;
gint64 start, stop;
gdouble rate;
gboolean update, flush;
gboolean update, flush, accurate;
GstSegment seeksegment;
GstClockTime first_pts = MPEGTIME_TO_GSTTIME (demux->first_pts);
guint32 seek_seqnum = gst_event_get_seqnum (event);
@ -1316,6 +1298,7 @@ gst_ps_demux_handle_seek_pull (GstPsDemux * demux, GstEvent * event)
goto no_scr_rate;
flush = flags & GST_SEEK_FLAG_FLUSH;
accurate = flags & GST_SEEK_FLAG_ACCURATE;
/* keyframe = flags & GST_SEEK_FLAG_KEY_UNIT; *//* FIXME */
@ -1363,11 +1346,11 @@ gst_ps_demux_handle_seek_pull (GstPsDemux * demux, GstEvent * event)
}
/* check the limits */
if (seeksegment.rate > 0.0 && first_pts != G_MAXUINT64) {
if (seeksegment.start < first_pts - demux->base_time) {
seeksegment.start = first_pts - demux->base_time;
seeksegment.position = seeksegment.start;
}
if (seeksegment.rate > 0.0 && first_pts != G_MAXUINT64
&& seeksegment.start < first_pts - demux->base_time) {
seeksegment.position = first_pts - demux->base_time;
if (!accurate)
seeksegment.start = seeksegment.position;
}
/* update the rate in our src segment */

View file

@ -141,7 +141,6 @@ struct _GstPsDemux
GstSegment sink_segment;
GstSegment src_segment;
gboolean adjust_segment;
guint32 segment_seqnum;
/* stream output */