tsdemux: Handle invalid PCR_PID streams
authorGilbok Lee <gilbok.lee@samsung.com>
Fri, 12 Nov 2021 03:38:50 +0000 (12:38 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Fri, 12 Nov 2021 09:14:58 +0000 (18:14 +0900)
- 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
gst/mpegtsdemux/mpegtspacketizer.h
gst/mpegtsdemux/tsdemux.c
packaging/gst-plugins-bad.spec

index 9332934..ddb6093 100644 (file)
@@ -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
index c86ef6b..cbe008e 100644 (file)
@@ -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 */
index 8aa6d03..34c2b3b 100644 (file)
@@ -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");
index cb280f5..9c3b1fc 100644 (file)
@@ -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\