[vlma-devel] commit: HTTP streams do not need a multicast IP address. (Adrien Grand )

git version control git at videolan.org
Sat Jun 28 01:46:07 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Fri Jun 27 17:31:40 2008 +0200| [523ee2d0cdf8215f281bf5c8f8dd6763260fb8e9]

HTTP streams do not need a multicast IP address.

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

 .../src/main/java/org/videolan/vlma/IpBank.java    |   17 ++++++++++++++++-
 .../java/org/videolan/vlma/VLMaServiceImpl.java    |   15 ++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
index 5c5b0cd..7ab308f 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.videolan.vlma.model.StreamingStrategy;
 import org.videolan.vlma.model.media.Media;
 import org.videolan.vlma.model.program.Program;
 
@@ -68,7 +69,7 @@ public class IpBank {
         }
         for (Media m : vlmaService.getMedias()) {
             Program p = m.getProgram();
-            if (p == null) {
+            if (p == null || !p.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)) {
                 continue;
             }
             logger.log(Level.DEBUG, "The media " + m.getName()
@@ -91,10 +92,24 @@ public class IpBank {
                 return entry.getKey();
             }
         }
+        logger.error("No free IP found.");
         return null;
     }
 
     /**
+     * Releases an IP address.
+     *
+     * @param ip
+     */
+    public void releaseIp(InetAddress ip) {
+        if (usedIps.containsKey(ip)) {
+            usedIps.put(ip, Boolean.FALSE);
+        } else {
+            logger.warn("IP address " + ip.getHostAddress() + " is not in the pool");
+        }
+    }
+
+    /**
      * Sets the VLMa service.
      *
      * @param vlmaService the vlmaService to set
diff --git a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
index c43d2a2..21298c7 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
@@ -429,6 +429,13 @@ public class VLMaServiceImpl implements VLMaService {
     synchronized public void updateMediaProgram(int media,
             Program program) throws MediaDoesNotExistException {
         Media m = this.getMedia(media);
+        if (m.getProgram().getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)
+                && !program.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)) {
+            ipBank.releaseIp(m.getProgram().getIp());
+        } else if (!m.getProgram().getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)
+                && program.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP)) {
+            program.setIp(ipBank.getIp());
+        }
         m.setProgram(program);
         logger.log(Level.DEBUG, "New programmation for media " + media);
         saveToDisk();
@@ -438,9 +445,11 @@ public class VLMaServiceImpl implements VLMaService {
             throws MediaDoesNotExistException {
         Media m = this.getMedia(media);
         Program program = programFactory.getProgram();
-        InetAddress a = ipBank.getIp();
-        logger.log(Level.DEBUG, "Multicast IPv4 address for " + m.getName() + ": " + a.toString());
-        program.setIp(a);
+        if (program.getStreamingStrategy().equals(StreamingStrategy.Protocol.UDP)) {
+            InetAddress a = ipBank.getIp();
+            logger.log(Level.DEBUG, "Multicast IPv4 address for " + m.getName() + ": " + a.toString());
+            program.setIp(a);
+        }
         m.setProgram(program);
         saveToDisk();
         return program;



More information about the vlma-devel mailing list