summaryrefslogtreecommitdiff
path: root/gst/rist/gstrist.c
diff options
context:
space:
mode:
authorStéphane Cerveau <scerveau@collabora.com>2021-02-25 15:22:15 +0100
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-04-11 16:16:55 +0000
commit891be511057dbcdf1f38740e55cbd376c4b25894 (patch)
treeb077e8cd0b584ebe2a10950ef2398ab3f60b48b4 /gst/rist/gstrist.c
parent7f60138ef68e2a1fef8ccd4ff3710dfccd243314 (diff)
downloadgstreamer-plugins-bad-891be511057dbcdf1f38740e55cbd376c4b25894.tar.gz
gst-plugins: allow per feature registration
Split plugin into features including dynamic types which can be indiviually registered during a static build. More details here: https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/199 https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/661 Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2110>
Diffstat (limited to 'gst/rist/gstrist.c')
-rw-r--r--gst/rist/gstrist.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/gst/rist/gstrist.c b/gst/rist/gstrist.c
new file mode 100644
index 000000000..b393925c0
--- /dev/null
+++ b/gst/rist/gstrist.c
@@ -0,0 +1,93 @@
+/* GStreamer RIST plugin
+ * Copyright (C) 2019 Net Insight AB
+ * Author: Nicolas Dufresne <nicolas.dufresne@collabora.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstrist.h"
+#include "gstroundrobin.h"
+
+/*
+ * rtp_ext_seq:
+ * @extseq: (inout): a previous extended seqs
+ * @seq: a new seq
+ *
+ * Update the @extseq field with the extended seq of @seq
+ * For the first call of the method, @extseq should point to a location
+ * with a value of -1.
+ *
+ * This function is able to handle both forward and backward seqs taking
+ * into account:
+ * - seq wraparound making sure that the returned value is properly increased.
+ * - seq unwraparound making sure that the returned value is properly decreased.
+ *
+ * Returns: The extended seq of @seq or 0 if the result can't go anywhere backwards.
+ *
+ * NOTE: This is a calque of gst_rtp_buffer_ext_timestamp() but with
+ * s/32/16/ and s/64/32/ and s/0xffffffff/0xffff/ and s/timestamp/seqnum/.
+ */
+guint32
+gst_rist_rtp_ext_seq (guint32 * extseqnum, guint16 seqnum)
+{
+ guint32 result, ext;
+
+ g_return_val_if_fail (extseqnum != NULL, -1);
+
+ ext = *extseqnum;
+
+ if (ext == -1) {
+ result = seqnum;
+ } else {
+ /* pick wraparound counter from previous seqnum and add to new seqnum */
+ result = seqnum + (ext & ~(0xffff));
+
+ /* check for seqnum wraparound */
+ if (result < ext) {
+ guint32 diff = ext - result;
+
+ if (diff > G_MAXINT16) {
+ /* seqnum went backwards more than allowed, we wrap around and get
+ * updated extended seqnum. */
+ result += (1 << 16);
+ }
+ } else {
+ guint32 diff = result - ext;
+
+ if (diff > G_MAXINT16) {
+ if (result < (1 << 16)) {
+ GST_WARNING
+ ("Cannot unwrap, any wrapping took place yet. Returning 0 without updating extended seqnum.");
+ return 0;
+ } else {
+ /* seqnum went forwards more than allowed, we unwrap around and get
+ * updated extended seqnum. */
+ result -= (1 << 16);
+ /* We don't want the extended seqnum storage to go back, ever */
+ return result;
+ }
+ }
+ }
+ }
+
+ *extseqnum = result;
+
+ return result;
+}