Skip to content
Reda Nezzar edited this page Jan 24, 2019 · 8 revisions

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:

  1. 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.
  2. Cpp code: The Visual Studio Solution has five projects; these are:
    1. 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.
    2. 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.
    3. MpvMediaPlayer: Used to compile the dll for the MPV media player.
    4. MediaPlayer: A Basic SDL and MPV player used for debugging and testing purposes.
    5. MediaPlayerTest: Unit Test for the VS Solution.
    6. 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.

JNI bridge

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.

Native Code

The native code interfaces to the c API from ffmpeg using JNI.

Compiling the Native Code for Windows using the Visual Studio

  1. Download and install Microsoft Visual Studio Community Edition link

  2. Download the "Dev" 64-bit version of FFmpeg link

  3. Download and install the Java 8 JDK from Oracle Website

  4. Download the SDL2 development libraries for Visual C++ 32/64-bit link and unzip them to a directory (we'll use C:\SDL2)

  5. Download the "Dev" version of MPV from link

  6. Create a directory named FFplay64 under C:\ to hold the headers and libraries that will be used.

  7. Create include and lib directory into C:\FFplay64

  8. Create a new directory called SDL2 inside of the C:\FFplay64\include folder and then move all of the files in the include folder of the downloaded SDL2 library into the C:\FFplay64\include\SDL2 folder and the files in the lib\x64\ into C:\FFplay64\lib.

  9. Unzip the Dev MPV version to a directory (we will use C:\MPV as an example) and copy the include folder from the downloaded zip into C:\FFplay64\include\MPV

  10. Unzip the Dev version of ffmpeg to a directory (we will use C:\FFmpeg-dev as an example) and move headers files from C:\FFmpeg-dev\include and C:\FFmpeg-dev\lib into C:\FFplay64\include and C:\FFplay64\lib, respectively.

  11. Clone this repository to a directory of your choosing, using the following git command:

     git clone https://github.com/databrary/datavyu-ffmpegplugin.git
    
  12. In Visual Studio, open MediaPlayer.sln using File -> Open -> Project/Solution and navigating to src\main\cpp in the folder where you cloned this repository.

  13. Once the solution is open, we have to tell Visual Studio where to find the FFmpeg, Java, and SDL headers and libraries.

    1. Click on "Solution Explorer" in the bottom of the left pane.
    2. Right click the FfmpegMediaPlayer project under Solution 'MediaPlayer' and click Properties.
    3. In the left pane under Configuration Properties click VC++ Directories.
      1. Add a directory to Include Directories that points to C:\FFplay64\include.
      2. Add a directory to Include Directories that points to C:\Program Files\Java\jdk1.8.0_YOURVERSION\include
      3. Add a directory to Include Directories that points to C:\Program Files\Java\jdk1.8.0_YOURVERSION\include\win32
      4. Add a directory to Library Directories that points to C:\FFplay64\lib.
      5. Add a directory to Library Directories that points to C:\Program Files\Java\jdk1.8.0_YOURVERSION\lib.
  14. 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.

Code formatting

C++ Code

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.

Java Code

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

Testing Native Code

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.

Java Code

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.

Debug

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.

Deployment

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

Debugging

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