]> git.sesse.net Git - vlc/commitdiff
Java bindings update: various enhancements; paint system changed; reparenting works...
authorFilippo Carone <littlejohn@videolan.org>
Tue, 5 Dec 2006 23:45:36 +0000 (23:45 +0000)
committerFilippo Carone <littlejohn@videolan.org>
Tue, 5 Dec 2006 23:45:36 +0000 (23:45 +0000)
bindings/java/Makefile.am
bindings/java/org/videolan/jvlc/Input.java
bindings/java/org/videolan/jvlc/JVLC.java
bindings/java/org/videolan/jvlc/JVLCCanvas.java
bindings/java/org/videolan/jvlc/Video.java
bindings/java/org/videolan/jvlc/VideoIntf.java
bindings/java/src/core-jni.cc
bindings/java/src/graphics-jni.cc
bindings/java/src/video-jni.cc

index b1a85cbc791d768be043cc48d6bb6e43b330d4f6..d9afa2f1ff782ca5812f4777acde6c19dc18dd62 100644 (file)
@@ -33,7 +33,7 @@ EXTRA_DIST+= \
 
 if BUILD_JAVA
 
-OBJECTS = org/videolan/jvlc/VLM.class org/videolan/jvlc/VLCException.class org/videolan/jvlc/Playlist.class org/videolan/jvlc/AudioIntf.class org/videolan/jvlc/Audio.class org/videolan/jvlc/InputIntf.class org/videolan/jvlc/Input.class org/videolan/jvlc/PlaylistIntf.class org/videolan/jvlc/VideoIntf.class org/videolan/jvlc/Video.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/GenericVideoWidget.class
+OBJECTS = org/videolan/jvlc/VLM.class org/videolan/jvlc/VLCException.class org/videolan/jvlc/Playlist.class org/videolan/jvlc/AudioIntf.class org/videolan/jvlc/Audio.class org/videolan/jvlc/InputIntf.class org/videolan/jvlc/Input.class org/videolan/jvlc/PlaylistIntf.class org/videolan/jvlc/VideoIntf.class org/videolan/jvlc/JVLCCanvas.class org/videolan/jvlc/Video.class org/videolan/jvlc/JLibVLC.class org/videolan/jvlc/JVLC.class  org/videolan/jvlc/JVLCPanel.class org/videolan/jvlc/VLMIntf.class org/videolan/jvlc/GenericVideoWidget.class
 
 PROCESSOR_FAMILY = `uname -m | sed -e 's/^i.86/i386/' | sed -e 's/^x86_64/amd64/'`
 
index 41316794efb8e05e7d8c893fbdc74d511ad46b7f..7b71231a342438760ae09a7cd8dad141d82f2125 100644 (file)
@@ -14,7 +14,7 @@ public class Input implements InputIntf {
     private native void                _setTime(long value);
     private native void                _setPosition(float value);
     private native boolean  _isPlaying();
-    private native boolean  _hasVout();
+    private native boolean  _hasVout() throws VLCException;
 
     
     public Input( long instance ) {
@@ -51,7 +51,7 @@ public class Input implements InputIntf {
     }
 
     public boolean hasVout() throws VLCException {
-        return _hasVout();
+       return _hasVout();
     }
     
        public long getInstance() {
index 18c848ea34b4d3c0faadac69711c84a55eb35bfd..e204cfb4c7dab7abfa9a3271b567750c4272d8fb 100644 (file)
 
 package org.videolan.jvlc;
 
-
 public class JVLC implements Runnable {
     
     static {
         System.loadLibrary("jvlc" );
     }
-
+    
     /**
      * These are set as final since they live along the jvlc object
      */
@@ -92,7 +91,10 @@ public class JVLC implements Runnable {
      */
     public void destroy() {
        beingDestroyed = true;
-       _destroy();
+       if (!beingDestroyed)
+       {
+               _destroy();
+       }
     }
  
 
@@ -138,37 +140,33 @@ public class JVLC implements Runnable {
         * In this thread we check the playlist and input status.
         */
        public void run() {
-               while (! beingDestroyed) {
-                       try {
-                               while (playlist.isRunning()) {
-                                       if (input.isPlaying()) {
-                                               inputPlaying = true;
-                                       }
-                                       else {
-                                               inputPlaying = false;
-                                   }
-                                           
-                                       if (input.hasVout()) {
-                                               inputVout = true;
-                                   }
-                                       else {
-                                               inputVout = false;
-                                   }
-                                       try {
+               try {
+                       while (!beingDestroyed) {
+                               try {
+                                       while (playlist.isRunning()) {
+                                               inputPlaying = input.isPlaying();
+                                               inputVout = input.hasVout();        
                                                Thread.sleep(resolution);
-                                       } catch (InterruptedException e) {
-                                               e.printStackTrace();
-                                       } 
+                                       } // while playlist running
+                               } catch (VLCException e) {
+                                       e.printStackTrace();
                                }
-                       } catch (VLCException e1) { } // while playlist running
-                  inputPlaying = false;
-                  inputVout = false;
-                       try {
+                               inputPlaying = false;
+                               inputVout = false;
                                Thread.sleep(resolution);
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       } // try
-               } // while ! being destroyed
-       } // run
+                       } // while ! being destroyed
+               } catch (InterruptedException e) {
+                       e.printStackTrace();
+               }
+       }
+
+       /* (non-Javadoc)
+        * @see java.lang.Object#finalize()
+        */
+       protected void finalize() throws Throwable {
+               destroy();
+               super.finalize();
+       }
+
 }
 
index 848a96d72c29773149d3f338ade2a08c4d8aa15f..7eb75a039a12358ab90bd84906128fc3774ef9b8 100644 (file)
@@ -33,7 +33,9 @@ import java.awt.Graphics;
 
 public class JVLCCanvas extends Canvas {
 
-    public native void paint(Graphics g);
+       public void paint(Graphics g) {
+               jvlc.video.paint(g);
+       }
 
     private final JVLC jvlc;
     
@@ -41,12 +43,16 @@ public class JVLCCanvas extends Canvas {
      * Default constructor. The canvas is set a dimension of 200x200
      */
     public JVLCCanvas() {
+       super();
         jvlc = new JVLC();
+       jvlc.video.setActualCanvas(this);
         setSize(200, 200);
     }
     
     public JVLCCanvas(String[] args) {
+       super();
        jvlc = new JVLC(args);
+       jvlc.video.setActualCanvas(this);
        setSize(200, 200);
     }
     
@@ -55,17 +61,23 @@ public class JVLCCanvas extends Canvas {
      * @param height The initial canvas height
      */
     public JVLCCanvas(int width, int height) {
+       super();
         jvlc = new JVLC();
+       jvlc.video.setActualCanvas(this);        
         setSize(width, height);
     }
     
     public JVLCCanvas(String[] args, int width, int height) {
+       super();
         jvlc = new JVLC(args);
+       jvlc.video.setActualCanvas(this);        
         setSize(width, height);
     }
 
     public JVLCCanvas(JVLC jvlc) {
+       super();
         this.jvlc = jvlc;
+       jvlc.video.setActualCanvas(this);        
     }
     
     public JVLC getJVLC() {
index 88c1059ef45425512c7bd7c54cdf1a9b7c469106..8e2af0a4c401846bc98ae56b7864ec4254b19d94 100644 (file)
@@ -3,16 +3,17 @@
  */
 package org.videolan.jvlc;
 
-import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.Graphics;
 
 public final class Video implements VideoIntf {
        
        private long libvlcInstance;
        
+    private JVLCCanvas actualCanvas;
+    
        public Video( long libvlcInstance) {
                this.libvlcInstance = libvlcInstance;
-               
        }
 
        /*
@@ -25,9 +26,10 @@ public final class Video implements VideoIntf {
     private native int                 _getWidth();
     private native void                        _getSnapshot(String filename);
     private native void                        _destroyVideo();
-    private native void                        _reparent(Component component);
+    private native void                        _reparent(JVLCCanvas component);
     private native void                        _setSize(int width, int height);
-       
+    private native void                        _paint(JVLCCanvas canvas, Graphics g);
+
        /* (non-Javadoc)
         * @see org.videolan.jvlc.VideoIntf#destroyVideo()
         */
@@ -66,8 +68,9 @@ public final class Video implements VideoIntf {
        /* (non-Javadoc)
         * @see org.videolan.jvlc.VideoIntf#reparentVideo(java.awt.Component)
         */
-       public void reparent(Component c) throws VLCException {
+       public void reparent(JVLCCanvas c) throws VLCException {
                _reparent(c);
+               setActualCanvas(c);
        }
 
        /* (non-Javadoc)
@@ -75,7 +78,6 @@ public final class Video implements VideoIntf {
         */
        public void setSize(int width, int height) throws VLCException {
                _setSize( width, height );
-
        }
 
        /* (non-Javadoc)
@@ -105,7 +107,15 @@ public final class Video implements VideoIntf {
        public void setSize(Dimension d) throws VLCException {
                setSize(d.width, d.height);
        }
+       
+       public void paint(Graphics g) {
+               _paint(actualCanvas, g);
+       }
 
+       public void setActualCanvas(JVLCCanvas canvas) {
+               actualCanvas = canvas;
+       }
+       
        public long getInstance() {
                return libvlcInstance;
        }
index cecd4acb21b25b01785471f10189c68532f57dc5..11ad03c27a1b2f418a722dacde202c6064cfba5b 100644 (file)
@@ -29,7 +29,6 @@
 
 package org.videolan.jvlc;
 
-import java.awt.Component;
 import java.awt.Dimension;
 
 
@@ -91,7 +90,7 @@ public interface VideoIntf {
      * @param c
      * @throws VLCException
      */
-    void reparent(Component c) throws VLCException;
+    void reparent(JVLCCanvas c) throws VLCException;
     
     /**
      * Resizes video output to width and height. This operation could be necessary
index cf09bd15f50b98e24479b4f3eacb9a19f23aadfa..4266f7ff1b6f014e9f8989331dd9492eadc9b138 100644 (file)
@@ -82,6 +82,9 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1destroy (JNIEnv *env, jobje
 }
 
 
+//JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1paint (JNIEnv *env, jobject _this, jobject canvas, jobject graphics)
+
+
 /*
  * Utility functions
  */
index 634aca727ef2b01e855e3cd7b1c1e2434b8f25c1..e24845622da86ce98079d4c8b5affccba198fcd0 100644 (file)
 
 jlong getJVLCInstance (JNIEnv *env, jobject _this);
 
-JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, jobject canvas, jobject graphics) {
-
-  JAWT awt;
-  JAWT_DrawingSurface* ds;
-  JAWT_DrawingSurfaceInfo* dsi;
-#ifdef WIN32
-  JAWT_Win32DrawingSurfaceInfo* dsi_win;
-#else
-  JAWT_X11DrawingSurfaceInfo* dsi_x11;
-  GC gc;
-#endif
+// JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, jobject canvas, jobject graphics) {
+
+//   JAWT awt;
+//   JAWT_DrawingSurface* ds;
+//   JAWT_DrawingSurfaceInfo* dsi;
+// #ifdef WIN32
+//   JAWT_Win32DrawingSurfaceInfo* dsi_win;
+// #else
+//   JAWT_X11DrawingSurfaceInfo* dsi_x11;
+//   GC gc;
+// #endif
   
-  jint lock;
+//   jint lock;
     
-  libvlc_drawable_t drawable;
-  libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
-  libvlc_exception_init( exception );
-
-  /* Get the AWT */
-  awt.version = JAWT_VERSION_1_3;
-  if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
-    printf("AWT Not found\n");
-    return;
-  }
-
-  /* Get the drawing surface */
-  ds = awt.GetDrawingSurface(env, canvas);
-  if (ds == NULL) {
-    printf("NULL drawing surface\n");
-    return;
-  }
-
-  /* Lock the drawing surface */
-  lock = ds->Lock(ds);
-  if((lock & JAWT_LOCK_ERROR) != 0) {
-    printf("Error locking surface\n");
-    awt.FreeDrawingSurface(ds);
-    return;
-  }
-
-  /* Get the drawing surface info */
-  dsi = ds->GetDrawingSurfaceInfo(ds);
-  if (dsi == NULL) {
-    printf("Error getting surface info\n");
-    ds->Unlock(ds);
-    awt.FreeDrawingSurface(ds);
-    return;
-  }
-
-
-#ifdef WIN32
-  /* Get the platform-specific drawing info */
-  dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
-
-  /* Now paint */
-
-  drawable = reinterpret_cast<int>(dsi_win->hwnd);
-  long vlcInstance = getJVLCInstance( env, canvas );
-  libvlc_video_set_parent( (libvlc_instance_t *) vlcInstance, drawable, exception );
-
-#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);
-  XSetBackground(dsi_x11->display, gc, 0);
+//   libvlc_drawable_t drawable;
+//   libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
+//   libvlc_exception_init( exception );
+
+//   /* Get the AWT */
+//   awt.version = JAWT_VERSION_1_3;
+//   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+//     printf("AWT Not found\n");
+//     return;
+//   }
+
+//   /* Get the drawing surface */
+//   ds = awt.GetDrawingSurface(env, canvas);
+//   if (ds == NULL) {
+//     printf("NULL drawing surface\n");
+//     return;
+//   }
+
+//   /* Lock the drawing surface */
+//   lock = ds->Lock(ds);
+//   if((lock & JAWT_LOCK_ERROR) != 0) {
+//     printf("Error locking surface\n");
+//     awt.FreeDrawingSurface(ds);
+//     return;
+//   }
+
+//   /* Get the drawing surface info */
+//   dsi = ds->GetDrawingSurfaceInfo(ds);
+//   if (dsi == NULL) {
+//     printf("Error getting surface info\n");
+//     ds->Unlock(ds);
+//     awt.FreeDrawingSurface(ds);
+//     return;
+//   }
+
+
+// #ifdef WIN32
+//   /* Get the platform-specific drawing info */
+//   dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+
+//   /* Now paint */
+
+//   drawable = reinterpret_cast<int>(dsi_win->hwnd);
+//   long vlcInstance = getJVLCInstance( env, canvas );
+//   libvlc_video_set_parent( (libvlc_instance_t *) vlcInstance, drawable, exception );
+
+// #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);
+//   XSetBackground(dsi_x11->display, gc, 0);
   
-  drawable = dsi_x11->drawable;
-  long vlcInstance = getJVLCInstance( env, canvas );
-  libvlc_video_set_parent( (libvlc_instance_t *)vlcInstance, drawable, exception );
+//   drawable = dsi_x11->drawable;
+//   long vlcInstance = getJVLCInstance( env, canvas );
+//   libvlc_video_set_parent( (libvlc_instance_t *)vlcInstance, drawable, exception );
 
-  XFreeGC(dsi_x11->display, gc);
+//   XFreeGC(dsi_x11->display, gc);
 
-#endif
+// #endif
 
-  /* Free the drawing surface info */
-  ds->FreeDrawingSurfaceInfo(dsi);
+//   /* Free the drawing surface info */
+//   ds->FreeDrawingSurfaceInfo(dsi);
 
-  /* Unlock the drawing surface */
-  ds->Unlock(ds);
+//   /* Unlock the drawing surface */
+//   ds->Unlock(ds);
 
-  /* Free the drawing surface */
-  awt.FreeDrawingSurface(ds);
-}
+//   /* Free the drawing surface */
+//   awt.FreeDrawingSurface(ds);
+// }
 
 /*
  * Utility functions
index 161b52dd08361dbefd4aaa9bf2ed118e9fcb3e51..86f2920f80a9604b21a2af8272dcec88a25d3128 100644 (file)
@@ -183,7 +183,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
     drawable = reinterpret_cast<int>(dsi_win->hwnd);
 
-    libvlc_video_reparent( input, drawable, exception );
+    libvlc_video_set_parent( input, drawable, exception );
 
     CHECK_EXCEPTION_FREE ;
     
@@ -198,7 +198,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
 
     /* and reparent */
     drawable = dsi_x11->drawable;
-    libvlc_video_reparent( input, drawable, exception );
+    libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, exception );
 
     CHECK_EXCEPTION_FREE ;
 
@@ -215,6 +215,93 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
   awt.FreeDrawingSurface(ds);
 }
 
+JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1paint (JNIEnv *env, jobject _this, jobject canvas, jobject graphics)
+{
+    INIT_FUNCTION ;
+    
+    libvlc_drawable_t drawable;
+
+    JAWT awt;
+    JAWT_DrawingSurface* ds;
+    JAWT_DrawingSurfaceInfo* dsi;
+#ifdef WIN32
+    JAWT_Win32DrawingSurfaceInfo* dsi_win;
+#else
+    JAWT_X11DrawingSurfaceInfo* dsi_x11;
+    GC gc;  
+#endif    
+    jint lock;
+    
+    /* Get the AWT */
+    awt.version = JAWT_VERSION_1_3;
+    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+        printf("AWT Not found\n");
+        return;
+    }
+
+    /* Get the drawing surface */
+    ds = awt.GetDrawingSurface(env, canvas);
+    if (ds == NULL) {
+        printf("NULL drawing surface\n");
+        return;
+    }
+
+    /* Lock the drawing surface */
+    lock = ds->Lock(ds);
+    if((lock & JAWT_LOCK_ERROR) != 0) {
+        printf("Error locking surface\n");
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    /* Get the drawing surface info */
+    dsi = ds->GetDrawingSurfaceInfo(ds);
+    if (dsi == NULL) {
+        printf("Error getting surface info\n");
+        ds->Unlock(ds);
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    
+#ifdef WIN32
+    /* Get the platform-specific drawing info */
+    dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+    drawable = reinterpret_cast<int>(dsi_win->hwnd);
+
+    libvlc_video_set_parent( input, drawable, exception );
+
+    CHECK_EXCEPTION_FREE ;
+    
+#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);
+    XSetBackground(dsi_x11->display, gc, 0);
+
+    /* and reparent */
+    drawable = dsi_x11->drawable;
+    libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, exception );
+
+    CHECK_EXCEPTION_FREE ;
+
+    XFreeGC(dsi_x11->display, gc);
+
+#endif
+  /* Free the drawing surface info */
+  ds->FreeDrawingSurfaceInfo(dsi);
+
+  /* Unlock the drawing surface */
+  ds->Unlock(ds);
+
+  /* Free the drawing surface */
+  awt.FreeDrawingSurface(ds);
+}
+
+
 
 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize (JNIEnv *env, jobject _this, jint width, jint height) 
 {