gstbuffer: factor three flags-to-string loops
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 7 Apr 2014 13:49:59 +0000 (14:49 +0100)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Wed, 4 Jun 2014 11:30:36 +0000 (12:30 +0100)
plugins/elements/Makefile.am
plugins/elements/gstelements_private.c [new file with mode: 0644]
plugins/elements/gstelements_private.h [new file with mode: 0644]
plugins/elements/gstfakesink.c
plugins/elements/gstfakesrc.c
plugins/elements/gstidentity.c

index 164c4a9..3821b3c 100644 (file)
@@ -6,6 +6,7 @@ libgstcoreelements_la_SOURCES = \
        gstcapsfilter.c         \
        gstdownloadbuffer.c     \
        gstelements.c           \
+       gstelements_private.c   \
        gstfakesrc.c            \
        gstfakesink.c           \
        gstfdsrc.c              \
@@ -34,6 +35,7 @@ libgstcoreelements_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
 noinst_HEADERS =               \
        gstcapsfilter.h         \
        gstdownloadbuffer.h     \
+       gstelements_private.h   \
        gstfakesink.h           \
        gstfakesrc.h            \
        gstfdsrc.h              \
diff --git a/plugins/elements/gstelements_private.c b/plugins/elements/gstelements_private.c
new file mode 100644 (file)
index 0000000..6c304b4
--- /dev/null
@@ -0,0 +1,70 @@
+/* GStreamer
+ * Copyright (C) 2014 Vincent Penquerc'h <vincent@collabora.co.uk>
+ *
+ * gstelements_private.c: Shared code for core elements
+ *
+ * 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 <string.h>
+#include "gst/gst.h"
+#include "gstelements_private.h"
+
+/**
+ * gst_buffer_get_flags_string:
+ * @buffer: a #GstBuffer
+ * Returns: A newly allocated string
+ *
+ * Returns a newly allocated string describing the flags on this buffer.
+ * The string must be freed using g_free() when done.
+ *
+ * Since: 1.4
+ */
+
+char *
+gst_buffer_get_flags_string (GstBuffer * buffer)
+{
+  static const char *const flag_list[] = {
+    "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
+    "marker", "header", "gap", "droppable", "delta-unit", "tag-memory",
+    "FIXME"
+  };
+  int i, max_bytes;
+  char *flag_str, *end;
+
+  max_bytes = 1;                /* NUL */
+  for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
+    max_bytes += strlen (flag_list[i]) + 1;     /* string and space */
+  }
+  flag_str = g_malloc (max_bytes);
+
+  end = flag_str;
+  end[0] = '\0';
+  for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
+    if (GST_MINI_OBJECT_CAST (buffer)->flags & (1 << i)) {
+      strcpy (end, flag_list[i]);
+      end += strlen (end);
+      end[0] = ' ';
+      end[1] = '\0';
+      end++;
+    }
+  }
+
+  return flag_str;
+}
diff --git a/plugins/elements/gstelements_private.h b/plugins/elements/gstelements_private.h
new file mode 100644 (file)
index 0000000..9ccae1b
--- /dev/null
@@ -0,0 +1,35 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000 Wim Taymans <wtay@chello.be>
+ *
+ * gst_private.h: Private header for within libgst
+ *
+ * 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_ELEMENTS_PRIVATE_H__
+#define __GST_ELEMENTS_PRIVATE_H__
+
+#include "gst/gst.h"
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+char *    gst_buffer_get_flags_string                   (GstBuffer *buffer);
+
+G_END_DECLS
+
+#endif /* __GST_ELEMENTS_PRIVATE_H__ */
index b2f5276..dde0fce 100644 (file)
@@ -37,6 +37,7 @@
 #  include "config.h"
 #endif
 
+#include "gstelements_private.h"
 #include "gstfakesink.h"
 #include <string.h>
 
@@ -428,7 +429,7 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
 
   if (!sink->silent) {
     gchar dts_str[64], pts_str[64], dur_str[64];
-    gchar flag_str[100];
+    gchar *flag_str;
 
     GST_OBJECT_LOCK (sink);
     g_free (sink->last_message);
@@ -454,25 +455,7 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
       g_strlcpy (dur_str, "none", sizeof (dur_str));
     }
 
-    {
-      const char *flag_list[] = {
-        "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
-        "marker", "header", "gap", "droppable", "delta-unit", "tag-memory",
-        "FIXME"
-      };
-      int i;
-      char *end = flag_str;
-      end[0] = '\0';
-      for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
-        if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
-          strcpy (end, flag_list[i]);
-          end += strlen (end);
-          end[0] = ' ';
-          end[1] = '\0';
-          end++;
-        }
-      }
-    }
+    flag_str = gst_buffer_get_flags_string (buf);
 
     sink->last_message =
         g_strdup_printf ("chain   ******* (%s:%s) (%u bytes, dts: %s, pts: %s"
@@ -482,6 +465,7 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
         (guint) gst_buffer_get_size (buf), dts_str, pts_str,
         dur_str, GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
         GST_MINI_OBJECT_CAST (buf)->flags, flag_str, buf);
+    g_free (flag_str);
     GST_OBJECT_UNLOCK (sink);
 
     gst_fake_sink_notify_last_message (sink);
index 0c7e32c..7b03cf5 100644 (file)
@@ -49,6 +49,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "gstelements_private.h"
 #include "gstfakesrc.h"
 
 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
@@ -804,7 +805,7 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length,
 
   if (!src->silent) {
     gchar dts_str[64], pts_str[64], dur_str[64];
-    gchar flag_str[100];
+    gchar *flag_str;
 
     GST_OBJECT_LOCK (src);
     g_free (src->last_message);
@@ -828,26 +829,7 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length,
       g_strlcpy (dur_str, "none", sizeof (dur_str));
     }
 
-    {
-      const char *flag_list[] = {
-        "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
-        "marker", "header", "gap", "droppable", "delta-unit", "tag-memory",
-        "FIXME"
-      };
-      int i;
-      char *end = flag_str;
-      end[0] = '\0';
-      for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
-        if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
-          strcpy (end, flag_list[i]);
-          end += strlen (end);
-          end[0] = ' ';
-          end[1] = '\0';
-          end++;
-        }
-      }
-    }
-
+    flag_str = gst_buffer_get_flags_string (buf);
     src->last_message =
         g_strdup_printf ("create   ******* (%s:%s) (%u bytes, dts: %s, pts:%s"
         ", duration: %s, offset: %" G_GINT64_FORMAT ", offset_end: %"
@@ -856,6 +838,7 @@ gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length,
         dts_str, pts_str, dur_str, GST_BUFFER_OFFSET (buf),
         GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT_CAST (buf)->flags,
         flag_str, buf);
+    g_free (flag_str);
     GST_OBJECT_UNLOCK (src);
 
     g_object_notify_by_pspec ((GObject *) src, pspec_last_message);
index 114a290..4151dad 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "gstelements_private.h"
 #include "../../gst/gst-i18n-lib.h"
 #include "gstidentity.h"
 
@@ -470,33 +471,7 @@ gst_identity_update_last_message_for_buffer (GstIdentity * identity,
 
   GST_OBJECT_LOCK (identity);
 
-  {
-    static const char *const flag_list[] = {
-      "", "", "", "", "live", "decode-only", "discont", "resync", "corrupted",
-      "marker", "header", "gap", "droppable", "delta-unit", "tag-memory",
-      "FIXME"
-    };
-    int i, max_bytes;
-    char *end;
-
-    max_bytes = 1;              /* NUL */
-    for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
-      max_bytes += strlen (flag_list[i]) + 1;   /* string and space */
-    }
-    flag_str = g_malloc (max_bytes);
-
-    end = flag_str;
-    end[0] = '\0';
-    for (i = 0; i < G_N_ELEMENTS (flag_list); i++) {
-      if (GST_MINI_OBJECT_CAST (buf)->flags & (1 << i)) {
-        strcpy (end, flag_list[i]);
-        end += strlen (end);
-        end[0] = ' ';
-        end[1] = '\0';
-        end++;
-      }
-    }
-  }
+  flag_str = gst_buffer_get_flags_string (buf);
 
   g_free (identity->last_message);
   identity->last_message = g_strdup_printf ("%s   ******* (%s:%s) "