Software Engineering

My part in its downfall

All the salient facts are true

Java video streaming part 1

Objective

Simple demo code for Java video streaming. Review the setup and configuration for different video streaming engines.

Target Audience

Java Developers new to modern video streaming frameworks and tooling

Source Documents

gradle wrapper
vlc vlcj
vlcj javafx
JavaFX Graphics System
Java Native Interface
Java Native Access (JNA)
YouTube Data API
JavaFX Demo app for vlcj

Summary

To write video streaming applications in Java you need to understand an underlying architecture, processes, tools and frameworks.
This is first part of a series that provides an outine for the above.
The main result for this first part is a simple demo application that renders video streams.
The demo application is based on the vlcj javafx code using vlcj.

Result

See the JavaFX Demo app for vlcj

Set Up

The read me steps through the attributes that need to be configured to play the test video or youtube serach result. The set up steps in order of prededence are
1. Use YouTube Data API documentation to obtain an api key
2. in src/main/resources/application.properties replace ‘your api key’ with api key from you tube
3. On your system download and install the vlc player vlc
4 Set the path to the native libaries in runtime.properties
5 Set the path to the test video in runtime.properties

Build and Run Video Streaming JavaFX Demo app

1 build the java source `./gradlew clean build -x test`
2 run  `java -jar -Dvs.properties=/home/HOME/aJavaFXSpectrum/v-stream/runtime.properties build/libs/v-stream-0.0.1-SNAPSHOT.jar`  

Discussion

From vlcj we discover a libary that allows java bindings for the native vlc runtime. If we go to the source code for the DefaultMediaPlayer we can see how these bindings are used via the JNA interface to the native code. JNA is one way to map Java methods to native methods.
We need to apply the bindings before we can stream video with vlcj the class JNASetUp from the demo code is one way to do this. Once we have applied the JNA bindings we then need two high level components
1. A rendering engine DefaultRenderCallback
2. A Buffer VLCJBufferFormatCallback line 51

Wth the above attributes we can proceed to build a Factory to produce instances of the vlcj DirectMediaPlayer type. VlcjMediaPlayerFactory

More Details

The above code is based on vlcj javafx examples. Currently vlcj javafx support is experimental. The stable library supports java Swing AWT rendering toolkit. The JavaFX Graphics System with the Glass Windowing Tool Kit and the Prisim rendering engine is superior to Swings AWT.
In the following parts to come for this series we will look at other options for video streaming in Java and JavaFX.

JavaFX Demo app for vlcj


Share

comments powered by Disqus