]> git.sesse.net Git - vlc/blobdiff - bindings/java/src/video-jni.cc
Bug-to-bug compatibility with Winsock
[vlc] / bindings / java / src / video-jni.cc
index e14fbf670c42b56483bae9085cc648c3375a09c8..9db7bb086681cfec061c1ccf9ef5a6f8d9e3ec85 100644 (file)
@@ -40,9 +40,11 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1toggleFullscreen (JNIEnv *
 
     GET_INPUT_THREAD ;
     
-    libvlc_toggle_fullscreen( input, exception );
+    libvlc_toggle_fullscreen( input, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+
+    CHECK_EXCEPTION ;
 }
 
 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setFullscreen (JNIEnv *env, jobject _this, jboolean value) 
@@ -51,9 +53,10 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setFullscreen (JNIEnv *env
 
     GET_INPUT_THREAD ;
 
-    libvlc_set_fullscreen( input, value, exception );
+    libvlc_set_fullscreen( input, value, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
 }
 
 JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Video__1getFullscreen (JNIEnv *env, jobject _this) 
@@ -63,9 +66,10 @@ JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Video__1getFullscreen (JNIEnv
 
     GET_INPUT_THREAD ;
 
-    res = libvlc_get_fullscreen( input, exception );
+    res = libvlc_get_fullscreen( input, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
     
     return res;
 }
@@ -77,9 +81,10 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getHeight (JNIEnv *env, jo
 
     GET_INPUT_THREAD ;
 
-    res = libvlc_video_get_height( input, exception );
+    res = libvlc_video_get_height( input, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
 
     return res;
 }
@@ -91,9 +96,10 @@ JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getWidth (JNIEnv *env, job
 
     GET_INPUT_THREAD ;
 
-    res = libvlc_video_get_width( input, exception );
+    res = libvlc_video_get_width( input, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
 
     return res;
 }
@@ -106,9 +112,10 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1getSnapshot (JNIEnv *env,
 
     GET_INPUT_THREAD ;
 
-    libvlc_video_take_snapshot( input, (char *) psz_filepath, exception );
+    libvlc_video_take_snapshot( input, (char *) psz_filepath, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
     
     if (psz_filepath != NULL) {
         env->ReleaseStringUTFChars( filepath, psz_filepath );
@@ -122,9 +129,10 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1destroyVideo (JNIEnv *env,
      
     GET_INPUT_THREAD ;
 
-    libvlc_video_destroy( input, exception );
+    libvlc_video_destroy( input, &exception );
 
-    CHECK_EXCEPTION_FREE;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION;
 }
 
 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, jobject _this, jobject canvas) 
@@ -133,6 +141,8 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
     
     GET_INPUT_THREAD ;
 
+    libvlc_drawable_t drawable;
+
     JAWT awt;
     JAWT_DrawingSurface* ds;
     JAWT_DrawingSurfaceInfo* dsi;
@@ -144,12 +154,11 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
 #endif    
     jint lock;
     
-    vlc_value_t value;
-
     /* Get the AWT */
     awt.version = JAWT_VERSION_1_3;
     if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
         printf("AWT Not found\n");
+       libvlc_media_instance_release(input);
         return;
     }
 
@@ -157,6 +166,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
     ds = awt.GetDrawingSurface(env, canvas);
     if (ds == NULL) {
         printf("NULL drawing surface\n");
+       libvlc_media_instance_release(input);
         return;
     }
 
@@ -165,6 +175,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
     if((lock & JAWT_LOCK_ERROR) != 0) {
         printf("Error locking surface\n");
         awt.FreeDrawingSurface(ds);
+       libvlc_media_instance_release(input);
         return;
     }
 
@@ -174,6 +185,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
         printf("Error getting surface info\n");
         ds->Unlock(ds);
         awt.FreeDrawingSurface(ds);
+       libvlc_media_instance_release(input);
         return;
     }
 
@@ -181,15 +193,99 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
 #ifdef WIN32
     /* Get the platform-specific drawing info */
     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+    drawable = reinterpret_cast<int>(dsi_win->hwnd);
 
-    libvlc_video_reparent( input, (libvlc_drawable_t)dsi_win->hwnd, exception );
+    libvlc_video_set_parent((libvlc_instance_t *) instance, drawable, &exception );
+    libvlc_media_instance_release(input);
 
-    CHECK_EXCEPTION_FREE ;
+    CHECK_EXCEPTION ;
     
+#else // UNIX
+    /* Get the platform-specific drawing info */
+
+    dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
+
     /* Now paint */
-    value.i_int = reinterpret_cast<int>(dsi_win->hwnd); 
-    VLC_VariableSet( 1, "drawable", value );
+    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 ;
+
+    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__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( (libvlc_instance_t *) instance, drawable, &exception );
+
+    CHECK_EXCEPTION ;
+    
 #else // UNIX
     /* Get the platform-specific drawing info */
 
@@ -200,14 +296,11 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
     XSetBackground(dsi_x11->display, gc, 0);
 
     /* and reparent */
-    libvlc_video_reparent( input, (libvlc_drawable_t)dsi_x11->drawable, exception );
+    drawable = dsi_x11->drawable;
+    libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    CHECK_EXCEPTION ;
 
-    /* also update the drawable variable value */
-    value.i_int = dsi_x11->drawable;
-    VLC_VariableSet( 0, "drawable", value );
-    
     XFreeGC(dsi_x11->display, gc);
 
 #endif
@@ -221,13 +314,16 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, job
   awt.FreeDrawingSurface(ds);
 }
 
-JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize__II (JNIEnv *env, jobject _this, jint width, jint height) 
+
+
+JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize (JNIEnv *env, jobject _this, jint width, jint height) 
 {
     INIT_FUNCTION ;
 
     GET_INPUT_THREAD ;
     
-    libvlc_video_resize( input, width, height, exception );
+    libvlc_video_resize( input, width, height, &exception );
 
-    CHECK_EXCEPTION_FREE ;
+    libvlc_media_instance_release(input);
+    CHECK_EXCEPTION ;
 }