[vlma-devel] commit: Cleanup. (Adrien Grand )

git version control git at videolan.org
Tue Mar 3 04:45:27 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Mar  1 02:21:27 2009 +0100| [df7ea7c51e9014fef73d7d0320e15dff36b25da6] | committer: Adrien Grand 

Cleanup.

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

 .../main/java/org/videolan/vlma/model/Order.java   |    3 +-
 .../main/java/org/videolan/vlma/model/Program.java |    2 +-
 .../java/org/videolan/vlma/model/ProgramGroup.java |   39 ++++++++++++++++++--
 .../org/videolan/vlma/order/vlm/OrderBuilder.java  |    9 +++--
 4 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Order.java b/vlma-api/src/main/java/org/videolan/vlma/model/Order.java
index 1f782ba..8f201c2 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Order.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Order.java
@@ -100,8 +100,7 @@ public class Order implements Comparable<Order> {
             return "adapter-" + adapter.getName();
         } else {
             // Warning if you want to change this, this name is used in the URI for RTSP streaming
-            Program program = programs.get(0);
-            return program.getId();
+            return programs.iterator().next().getId();
         }
     }
 
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Program.java b/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
index 0020085..d0d2486 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
@@ -30,7 +30,7 @@ import java.util.Date;
  *
  * @author Sylvain Cadilhac <sylv at videolan.org>
  */
-public class Program implements Serializable {
+public final class Program implements Serializable {
 
     private static final long serialVersionUID = 5L;
 
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/ProgramGroup.java b/vlma-api/src/main/java/org/videolan/vlma/model/ProgramGroup.java
index c1dc870..466f951 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/ProgramGroup.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/ProgramGroup.java
@@ -20,7 +20,10 @@
 
 package org.videolan.vlma.model;
 
+import java.util.AbstractCollection;
 import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 
 /**
@@ -30,9 +33,15 @@ import java.util.ArrayList;
  * @author Sylvain Cadilhac <sylv at videolan.org>
  * @author Adrien Grand <jpountz at videolan.org>
  */
-public abstract class ProgramGroup extends ArrayList<Program>
+public abstract class ProgramGroup extends AbstractCollection<Program>
                                    implements Comparable<ProgramGroup> {
 
+    // Only one streaming strategy type is possible for a given program group
+    private StreamingStrategy.Type type = StreamingStrategy.Type.BROADCAST;
+
+    // Storage backend for the programs
+    private List<Program> programs = new ArrayList<Program>();
+
     /**
      * Compares groups according to their priority.
      *
@@ -76,7 +85,7 @@ public abstract class ProgramGroup extends ArrayList<Program>
      * @return the mediagroup load
      */
     public int getLoad() {
-        // A constant load (per order) plus how many channels will be streamed
+        // A constant load (per order) plus how many programs will be streamed
         return 1 + size();
     }
 
@@ -117,15 +126,39 @@ public abstract class ProgramGroup extends ArrayList<Program>
      */
     protected abstract boolean isAddable(Program program);
 
+    /**
+     * Gets the program group's type.
+     *
+     * @return the proogram group's type
+     */
+    public StreamingStrategy.Type getType() {
+        return type;
+    }
+
+    // Methods of the Collection interface
+
     @Override
     public boolean add(Program program) {
         if (program.belongsToGroup(this)) {
-            return super.add(program);
+            if (isEmpty()) {
+                type = program.getStreamingStrategy().getType();
+            }
+            return programs.add(program);
         }
         throw new IllegalArgumentException("The program does not belong to this group");
     }
 
     @Override
+    public Iterator<Program> iterator() {
+        return programs.iterator();
+    }
+
+    @Override
+    public int size() {
+        return programs.size();
+    }
+
+    @Override
     public String toString() {
         boolean first = true;
         StringBuilder result = new StringBuilder();
diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/vlm/OrderBuilder.java b/vlma-core/src/main/java/org/videolan/vlma/order/vlm/OrderBuilder.java
index 7c709d4..1f3eda2 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/vlm/OrderBuilder.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/vlm/OrderBuilder.java
@@ -49,7 +49,10 @@ public class OrderBuilder {
     private Configuration configuration;
 
     public VLMOrder buildOrder(Order order) {
-        switch (order.getPrograms().get(0).getStreamingStrategy().getType()) {
+        if (order.getPrograms().isEmpty()) {
+            throw new IllegalArgumentException("Cannot build a VLM order for an empty group");
+        }
+        switch (order.getPrograms().getType()) {
         case BROADCAST:
             return buildBroadcast(order);
         case VOD:
@@ -124,7 +127,7 @@ public class OrderBuilder {
         ProgramGroup group = order.getPrograms();
         if (group instanceof FilesProgramGroup) {
             assert group.size() == 1;
-            FilesChannel ch = (FilesChannel) group.get(0).getMedia();
+            FilesChannel ch = (FilesChannel) ((FilesProgramGroup) group).getMedia();
             // Only one media per VoD
             assert ch.getFiles().size() == 1 : "Only one input allowed for VoD";
             result.addInput(ch.getFiles().get(0));
@@ -147,7 +150,7 @@ public class OrderBuilder {
             sout.setCharAt(sout.length() - 1, '}');
         } else {
             sout.append('#');
-            buildDst(sout, group.get(0));
+            buildDst(sout, group.iterator().next());
         }
         return sout.toString();
     }



More information about the vlma-devel mailing list