├── .gitignore ├── BasicPipeline ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── BasicPipeline.java │ └── Utils.java ├── BufferProbe ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── BufferProbe.java │ └── Utils.java ├── Controllers ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── Controllers.java │ └── Utils.java ├── FXCamera ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── FXCamera.java │ └── Utils.java ├── FXPlayer ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── FXPlayer.java │ └── Utils.java ├── HLS ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ ├── java │ └── org │ │ └── freedesktop │ │ └── gstreamer │ │ └── examples │ │ ├── HLS.java │ │ └── Utils.java │ └── resources │ └── public │ └── index.html ├── README.md ├── SwingCamera ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── SwingCamera.java │ └── Utils.java ├── SwingPlayer ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── SwingPlayer.java │ └── Utils.java ├── WebRTCSendRecv ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── java │ └── org │ └── freedesktop │ └── gstreamer │ └── examples │ ├── Utils.java │ └── WebRTCSendRecv.java └── archive ├── nbactions.xml ├── pom.xml └── src └── main └── java └── org └── freedesktop └── gstreamer └── examples ├── AppSrcToAppSinkExample.java ├── BatchTranscode.java ├── CameraTest.java ├── MultiSinkExample.java ├── PlayBinVideoPlayer.java ├── SimpleVideoComponent.java ├── TestFootageCapture.java ├── TestProcessVideoMP4ToMP4.java ├── TestProcessVideoRTSPToMP4.java └── TextColorControlExample.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | hs_err_pid* 9 | 10 | .gradle 11 | build/ 12 | 13 | target/ 14 | 15 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 16 | !gradle-wrapper.jar 17 | 18 | # Cache of project 19 | .gradletasknamecache 20 | 21 | # Eclipse Files # 22 | .classpath 23 | .project 24 | .settings 25 | 26 | # NetBeans Files # 27 | /nbproject/ 28 | nb-configuration.xml 29 | -------------------------------------------------------------------------------- /BasicPipeline/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'application' 3 | 4 | 5 | mainClassName = 'org.freedesktop.gstreamer.examples.BasicPipeline' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation 'net.java.dev.jna:jna:5.10.0' 13 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 14 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 15 | } 16 | -------------------------------------------------------------------------------- /BasicPipeline/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/BasicPipeline/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /BasicPipeline/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /BasicPipeline/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /BasicPipeline/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /BasicPipeline/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'BasicPipeline' 2 | -------------------------------------------------------------------------------- /BasicPipeline/src/main/java/org/freedesktop/gstreamer/examples/BasicPipeline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import java.util.concurrent.TimeUnit; 15 | import org.freedesktop.gstreamer.Gst; 16 | import org.freedesktop.gstreamer.Pipeline; 17 | import org.freedesktop.gstreamer.Version; 18 | 19 | /** 20 | * Simply launches a test GStreamer pipeline using the Java bindings. 21 | * 22 | * @author Neil C Smith ( https://www.codelerity.com ) 23 | */ 24 | public class BasicPipeline { 25 | 26 | /** 27 | * Always store the top-level pipeline reference to stop it being garbage 28 | * collected. 29 | */ 30 | private static Pipeline pipeline; 31 | 32 | /** 33 | * @param args the command line arguments 34 | */ 35 | public static void main(String[] args) { 36 | 37 | /** 38 | * Set up paths to native GStreamer libraries - see adjacent file. 39 | */ 40 | Utils.configurePaths(); 41 | 42 | /** 43 | * Initialize GStreamer. Always pass the lowest version you require - 44 | * Version.BASELINE is GStreamer 1.8. Use Version.of() for higher. 45 | * Features requiring later versions of GStreamer than passed here will 46 | * throw an exception in the bindings even if the actual native library 47 | * is a higher version. 48 | */ 49 | Gst.init(Version.BASELINE, "BasicPipeline", args); 50 | 51 | /** 52 | * Use Gst.parseLaunch() to create a pipeline from a GStreamer string 53 | * definition. This method returns Pipeline when more than one element 54 | * is specified. 55 | */ 56 | pipeline = (Pipeline) Gst.parseLaunch("videotestsrc ! autovideosink"); 57 | 58 | /** 59 | * Start the pipeline. 60 | */ 61 | pipeline.play(); 62 | 63 | /** 64 | * GStreamer native threads will not be taken into account by the JVM 65 | * when deciding whether to shutdown, so we have to keep the main thread 66 | * alive. Gst.main() will keep the calling thread alive until Gst.quit() 67 | * is called. Here we use the built-in executor to schedule a quit after 68 | * 10 seconds. 69 | */ 70 | Gst.getExecutor().schedule(Gst::quit, 10, TimeUnit.SECONDS); 71 | Gst.main(); 72 | 73 | } 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /BasicPipeline/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /BufferProbe/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'application' 3 | 4 | 5 | mainClassName = 'org.freedesktop.gstreamer.examples.BufferProbe' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation 'net.java.dev.jna:jna:5.10.0' 13 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 14 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 15 | } 16 | -------------------------------------------------------------------------------- /BufferProbe/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/BufferProbe/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /BufferProbe/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /BufferProbe/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /BufferProbe/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /BufferProbe/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'BufferProbe' 2 | -------------------------------------------------------------------------------- /BufferProbe/src/main/java/org/freedesktop/gstreamer/examples/BufferProbe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import java.awt.Color; 15 | import java.awt.GradientPaint; 16 | import java.awt.Graphics2D; 17 | import java.awt.Paint; 18 | import java.awt.RenderingHints; 19 | import java.awt.geom.AffineTransform; 20 | import java.awt.geom.GeneralPath; 21 | import java.awt.image.BufferedImage; 22 | import java.awt.image.DataBufferInt; 23 | import java.nio.ByteOrder; 24 | import java.nio.IntBuffer; 25 | import org.freedesktop.gstreamer.Buffer; 26 | import org.freedesktop.gstreamer.Bus; 27 | import org.freedesktop.gstreamer.Element; 28 | import org.freedesktop.gstreamer.Gst; 29 | import org.freedesktop.gstreamer.Pad; 30 | import org.freedesktop.gstreamer.PadProbeInfo; 31 | import org.freedesktop.gstreamer.PadProbeReturn; 32 | import org.freedesktop.gstreamer.PadProbeType; 33 | import org.freedesktop.gstreamer.Pipeline; 34 | import org.freedesktop.gstreamer.Version; 35 | 36 | /** 37 | * Launches a GStreamer pipeline and uses a buffer probe to draw an animation on 38 | * top of the video stream using Java2D. 39 | * 40 | * @author Neil C Smith ( https://www.codelerity.com ) 41 | */ 42 | public class BufferProbe { 43 | 44 | private static final int WIDTH = 800; 45 | private static final int HEIGHT = 600; 46 | 47 | /** 48 | * Use a Pad.PROBE and Java2D to draw on to the buffers passing through the 49 | * pipeline. 50 | */ 51 | private static Pipeline pipeline; 52 | 53 | /** 54 | * @param args the command line arguments 55 | */ 56 | public static void main(String[] args) { 57 | 58 | /** 59 | * Set up paths to native GStreamer libraries - see adjacent file. 60 | */ 61 | Utils.configurePaths(); 62 | 63 | /** 64 | * Initialize GStreamer. Always pass the lowest version you require - 65 | * Version.BASELINE is GStreamer 1.8. Use Version.of() for higher. 66 | * Features requiring later versions of GStreamer than passed here will 67 | * throw an exception in the bindings even if the actual native library 68 | * is a higher version. 69 | */ 70 | Gst.init(Version.BASELINE, "BufferProbe", args); 71 | 72 | /** 73 | * Set up a Caps string with the width, height and buffer format 74 | * required for reading and writing into the BufferedImage. 75 | */ 76 | String caps = "video/x-raw, width=" + WIDTH + ", height=" + HEIGHT 77 | + ", pixel-aspect-ratio=1/1, " 78 | + (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN 79 | ? "format=BGRx" : "format=xRGB"); 80 | 81 | /** 82 | * Use Gst.parseLaunch() to create a pipeline from a GStreamer string 83 | * definition. This method returns Pipeline when more than one element 84 | * is specified. 85 | * 86 | * The named Identity element can be acquired from the pipeline by name 87 | * and the probe attached to its sink pad. 88 | */ 89 | pipeline = (Pipeline) Gst.parseLaunch("autovideosrc ! videoconvert ! videoscale ! " 90 | + caps + " ! identity name=identity ! videoconvert ! autovideosink"); 91 | Element identity = pipeline.getElementByName("identity"); 92 | identity.getStaticPad("sink") 93 | .addProbe(PadProbeType.BUFFER, new Renderer(WIDTH, HEIGHT)); 94 | 95 | /** 96 | * Start the pipeline. Attach a bus listener to call Gst.quit on EOS or 97 | * error. 98 | */ 99 | pipeline.getBus().connect((Bus.ERROR) ((source, code, message) -> { 100 | System.out.println(message); 101 | Gst.quit(); 102 | })); 103 | pipeline.getBus().connect((Bus.EOS) (source) -> Gst.quit()); 104 | pipeline.play(); 105 | Gst.main(); 106 | 107 | } 108 | 109 | /** 110 | * A Pad.PROBE implementation that acquires the Buffer, reads it into the 111 | * data array of a BufferedImage, renders an animation on top, and writes 112 | * back into the Buffer. 113 | */ 114 | static class Renderer implements Pad.PROBE { 115 | 116 | private final BufferedImage image; 117 | private final int[] data; 118 | private final Point[] points; 119 | private final Paint fill; 120 | 121 | private Renderer(int width, int height) { 122 | image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 123 | data = ((DataBufferInt) (image.getRaster().getDataBuffer())).getData(); 124 | points = new Point[18]; 125 | for (int i = 0; i < points.length; i++) { 126 | points[i] = new Point(); 127 | } 128 | fill = new GradientPaint(0, 0, new Color(1.0f, 0.3f, 0.5f, 0.9f), 129 | 60, 20, new Color(0.3f, 1.0f, 0.7f, 0.8f), true); 130 | } 131 | 132 | @Override 133 | public PadProbeReturn probeCallback(Pad pad, PadProbeInfo info) { 134 | Buffer buffer = info.getBuffer(); 135 | if (buffer.isWritable()) { 136 | IntBuffer ib = buffer.map(true).asIntBuffer(); 137 | ib.get(data); 138 | render(); 139 | ib.rewind(); 140 | ib.put(data); 141 | buffer.unmap(); 142 | } 143 | return PadProbeReturn.OK; 144 | } 145 | 146 | private void render() { 147 | Graphics2D g2d = image.createGraphics(); 148 | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 149 | RenderingHints.VALUE_ANTIALIAS_ON); 150 | for (Point point : points) { 151 | point.tick(); 152 | } 153 | GeneralPath path = new GeneralPath(); 154 | path.moveTo(points[0].x, points[0].y); 155 | for (int i = 2; i < points.length; i += 2) { 156 | path.quadTo(points[i - 1].x, points[i - 1].y, 157 | points[i].x, points[i].y); 158 | } 159 | path.closePath(); 160 | path.transform(AffineTransform.getScaleInstance(image.getWidth(), image.getHeight())); 161 | g2d.setPaint(fill); 162 | g2d.fill(path); 163 | g2d.setColor(Color.BLACK); 164 | g2d.draw(path); 165 | } 166 | 167 | } 168 | 169 | static class Point { 170 | 171 | private double x, y, dx, dy; 172 | 173 | private Point() { 174 | this.x = Math.random(); 175 | this.y = Math.random(); 176 | this.dx = 0.02 * Math.random(); 177 | this.dy = 0.02 * Math.random(); 178 | } 179 | 180 | private void tick() { 181 | x += dx; 182 | y += dy; 183 | if (x < 0 || x > 1) { 184 | dx = -dx; 185 | } 186 | if (y < 0 || y > 1) { 187 | dy = -dy; 188 | } 189 | } 190 | 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /BufferProbe/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Controllers/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'application' 3 | 4 | 5 | mainClassName = 'org.freedesktop.gstreamer.examples.Controllers' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation 'net.java.dev.jna:jna:5.10.0' 13 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 14 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 15 | } 16 | -------------------------------------------------------------------------------- /Controllers/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/Controllers/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Controllers/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Controllers/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /Controllers/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /Controllers/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Controllers' 2 | -------------------------------------------------------------------------------- /Controllers/src/main/java/org/freedesktop/gstreamer/examples/Controllers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. / Tim-Philipp Müller 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import java.util.concurrent.TimeUnit; 15 | import org.freedesktop.gstreamer.Element; 16 | import org.freedesktop.gstreamer.ElementFactory; 17 | import org.freedesktop.gstreamer.Gst; 18 | import org.freedesktop.gstreamer.Pipeline; 19 | import org.freedesktop.gstreamer.Version; 20 | import org.freedesktop.gstreamer.controller.ARGBControlBinding; 21 | import org.freedesktop.gstreamer.controller.DirectControlBinding; 22 | import org.freedesktop.gstreamer.controller.LFOControlSource; 23 | 24 | /** 25 | * Builds a pipeline with videotestsrc and textoverlay, and uses control sources 26 | * to modulate text colour and position. 27 | *
28 | * Adapted from the C example by Tim-Philipp Müller at 29 | * 30 | * https://gitlab.freedesktop.org/gstreamer/gstreamer/blob/master/tests/examples/controller/text-color-example.c 31 | * 32 | * @author Neil C Smith ( https://www.codelerity.com ) 33 | */ 34 | public class Controllers { 35 | 36 | /** 37 | * Always store the top-level pipeline reference to stop it being garbage 38 | * collected. 39 | */ 40 | private static Pipeline pipeline; 41 | 42 | /** 43 | * @param args the command line arguments 44 | */ 45 | public static void main(String[] args) { 46 | 47 | /** 48 | * Set up paths to native GStreamer libraries - see adjacent file. 49 | */ 50 | Utils.configurePaths(); 51 | 52 | /** 53 | * Initialize GStreamer. Always pass the lowest version you require - 54 | * Version.BASELINE is GStreamer 1.8. Use Version.of() for higher. 55 | * Features requiring later versions of GStreamer than passed here will 56 | * throw an exception in the bindings even if the actual native library 57 | * is a higher version. 58 | */ 59 | Gst.init(Version.BASELINE, "Controllers", args); 60 | 61 | pipeline = new Pipeline(); 62 | 63 | /** 64 | * Set up a videotestsrc. Use setAsString to pass the pattern as a name 65 | * rather than a number. 66 | */ 67 | Element src = ElementFactory.make("videotestsrc", "src"); 68 | src.setAsString("pattern", "circular"); 69 | 70 | /** 71 | * Set up a textoverlay. Configure horizontal and vertical alignment to 72 | * position so the controllers can move the text. 73 | */ 74 | Element text = ElementFactory.make("textoverlay", "text"); 75 | text.set("text", "GStreamer rocks!"); 76 | text.set("font-desc", "Sans, 42"); 77 | text.setAsString("halignment", "position"); 78 | text.setAsString("valignment", "position"); 79 | 80 | /** 81 | * Use a capsfilter to increase the default dimensions of the output. 82 | */ 83 | Element capsfilter = ElementFactory.make("capsfilter", "capsfilter"); 84 | capsfilter.setAsString("caps", "video/x-raw, width=800, height=600"); 85 | 86 | /** 87 | * Use an autovideosink. Add all the elements to the pipeline and link. 88 | */ 89 | Element sink = ElementFactory.make("autovideosink", "sink"); 90 | pipeline.addMany(src, text, capsfilter, sink); 91 | Pipeline.linkMany(src, text, capsfilter, sink); 92 | 93 | /** 94 | * Create and configure LFO control sources to control the text 95 | * position. Create direct control bindings mapped to the element 96 | * properties, then add the bindings to the element. 97 | */ 98 | LFOControlSource csXPos = new LFOControlSource(); 99 | csXPos.setFrequency(0.11).setAmplitude(0.2).setOffset(0.5); 100 | text.addControlBinding(DirectControlBinding.create(text, "xpos", csXPos)); 101 | 102 | LFOControlSource csYPos = new LFOControlSource(); 103 | csYPos.setFrequency(0.04).setAmplitude(0.4).setOffset(0.5); 104 | text.addControlBinding(DirectControlBinding.create(text, "ypos", csYPos)); 105 | 106 | /** 107 | * Create and configure 3 LFO control sources for the colour channels, 108 | * create an ARGB control binding mapped to the colour property, and add 109 | * the binding to the element. 110 | */ 111 | LFOControlSource csR = new LFOControlSource(); 112 | csR.setFrequency(0.19).setAmplitude(0.5).setOffset(0.5); 113 | LFOControlSource csG = new LFOControlSource(); 114 | csG.setFrequency(0.27).setAmplitude(0.5).setOffset(0.5); 115 | LFOControlSource csB = new LFOControlSource(); 116 | csB.setFrequency(0.13).setAmplitude(0.5).setOffset(0.5); 117 | text.addControlBinding(ARGBControlBinding.create(text, "color", null, csR, csG, csB)); 118 | 119 | // start the pipeline 120 | pipeline.play(); 121 | 122 | /** 123 | * GStreamer native threads will not be taken into account by the JVM 124 | * when deciding whether to shutdown, so we have to keep the main thread 125 | * alive. Gst.main() will keep the calling thread alive until Gst.quit() 126 | * is called. Here we use the built-in executor to schedule a quit after 127 | * 15 seconds. 128 | */ 129 | Gst.getExecutor().schedule(Gst::quit, 15, TimeUnit.SECONDS); 130 | Gst.main(); 131 | 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /Controllers/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /FXCamera/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | id 'org.openjfx.javafxplugin' version '0.0.11' 4 | } 5 | 6 | mainClassName = 'org.freedesktop.gstreamer.examples.FXCamera' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | javafx { 13 | version = "17" 14 | modules = [ 'javafx.controls' ] 15 | } 16 | 17 | dependencies { 18 | implementation 'net.java.dev.jna:jna:5.10.0' 19 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 20 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 21 | implementation 'org.freedesktop.gstreamer:gst1-java-fx:0.9.0' 22 | } 23 | -------------------------------------------------------------------------------- /FXCamera/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/FXCamera/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /FXCamera/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /FXCamera/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /FXCamera/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /FXCamera/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'FXCamera' 2 | -------------------------------------------------------------------------------- /FXCamera/src/main/java/org/freedesktop/gstreamer/examples/FXCamera.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import javafx.application.Application; 15 | import javafx.geometry.Insets; 16 | import javafx.scene.Scene; 17 | import javafx.scene.image.ImageView; 18 | import javafx.scene.layout.Background; 19 | import javafx.scene.layout.BackgroundFill; 20 | import javafx.scene.layout.BorderPane; 21 | import javafx.scene.layout.CornerRadii; 22 | import javafx.scene.paint.Color; 23 | import javafx.stage.Stage; 24 | import org.freedesktop.gstreamer.Bin; 25 | import org.freedesktop.gstreamer.Gst; 26 | import org.freedesktop.gstreamer.Pipeline; 27 | import org.freedesktop.gstreamer.Version; 28 | import org.freedesktop.gstreamer.fx.FXImageSink; 29 | 30 | /** 31 | * Displays camera input to a JavaFX window. By using autovideosrc, this will 32 | * revert to a test video source if no camera is detected. 33 | * 34 | * @author Neil C Smith ( https://www.codelerity.com ) 35 | */ 36 | public class FXCamera extends Application { 37 | 38 | /** 39 | * Always store the top-level pipeline reference to stop it being garbage 40 | * collected. 41 | */ 42 | private Pipeline pipeline; 43 | 44 | @Override 45 | public void init() throws Exception { 46 | /** 47 | * Set up paths to native GStreamer libraries - see adjacent file. 48 | */ 49 | Utils.configurePaths(); 50 | 51 | /** 52 | * Initialize GStreamer. Always pass the lowest version you require - 53 | * Version.BASELINE is GStreamer 1.8. Use Version.of() for higher. 54 | * Features requiring later versions of GStreamer than passed here will 55 | * throw an exception in the bindings even if the actual native library 56 | * is a higher version. 57 | */ 58 | Gst.init(Version.BASELINE, "FXCamera"); 59 | } 60 | 61 | @Override 62 | public void start(Stage stage) throws Exception { 63 | 64 | /** 65 | * FXImageSink from gst1-java-fx wraps the native data from the 66 | * GStreamer AppSink in a JavaFX image. Requested dimensions will be set 67 | * on the caps for the AppSink. 68 | */ 69 | FXImageSink imageSink = new FXImageSink(); 70 | imageSink.requestFrameSize(640, 480); 71 | 72 | /** 73 | * Parse a Bin to contain the autovideosrc from a GStreamer string 74 | * representation. The alternative approach would be to create and link 75 | * the elements in code using ElementFactory::make. 76 | * 77 | * The Bin uses a videoconvert element to convert the video format to 78 | * that required by the FXImageSink, a videoscale in case the source 79 | * does not support the required resolution. 80 | * 81 | * The bin is added to a top-level pipeline and linked to the AppSink 82 | * from the image sink. 83 | */ 84 | Bin bin = Gst.parseBinFromDescription( 85 | "autovideosrc ! videoscale ! videoconvert", 86 | true); 87 | pipeline = new Pipeline(); 88 | pipeline.addMany(bin, imageSink.getSinkElement()); 89 | Pipeline.linkMany(bin, imageSink.getSinkElement()); 90 | 91 | /** 92 | * Set up a simple JavaFX window with ImageView. 93 | */ 94 | stage.setTitle("FX Camera"); 95 | BorderPane pane = new BorderPane(); 96 | pane.setBackground(new Background(new BackgroundFill( 97 | Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); 98 | ImageView view = new ImageView(); 99 | pane.setCenter(view); 100 | 101 | /** 102 | * Bind the ImageView to the image from the FXImageSink, and scale the 103 | * view within the window. 104 | */ 105 | view.imageProperty().bind(imageSink.imageProperty()); 106 | view.fitWidthProperty().bind(pane.widthProperty()); 107 | view.fitHeightProperty().bind(pane.heightProperty()); 108 | view.setPreserveRatio(true); 109 | 110 | /** 111 | * Show the window and start the pipeline. 112 | */ 113 | stage.setScene(new Scene(pane, 640, 480)); 114 | stage.show(); 115 | pipeline.play(); 116 | } 117 | 118 | public static void main(String[] args) { 119 | // pass to JavaFX 120 | launch(args); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /FXCamera/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /FXPlayer/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | id 'org.openjfx.javafxplugin' version '0.0.11' 4 | } 5 | 6 | mainClassName = 'org.freedesktop.gstreamer.examples.FXPlayer' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | javafx { 13 | version = "17" 14 | modules = [ 'javafx.controls' ] 15 | } 16 | 17 | dependencies { 18 | implementation 'net.java.dev.jna:jna:5.10.0' 19 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 20 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 21 | implementation 'org.freedesktop.gstreamer:gst1-java-fx:0.9.0' 22 | } 23 | -------------------------------------------------------------------------------- /FXPlayer/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/FXPlayer/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /FXPlayer/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /FXPlayer/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /FXPlayer/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /FXPlayer/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'FXPlayer' 2 | -------------------------------------------------------------------------------- /FXPlayer/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /HLS/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'application' 3 | 4 | 5 | mainClassName = 'org.freedesktop.gstreamer.examples.HLS' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation 'net.java.dev.jna:jna:5.10.0' 13 | implementation 'net.java.dev.jna:jna-platform:5.10.0' 14 | implementation 'org.freedesktop.gstreamer:gst1-java-core:1.4.0' 15 | implementation 'io.javalin:javalin:3.13.7' 16 | implementation 'org.slf4j:slf4j-simple:1.7.30' 17 | implementation 'org.webjars.npm:hls.js:1.0.7' 18 | } 19 | -------------------------------------------------------------------------------- /HLS/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gstreamer-java/gst1-java-examples/0667161ac70d3c8394990e8c010947c3a6aed7fe/HLS/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /HLS/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /HLS/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /HLS/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /HLS/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'HLS' 2 | -------------------------------------------------------------------------------- /HLS/src/main/java/org/freedesktop/gstreamer/examples/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright 2021 Neil C Smith - Codelerity Ltd. 5 | * 6 | * Copying and distribution of this file, with or without modification, 7 | * are permitted in any medium without royalty provided the copyright 8 | * notice and this notice are preserved. This file is offered as-is, 9 | * without any warranty. 10 | * 11 | */ 12 | package org.freedesktop.gstreamer.examples; 13 | 14 | import com.sun.jna.Platform; 15 | import com.sun.jna.platform.win32.Kernel32; 16 | import java.io.File; 17 | import java.util.stream.Stream; 18 | 19 | /** 20 | * Utility methods for use in examples. 21 | */ 22 | class Utils { 23 | 24 | private Utils() { 25 | } 26 | 27 | /** 28 | * Configures paths to the GStreamer libraries. On Windows queries various 29 | * GStreamer environment variables, and then sets up the PATH environment 30 | * variable. On macOS, adds the location to jna.library.path (macOS binaries 31 | * link to each other). On both, the gstreamer.path system property can be 32 | * used to override. On Linux, assumes GStreamer is in the path already. 33 | */ 34 | static void configurePaths() { 35 | if (Platform.isWindows()) { 36 | String gstPath = System.getProperty("gstreamer.path", findWindowsLocation()); 37 | if (!gstPath.isEmpty()) { 38 | String systemPath = System.getenv("PATH"); 39 | if (systemPath == null || systemPath.trim().isEmpty()) { 40 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath); 41 | } else { 42 | Kernel32.INSTANCE.SetEnvironmentVariable("PATH", gstPath 43 | + File.pathSeparator + systemPath); 44 | } 45 | } 46 | } else if (Platform.isMac()) { 47 | String gstPath = System.getProperty("gstreamer.path", 48 | "/Library/Frameworks/GStreamer.framework/Libraries/"); 49 | if (!gstPath.isEmpty()) { 50 | String jnaPath = System.getProperty("jna.library.path", "").trim(); 51 | if (jnaPath.isEmpty()) { 52 | System.setProperty("jna.library.path", gstPath); 53 | } else { 54 | System.setProperty("jna.library.path", jnaPath + File.pathSeparator + gstPath); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | /** 62 | * Query over a stream of possible environment variables for GStreamer 63 | * location, filtering on the first non-null result, and adding \bin\ to the 64 | * value. 65 | * 66 | * @return location or empty string 67 | */ 68 | static String findWindowsLocation() { 69 | if (Platform.is64Bit()) { 70 | return Stream.of("GSTREAMER_1_0_ROOT_MSVC_X86_64", 71 | "GSTREAMER_1_0_ROOT_MINGW_X86_64", 72 | "GSTREAMER_1_0_ROOT_X86_64") 73 | .map(System::getenv) 74 | .filter(p -> p != null) 75 | .map(p -> p.endsWith("\\") ? p + "bin\\" : p + "\\bin\\") 76 | .findFirst().orElse(""); 77 | } else { 78 | return ""; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /HLS/src/main/resources/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Video may take up to 20s to appear from server start. Playlist file is
13 | only created after some segments are available.
The default latency is
14 | quite high (15-30s). This can be lowered using hlssink2
element
15 | properties and hls.js
configuration.