<div dir="ltr">Hi,<div>I wonder if this will be applied ?<div>Thanks,</div><div>Paulo</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-11 1:16 GMT-02:00 Paulo Vitor Magacho da Silva <span dir="ltr"><<a href="mailto:pvmagacho@gmail.com" target="_blank">pvmagacho@gmail.com</a>></span>:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 modules/codec/omxil/android_mediacodec.c      | 30 +++++++++-----<br>
 modules/codec/omxil/omxil.c                   | 27 +++++++++----<br>
 modules/codec/omxil/omxil.h                   |  3 ++<br>
 modules/video_output/android/android_window.c | 58 ++++++++++++++++-----------<br>
 modules/video_output/android/nativewindow.c   | 14 +++----<br>
 modules/video_output/android/surface.c        | 47 ++++++++++++++--------<br>
 modules/video_output/android/utils.h          |  3 ++<br>
 7 files changed, 119 insertions(+), 63 deletions(-)<br>
<br>
diff --git a/modules/codec/omxil/android_mediacodec.c b/modules/codec/omxil/android_mediacodec.c<br>
index 2d0d346..015a27c 100644<br>
--- a/modules/codec/omxil/android_mediacodec.c<br>
+++ b/modules/codec/omxil/android_mediacodec.c<br>
@@ -50,13 +50,15 @@<br>
<br>
 #define THREAD_NAME "android_mediacodec"<br>
<br>
+typedef struct android_surf_value_t android_surf_value_t;<br>
+<br>
 extern int jni_attach_thread(JNIEnv **env, const char *thread_name);<br>
 extern void jni_detach_thread();<br>
 /* JNI functions to get/set an Android Surface object. */<br>
-extern jobject jni_LockAndGetAndroidJavaSurface();<br>
-extern void jni_UnlockAndroidSurface();<br>
-extern void jni_EventHardwareAccelerationError();<br>
-extern bool jni_IsVideoPlayerActivityCreated();<br>
+extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t *object);<br>
+extern void jni_UnlockAndroidSurface(android_surf_value_t *object);<br>
+extern void jni_EventHardwareAccelerationError(android_surf_value_t *android_surface);<br>
+extern bool jni_IsVideoPlayerActivityCreated(android_surf_value_t *android_surface);<br>
<br>
 /* Implementation of a circular buffer of timestamps with overwriting<br>
  * of older values. MediaCodec has only one type of timestamp, if a<br>
@@ -172,6 +174,8 @@ struct decoder_sys_t<br>
     picture_t** inflight_picture; /**< stores the inflight picture for each output buffer or NULL */<br>
<br>
     timestamp_fifo_t *timestamp_fifo;<br>
+<br>
+    android_surf_value_t *object;<br>
 };<br>
<br>
 enum Types<br>
@@ -325,6 +329,12 @@ static int OpenDecoder(vlc_object_t *p_this)<br>
     if ((p_dec->p_sys = p_sys = calloc(1, sizeof(*p_sys))) == NULL)<br>
         return VLC_ENOMEM;<br>
<br>
+    p_sys->object = var_CreateGetAddress (p_dec, "drawable-androidobject");<br>
+    if (!p_sys->object) {<br>
+        msg_Warn(p_dec, "No android_surf_value_t set.");<br>
+        return VLC_EGENERIC;<br>
+    }<br>
+<br>
     p_dec->pf_decode_video = DecodeVideo;<br>
<br>
     p_dec->fmt_out.i_cat = p_dec->fmt_in.i_cat;<br>
@@ -504,7 +514,7 @@ static int OpenDecoder(vlc_object_t *p_this)<br>
     /* If the VideoPlayerActivity is not started, MediaCodec opaque<br>
        direct rendering should be disabled since no surface will be<br>
        attached to the JNI. */<br>
-    p_sys->direct_rendering = jni_IsVideoPlayerActivityCreated() && var_InheritBool(p_dec, CFG_PREFIX "dr");<br>
+    p_sys->direct_rendering = jni_IsVideoPlayerActivityCreated(p_sys->object) && var_InheritBool(p_dec, CFG_PREFIX "dr");<br>
     if (p_sys->direct_rendering) {<br>
         if (p_dec->fmt_in.video.orientation != ORIENT_NORMAL) {<br>
             int i_angle;<br>
@@ -527,14 +537,14 @@ static int OpenDecoder(vlc_object_t *p_this)<br>
                                    i_angle);<br>
         }<br>
<br>
-        jobject surf = jni_LockAndGetAndroidJavaSurface();<br>
+        jobject surf = jni_LockAndGetAndroidJavaSurface(p_sys->object);<br>
         if (surf) {<br>
             // Configure MediaCodec with the Android surface.<br>
             (*env)->CallVoidMethod(env, p_sys->codec, p_sys->configure, format, surf, NULL, 0);<br>
             if ((*env)->ExceptionOccurred(env)) {<br>
                 msg_Warn(p_dec, "Exception occurred in MediaCodec.configure with an output surface.");<br>
                 (*env)->ExceptionClear(env);<br>
-                jni_UnlockAndroidSurface();<br>
+                jni_UnlockAndroidSurface(p_sys->object);<br>
                 goto error;<br>
             }<br>
             p_dec->fmt_out.i_codec = VLC_CODEC_ANDROID_OPAQUE;<br>
@@ -542,7 +552,7 @@ static int OpenDecoder(vlc_object_t *p_this)<br>
             msg_Warn(p_dec, "Failed to get the Android Surface, disabling direct rendering.");<br>
             p_sys->direct_rendering = false;<br>
         }<br>
-        jni_UnlockAndroidSurface();<br>
+        jni_UnlockAndroidSurface(p_sys->object);<br>
     }<br>
     if (!p_sys->direct_rendering) {<br>
         (*env)->CallVoidMethod(env, p_sys->codec, p_sys->configure, format, NULL, NULL, 0);<br>
@@ -597,6 +607,8 @@ static void CloseDecoder(vlc_object_t *p_this)<br>
     if (!p_sys)<br>
         return;<br>
<br>
+    var_Destroy (p_dec, "drawable-androidobject");<br>
+<br>
     /* Invalidate all pictures that are currently in flight in order<br>
      * to prevent the vout from using destroyed output buffers. */<br>
     if (p_sys->direct_rendering)<br>
@@ -906,7 +918,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)<br>
         block_Release(p_block);<br>
         if (!p_sys->error_event_sent) {<br>
             /* Signal the error to the Java. */<br>
-            jni_EventHardwareAccelerationError();<br>
+            jni_EventHardwareAccelerationError(p_sys->object);<br>
             p_sys->error_event_sent = true;<br>
         }<br>
         return NULL;<br>
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c<br>
index 03814d0..5c58f07 100644<br>
--- a/modules/codec/omxil/omxil.c<br>
+++ b/modules/codec/omxil/omxil.c<br>
@@ -70,9 +70,9 @@<br>
 #define THREAD_NAME "omxil"<br>
 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_IsVideoPlayerActivityCreated();<br>
+extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t *object);<br>
+extern void jni_UnlockAndroidSurface(android_surf_value_t *object);<br>
+extern bool jni_IsVideoPlayerActivityCreated(android_surf_value_t *android_surface);<br>
 #endif<br>
<br>
 /*****************************************************************************<br>
@@ -489,7 +489,7 @@ static OMX_ERRORTYPE AllocateBuffers(decoder_t *p_dec, OmxPort *p_port)<br>
                                     p_port->i_port_index, 0,<br>
                                     p_port->definition.nBufferSize);<br>
             OMX_DBG( "OMX_AllocateBuffer(%d) %p, %p", def->eDir,<br>
-                     p_port->pp_buffers[i], p_port->pp_buffers[i] ?<br>
+                     p_port->pp_buffers[i], p_port->pp_buffers[i] ?<br>
                      p_port->pp_buffers[i]->pBuffer : NULL );<br>
         }<br>
<br>
@@ -1056,6 +1056,15 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )<br>
         return VLC_ENOMEM;<br>
     }<br>
<br>
+#if defined(USE_IOMX)<br>
+    p_sys->object = var_CreateGetAddress (p_dec, "drawable-androidobject");<br>
+    if (!p_sys->object) {<br>
+        msg_Warn(p_dec, "No android_surf_value_t set.");<br>
+        DeinitOmxCore();<br>
+        return VLC_EGENERIC;<br>
+    }<br>
+#endif<br>
+<br>
     /* Initialise the thread properties */<br>
     if(!b_encode)<br>
     {<br>
@@ -1078,7 +1087,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )<br>
     p_sys->in.p_fmt = &p_dec->fmt_in;<br>
     OMX_FIFO_INIT (&p_sys->out.fifo, pInputPortPrivate );<br>
 #if defined(USE_IOMX)<br>
-    p_sys->out.b_direct = jni_IsVideoPlayerActivityCreated() && var_InheritBool(p_dec, CFG_PREFIX "dr");<br>
+    p_sys->out.b_direct = jni_IsVideoPlayerActivityCreated(p_sys->object) && var_InheritBool(p_dec, CFG_PREFIX "dr");<br>
 #else<br>
     p_sys->out.b_direct = false;<br>
 #endif<br>
@@ -1913,6 +1922,8 @@ static void CloseGeneric( vlc_object_t *p_this )<br>
     OMX_FIFO_DESTROY( &p_sys->in.fifo );<br>
     OMX_FIFO_DESTROY( &p_sys->out.fifo );<br>
<br>
+    var_Destroy (p_dec, "drawable-androidobject");<br>
+<br>
     free( p_sys );<br>
 }<br>
<br>
@@ -2089,9 +2100,9 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )<br>
         goto error;<br>
     }<br>
<br>
-    surf = jni_LockAndGetAndroidJavaSurface();<br>
+    surf = jni_LockAndGetAndroidJavaSurface(p_dec->p_sys->object);<br>
     if( !surf ) {<br>
-        jni_UnlockAndroidSurface();<br>
+        jni_UnlockAndroidSurface(p_dec->p_sys->object);<br>
         msg_Warn( p_dec, "jni_LockAndGetAndroidJavaSurface failed" );<br>
         goto error;<br>
     }<br>
@@ -2100,7 +2111,7 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )<br>
     p_port->p_hwbuf->window = p_port->p_hwbuf->native_window.winFromSurface( p_env, surf );<br>
     jni_detach_thread();<br>
<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(p_dec->p_sys->object);<br>
     if( !p_port->p_hwbuf->window ) {<br>
         msg_Warn( p_dec, "winFromSurface failed" );<br>
         goto error;<br>
diff --git a/modules/codec/omxil/omxil.h b/modules/codec/omxil/omxil.h<br>
index 911f5f6..02279a3 100644<br>
--- a/modules/codec/omxil/omxil.h<br>
+++ b/modules/codec/omxil/omxil.h<br>
@@ -138,4 +138,7 @@ struct decoder_sys_t<br>
     size_t i_nal_size_length; /* Length of the NAL size field for H264 */<br>
     int b_use_pts;<br>
<br>
+#if defined(USE_IOMX)<br>
+    android_surf_value_t *object;<br>
+#endif<br>
 };<br>
diff --git a/modules/video_output/android/android_window.c b/modules/video_output/android/android_window.c<br>
index 5c50975..eee7719 100644<br>
--- a/modules/video_output/android/android_window.c<br>
+++ b/modules/video_output/android/android_window.c<br>
@@ -70,14 +70,15 @@ vlc_module_end()<br>
 extern int jni_attach_thread(JNIEnv **env, const char *thread_name);<br>
 extern void jni_detach_thread();<br>
<br>
-extern jobject jni_LockAndGetAndroidJavaSurface();<br>
-extern jobject jni_LockAndGetSubtitlesSurface();<br>
-extern void  jni_UnlockAndroidSurface();<br>
-extern bool  jni_LockAndGetIsSurfaceAttached();<br>
+extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t *object);<br>
+extern jobject jni_LockAndGetSubtitlesSurface(android_surf_value_t *object);<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>
-extern int jni_GetWindowSize(int *width, int *height);<br>
+extern void  jni_UnlockAndroidSurface(android_surf_value_t *object);<br>
+extern bool  jni_LockAndGetIsSurfaceAttached(android_surf_value_t *object);<br>
+<br>
+extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
+extern int jni_ConfigureSurface(android_surf_value_t *object, int width, int height, int hal, bool *configured);<br>
+extern int jni_GetWindowSize(android_surf_value_t *object, int *width, int *height);<br>
<br>
 static const vlc_fourcc_t subpicture_chromas[] =<br>
 {<br>
@@ -137,9 +138,11 @@ struct vout_display_sys_t<br>
     bool b_has_subpictures;<br>
<br>
     uint8_t hash[16];<br>
+<br>
+    android_surf_value_t *object;<br>
 };<br>
<br>
-static int UpdateWindowSize(video_format_t *p_fmt, bool b_cropped)<br>
+static int UpdateWindowSize(vout_display_sys_t *sys, video_format_t *p_fmt, bool b_cropped)<br>
 {<br>
     unsigned int i_width, i_height;<br>
     unsigned int i_sar_num = 1, i_sar_den = 1;<br>
@@ -159,7 +162,8 @@ static int UpdateWindowSize(video_format_t *p_fmt, bool b_cropped)<br>
         i_height = rot_fmt.i_height;<br>
     }<br>
<br>
-    jni_SetSurfaceLayout(i_width, i_height,<br>
+    jni_SetSurfaceLayout(sys->object,<br>
+                         i_width, i_height,<br>
                          rot_fmt.i_visible_width,<br>
                          rot_fmt.i_visible_height,<br>
                          i_sar_num,<br>
@@ -437,7 +441,7 @@ static int AndroidWindow_ConfigureSurface(vout_display_sys_t *sys,<br>
      * if jni_ConfigureSurface succeed, you need to get a new surface handle.<br>
      * That's why AndroidWindow_SetSurface is called again here.<br>
      */<br>
-    err = jni_ConfigureSurface(p_window->jsurf,<br>
+    err = jni_ConfigureSurface(sys->object,<br>
                                p_window->fmt.i_width,<br>
                                p_window->fmt.i_height,<br>
                                p_window->i_android_hal,<br>
@@ -562,9 +566,9 @@ static int AndroidWindow_LockPicture(vout_display_sys_t *sys,<br>
 static int SetupWindowSurface(vout_display_sys_t *sys, unsigned i_pic_count)<br>
 {<br>
     int err;<br>
-    jobject jsurf = jni_LockAndGetAndroidJavaSurface();<br>
+    jobject jsurf = jni_LockAndGetAndroidJavaSurface(sys->object);<br>
     err = AndroidWindow_SetSurface(sys, sys->p_window, jsurf);<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(sys->object);<br>
     err = err == 0 ? AndroidWindow_Setup(sys, sys->p_window, i_pic_count) : err;<br>
     return err;<br>
 }<br>
@@ -572,9 +576,9 @@ static int SetupWindowSurface(vout_display_sys_t *sys, unsigned i_pic_count)<br>
 static int SetupWindowSubtitleSurface(vout_display_sys_t *sys)<br>
 {<br>
     int err;<br>
-    jobject jsurf = jni_LockAndGetSubtitlesSurface();<br>
+    jobject jsurf = jni_LockAndGetSubtitlesSurface(sys->object);<br>
     err = AndroidWindow_SetSurface(sys, sys->p_sub_window, jsurf);<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(sys->object);<br>
     err = err == 0 ? AndroidWindow_Setup(sys, sys->p_sub_window, 1) : err;<br>
     return err;<br>
 }<br>
@@ -602,7 +606,7 @@ static void SendEventDisplaySize(vout_display_t *vd)<br>
     vout_display_sys_t *sys = vd->sys;<br>
     int i_display_width, i_display_height;<br>
<br>
-    if (jni_GetWindowSize(&i_display_width, &i_display_height) == 0<br>
+    if (jni_GetWindowSize(sys->object, &i_display_width, &i_display_height) == 0<br>
         && i_display_width != 0 && i_display_height != 0<br>
         && (i_display_width != sys->i_display_width<br>
          || i_display_height != sys->i_display_height))<br>
@@ -624,6 +628,12 @@ static int Open(vlc_object_t *p_this)<br>
     if (!sys)<br>
         return VLC_ENOMEM;<br>
<br>
+    sys->object = var_CreateGetAddress (vd, "drawable-androidobject");<br>
+    if (!sys->object) {<br>
+        msg_Err(vd, "No android_surf_value_t set.");<br>
+        goto error;<br>
+    }<br>
+<br>
     sys->p_library = LoadNativeWindowAPI(&sys->anw);<br>
     if (!sys->p_library) {<br>
         msg_Err(vd, "Could not initialize NativeWindow API.");<br>
@@ -716,6 +726,8 @@ static void Close(vlc_object_t *p_this)<br>
     vout_display_t *vd = (vout_display_t *)p_this;<br>
     vout_display_sys_t *sys = vd->sys;<br>
<br>
+    var_Destroy (vd, "drawable-androidobject");<br>
+<br>
     if (!sys)<br>
         return;<br>
<br>
@@ -792,7 +804,7 @@ static picture_pool_t *PoolAlloc(vout_display_t *vd, unsigned requested_count)<br>
     requested_count = sys->p_window->i_pic_count;<br>
     msg_Dbg(vd, "PoolAlloc: got %d frames", requested_count);<br>
<br>
-    UpdateWindowSize(&sys->p_window->fmt, sys->p_window->b_use_priv);<br>
+    UpdateWindowSize(sys, &sys->p_window->fmt, sys->p_window->b_use_priv);<br>
<br>
     pp_pics = calloc(requested_count, sizeof(picture_t));<br>
<br>
@@ -891,7 +903,7 @@ static void SubtitleGetDirtyBounds(vout_display_t *vd,<br>
     if (!sys->p_sub_buffer_bounds<br>
      || sys->p_sub_buffer_bounds[i].p_pixels == NULL) {<br>
         buffer_bounds *p_bb = realloc(sys->p_sub_buffer_bounds,<br>
-                                      (i + 2) * sizeof(buffer_bounds));<br>
+                                      (i + 2) * sizeof(buffer_bounds));<br>
         if (p_bb) {<br>
             sys->p_sub_buffer_bounds = p_bb;<br>
             sys->p_sub_buffer_bounds[i].p_pixels = sys->p_sub_pic->p[0].p_pixels;<br>
@@ -955,12 +967,12 @@ 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>
+    if (!jni_LockAndGetIsSurfaceAttached(sys->object) && 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>
+    jni_UnlockAndroidSurface(sys->object);<br>
<br>
     if (sys->pool == NULL)<br>
         sys->pool = PoolAlloc(vd, requested_count);<br>
@@ -976,7 +988,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture,<br>
     SendEventDisplaySize(vd);<br>
<br>
     if (subpicture) {<br>
-        if (sys->b_sub_invalid) {<br>
+         if (sys->b_sub_invalid) {<br>
             sys->b_sub_invalid = false;<br>
             if (sys->p_sub_pic) {<br>
                 picture_Release(sys->p_sub_pic);<br>
@@ -990,11 +1002,11 @@ 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>
+        if (!jni_LockAndGetIsSurfaceAttached(sys->object) && sys->p_sub_pic != NULL) {<br>
             picture_Release(sys->p_sub_pic);<br>
             sys->p_sub_pic = NULL;<br>
         }<br>
-        jni_UnlockAndroidSurface();<br>
+        jni_UnlockAndroidSurface(sys->object);<br>
<br>
         if (!sys->p_sub_pic && SetupWindowSubtitleSurface(sys) == 0)<br>
             sys->p_sub_pic = PictureAlloc(sys, &sys->p_sub_window->fmt);<br>
@@ -1084,7 +1096,7 @@ static int Control(vout_display_t *vd, int query, va_list args)<br>
             } else<br>
                 CopySourceAspect(&sys->p_window->fmt, source);<br>
<br>
-            UpdateWindowSize(&sys->p_window->fmt, sys->p_window->b_use_priv);<br>
+            UpdateWindowSize(sys, &sys->p_window->fmt, sys->p_window->b_use_priv);<br>
         } else {<br>
             const vout_display_cfg_t *cfg;<br>
<br>
diff --git a/modules/video_output/android/nativewindow.c b/modules/video_output/android/nativewindow.c<br>
index 98c03fa..584bdec 100644<br>
--- a/modules/video_output/android/nativewindow.c<br>
+++ b/modules/video_output/android/nativewindow.c<br>
@@ -40,9 +40,9 @@<br>
 #define THREAD_NAME "ANativeWindow"<br>
 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 void  jni_SetSurfaceLayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
+extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t *object);<br>
+extern void jni_UnlockAndroidSurface(android_surf_value_t *object);<br>
+extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
<br>
 static int Open(vout_window_t *, const vout_window_cfg_t *);<br>
 static void Close(vout_window_t *);<br>
@@ -90,7 +90,7 @@ static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)<br>
     }<br>
<br>
     // Create the native window by first getting the Java surface.<br>
-    jobject javaSurface = jni_LockAndGetAndroidJavaSurface();<br>
+    jobject javaSurface = jni_LockAndGetAndroidJavaSurface(NULL);<br>
     if (javaSurface == NULL)<br>
         goto error;<br>
<br>
@@ -99,7 +99,7 @@ static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)<br>
     p_sys->window = p_sys->native_window.winFromSurface(p_env, javaSurface); // ANativeWindow_fromSurface call.<br>
     jni_detach_thread();<br>
<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(NULL);<br>
<br>
     if (p_sys->window == NULL)<br>
         goto error;<br>
@@ -110,7 +110,7 @@ static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)<br>
     wnd->sys = p_sys;<br>
<br>
     // Set the Java surface size.<br>
-    jni_SetSurfaceLayout(cfg->width, cfg->height, cfg->width, cfg->height, 1, 1);<br>
+    jni_SetSurfaceLayout(NULL, cfg->width, cfg->height, cfg->width, cfg->height, 1, 1);<br>
<br>
     return VLC_SUCCESS;<br>
<br>
@@ -144,7 +144,7 @@ static int Control(vout_window_t *wnd, int cmd, va_list ap)<br>
         {<br>
             unsigned width = va_arg(ap, unsigned);<br>
             unsigned height = va_arg(ap, unsigned);<br>
-            jni_SetSurfaceLayout(width, height, width, height, 1, 1);<br>
+            jni_SetSurfaceLayout(NULL, width, height, width, height, 1, 1);<br>
             break;<br>
         }<br>
         case VOUT_WINDOW_SET_STATE:<br>
diff --git a/modules/video_output/android/surface.c b/modules/video_output/android/surface.c<br>
index 5ccb102..a07f2eb 100644<br>
--- a/modules/video_output/android/surface.c<br>
+++ b/modules/video_output/android/surface.c<br>
@@ -76,12 +76,15 @@ vlc_module_end()<br>
 #define THREAD_NAME "AndroidSurface"<br>
 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>
+<br>
+extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t *object);<br>
+<br>
+extern void  jni_UnlockAndroidSurface(android_surf_value_t *object);<br>
+extern bool  jni_LockAndGetIsSurfaceAttached(android_surf_value_t *object);<br>
+extern void *jni_AndroidJavaSurfaceToNativeSurface(jobject surf);<br>
+<br>
+extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);<br>
+extern int jni_ConfigureSurface(android_surf_value_t *object, int width, int height, int hal, bool *configured);<br>
<br>
 // _ZN7android7Surface4lockEPNS0_11SurfaceInfoEb<br>
 typedef void (*Surface_lock)(void *, void *, int);<br>
@@ -125,6 +128,8 @@ struct vout_display_sys_t {<br>
     unsigned int i_alloc_height;<br>
<br>
     video_format_t fmt;<br>
+<br>
+    android_surf_value_t *object;<br>
 };<br>
<br>
 struct picture_sys_t {<br>
@@ -187,7 +192,8 @@ static void UpdateLayout(vout_display_sys_t *sys)<br>
         i_height = sys->fmt.i_height;<br>
     }<br>
<br>
-    jni_SetSurfaceLayout(i_width, i_height,<br>
+    jni_SetSurfaceLayout(sys->object,<br>
+                         i_width, i_height,<br>
                          sys->fmt.i_visible_width,<br>
                          sys->fmt.i_visible_height,<br>
                          i_sar_num,<br>
@@ -210,6 +216,13 @@ static int Open(vlc_object_t *p_this)<br>
     if (!sys)<br>
         goto error;<br>
<br>
+    sys->object = var_CreateGetAddress (vd, "drawable-androidobject");<br>
+    if (!sys->object) {<br>
+        free(sys);<br>
+        msg_Err(vd, "No android_surf_value_t set.");<br>
+        return VLC_EGENERIC;<br>
+    }<br>
+<br>
     /* */<br>
     sys->p_library = InitLibrary(sys);<br>
     if (!sys->p_library) {<br>
@@ -305,6 +318,8 @@ static void Close(vlc_object_t *p_this)<br>
     vout_display_t *vd = (vout_display_t *)p_this;<br>
     vout_display_sys_t *sys = vd->sys;<br>
<br>
+    var_Destroy (vd, "drawable-androidobject");<br>
+<br>
     if (sys) {<br>
         if (sys->pool)<br>
             picture_pool_Release(sys->pool);<br>
@@ -329,11 +344,11 @@ static int  AndroidLockSurface(picture_t *picture)<br>
     uint32_t sw, sh;<br>
<br>
     if (!sys->native_surface) {<br>
-        picsys->surf = jni_LockAndGetAndroidJavaSurface();<br>
+        picsys->surf = jni_LockAndGetAndroidJavaSurface(sys->object);<br>
         if (unlikely(!picsys->surf))<br>
             goto error;<br>
         sys->native_surface = jni_AndroidJavaSurfaceToNativeSurface(picsys->surf);<br>
-        jni_UnlockAndroidSurface();<br>
+        jni_UnlockAndroidSurface(sys->object);<br>
<br>
         if (!sys->native_surface)<br>
             return VLC_EGENERIC;<br>
@@ -347,7 +362,7 @@ static int  AndroidLockSurface(picture_t *picture)<br>
<br>
     if (aligned_width != sys->i_alloc_width || sh != sys->i_alloc_height) {<br>
         bool configured;<br>
-        if (jni_ConfigureSurface(picsys->surf,<br>
+        if (jni_ConfigureSurface(sys->object,<br>
                                  aligned_width,<br>
                                  sh,<br>
                                  sys->i_android_hal,<br>
@@ -360,7 +375,7 @@ static int  AndroidLockSurface(picture_t *picture)<br>
         UpdateLayout(sys);<br>
     }<br>
<br>
-    if (!jni_LockAndGetIsSurfaceAttached()) {<br>
+    if (!jni_LockAndGetIsSurfaceAttached(sys->object)) {<br>
         sys->native_surface = NULL;<br>
         goto error;<br>
     }<br>
@@ -372,10 +387,10 @@ 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>
-        goto error;<br>
+        return VLC_EGENERIC;<br>
     }<br>
<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(sys->object);<br>
<br>
     picture->p[0].p_pixels = (uint8_t*)info->bits;<br>
     picture->p[0].i_lines = info->h;<br>
@@ -384,7 +399,7 @@ static int  AndroidLockSurface(picture_t *picture)<br>
     return VLC_SUCCESS;<br>
<br>
 error:<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(sys->object);<br>
     return VLC_EGENERIC;<br>
 }<br>
<br>
@@ -393,9 +408,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 (jni_LockAndGetIsSurfaceAttached() && sys->native_surface)<br>
+    if (jni_LockAndGetIsSurfaceAttached(sys->object) && sys->native_surface)<br>
         sys->s_unlockAndPost(sys->native_surface);<br>
-    jni_UnlockAndroidSurface();<br>
+    jni_UnlockAndroidSurface(sys->object);<br>
 }<br>
<br>
 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)<br>
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h<br>
index 96d4f86..dfc4913 100644<br>
--- a/modules/video_output/android/utils.h<br>
+++ b/modules/video_output/android/utils.h<br>
@@ -24,6 +24,7 @@<br>
 # include "config.h"<br>
 #endif<br>
<br>
+#include <pthread.h><br>
 #include <android/native_window.h><br>
 #include <jni.h><br>
 #include <android/native_window_jni.h><br>
@@ -46,6 +47,8 @@ typedef struct<br>
     ptr_ANativeWindow_setBuffersGeometry setBuffersGeometry;<br>
 } native_window_api_t;<br>
<br>
+typedef struct android_surf_value_t android_surf_value_t;<br>
+<br>
 /* Fill the structure passed as parameter and return a library handle<br>
    that should be destroyed with dlclose. */<br>
 void *LoadNativeWindowAPI(native_window_api_t *native);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.3 (Apple Git-50)<br>
<br>
</font></span></blockquote></div></div>