mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
tsdemux: Unify duration querying code
And properly use it in the SEEKING query. Fixes seeking with gst-play
This commit is contained in:
parent
89e2a5fe75
commit
b80ae9cdcd
1 changed files with 31 additions and 16 deletions
|
@ -454,6 +454,25 @@ gst_ts_demux_get_property (GObject * object, guint prop_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_ts_demux_get_duration (GstTSDemux * demux, GstClockTime * dur)
|
||||||
|
{
|
||||||
|
MpegTSBase *base = (MpegTSBase *) demux;
|
||||||
|
gboolean res = FALSE;
|
||||||
|
gint64 val;
|
||||||
|
|
||||||
|
/* Get total size in bytes */
|
||||||
|
if (gst_pad_peer_query_duration (base->sinkpad, GST_FORMAT_BYTES, &val)) {
|
||||||
|
/* Convert it to duration */
|
||||||
|
*dur =
|
||||||
|
mpegts_packetizer_offset_to_ts (base->packetizer, val,
|
||||||
|
demux->program->pcr_pid);
|
||||||
|
if (GST_CLOCK_TIME_IS_VALID (*dur))
|
||||||
|
res = TRUE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||||
{
|
{
|
||||||
|
@ -472,20 +491,11 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||||
gst_query_parse_duration (query, &format, NULL);
|
gst_query_parse_duration (query, &format, NULL);
|
||||||
if (format == GST_FORMAT_TIME) {
|
if (format == GST_FORMAT_TIME) {
|
||||||
if (!gst_pad_peer_query (base->sinkpad, query)) {
|
if (!gst_pad_peer_query (base->sinkpad, query)) {
|
||||||
gint64 val;
|
GstClockTime dur;
|
||||||
|
if (gst_ts_demux_get_duration (demux, &dur))
|
||||||
format = GST_FORMAT_BYTES;
|
gst_query_set_duration (query, GST_FORMAT_TIME, dur);
|
||||||
if (!gst_pad_peer_query_duration (base->sinkpad, format, &val))
|
else
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
else {
|
|
||||||
GstClockTime dur =
|
|
||||||
mpegts_packetizer_offset_to_ts (base->packetizer, val,
|
|
||||||
demux->program->pcr_pid);
|
|
||||||
if (GST_CLOCK_TIME_IS_VALID (dur))
|
|
||||||
gst_query_set_duration (query, GST_FORMAT_TIME, dur);
|
|
||||||
else
|
|
||||||
res = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (demux, "only query duration on TIME is supported");
|
GST_DEBUG_OBJECT (demux, "only query duration on TIME is supported");
|
||||||
|
@ -521,6 +531,7 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||||
{
|
{
|
||||||
GST_DEBUG ("query seeking");
|
GST_DEBUG ("query seeking");
|
||||||
gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
|
gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
|
||||||
|
GST_DEBUG ("asked for format %s", gst_format_get_name (format));
|
||||||
if (format == GST_FORMAT_TIME) {
|
if (format == GST_FORMAT_TIME) {
|
||||||
gboolean seekable = FALSE;
|
gboolean seekable = FALSE;
|
||||||
|
|
||||||
|
@ -529,9 +540,13 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||||
|
|
||||||
/* If upstream is not seekable in TIME format we use
|
/* If upstream is not seekable in TIME format we use
|
||||||
* our own values here */
|
* our own values here */
|
||||||
if (!seekable)
|
if (!seekable) {
|
||||||
gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0,
|
GstClockTime dur;
|
||||||
demux->segment.duration);
|
if (gst_ts_demux_get_duration (demux, &dur)) {
|
||||||
|
gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0, dur);
|
||||||
|
GST_DEBUG ("Gave duration: %" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (demux, "only TIME is supported for query seeking");
|
GST_DEBUG_OBJECT (demux, "only TIME is supported for query seeking");
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
|
|
Loading…
Reference in a new issue