[Android] Fix RendererItem created twice

Geoffrey Métais git at videolan.org
Thu Jul 19 13:18:09 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul 18 12:07:25 2018 +0200| [813cdff0d971d1e36832a77e9472b54971e48bfc] | committer: Geoffrey Métais

Fix RendererItem created twice

> https://code.videolan.org/videolan/vlc-android/commit/813cdff0d971d1e36832a77e9472b54971e48bfc
---

 libvlc/jni/libvlcjni-rendererdiscoverer.c              | 13 ++++++++-----
 libvlc/src/org/videolan/libvlc/RendererDiscoverer.java |  3 ++-
 libvlc/src/org/videolan/libvlc/RendererItem.java       | 12 ------------
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/libvlc/jni/libvlcjni-rendererdiscoverer.c b/libvlc/jni/libvlcjni-rendererdiscoverer.c
index cc3bfa0f3..1a3383402 100644
--- a/libvlc/jni/libvlcjni-rendererdiscoverer.c
+++ b/libvlc/jni/libvlcjni-rendererdiscoverer.c
@@ -197,22 +197,25 @@ error:
 }
 
 jobject
-Java_org_videolan_libvlc_RendererItem_nativeNewItem(JNIEnv *env, jobject thiz, jobject rd,
+Java_org_videolan_libvlc_RendererDiscoverer_nativeNewItem(JNIEnv *env, jobject thiz,
                                                     jlong ref)
 {
-    vlcjni_object *p_rd_obj = VLCJniObject_getInstance(env, rd);
+    vlcjni_object *p_rd_obj = VLCJniObject_getInstance(env, thiz);
     vlcjni_object *p_obj;
+    libvlc_renderer_item_t *item_ref = (libvlc_renderer_item_t *)(intptr_t)ref;
 
     if (!p_rd_obj)
         return NULL;
 
-    p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_rd_obj->p_libvlc);
+    jobject jitem = item_to_object(env, item_ref);
+
+    p_obj = VLCJniObject_newFromLibVlc(env, jitem, p_rd_obj->p_libvlc);
     if (!p_obj)
         return NULL;
 
-    p_obj->u.p_r = libvlc_renderer_item_hold((libvlc_renderer_item_t *)ref);
+    p_obj->u.p_r = libvlc_renderer_item_hold(item_ref);
 
-    return item_to_object(env, p_obj->u.p_r);
+    return jitem;
 }
 
 void
diff --git a/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java b/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
index 2baf28ee8..48d917ef6 100644
--- a/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
+++ b/libvlc/src/org/videolan/libvlc/RendererDiscoverer.java
@@ -112,7 +112,7 @@ public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
 
     private final LongSparseArray<RendererItem> index = new LongSparseArray<>();
     private synchronized RendererItem insertItemFromEvent(long arg1) {
-        final RendererItem item = new RendererItem(this, arg1);
+        final RendererItem item = nativeNewItem(arg1);
         index.put(arg1, item);
         return item;
     }
@@ -139,4 +139,5 @@ public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
     private native boolean nativeStart();
     private native void nativeStop();
     private static native Description[] nativeList(LibVLC libVLC);
+    private native RendererItem nativeNewItem(long ref);
 }
diff --git a/libvlc/src/org/videolan/libvlc/RendererItem.java b/libvlc/src/org/videolan/libvlc/RendererItem.java
index 0d1d7ba77..d9c1b6d65 100644
--- a/libvlc/src/org/videolan/libvlc/RendererItem.java
+++ b/libvlc/src/org/videolan/libvlc/RendererItem.java
@@ -15,17 +15,6 @@ public class RendererItem extends VLCObject<RendererItem.Event> {
     final int flags;
     private final long ref;
 
-    RendererItem (RendererDiscoverer rd, long ref) {
-        super(rd);
-        final RendererItem item = nativeNewItem(rd, ref);
-        name = item == null ? null : item.name;
-        displayName = item == null ? null : item.displayName;
-        this.type = item == null ? null : item.type;
-        this.iconUrl = item == null ? null : item.iconUrl;
-        this.flags = item == null ? 0 : item.flags;
-        this.ref = item == null ? ref : item.ref;
-    }
-
     RendererItem(String name, String type, String iconUrl, int flags, long ref) {
         final int index = name.lastIndexOf('-');
         this.name = name;
@@ -57,6 +46,5 @@ public class RendererItem extends VLCObject<RendererItem.Event> {
         }
     }
 
-    private native RendererItem nativeNewItem(RendererDiscoverer rd, long ref);
     private native void nativeReleaseItem();
 }



More information about the Android mailing list