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

Rafaël Carré rafael.carre at gmail.com
Tue Nov 26 19:46:41 CET 2013


If (is_playing && get_position) does exactly this :)


Felix Abecassis <felix.abecassis at gmail.com> a écrit :
>Because I don't want to call get_position before is_playing becomes
>true.
>But you are right, it can be done.
>
>2013/11/26 Rafaël Carré <rafael.carre at gmail.com>:
>> Why not merge is_playing and get_position in one single loop?
>>
>>
>> Felix Abecassis <felix.abecassis at gmail.com> a écrit :
>>>
>>> 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().
>>> ---
>>> vlc-android/jni/thumbnailer.c | 15 +++++++++++----
>>> 1 file changed, 11 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/vlc-android/jni/thumbnailer.c
>b/vlc-android/jni/thumbnailer.c
>>> index 2d41a59..4086612 100644
>>> --- a/vlc-android/jni/thumbnailer.c
>>> +++ b/vlc-android/jni/thumbnailer.c
>>> @@ -263,12 +263,19 @@ 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 (;;) {
>>> +    int wait_time = 50000;
>>> +    int max_attempts = 100;
>>> +    for (int i = 0; i < max_attempts; ++i) {
>>> +        int playing = libvlc_media_player_is_playing(mp);
>>> +
>>>     if (playing)
>>> +            break;
>>> +        usleep(wait_time);
>>> +    }
>>> +    for (int i = 0; i < max_attempts; ++i) {
>>> float pos = libvlc_media_player_get_position(mp);
>>> -        if (pos > THUMBNAIL_POSITION || !loops--)
>>> +        if (pos >= THUMBNAIL_POSITION)
>>> break;
>>> -        usleep(50000);
>>> +        usleep(wait_time);
>>> }
>>>
>>> /* Wait for the thumbnail to be generated. */
>>
>>
>> --
>> Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.
>>
>> _______________________________________________
>> Android mailing list
>> Android at videolan.org
>> https://mailman.videolan.org/listinfo/android
>>
>
>
>
>-- 
>Félix Abecassis
>http://felix.abecassis.me
>_______________________________________________
>Android mailing list
>Android at videolan.org
>https://mailman.videolan.org/listinfo/android

-- 
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20131126/b246fd6a/attachment.html>


More information about the Android mailing list