mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
The gstreamer library and plugin path can be passed to the video library using the gstreamer.library.path and gstreamer.plugin.path system properties
This commit is contained in:
@@ -34,27 +34,25 @@ import java.util.List;
|
||||
* this library.
|
||||
*/
|
||||
public class Video implements PConstants {
|
||||
// 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.
|
||||
protected static String gstreamerPath = "";
|
||||
|
||||
// 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.
|
||||
// Path that the video library will use to load the GStreamer base libraries
|
||||
// and plugins from. They can be passed from the application using the
|
||||
// gstreamer.library.path and gstreamer.plugin.path system variables (see
|
||||
// comments in initImpl() below).
|
||||
protected static String gstreamerLibPath = "";
|
||||
protected static String gstreamerPluginPath = "";
|
||||
|
||||
// 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.
|
||||
protected 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.
|
||||
protected static boolean useGLBufferSink = true;
|
||||
|
||||
// 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 = "";
|
||||
// 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.
|
||||
protected static boolean useGLBufferSink = true;
|
||||
|
||||
protected static boolean defaultGLibContext = false;
|
||||
|
||||
@@ -64,47 +62,55 @@ public class Video implements PConstants {
|
||||
static {
|
||||
bitsJVM = PApplet.parseInt(System.getProperty("sun.arch.data.model"));
|
||||
}
|
||||
|
||||
|
||||
static public void setLibPath(String path) {
|
||||
gstreamerPath = path;
|
||||
}
|
||||
|
||||
static String pluginPath = "plugins";
|
||||
static public void setPluginPath(String path) {
|
||||
pluginPath = path;
|
||||
}
|
||||
|
||||
|
||||
static public void useGL(boolean gl) {
|
||||
useGLBufferSink = gl;
|
||||
}
|
||||
|
||||
|
||||
static public void init() {
|
||||
static protected void init() {
|
||||
if (INSTANCES_COUNT == 0) {
|
||||
initImpl();
|
||||
}
|
||||
INSTANCES_COUNT++;
|
||||
}
|
||||
|
||||
static public void restart() {
|
||||
|
||||
static protected void restart() {
|
||||
removePlugins();
|
||||
Gst.deinit();
|
||||
initImpl();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static protected void initImpl() {
|
||||
if (PApplet.platform == LINUX) {
|
||||
setLinuxPath();
|
||||
} else if (PApplet.platform == WINDOWS) {
|
||||
setWindowsPath();
|
||||
} else if (PApplet.platform == MACOSX) {
|
||||
setMacOSXPath();
|
||||
}
|
||||
// The location of the GStreamer base libraries can be passed from the
|
||||
// application to the vide library via a system variable. In Eclipse, add to
|
||||
// "VM Arguments" in "Run Configurations" the following line:
|
||||
// -Dgstreamer.library.path=path
|
||||
String libPath = System.getProperty("gstreamer.library.path");
|
||||
if (libPath != null) {
|
||||
gstreamerLibPath = libPath;
|
||||
|
||||
// If the GStreamer installation referred by gstreamer.library.path is not
|
||||
// a system installation, then the path containing the plugins needs to be
|
||||
// specified separately, otherwise the plugins will be automatically
|
||||
// loaded from the default location. The system property for the plugin
|
||||
// path is "gstreamer.plugin.path"
|
||||
String pluginPath = System.getProperty("gstreamer.plugin.path");
|
||||
if (pluginPath != null) {
|
||||
gstreamerPluginPath = pluginPath;
|
||||
}
|
||||
} else {
|
||||
// Paths are build automatically from the curren location of the video
|
||||
// library.
|
||||
if (PApplet.platform == LINUX) {
|
||||
buildLinuxPaths();
|
||||
} else if (PApplet.platform == WINDOWS) {
|
||||
buildWindowsPaths();
|
||||
} else if (PApplet.platform == MACOSX) {
|
||||
buildMacOSXPaths();
|
||||
}
|
||||
}
|
||||
|
||||
if (!gstreamerBinPath.equals("")) {
|
||||
System.setProperty("jna.library.path", gstreamerBinPath);
|
||||
if (!gstreamerLibPath.equals("")) {
|
||||
System.setProperty("jna.library.path", gstreamerLibPath);
|
||||
}
|
||||
|
||||
if (PApplet.platform == WINDOWS) {
|
||||
@@ -123,12 +129,12 @@ public class Video implements PConstants {
|
||||
|
||||
|
||||
static protected void addPlugins() {
|
||||
if (!gstreamerPluginsPath.equals("")) {
|
||||
if (!gstreamerPluginPath.equals("")) {
|
||||
Registry reg = Registry.getDefault();
|
||||
boolean res;
|
||||
res = reg.scanPath(gstreamerPluginsPath);
|
||||
res = reg.scanPath(gstreamerPluginPath);
|
||||
if (!res) {
|
||||
System.err.println("Cannot load GStreamer plugins from " + gstreamerPluginsPath);
|
||||
System.err.println("Cannot load GStreamer plugins from " + gstreamerPluginPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,39 +149,29 @@ public class Video implements PConstants {
|
||||
}
|
||||
|
||||
|
||||
static protected void setLinuxPath() {
|
||||
gstreamerBinPath = "";
|
||||
gstreamerPluginsPath = "";
|
||||
static protected void buildLinuxPaths() {
|
||||
gstreamerLibPath = "";
|
||||
gstreamerPluginPath = "";
|
||||
}
|
||||
|
||||
|
||||
static protected void setWindowsPath() {
|
||||
if (gstreamerPath.equals("")) {
|
||||
LibraryPath libPath = new LibraryPath();
|
||||
String path = libPath.get();
|
||||
gstreamerBinPath = buildGStreamerBinPath(path, "\\windows" + bitsJVM);
|
||||
gstreamerPluginsPath = gstreamerBinPath + "\\plugins";
|
||||
} else {
|
||||
gstreamerBinPath = gstreamerPath;
|
||||
gstreamerPluginsPath = gstreamerPath + "\\plugins";
|
||||
}
|
||||
static protected void buildWindowsPaths() {
|
||||
LibraryPath libPath = new LibraryPath();
|
||||
String path = libPath.get();
|
||||
gstreamerLibPath = buildGStreamerLibPath(path, "\\windows" + bitsJVM);
|
||||
gstreamerPluginPath = gstreamerLibPath + "\\plugins";
|
||||
}
|
||||
|
||||
|
||||
static protected void setMacOSXPath() {
|
||||
if (gstreamerPath.equals("")) {
|
||||
LibraryPath libPath = new LibraryPath();
|
||||
String path = libPath.get();
|
||||
gstreamerBinPath = buildGStreamerBinPath(path, "/macosx" + bitsJVM);
|
||||
gstreamerPluginsPath = gstreamerBinPath + "/plugins";
|
||||
} else {
|
||||
gstreamerBinPath = gstreamerPath;
|
||||
gstreamerPluginsPath = gstreamerPath + "/" + pluginPath; //"/plugins";
|
||||
}
|
||||
static protected void buildMacOSXPaths() {
|
||||
LibraryPath libPath = new LibraryPath();
|
||||
String path = libPath.get();
|
||||
gstreamerLibPath = buildGStreamerLibPath(path, "/macosx" + bitsJVM);
|
||||
gstreamerPluginPath = gstreamerLibPath + "/plugins";
|
||||
}
|
||||
|
||||
|
||||
static protected String buildGStreamerBinPath(String base, String os) {
|
||||
static protected String buildGStreamerLibPath(String base, String os) {
|
||||
File path = new File(base + os);
|
||||
if (path.exists()) {
|
||||
return base + os;
|
||||
@@ -195,47 +191,5 @@ public class Video implements PConstants {
|
||||
static protected long secToNanoLong(float sec) {
|
||||
Float f = new Float(sec * 1E9);
|
||||
return f.longValue();
|
||||
}
|
||||
|
||||
/*
|
||||
static protected boolean lookForGlobalGStreamer() {
|
||||
LibraryPath libPath = new LibraryPath();
|
||||
String locPath = libPath.get();
|
||||
locPath = locPath.replace("/", System.getProperty("file.separator"));
|
||||
|
||||
String[] searchPaths = null;
|
||||
if (!systemGStreamerPath.equals("")) {
|
||||
searchPaths = new String[] {systemGStreamerPath};
|
||||
}
|
||||
|
||||
if (searchPaths == null) {
|
||||
String lpaths = System.getProperty("java.library.path");
|
||||
String pathsep = System.getProperty("path.separator");
|
||||
searchPaths = lpaths.split(pathsep);
|
||||
}
|
||||
|
||||
for (int i = 0; i < searchPaths.length; i++) {
|
||||
String path = searchPaths[i];
|
||||
if ((locPath.equals("") || path.indexOf(locPath) == -1) && libgstreamerPresent(path, "libgstreamer")) {
|
||||
systemGStreamerPath = path;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static protected boolean libgstreamerPresent(String dir, String file) {
|
||||
File libPath = new File(dir);
|
||||
String[] files = libPath.list();
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (-1 < files[i].indexOf(file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user