[Android] LibVLC: Clean up renderers API

Geoffrey Métais git at videolan.org
Thu Feb 28 11:59:47 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 28 11:37:32 2019 +0100| [6cc497c9f899705fe1d1be24d3171ebb5a15400c] | committer: Geoffrey Métais

LibVLC: Clean up renderers API

> https://code.videolan.org/videolan/vlc-android/commit/6cc497c9f899705fe1d1be24d3171ebb5a15400c
---

 .../org/videolan/libvlc/RendererDiscoverer.java    | 23 ++++++++++++++++++++--
 .../src/org/videolan/vlc/RendererDelegate.kt       |  5 ++---
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java b/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
index fe107430c..ad02081da 100644
--- a/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
+++ b/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
@@ -20,26 +20,38 @@
 
 package org.videolan.libvlc;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import androidx.collection.LongSparseArray;
 
 public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
     private final static String TAG = "LibVLC/RendererDiscoverer";
 
+    final List<RendererItem> mRenderers = new ArrayList<>();
+
     public static class Event extends VLCEvent {
 
         public static final int ItemAdded   = 0x502;
         public static final int ItemDeleted = 0x503;
 
-        private RendererItem item;
+        private final RendererItem item;
 
         protected Event(int type, long nativeHolder, RendererItem item) {
             super(type, nativeHolder);
             this.item = item;
+            item.retain();
         }
 
         public RendererItem getItem() {
             return item;
         }
+
+        @Override
+        void release() {
+            item.release();
+            super.release();
+        }
     }
 
     @SuppressWarnings("unused") /* Used from JNI */
@@ -114,17 +126,24 @@ public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
     private synchronized RendererItem insertItemFromEvent(long arg1) {
         final RendererItem item = nativeNewItem(arg1);
         index.put(arg1, item);
+        mRenderers.add(item);
         return item;
     }
 
     private synchronized RendererItem removeItemFromEvent(long arg1) {
         final RendererItem item = index.get(arg1);
-        if (item != null) index.remove(arg1);
+        if (item != null) {
+            index.remove(arg1);
+            mRenderers.remove(item);
+            item.release();
+        }
         return item;
     }
 
     @Override
     protected void onReleaseNative() {
+        for (RendererItem item : mRenderers) item.release();
+        mRenderers.clear();
         nativeRelease();
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
index e40d60a7c..d17aeb4ed 100644
--- a/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/RendererDelegate.kt
@@ -58,7 +58,6 @@ object RendererDelegate : RendererDiscoverer.EventListener {
         if (!started) return
         started = false
         for (discoverer in discoverers) discoverer.stop()
-        for (renderer in renderers.value) renderer.release()
         clear()
     }
 
@@ -69,8 +68,8 @@ object RendererDelegate : RendererDiscoverer.EventListener {
 
     override fun onEvent(event: RendererDiscoverer.Event?) {
         when (event?.type) {
-            RendererDiscoverer.Event.ItemAdded -> { renderers.add(event.item) }
-            RendererDiscoverer.Event.ItemDeleted -> { renderers.remove(event.item); event.item.release() }
+            RendererDiscoverer.Event.ItemAdded -> renderers.add(event.item)
+            RendererDiscoverer.Event.ItemDeleted -> renderers.remove(event.item)
         }
     }
 }



More information about the Android mailing list