<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>I don't like this, you shouldn't lock a mutex  each time you want to access the pool.<br></div>
<div>Especially when this mutex can be holded for some time by others jni_func*.<br></div>
<div> </div>
<div>And what happen for MediaCodec (that is used by default on most device after android 4.2) ?<br></div>
<div> </div>
<div>I'm not saying the actual solution is perfect, I planned to work on it after your single instance patch is merged.<br></div>
<div> </div>
<div>On Mon, Dec 8, 2014, at 14:10, Paulo Vitor Magacho da Silva wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>Hi,<br></div>
<div>do you think this patch can be accepted ? I need this to submit the multiple video instances patch.<br></div>
<div>Thanks<br></div>
<div> </div>
<div defang_data-gmailquote="yes"><div>2014-12-04 23:10 GMT-02:00 Paulo Vitor Magacho da Silva <span dir="ltr"><<a defang_rel="noreferrer" href="">pvmagacho@gmail.com</a>></span>:<br></div>
<blockquote defang_data-gmailquote="yes" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 modules/video_output/android/android_window.c | 14 ++++++++++++++<br>
 modules/video_output/android/surface.c        | 23 +++++++++++++++++------<br>
 2 files changed, 31 insertions(+), 6 deletions(-)<br> <br>
diff --git a/modules/video_output/android/android_window.c b/modules/video_output/android/android_window.c<br>
index e584a54..5c50975 100644<br>
--- a/modules/video_output/android/android_window.c<br>
+++ b/modules/video_output/android/android_window.c<br>
@@ -73,6 +73,7 @@ extern void jni_detach_thread();<br>
 extern jobject jni_LockAndGetAndroidJavaSurface();<br>
 extern jobject jni_LockAndGetSubtitlesSurface();<br>
 extern void  jni_UnlockAndroidSurface();<br>
+extern bool  jni_LockAndGetIsSurfaceAttached();<br> <br>
 extern void  jni_SetSurfaceLayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
 extern int jni_ConfigureSurface(jobject jsurf, int width, int height, int hal, bool *configured);<br>
@@ -954,6 +955,13 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned requested_count)<br>
 {<br>
     vout_display_sys_t *sys = vd->sys;<br> <br>
+    if (!jni_LockAndGetIsSurfaceAttached() && sys->pool != NULL) {<br>
+        msg_Dbg(vd, "Surface got destroyed");<br>
+        picture_pool_Release(sys->pool);<br>
+        sys->pool = NULL;<br>
+    }<br>
+    jni_UnlockAndroidSurface();<br>
+<br>
     if (sys->pool == NULL)<br>
         sys->pool = PoolAlloc(vd, requested_count);<br>
     return sys->pool;<br>
@@ -982,6 +990,12 @@ static void Prepare(vout_display_t *vd, picture_t *picture,<br>
             sys->p_sub_buffer_bounds = NULL;<br>
         }<br> <br>
+        if (!jni_LockAndGetIsSurfaceAttached() && sys->p_sub_pic != NULL) {<br>
+            picture_Release(sys->p_sub_pic);<br>
+            sys->p_sub_pic = NULL;<br>
+        }<br>
+        jni_UnlockAndroidSurface();<br>
+<br>
         if (!sys->p_sub_pic && SetupWindowSubtitleSurface(sys) == 0)<br>
             sys->p_sub_pic = PictureAlloc(sys, &sys->p_sub_window->fmt);<br>
         if (!sys->p_spu_blend)<br>
diff --git a/modules/video_output/android/surface.c b/modules/video_output/android/surface.c<br>
index ce1f922..5ccb102 100644<br>
--- a/modules/video_output/android/surface.c<br>
+++ b/modules/video_output/android/surface.c<br>
@@ -78,6 +78,7 @@ extern int jni_attach_thread(JNIEnv **env, const char *thread_name);<br>
 extern void jni_detach_thread();<br>
 extern jobject jni_LockAndGetAndroidJavaSurface();<br>
 extern void  jni_UnlockAndroidSurface();<br>
+extern bool  jni_LockAndGetIsSurfaceAttached();<br>
 extern void *jni_AndroidJavaSurfaceToNativeSurface(jobject *surf);<br>
 extern void  jni_SetSurfaceLayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
 extern int jni_ConfigureSurface(jobject jsurf, int width, int height, int hal, bool *configured);<br>
@@ -329,10 +330,8 @@ static int  AndroidLockSurface(picture_t *picture)<br> <br>
     if (!sys->native_surface) {<br>
         picsys->surf = jni_LockAndGetAndroidJavaSurface();<br>
-        if (unlikely(!picsys->surf)) {<br>
-            jni_UnlockAndroidSurface();<br>
-            return VLC_EGENERIC;<br>
-        }<br>
+        if (unlikely(!picsys->surf))<br>
+            goto error;<br>
         sys->native_surface = jni_AndroidJavaSurfaceToNativeSurface(picsys->surf);<br>
         jni_UnlockAndroidSurface();<br> <br>
@@ -361,6 +360,11 @@ static int  AndroidLockSurface(picture_t *picture)<br>
         UpdateLayout(sys);<br>
     }<br> <br>
+    if (!jni_LockAndGetIsSurfaceAttached()) {<br>
+        sys->native_surface = NULL;<br>
+        goto error;<br>
+    }<br>
+<br>
     if (sys->s_lock)<br>
         sys->s_lock(sys->native_surface, info, 1);<br>
     else<br>
@@ -368,14 +372,20 @@ static int  AndroidLockSurface(picture_t *picture)<br> <br>
     if (info->w != sys->i_alloc_width || info->h != sh) {<br>
         sys->s_unlockAndPost(sys->native_surface);<br>
-        return VLC_EGENERIC;<br>
+        goto error;<br>
     }<br> <br>
+    jni_UnlockAndroidSurface();<br>
+<br>
     picture->p[0].p_pixels = (uint8_t*)info->bits;<br>
     picture->p[0].i_lines = info->h;<br>
     picture->p[0].i_pitch = picture->p[0].i_pixel_pitch * info->s;<br> <br>
     return VLC_SUCCESS;<br>
+<br>
+error:<br>
+    jni_UnlockAndroidSurface();<br>
+    return VLC_EGENERIC;<br>
 }<br> <br>
 static void AndroidUnlockSurface(picture_t *picture)<br>
@@ -383,8 +393,9 @@ static void AndroidUnlockSurface(picture_t *picture)<br>
     picture_sys_t *picsys = picture->p_sys;<br>
     vout_display_sys_t *sys = picsys->sys;<br> <br>
-    if (sys->native_surface)<br>
+    if (jni_LockAndGetIsSurfaceAttached() && sys->native_surface)<br>
         sys->s_unlockAndPost(sys->native_surface);<br>
+    jni_UnlockAndroidSurface();<br>
 }<br> <br>
 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)<br> <span><span style="color:rgb(136, 136, 136)" class="colour">--<br>
1.9.3 (Apple Git-50)<br> </span></span></blockquote></div>
<div> </div>
</div>
<div><u>_______________________________________________</u><br></div>
<div>vlc-devel mailing list<br></div>
<div>To unsubscribe or modify your subscription options:<br></div>
<div><a defang_rel="noreferrer" href="">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div>
</blockquote><div> </div>
</body>
</html>