From b2515427b46b24c815031f202fdf216812f34d25 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 13 Jun 2012 19:40:49 +0000 Subject: [PATCH] video library updates --- .../Capture/AsciiVideo/AsciiVideo.pde | 11 +-- .../BackgroundSubtraction.pde | 2 +- .../BrightnessThresholding.pde | 2 +- .../BrightnessTracking/BrightnessTracking.pde | 2 +- .../Capture/ColorSorting/ColorSorting.pde | 9 +- .../examples/Capture/ColorSorting/Tuple.pde | 10 +- .../examples/Capture/Disgrand/Disgrand.pde | 9 +- .../video/examples/Capture/Disgrand/Tuple.pde | 10 +- .../FrameDifferencing/FrameDifferencing.pde | 2 +- .../Capture/Framingham/Framingham.pde | 5 +- .../GettingStartedCapture.pde | 2 +- .../examples/Capture/HsvSpace/HsvSpace.pde | 7 +- .../video/examples/Capture/HsvSpace/Tuple.pde | 12 +-- .../examples/Capture/LivePocky/LivePocky.pde | 2 +- .../video/examples/Capture/Mirror/Mirror.pde | 2 +- .../examples/Capture/Mirror2/Mirror2.pde | 2 +- .../Capture/RadialPocky/RadialPocky.pde | 2 +- .../examples/Capture/SlitScan/SlitScan.pde | 2 +- .../video/examples/Movie/Reverse/Reverse.pde | 6 +- .../video/examples/Movie/Speed/Speed.pde | 6 +- .../video/src/processing/video/Capture.java | 33 ++++--- .../src/processing/video/LibraryPath.java | 17 ---- .../video/src/processing/video/Movie.java | 29 +++--- .../video/src/processing/video/Video.java | 93 ++++++++++--------- 24 files changed, 137 insertions(+), 140 deletions(-) diff --git a/java/libraries/video/examples/Capture/AsciiVideo/AsciiVideo.pde b/java/libraries/video/examples/Capture/AsciiVideo/AsciiVideo.pde index aea1272a3..b332e59e3 100644 --- a/java/libraries/video/examples/Capture/AsciiVideo/AsciiVideo.pde +++ b/java/libraries/video/examples/Capture/AsciiVideo/AsciiVideo.pde @@ -26,10 +26,8 @@ PFont font; float fontSize = 1.5; -public void setup() { - size(640, 480, P3D); - // Or run full screen, more fun! Use with Sketch -> Present - //size(screen.width, screen.height, OPENGL); +void setup() { + size(640, 480, P2D); // Uses the default video input, see the reference if this causes an error video = new Capture(this, 160, 120); @@ -59,7 +57,7 @@ public void setup() { } -public void captureEvent(Capture c) { +void captureEvent(Capture c) { c.read(); } @@ -76,6 +74,7 @@ void draw() { textFont(font, fontSize); int index = 0; + video.loadPixels(); for (int y = 1; y < video.height; y++) { // Move down for next line @@ -127,7 +126,7 @@ void draw() { * 'g' grabs an image and saves the frame to a tiff image * 'f' and 'F' increase and decrease the font size */ -public void keyPressed() { +void keyPressed() { switch (key) { case 'g': saveFrame(); break; case 'c': cheatScreen = !cheatScreen; break; diff --git a/java/libraries/video/examples/Capture/BackgroundSubtraction/BackgroundSubtraction.pde b/java/libraries/video/examples/Capture/BackgroundSubtraction/BackgroundSubtraction.pde index 35c00c2a8..06e47d0e9 100644 --- a/java/libraries/video/examples/Capture/BackgroundSubtraction/BackgroundSubtraction.pde +++ b/java/libraries/video/examples/Capture/BackgroundSubtraction/BackgroundSubtraction.pde @@ -15,7 +15,7 @@ Capture video; void setup() { // Change size to 320 x 240 if too slow at 640 x 480 - size(640, 480); + size(640, 480, P2D); video = new Capture(this, width, height); video.start(); diff --git a/java/libraries/video/examples/Capture/BrightnessThresholding/BrightnessThresholding.pde b/java/libraries/video/examples/Capture/BrightnessThresholding/BrightnessThresholding.pde index 7f9d65439..0de1b4f98 100644 --- a/java/libraries/video/examples/Capture/BrightnessThresholding/BrightnessThresholding.pde +++ b/java/libraries/video/examples/Capture/BrightnessThresholding/BrightnessThresholding.pde @@ -15,7 +15,7 @@ int numPixels; Capture video; void setup() { - size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 + size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480 strokeWeight(5); // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height); diff --git a/java/libraries/video/examples/Capture/BrightnessTracking/BrightnessTracking.pde b/java/libraries/video/examples/Capture/BrightnessTracking/BrightnessTracking.pde index 649e3866d..bf0cf9ee5 100644 --- a/java/libraries/video/examples/Capture/BrightnessTracking/BrightnessTracking.pde +++ b/java/libraries/video/examples/Capture/BrightnessTracking/BrightnessTracking.pde @@ -11,7 +11,7 @@ import processing.video.*; Capture video; void setup() { - size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 + size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height); video.start(); diff --git a/java/libraries/video/examples/Capture/ColorSorting/ColorSorting.pde b/java/libraries/video/examples/Capture/ColorSorting/ColorSorting.pde index 631aa264d..f84e63571 100644 --- a/java/libraries/video/examples/Capture/ColorSorting/ColorSorting.pde +++ b/java/libraries/video/examples/Capture/ColorSorting/ColorSorting.pde @@ -20,8 +20,8 @@ int[] bright; int increment = 5; -public void setup() { - size(800, 600, P3D); +void setup() { + size(800, 600, P2D); noCursor(); // Uses the default video input, see the reference if this causes an error @@ -39,9 +39,10 @@ public void setup() { } -public void draw() { +void draw() { if (video.available()) { video.read(); + video.loadPixels(); background(0); noStroke(); @@ -85,7 +86,7 @@ public void draw() { } -public void keyPressed() { +void keyPressed() { if (key == 'g') { saveFrame(); } else if (key == 'c') { diff --git a/java/libraries/video/examples/Capture/ColorSorting/Tuple.pde b/java/libraries/video/examples/Capture/ColorSorting/Tuple.pde index fe6d1d9af..c3d8b5900 100644 --- a/java/libraries/video/examples/Capture/ColorSorting/Tuple.pde +++ b/java/libraries/video/examples/Capture/ColorSorting/Tuple.pde @@ -3,26 +3,26 @@ class Tuple { float x, y, z; - public Tuple() { } + Tuple() { } - public Tuple(float x, float y, float z) { + Tuple(float x, float y, float z) { set(x, y, z); } - public void set(float x, float y, float z) { + void set(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } - public void target(Tuple another, float amount) { + void target(Tuple another, float amount) { float amount1 = 1.0 - amount; x = x*amount1 + another.x*amount; y = y*amount1 + another.y*amount; z = z*amount1 + another.z*amount; } - public void phil() { + void phil() { fill(x, y, z); } } diff --git a/java/libraries/video/examples/Capture/Disgrand/Disgrand.pde b/java/libraries/video/examples/Capture/Disgrand/Disgrand.pde index 56dfa8975..b3b802a86 100644 --- a/java/libraries/video/examples/Capture/Disgrand/Disgrand.pde +++ b/java/libraries/video/examples/Capture/Disgrand/Disgrand.pde @@ -19,8 +19,8 @@ int[] bright; int increment = 5; -public void setup() { - size(800, 600, P3D); +void setup() { + size(800, 600, P2D); noCursor(); // Uses the default video input, see the reference if this causes an error @@ -38,9 +38,10 @@ public void setup() { } -public void draw() { +void draw() { if (video.available()) { video.read(); + video.loadPixels(); background(0); noStroke(); @@ -84,7 +85,7 @@ public void draw() { } -public void keyPressed() { +void keyPressed() { if (key == 'g') { saveFrame(); } else if (key == 'c') { diff --git a/java/libraries/video/examples/Capture/Disgrand/Tuple.pde b/java/libraries/video/examples/Capture/Disgrand/Tuple.pde index fe6d1d9af..c3d8b5900 100644 --- a/java/libraries/video/examples/Capture/Disgrand/Tuple.pde +++ b/java/libraries/video/examples/Capture/Disgrand/Tuple.pde @@ -3,26 +3,26 @@ class Tuple { float x, y, z; - public Tuple() { } + Tuple() { } - public Tuple(float x, float y, float z) { + Tuple(float x, float y, float z) { set(x, y, z); } - public void set(float x, float y, float z) { + void set(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } - public void target(Tuple another, float amount) { + void target(Tuple another, float amount) { float amount1 = 1.0 - amount; x = x*amount1 + another.x*amount; y = y*amount1 + another.y*amount; z = z*amount1 + another.z*amount; } - public void phil() { + void phil() { fill(x, y, z); } } diff --git a/java/libraries/video/examples/Capture/FrameDifferencing/FrameDifferencing.pde b/java/libraries/video/examples/Capture/FrameDifferencing/FrameDifferencing.pde index ca7e464b3..58380e7fc 100644 --- a/java/libraries/video/examples/Capture/FrameDifferencing/FrameDifferencing.pde +++ b/java/libraries/video/examples/Capture/FrameDifferencing/FrameDifferencing.pde @@ -13,7 +13,7 @@ int[] previousFrame; Capture video; void setup() { - size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 + size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new Capture(this, width, height); video.start(); diff --git a/java/libraries/video/examples/Capture/Framingham/Framingham.pde b/java/libraries/video/examples/Capture/Framingham/Framingham.pde index 057834bff..51062711d 100644 --- a/java/libraries/video/examples/Capture/Framingham/Framingham.pde +++ b/java/libraries/video/examples/Capture/Framingham/Framingham.pde @@ -1,3 +1,5 @@ +// Currently broken with the P2D renderer. + /** * Framingham * by Ben Fry. @@ -18,7 +20,7 @@ int[] scoot; void setup() { - size(640, 480, P3D); + size(640, 480, P2D); // Uses the default video input, see the reference if this causes an error video = new Capture(this, 160, 120); @@ -39,6 +41,7 @@ void draw() { // By using video.available, only the frame rate need be set inside setup() if (video.available()) { video.read(); + video.loadPixels(); set(video.width*column, video.height*lastRow, video); column++; if (column == columnCount) { diff --git a/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde b/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde index a7a6838eb..28ec1600f 100644 --- a/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde +++ b/java/libraries/video/examples/Capture/GettingStartedCapture/GettingStartedCapture.pde @@ -9,7 +9,7 @@ import processing.video.*; Capture cam; void setup() { - size(640, 480); + size(640, 480, P2D); String[] cameras = Capture.list(); diff --git a/java/libraries/video/examples/Capture/HsvSpace/HsvSpace.pde b/java/libraries/video/examples/Capture/HsvSpace/HsvSpace.pde index 020f716d7..9faf65dcd 100644 --- a/java/libraries/video/examples/Capture/HsvSpace/HsvSpace.pde +++ b/java/libraries/video/examples/Capture/HsvSpace/HsvSpace.pde @@ -34,9 +34,8 @@ boolean motion; boolean blobby = false; -public void setup() { +void setup() { size(640, 480, P3D); - //size(screen.width, screen.height, OPENGL); video = new Capture(this, 160, 120); video.start(); @@ -84,6 +83,7 @@ void draw() { } noStroke(); + video.loadPixels(); for (int i = 0; i < count; i++) { int pixelColor = video.pixels[i]; int r = (pixelColor >> 16) & 0xff; @@ -133,7 +133,6 @@ void draw() { void captureEvent(Capture c) { c.read(); - c.loadPixels(); } @@ -200,7 +199,7 @@ void wireCone(float radius, float height, int stepX, int stepY) { noFill(); pushMatrix(); translate(0, 0, height); - ellipseMode(CENTER_RADIUS); + ellipseMode(CENTER); ellipse(0, 0, radius, radius); popMatrix(); } diff --git a/java/libraries/video/examples/Capture/HsvSpace/Tuple.pde b/java/libraries/video/examples/Capture/HsvSpace/Tuple.pde index f4c898a33..19c1507aa 100644 --- a/java/libraries/video/examples/Capture/HsvSpace/Tuple.pde +++ b/java/libraries/video/examples/Capture/HsvSpace/Tuple.pde @@ -3,30 +3,30 @@ class Tuple { float x, y, z; - public Tuple() { } + Tuple() { } - public Tuple(float x, float y, float z) { + Tuple(float x, float y, float z) { set(x, y, z); } - public void set(float x, float y, float z) { + void set(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } - public void target(Tuple another, float amount) { + void target(Tuple another, float amount) { float amount1 = 1.0 - amount; x = x*amount1 + another.x*amount; y = y*amount1 + another.y*amount; z = z*amount1 + another.z*amount; } - public void phil() { + void phil() { fill(x, y, z); } - public void tran() { + void tran() { translate(x, y, z); } } diff --git a/java/libraries/video/examples/Capture/LivePocky/LivePocky.pde b/java/libraries/video/examples/Capture/LivePocky/LivePocky.pde index a2048559e..3dbe46c24 100644 --- a/java/libraries/video/examples/Capture/LivePocky/LivePocky.pde +++ b/java/libraries/video/examples/Capture/LivePocky/LivePocky.pde @@ -16,7 +16,7 @@ int buffer[]; void setup() { - size(600, 400); + size(600, 400, P2D); // Uses the default video input, see the reference if this causes an error video = new Capture(this, 160, 120); diff --git a/java/libraries/video/examples/Capture/Mirror/Mirror.pde b/java/libraries/video/examples/Capture/Mirror/Mirror.pde index 9a3181967..5ef7520a2 100644 --- a/java/libraries/video/examples/Capture/Mirror/Mirror.pde +++ b/java/libraries/video/examples/Capture/Mirror/Mirror.pde @@ -17,7 +17,7 @@ Capture video; void setup() { - size(640, 480, P3D); + size(640, 480, P2D); frameRate(30); cols = width / cellSize; rows = height / cellSize; diff --git a/java/libraries/video/examples/Capture/Mirror2/Mirror2.pde b/java/libraries/video/examples/Capture/Mirror2/Mirror2.pde index ecdffb67f..0fc538927 100644 --- a/java/libraries/video/examples/Capture/Mirror2/Mirror2.pde +++ b/java/libraries/video/examples/Capture/Mirror2/Mirror2.pde @@ -16,7 +16,7 @@ Capture video; void setup() { - size(640, 480, P3D); + size(640, 480, P2D); //set up columns and rows cols = width / cellSize; rows = height / cellSize; diff --git a/java/libraries/video/examples/Capture/RadialPocky/RadialPocky.pde b/java/libraries/video/examples/Capture/RadialPocky/RadialPocky.pde index 84051e2d9..a4e640204 100644 --- a/java/libraries/video/examples/Capture/RadialPocky/RadialPocky.pde +++ b/java/libraries/video/examples/Capture/RadialPocky/RadialPocky.pde @@ -19,7 +19,7 @@ int angles[]; void setup() { // size must be set to video.width*video.height*2 in both directions - size(600, 600); + size(600, 600, P2D); // Uses the default video input, see the reference if this causes an error video = new Capture(this, 160, 120); diff --git a/java/libraries/video/examples/Capture/SlitScan/SlitScan.pde b/java/libraries/video/examples/Capture/SlitScan/SlitScan.pde index bbcd911e4..2275c4f67 100644 --- a/java/libraries/video/examples/Capture/SlitScan/SlitScan.pde +++ b/java/libraries/video/examples/Capture/SlitScan/SlitScan.pde @@ -18,7 +18,7 @@ int videoSliceX; int drawPositionX; void setup() { - size(600, 240); + size(600, 240, P2D); // Uses the default video input, see the reference if this causes an error video = new Capture(this, 320, 240); diff --git a/java/libraries/video/examples/Movie/Reverse/Reverse.pde b/java/libraries/video/examples/Movie/Reverse/Reverse.pde index 09cc41136..883b39567 100644 --- a/java/libraries/video/examples/Movie/Reverse/Reverse.pde +++ b/java/libraries/video/examples/Movie/Reverse/Reverse.pde @@ -18,18 +18,18 @@ import processing.video.*; Movie myMovie; boolean speedSet = false; -public void setup() { +void setup() { size(320, 240); background(0); myMovie = new Movie(this, "balloon.ogg"); myMovie.play(); } -public void movieEvent(Movie myMovie) { +void movieEvent(Movie myMovie) { myMovie.read(); } -public void draw() { +void draw() { if (myMovie.ready()) { if (!speedSet) { // Setting the speed should be done only once, diff --git a/java/libraries/video/examples/Movie/Speed/Speed.pde b/java/libraries/video/examples/Movie/Speed/Speed.pde index 7fb235538..3f5b2090b 100644 --- a/java/libraries/video/examples/Movie/Speed/Speed.pde +++ b/java/libraries/video/examples/Movie/Speed/Speed.pde @@ -10,7 +10,7 @@ import processing.video.*; Movie movie; -public void setup() { +void setup() { size(320, 240); background(0); movie = new Movie(this, "balloon.ogg"); @@ -20,11 +20,11 @@ public void setup() { textFont(font, 24); } -public void movieEvent(Movie movie) { +void movieEvent(Movie movie) { movie.read(); } -public void draw() { +void draw() { image(movie, 0, 0, width, height); float newSpeed = map(mouseX, 0, width, 0.1, 2); diff --git a/java/libraries/video/src/processing/video/Capture.java b/java/libraries/video/src/processing/video/Capture.java index 8134070db..8648f58fc 100644 --- a/java/libraries/video/src/processing/video/Capture.java +++ b/java/libraries/video/src/processing/video/Capture.java @@ -109,7 +109,7 @@ public class Capture extends PImage implements PConstants { protected int reqHeight; protected boolean useBufferSink = false; - protected boolean useGLSink = true; +// protected boolean useGLSink = true; protected Object bufferSink; protected Method sinkCopyMethod; protected Method sinkSetMethod; @@ -253,7 +253,7 @@ public class Capture extends PImage implements PConstants { * * @return boolean */ - public boolean newFrame() { + public synchronized boolean newFrame() { boolean res = newFrame; newFrame = false; return res; @@ -338,9 +338,9 @@ public class Capture extends PImage implements PConstants { * @usage web_application */ public synchronized void read() { - // We loadPixels() first to ensure that at least we always have a non-null - // pixels array, even if without any valid image inside. - loadPixels(); +// if (pixels == null) { +// pixels = new int[width * height]; +// } if (useBufferSink) { // The native buffer from gstreamer is copied to the buffer sink. if (natBuffer == null) { @@ -349,7 +349,7 @@ public class Capture extends PImage implements PConstants { if (firstFrame) { super.init(bufWidth, bufHeight, ARGB); - loadPixels(); + //loadPixels(); firstFrame = false; } @@ -378,7 +378,7 @@ public class Capture extends PImage implements PConstants { if (firstFrame) { super.init(bufWidth, bufHeight, RGB); - loadPixels(); + //loadPixels(); firstFrame = false; } @@ -631,7 +631,7 @@ public class Capture extends PImage implements PConstants { fpsStr = ", framerate=" + fps; } - if (bufferSink != null || (useGLSink && parent.g.isGL())) { + if (bufferSink != null || (Video.useGLBufferSink && parent.g.isGL())) { useBufferSink = true; if (bufferSink != null) { @@ -671,10 +671,9 @@ public class Capture extends PImage implements PConstants { public void rgbFrame(int w, int h, IntBuffer buffer) { invokeEvent(w, h, buffer); } - }); - // Setting direct buffer passing in the video sink, so no new buffers are created - // and disposed by the GC on each frame (thanks to Octavi Estape for pointing - // out this one). + }); + + // Setting direct buffer passing in the video sink. rgbSink.setPassDirectBuffer(Video.passDirectBuffer); // No need for rgbSink.dispose(), because the addMany() doesn't increment the @@ -817,9 +816,9 @@ public class Capture extends PImage implements PConstants { * renderers. * */ - public void noGL() { - useGLSink = false; - } +// public void noGL() { +// useGLSink = false; +// } /** * Sets the object to use as destination for the frames read from the stream. @@ -844,6 +843,10 @@ public class Capture extends PImage implements PConstants { copyMask = mask; } + public boolean hasBufferSink() { + return bufferSink != null; + } + public synchronized void disposeBuffer(Object buf) { ((Buffer)buf).dispose(); } diff --git a/java/libraries/video/src/processing/video/LibraryPath.java b/java/libraries/video/src/processing/video/LibraryPath.java index d8f16d876..ccabe2467 100644 --- a/java/libraries/video/src/processing/video/LibraryPath.java +++ b/java/libraries/video/src/processing/video/LibraryPath.java @@ -39,23 +39,6 @@ class LibraryPath { int n0 = path.indexOf('/'); int n1 = -1; - /* - if (Platform.isWindows()) { - n1 = path.indexOf("/lib/video.jar"); // location of video.jar in - // exported apps. - if (n1 == -1) - n1 = path.indexOf("/video.jar"); // location of video.jar in - // library folder. - - // In Windows, path string starts with "jar file/C:/..." - // so the substring up to the first / is removed. - n0++; - } else if (Platform.isMac()) { - // In Mac, getting the index of video.jar is enough in the case of sketches running from the PDE - // as well as exported applications. - n1 = path.indexOf("video.jar"); - */ - if (Platform.isLinux()) { return ""; diff --git a/java/libraries/video/src/processing/video/Movie.java b/java/libraries/video/src/processing/video/Movie.java index 364fa9ed0..ca84bd10b 100644 --- a/java/libraries/video/src/processing/video/Movie.java +++ b/java/libraries/video/src/processing/video/Movie.java @@ -80,7 +80,7 @@ public class Movie extends PImage implements PConstants { protected boolean seeking = false; protected boolean useBufferSink = false; - protected boolean useGLSink = true; +// protected boolean useGLSink = true; protected Object bufferSink; protected Method sinkCopyMethod; protected Method sinkSetMethod; @@ -528,11 +528,7 @@ public class Movie extends PImage implements PConstants { // which is already playing since we are in read(). fps = getSourceFrameRate(); } - - // We loadPixels() first to ensure that at least we always have a non-null - // pixels array, even if without any valid image inside. - loadPixels(); - + if (useBufferSink) { // The native buffer from gstreamer is copied to the buffer sink. if (natBuffer == null) { return; @@ -540,7 +536,7 @@ public class Movie extends PImage implements PConstants { if (firstFrame) { super.init(bufWidth, bufHeight, ARGB); - loadPixels(); + //loadPixels(); firstFrame = false; } @@ -568,7 +564,8 @@ public class Movie extends PImage implements PConstants { } if (firstFrame) { - resize(bufWidth, bufHeight); + //resize(bufWidth, bufHeight); + super.init(bufWidth, bufHeight, RGB); firstFrame = false; } @@ -726,7 +723,7 @@ public class Movie extends PImage implements PConstants { } protected void initSink() { - if (bufferSink != null || (useGLSink && parent.g.isGL())) { + if (bufferSink != null || (Video.useGLBufferSink && parent.g.isGL())) { useBufferSink = true; if (bufferSink != null) { @@ -758,9 +755,7 @@ public class Movie extends PImage implements PConstants { } }); - // Setting direct buffer passing in the video sink, so no new buffers are created - // and disposed by the GC on each frame (thanks to Octavi Estape for pointing - // out this one). + // Setting direct buffer passing in the video sink. rgbSink.setPassDirectBuffer(Video.passDirectBuffer); gplayer.setVideoSink(rgbSink); // The setVideoSink() method sets the videoSink as a property of the PlayBin, @@ -859,9 +854,9 @@ public class Movie extends PImage implements PConstants { * renderers. * */ - public void noGL() { - useGLSink = false; - } +// public void noGL() { +// useGLSink = false; +// } /** * Sets the object to use as destination for the frames read from the stream. @@ -885,6 +880,10 @@ public class Movie extends PImage implements PConstants { bufferSink = sink; copyMask = mask; } + + public boolean hasBufferSink() { + return bufferSink != null; + } public synchronized void disposeBuffer(Object buf) { ((Buffer)buf).dispose(); diff --git a/java/libraries/video/src/processing/video/Video.java b/java/libraries/video/src/processing/video/Video.java index a7a7aaebb..bfd7319b6 100644 --- a/java/libraries/video/src/processing/video/Video.java +++ b/java/libraries/video/src/processing/video/Video.java @@ -37,48 +37,57 @@ import java.util.List; * this library. */ public class Video implements PConstants { - protected static long INSTANCES_COUNT = 0; + // Streams type constants. + static public final int AUDIO = 0; + static public final int VIDEO = 1; + static public final int RAW = 2; - protected static String gstreamerBinPath = ""; - protected static String gstreamerPluginsPath = ""; - - protected static boolean defaultGLibContext = false; - - // Priority is given to global install of GStreamer if this is set to true. - public static boolean globalGStreamer = false; - - // Direct buffer pass enabled by default. - public static boolean passDirectBuffer = true; - - public static String globalGStreamerPath; - public static String globalPluginsFolder = "gstreamer-0.10"; + // Priority is given to the system install of GStreamer if this is set to true. + public static boolean systemGStreamer = false; + public static String systemGStreamerPath; + public static String systemPluginsFolder = "gstreamer-0.10"; // Default locations of the global install of gstreamer for each platform: static { if (PApplet.platform == MACOSX) { - globalGStreamerPath = "/System/Library/Frameworks/GStreamer.framework/Versions/Current/lib"; + systemGStreamerPath = "/System/Library/Frameworks/GStreamer.framework/Versions/Current/lib"; } else if (PApplet.platform == WINDOWS) { - globalGStreamerPath = ""; + systemGStreamerPath = ""; } else if (PApplet.platform == LINUX) { - globalGStreamerPath = "/usr/lib"; + systemGStreamerPath = "/usr/lib"; } else {} } - - protected static int bitsJVM; - static { - bitsJVM = PApplet.parseInt(System.getProperty("sun.arch.data.model")); - } - + // Default location of the local install of gstreamer. Suggested by Charles Bourasseau. // When it is left as empty string, GSVideo will attempt to use the path from GSLibraryPath.get(), // otherwise it will use it as the path to the folder where the libgstreamer.dylib and other // files are located. public static String localGStreamerPath = ""; public static String localPluginsFolder = "plugins"; + + // Direct buffer pass enabled by default. With this mode enabled, no new buffers are created + // and disposed by the GC in each frame (thanks to Octavi Estape for suggesting this improvement) + // which should help performance in most situations. + public static boolean passDirectBuffer = true; + + // OpenGL texture used as buffer sink by default, when the renderer is GL-based. This + // can improve performance significantly, since the video frames are automatically + // copied into the texture without passing through the pixels arrays, as well as + // having the color conversion into RGBA handled natively by gstreamer. + public static boolean useGLBufferSink = false; - // Some constants to identify AUDIO, VIDEO and RAW streams. - static public final int AUDIO = 0; - static public final int VIDEO = 1; - static public final int RAW = 2; + // Path that the video library will use to load the gstreamer native libs from. + // It is buit either from the system or local paths. + protected static String gstreamerBinPath = ""; + protected static String gstreamerPluginsPath = ""; + + protected static boolean defaultGLibContext = false; + + protected static long INSTANCES_COUNT = 0; + + protected static int bitsJVM; + static { + bitsJVM = PApplet.parseInt(System.getProperty("sun.arch.data.model")); + } static public void init() { if (INSTANCES_COUNT == 0) { @@ -96,7 +105,7 @@ public class Video implements PConstants { static protected void initImpl() { if (PApplet.platform == LINUX) { // Linux only supports global gstreamer for now. - globalGStreamer = true; + systemGStreamer = true; setLinuxPath(); } else if (PApplet.platform == WINDOWS) { setWindowsPath(); @@ -108,18 +117,18 @@ public class Video implements PConstants { System.setProperty("jna.library.path", gstreamerBinPath); } - if ((PApplet.platform == LINUX) && !globalGStreamer) { + if ((PApplet.platform == LINUX) && !systemGStreamer) { System.err.println("Loading local version of GStreamer not supported in Linux at this time."); } - if ((PApplet.platform == WINDOWS) && !globalGStreamer) { + if ((PApplet.platform == WINDOWS) && !systemGStreamer) { LibraryLoader loader = LibraryLoader.getInstance(); if (loader == null) { System.err.println("Cannot load local version of GStreamer libraries."); } } - if ((PApplet.platform == MACOSX) && !globalGStreamer) { + if ((PApplet.platform == MACOSX) && !systemGStreamer) { // Nothing to do here, since the dylib mechanism in OSX doesn't require the // library loader. } @@ -151,11 +160,11 @@ public class Video implements PConstants { } static protected void setLinuxPath() { - if (globalGStreamer && lookForGlobalGStreamer()) { + if (systemGStreamer && lookForGlobalGStreamer()) { gstreamerBinPath = ""; gstreamerPluginsPath = ""; } else { - globalGStreamer = false; + systemGStreamer = false; if (localGStreamerPath.equals("")) { LibraryPath libPath = new LibraryPath(); String path = libPath.get(); @@ -169,11 +178,11 @@ public class Video implements PConstants { } static protected void setWindowsPath() { - if (globalGStreamer && lookForGlobalGStreamer()) { + if (systemGStreamer && lookForGlobalGStreamer()) { gstreamerBinPath = ""; gstreamerPluginsPath = ""; } else { - globalGStreamer = false; + systemGStreamer = false; if (localGStreamerPath.equals("")) { LibraryPath libPath = new LibraryPath(); String path = libPath.get(); @@ -187,11 +196,11 @@ public class Video implements PConstants { } static protected void setMacOSXPath() { - if (globalGStreamer && lookForGlobalGStreamer()) { - gstreamerBinPath = globalGStreamerPath; - gstreamerPluginsPath = globalGStreamerPath + "/" + globalPluginsFolder; + if (systemGStreamer && lookForGlobalGStreamer()) { + gstreamerBinPath = systemGStreamerPath; + gstreamerPluginsPath = systemGStreamerPath + "/" + systemPluginsFolder; } else { - globalGStreamer = false; + systemGStreamer = false; if (localGStreamerPath.equals("")) { LibraryPath libPath = new LibraryPath(); String path = libPath.get(); @@ -210,8 +219,8 @@ public class Video implements PConstants { locPath = locPath.replace("/", System.getProperty("file.separator")); String[] searchPaths = null; - if (!globalGStreamerPath.equals("")) { - searchPaths = new String[] {globalGStreamerPath}; + if (!systemGStreamerPath.equals("")) { + searchPaths = new String[] {systemGStreamerPath}; } if (searchPaths == null) { @@ -223,7 +232,7 @@ public class Video implements PConstants { for (int i = 0; i < searchPaths.length; i++) { String path = searchPaths[i]; if ((locPath.equals("") || path.indexOf(locPath) == -1) && libgstreamerPresent(path, "libgstreamer")) { - globalGStreamerPath = path; + systemGStreamerPath = path; return true; } }