UDPSRC Gstreamer Plugin
Session VIII
UDPSRC - Overview
• Source element
– Receives the packet from UDP port & provide it
over gstreamer pipeline
– Contains Single PAD ( source PAD )
Properties
• PROP_PORT
• PROP_MULTICAST_GROUP
• PROP_MULTICAST_IFACE
• PROP_URI
• PROP_CAPS
• PROP_SOCKFD
• PROP_BUFFER_SIZE
• PROP_TIMEOUT
• PROP_SKIP_FIRST_BYTES
• PROP_CLOSEFD
• PROP_SOCK
• PROP_AUTO_MULTICAST
• PROP_REUSE
gst_udpsrc_base_init
• Does the base initialization of udpsrc source
element
• Adds / registers the static source PAD
gst_udpsrc_base_init
static void gst_udpsrc_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_static_pad_template (element_class,
&src_template);
gst_element_class_set_details_simple (element_class, "UDP packet
receiver",
"Source/Network",
"Receive data over the network via UDP",
"Wim Taymans <wim@fluendo.com>, "
"Thijs Vermeir <thijs.vermeir@barco.com>");
}
gst_udpsrc_class_init
• Call back function initialization to
– Get property - gst_udpsrc_get_property
– Set property - gst_udpsrc_set_property
– Finalize - gst_udpsrc_finalize
– Start - gst_udpsrc_start
– Stop - gst_udpsrc_stop
– Unlock - gst_udpsrc_unlock
– Unlock_stop - gst_udpsrc_unlock_stop
– Getcaps - gst_udpsrc_getcaps
– Create - gst_udpsrc_create
gst_udpsrc_class_init
• Initialization / registeration of element properties
– Port – Port Number ( int )
– Multicast-group : Name of group ( String )
– Multicast-iface : Name of Interface ( String )
– Uri : string
– Sockfd – Socket handler ( int )
– Buffer-size – Buffer-Size (int )
– Timeout – (int)
– Skip First bytes – Number of byte to skip ( int )
– closeFd – Close sockfd if passed as property of state change ( int )
– Sock – Socket Handle ( int )
– Auto-multicast – Automatically joins / leaves multicast groups ( int )
– Reuse : Enables reuse of the port ( boolean )
Property registration
• Property registration is done by
– g_object_class_install_property
• Parameter specified by either
– g_param_spec_int
– g_param_spec_string
– g_param_spec_boolean
– g_param_spec_uint64
gst_udpsrc_init
• Initializes uri string
• Initializes all the property variables
gst_udpsrc_finalize
• This does the cleanup & frees the memory
• unref the capabilities
• frees memory of multicast_iface
• frees memory of uri & uristr
• Closes the socket, if closeFd option enabled
• Cleanup the object
• Finalize gstreamer base object
gst_udpsrc_getcaps
static GstCaps *
gst_udpsrc_getcaps (GstBaseSrc * src)
{
GstUDPSrc *udpsrc;
udpsrc = GST_UDPSRC (src);
if (udpsrc->caps)
return gst_caps_ref (udpsrc->caps);
else
return gst_caps_new_any ();
}
clear_error
• Reads a message from error queue
• Flushes ERROR from fd so next poll will not
return at once
• Local address handling without address
gst_udpsrc_start
• Gets URI information
• Creates a socket
• Enables port reuse option using setsockopt, if
reuse is enabled
• Set socket name if it is multicast
• Configure the kernel receiver buffer size, if buffer-
size parameter is given
• Add the socket into poll fd
• Add the socket into control fd read
gst_udpsrc_stop
static gboolean
gst_udpsrc_stop (GstBaseSrc * bsrc)
{
GstUDPSrc *src;
src = GST_UDPSRC (bsrc);
GST_DEBUG ("stopping, closing sockets");
if (src->sock.fd >= 0) {
if (src->auto_multicast && gst_udp_is_multicast (&src->myaddr)) {
GST_DEBUG_OBJECT (src, "leaving multicast group %s", src->uri.host);
gst_udp_leave_group (src->sock.fd, &src->myaddr);
}
CLOSE_IF_REQUESTED (src);
}
if (src->fdset) {
gst_poll_free (src->fdset);
src->fdset = NULL;
}
return TRUE;
}
gst_udpsrc_create
• Wait for the socket data using gst_poll_wait
• Recv the packet from socket using recvfrom
• Allocate memory for sending data to stream
• Skip first bytes if the option is enabled
• Buffer cast the data to flow into pipeline.
Get Type & Protocols
static GstURIType
gst_udpsrc_uri_get_type (void)
{
return GST_URI_SRC;
}
static gchar **
gst_udpsrc_uri_get_protocols (void)
{
static gchar *protocols[] = { (char *) "udp", NULL };
return protocols;
}
Get & Set URI
static const gchar * gst_udpsrc_uri_get_uri (GstURIHandler * handler)
{
GstUDPSrc *src = GST_UDPSRC (handler);
g_free (src->uristr);
src->uristr = gst_udp_uri_string (&src->uri);
return src->uristr;
}
static gboolean gst_udpsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri)
{
gboolean ret;
GstUDPSrc *src = GST_UDPSRC (handler);
ret = gst_udpsrc_set_uri (src, uri);
return ret;
}
gst_udpsrc_uri_handler_init
static void
gst_udpsrc_uri_handler_init (gpointer g_iface, gpointer
iface_data)
{
GstURIHandlerInterface *iface = (GstURIHandlerInterface *)
g_iface;
iface->get_type = gst_udpsrc_uri_get_type;
iface->get_protocols = gst_udpsrc_uri_get_protocols;
iface->get_uri = gst_udpsrc_uri_get_uri;
iface->set_uri = gst_udpsrc_uri_set_uri;
}

UDPSRC GStreamer Plugin Session VIII

  • 1.
  • 2.
    UDPSRC - Overview •Source element – Receives the packet from UDP port & provide it over gstreamer pipeline – Contains Single PAD ( source PAD )
  • 3.
    Properties • PROP_PORT • PROP_MULTICAST_GROUP •PROP_MULTICAST_IFACE • PROP_URI • PROP_CAPS • PROP_SOCKFD • PROP_BUFFER_SIZE • PROP_TIMEOUT • PROP_SKIP_FIRST_BYTES • PROP_CLOSEFD • PROP_SOCK • PROP_AUTO_MULTICAST • PROP_REUSE
  • 4.
    gst_udpsrc_base_init • Does thebase initialization of udpsrc source element • Adds / registers the static source PAD
  • 5.
    gst_udpsrc_base_init static void gst_udpsrc_base_init(gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_static_pad_template (element_class, &src_template); gst_element_class_set_details_simple (element_class, "UDP packet receiver", "Source/Network", "Receive data over the network via UDP", "Wim Taymans <wim@fluendo.com>, " "Thijs Vermeir <thijs.vermeir@barco.com>"); }
  • 6.
    gst_udpsrc_class_init • Call backfunction initialization to – Get property - gst_udpsrc_get_property – Set property - gst_udpsrc_set_property – Finalize - gst_udpsrc_finalize – Start - gst_udpsrc_start – Stop - gst_udpsrc_stop – Unlock - gst_udpsrc_unlock – Unlock_stop - gst_udpsrc_unlock_stop – Getcaps - gst_udpsrc_getcaps – Create - gst_udpsrc_create
  • 7.
    gst_udpsrc_class_init • Initialization /registeration of element properties – Port – Port Number ( int ) – Multicast-group : Name of group ( String ) – Multicast-iface : Name of Interface ( String ) – Uri : string – Sockfd – Socket handler ( int ) – Buffer-size – Buffer-Size (int ) – Timeout – (int) – Skip First bytes – Number of byte to skip ( int ) – closeFd – Close sockfd if passed as property of state change ( int ) – Sock – Socket Handle ( int ) – Auto-multicast – Automatically joins / leaves multicast groups ( int ) – Reuse : Enables reuse of the port ( boolean )
  • 8.
    Property registration • Propertyregistration is done by – g_object_class_install_property • Parameter specified by either – g_param_spec_int – g_param_spec_string – g_param_spec_boolean – g_param_spec_uint64
  • 9.
    gst_udpsrc_init • Initializes uristring • Initializes all the property variables
  • 10.
    gst_udpsrc_finalize • This doesthe cleanup & frees the memory • unref the capabilities • frees memory of multicast_iface • frees memory of uri & uristr • Closes the socket, if closeFd option enabled • Cleanup the object • Finalize gstreamer base object
  • 11.
    gst_udpsrc_getcaps static GstCaps * gst_udpsrc_getcaps(GstBaseSrc * src) { GstUDPSrc *udpsrc; udpsrc = GST_UDPSRC (src); if (udpsrc->caps) return gst_caps_ref (udpsrc->caps); else return gst_caps_new_any (); }
  • 12.
    clear_error • Reads amessage from error queue • Flushes ERROR from fd so next poll will not return at once • Local address handling without address
  • 13.
    gst_udpsrc_start • Gets URIinformation • Creates a socket • Enables port reuse option using setsockopt, if reuse is enabled • Set socket name if it is multicast • Configure the kernel receiver buffer size, if buffer- size parameter is given • Add the socket into poll fd • Add the socket into control fd read
  • 14.
    gst_udpsrc_stop static gboolean gst_udpsrc_stop (GstBaseSrc* bsrc) { GstUDPSrc *src; src = GST_UDPSRC (bsrc); GST_DEBUG ("stopping, closing sockets"); if (src->sock.fd >= 0) { if (src->auto_multicast && gst_udp_is_multicast (&src->myaddr)) { GST_DEBUG_OBJECT (src, "leaving multicast group %s", src->uri.host); gst_udp_leave_group (src->sock.fd, &src->myaddr); } CLOSE_IF_REQUESTED (src); } if (src->fdset) { gst_poll_free (src->fdset); src->fdset = NULL; } return TRUE; }
  • 15.
    gst_udpsrc_create • Wait forthe socket data using gst_poll_wait • Recv the packet from socket using recvfrom • Allocate memory for sending data to stream • Skip first bytes if the option is enabled • Buffer cast the data to flow into pipeline.
  • 16.
    Get Type &Protocols static GstURIType gst_udpsrc_uri_get_type (void) { return GST_URI_SRC; } static gchar ** gst_udpsrc_uri_get_protocols (void) { static gchar *protocols[] = { (char *) "udp", NULL }; return protocols; }
  • 17.
    Get & SetURI static const gchar * gst_udpsrc_uri_get_uri (GstURIHandler * handler) { GstUDPSrc *src = GST_UDPSRC (handler); g_free (src->uristr); src->uristr = gst_udp_uri_string (&src->uri); return src->uristr; } static gboolean gst_udpsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri) { gboolean ret; GstUDPSrc *src = GST_UDPSRC (handler); ret = gst_udpsrc_set_uri (src, uri); return ret; }
  • 18.
    gst_udpsrc_uri_handler_init static void gst_udpsrc_uri_handler_init (gpointerg_iface, gpointer iface_data) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; iface->get_type = gst_udpsrc_uri_get_type; iface->get_protocols = gst_udpsrc_uri_get_protocols; iface->get_uri = gst_udpsrc_uri_get_uri; iface->set_uri = gst_udpsrc_uri_set_uri; }