rtpmanager: Move some duplicated constant and helper function to a single place
authorSebastian Dröge <sebastian@centricular.com>
Wed, 20 Apr 2022 07:53:16 +0000 (10:53 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 20 Apr 2022 14:40:25 +0000 (14:40 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2132>

subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtpfunnel.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtpsession.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.c [new file with mode: 0644]
subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.h [new file with mode: 0644]
subprojects/gst-plugins-good/gst/rtpmanager/meson.build
subprojects/gst-plugins-good/gst/rtpmanager/rtpsession.c
subprojects/gst-plugins-good/gst/rtpmanager/rtptwcc.c

index b139f44..c7ab439 100644 (file)
 #include "rtpsession.h"
 #include "gstrtpsession.h"
 #include "gstrtpjitterbuffer.h"
+#include "gstrtputils.h"
 
 #include <gst/glib-compat-private.h>
 
@@ -1298,7 +1299,7 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time,
     if (bin->use_pipeline_clock) {
       ntpns = rt;
       /* add constant to convert from 1970 based time to 1900 based time */
-      ntpns += (2208988800LL * GST_SECOND);
+      ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
     } else {
       switch (bin->ntp_time_source) {
         case GST_RTP_NTP_TIME_SOURCE_NTP:
@@ -1308,7 +1309,7 @@ get_current_times (GstRtpBin * bin, GstClockTime * running_time,
 
           /* add constant to convert from 1970 based time to 1900 based time */
           if (bin->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
-            ntpns += (2208988800LL * GST_SECOND);
+            ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
           break;
         }
         case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
index 443ea87..841b55b 100644 (file)
@@ -70,6 +70,7 @@
 #include <gst/rtp/gstrtphdrext.h>
 
 #include "gstrtpfunnel.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY_STATIC (gst_rtp_funnel_debug);
 #define GST_CAT_DEFAULT gst_rtp_funnel_debug
@@ -327,29 +328,6 @@ gst_rtp_funnel_set_twcc_ext_id (GstRtpFunnel * funnel, guint8 twcc_ext_id)
   gst_rtp_header_extension_set_id (funnel->twcc_ext, twcc_ext_id);
 }
 
-static guint8
-_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
-{
-  guint i;
-  guint8 extmap_id = 0;
-  guint n_fields = gst_structure_n_fields (s);
-
-  for (i = 0; i < n_fields; i++) {
-    const gchar *field_name = gst_structure_nth_field_name (s, i);
-    if (g_str_has_prefix (field_name, "extmap-")) {
-      const gchar *str = gst_structure_get_string (s, field_name);
-      if (str && g_strcmp0 (str, ext_name) == 0) {
-        gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
-        if (id > 0 && id < 15) {
-          extmap_id = id;
-          break;
-        }
-      }
-    }
-  }
-  return extmap_id;
-}
-
 #define TWCC_EXTMAP_STR "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
 
 static gboolean
@@ -398,7 +376,7 @@ gst_rtp_funnel_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
         funnel->twcc_ext =
             gst_rtp_header_extension_create_from_uri (TWCC_EXTMAP_STR);
 
-      ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
+      ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
       if (ext_id > 0) {
         fpad->has_twcc = TRUE;
         funnel->twcc_pads++;
index 0a090e4..3ba70c8 100644 (file)
 #include "rtpjitterbuffer.h"
 #include "rtpstats.h"
 #include "rtptimerqueue.h"
+#include "gstrtputils.h"
 
 #include <gst/glib-compat-private.h>
 
@@ -1494,29 +1495,6 @@ _get_cname_ssrc_mappings (GstRtpJitterBuffer * jitterbuffer,
   }
 }
 
-static guint8
-_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
-{
-  guint i;
-  guint8 extmap_id = 0;
-  guint n_fields = gst_structure_n_fields (s);
-
-  for (i = 0; i < n_fields; i++) {
-    const gchar *field_name = gst_structure_nth_field_name (s, i);
-    if (g_str_has_prefix (field_name, "extmap-")) {
-      const gchar *str = gst_structure_get_string (s, field_name);
-      if (str && g_strcmp0 (str, ext_name) == 0) {
-        gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
-        if (id > 0 && id < 15) {
-          extmap_id = id;
-          break;
-        }
-      }
-    }
-  }
-  return extmap_id;
-}
-
 /*
  * Must be called with JBUF_LOCK held
  */
@@ -1692,7 +1670,7 @@ gst_jitter_buffer_sink_parse_caps (GstRtpJitterBuffer * jitterbuffer,
 
   _get_cname_ssrc_mappings (jitterbuffer, caps_struct);
   priv->ntp64_ext_id =
-      _get_extmap_id_for_attribute (caps_struct,
+      gst_rtp_get_extmap_id_for_attribute (caps_struct,
       GST_RTP_HDREXT_BASE GST_RTP_HDREXT_NTP_64);
 
   return TRUE;
index 2ec5907..fde6eee 100644 (file)
 
 #include "gstrtpsession.h"
 #include "rtpsession.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY_STATIC (gst_rtp_session_debug);
 #define GST_CAT_DEFAULT gst_rtp_session_debug
@@ -1101,7 +1102,7 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
     if (rtpsession->priv->use_pipeline_clock) {
       ntpns = rt;
       /* add constant to convert from 1970 based time to 1900 based time */
-      ntpns += (2208988800LL * GST_SECOND);
+      ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
     } else {
       switch (rtpsession->priv->ntp_time_source) {
         case GST_RTP_NTP_TIME_SOURCE_NTP:
@@ -1111,7 +1112,7 @@ get_current_times (GstRtpSession * rtpsession, GstClockTime * running_time,
 
           /* add constant to convert from 1970 based time to 1900 based time */
           if (rtpsession->priv->ntp_time_source == GST_RTP_NTP_TIME_SOURCE_NTP)
-            ntpns += (2208988800LL * GST_SECOND);
+            ntpns += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
           break;
         }
         case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
@@ -2458,7 +2459,7 @@ gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
     if (rtpsession->priv->use_pipeline_clock) {
       ntpnstime = running_time;
       /* add constant to convert from 1970 based time to 1900 based time */
-      ntpnstime += (2208988800LL * GST_SECOND);
+      ntpnstime += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
     } else {
       switch (rtpsession->priv->ntp_time_source) {
         case GST_RTP_NTP_TIME_SOURCE_NTP:
@@ -2494,7 +2495,7 @@ gst_rtp_session_chain_send_rtp_common (GstRtpSession * rtpsession,
           if (ntpnstime != GST_CLOCK_TIME_NONE
               && rtpsession->priv->ntp_time_source ==
               GST_RTP_NTP_TIME_SOURCE_NTP)
-            ntpnstime += (2208988800LL * GST_SECOND);
+            ntpnstime += (GST_RTP_NTP_UNIX_OFFSET * GST_SECOND);
           break;
         }
         case GST_RTP_NTP_TIME_SOURCE_RUNNING_TIME:
diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.c b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.c
new file mode 100644 (file)
index 0000000..eb81133
--- /dev/null
@@ -0,0 +1,44 @@
+/* GStreamer
+ * Copyright (C) 2022 Sebastian Dröge <sebastian@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gstrtputils.h"
+
+guint8
+gst_rtp_get_extmap_id_for_attribute (const GstStructure * s,
+    const gchar * ext_name)
+{
+  guint i;
+  guint8 extmap_id = 0;
+  guint n_fields = gst_structure_n_fields (s);
+
+  for (i = 0; i < n_fields; i++) {
+    const gchar *field_name = gst_structure_nth_field_name (s, i);
+    if (g_str_has_prefix (field_name, "extmap-")) {
+      const gchar *str = gst_structure_get_string (s, field_name);
+      if (str && g_strcmp0 (str, ext_name) == 0) {
+        gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
+        if (id > 0 && id < 15) {
+          extmap_id = id;
+          break;
+        }
+      }
+    }
+  }
+  return extmap_id;
+}
diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.h b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtputils.h
new file mode 100644 (file)
index 0000000..6689333
--- /dev/null
@@ -0,0 +1,34 @@
+/* GStreamer
+ * Copyright (C) 2022 Sebastian Dröge <sebastian@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GST_RTP_UTILS_H__
+#define __GST_RTP_UTILS_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define GST_RTP_NTP_UNIX_OFFSET (2208988800LL)
+
+G_GNUC_INTERNAL guint8
+gst_rtp_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name);
+
+G_END_DECLS
+
+#endif /* __GST_RTP_UTILS_H__ */
index bbd2b4f..6c8ccf2 100644 (file)
@@ -24,7 +24,8 @@ rtpmanager_sources = [
   'gstrtpsession.c',
   'gstrtpfunnel.c',
   'gstrtpst2022-1-fecdec.c',
-  'gstrtpst2022-1-fecenc.c'
+  'gstrtpst2022-1-fecenc.c',
+  'gstrtputils.c'
 ]
 
 gstrtpmanager = library('gstrtpmanager',
index a4cbaed..e5c8488 100644 (file)
@@ -30,6 +30,7 @@
 #include <gst/glib-compat-private.h>
 
 #include "rtpsession.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY (rtp_session_debug);
 #define GST_CAT_DEFAULT rtp_session_debug
@@ -3177,29 +3178,6 @@ invalid_packet:
   }
 }
 
-static guint8
-_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
-{
-  guint i;
-  guint8 extmap_id = 0;
-  guint n_fields = gst_structure_n_fields (s);
-
-  for (i = 0; i < n_fields; i++) {
-    const gchar *field_name = gst_structure_nth_field_name (s, i);
-    if (g_str_has_prefix (field_name, "extmap-")) {
-      const gchar *str = gst_structure_get_string (s, field_name);
-      if (str && g_strcmp0 (str, ext_name) == 0) {
-        gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
-        if (id > 0 && id < 15) {
-          extmap_id = id;
-          break;
-        }
-      }
-    }
-  }
-  return extmap_id;
-}
-
 /**
  * rtp_session_update_send_caps:
  * @sess: an #RTPSession
@@ -3256,7 +3234,7 @@ rtp_session_update_send_caps (RTPSession * sess, GstCaps * caps)
   }
 
   sess->send_ntp64_ext_id =
-      _get_extmap_id_for_attribute (s,
+      gst_rtp_get_extmap_id_for_attribute (s,
       GST_RTP_HDREXT_BASE GST_RTP_HDREXT_NTP_64);
 
   rtp_twcc_manager_parse_send_ext_id (sess->twcc, s);
index edbbfc2..e96c56b 100644 (file)
@@ -22,6 +22,8 @@
 #include <gst/base/gstbitreader.h>
 #include <gst/base/gstbitwriter.h>
 
+#include "gstrtputils.h"
+
 GST_DEBUG_CATEGORY_EXTERN (rtp_session_debug);
 #define GST_CAT_DEFAULT rtp_session_debug
 
@@ -166,34 +168,11 @@ recv_packet_init (RecvPacket * packet, guint16 seqnum, RTPPacketInfo * pinfo)
     packet->ts = pinfo->current_time;
 }
 
-static guint8
-_get_extmap_id_for_attribute (const GstStructure * s, const gchar * ext_name)
-{
-  guint i;
-  guint8 extmap_id = 0;
-  guint n_fields = gst_structure_n_fields (s);
-
-  for (i = 0; i < n_fields; i++) {
-    const gchar *field_name = gst_structure_nth_field_name (s, i);
-    if (g_str_has_prefix (field_name, "extmap-")) {
-      const gchar *str = gst_structure_get_string (s, field_name);
-      if (str && g_strcmp0 (str, ext_name) == 0) {
-        gint64 id = g_ascii_strtoll (field_name + 7, NULL, 10);
-        if (id > 0 && id < 15) {
-          extmap_id = id;
-          break;
-        }
-      }
-    }
-  }
-  return extmap_id;
-}
-
 void
 rtp_twcc_manager_parse_recv_ext_id (RTPTWCCManager * twcc,
     const GstStructure * s)
 {
-  guint8 recv_ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
+  guint8 recv_ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
   if (recv_ext_id > 0) {
     twcc->recv_ext_id = recv_ext_id;
     GST_INFO ("TWCC enabled for recv using extension id: %u",
@@ -205,7 +184,7 @@ void
 rtp_twcc_manager_parse_send_ext_id (RTPTWCCManager * twcc,
     const GstStructure * s)
 {
-  guint8 send_ext_id = _get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
+  guint8 send_ext_id = gst_rtp_get_extmap_id_for_attribute (s, TWCC_EXTMAP_STR);
   if (send_ext_id > 0) {
     twcc->send_ext_id = send_ext_id;
     GST_INFO ("TWCC enabled for send using extension id: %u",