]> git.sesse.net Git - vlc/commitdiff
jvlc #23: make native resources release explicit
authorFilippo Carone <littlejohn@videolan.org>
Sat, 10 Jan 2009 01:39:53 +0000 (02:39 +0100)
committerFilippo Carone <littlejohn@videolan.org>
Sat, 10 Jan 2009 23:54:54 +0000 (00:54 +0100)
bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java
bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java

index eef9a80dac8984c233dc601fc3cb49a180bb6b35..bcfd94937107e9e0cb79f362fafd6a8dbb56319a 100644 (file)
@@ -176,6 +176,9 @@ public class JVLC
             vlm.release();
             vlm = null;
         }
+        mediaList.release();
+        mediaListPlayer.release();
+        
         libvlc.libvlc_release(instance);
     }
 
index 5b5f14ee96236a435c3c86f943f8fe9ed04a9700..4997f4c2e3afcf803294564d9a6b33658c57b537 100644 (file)
@@ -36,7 +36,7 @@ public class MediaDescriptor
     private LibVlcMedia instance;
     private LibVlc libvlc;
     private LibVlcEventManager eventManager;
-    private boolean released;
+    private volatile boolean released;
     
     private MediaPlayer mediaPlayer;
     
index c7dcbd03b2369e855634e0ab17e0d5a482c09325..834c4bd9a3496c246a1f010d13e9622dbafeb096 100644 (file)
@@ -26,7 +26,6 @@
 package org.videolan.jvlc;
 
 import java.util.ArrayList;
-import java.util.LinkedHashSet;
 import java.util.List;
 
 import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
@@ -42,10 +41,12 @@ public class MediaList
 
     private final LibVlcMediaList instance;
 
-    private final LibVlcEventManager eventManager;
-
     private List<String> items = new ArrayList<String>();
 
+    private LibVlcEventManager eventManager;
+
+    private volatile boolean released;
+    
     public MediaList(JVLC jvlc)
     {
         this.jvlc = jvlc;
@@ -188,7 +189,7 @@ public class MediaList
     @Override
     protected void finalize() throws Throwable
     {
-        jvlc.getLibvlc().libvlc_media_list_release(instance);
+        release();
         super.finalize();
     }
 
@@ -201,6 +202,20 @@ public class MediaList
         return instance;
     }
 
+    /**
+     * 
+     */
+    public void release()
+    {
+        if (released)
+        {
+            return;
+        }
+        released = true;
+        
+        jvlc.getLibvlc().libvlc_media_list_release(instance);
+    }
+
 
 
 }
index b5e9a72c45f29a60fa36304111e96ad4a8f52777..032008e4557dcc6db5c2036b7cc19f240a460b26 100644 (file)
@@ -35,6 +35,8 @@ public class MediaListPlayer
     private final LibVlcMediaListPlayer instance;
 
     private final JVLC jvlc;
+
+    private volatile boolean released;
     
     public MediaListPlayer(JVLC jvlc)
     {
@@ -172,8 +174,22 @@ public class MediaListPlayer
     @Override
     protected void finalize() throws Throwable
     {
-        jvlc.getLibvlc().libvlc_media_list_player_release(instance);
+        release();
         super.finalize();
     }
 
+    /**
+     * 
+     */
+    public void release()
+    {
+        if (released)
+        {
+            return;
+        }
+        released = true;
+        jvlc.getLibvlc().libvlc_media_list_player_release(instance);
+        
+    }
+
 }
index da069b6bae475e749dfb9e92aff6dbf131703761..8590e4645992f5febc6ab53c96771aaf1ac39e29 100644 (file)
@@ -51,6 +51,8 @@ public class MediaPlayer
 
     private MediaDescriptor mediaDescriptor;
 
+    private volatile boolean released;
+
     MediaPlayer(JVLC jvlc, LibVlcMediaPlayer instance)
     {
         libvlc_exception_t exception = new libvlc_exception_t();
@@ -176,6 +178,18 @@ public class MediaPlayer
     @Override
     protected void finalize() throws Throwable
     {
+        release();
+        super.finalize();
+    }
+
+    public void release()
+    {
+        if (released)
+        {
+            return;
+        }
+        released = true;
+
         libvlc_exception_t exception = new libvlc_exception_t();
         for (MediaPlayerCallback callback : callbacks)  
         {
@@ -187,9 +201,9 @@ public class MediaPlayer
             }
         }
         libvlc.libvlc_media_player_release(instance);
-        super.finalize();
+        
     }
-
+    
     /**
      * Returns the instance.
      * @return the instance