[vlma-devel] commit: More robust RtspStreamWatcher. (Adrien Grand )

git version control git at videolan.org
Fri Jan 2 01:38:24 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Fri Jan  2 01:37:35 2009 +0100| [194c38b058f2e9b6346f634f97bfcd754455738e] | committer: Adrien Grand 

More robust RtspStreamWatcher.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=194c38b058f2e9b6346f634f97bfcd754455738e
---

 .../videolan/vlma/watcher/RtspStreamWatcher.java   |   40 ++++++++------------
 1 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/watcher/RtspStreamWatcher.java b/vlma-core/src/main/java/org/videolan/vlma/watcher/RtspStreamWatcher.java
index 4b82852..e3ceb77 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/watcher/RtspStreamWatcher.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/watcher/RtspStreamWatcher.java
@@ -85,35 +85,28 @@ public class RtspStreamWatcher implements StreamWatcher {
         Thread waitThread = new Waiter(mySocket);
         waitThread.setName("waitThread");
         waitThread.start();
-        while(true) {
-            /* The waiter thread allow to exit this loop by closing the socket */
-            String line;
-            try {
-                line = in.readLine();
-            } catch (IOException e) {
-                break;
-            }
-
-            if(line == null)
-                break;
-            /* If the RTSP server talks about the media URL, then it must be able
-            to broadcast it.
-            Maybe we could do something better ... */
-            else if(line.contains(url)) {
-                isPlayed = true;
-                break;
+        try {
+            String line = in.readLine();
+            String[] resp = line.split("\\s+"); // RTSP/1.0 <code> <message>
+            if (resp.length == 3 && resp[1].matches("[0-9]{3}")) {
+                int code = Integer.parseInt(resp[1]);
+                if (code == 200) {
+                    isPlayed = true;
+                    logger.debug("The RTSP media " + program.getSapName() + " is available.");
+                } else {
+                    logger.debug(String.format("The RTSP media %s is NOT available: %d code received", program.getSapName(), code));
+                }
+            } else {
+                logger.debug("The RTSP media " + program.getSapName() + " is not played: Bad response format: " + line);
             }
+        } catch (IOException e) {
+            logger.debug("The RTSP media " + program.getSapName() + " is not played: Timeout while waiting for the response");
+            isPlayed = false;
         }
 
         /* Stop the thread if it hasn't already be done */
         waitThread.interrupt();
 
-        /* Some log output */
-        if( isPlayed )
-            logger.debug("The RTSP media " + program.getSapName() + " is available.");
-        else
-            logger.debug("The RTSP media " + program.getSapName() + " is NOT available.");
-
         return isPlayed;
     }
 
@@ -165,4 +158,3 @@ public class RtspStreamWatcher implements StreamWatcher {
         this.vlmaService = vlmaService;
     }
 }
-



More information about the vlma-devel mailing list