<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">2014-07-27 19:24 GMT+01:00 Jean-Baptiste Kempf <span dir="ltr"><<a href="mailto:jb@videolan.org" target="_blank">jb@videolan.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks a lot for the work.<br>
It's a hard one, especially, since it was not correctly designed on day<br>
one...<br>
<br>
On 27 Jul, Paulo Vitor Magacho da Silva wrote :<br>
<div class="">> +    // initialize android_surface_value_t structure<br>
> +    android_surf_value_t *android_surface = (android_surf_value_t *) malloc(sizeof(android_surf_value_t));<br>
<br>
</div>Unchecked malloc...</blockquote><div><br></div><div>Will fix.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
> -    init_native_crash_handler(env, thiz);<br>
> +    // init_native_crash_handler(env, thiz);<br>
<br>
</div>Why?<br></blockquote><div><br></div><div>Still need to figure out to handle this without using global variable.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
> +    // destroy_native_crash_handler(env);<br>
<br>
idem.<br></blockquote><div><br></div><div>idem.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
>  void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {<br>
> -    pthread_mutex_lock(&vout_android_lock);<br>
> -    vout_android_surf = NULL;<br>
> -    if (vout_android_gui != NULL)<br>
> -        (*env)->DeleteGlobalRef(env, vout_android_gui);<br>
> -    if (vout_android_java_surf != NULL)<br>
> -        (*env)->DeleteGlobalRef(env, vout_android_java_surf);<br>
> -    vout_android_gui = NULL;<br>
> -    vout_android_java_surf = NULL;<br>
> -    pthread_mutex_unlock(&vout_android_lock);<br>
> +    android_surf_value_t * android_surface = (android_surf_value_t *)(intptr_t)getLong(env, thiz, "mAndroidSurfaceValue");<br>
> +<br>
> +    pthread_mutex_lock(&android_surface->vout_android_lock);<br>
> +    android_surface->vout_android_surf = NULL;<br>
> +    if (android_surface->vout_android_gui != NULL)<br>
> +        (*env)->DeleteGlobalRef(env, android_surface->vout_android_gui);<br>
> +    if (android_surface->vout_android_java_surf != NULL)<br>
> +        (*env)->DeleteGlobalRef(env, android_surface->vout_android_java_surf);<br>
> +    android_surface->vout_android_gui = NULL;<br>
> +    android_surface->vout_android_java_surf = NULL;<br>
> +    pthread_mutex_unlock(&android_surface->vout_android_lock);<br>
>  }<br>
<br>
</div>Wouldn't it better to pass the surface in parameter to the function ?<br></blockquote><div><br></div><div>I think that could be like that also.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
>  void Java_org_videolan_libvlc_LibVLC_attachSubtitlesSurface(JNIEnv *env, jobject thiz, jobject surf) {<br>
> -    pthread_mutex_lock(&vout_android_lock);<br>
> -    vout_android_subtitles_surf = (*env)->NewGlobalRef(env, surf);<br>
> -    pthread_cond_signal(&vout_android_surf_attached);<br>
> -    pthread_mutex_unlock(&vout_android_lock);<br>
> +    android_surf_value_t * android_surface = (android_surf_value_t *)(intptr_t)getLong(env, thiz, "mAndroidSurfaceValue");<br>
> +<br>
> +    pthread_mutex_lock(&android_surface->vout_android_lock);<br>
> +    android_surface->vout_android_subtitles_surf = (*env)->NewGlobalRef(env, surf);<br>
> +    pthread_cond_signal(&android_surface->vout_android_surf_attached);<br>
> +    pthread_mutex_unlock(&android_surface->vout_android_lock);<br>
>  }<br>
><br>
>  void Java_org_videolan_libvlc_LibVLC_detachSubtitlesSurface(JNIEnv *env, jobject thiz) {<br>
> -    pthread_mutex_lock(&vout_android_lock);<br>
> -    (*env)->DeleteGlobalRef(env, vout_android_subtitles_surf);<br>
> -    vout_android_subtitles_surf = NULL;<br>
> -    pthread_mutex_unlock(&vout_android_lock);<br>
> +    android_surf_value_t * android_surface = (android_surf_value_t *)(intptr_t)getLong(env, thiz, "mAndroidSurfaceValue");<br>
> +<br>
> +    pthread_mutex_lock(&android_surface->vout_android_lock);<br>
> +    if (android_surface->vout_android_subtitles_surf != NULL)<br>
> +        (*env)->DeleteGlobalRef(env, android_surface->vout_android_subtitles_surf);<br>
> +    android_surface->vout_android_subtitles_surf = NULL;<br>
> +    pthread_mutex_unlock(&android_surface->vout_android_lock);<br>
>  }<br>
<br>
</div>idem?<br></blockquote><div><br></div><div>idem.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
> +typedef struct android_surf_value_t {<br>
> +    pthread_mutex_t vout_android_lock;<br>
> +    pthread_cond_t vout_android_surf_attached;<br>
> +    void *vout_android_surf;<br>
> +    void *vout_android_gui;<br>
> +    jobject vout_android_java_surf;<br>
> +    jobject vout_android_subtitles_surf;<br>
> +    bool vout_video_player_activity_created;<br>
> +} android_surf_value_t;<br>
><br>
<br>
</div>I'm not such a fan of this...<br></blockquote><div><br></div><div>Will think of how to replace this. But I think for now we can go with this (if it's working of course).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
> --- a/vlc-android/src/org/videolan/libvlc/LibVLC.java<br>
> +++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java<br>
> @@ -51,6 +51,9 @@ public class LibVLC {<br>
>      private int mInternalMediaPlayerIndex = 0; // Read-only, reserved for JNI<br>
>      private long mInternalMediaPlayerInstance = 0; // Read-only, reserved for JNI<br>
><br>
> +    // Android surface structure<br>
> +    private long mAndroidSurfaceValue = 0; // Read-only, reserved for JNI<br>
<br>
</div>That means only one surface per libvlc instance?<br></blockquote><div><br></div><div>Yes. This is the idea. Do we need more ?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
> -    public static synchronized void restart(Context context) {<br>
> +    public static synchronized void restartInstance(Context context) {<br>
>          if (sInstance != null) {<br>
>              try {<br>
>                  sInstance.destroy();<br>
> @@ -235,6 +237,15 @@ public class LibVLC {<br>
>          }<br>
>      }<br>
><br>
> +    public void restart(Context context) {<br>
> +        try {<br>
> +            this.destroy();<br>
> +            this.init(context);<br>
> +        } catch (LibVlcException lve) {<br>
> +            Log.e(TAG, "Unable to reinit libvlc: " + lve);<br>
> +        }<br>
> +    }<br>
<br>
</div>So, there is restart and restartInstance? Isn't that, a bit confusing?<br></blockquote><div><br></div><div>This is just for now not to break VLC application. The VLC app needs to be refactored to support multiple player instances.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
> -    private void applyEqualizer()<br>
> +    protected void applyEqualizer()<br>
<br>
</div>How is that related to the rest?<br></blockquote><div><br></div><div>Native code calls this method. And if it's left as private LibVLC cannot be extended.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
With my kindest regards,<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Jean-Baptiste Kempf<br>
<a href="http://www.jbkempf.com/" target="_blank">http://www.jbkempf.com/</a> - <a href="tel:%2B33%20672%20704%20734" value="+33672704734">+33 672 704 734</a><br>
Sent from my Electronic Device<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</font></span></blockquote></div><br></div></div>