[Live-devel] [PATCH] Infinite loop in source port selection on WinCE

Pierre Ynard linkfanel at yahoo.fr
Fri Dec 19 06:26:11 PST 2008


Hello,

I am using the live555 library on a smartphone running under Windows
CE, as a plugin for the VLC media player, used as part of a custom
application. When opening an RTSP stream, live555 source port selection
algorithm sometimes gets caught in an infinite loop, which freezes the
process. (It even freezes the whole Windows CE system, since apparently
preempting a process in an infinite loop is too much for Windows CE.)

RTP needs an even source port number, so live555 requests a socket,
checks the source port, and if it's not even, loops back until it is.
According to my investigations, WinCE occasionally keeps returning the
same source port again and again, effectively causing an endless loop. I
found that this can be partially prevented by fiddling with the network
stack, like, resetting the GPRS connection.

I applied this patch, and it solves my problem: no more freezes, no
errors. Please consider.


--- live_orig/liveMedia/MediaSession.cpp	2008-11-13 10:30:10.000000000 +0100
+++ live/liveMedia/MediaSession.cpp	2008-12-19 11:57:33.000000000 +0100
@@ -599,7 +599,8 @@
     struct in_addr tempAddr;
     tempAddr.s_addr = connectionEndpointAddress();
         // This could get changed later, as a result of a RTSP "SETUP"
-    while (1) {
+    unsigned int numTries;
+    for (numTries = 0; numTries < 20; numTries++) {
       unsigned short rtpPortNum = fClientPortNum&~1;
       if (isSSM()) {
 	fRTPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr,
@@ -608,7 +609,10 @@
 	fRTPSocket = new Groupsock(env(), tempAddr, rtpPortNum, 255);
       }
       if (fRTPSocket == NULL) {
-	env().setResultMsg("Failed to create RTP socket");
+	if (fClientPortNum && numTries > 0) {
+	  fClientPortNum += 2;
+	  continue;
+	}
 	break;
       }
 
@@ -627,8 +631,11 @@
       // Try again:
       delete oldGroupsock;
       oldGroupsock = fRTPSocket;
-      fClientPortNum = 0;
+      if (numTries < 10) {
+	fClientPortNum = 0;
+      }
     }
+    env().setResultMsg("Failed to create RTP socket");
     delete oldGroupsock;
     if (!success) break;
 
----------

Regards,

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."


More information about the live-devel mailing list