Commit b2de137f authored by Filippo Carone's avatar Filippo Carone

Java bindings update:

* more synchronization with playlist and input threads
* new libvlc functions binded
parent 10225af5
......@@ -33,4 +33,4 @@ is really straightforward and simple to use.
Try the software and report any errors or bugs you find to me. This application
needs porting to MS/Windows and MacOS, if you are able to implement the JNI for
these platform you may contribute the code.
\ No newline at end of file
these platforms you may contribute the code.
\ No newline at end of file
......@@ -4,7 +4,7 @@
if BUILD_JAVA
OBJECTS = org/videolan/jvlc/AudioIntf.class org/videolan/jvlc/InputIntf.class org/videolan/jvlc/PlaylistIntf.class org/videolan/jvlc/VideoIntf.class org/videolan/jvlc/JLibVLC.class org/videolan/jvlc/JVLC.class org/videolan/jvlc/JVLCCanvas.class org/videolan/jvlc/JVLCPanel.class org/videolan/jvlc/VLMIntf.class org/videolan/jvlc/Playlist.class
OBJECTS = org/videolan/jvlc/AudioIntf.class org/videolan/jvlc/InputIntf.class org/videolan/jvlc/PlaylistIntf.class org/videolan/jvlc/VideoIntf.class org/videolan/jvlc/JLibVLC.class org/videolan/jvlc/JVLC.class org/videolan/jvlc/JVLCCanvas.class org/videolan/jvlc/JVLCPanel.class org/videolan/jvlc/VLMIntf.class org/videolan/jvlc/Playlist.class org/videolan/jvlc/Status.class
JNIHEADERS = org_videolan_jvlc_JVLC.h org_videolan_jvlc_JVLCCanvas.h org_videolan_jvlc_JVLCPanel.h
......@@ -21,7 +21,7 @@ JCH = gcjh -jni
# Compile flags
JAVACXXFLAGS = `top_builddir=../.. ../../vlc-config --cflags pic` -I../../ -I ../../include $(JINCLUDES)
JAVALDFLAGS = -L../../lib -lvlc_pic `top_builddir=../.. ../../vlc-config --libs builtin vlc pic`
JAVALDFLAGS = -L../../src -lvlc `top_builddir=../.. ../../vlc-config --libs builtin vlc pic`
# Build targets
all: libjvlc.so VlcClient
......
$Id$
First of all, this is a *developers* only version
......@@ -7,17 +7,17 @@ Usage
In order to use these bindings you have to compile vlc from source. I
recommend you to take the latest version from videolan svn repository
by doing:
(or use at least revison 15823) by doing:
svn co svn://svn.videolan.org/vlc/trunk vlc-trunk
bootstrap and configure. At the configure give the command:
bootstrap, clean and configure:
./configure --enable-mozilla && make && make install
./bootstrap && make distclean
./configure --enable-java-bindings && make && make install
to enable compilation of _pic version of libraries. If you give a
prefix be sure to change the PREFIX variable in the Makefile from
/usr/local to your prefix.
If you give a prefix be sure to change the PREFIX variable in the Makefile
from /usr/local to your prefix.
Once you've done with vlc you can run make in jvlc directory. Be sure
you have gcj, gcjh and if you want to use the SUN Java compiler,
......@@ -28,18 +28,11 @@ LIBJINCLUDES
In the next releases I will automate this process.
To run JVLC issue:
To run a Java VLC example issue:
java -Djava.library.path=. VlcClient
Be sure your ldconfig can find libjawt.so and libmawt.so or you will
get linking errors when you run the program.
To try the SWT version of the player, issue:
javac -cp /usr/share/java/swt-gtk.jar:. SWTUglyPlayer.java
java -cp /usr/share/java/swt-gtk.jar:. -Djava.library.path=.:/usr/lib/jni SWTUglyPlayer
using the appropriate paths.
Happy playing.
......@@ -30,6 +30,7 @@
package org.videolan.jvlc;
public interface InputIntf {
/**
* This function returns the total length of the current file playing
* in millis.
......@@ -41,7 +42,8 @@ public interface InputIntf {
* currently playing playlist item.
*/
long getInputTime();
void getInputPosition();
long getInputPosition();
void setInputTime();
double getInputFPS();
}
......@@ -38,15 +38,18 @@ public class JVLC implements JLibVLC {
private long _instance;
public Playlist playlist;
public Status status;
public JVLC() {
_instance = createInstance();
playlist = new Playlist( _instance );
status = new Status(this);
}
public JVLC(String[] args) {
_instance = createInstance( args );
playlist = new Playlist( _instance );
status = new Status(this);
}
/*
......@@ -68,15 +71,19 @@ public class JVLC implements JLibVLC {
* Input native methods
*/
private native long _getInputLength();
private native long _getInputPosition();
private native long _getInputTime();
/*
* Video native methods
*/
private native void _toggleFullscreen();
private native void _setFullscreen( boolean value);
private native boolean _getFullscreen();
private native void _toggleFullscreen();
private native void _setFullscreen( boolean value);
private native boolean _getFullscreen();
private native int _getVideoHeight();
private native int _getVideoWidth();
private native void _getSnapshot(String filename);
public boolean getMute() {
......@@ -115,6 +122,16 @@ public class JVLC implements JLibVLC {
return _getFullscreen();
}
public int getVideoHeight() {
return _getVideoHeight();
}
public int getVideoWidth() {
return _getVideoWidth();
}
public long getInputLength() {
return _getInputLength();
}
......@@ -123,8 +140,8 @@ public class JVLC implements JLibVLC {
return _getInputTime();
}
public void getInputPosition() {
// TODO Auto-generated method stub
public long getInputPosition() {
return _getInputPosition();
}
......@@ -137,7 +154,7 @@ public class JVLC implements JLibVLC {
// TODO Auto-generated method stub
return 0;
}
public long getInstance() {
return _instance;
}
......@@ -148,5 +165,10 @@ public class JVLC implements JLibVLC {
public Playlist getPlaylist() {
return playlist;
}
public void getSnapshot(String filename) {
_getSnapshot(filename);
}
}
/*****************************************************************************
/*****************************************************************************
* PlaylistIntf.java: The playlist interface
*****************************************************************************
*
......@@ -48,70 +48,83 @@ public class Playlist implements PlaylistIntf {
native private void _deleteItem(int itemID);
native private int _itemsCount();
native private int _isPlaying();
native private int _isRunning();
native private boolean _inputIsPlaying();
native private boolean _inputHasVout();
public void play(int id, String[] options) {
public synchronized void play(int id, String[] options) {
_play(id, options);
while (! _inputIsPlaying()) ;
}
public void play() {
public synchronized void play() {
play(-1, null);
}
public void pause() {
public synchronized void pause() {
_pause();
}
public void stop() {
public synchronized void stop() {
_stop();
}
public boolean isPlaying() {
return (_isPlaying() == 0)? false : true ;
public boolean isRunning() {
return (_isRunning() == 0)? false : true ;
}
public int itemsCount() {
public synchronized int itemsCount() {
return _itemsCount();
}
public void next() {
if (! isPlaying())
public synchronized void next() {
if (! isRunning())
play();
_next();
}
public void prev() {
public synchronized void prev() {
if (! isRunning())
play();
_prev();
}
public void clear() {
if (! isPlaying())
play();
_clear();
public synchronized void clear() {
/*
* This method has been commented out until
* playlist_Clear has been fixed in vlc.
*/
//_clear();
}
public int add(String uri, String name, String[] options) {
public synchronized int add(String uri, String name, String[] options) {
return _playlist_add(uri, name, options);
}
public int add(String uri, String name) {
public synchronized int add(String uri, String name) {
return add(uri, name, null);
}
public void addExtended() {
public synchronized void addExtended() {
}
public void deleteItem(int itemID) {
public synchronized void deleteItem(int itemID) {
_deleteItem(itemID);
}
public long getInstance() {
return libvlcInstance;
}
public synchronized boolean inputIsPlaying() {
return _inputIsPlaying();
}
public synchronized boolean inputHasVout() {
return _inputHasVout();
}
}
......@@ -33,12 +33,15 @@ public interface PlaylistIntf {
void play(int id, String[] options);
void pause();
void stop();
boolean isPlaying();
boolean isRunning();
int itemsCount();
boolean inputIsPlaying();
void next();
void prev();
void clear();
int add(String uri, String name);
void addExtended();
boolean inputHasVout();
}
......@@ -33,5 +33,8 @@ public interface VideoIntf {
void toggleFullscreen();
void setFullscreen( boolean value );
boolean getFullscreen();
void getSnapshot(String filepath);
int getVideoHeight();
int getVideoWidth();
}
......@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/* These are a must*/
......@@ -27,6 +27,7 @@
#include <jawt_md.h>
#include <X11/Xlib.h> // for Xlibs graphics functions
#include <stdio.h> // for printf
/* JVLC internal imports, generated by gcjh */
#include "org_videolan_jvlc_JVLCCanvas.h"
......@@ -41,12 +42,11 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, job
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_X11DrawingSurfaceInfo* dsi_x11;
jboolean result;
jint lock;
GC gc;
vlc_value_t value;
short i;
/* Get the AWT */
awt.version = JAWT_VERSION_1_3;
......@@ -79,9 +79,18 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, job
return;
}
#ifdef WIN32
/* Get the platform-specific drawing info */
dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
/* Now paint */
value.i_int = reinterpret_cast<int>(dsi_win->hwnd);
VLC_VariableSet( 1, "drawable", value );
#else // UNIX
/* Get the platform-specific drawing info */
dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
/* Now paint */
gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
......@@ -89,9 +98,10 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, job
value.i_int = dsi_x11->drawable;
VLC_VariableSet( 0, "drawable", value );
XFreeGC(dsi_x11->display, gc);
#endif
/* Free the drawing surface info */
ds->FreeDrawingSurfaceInfo(dsi);
......
......@@ -29,7 +29,7 @@
#include <stdio.h> // for printf
#include <stdlib.h> // for calloc
#include <string.h> // for strcmp
#include <unistd.h> // for usleep
/* JVLC internal imports, generated by gcjh */
#include "org_videolan_jvlc_JVLC.h"
......@@ -43,9 +43,11 @@ JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC_createInstance__ (JNIEnv *en
// res is the pointer to libvlc_instance_t
long res;
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
char temp_argv[1][5] = {""};
libvlc_exception_init( exception );
res = ( long ) libvlc_new( 0, NULL, exception );
res = ( long ) libvlc_new( 0, (char **)temp_argv, exception );
if ( libvlc_exception_raised( exception ))
{
......@@ -55,6 +57,8 @@ JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC_createInstance__ (JNIEnv *en
free( exception );
//libvlc_playlist_lock( ( libvlc_instance_t * ) res, NULL);
return res;
}
......@@ -312,8 +316,91 @@ JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_JVLC__1getFullscreen (JNIEnv *
return res;
}
JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1getSnapshot (JNIEnv *env, jobject _this, jstring filepath)
{
const char* psz_filepath = env->GetStringUTFChars( filepath, 0 );
libvlc_exception_t *exception = (libvlc_exception_t *) malloc( sizeof( libvlc_exception_t ));
long instance = 0;
libvlc_input_t *input;
libvlc_exception_init( exception );
instance = getPlaylistInstance( env, _this );
input = libvlc_playlist_get_input( ( libvlc_instance_t *) instance, exception );
if ( libvlc_exception_raised( exception ))
{
///\TODO: raise java exception
printf("%s\n", libvlc_exception_get_message( exception ));
}
libvlc_video_take_snapshot( input, (char *) psz_filepath, exception );
if ( libvlc_exception_raised( exception ))
{
///\TODO: raise java exception
printf("%s\n", libvlc_exception_get_message( exception ));
}
if (psz_filepath != NULL) {
env->ReleaseStringUTFChars( filepath, psz_filepath );
}
}
JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVideoHeight (JNIEnv *env, jobject _this)
{
int res = 0;
libvlc_input_t *input;
long instance = 0;
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
libvlc_exception_init( exception );
instance = getPlaylistInstance( env, _this );
input = libvlc_playlist_get_input( ( libvlc_instance_t *) instance, exception );
res = libvlc_video_get_height( input, exception );
if ( libvlc_exception_raised( exception ))
{
///\TODO: raise java exception
printf("%s\n", libvlc_exception_get_message( exception ));
}
free( exception );
return res;
}
JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC__1getVideoWidth (JNIEnv *env, jobject _this)
{
int res = 0;
libvlc_input_t *input;
long instance = 0;
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
libvlc_exception_init( exception );
instance = getPlaylistInstance( env, _this );
input = libvlc_playlist_get_input( ( libvlc_instance_t *) instance, exception );
res = libvlc_video_get_width( input, exception );
if ( libvlc_exception_raised( exception ))
{
///\TODO: raise java exception
printf("%s\n", libvlc_exception_get_message( exception ));
}
free( exception );
return res;
}
/*
* Playlist native functions
......@@ -364,10 +451,11 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1playlist_1add (JNIEnv *
JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1play (JNIEnv *env, jobject _this, jint id, jobjectArray options) {
long instance = 0;
int i_options = 0;
const char** ppsz_options = NULL;
instance = getPlaylistInstance( env, _this );
libvlc_instance_t *p_instance = ( libvlc_instance_t * ) getPlaylistInstance( env, _this );
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
libvlc_exception_init( exception );
......@@ -383,7 +471,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1play (JNIEnv *env, jobj
}
}
libvlc_playlist_play( ( libvlc_instance_t * ) instance, id, i_options, ( char ** ) ppsz_options, exception );
libvlc_playlist_play( p_instance, id, i_options, ( char ** ) ppsz_options, exception );
free( exception );
return;
......@@ -481,7 +569,7 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1itemsCount (JNIEnv *env
}
JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1isPlaying (JNIEnv *env, jobject _this) {
JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1isRunning (JNIEnv *env, jobject _this) {
long instance = 0;
int res = 0;
libvlc_exception_t *exception = (libvlc_exception_t *) malloc( sizeof( libvlc_exception_t ));
......@@ -495,6 +583,46 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1isPlaying (JNIEnv *env,
}
JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Playlist__1inputIsPlaying (JNIEnv *env, jobject _this)
{
vlc_bool_t res = 0;
long instance = 0;
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
libvlc_input_t *input;
libvlc_exception_init( exception );
instance = getPlaylistInstance( env, _this );
input = libvlc_playlist_get_input( ( libvlc_instance_t* ) instance, exception );
/// \todo check exceptions
res = libvlc_input_will_play( input, exception );
/// \todo check exceptions
free( exception );
return res;
}
JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Playlist__1inputHasVout (JNIEnv *env, jobject _this)
{
vlc_bool_t res = 0;
long instance = 0;
libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
libvlc_input_t *input;
libvlc_exception_init( exception );
instance = getPlaylistInstance( env, _this );
input = libvlc_playlist_get_input( ( libvlc_instance_t* ) instance, exception );
/// \todo check exceptions
res = libvlc_input_has_vout( input, exception );
/// \todo check exceptions
free( exception );
return res;
}
/*
* Input handling functions
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment