Modified:
trunk/src/org/rdv/data/Channel.java
trunk/src/org/rdv/data/LocalChannel.java
trunk/src/org/rdv/rbnb/MetadataManager.java
trunk/src/org/rdv/rbnb/RBNBChannel.java
trunk/src/org/rdv/rbnb/RBNBController.java
trunk/src/org/rdv/ui/ExportDialog.java
trunk/src/org/rdv/ui/ExportVideoDialog.java
trunk/src/org/rdv/ui/MetadataPanel.java
trunk/tests/org/rdv/rbnb/RBNBChannelTest.java
Log:
Add methods to get the start and duration from a channel.
Modified: trunk/src/org/rdv/data/Channel.java
==============================================================================
--- trunk/src/org/rdv/data/Channel.java (original)
+++ trunk/src/org/rdv/data/Channel.java Mon Dec 8 08:38:36 2008
@@ -51,6 +51,12 @@
/** The unit of the channel */
private String unit;
+ /** the start time for the data */
+ private double start;
+
+ /** the duration of the data */
+ private double duration;
+
/** the metadata map for this channel */
private final Map<String, String> metadata;
@@ -108,6 +114,42 @@
}
/**
+ * Gets the start time for the data.
+ *
+ * @return the start time
+ */
+ public double getStart() {
+ return start;
+ }
+
+ /**
+ * Sets the start time for the data.
+ *
+ * @param start the new start time
+ */
+ protected void setStart(double start) {
+ this.start = start;
+ }
+
+ /**
+ * Gets the duration of the data.
+ *
+ * @return the duration
+ */
+ public double getDuration() {
+ return duration;
+ }
+
+ /**
+ * Sets the duration of the data.
+ *
+ * @param duration the new duration
+ */
+ protected void setDuration(double duration) {
+ this.duration = duration;
+ }
+
+ /**
* Gets the metatadata string associated with the given key.
*
* @param key the key corresponding to the desired metadata string
@@ -190,6 +232,5 @@
return string.toString();
}
-
-}
+}
\ No newline at end of file
Modified: trunk/src/org/rdv/data/LocalChannel.java
==============================================================================
--- trunk/src/org/rdv/data/LocalChannel.java (original)
+++ trunk/src/org/rdv/data/LocalChannel.java Mon Dec 8 08:38:36 2008
@@ -186,10 +186,6 @@
// set the size of the data
setMetadata("size", "8");
- // set start and duration metadata to default values
- setMetadata("start", "0");
- setMetadata("duration", "0");
-
// a key to signify that this is a local channel
setMetadata("local");
@@ -242,7 +238,7 @@
public void updateMetadata(ChannelMap channelMap, ChannelTree
serverChannelTree) throws SAPIException {
// see if the first server channel exists
Node serverNode = serverChannelTree.findNode(variableChannels[0]);
- if (node == null) {
+ if (serverNode == null) {
return;
}
@@ -253,8 +249,8 @@
channelMap.PutMime(index, metadataXMLType);
// update start and duration metadata
- setMetadata("start", Double.toString(serverNode.getStart()));
- setMetadata("duration", Double.toString(serverNode.getDuration()));
+ setStart(serverNode.getStart());
+ setDuration(serverNode.getDuration());
}
/**
Modified: trunk/src/org/rdv/rbnb/MetadataManager.java
==============================================================================
--- trunk/src/org/rdv/rbnb/MetadataManager.java (original)
+++ trunk/src/org/rdv/rbnb/MetadataManager.java Mon Dec 8 08:38:36 2008
@@ -137,7 +137,6 @@
} catch (UnknownHostException e) {}
metadataListeners = new ArrayList<MetadataListener>();
- addMetadataListener(rbnbController);
channels = new HashMap<String,Channel>();
Modified: trunk/src/org/rdv/rbnb/RBNBChannel.java
==============================================================================
--- trunk/src/org/rdv/rbnb/RBNBChannel.java (original)
+++ trunk/src/org/rdv/rbnb/RBNBChannel.java Mon Dec 8 08:38:36 2008
@@ -79,8 +79,8 @@
setMime(node);
// set other properties read from the node
- setMetadata("start", Double.toString(node.getStart()));
- setMetadata("duration", Double.toString(node.getDuration()));
+ setStart(node.getStart());
+ setDuration(node.getDuration());
setMetadata("size", Integer.toString(node.getSize()));
}
Modified: trunk/src/org/rdv/rbnb/RBNBController.java
==============================================================================
--- trunk/src/org/rdv/rbnb/RBNBController.java (original)
+++ trunk/src/org/rdv/rbnb/RBNBController.java Mon Dec 8 08:38:36 2008
@@ -38,7 +38,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -60,7 +59,7 @@
*
* @author Jason P. Hanley
*/
-public class RBNBController implements Player, MetadataListener {
+public class RBNBController implements Player {
static Log log = LogFactory.getLog(RBNBController.class.getName());
@@ -84,7 +83,6 @@
private boolean requestIsMonitor;
private ChannelMap requestedChannels;
- private ChannelTree metaDataChannelTree;
private ChannelManager channelManager;
private MetadataManager metadataManager;
@@ -146,7 +144,6 @@
timeScale = 1;
requestedChannels = new ChannelMap();
- metaDataChannelTree = ChannelTree.EMPTY_TREE;
channelManager = new ChannelManager();
metadataManager = new MetadataManager(this);
@@ -611,7 +608,7 @@
for (String channelName : channelNames) {
try {
- if (isVideo(metaDataChannelTree, channelName)) {
+ if (isVideo(channelName)) {
imageChannels.Add(channelName);
} else if (channelManager.isChannelTabularOnly(channelName)) {
tabularChannels.Add(channelName);
@@ -730,7 +727,7 @@
}
//stop if no data in fetch and past end time, most likely end of data
- if (getmap.NumberOfChannels() == 0
&& !moreData(requestedChannels.GetChannelList(), metaDataChannelTree,
location)) {
+ if (getmap.NumberOfChannels() == 0
&& !moreData(requestedChannels.GetChannelList(), location)) {
log.warn("Received no data. Assuming end of channel.");
changeStateSafe(STATE_STOPPED);
return;
@@ -975,52 +972,38 @@
}
- // Utility (Static) Methods
+ // Utility Methods
- private static boolean moreData(String[] channels, ChannelTree ctree,
double time) {
- double endTime = -1;
-
- Iterator<?> it = ctree.iterator();
- while (it.hasNext()) {
- ChannelTree.Node node = (ChannelTree.Node)it.next();
- double channelEndTime = node.getStart() + node.getDuration();
- if (channelEndTime != -1) {
- endTime = Math.max(endTime, channelEndTime);
- }
- }
-
- if (endTime == -1 || time >= endTime) {
- return false;
- } else {
- return true;
- }
- }
+ private boolean moreData(String[] channels, double time) {
+ double endTime = 0;
+
+ for (String channelName : channels) {
+ Channel channel = getChannel(channelName);
+ if (channel == null) {
+ continue;
+ }
+
+ double channelEndTime = channel.getStart() + channel.getDuration();
+ endTime = Math.max(endTime, channelEndTime);
+ }
+
+ return time < endTime;
+ }
+
+ private boolean isVideo(String channelName) {
+ Channel channel = getChannel(channelName);
+ if (channel == null) {
+ return false;
+ }
+
+ String mime = channel.getMetadata("mime");
+ if (mime != null && mime.equals("image/jpeg")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
- private static boolean isVideo(ChannelTree channelTree, String
channelName) {
- if (channelName == null) {
- log.error("Channel name is null for. Can't determine if is video.");
- return false;
- } else if (channelTree == null) {
- log.warn("Haven't received metadata yet, can't determine channel
type.");
- return false;
- }
-
- ChannelTree.Node node = channelTree.findNode(channelName);
- if (node == null) {
- log.error("Unable to find channel in metadata.");
- return false;
- } else {
- String mime = node.getMime();
- if (mime != null && mime.equals("image/jpeg")) {
- return true;
- } else if (channelName.endsWith(".jpg")){
- return true;
- } else {
- return false;
- }
- }
- }
-
private static double getLastTime(ChannelMap channelMap) {
double lastTime = -1;
@@ -1509,10 +1492,6 @@
*/
public void updateMetadata() {
metadataManager.updateMetadataBackground();
- }
-
- public void channelTreeUpdated(ChannelTree ctree) {
- metaDataChannelTree = ctree;
}
Modified: trunk/src/org/rdv/ui/ExportDialog.java
==============================================================================
--- trunk/src/org/rdv/ui/ExportDialog.java (original)
+++ trunk/src/org/rdv/ui/ExportDialog.java Mon Dec 8 08:38:36 2008
@@ -431,8 +431,8 @@
continue;
}
- double channelStart =
Double.parseDouble(channel.getMetadata("start"));
- double channelDuration =
Double.parseDouble(channel.getMetadata("duration"));
+ double channelStart = channel.getStart();
+ double channelDuration = channel.getDuration();
double channelEnd = channelStart+channelDuration;
if (channelStart < minimum) {
Modified: trunk/src/org/rdv/ui/ExportVideoDialog.java
==============================================================================
--- trunk/src/org/rdv/ui/ExportVideoDialog.java (original)
+++ trunk/src/org/rdv/ui/ExportVideoDialog.java Mon Dec 8 08:38:36 2008
@@ -443,8 +443,8 @@
continue;
}
- double channelStart =
Double.parseDouble(channel.getMetadata("start"));
- double channelDuration =
Double.parseDouble(channel.getMetadata("duration"));
+ double channelStart = channel.getStart();
+ double channelDuration = channel.getDuration();
double channelEnd = channelStart+channelDuration;
if (channelStart < minimum) {
Modified: trunk/src/org/rdv/ui/MetadataPanel.java
==============================================================================
--- trunk/src/org/rdv/ui/MetadataPanel.java (original)
+++ trunk/src/org/rdv/ui/MetadataPanel.java Mon Dec 8 08:38:36 2008
@@ -126,8 +126,8 @@
String unit = channelMetadata.getUnit();
String mime = channelMetadata.getMetadata("mime");
String description = channelMetadata.getMetadata("description");
- double start =
Double.parseDouble(channelMetadata.getMetadata("start"));
- double duration =
Double.parseDouble(channelMetadata.getMetadata("duration"));
+ double start = channelMetadata.getStart();
+ double duration = channelMetadata.getDuration();
int size = Integer.parseInt(channelMetadata.getMetadata("size"));
String formula = channelMetadata.getMetadata("formula");
Modified: trunk/tests/org/rdv/rbnb/RBNBChannelTest.java
==============================================================================
--- trunk/tests/org/rdv/rbnb/RBNBChannelTest.java (original)
+++ trunk/tests/org/rdv/rbnb/RBNBChannelTest.java Mon Dec 8 08:38:36 2008
@@ -66,6 +66,12 @@
/** the channel unit */
private static final String unit = "in";
+ /** the start time of the data */
+ private static final double start = System.currentTimeMillis()/1000d;
+
+ /** the duartion of the data */
+ private static final double duration = 12;
+
/**
* Create the channel and give it metadata. This starts up a local RBNB
* server, registers a channel with the server, and then creates the
channel
@@ -86,6 +92,11 @@
source.Register(channelMap);
+ channelIndex = channelMap.Add(channelName);
+ channelMap.PutTime(start, duration);
+ channelMap.PutDataAsFloat64(channelIndex, new double[] { 0 });
+ source.Flush(channelMap);
+
Sink sink = new Sink();
sink.OpenRBNBConnection();
sink.RequestRegistration();
@@ -116,13 +127,26 @@
public void testGetUnit() {
assertEquals(unit, channel.getUnit());
}
+
+ /**
+ * Tests getting the start of the data for the channel.
+ */
+ public void testGetStart() {
+ assertEquals(start, channel.getStart());
+ }
+
+ /**
+ * Tests getting the duration of the data for the channel.
+ */
+ public void testGetDuration() {
+ assertEquals(duration, channel.getDuration());
+ }
/**
* Test getting the metadata for the channel. This tests the unit of the
* channel.
*/
public void testGetMetadata() {
- assertEquals("0.0", channel.getMetadata("duration"));
assertEquals("", channel.getMetadata("server"));
assertEquals("application/octet-stream", channel.getMetadata("mime"));
assertEquals(unit, channel.getMetadata("units"));