[Android] thumbnailer: do not wait until video position becomes *strictly* superior to THUMBNAIL_POSITION.

Felix Abecassis git at videolan.org
Wed Nov 27 15:31:00 CET 2013


vlc-ports/android | branch: 0.1.x-bugfix | Felix Abecassis <felix.abecassis at gmail.com> | Wed Nov 27 10:17:13 2013 +0100| [bf90b313dc9b7c0f21d547deb771966ab7cc80a3] | committer: Jean-Baptiste Kempf

thumbnailer: do not wait until video position becomes *strictly* superior to THUMBNAIL_POSITION.

Avoid waiting unnecessarily when the media player reaches exactly THUMBNAIL_POSITION. However we must now wait until libvlc updates the position before polling with libvlc_media_player_get_position().

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 0c2844f9a396953164890ea4d5b3a8723cb8a722)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 vlc-android/jni/thumbnailer.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/vlc-android/jni/thumbnailer.c b/vlc-android/jni/thumbnailer.c
index 2d41a59..1f65ed7 100644
--- a/vlc-android/jni/thumbnailer.c
+++ b/vlc-android/jni/thumbnailer.c
@@ -263,12 +263,12 @@ jbyteArray Java_org_videolan_libvlc_LibVLC_getThumbnail(JNIEnv *env, jobject thi
     libvlc_media_player_play(mp);
     libvlc_media_player_set_position(mp, THUMBNAIL_POSITION);
 
-    int loops = 100;
-    for (;;) {
-        float pos = libvlc_media_player_get_position(mp);
-        if (pos > THUMBNAIL_POSITION || !loops--)
+    const int wait_time = 50000;
+    const int max_attempts = 100;
+    for (int i = 0; i < max_attempts; ++i) {
+        if (libvlc_media_player_is_playing(mp) && libvlc_media_player_get_position(mp) >= THUMBNAIL_POSITION)
             break;
-        usleep(50000);
+        usleep(wait_time);
     }
 
     /* Wait for the thumbnail to be generated. */



More information about the Android mailing list