Skip to content

Commit

Permalink
using latest beta of gstreamer-java bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed Apr 3, 2019
1 parent 279a51a commit 6c7c716
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="library/gst1-java-core-0.9.1.jar"/>
<classpathentry kind="lib" path="library/jna.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
<classpathentry kind="lib" path="library/gst1-java-core-1.0.0-beta-2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
srcdir="src" destdir="bin"
encoding="UTF-8"
includeAntRuntime="false"
classpath="${core.classpath.location}/core.jar; library/gst1-java-core-0.9.1.jar; library/jna.jar"
classpath="${core.classpath.location}/core.jar; library/gst1-java-core-1.0.0-beta-2.jar; library/jna.jar"
nowarn="true">
<compilerclasspath path="${compiler.classpath.location}/org.eclipse.jdt.core.jar;
${compiler.classpath.location}/jdtCompilerAdapter.jar" />
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = http://processing.org/reference/libraries/video/index.html
category = Video & Vision
sentence = GStreamer-based video library for Processing.
paragraph =
version = 3
prettyVersion = 2.0-beta1
version = 4
prettyVersion = 2.0-beta2
minRevision = 228
maxRevision = 0
Binary file removed library/gst1-java-core-0.9.1.jar
Binary file not shown.
Binary file added library/gst1-java-core-1.0.0-beta-2.jar
Binary file not shown.
20 changes: 12 additions & 8 deletions src/processing/video/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.EnumSet;
import java.util.List;
import java.lang.reflect.*;

import org.freedesktop.gstreamer.*;
import org.freedesktop.gstreamer.Buffer;
import org.freedesktop.gstreamer.device.*;
import org.freedesktop.gstreamer.elements.*;
import org.freedesktop.gstreamer.event.SeekFlags;
import org.freedesktop.gstreamer.event.SeekType;


/**
Expand Down Expand Up @@ -270,8 +273,7 @@ public void frameRate(float ifps) {
stop = t;
}

res = pipe.seek(rate * f, Format.TIME, SeekFlags.FLUSH,
SeekType.SET, start, SeekType.SET, stop);
res = pipe.seek(rate * f, Format.TIME, EnumSet.of(SeekFlags.FLUSH, SeekFlags.ACCURATE), SeekType.SET, start, SeekType.SET, stop);
pipe.getState();

if (!res) {
Expand Down Expand Up @@ -330,8 +332,8 @@ public void speed(float irate) {
* @brief Returns length of movie in seconds
*/
public float duration() {
float sec = pipe.queryDuration().toSeconds();
float nanosec = pipe.queryDuration().getNanoSeconds();
float sec = pipe.queryDuration(TimeUnit.SECONDS);
float nanosec = pipe.queryDuration(TimeUnit.NANOSECONDS);
return sec + Video.nanoSecToSecFrac(nanosec);
}

Expand All @@ -349,8 +351,8 @@ public float duration() {
* @brief Returns location of playback head in units of seconds
*/
public float time() {
float sec = pipe.queryPosition().toSeconds();
float nanosec = pipe.queryPosition().getNanoSeconds();
float sec = pipe.queryDuration(TimeUnit.SECONDS);
float nanosec = pipe.queryDuration(TimeUnit.NANOSECONDS);
return sec + Video.nanoSecToSecFrac(nanosec);
}

Expand Down Expand Up @@ -750,9 +752,10 @@ protected void initGStreamer(PApplet parent) {

// look for device
if (devices == null) {
DeviceMonitor monitor = DeviceMonitor.createNew();
DeviceMonitor monitor = new DeviceMonitor();
monitor.addFilter("Video/Source", null);
devices = monitor.getDevices();
monitor.close();
}

for (int i=0; i < devices.size(); i++) {
Expand Down Expand Up @@ -1139,9 +1142,10 @@ static public String[] list() {
String[] out;
if (PApplet.platform == WINDOWS || PApplet.platform == LINUX) {

DeviceMonitor monitor = DeviceMonitor.createNew();
DeviceMonitor monitor = new DeviceMonitor();
monitor.addFilter("Video/Source", null);
devices = monitor.getDevices();
monitor.close();

out = new String[devices.size()];
for (int i=0; i < devices.size(); i++) {
Expand Down
58 changes: 33 additions & 25 deletions src/processing/video/Movie.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.*;
import java.net.URI;
import java.nio.*;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -38,6 +39,8 @@
import org.freedesktop.gstreamer.*;
import org.freedesktop.gstreamer.Buffer;
import org.freedesktop.gstreamer.elements.*;
import org.freedesktop.gstreamer.event.SeekFlags;
import org.freedesktop.gstreamer.event.SeekType;


/**
Expand All @@ -55,6 +58,8 @@
public class Movie extends PImage implements PConstants {
public static String[] supportedProtocols = { "http" };

protected int nativeWidth;
protected int nativeHeight;
protected float nativeFrameRate; // the file's native fps
public float frameRate; // the current playback fps
protected float rate; // speed multiplier (1.0: frameRate = nativeFrameRate)
Expand Down Expand Up @@ -212,8 +217,10 @@ public void frameRate(float ifps) {
stop = t;
}

res = playbin.seek(rate * f, Format.TIME, SeekFlags.FLUSH,
SeekType.SET, start, SeekType.SET, stop);
res = playbin.seek(rate * f, Format.TIME, EnumSet.of(SeekFlags.FLUSH, SeekFlags.ACCURATE), SeekType.SET, start, SeekType.SET, stop);



playbin.getState();

if (!res) {
Expand Down Expand Up @@ -267,8 +274,8 @@ public void speed(float irate) {
* @brief Returns length of movie in seconds
*/
public float duration() {
float sec = playbin.queryDuration().toSeconds();
float nanosec = playbin.queryDuration().getNanoSeconds();
float sec = playbin.queryDuration(TimeUnit.SECONDS);
float nanosec = playbin.queryDuration(TimeUnit.NANOSECONDS);
return sec + Video.nanoSecToSecFrac(nanosec);
}

Expand All @@ -286,8 +293,8 @@ public float duration() {
* @brief Returns location of playback head in units of seconds
*/
public float time() {
float sec = playbin.queryPosition().toSeconds();
float nanosec = playbin.queryPosition().getNanoSeconds();
float sec = playbin.queryDuration(TimeUnit.SECONDS);
float nanosec = playbin.queryDuration(TimeUnit.NANOSECONDS);
return sec + Video.nanoSecToSecFrac(nanosec);
}

Expand Down Expand Up @@ -323,8 +330,7 @@ public void jump(float where) {
boolean res;
long pos = Video.secToNanoLong(where);

res = playbin.seek(rate, Format.TIME, SeekFlags.FLUSH,
SeekType.SET, pos, SeekType.NONE, -1);
res = playbin.seek(rate, Format.TIME, EnumSet.of(SeekFlags.FLUSH, SeekFlags.ACCURATE), SeekType.SET, pos, SeekType.NONE, -1);

if (!res) {
PGraphics.showWarning("Seek operation failed.");
Expand Down Expand Up @@ -909,12 +915,13 @@ private void fireMovieEvent() {
* @return int
*/
protected int getSourceHeight() {
Dimension dim = playbin.getVideoSize();
if (dim != null) {
return dim.height;
} else {
return 0;
}
// Dimension dim = playbin.getVideoSize();
// if (dim != null) {
// return dim.height;
// } else {
// return 0;
// }
return nativeWidth;
}


Expand All @@ -939,12 +946,13 @@ protected float getSourceFrameRate() {
* @return int
*/
protected int getSourceWidth() {
Dimension dim = playbin.getVideoSize();
if (dim != null) {
return dim.width;
} else {
return 0;
}
// Dimension dim = playbin.getVideoSize();
// if (dim != null) {
// return dim.width;
// } else {
// return 0;
// }
return nativeHeight;
}


Expand Down Expand Up @@ -1061,8 +1069,8 @@ public FlowReturn newSample(AppSink sink) {

// pull out metadata from caps
Structure capsStruct = sample.getCaps().getStructure(0);
int w = capsStruct.getInteger("width");
int h = capsStruct.getInteger("height");
nativeWidth = capsStruct.getInteger("width");
nativeHeight = capsStruct.getInteger("height");
Fraction fps = capsStruct.getFraction("framerate");
nativeFrameRate = (float)fps.numerator / fps.denominator;

Expand All @@ -1082,10 +1090,10 @@ public FlowReturn newSample(AppSink sink) {
IntBuffer rgb = bb.asIntBuffer();

available = true;
bufWidth = w;
bufHeight = h;
bufWidth = nativeWidth;
bufHeight = nativeHeight;
if (copyPixels == null) {
copyPixels = new int[w * h];
copyPixels = new int[nativeWidth * nativeHeight];
}

try {
Expand Down

0 comments on commit 6c7c716

Please sign in to comment.