-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Welcome to the datavyu-ffmpegplugin wiki!
This repository holds the native c++/java code that composes the Datavyu ffmpegplugin plugin. It is structured like this:
- Java Code: Provides a Java wrapper for the native media players, this part relies on JNI to control the players compiled using Visual Studio projects.
- Cpp code: The Visual Studio Solution has five projects; these are:
- FFmpegJavaMediaPlayer: Used to compile the dll for the FFmpeg Java media player that uses Java to display images and play sound from native buffers passed through JNI calls.
- FFmpegSdlMediaPlayer: Used to compile the dll for the FFmpeg media player in java that uses the SDL framework to display images and play sound natively.
- MpvMediaPlayer: Used to compile the dll for the MPV media player.
- MediaPlayer: A Basic SDL and MPV player used for debugging and testing purposes.
- MediaPlayerTest: Unit Test for the VS Solution.
- VideoState: A shared project referenced in the projects listed above.
To compile the dll's for these projects follow the directions under "Compiling Native Code".
Note: Tee Java Media Player is the only one that provides access to video and audio buffers to be consumed in the Java Side.
The design and development of this bridge follows the JavaFx project closely. The javafx for project is here:
To compile the wrapper classes for the JNI bridge, use the following commands from the root directory of the Datavyu ffmpegplugin project:
javah -d src/main/cpp -classpath src/main/java org.datavyu.plugins.ffmpeg.NativeMediaPlayer
javah -d src/main/cpp -classpath src/main/java org.datavyu.plugins.ffmpeg.FfmpegSdlMediaPlayer
javah -d src/main/cpp -classpath src/main/java org.datavyu.plugins.ffmpeg.FfmpegJavaMediaPlayer
javah -d src/main/cpp -classpath src/main/java org.datavyu.plugins.ffmpeg.MpvMediaPlayer
Note, from NativeMediaPlayer.class
we only use the produced stub org_datavyu_plugins_ffmpeg_NativeMediaPlayer.h
to
get the state codes.
The native code interfaces to the c API from ffmpeg using JNI.
-
Download and install Microsoft Visual Studio Community Edition link
-
Download the "Dev" 64-bit version of FFmpeg link
-
Download and install the Java 8 JDK from Oracle Website
-
Download the SDL2 development libraries for Visual C++ 32/64-bit link and unzip them to a directory (we'll use
C:\SDL2
) -
Download the "Dev" version of MPV from link
-
Create a directory named
FFplay64
underC:\
to hold the headers and libraries that will be used. -
Create
include
andlib
directory intoC:\FFplay64
-
Create a new directory called
SDL2
inside of theC:\FFplay64\include
folder and then move all of the files in theinclude
folder of the downloaded SDL2 library into theC:\FFplay64\include\SDL2
folder and the files in thelib\x64\
intoC:\FFplay64\lib
. -
Unzip the Dev MPV version to a directory (we will use
C:\MPV
as an example) and copy theinclude
folder from the downloaded zip intoC:\FFplay64\include\MPV
-
Unzip the Dev version of ffmpeg to a directory (we will use
C:\FFmpeg-dev
as an example) and move headers files fromC:\FFmpeg-dev\include
andC:\FFmpeg-dev\lib
intoC:\FFplay64\include
andC:\FFplay64\lib
, respectively. -
Clone this repository to a directory of your choosing, using the following git command:
git clone https://github.com/databrary/datavyu-ffmpegplugin.git
-
In Visual Studio, open MediaPlayer.sln using
File -> Open -> Project/Solution
and navigating tosrc\main\cpp
in the folder where you cloned this repository. -
Once the solution is open, we have to tell Visual Studio where to find the FFmpeg, Java, and SDL headers and libraries.
- Click on "Solution Explorer" in the bottom of the left pane.
- Right click the
FfmpegMediaPlayer
project underSolution 'MediaPlayer'
and clickProperties
. - In the left pane under
Configuration Properties
clickVC++ Directories
.- Add a directory to
Include Directories
that points toC:\FFplay64\include
. - Add a directory to
Include Directories
that points toC:\Program Files\Java\jdk1.8.0_YOURVERSION\include
- Add a directory to
Include Directories
that points toC:\Program Files\Java\jdk1.8.0_YOURVERSION\include\win32
- Add a directory to
Library Directories
that points toC:\FFplay64\lib
. - Add a directory to
Library Directories
that points toC:\Program Files\Java\jdk1.8.0_YOURVERSION\lib
.
- Add a directory to
-
Right click on the
MediaPlayer
solution and hit build. The build should be a success and create new DLL's in your root directory of the Datavyu ffmpegplugin project.
We follow google's style guide. You can use the following command line to format the code
clang-format -style=Google -i *.cc *.h
from the path that the files are. On windows you can install the clang compiler from here or the extension for Visual Studio from here If you plan to use the extension use CTRL + R & D to all code in one file.
We use google's style code for the Java Code as well. You can install follow the instructions for from the google java format Github Repo
To test the native code we use Google's C++ test framework link.
All Unit tests are located in the MediaPlayerTest project, the tests run automatically when building the Visual Studio solution (MediaPlayer.sln)
We strongly recommend building the VS solution instead of by project in order to test changes made to the different players.
The java code provides examples on how to interface with the movie stream interface; especially on how to playback image frames and audio frames through separate threads.
To debug the the native players from java, you will have to use to following maven command to build the native side with the Debug
configuration:
mvn -Pwin64-debug -Ddebug=true clean compile
The command will generate a dll and a pdb file in your root directory, set a breakpoint in your favorite IDE and run the debuger, once the program stops at the breakpoint, you will have to grab the Process ID of your java program by typing in the command prompt the following command:
jps
Find the name of your java program and its PID that you will have to attach to the Visual Studio Debugger by openning Visual Studio and going to DEBUG->attach to process and you look for your PID.
Once the Visual Studio debugger is running you set up a breakpoint in your c++ code and resume the debugger in your Java IDE.
To build process we use maven. Dependencies are described in a pom file. The package is build with
mvn -Pwin64-release clean package
and deployed with
mvn -U -Pwin64-release clean deploy
Emergency deployment (not recommended): If tests are broken you can exclude them from the deployment, through the command. Note that these will not exluds native side tests
mvn -U -Pwin64-release Dmaven.test.skip=true clean deploy
To compile a debug version you need to switch the compile into debug mode like this
mvn -Pwin64-debug -Ddebug=true deploy
and as before if you need to skip tests you can use
mvn -Pwin64-debug -Ddebug=true -Dmaven.test.skip=true deploy