From cfb796c23f4a05147e248394d97076fbee7d10c5 Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sat, 11 Jan 2014 23:53:08 +0100 Subject: [PATCH] Cleanup code --- build.xml | 4 +- src/com/limelight/Limelight.java | 15 ++-- src/com/limelight/binding/LibraryHelper.java | 88 ------------------- .../limelight/binding/PlatformBinding.java | 3 +- .../binding/audio/JavaxAudioRenderer.java | 3 +- .../limelight/binding/video/OmxDecoder.java | 8 +- src/com/limelight/input/Device.java | 25 ------ src/com/limelight/input/DeviceListener.java | 6 -- 8 files changed, 16 insertions(+), 136 deletions(-) delete mode 100644 src/com/limelight/binding/LibraryHelper.java delete mode 100644 src/com/limelight/input/Device.java delete mode 100644 src/com/limelight/input/DeviceListener.java diff --git a/build.xml b/build.xml index 88621ec..603ec00 100644 --- a/build.xml +++ b/build.xml @@ -36,8 +36,8 @@ - - + + diff --git a/src/com/limelight/Limelight.java b/src/com/limelight/Limelight.java index 7536a90..2e8aec2 100644 --- a/src/com/limelight/Limelight.java +++ b/src/com/limelight/Limelight.java @@ -2,7 +2,6 @@ package com.limelight; import java.io.IOException; -import com.limelight.binding.LibraryHelper; import com.limelight.binding.PlatformBinding; import com.limelight.input.EvdevHandler; import com.limelight.nvstream.NvConnection; @@ -19,10 +18,10 @@ import java.util.List; import org.xmlpull.v1.XmlPullParserException; /** - * Main class for Limelight-pc contains methods for starting the application as well - * as the stream to the host pc. + * Main class for Limelight-pi * @author Diego Waxemberg
* Cameron Gutman + * Iwan Timmer */ public class Limelight implements NvConnectionListener { public static final double VERSION = 1.0; @@ -64,6 +63,9 @@ public class Limelight implements NvConnectionListener { PlatformBinding.getVideoDecoderRenderer()); } + /** + * Pair the device with the host + */ private void pair() { String macAddress; try { @@ -110,13 +112,6 @@ public class Limelight implements NvConnectionListener { * @param args unused. */ public static void main(String args[]) { - LibraryHelper.prepareNativeLibraries(); - - parseCommandLine(args); - } - - //TODO: make this less jank - private static void parseCommandLine(String[] args) { String host = null; List inputs = new ArrayList(); boolean pair = false; diff --git a/src/com/limelight/binding/LibraryHelper.java b/src/com/limelight/binding/LibraryHelper.java deleted file mode 100644 index cb254d0..0000000 --- a/src/com/limelight/binding/LibraryHelper.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.limelight.binding; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; - -public class LibraryHelper { - private static final HashSet avcDependencies = new HashSet(); - private static final boolean needsDependencyExtraction; - private static final String libraryExtractionFolder; - - private static boolean librariesExtracted = false; - - static { - needsDependencyExtraction = System.getProperty("os.name").contains("Windows"); - libraryExtractionFolder = System.getProperty("java.io.tmpdir", "."); - - // The AVC JNI library itself - avcDependencies.add("nv_avc_dec"); - } - - public static void loadNativeLibrary(String libraryName) { - if (librariesExtracted && avcDependencies.contains(libraryName)) { - System.load(libraryExtractionFolder + File.separatorChar + System.mapLibraryName(libraryName)); - } - else { - System.loadLibrary(libraryName); - } - } - - public static void prepareNativeLibraries() { - if (!needsDependencyExtraction) { - return; - } - - try { - for (String dependency : avcDependencies) { - extractNativeLibrary(dependency); - } - } catch (IOException e) { - // This is expected if this code is not running from a JAR - return; - } - - librariesExtracted = true; - } - - private static void extractNativeLibrary(String libraryName) throws IOException { - // convert general library name to platform-specific name - libraryName = System.mapLibraryName(libraryName); - - InputStream resource = new Object().getClass().getResourceAsStream("/binlib/"+libraryName); - if (resource == null) { - throw new FileNotFoundException("Unable to find native library in JAR: "+libraryName); - } - File destination = new File(libraryExtractionFolder+File.separatorChar+libraryName); - - // this will only delete it if it exists, and then create a new file - destination.delete(); - destination.createNewFile(); - - // schedule the temporary file to be deleted when the program exits - destination.deleteOnExit(); - - //this is the janky java 6 way to copy a file - FileOutputStream fos = null; - try { - fos = new FileOutputStream(destination); - int read; - byte[] readBuffer = new byte[16384]; - while ((read = resource.read(readBuffer)) != -1) { - fos.write(readBuffer, 0, read); - } - } finally { - if (fos != null) { - fos.close(); - } - } - } - - public static boolean isRunningFromJar() { - String classPath = LibraryHelper.class.getResource("LibraryHelper.class").toString(); - return classPath.startsWith("jar:"); - } -} diff --git a/src/com/limelight/binding/PlatformBinding.java b/src/com/limelight/binding/PlatformBinding.java index cbf0583..3f22d70 100644 --- a/src/com/limelight/binding/PlatformBinding.java +++ b/src/com/limelight/binding/PlatformBinding.java @@ -10,7 +10,8 @@ import com.limelight.nvstream.av.video.VideoDecoderRenderer; /** * Used for platform-specific video/audio bindings. - * @author Cameron Gutman + * @author Cameron Gutman
+ * Iwan Timmer */ public class PlatformBinding { /** diff --git a/src/com/limelight/binding/audio/JavaxAudioRenderer.java b/src/com/limelight/binding/audio/JavaxAudioRenderer.java index 7027767..f3f772e 100644 --- a/src/com/limelight/binding/audio/JavaxAudioRenderer.java +++ b/src/com/limelight/binding/audio/JavaxAudioRenderer.java @@ -13,7 +13,8 @@ import java.util.LinkedList; /** * Audio renderer implementation - * @author Cameron Gutman + * @author Cameron Gutman
+ * Iwan Timmer */ public class JavaxAudioRenderer implements AudioRenderer { diff --git a/src/com/limelight/binding/video/OmxDecoder.java b/src/com/limelight/binding/video/OmxDecoder.java index 51bb90a..8ce71ec 100644 --- a/src/com/limelight/binding/video/OmxDecoder.java +++ b/src/com/limelight/binding/video/OmxDecoder.java @@ -1,10 +1,12 @@ package com.limelight.binding.video; -import com.limelight.binding.LibraryHelper; - +/** + * JNI Decoder bindings + * @author Iwan Timmer + */ public class OmxDecoder { static { - LibraryHelper.loadNativeLibrary("nv_omx_dec"); + System.loadLibrary("nv_omx_dec"); } public static native int init(); diff --git a/src/com/limelight/input/Device.java b/src/com/limelight/input/Device.java deleted file mode 100644 index 901e332..0000000 --- a/src/com/limelight/input/Device.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.limelight.input; - -public class Device { - private int id; - private int numButtons; - private int numAxes; - - public Device(int deviceID, int numButtons, int numAxes) { - this.id = deviceID; - this.numButtons = numButtons; - this.numAxes = numAxes; - } - - public int getId() { - return id; - } - - public int getNumButtons() { - return numButtons; - } - - public int getNumAxes() { - return numAxes; - } -} diff --git a/src/com/limelight/input/DeviceListener.java b/src/com/limelight/input/DeviceListener.java deleted file mode 100644 index d344beb..0000000 --- a/src/com/limelight/input/DeviceListener.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.limelight.input; - -public interface DeviceListener { - public void handleButton(Device device, int buttonId, boolean pressed); - public void handleAxis(Device device, int axisId, float newValue, float lastValue); -}