[vlc-devel] [PATCH 02/19] nativewindowpriv: use native_window_priv as a handle

Thomas Guillem thomas at gllm.fr
Fri Nov 14 17:09:53 CET 2014


---
 modules/codec/omxil/omxil.c                     |  36 +++----
 modules/codec/omxil/omxil.h                     |   1 +
 modules/video_output/android/nativewindowpriv.c | 129 +++++++++++-------------
 modules/video_output/android/utils.h            |  23 +++--
 4 files changed, 91 insertions(+), 98 deletions(-)

diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 042c2fc..5b1be01 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -2106,7 +2106,9 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
         msg_Warn( p_dec, "winFromSurface failed" );
         goto error;
     }
-    if( p_port->p_hwbuf->anwpriv.connect( p_port->p_hwbuf->window ) != 0 ) {
+    p_port->p_hwbuf->window_priv =
+        p_port->p_hwbuf->anwpriv.connect( p_port->p_hwbuf->window );
+    if( !p_port->p_hwbuf->window_priv ) {
         msg_Warn( p_dec, "connect failed" );
         p_port->p_hwbuf->native_window.winRelease( p_port->p_hwbuf->window );
         p_port->p_hwbuf->window = NULL;
@@ -2146,7 +2148,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 );
+                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 );
                 p_port->p_hwbuf->native_window.winRelease( p_port->p_hwbuf->window );
@@ -2210,14 +2212,14 @@ 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,
+        p_port->p_hwbuf->anwpriv.setOrientation( p_port->p_hwbuf->window_priv,
                                                  i_angle );
         video_format_ApplyRotation( &p_port->p_hwbuf->fmt_out,
                                     &p_port->p_fmt->video );
     } else
         p_port->p_hwbuf->fmt_out = p_port->p_fmt->video;
 
-    if( p_port->p_hwbuf->anwpriv.setup( p_port->p_hwbuf->window,
+    if( p_port->p_hwbuf->anwpriv.setup( p_port->p_hwbuf->window_priv,
                                         def->format.video.nFrameWidth,
                                         def->format.video.nFrameHeight,
                                         colorFormat,
@@ -2227,7 +2229,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,
+    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" );
@@ -2249,7 +2251,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,
+    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" );
@@ -2284,7 +2286,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,
+        if( p_port->p_hwbuf->anwpriv.dequeue( p_port->p_hwbuf->window_priv,
                                               &p_handle ) != 0 )
         {
             msg_Err( p_dec, "OMXHWBuffer_dequeue Fail" );
@@ -2297,7 +2299,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,
+        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv,
                                          p_port->p_hwbuf->pp_handles[i] );
     }
 
@@ -2328,7 +2330,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, 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 );
             }
         }
@@ -2368,7 +2370,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,
+            if( p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window_priv,
                                                p_header->pBuffer ) != 0 )
             {
                 msg_Err( p_dec, "lock failed" );
@@ -2418,7 +2420,7 @@ static int HwBuffer_Stop( decoder_t *p_dec, OmxPort *p_port )
                     void *p_handle = p_port->pp_buffers[p_picsys->i_index]->pBuffer;
                     if( p_handle )
                     {
-                        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, p_handle );
+                        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
                         HwBuffer_ChangeState( p_dec, p_port, p_picsys->i_index,
                                               BUF_STATE_NOT_OWNED );
                     }
@@ -2513,7 +2515,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,
+    p_port->p_hwbuf->anwpriv.setCrop( p_port->p_hwbuf->window_priv,
                                       p_rect->nLeft, p_rect->nTop,
                                       p_rect->nWidth, p_rect->nHeight );
 }
@@ -2548,9 +2550,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, &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, p_handle );
+            err = p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window_priv, p_handle );
 
         HWBUFFER_LOCK();
 
@@ -2562,7 +2564,7 @@ static void *DequeueThread( void *data )
 
         if( !p_port->p_hwbuf->b_run )
         {
-            p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, p_handle );
+            p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
             continue;
         }
 
@@ -2626,9 +2628,9 @@ static void DisplayBuffer( picture_sys_t* p_picsys, bool b_render )
     }
 
     if( b_render )
-        p_port->p_hwbuf->anwpriv.queue( p_port->p_hwbuf->window, 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, p_handle );
+        p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv, p_handle );
 
     HwBuffer_ChangeState( p_dec, p_port, p_picsys->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 651d708..3f793b5 100644
--- a/modules/codec/omxil/omxil.h
+++ b/modules/codec/omxil/omxil.h
@@ -80,6 +80,7 @@ typedef struct HwBuffer
 #if defined(USE_IOMX)
     native_window_api_t native_window;
     native_window_priv_api_t anwpriv;
+    native_window_priv *window_priv;
 #endif
 
 } HwBuffer;
diff --git a/modules/video_output/android/nativewindowpriv.c b/modules/video_output/android/nativewindowpriv.c
index 9448241..4f870e5 100644
--- a/modules/video_output/android/nativewindowpriv.c
+++ b/modules/video_output/android/nativewindowpriv.c
@@ -26,6 +26,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #if ANDROID_API <= 13
 #include <ui/android_native_buffer.h>
@@ -44,6 +45,12 @@ typedef int32_t status_t;
 #if ANDROID_API <= 13
 typedef android_native_buffer_t ANativeWindowBuffer_t;
 #endif
+typedef struct native_window_priv native_window_priv;
+
+struct native_window_priv
+{
+    ANativeWindow *anw;
+};
 
 #define LOG_TAG "VLC/ANW"
 
@@ -57,14 +64,6 @@ typedef android_native_buffer_t ANativeWindowBuffer_t;
     }\
 } while (0)
 
-#define CHECK_ANW() do {\
-    if( anw->common.magic != ANDROID_NATIVE_WINDOW_MAGIC &&\
-            anw->common.version != sizeof(ANativeWindow) ) {\
-        LOGE( "error, window not valid\n"  );\
-        return -EINVAL;\
-    }\
-} while (0)
-
 #define CHECK_ANB() do {\
     if( anb->common.magic != ANDROID_NATIVE_BUFFER_MAGIC &&\
             anb->common.version != sizeof(ANativeWindowBuffer_t) ) {\
@@ -73,130 +72,129 @@ typedef android_native_buffer_t ANativeWindowBuffer_t;
     }\
 } while (0)
 
-int ANativeWindowPriv_connect( void *window )
+native_window_priv *ANativeWindowPriv_connect( void *window )
 {
+    native_window_priv *priv;
     ANativeWindow *anw = (ANativeWindow *)window;
-    CHECK_ANW();
+
+    if( anw->common.magic != ANDROID_NATIVE_WINDOW_MAGIC &&
+            anw->common.version != sizeof(ANativeWindow) ) {
+        LOGE( "error, window not valid\n"  );
+        return NULL;
+    }
 
 #if ANDROID_API >= 14
     if (native_window_api_connect( anw, NATIVE_WINDOW_API_MEDIA ) != 0) {
         LOGE( "native_window_api_connect FAIL"  );
-        return -EINVAL;
+        return NULL;
     }
 #endif
 
-    return 0;
-}
+    priv = calloc( 1, sizeof(native_window_priv) );
 
-int ANativeWindowPriv_disconnect( void *window )
-{
-    ANativeWindow *anw = (ANativeWindow *)window;
+    if( !priv ) {
+#if ANDROID_API >= 14
+        native_window_api_disconnect( anw, NATIVE_WINDOW_API_MEDIA );
+#endif
+        return NULL;
+    }
+    priv->anw = anw;
 
-    CHECK_ANW();
+    return priv;
+}
 
+int ANativeWindowPriv_disconnect( native_window_priv *priv )
+{
 #if ANDROID_API >= 14
-    native_window_api_disconnect( anw, NATIVE_WINDOW_API_MEDIA );
+    native_window_api_disconnect( priv->anw, NATIVE_WINDOW_API_MEDIA );
 #endif
+    free(priv);
 
     return 0;
 }
 
-int ANativeWindowPriv_setup( void *window, int w, int h, int hal_format, int hw_usage )
+int ANativeWindowPriv_setup( native_window_priv *priv, int w, int h, int hal_format, int hw_usage )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     int usage = 0;
     status_t err;
 
-    CHECK_ANW();
-
     LOGD( "setup: %p, %d, %d, %X, %X\n",
-          anw, w, h, hal_format, hw_usage );
+          priv->anw, w, h, hal_format, hw_usage );
 
     usage |= hw_usage | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
 #if ANDROID_API >= 11
     usage |= GRALLOC_USAGE_EXTERNAL_DISP;
 #endif
 
-    err = native_window_set_usage( anw, usage );
+    err = native_window_set_usage( priv->anw, usage );
     CHECK_ERR();
 
 #if ANDROID_API <= 13
-    err = native_window_set_buffers_geometry( anw, w, h, hal_format );
+    err = native_window_set_buffers_geometry( priv->anw, w, h, hal_format );
     CHECK_ERR();
 #else
-    err = native_window_set_scaling_mode( anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW );
+    err = native_window_set_scaling_mode( priv->anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW );
     CHECK_ERR();
 
-    err = native_window_set_buffers_dimensions( anw, w, h );
+    err = native_window_set_buffers_dimensions( priv->anw, w, h );
     CHECK_ERR();
 
-    err = native_window_set_buffers_format( anw, hal_format );
+    err = native_window_set_buffers_format( priv->anw, hal_format );
     CHECK_ERR();
 #endif
 
     return 0;
 }
 
-int ANativeWindowPriv_getMinUndequeued( void *window, unsigned int *min_undequeued )
+int ANativeWindowPriv_getMinUndequeued( native_window_priv *priv, unsigned int *min_undequeued )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     status_t err;
 
-    CHECK_ANW();
 #if ANDROID_API >= 11
-    err = anw->query( anw, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, min_undequeued );
+    err = priv->anw->query( priv->anw, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, min_undequeued );
     CHECK_ERR();
 #endif
     /* set a minimum value of min_undequeued in case query fails */
     if( *min_undequeued == 0 )
         *min_undequeued = 2;
 
-    LOGD( "getMinUndequeued: %p %u", anw, *min_undequeued );
+    LOGD( "getMinUndequeued: %p %u", priv->anw, *min_undequeued );
 
     return 0;
 }
 
-int ANativeWindowPriv_setBufferCount(void *window, unsigned int count )
+int ANativeWindowPriv_setBufferCount(native_window_priv *priv, unsigned int count )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     status_t err;
 
-    CHECK_ANW();
-
-    LOGD( "setBufferCount: %p %u", anw, count );
+    LOGD( "setBufferCount: %p %u", priv->anw, count );
 
-    err = native_window_set_buffer_count( anw, count );
+    err = native_window_set_buffer_count( priv->anw, count );
     CHECK_ERR();
 
     return 0;
 }
 
-int ANativeWindowPriv_setCrop( void *window, int ofs_x, int ofs_y, int w, int h )
+int ANativeWindowPriv_setCrop( native_window_priv *priv, int ofs_x, int ofs_y, int w, int h )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     android_native_rect_t crop;
 
-    CHECK_ANW();
-
     crop.left = ofs_x;
     crop.top = ofs_y;
     crop.right = ofs_x + w;
     crop.bottom = ofs_y + h;
-    return native_window_set_crop( anw, &crop );
+    return native_window_set_crop( priv->anw, &crop );
 }
 
-int ANativeWindowPriv_dequeue( void *window, void **pp_handle )
+int ANativeWindowPriv_dequeue( native_window_priv *priv, void **pp_handle )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     ANativeWindowBuffer_t *anb;
     status_t err = NO_ERROR;
 
-    CHECK_ANW();
-
 #if ANDROID_API >= 18
-    err = anw->dequeueBuffer_DEPRECATED( anw, &anb );
+    err = priv->anw->dequeueBuffer_DEPRECATED( priv->anw, &anb );
 #else
-    err = anw->dequeueBuffer( anw, &anb );
+    err = priv->anw->dequeueBuffer( priv->anw, &anb );
 #endif
     CHECK_ERR();
 
@@ -205,71 +203,62 @@ int ANativeWindowPriv_dequeue( void *window, void **pp_handle )
     return 0;
 }
 
-int ANativeWindowPriv_lock( void *window, void *p_handle )
+int ANativeWindowPriv_lock( native_window_priv *priv, void *p_handle )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
     status_t err = NO_ERROR;
 
-    CHECK_ANW();
     CHECK_ANB();
 
 #if ANDROID_API >= 18
-    err = anw->lockBuffer_DEPRECATED( anw, anb );
+    err = priv->anw->lockBuffer_DEPRECATED( priv->anw, anb );
 #else
-    err = anw->lockBuffer( anw, anb );
+    err = priv->anw->lockBuffer( priv->anw, anb );
 #endif
     CHECK_ERR();
 
     return 0;
 }
 
-int ANativeWindowPriv_queue( void *window, void *p_handle )
+int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
     status_t err = NO_ERROR;
 
-    CHECK_ANW();
     CHECK_ANB();
 
 #if ANDROID_API >= 18
-    err = anw->queueBuffer_DEPRECATED( anw, anb );
+    err = priv->anw->queueBuffer_DEPRECATED( priv->anw, anb );
 #else
-    err = anw->queueBuffer( anw, anb );
+    err = priv->anw->queueBuffer( priv->anw, anb );
 #endif
     CHECK_ERR();
 
     return 0;
 }
 
-int ANativeWindowPriv_cancel( void *window, void *p_handle )
+int ANativeWindowPriv_cancel( native_window_priv *priv, void *p_handle )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
     status_t err = NO_ERROR;
 
-    CHECK_ANW();
     CHECK_ANB();
 
 #if ANDROID_API >= 18
-    err = anw->cancelBuffer_DEPRECATED( anw, anb );
+    err = priv->anw->cancelBuffer_DEPRECATED( priv->anw, anb );
 #else
-    err = anw->cancelBuffer( anw, anb );
+    err = priv->anw->cancelBuffer( priv->anw, anb );
 #endif
     CHECK_ERR();
 
     return 0;
 }
 
-int ANativeWindowPriv_setOrientation( void *window, int orientation )
+int ANativeWindowPriv_setOrientation( native_window_priv *priv, int orientation )
 {
-    ANativeWindow *anw = (ANativeWindow *)window;
     status_t err = NO_ERROR;
     int transform;
 
-    CHECK_ANW();
-
     switch( orientation )
     {
         case 90:
@@ -285,7 +274,7 @@ int ANativeWindowPriv_setOrientation( void *window, int orientation )
             transform = 0;
     }
 
-    err = native_window_set_buffers_transform( anw, transform );
+    err = native_window_set_buffers_transform( priv->anw, transform );
     CHECK_ERR();
 
     return 0;
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index b0df281..86215f2 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -51,17 +51,18 @@ typedef struct
 void *LoadNativeWindowAPI(native_window_api_t *native);
 void Manage(vout_display_t *);
 
-typedef int (*ptr_ANativeWindowPriv_connect) (void *);
-typedef int (*ptr_ANativeWindowPriv_disconnect) (void *);
-typedef int (*ptr_ANativeWindowPriv_setup) (void *, int, int, int, int );
-typedef int (*ptr_ANativeWindowPriv_getMinUndequeued) (void *, unsigned int *);
-typedef int (*ptr_ANativeWindowPriv_setBufferCount) (void *, unsigned int );
-typedef int (*ptr_ANativeWindowPriv_setCrop) (void *, int, int, int, int);
-typedef int (*ptr_ANativeWindowPriv_dequeue) (void *, void **);
-typedef int (*ptr_ANativeWindowPriv_lock) (void *, void *);
-typedef int (*ptr_ANativeWindowPriv_queue) (void *, void *);
-typedef int (*ptr_ANativeWindowPriv_cancel) (void *, void *);
-typedef int (*ptr_ANativeWindowPriv_setOrientation) (void *, int);
+typedef struct native_window_priv native_window_priv;
+typedef native_window_priv *(*ptr_ANativeWindowPriv_connect) (void *);
+typedef int (*ptr_ANativeWindowPriv_disconnect) (native_window_priv *);
+typedef int (*ptr_ANativeWindowPriv_setup) (native_window_priv *, int, int, int, int );
+typedef int (*ptr_ANativeWindowPriv_getMinUndequeued) (native_window_priv *, unsigned int *);
+typedef int (*ptr_ANativeWindowPriv_setBufferCount) (native_window_priv *, unsigned int );
+typedef int (*ptr_ANativeWindowPriv_setCrop) (native_window_priv *, int, int, int, int);
+typedef int (*ptr_ANativeWindowPriv_dequeue) (native_window_priv *, void **);
+typedef int (*ptr_ANativeWindowPriv_lock) (native_window_priv *, void *);
+typedef int (*ptr_ANativeWindowPriv_queue) (native_window_priv *, void *);
+typedef int (*ptr_ANativeWindowPriv_cancel) (native_window_priv *, void *);
+typedef int (*ptr_ANativeWindowPriv_setOrientation) (native_window_priv *, int);
 
 typedef struct
 {
-- 
2.1.1




More information about the vlc-devel mailing list