[Android] Copy files vector to prevent race condition

Geoffrey Métais git at videolan.org
Tue Apr 4 10:18:29 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr  3 16:59:30 2017 +0200| [4d09ee518e3882d2b0533d2473f30d8c43c9b375] | committer: Geoffrey Métais

Copy files vector to prevent race condition

> https://code.videolan.org/videolan/vlc-android/commit/4d09ee518e3882d2b0533d2473f30d8c43c9b375
---

 medialibrary/jni/utils.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index bbe6db4..eb2ba2d 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -16,9 +16,11 @@
 jobject
 mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& mediaPtr)
 {
-    if (mediaPtr == nullptr || mediaPtr->files().empty())
+    if (mediaPtr == nullptr)
+        return nullptr;
+    const std::vector<medialibrary::FilePtr> files = mediaPtr->files();
+    if (files.empty())
         return nullptr;
-    medialibrary::FilePtr file = mediaPtr->files().at(0);
     //TODO get track, audio & spu track numbers
     jint type;
     switch (mediaPtr->type()) {
@@ -50,7 +52,7 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
         }
     }
     title = mediaPtr->title().empty() ? NULL : env->NewStringUTF(mediaPtr->title().c_str());
-    mrl = env->NewStringUTF(file->mrl().c_str());
+    mrl = env->NewStringUTF(files.at(0)->mrl().c_str());
     thumbnail = mediaPtr->thumbnail().empty() ? NULL : env->NewStringUTF(mediaPtr->thumbnail().c_str());
     std::vector<medialibrary::VideoTrackPtr> videoTracks = mediaPtr->videoTracks();
     bool hasVideoTracks = !videoTracks.empty();
@@ -63,7 +65,7 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
                           (jlong) mediaPtr->id(), mrl,(jlong) progress, (jlong) duration, type,
                           title, artist, genre, album,
                           albumArtist, width, height, thumbnail,
-                          (jint) -2, (jint) -2, (jint) 0, (jint) 0, (jlong) file->lastModificationDate());
+                          (jint) -2, (jint) -2, (jint) 0, (jint) 0, (jlong) files.at(0)->lastModificationDate());
     if (artist != NULL)
         env->DeleteLocalRef(artist);
     if (genre != NULL)



More information about the Android mailing list