[gst-devel] patch udp plugin

Jim Thornton jthornton at parc.com
Thu Mar 21 11:00:18 CET 2002


Hi,

I'm new to gstreamer and so I've been running random pieces of the system 
to find out how it works.  I've been finding various bugs, some perhaps 
well off the beaten path.  I'm going to try to submit some patches 
with small fixes here and hope that I've done this correctly.   These are 
off of the March 10 tarball.

First, for gstudpsink, it wasn't clocking out the data so I added a wait 
with the system clock.  Then gstudpsrc had a couple of bugs:
- tmpaddr not setup properly for recvfrom
- returning a null buffer from get when something comes in on control 
socket

--- gstudpsink.c.orig	Fri Mar 15 18:21:10 2002
+++ gstudpsink.c	Thu Mar 21 10:46:15 2002
@@ -181,6 +181,7 @@
 {
   GstUDPSink *udpsink;
   int tolen;
+  GstClock *clock;
 
   g_return_if_fail (pad != NULL);
   g_return_if_fail (GST_IS_PAD (pad));
@@ -190,6 +191,9 @@
 
   tolen = sizeof(udpsink->theiraddr);
 
+  
+  clock = gst_system_clock_obtain();
+  gst_element_clock_wait(GST_ELEMENT(udpsink), clock,   
GST_BUFFER_TIMESTAMP(buf));
   if (sendto (udpsink->sock, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE 
(buf), 0, 
 			  (struct sockaddr *) &udpsink->theiraddr, tolen) 
== -1)
   {


--- gstudpsink.h.orig	Thu Mar 21 10:46:07 2002
+++ gstudpsink.h	Thu Mar 21 10:46:11 2002
@@ -24,6 +24,7 @@
 
 #include <config.h>
 #include <gst/gst.h>
+#include <gst/gstsystemclock.h>
 
 #ifdef __cplusplus
 extern "C" {

--- gstudpsrc.c.orig	Fri Mar 15 15:43:02 2002
+++ gstudpsrc.c	Fri Mar 15 16:09:59 2002
@@ -130,66 +130,71 @@
 
   udpsrc = GST_UDPSRC (GST_OBJECT_PARENT (pad));
 
-  FD_ZERO (&read_fds);
-  FD_SET (udpsrc->control_sock, &read_fds);
-  FD_SET (udpsrc->sock, &read_fds);
+  while (1) {
+    FD_ZERO (&read_fds);
+    FD_SET (udpsrc->control_sock, &read_fds);
+    FD_SET (udpsrc->sock, &read_fds);
 
-  if (select (udpsrc->control_sock+1, &read_fds, NULL, NULL, NULL) > 0) {
-    if (FD_ISSET (udpsrc->control_sock, &read_fds)) {
+    if (select (udpsrc->control_sock+1, &read_fds, NULL, NULL, NULL) > 0) 
{
+      if (FD_ISSET (udpsrc->control_sock, &read_fds)) {
 #ifndef GST_DISABLE_LOADSAVE
-      guchar *buf;
-      int ret;
-      int fdread;
-      struct sockaddr addr;
-      socklen_t len;
-      xmlDocPtr doc;
-      GstCaps *caps;
-
-      buf = g_malloc (1024*10);
-
-      len = sizeof (struct sockaddr);
-      fdread = accept (udpsrc->control_sock, &addr, &len);
-      if (fdread < 0) {
-	perror ("accept");
-      }
+	guchar *buf;
+	int ret;
+	int fdread;
+	struct sockaddr addr;
+	socklen_t len;
+	xmlDocPtr doc;
+	GstCaps *caps;
+
+	buf = g_malloc (1024*10);
+
+	len = sizeof (struct sockaddr);
+	fdread = accept (udpsrc->control_sock, &addr, &len);
+	if (fdread < 0) {
+	  perror ("accept");
+	}
       
-      ret = read (fdread, buf, 1024*10);
-      if (ret < 0) {
-	perror ("read");
-      }
-      buf[ret] = '\0';
-      doc = xmlParseMemory(buf, ret);
-      caps = gst_caps_load_thyself(doc->xmlRootNode);
+	ret = read (fdread, buf, 1024*10);
+	if (ret < 0) {
+	  perror ("read");
+	}
+	buf[ret] = '\0';
+	doc = xmlParseMemory(buf, ret);
+	caps = gst_caps_load_thyself(doc->xmlRootNode);
       
-      gst_pad_try_set_caps (udpsrc->srcpad, caps);
+	gst_pad_try_set_caps (udpsrc->srcpad, caps);
 
 #endif
-      outbuf = NULL;
-    }
-    else {
-      outbuf = gst_buffer_new ();
-      GST_BUFFER_DATA (outbuf) = g_malloc (24000);
-      GST_BUFFER_SIZE (outbuf) = 24000;
-
-      numbytes = recvfrom (udpsrc->sock, GST_BUFFER_DATA (outbuf),
-		  GST_BUFFER_SIZE (outbuf), 0, (struct sockaddr 
*)&tmpaddr, &len);
-
-      if (numbytes != -1) {
-        GST_BUFFER_SIZE (outbuf) = numbytes;
+	outbuf = NULL;
       }
       else {
-	perror ("recvfrom");
-        gst_buffer_unref (outbuf);
-        outbuf = NULL;
-      }
+	outbuf = gst_buffer_new ();
+	GST_BUFFER_DATA (outbuf) = g_malloc (24000);
+	GST_BUFFER_SIZE (outbuf) = 24000;
+
+	len=sizeof(tmpaddr);
+	memset(&tmpaddr, 0, len);
+	tmpaddr.sin_family=AF_INET;
+	numbytes = recvfrom (udpsrc->sock, GST_BUFFER_DATA (outbuf),
+			     GST_BUFFER_SIZE (outbuf), 0, (struct sockaddr 
*)&tmpaddr, &len);
+
+	if (numbytes != -1) {
+	  GST_BUFFER_SIZE (outbuf) = numbytes;
+	}
+	else {
+	  perror ("recvfrom");
+	  gst_buffer_unref (outbuf);
+	  outbuf = NULL;
+	}
   
+	return outbuf;
+      }
+    }
+    else {
+      perror ("select");
+      return NULL;
     }
   }
-  else {
-    perror ("select");
-    outbuf = NULL;
-  }
-  return outbuf;
 }






More information about the gstreamer-devel mailing list