[Android] Abort thumbnailer if no video is coming after 10 seconds

Rafaël Carré git at videolan.org
Mon Jun 18 16:57:07 CEST 2012


android | branch: master | Rafaël Carré <funman at videolan.org> | Mon Jun 18 16:55:22 2012 +0200| [ecc0cfe16ad0d4c7650fe1a5a86a8e211592d013] | committer: Rafaël Carré

Abort thumbnailer if no video is coming after 10 seconds

Closes #6958

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

 vlc-android/jni/thumbnailer.c |   34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/vlc-android/jni/thumbnailer.c b/vlc-android/jni/thumbnailer.c
index 8c0b660..151378b 100644
--- a/vlc-android/jni/thumbnailer.c
+++ b/vlc-android/jni/thumbnailer.c
@@ -23,6 +23,8 @@
 #include <vlc/vlc.h>
 #include <pthread.h>
 #include <stdbool.h>
+#include <time.h>
+#include <errno.h>
 
 #define LOG_TAG "VLC/JNI/thumbnailer"
 #include "log.h"
@@ -227,24 +229,32 @@ jbyteArray Java_org_videolan_vlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
 
     /* Wait for the thumbnail to be generated. */
     pthread_mutex_lock(&sys->doneMutex);
-    while (!sys->hasThumb)
-        pthread_cond_wait(&sys->doneCondVar, &sys->doneMutex);
+    struct timespec deadline;
+    clock_gettime(CLOCK_REALTIME, &deadline);
+    deadline.tv_sec += 10; /* amount of seconds before we abort thumbnailer */
+    while (!sys->hasThumb) {
+        int ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline);
+        if (ret == ETIMEDOUT)
+            break;
+    }
     pthread_mutex_unlock(&sys->doneMutex);
 
-    /* Stop and realease the media player. */
+    /* Stop and release the media player. */
     libvlc_media_player_stop(sys->mp);
     libvlc_media_player_release(sys->mp);
 
-    /* Create the Java byte array to return the create thumbnail. */
-    byteArray = (*env)->NewByteArray(env, thumbnailSize);
-    if (byteArray == NULL)
-    {
-        LOGE("Could not allocate the Java byte array to store the frame!");
-        goto end;
-    }
+    if (sys->hasThumb) {
+        /* Create the Java byte array to return the create thumbnail. */
+        byteArray = (*env)->NewByteArray(env, thumbnailSize);
+        if (byteArray == NULL)
+        {
+            LOGE("Could not allocate the Java byte array to store the frame!");
+            goto end;
+        }
 
-    (*env)->SetByteArrayRegion(env, byteArray, 0, thumbnailSize,
-                                 (jbyte *)sys->thumbnail);
+        (*env)->SetByteArrayRegion(env, byteArray, 0, thumbnailSize,
+                (jbyte *)sys->thumbnail);
+    }
 
 end:
     pthread_mutex_destroy(&sys->doneMutex);



More information about the Android mailing list