[vlc-commits] vout: android: move native_window_priv_api_t from AWindowHandler

Thomas Guillem git at videolan.org
Mon Nov 28 16:37:46 CET 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Nov 22 18:16:11 2016 +0100| [ee1c41694436c7ef812ace205fb8adee3860f8db] | committer: Thomas Guillem

vout: android: move native_window_priv_api_t from AWindowHandler

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ee1c41694436c7ef812ace205fb8adee3860f8db
---

 modules/codec/omxil/omxil.c            | 41 ++++++++++++------------
 modules/codec/omxil/omxil.h            |  2 +-
 modules/video_output/android/display.c | 57 +++++++++++++++++-----------------
 modules/video_output/android/utils.c   | 15 ++-------
 modules/video_output/android/utils.h   | 14 +++++----
 5 files changed, 61 insertions(+), 68 deletions(-)

diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 2ffaa6a..3e071a3 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -2083,10 +2083,9 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
         msg_Warn( p_dec, "AWindowHandler_new failed" );
         goto error;
     }
-    p_port->p_hwbuf->anwpriv = AWindowHandler_getANativeWindowPrivAPI( p_port->p_hwbuf->p_awh );
-    if( !p_port->p_hwbuf->anwpriv )
+    if( android_loadNativeWindowPrivApi( &p_port->p_hwbuf->anwpriv ) )
     {
-        msg_Warn( p_dec, "AWindowHandler_getANativeWindowPrivAPI failed" );
+        msg_Warn( p_dec, "android_loadNativeWindowPrivApi failed" );
         goto error;
     }
     p_anw = AWindowHandler_getANativeWindow( p_port->p_hwbuf->p_awh,
@@ -2097,7 +2096,7 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
         goto error;
     }
 
-    p_port->p_hwbuf->window_priv = p_port->p_hwbuf->anwpriv->connect( p_anw );
+    p_port->p_hwbuf->window_priv = p_port->p_hwbuf->anwpriv.connect( p_anw );
     if( !p_port->p_hwbuf->window_priv ) {
         msg_Warn( p_dec, "connect failed" );
         goto error;
@@ -2134,7 +2133,7 @@ static void HwBuffer_Destroy( decoder_t *p_dec, OmxPort *p_port )
             HwBuffer_Stop( p_dec, p_port );
             HwBuffer_FreeBuffers( p_dec, p_port );
             HwBuffer_Join( p_dec, p_port );
-            p_port->p_hwbuf->anwpriv->disconnect( p_port->p_hwbuf->window_priv );
+            p_port->p_hwbuf->anwpriv.disconnect( p_port->p_hwbuf->window_priv );
             pf_enable_graphic_buffers( p_port->omx_handle,
                                        p_port->i_port_index, OMX_FALSE );
         }
@@ -2201,17 +2200,17 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
             default:
                 i_angle = 0;
         }
-        p_port->p_hwbuf->anwpriv->setOrientation( p_port->p_hwbuf->window_priv,
+        p_port->p_hwbuf->anwpriv.setOrientation( p_port->p_hwbuf->window_priv,
                                                  i_angle );
     }
 
-    if( p_port->p_hwbuf->anwpriv->setUsage( p_port->p_hwbuf->window_priv,
+    if( p_port->p_hwbuf->anwpriv.setUsage( p_port->p_hwbuf->window_priv,
                                            true, (int) i_hw_usage ) != 0 )
     {
         msg_Err( p_dec, "can't set usage" );
         goto error;
     }
-    if( p_port->p_hwbuf->anwpriv->setBuffersGeometry( p_port->p_hwbuf->window_priv,
+    if( p_port->p_hwbuf->anwpriv.setBuffersGeometry( p_port->p_hwbuf->window_priv,
                                                      def->format.video.nFrameWidth,
                                                      def->format.video.nFrameHeight,
                                                      colorFormat ) != 0 )
@@ -2220,7 +2219,7 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
         goto error;
     }
 
-    if( p_port->p_hwbuf->anwpriv->getMinUndequeued( p_port->p_hwbuf->window_priv,
+    if( p_port->p_hwbuf->anwpriv.getMinUndequeued( p_port->p_hwbuf->window_priv,
                                                    &min_undequeued ) != 0 )
     {
         msg_Err( p_dec, "can't get min_undequeued" );
@@ -2242,7 +2241,7 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
                      omx_error, ErrorToString(omx_error) );
     }
 
-    if( p_port->p_hwbuf->anwpriv->setBufferCount( p_port->p_hwbuf->window_priv,
+    if( p_port->p_hwbuf->anwpriv.setBufferCount( p_port->p_hwbuf->window_priv,
                                                  def->nBufferCountActual ) != 0 )
     {
         msg_Err( p_dec, "can't set buffer_count" );
@@ -2270,7 +2269,7 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
     {
         void *p_handle = NULL;
 
-        if( p_port->p_hwbuf->anwpriv->dequeue( p_port->p_hwbuf->window_priv,
+        if( p_port->p_hwbuf->anwpriv.dequeue( p_port->p_hwbuf->window_priv,
                                               &p_handle ) != 0 )
         {
             msg_Err( p_dec, "OMXHWBuffer_dequeue Fail" );
@@ -2283,7 +2282,7 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
     for(; i < p_port->p_hwbuf->i_buffers; i++)
     {
         OMX_DBG( "canceling buffer(%d)", i );
-        p_port->p_hwbuf->anwpriv->cancel( p_port->p_hwbuf->window_priv,
+        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv,
                                          p_port->p_hwbuf->pp_handles[i] );
     }
 
@@ -2314,7 +2313,7 @@ static int HwBuffer_FreeBuffers( decoder_t *p_dec, OmxPort *p_port )
 
             if( p_handle && p_port->p_hwbuf->i_states[i] == BUF_STATE_OWNED )
             {
-                p_port->p_hwbuf->anwpriv->cancel( p_port->p_hwbuf->window_priv, p_handle );
+                p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
                 HwBuffer_ChangeState( p_dec, p_port, i, BUF_STATE_NOT_OWNED );
             }
         }
@@ -2354,7 +2353,7 @@ static int HwBuffer_Start( decoder_t *p_dec, OmxPort *p_port )
 
         if( p_header && p_port->p_hwbuf->i_states[i] == BUF_STATE_OWNED )
         {
-            if( p_port->p_hwbuf->anwpriv->lock( p_port->p_hwbuf->window_priv,
+            if( p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window_priv,
                                                p_header->pBuffer ) != 0 )
             {
                 msg_Err( p_dec, "lock failed" );
@@ -2487,7 +2486,7 @@ static void HwBuffer_SetCrop( decoder_t *p_dec, OmxPort *p_port,
 {
     VLC_UNUSED( p_dec );
 
-    p_port->p_hwbuf->anwpriv->setCrop( p_port->p_hwbuf->window_priv,
+    p_port->p_hwbuf->anwpriv.setCrop( p_port->p_hwbuf->window_priv,
                                       p_rect->nLeft, p_rect->nTop,
                                       p_rect->nWidth, p_rect->nHeight );
 }
@@ -2522,9 +2521,9 @@ static void *DequeueThread( void *data )
         /* The thread can be stuck here. It shouldn't happen since we make sure
          * we call the dequeue function if there is at least one buffer
          * available. */
-        err = p_port->p_hwbuf->anwpriv->dequeue( p_port->p_hwbuf->window_priv, &p_handle );
+        err = p_port->p_hwbuf->anwpriv.dequeue( p_port->p_hwbuf->window_priv, &p_handle );
         if( err == 0 )
-            err = p_port->p_hwbuf->anwpriv->lock( p_port->p_hwbuf->window_priv, p_handle );
+            err = p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window_priv, p_handle );
 
         HWBUFFER_LOCK( p_port );
 
@@ -2536,7 +2535,7 @@ static void *DequeueThread( void *data )
 
         if( !p_port->p_hwbuf->b_run )
         {
-            p_port->p_hwbuf->anwpriv->cancel( p_port->p_hwbuf->window_priv, p_handle );
+            p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
             continue;
         }
 
@@ -2551,7 +2550,7 @@ static void *DequeueThread( void *data )
         }
         if( i_index == -1 )
         {
-            msg_Err( p_dec, "p_port->p_hwbuf->anwpriv->dequeue returned unknown handle" );
+            msg_Err( p_dec, "p_port->p_hwbuf->anwpriv.dequeue returned unknown handle" );
             continue;
         }
 
@@ -2591,9 +2590,9 @@ static void ReleasePicture( decoder_t *p_dec, unsigned int i_index,
     }
 
     if( b_render )
-        p_port->p_hwbuf->anwpriv->queue( p_port->p_hwbuf->window_priv, p_handle );
+        p_port->p_hwbuf->anwpriv.queue( p_port->p_hwbuf->window_priv, p_handle );
     else
-        p_port->p_hwbuf->anwpriv->cancel( p_port->p_hwbuf->window_priv, p_handle );
+        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
 
     HwBuffer_ChangeState( p_dec, p_port, i_index, BUF_STATE_NOT_OWNED );
     HWBUFFER_BROADCAST( p_port );
diff --git a/modules/codec/omxil/omxil.h b/modules/codec/omxil/omxil.h
index b744b24..74a3621 100644
--- a/modules/codec/omxil/omxil.h
+++ b/modules/codec/omxil/omxil.h
@@ -77,7 +77,7 @@ typedef struct HwBuffer
 
 #if defined(USE_IOMX)
     AWindowHandler *p_awh;
-    native_window_priv_api_t *anwpriv;
+    native_window_priv_api_t anwpriv;
     native_window_priv *window_priv;
 #endif
 
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index 970c36c..7d9f9f3 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -113,7 +113,8 @@ struct vout_display_sys_t
 
     AWindowHandler *p_awh;
     native_window_api_t *anw;
-    native_window_priv_api_t *anwp;
+    native_window_priv_api_t anwp;
+    bool b_has_anwp;
 
     android_window *p_window;
     android_window *p_sub_window;
@@ -332,7 +333,7 @@ static void AndroidWindow_DisconnectSurface(vout_display_sys_t *sys,
                                             bool b_clear)
 {
     if (p_window->p_surface_priv) {
-        sys->anwp->disconnect(p_window->p_surface_priv);
+        sys->anwp.disconnect(p_window->p_surface_priv);
         p_window->p_surface_priv = NULL;
     }
     if (p_window->p_surface) {
@@ -369,7 +370,7 @@ static android_window *AndroidWindow_New(vout_display_t *vd,
     p_window->id = id;
     p_window->b_opaque = p_fmt->i_chroma == VLC_CODEC_ANDROID_OPAQUE;
     if (!p_window->b_opaque) {
-        p_window->b_use_priv = sys->anwp && b_use_priv;
+        p_window->b_use_priv = sys->b_has_anwp && b_use_priv;
 
         p_window->i_android_hal = ChromaToAndroidHal(p_fmt->i_chroma);
         if (p_window->i_android_hal == -1)
@@ -424,11 +425,11 @@ static int AndroidWindow_UpdateCrop(vout_display_sys_t *sys,
     if (!p_window->p_surface_priv)
         return -1;
 
-    return sys->anwp->setCrop(p_window->p_surface_priv,
-                              p_window->fmt.i_x_offset,
-                              p_window->fmt.i_y_offset,
-                              p_window->fmt.i_visible_width,
-                              p_window->fmt.i_visible_height);
+    return sys->anwp.setCrop(p_window->p_surface_priv,
+                             p_window->fmt.i_x_offset,
+                             p_window->fmt.i_y_offset,
+                             p_window->fmt.i_visible_width,
+                             p_window->fmt.i_visible_height);
 }
 
 static int AndroidWindow_SetupANWP(vout_display_sys_t *sys,
@@ -438,37 +439,37 @@ static int AndroidWindow_SetupANWP(vout_display_sys_t *sys,
     unsigned int i_max_buffer_count = 0;
 
     if (!p_window->p_surface_priv)
-        p_window->p_surface_priv = sys->anwp->connect(p_window->p_surface);
+        p_window->p_surface_priv = sys->anwp.connect(p_window->p_surface);
 
     if (!p_window->p_surface_priv)
         goto error;
 
-    if (sys->anwp->setUsage(p_window->p_surface_priv, false, 0) != 0)
+    if (sys->anwp.setUsage(p_window->p_surface_priv, false, 0) != 0)
         goto error;
 
     if (!b_java_configured
-        && sys->anwp->setBuffersGeometry(p_window->p_surface_priv,
-                                         p_window->fmt.i_width,
-                                         p_window->fmt.i_height,
-                                         p_window->i_android_hal) != 0)
+        && sys->anwp.setBuffersGeometry(p_window->p_surface_priv,
+                                        p_window->fmt.i_width,
+                                        p_window->fmt.i_height,
+                                        p_window->i_android_hal) != 0)
         goto error;
 
-    sys->anwp->getMinUndequeued(p_window->p_surface_priv,
-                                &p_window->i_min_undequeued);
+    sys->anwp.getMinUndequeued(p_window->p_surface_priv,
+                               &p_window->i_min_undequeued);
 
-    sys->anwp->getMaxBufferCount(p_window->p_surface_priv, &i_max_buffer_count);
+    sys->anwp.getMaxBufferCount(p_window->p_surface_priv, &i_max_buffer_count);
 
     if ((p_window->i_min_undequeued + p_window->i_pic_count) >
          i_max_buffer_count)
         p_window->i_pic_count = i_max_buffer_count - p_window->i_min_undequeued;
 
-    if (sys->anwp->setBufferCount(p_window->p_surface_priv,
-                                  p_window->i_pic_count +
-                                  p_window->i_min_undequeued) != 0)
+    if (sys->anwp.setBufferCount(p_window->p_surface_priv,
+                                 p_window->i_pic_count +
+                                 p_window->i_min_undequeued) != 0)
         goto error;
 
-    if (sys->anwp->setOrientation(p_window->p_surface_priv,
-                                  p_window->i_angle) != 0)
+    if (sys->anwp.setOrientation(p_window->p_surface_priv,
+                                 p_window->i_angle) != 0)
         goto error;
 
     AndroidWindow_UpdateCrop(sys, p_window);
@@ -476,7 +477,7 @@ static int AndroidWindow_SetupANWP(vout_display_sys_t *sys,
     return 0;
 error:
     if (p_window->p_surface_priv) {
-        sys->anwp->disconnect(p_window->p_surface_priv);
+        sys->anwp.disconnect(p_window->p_surface_priv);
         p_window->p_surface_priv = NULL;
     }
     p_window->b_use_priv = false;
@@ -575,7 +576,7 @@ static void AndroidWindow_UnlockPicture(vout_display_sys_t *sys,
         if (p_handle == NULL)
             return;
 
-        sys->anwp->unlockData(p_window->p_surface_priv, p_handle, b_render);
+        sys->anwp.unlockData(p_window->p_surface_priv, p_handle, b_render);
     } else
         sys->anw->unlockAndPost(p_window->p_surface);
 }
@@ -590,8 +591,8 @@ static int AndroidWindow_LockPicture(vout_display_sys_t *sys,
         void *p_handle;
         int err;
 
-        err = sys->anwp->lockData(p_window->p_surface_priv,
-                                  &p_handle, &p_picsys->priv.sw.buf);
+        err = sys->anwp.lockData(p_window->p_surface_priv,
+                                 &p_handle, &p_picsys->priv.sw.buf);
         if (err != 0)
             return -1;
         p_picsys->priv.sw.p_handle = p_handle;
@@ -675,8 +676,8 @@ static int Open(vlc_object_t *p_this)
     sys->anw = AWindowHandler_getANativeWindowAPI(sys->p_awh);
 
 #ifdef USE_ANWP
-    sys->anwp = AWindowHandler_getANativeWindowPrivAPI(sys->p_awh);
-    if (!sys->anwp)
+    sys->b_has_anwp = android_loadNativeWindowPrivApi(&sys->anwp) == 0;
+    if (!sys->b_has_anwp)
         msg_Warn(vd, "Could not initialize NativeWindow Priv API.");
 #endif
 
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 141b2ed..08d9f46 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -283,8 +283,8 @@ LoadNativeWindowAPI(AWindowHandler *p_awh)
  * Android private NativeWindow (post android 2.3)
  */
 
-static int
-LoadNativeWindowPrivAPI(native_window_priv_api_t *native)
+int
+android_loadNativeWindowPrivApi(native_window_priv_api_t *native)
 {
 #define LOAD(symbol) do { \
 if ((native->symbol = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_" #symbol)) == NULL) \
@@ -514,7 +514,7 @@ AWindowHandler_releaseANativeWindowEnv(AWindowHandler *p_awh, JNIEnv *p_env,
          * Don't do it earlier because MediaCodec may not be able to connect to
          * the surface anymore. */
         if (b_clear && p_awh->anw_api.setBuffersGeometry
-         && AWindowHandler_getANativeWindowPrivAPI(p_awh) == NULL)
+         && dlsym(RTLD_DEFAULT, "ANativeWindowPriv_connect") == NULL)
         {
             /* Clear the surface by displaying a 1x1 black RGB buffer */
             ANativeWindow *p_anw = p_awh->views[id].p_anw;
@@ -569,15 +569,6 @@ AWindowHandler_getANativeWindowAPI(AWindowHandler *p_awh)
     return &p_awh->anw_api;
 }
 
-native_window_priv_api_t *
-AWindowHandler_getANativeWindowPrivAPI(AWindowHandler *p_awh)
-{
-    if (LoadNativeWindowPrivAPI(&p_awh->anwpriv_api) != 0)
-        return NULL;
-    else
-        return &p_awh->anwpriv_api;
-}
-
 static int
 WindowHandler_NewSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
                             enum AWindow_ID id)
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 6072ac7..cdde4e7 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -97,6 +97,14 @@ typedef struct
 } native_window_priv_api_t;
 
 /**
+ * This function load a native_window_priv_api_t that can be used to access
+ * the private ANativeWindow API.
+ * \param api doesn't need to be released
+ * \return 0 on success, -1 on error.
+ */
+int android_loadNativeWindowPrivApi(native_window_priv_api_t *api);
+
+/**
  * This function returns a JNIEnv* created from the android JavaVM attached to
  * the VLC object var. it doesn't need to be released.
  */
@@ -117,12 +125,6 @@ void AWindowHandler_destroy(AWindowHandler *p_awh);
 native_window_api_t *AWindowHandler_getANativeWindowAPI(AWindowHandler *p_awh);
 
 /**
- * This function returns a native_window_priv_api_t that can be used to access
- * the private ANativeWindow API. It can be NULL and shouldn't be released
- */
-native_window_priv_api_t *AWindowHandler_getANativeWindowPrivAPI(AWindowHandler *p_awh);
-
-/**
  * This function retrieves the mouse coordinates sent by the Android
  * MediaPlayer. It returns true if the coordinates are valid.
  */



More information about the vlc-commits mailing list