udpsrc: track max packet size and save allocator negotiated by GstBaseSrc

This commit is contained in:
Tim-Philipp Müller 2014-09-09 09:42:15 +01:00
parent 8e28994207
commit 305e4c2f46
2 changed files with 49 additions and 0 deletions

View 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;
}

View 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;
};