mpegtsbase: Search SCTE-35 DRF_ID_CUEI in multiple registration descriptors
authorVivia Nikolaidou <vivia@ahiru.eu>
Tue, 31 Aug 2021 13:35:06 +0000 (16:35 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 18 Oct 2021 13:58:39 +0000 (13:58 +0000)
There are streams in the wild that have to add a SCTE-35 trigger in
another e.g. GA94 stream. Most encoders would replace the GA94
descriptor ID with the CUEI one temporarily, but there are some that
will add two registration ID descriptors, one with GA94 and one with
CUEI.

Failing to parse the CUEI registration ID in that case would return
FALSE in _stream_is_private_section , therefore setting it as known PES
and pushing packets downstream instead of calling handle_psi.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/979>

subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtsbase.c

index e5f1415..0658f0e 100644 (file)
@@ -575,6 +575,28 @@ get_registration_from_descriptors (GPtrArray * descriptors)
   return 0;
 }
 
+static gboolean
+find_registration_in_descriptors (GPtrArray * descriptors,
+    guint32 registration_id)
+{
+
+  guint i, nb_desc;
+
+  if (!descriptors)
+    return FALSE;
+
+  nb_desc = descriptors->len;
+  for (i = 0; i < nb_desc; i++) {
+    GstMpegtsDescriptor *desc = g_ptr_array_index (descriptors, i);
+    if (desc->tag == GST_MTS_DESC_REGISTRATION) {
+      guint32 reg_desc = GST_READ_UINT32_BE (desc->data + 2);
+      if (reg_desc == registration_id)
+        return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 static MpegTSBaseStream *
 mpegts_base_program_add_stream (MpegTSBase * base,
     MpegTSBaseProgram * program, guint16 pid, guint8 stream_type,
@@ -763,10 +785,8 @@ _stream_is_private_section (const GstMpegtsPMT * pmt,
       return TRUE;
     case GST_MPEGTS_STREAM_TYPE_SCTE_SIT:
     {
-      guint32 registration_id =
-          get_registration_from_descriptors (pmt->descriptors);
       /* Not a private section stream */
-      if (registration_id != DRF_ID_CUEI)
+      if (!find_registration_in_descriptors (pmt->descriptors, DRF_ID_CUEI))
         return FALSE;
       return TRUE;
     }