From e855c84953393d0cef683f20c197608656347c4c Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 10 Oct 2011 21:31:01 +0000 Subject: [PATCH] Simplified property setting in Capture --- .../GettingStartedCapture.pde | 2 +- .../video/src/processing/video/Capture.java | 77 +++++-------------- .../src/processing/video/Resolution.java | 2 +- 3 files changed, 23 insertions(+), 58 deletions(-) diff --git a/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde b/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde index 7ff820dd4..d4df059d2 100644 --- a/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde +++ b/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde @@ -33,7 +33,7 @@ void setup() { println("Supported resolutions:"); for (int i = 0; i < res.length; i++) { println(res[i].width + "x" + res[i].height + ", " + - res[i].fps + "fps (" + res[i].fpsString +")"); + res[i].fps + " fps (" + res[i].fpsString +")"); } } } diff --git a/java/libraries/video/src/processing/video/Capture.java b/java/libraries/video/src/processing/video/Capture.java index 5456a6d1f..f923edf7c 100644 --- a/java/libraries/video/src/processing/video/Capture.java +++ b/java/libraries/video/src/processing/video/Capture.java @@ -119,9 +119,7 @@ public class Capture extends PImage implements PConstants { */ public Capture(PApplet parent, int requestWidth, int requestHeight) { super(requestWidth, requestHeight, RGB); - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, - new String[] {}, new int[] {}, - new String[] {}, new String[] {}, ""); + initGStreamer(parent, requestWidth, requestHeight, capturePlugin, null, ""); } /** @@ -132,9 +130,7 @@ public class Capture extends PImage implements PConstants { */ public Capture(PApplet parent, int requestWidth, int requestHeight, int frameRate) { super(requestWidth, requestHeight, RGB); - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, - new String[] {}, new int[] {}, - new String[] {}, new String[] {}, frameRate + "/1"); + initGStreamer(parent, requestWidth, requestHeight, capturePlugin, null, frameRate + "/1"); } /** @@ -146,16 +142,14 @@ public class Capture extends PImage implements PConstants { */ public Capture(PApplet parent, int requestWidth, int requestHeight, String cameraName) { super(requestWidth, requestHeight, RGB); + HashMap properties = new HashMap(); if (devicePropertyName.equals("")) { // For plugins without device name property, the name is casted as an index - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, - new String[] { indexPropertyName }, new int[] { PApplet.parseInt(cameraName) }, - new String[] { }, new String[] { }, ""); + properties.put(indexPropertyName, PApplet.parseInt(cameraName)); } else { - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, - new String[] {}, new int[] {}, - new String[] { devicePropertyName }, new String[] { cameraName }, ""); + properties.put(devicePropertyName, cameraName); } + initGStreamer(parent, requestWidth, requestHeight, capturePlugin, properties, ""); } /** @@ -164,45 +158,24 @@ public class Capture extends PImage implements PConstants { */ public Capture(PApplet parent, int requestWidth, int requestHeight, String cameraName, int frameRate) { super(requestWidth, requestHeight, RGB); + HashMap properties = new HashMap(); if (devicePropertyName.equals("")) { // For plugins without device name property, the name is casted as an index - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, - new String[] { indexPropertyName }, new int[] { PApplet.parseInt(cameraName) }, - new String[] { }, new String[] { }, frameRate + "/1"); + properties.put(indexPropertyName, PApplet.parseInt(cameraName)); } else { - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, new String[] {}, new int[] {}, - new String[] { devicePropertyName }, new String[] { cameraName }, frameRate + "/1"); + properties.put(devicePropertyName, cameraName); } + initGStreamer(parent, requestWidth, requestHeight, capturePlugin, properties, frameRate + "/1"); } /** *

Advanced

- * This constructor allows to specify the camera name and the desired framerate. + * This constructor allows to specify the source element, properties and desired framerate (in fraction form). */ public Capture(PApplet parent, int requestWidth, int requestHeight, String sourceName, HashMap properties, String frameRate) { super(requestWidth, requestHeight, RGB); - - // ArrayList - - Iterator it = properties.keySet().iterator(); - while (it.hasNext()) { - String key = (String) it.next(); - Object prop = properties.get(key); - if (prop instanceof String) { - - } else if (prop instanceof Integer) { - - } else if (prop instanceof Float) { - - } - } - - /* - initGStreamer(parent, requestWidth, requestHeight, capturePlugin, new String[] {}, new int[] {}, - new String[] { devicePropertyName }, new String[] { cameraName }, frameRate + "/1"); - */ - + initGStreamer(parent, requestWidth, requestHeight, sourceName, properties, frameRate); } /** @@ -622,8 +595,7 @@ public class Capture extends PImage implements PConstants { // The main initialization here. protected void initGStreamer(PApplet parent, int requestWidth, int requestHeight, String sourceName, - String[] intPropNames, int[] intPropValues, - String[] strPropNames, String[] strPropValues, String frameRate) { + HashMap properties, String frameRate) { this.parent = parent; Video.init(); @@ -642,22 +614,15 @@ public class Capture extends PImage implements PConstants { reqHeight = requestHeight; gsource = ElementFactory.make(sourceName, "Source"); - - if (intPropNames.length != intPropValues.length) { - parent.die("Error: number of integer property names is different from number of values.", null); + + if (properties != null) { + Iterator it = properties.keySet().iterator(); + while (it.hasNext()) { + String name = (String) it.next(); + Object value = properties.get(name); + gsource.set(name, value); + } } - - for (int i = 0; i < intPropNames.length; i++) { - gsource.set(intPropNames[i], intPropValues[i]); - } - - if (strPropNames.length != strPropValues.length) { - parent.die("Error: number of string property names is different from number of values.", null); - } - - for (int i = 0; i < strPropNames.length; i++) { - gsource.set(strPropNames[i], strPropValues[i]); - } bufWidth = bufHeight = 0; pipelineReady = false; diff --git a/java/libraries/video/src/processing/video/Resolution.java b/java/libraries/video/src/processing/video/Resolution.java index bf55e77d5..3ecf5fe2d 100644 --- a/java/libraries/video/src/processing/video/Resolution.java +++ b/java/libraries/video/src/processing/video/Resolution.java @@ -50,6 +50,6 @@ public class Resolution { } public String toString() { - return width + "x" + height + ", " + PApplet.nfc(fps, 2) + "fps (" + fpsString +")"; + return width + "x" + height + ", " + PApplet.nfc(fps, 2) + " fps (" + fpsString +")"; } } \ No newline at end of file