From e28a6ae9b7e52fa5d75eab5a6487aa21edc3d668 Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Fri, 12 Nov 2021 12:38:50 +0900 Subject: [PATCH] tsdemux: Handle invalid PCR_PID streams - If pcr_pid stream does not have PCR, find PCR in all streams and update the program PCR_pid Change-Id: I53c7fcfc8c405eb9ff162d52000d56d7e9cf3bfb --- gst/mpegtsdemux/mpegtspacketizer.c | 19 +++++++++++++++++++ gst/mpegtsdemux/mpegtspacketizer.h | 5 +++++ gst/mpegtsdemux/tsdemux.c | 26 +++++++++++++++++++++++++- packaging/gst-plugins-bad.spec | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/gst/mpegtsdemux/mpegtspacketizer.c b/gst/mpegtsdemux/mpegtspacketizer.c index 9332934..ddb6093 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.c +++ b/gst/mpegtsdemux/mpegtspacketizer.c @@ -2589,3 +2589,22 @@ mpegts_packetizer_set_current_pcr_offset (MpegTSPacketizer2 * packetizer, } PACKETIZER_GROUP_UNLOCK (packetizer); } + +#ifdef TIZEN_FEATURE_TSDEMUX_INVALID_PCR_PID +GstClockTime +mpegts_packetizer_get_pcr_base_time (MpegTSPacketizer2 * packetizer, + guint16 pcr_pid) +{ + GstClockTime res = GST_CLOCK_TIME_NONE; + MpegTSPCR *pcrtable; + + PACKETIZER_GROUP_LOCK (packetizer); + pcrtable = get_pcr_table (packetizer, pcr_pid); + + if (GST_CLOCK_TIME_IS_VALID (pcrtable->base_time) && (pcr_pid != 0x1fff)) + res = pcrtable->base_time; + + PACKETIZER_GROUP_UNLOCK (packetizer); + return res; +} +#endif diff --git a/gst/mpegtsdemux/mpegtspacketizer.h b/gst/mpegtsdemux/mpegtspacketizer.h index c86ef6b..cbe008e 100644 --- a/gst/mpegtsdemux/mpegtspacketizer.h +++ b/gst/mpegtsdemux/mpegtspacketizer.h @@ -381,6 +381,11 @@ mpegts_packetizer_set_reference_offset (MpegTSPacketizer2 * packetizer, G_GNUC_INTERNAL void mpegts_packetizer_set_pcr_discont_threshold (MpegTSPacketizer2 * packetizer, GstClockTime threshold); +#ifdef TIZEN_FEATURE_TSDEMUX_INVALID_PCR_PID +G_GNUC_INTERNAL GstClockTime +mpegts_packetizer_get_pcr_base_time (MpegTSPacketizer2 * packetizer, + guint16 pcr_pid); +#endif G_END_DECLS #endif /* GST_MPEGTS_PACKETIZER_H */ diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index 8aa6d03..34c2b3b 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -2478,6 +2478,9 @@ check_pending_buffers (GstTSDemux * demux) guint64 offset = 0; GList *tmp; gboolean have_only_sparse = TRUE; +#ifdef TIZEN_FEATURE_TSDEMUX_INVALID_PCR_PID + gboolean wrong_pcr_pid = FALSE; +#endif /* 0. Do we only have sparse stream */ for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) { @@ -2503,8 +2506,30 @@ check_pending_buffers (GstTSDemux * demux) } /* 2. If we don't have a valid value yet, break out */ +#ifdef TIZEN_FEATURE_TSDEMUX_INVALID_PCR_PID + if (have_observation == FALSE) { + /* Checking PCR other pid */ + for (int i = 0; i < demux->program->pmt->streams->len; ++i) { + GstMpegtsPMTStream *pmt_stream = + g_ptr_array_index (demux->program->pmt->streams, i); + if (pmt_stream->pid == demux->program->pcr_pid) + continue; + if (GST_CLOCK_TIME_IS_VALID (mpegts_packetizer_get_pcr_base_time + (MPEG_TS_BASE_PACKETIZER (demux), pmt_stream->pid))) { + GST_WARNING ("PCR_PID will update %x -> %x", demux->program->pcr_pid, + pmt_stream->pid); + demux->program->pcr_pid = pmt_stream->pid; + wrong_pcr_pid = TRUE; + break; + } + } + if (!wrong_pcr_pid) + return FALSE; + } +#else if (have_observation == FALSE) return FALSE; +#endif /* 3. Go over all streams that have current/pending data */ for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) { @@ -2861,7 +2886,6 @@ push_new_segment: gst_pad_push_event (stream->pad, gst_event_new_tag (gst_tag_list_ref (demux->global_tags))); } - #ifdef TIZEN_FEATURE_TSDEMUX_LANG_TAG if (demux->pending_custom_event) { GST_DEBUG_OBJECT (stream->pad, "Pushing custom event"); diff --git a/packaging/gst-plugins-bad.spec b/packaging/gst-plugins-bad.spec index cb280f5..9c3b1fc 100644 --- a/packaging/gst-plugins-bad.spec +++ b/packaging/gst-plugins-bad.spec @@ -82,6 +82,7 @@ export CFLAGS+=" -Wall -g -fPIC\ -DTIZEN_FEATURE_ADAPTIVE_MODIFICATION\ -DTIZEN_FEATURE_HLSDEMUX_PROPERTY\ -DTIZEN_FEATURE_TSDEMUX_MODIFICATION\ + -DTIZEN_FEATURE_TSDEMUX_WRONG_PCR_PID\ -DTIZEN_FEATURE_TSDEMUX_LANG_TAG\ -DTIZEN_FEATURE_HLS_WEBVTT\ -DTIZEN_FEATURE_OALSINK_MODIFICATION\ -- 2.7.4