From: rtrimana Date: Thu, 1 Feb 2018 18:19:05 +0000 (-0800) Subject: More adjustments to files after paper evaluation X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=325bdddf294e581e97dcf23bbbcaed7df7efaea8;ds=sidebyside More adjustments to files after paper evaluation --- diff --git a/benchmarks/drivers/Java/IHome/MP3Decoder.java b/benchmarks/drivers/Java/IHome/MP3Decoder.java new file mode 100644 index 0000000..77a5a2c --- /dev/null +++ b/benchmarks/drivers/Java/IHome/MP3Decoder.java @@ -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 + *

+ * This class decodes mp3 files into raw pcm data + * + * @author Ali Younis + * @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 audioLinkedList = new LinkedList(); + 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 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; + } + +} + + + + + + + + + + diff --git a/iotjava/iotruntime/IoTHTTP.java b/iotjava/iotruntime/IoTHTTP.java index 2c1c4ad..36948ac 100644 --- a/iotjava/iotruntime/IoTHTTP.java +++ b/iotjava/iotruntime/IoTHTTP.java @@ -48,7 +48,6 @@ public final class IoTHTTP { public void setURL(String strUrlComplete) throws MalformedURLException { url = new URL(iotDevAdd.getURL(strUrlComplete)); - } /** diff --git a/iotjava/iotruntime/slave/IoTDeviceAddress.java b/iotjava/iotruntime/slave/IoTDeviceAddress.java index 8a6455b..5883b68 100644 --- a/iotjava/iotruntime/slave/IoTDeviceAddress.java +++ b/iotjava/iotruntime/slave/IoTDeviceAddress.java @@ -150,4 +150,17 @@ public final class IoTDeviceAddress extends IoTAddress { return "http://" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete; } + + /** + * getURL() method + * + * @return String + */ + public String getURL(String strURLComplete, String strUser, String strPassword) { + + //e.g. http:// + inetAddress.getHostAddress() + strURLComplete + // http://192.168.2.254/cgi-bin/mjpg/video.cgi? + return "http://" + strUser + ":" + strPassword + "@" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete; + + } }