[Android] Use length_change_monitor to wait until the demux is working

Ludovic Fauvet etix at videolan.org
Wed Jun 20 09:19:27 CEST 2012


On Wed, Jun 20, 2012 at 5:51 AM, Edward Wang <git at videolan.org> wrote:
> android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Tue Jun 19 23:49:29 2012 -0400| [d529d95f73b86052439c8644fce3b38f776f1518] | committer: Edward Wang
>
> Use length_change_monitor to wait until the demux is working
>
> Otherwise, on network streams this function would also return audio because the demux had not finished adding the es yet.
>
>> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=d529d95f73b86052439c8644fce3b38f776f1518
> ---
>
>  vlc-android/jni/libvlcjni.c |   39 ++++++++++++++++++++++++++++-----------
>  1 file changed, 28 insertions(+), 11 deletions(-)
>
> diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
> index c62d0c9..f6979ae 100644
> --- a/vlc-android/jni/libvlcjni.c
> +++ b/vlc-android/jni/libvlcjni.c
> @@ -558,20 +558,37 @@ jboolean Java_org_videolan_vlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
>     libvlc_media_track_info_t *p_tracks;
>     libvlc_media_parse(p_m);
>
> -    jboolean hasVideo = JNI_FALSE;
> -    int i_nbTracks = libvlc_media_get_tracks_info(p_m, &p_tracks);
> -    unsigned i;
> -    for (i = 0; i < i_nbTracks; ++i)
> -        if (p_tracks[i].i_type == libvlc_track_video)
> -        {
> -            hasVideo = JNI_TRUE;
> -            break;
> -        }
> +    libvlc_media_player_t* p_mp = libvlc_media_player_new_from_media(p_m);
>
> -    libvlc_media_tracks_info_release(p_tracks, i_nbTracks);
> +    struct length_change_monitor* monitor;
> +    monitor = malloc(sizeof(struct length_change_monitor));
> +    if (!monitor) return 0;
> +
> +    /* Initialize pthread variables. */
> +    pthread_mutex_init(&monitor->doneMutex, NULL);
> +    pthread_cond_init(&monitor->doneCondVar, NULL);
> +    monitor->length_changed = false;
> +
> +    libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_mp);
> +    libvlc_event_attach(ev, libvlc_MediaPlayerLengthChanged, length_changed_callback, monitor);
> +    libvlc_media_player_play( p_mp );
> +
> +    pthread_mutex_lock(&monitor->doneMutex);
> +    while (!monitor->length_changed)
> +        pthread_cond_wait(&monitor->doneCondVar, &monitor->doneMutex);
> +    pthread_mutex_unlock(&monitor->doneMutex);
> +
> +    int i_nbTracks = libvlc_video_get_track_count(p_mp);
> +    LOGI("Number of video tracks: %d",i_nbTracks);
> +
> +    libvlc_media_player_stop(p_mp);
> +    libvlc_media_player_release(p_mp);
>     libvlc_media_release(p_m);
>

aren't you leaking monitor here?

> -    return hasVideo;
> +    if(i_nbTracks > 0)
> +        return JNI_TRUE;
> +    else
> +        return JNI_FALSE;
>  }
>
>  jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject thiz,

Best regards,
-- Ludovic Fauvet


More information about the Android mailing list