[Android] Pass libvlc instance to the ML

Nicolas Pomepuy git at videolan.org
Thu Jun 10 09:40:57 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Mar 10 13:42:00 2021 +0100| [3f4d3aa3a5bf3a5b4f9c248a6de992d259092061] | committer: Nicolas Pomepuy

Pass libvlc instance to the ML

> https://code.videolan.org/videolan/vlc-android/commit/3f4d3aa3a5bf3a5b4f9c248a6de992d259092061
---

 .../vlc-android/src/org/videolan/vlc/MediaParsingService.kt      | 2 ++
 buildsystem/compile-medialibrary.sh                              | 2 +-
 libvlc/jni/libvlcjni-vlcobject.c                                 | 9 +++++++++
 libvlc/src/org/videolan/libvlc/VLCObject.java                    | 6 ++++--
 medialibrary/jni/AndroidMediaLibrary.cpp                         | 5 +++++
 medialibrary/jni/AndroidMediaLibrary.h                           | 1 +
 medialibrary/jni/medialibrary.cpp                                | 7 +++++++
 medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java | 6 ++++++
 .../src/org/videolan/medialibrary/interfaces/Medialibrary.java   | 1 +
 .../src/org/videolan/medialibrary/stubs/StubMedialibrary.java    | 3 +++
 10 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index adcd22b3a..c9c284271 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -43,6 +43,7 @@ import kotlinx.coroutines.channels.Channel
 import kotlinx.coroutines.channels.SendChannel
 import kotlinx.coroutines.channels.actor
 import org.videolan.libvlc.util.AndroidUtil
+import org.videolan.libvlc.LibVLC
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb
 import org.videolan.medialibrary.interfaces.Medialibrary
@@ -453,6 +454,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
                     val context = this at MediaParsingService
                     var shouldInit = !dbExists()
                     val initCode = medialibrary.init(context)
+                    medialibrary.setLibVLCInstance((VLCInstance.getInstance(context) as LibVLC).getInstance())
                     medialibrary.setDiscoverNetworkEnabled(true)
                     if (initCode != Medialibrary.ML_INIT_ALREADY_INITIALIZED) {
                         shouldInit = shouldInit or (initCode == Medialibrary.ML_INIT_DB_RESET) or (initCode == Medialibrary.ML_INIT_DB_CORRUPTED)
diff --git a/buildsystem/compile-medialibrary.sh b/buildsystem/compile-medialibrary.sh
index 62c45cfcc..bae6d1e3e 100755
--- a/buildsystem/compile-medialibrary.sh
+++ b/buildsystem/compile-medialibrary.sh
@@ -4,7 +4,7 @@
 # ARGUMENTS #
 #############
 
-MEDIALIBRARY_HASH=a688a101aa3ff85b4c2b7d985345987cbeb12e6c
+MEDIALIBRARY_HASH=dfe6e8164a7c650195ed9841c3befa1b6b27c7f3
 
 while [ $# -gt 0 ]; do
   case $1 in
diff --git a/libvlc/jni/libvlcjni-vlcobject.c b/libvlc/jni/libvlcjni-vlcobject.c
index 02ca8327b..5505404a9 100644
--- a/libvlc/jni/libvlcjni-vlcobject.c
+++ b/libvlc/jni/libvlcjni-vlcobject.c
@@ -226,3 +226,12 @@ Java_org_videolan_libvlc_VLCObject_nativeDetachEvents(JNIEnv *env, jobject thiz)
     p_obj->p_owner->p_event_manager = NULL;
     p_obj->p_owner->p_events = NULL;
 }
+
+long
+Java_org_videolan_libvlc_VLCObject_getInstance(JNIEnv *env, jobject thiz)
+{
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+    if (!p_obj)
+        return 0;
+    return p_obj->u.p_libvlc;
+}
diff --git a/libvlc/src/org/videolan/libvlc/VLCObject.java b/libvlc/src/org/videolan/libvlc/VLCObject.java
index 797c0c335..f1eba092a 100644
--- a/libvlc/src/org/videolan/libvlc/VLCObject.java
+++ b/libvlc/src/org/videolan/libvlc/VLCObject.java
@@ -23,14 +23,14 @@ package org.videolan.libvlc;
 import android.os.Handler;
 import android.os.Looper;
 
-import java.lang.ref.WeakReference;
-
 import androidx.annotation.Nullable;
 
 import org.videolan.libvlc.interfaces.AbstractVLCEvent;
 import org.videolan.libvlc.interfaces.ILibVLC;
 import org.videolan.libvlc.interfaces.IVLCObject;
 
+import java.lang.ref.WeakReference;
+
 @SuppressWarnings("JniMissingFunction")
 abstract class VLCObject<T extends AbstractVLCEvent> implements IVLCObject<T> {
     private AbstractVLCEvent.Listener<T> mEventListener = null;
@@ -191,4 +191,6 @@ abstract class VLCObject<T extends AbstractVLCEvent> implements IVLCObject<T> {
         if (obj != null)
             obj.dispatchEventFromNative(eventType, arg1, arg2, argf1, args1);
     }
+
+    public native long getInstance();
 }
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index ad52f2e53..b30529ff3 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -655,6 +655,11 @@ AndroidMediaLibrary::requestThumbnail( int64_t media_id, medialibrary::Thumbnail
     if (media != nullptr) media->requestThumbnail(sizeType, desiredWidth, desiredHeight, position);
 }
 
+void AndroidMediaLibrary::setLibvlcInstance( libvlc_instance_t* inst )
+{
+    p_ml->setExternalLibvlcInstance( inst );
+}
+
 void
 AndroidMediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> mediaList )
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 6dcc4f151..4b136f836 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -54,6 +54,7 @@ public:
     void forceRescan();
     bool setProgress(int64_t mediaId, float progress);
     bool removeMediaFromHistory(int64_t mediaId);
+    void setLibvlcInstance(libvlc_instance_t* inst);
     /* History */
     std::vector<medialibrary::MediaPtr> lastMediaPlayed();
     bool addToHistory( const std::string& mrl, const std::string& title );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index d2a34e6f4..0fd6c9912 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -155,6 +155,12 @@ setDiscoverNetworkEnabled(JNIEnv* env, jobject thiz, jboolean enabled)
     return aml->setDiscoverNetworkEnabled(enabled);
 }
 
+void
+setLibVLCInstance(JNIEnv* env, jobject thiz, jlong libVLC){
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    aml->setLibvlcInstance( (libvlc_instance_t*)libVLC );
+}
+
 void
 removeEntryPoint(JNIEnv* env, jobject thiz, jstring storagePath)
 {
@@ -2020,6 +2026,7 @@ static JNINativeMethod methods[] = {
     {"nativeDeleteRemovableDevices", "()Z", (void*)deleteRemovableDevices },
     {"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
     {"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
+    {"nativeSetLibVLCInstance", "(J)V", (void*)setLibVLCInstance },
     {"nativeSetDiscoverNetworkEnabled", "(Z)Z", (void*)setDiscoverNetworkEnabled },
     {"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
     {"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index d898b64f3..c50303c87 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -136,6 +136,11 @@ public class MedialibraryImpl extends Medialibrary {
         if (mIsInitiated) nativeDiscover(Tools.encodeVLCMrl(path));
     }
 
+    @Override
+    public void setLibVLCInstance(long libVLC) {
+        if (mIsInitiated) nativeSetLibVLCInstance(libVLC);
+    }
+
     @Override
     public boolean setDiscoverNetworkEnabled(boolean enabled) {
         if (mIsInitiated) return nativeSetDiscoverNetworkEnabled(enabled);
@@ -590,6 +595,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native boolean nativeDeleteRemovableDevices();
     private native String[] nativeDevices();
     private native void nativeDiscover(String path);
+    private native void nativeSetLibVLCInstance(long libVLC);
     private native boolean nativeSetDiscoverNetworkEnabled(boolean enabled);
     private native void nativeRemoveEntryPoint(String path);
     private native String[] nativeEntryPoints();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index a388bf0cf..e3984e78f 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -679,6 +679,7 @@ abstract public class Medialibrary {
     abstract public boolean isDeviceKnown(@NonNull String uuid, @NonNull String path, boolean removable);
     abstract public boolean deleteRemovableDevices();
     abstract public void discover(@NonNull String path);
+    abstract public void setLibVLCInstance(long libVLC);
     abstract public boolean setDiscoverNetworkEnabled(boolean enabled);
     abstract public void removeFolder(@NonNull String mrl);
     abstract public String[] getFoldersList();
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index 947ed7260..4ac453737 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -83,6 +83,9 @@ public class StubMedialibrary extends Medialibrary {
         onBackgroundTasksIdleChanged(true);
     }
 
+    @Override
+    public void setLibVLCInstance(long libVLC) { }
+
     @Override
     public boolean setDiscoverNetworkEnabled(boolean enabled) {
         return false;



More information about the Android mailing list