From 0627647ffb3c4dc71b4803f8da5035d507f0f6f2 Mon Sep 17 00:00:00 2001 From: Filippo Carone Date: Sat, 10 Jun 2006 13:58:03 +0000 Subject: [PATCH] Java bindings update. * new JVLC.destroy() method to cleanup a JVLC object * new GenericVideoWidget for general use (thx: Kuldipsingh Pabla) * Status class removed * new JVLC.isInputPlaying() and JVLC.hasVout() methods --- bindings/java/Makefile.am | 2 +- bindings/java/THANKS | 1 + .../org/videolan/jvlc/GenericVideoWidget.java | 59 ++++++++++++ bindings/java/org/videolan/jvlc/JVLC.java | 93 +++++++++++++++++-- bindings/java/org/videolan/jvlc/Playlist.java | 6 +- .../java/org/videolan/jvlc/VideoIntf.java | 46 ++++++++- bindings/java/vlc-libvlc-jni.cc | 14 +++ 7 files changed, 202 insertions(+), 19 deletions(-) create mode 100644 bindings/java/org/videolan/jvlc/GenericVideoWidget.java diff --git a/bindings/java/Makefile.am b/bindings/java/Makefile.am index 9c942ab872..318fff3bc5 100644 --- a/bindings/java/Makefile.am +++ b/bindings/java/Makefile.am @@ -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 org/videolan/jvlc/Status.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/GenericVideoWidget.class JNIHEADERS = org_videolan_jvlc_JVLC.h org_videolan_jvlc_JVLCCanvas.h org_videolan_jvlc_JVLCPanel.h diff --git a/bindings/java/THANKS b/bindings/java/THANKS index 6df278d0bd..2d42511862 100644 --- a/bindings/java/THANKS +++ b/bindings/java/THANKS @@ -2,6 +2,7 @@ Thanks to: * Kuldipsingh Pabla for solaris port and various contributions to the native interface. + for the GenericVideoWidget class * Tvrtko Bedekovic for initial win32 port diff --git a/bindings/java/org/videolan/jvlc/GenericVideoWidget.java b/bindings/java/org/videolan/jvlc/GenericVideoWidget.java new file mode 100644 index 0000000000..ff23f3a5c1 --- /dev/null +++ b/bindings/java/org/videolan/jvlc/GenericVideoWidget.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * SWTVideoWidget.java: A component usable in SWT Application, embeds JVLC + ***************************************************************************** + * + * Copyright (C) 1998-2006 the VideoLAN team + * + * Author: Kuldipsingh Pabla + * + * Created on 10-jun-2006 + * + * $Id $ + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * 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. + * + */ + + +package org.videolan.jvlc; +import java.awt.Frame; +import java.awt.Component; + + +public class GenericVideoWidget { + /* + * This class implements a Composite container for VLC Video Output + */ + + /* + * The root SWT Frame we embed JVLCCanvas in + */ + public Frame rootFrame; + private JVLCCanvas jvlcCanvas; + + public GenericVideoWidget( Component parent ) { + // allocate the new AWT Frame to embed in the Composite + rootFrame = new Frame (); + + // add the JVLCCanvas to the Frame + jvlcCanvas = new JVLCCanvas(); + rootFrame.add( jvlcCanvas ); + } + + + public JVLC getJVLC() { + return jvlcCanvas.getJVLC(); + } +} diff --git a/bindings/java/org/videolan/jvlc/JVLC.java b/bindings/java/org/videolan/jvlc/JVLC.java index 99bfe14d20..a7274df21d 100644 --- a/bindings/java/org/videolan/jvlc/JVLC.java +++ b/bindings/java/org/videolan/jvlc/JVLC.java @@ -29,35 +29,57 @@ package org.videolan.jvlc; -public class JVLC implements JLibVLC { +/** + * @author little + * + */ +public class JVLC implements JLibVLC, Runnable { static { System.load(System.getProperty( "user.dir" ) + "/libjvlc.so" ); } + /** + * These are set as final since they live along the jvlc object + */ + private final long _instance; + public final Playlist playlist; - private long _instance; - public Playlist playlist; - public Status status; + + private boolean beingDestroyed = false; + private long resolution = 50; + private boolean inputPlaying = false; + private boolean inputVout = false; public JVLC() { _instance = createInstance(); playlist = new Playlist( _instance ); - status = new Status(this); + new Thread(this).start(); } public JVLC(String[] args) { _instance = createInstance( args ); playlist = new Playlist( _instance ); - status = new Status(this); + new Thread(this).start(); } - /* + + /** + * Destroys the current instance of jvlc, cleaning up objects. + * This is unreversible. + */ + public void destroy() { + beingDestroyed = true; + _destroy(); + } + + + /* * Core methods */ private native long createInstance(); private native long createInstance( String[] args ); - + private native void _destroy(); /* * Audio native methods */ @@ -170,5 +192,60 @@ public class JVLC implements JLibVLC { public void getSnapshot(String filename) { _getSnapshot(filename); } + + /** + * Checks if the input is playing. + * @return True if there is a playing input. + */ + public boolean isInputPlaying() { + return inputPlaying; + } + + /** + * Checks if the input has spawned a video window. + * @return True if there is a video window. + */ + public boolean hasVout() { + return inputVout; + } + + /* + * (non-Javadoc) + * @see java.lang.Runnable#run() + * + * In this thread we check the playlist and input status. + */ + public void run() { + while (! beingDestroyed) { + while (playlist.isRunning()) { + if (playlist.inputIsPlaying()) { + inputPlaying = true; + } + else { + inputPlaying = false; + } + + if (playlist.inputHasVout()) { + inputVout = true; + } + else { + inputVout = false; + } + try { + Thread.sleep(resolution); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } // while playlist running + inputPlaying = false; + inputVout = false; + try { + Thread.sleep(resolution); + } catch (InterruptedException e) { + e.printStackTrace(); + } // try + } // while ! being destroyed + } // run } + diff --git a/bindings/java/org/videolan/jvlc/Playlist.java b/bindings/java/org/videolan/jvlc/Playlist.java index 26120d49a0..0e62066266 100644 --- a/bindings/java/org/videolan/jvlc/Playlist.java +++ b/bindings/java/org/videolan/jvlc/Playlist.java @@ -93,11 +93,7 @@ public class Playlist implements PlaylistIntf { } public synchronized void clear() { - /* - * This method has been commented out until - * playlist_Clear has been fixed in vlc. - */ - //_clear(); + _clear(); } public synchronized int add(String uri, String name, String[] options) { diff --git a/bindings/java/org/videolan/jvlc/VideoIntf.java b/bindings/java/org/videolan/jvlc/VideoIntf.java index 10396185c5..8b0d333cd8 100644 --- a/bindings/java/org/videolan/jvlc/VideoIntf.java +++ b/bindings/java/org/videolan/jvlc/VideoIntf.java @@ -29,12 +29,48 @@ package org.videolan.jvlc; +/** + * @author little + * + */ +/** + * @author little + * + */ public interface VideoIntf { - void toggleFullscreen(); - void setFullscreen( boolean value ); + /** + * Toggles the fullscreen. + */ + void toggleFullscreen(); + + + /** + * Sets fullscreen if fullscreen argument is true. + * @param fullscreen + */ + void setFullscreen( boolean fullscreen ); + + + /** + * @return True if the current video window is in fullscreen mode. + */ boolean getFullscreen(); - void getSnapshot(String filepath); - int getVideoHeight(); - int getVideoWidth(); + + /** + * Saves a snapshot of the current video window. + * @param filepath The full path (including filename) were to save the snapshot to. + */ + void getSnapshot(String filepath); + + + /** + * @return The current video window height + */ + int getVideoHeight(); + + /** + * @return The current video window width + */ + int getVideoWidth(); } diff --git a/bindings/java/vlc-libvlc-jni.cc b/bindings/java/vlc-libvlc-jni.cc index 630794df8b..4615d83bff 100644 --- a/bindings/java/vlc-libvlc-jni.cc +++ b/bindings/java/vlc-libvlc-jni.cc @@ -91,6 +91,20 @@ JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC_createInstance___3Ljava_lang } +JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1destroy (JNIEnv *env, jobject _this) +{ + long instance; + + instance = getClassInstance( env, _this ); + + libvlc_destroy( (libvlc_instance_t *) instance); + + return; +} + + + + /* * Audio native functions */ -- 2.39.2