More adjustments to files after paper evaluation
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 18:19:05 +0000 (10:19 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 18:19:05 +0000 (10:19 -0800)
benchmarks/drivers/Java/IHome/MP3Decoder.java [new file with mode: 0644]
iotjava/iotruntime/IoTHTTP.java
iotjava/iotruntime/slave/IoTDeviceAddress.java

diff --git a/benchmarks/drivers/Java/IHome/MP3Decoder.java b/benchmarks/drivers/Java/IHome/MP3Decoder.java
new file mode 100644 (file)
index 0000000..77a5a2c
--- /dev/null
@@ -0,0 +1,104 @@
+package iotcode.IHome;
+
+import javazoom.jl.player.advanced.*;
+import javazoom.jl.player.*;
+
+// Standard Java Packages
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.List;
+import java.util.LinkedList;
+import java.io.FileInputStream;
+
+/** Class MP3Decoder for the smart home application benchmark
+ *  <p>
+ *  This class decodes mp3 files into raw pcm data
+ *
+ * @author      Ali Younis <ayounis @ uci.edu>
+ * @version     1.0                
+ * @since       2016-05-01
+ */
+public class MP3Decoder extends AudioDeviceBase {
+
+    private class PlaybackList extends PlaybackListener {
+        private MP3Decoder decoder;
+        public PlaybackList(MP3Decoder _d) {
+            decoder = _d;
+        }
+
+        public void playbackFinished(PlaybackEvent evt) {
+            decoder.decodeDone();
+        }
+
+        public void playbackStarted(PlaybackEvent evt) {
+            // do nothing
+        }
+    }
+
+    private String fileName = "";
+    private LinkedList<short[]> audioLinkedList = new LinkedList<short[]>();
+    private AtomicBoolean decodeDone = new AtomicBoolean();
+    private long dataLength = 0;
+
+    public MP3Decoder(String _fileName) {
+        fileName = _fileName;
+        decodeDone.set(false);
+
+        PlaybackList pl = new PlaybackList(this);
+
+        try {
+            AdvancedPlayer ap = new AdvancedPlayer(new FileInputStream(fileName), this);
+            ap.setPlayBackListener(pl);
+            ap.play();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public List<short[]> getDecodedFrames() {
+
+        while (decodeDone.get() == false) {
+            // just block until done
+        }
+
+        return audioLinkedList;
+    }
+
+    public long getAudioFrameLength() {
+        // stereo
+        return dataLength / 2;
+    }
+
+    protected void decodeDone() {
+        decodeDone.set(true);
+    }
+
+    public int getPosition() {
+        // not used, just needed for AdvancedPlayer to work.
+        return 0;
+    }
+
+    protected void writeImpl(short[] _samples, int _offs, int _len) {
+        short[] sample = new short[_len];
+        int j = _offs;
+        for (int i = 0; i < _len; i++, j++) {
+            sample[i] = _samples[j];
+        }
+        synchronized (audioLinkedList) {
+            audioLinkedList.addLast(sample);
+        }
+
+        dataLength += (long)_len;
+    }
+
+}
+
+
+
+
+
+
+
+
+
+
index 2c1c4ad..36948ac 100644 (file)
@@ -48,7 +48,6 @@ public final class IoTHTTP {
        public void setURL(String strUrlComplete) throws MalformedURLException {\r
 \r
                url = new URL(iotDevAdd.getURL(strUrlComplete));\r
-\r
        }\r
 \r
        /**\r
index 8a6455b..5883b68 100644 (file)
@@ -150,4 +150,17 @@ public final class IoTDeviceAddress extends IoTAddress {
                return "http://" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete;\r
 \r
        }\r
+       \r
+       /**\r
+        * getURL() method\r
+        *\r
+        * @return  String\r
+        */\r
+       public String getURL(String strURLComplete, String strUser, String strPassword) {\r
+\r
+               //e.g. http:// + inetAddress.getHostAddress() + strURLComplete\r
+               //     http://192.168.2.254/cgi-bin/mjpg/video.cgi?\r
+               return "http://" + strUser + ":" + strPassword + "@" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete;\r
+\r
+       }\r
 }\r