[vlc-devel] commit: jvlc #23: make native resources release explicit (Filippo Carone )

git version control git at videolan.org
Sun Jan 11 00:54:58 CET 2009


vlc | branch: master | Filippo Carone <littlejohn at videolan.org> | Sat Jan 10 02:39:53 2009 +0100| [de94406f0097da88e57f9a4f36acdbf50580a312] | committer: Filippo Carone 

jvlc #23: make native resources release explicit

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=de94406f0097da88e57f9a4f36acdbf50580a312
---

 .../core/src/main/java/org/videolan/jvlc/JVLC.java |    3 ++
 .../java/org/videolan/jvlc/MediaDescriptor.java    |    2 +-
 .../src/main/java/org/videolan/jvlc/MediaList.java |   23 ++++++++++++++++---
 .../java/org/videolan/jvlc/MediaListPlayer.java    |   18 ++++++++++++++-
 .../main/java/org/videolan/jvlc/MediaPlayer.java   |   18 +++++++++++++-
 5 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java b/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
index eef9a80..bcfd949 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/JVLC.java
@@ -176,6 +176,9 @@ public class JVLC
             vlm.release();
             vlm = null;
         }
+        mediaList.release();
+        mediaListPlayer.release();
+        
         libvlc.libvlc_release(instance);
     }
 
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java
index 5b5f14e..4997f4c 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java
@@ -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;
     
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
index c7dcbd0..834c4bd 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
@@ -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);
+    }
+
 
 
 }
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
index b5e9a72..032008e 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
@@ -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);
+        
+    }
+
 }
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
index da069b6..8590e46 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
@@ -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




More information about the vlc-devel mailing list