udpsrc: track max packet size and save allocator negotiated by GstBaseSrc
authorTim-Philipp Müller <tim@centricular.com>
Tue, 9 Sep 2014 08:42:15 +0000 (09:42 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 9 Sep 2014 16:35:14 +0000 (17:35 +0100)
gst/udp/gstudpsrc.c
gst/udp/gstudpsrc.h

index 98cb209..cfde461 100644 (file)
@@ -182,6 +182,7 @@ static GstFlowReturn gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf);
 static gboolean gst_udpsrc_close (GstUDPSrc * src);
 static gboolean gst_udpsrc_unlock (GstBaseSrc * bsrc);
 static gboolean gst_udpsrc_unlock_stop (GstBaseSrc * bsrc);
+static gboolean gst_udpsrc_negotiate (GstBaseSrc * basesrc);
 
 static void gst_udpsrc_finalize (GObject * object);
 
@@ -294,6 +295,7 @@ gst_udpsrc_class_init (GstUDPSrcClass * klass)
   gstbasesrc_class->unlock = gst_udpsrc_unlock;
   gstbasesrc_class->unlock_stop = gst_udpsrc_unlock_stop;
   gstbasesrc_class->get_caps = gst_udpsrc_getcaps;
+  gstbasesrc_class->negotiate = gst_udpsrc_negotiate;
 
   gstpushsrc_class->create = gst_udpsrc_create;
 }
@@ -390,6 +392,32 @@ gst_udpsrc_getcaps (GstBaseSrc * src, GstCaps * filter)
   return result;
 }
 
+static gboolean
+gst_udpsrc_negotiate (GstBaseSrc * basesrc)
+{
+  gboolean ret;
+
+  /* just chain up to the default implementation, we just want to
+   * retrieve the allocator at the end of it (if there is one) */
+  ret = GST_BASE_SRC_CLASS (parent_class)->negotiate (basesrc);
+
+  if (ret) {
+    GstUDPSrc *src;
+
+    src = GST_UDPSRC (basesrc);
+
+    if (src->allocator != NULL) {
+      gst_object_unref (src->allocator);
+      src->allocator = NULL;
+    }
+
+    gst_base_src_get_allocator (basesrc, &src->allocator, &src->params);
+    GST_INFO_OBJECT (src, "allocator: %" GST_PTR_FORMAT, src->allocator);
+  }
+
+  return ret;
+}
+
 static GstFlowReturn
 gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
 {
@@ -507,6 +535,10 @@ no_select:
     goto receive_error;
   }
 
+  /* remember maximum packet size */
+  if (res > udpsrc->max_size)
+    udpsrc->max_size = res;
+
   /* patch offset and size when stripping off the headers */
   if (G_UNLIKELY (udpsrc->skip_first_bytes != 0)) {
     if (G_UNLIKELY (readsize < udpsrc->skip_first_bytes))
@@ -997,6 +1029,11 @@ gst_udpsrc_open (GstUDPSrc * src)
     g_object_unref (addr);
   }
 
+  src->allocator = NULL;
+  gst_allocation_params_init (&src->params);
+
+  src->max_size = 0;
+
   return TRUE;
 
   /* ERRORS */
@@ -1102,6 +1139,11 @@ gst_udpsrc_close (GstUDPSrc * src)
     src->addr = NULL;
   }
 
+  if (src->allocator != NULL) {
+    gst_object_unref (src->allocator);
+    src->allocator = NULL;
+  }
+
   return TRUE;
 }
 
index c631e35..5258881 100644 (file)
@@ -61,12 +61,19 @@ struct _GstUDPSrc {
   gboolean   auto_multicast;
   gboolean   reuse;
 
+  /* stats */
+  guint      max_size;
+
   /* our sockets */
   GSocket   *used_socket;
   GCancellable *cancellable;
   GInetSocketAddress *addr;
   gboolean   external_socket;
 
+  /* memory management */
+  GstAllocator *allocator;
+  GstAllocationParams params;
+
   gchar     *uri;
 };