[vlc-devel] [PATCH 1/3] omxil: split iomx_hwbuffer.cpp
Thomas Guillem
thomas.guillem at gmail.com
Wed Oct 1 10:21:40 CEST 2014
As iomx_hwbuffer.cpp contains mainly call to private native window from
system/window.h:
- move system window calls to modules/video_output/android/nativewindowpriv.c
- move get_hal_format to iomx.cpp
---
modules/codec/omxil/iomx.cpp | 24 ++
modules/codec/omxil/iomx_hwbuffer.c | 288 ------------------------
modules/codec/omxil/omxil.c | 73 +++---
modules/codec/omxil/omxil.h | 1 +
modules/codec/omxil/omxil_core.c | 26 +--
modules/codec/omxil/omxil_core.h | 14 +-
modules/video_output/android/nativewindowpriv.c | 261 +++++++++++++++++++++
modules/video_output/android/utils.c | 19 ++
modules/video_output/android/utils.h | 28 +++
9 files changed, 373 insertions(+), 361 deletions(-)
delete mode 100644 modules/codec/omxil/iomx_hwbuffer.c
create mode 100644 modules/video_output/android/nativewindowpriv.c
diff --git a/modules/codec/omxil/iomx.cpp b/modules/codec/omxil/iomx.cpp
index c75d835..2de5df4 100644
--- a/modules/codec/omxil/iomx.cpp
+++ b/modules/codec/omxil/iomx.cpp
@@ -427,6 +427,30 @@ OMX_ERRORTYPE PREFIX(OMXAndroid_GetGraphicBufferUsage)(OMX_HANDLETYPE component,
return OMX_ErrorUndefined;
return OMX_ErrorNone;
}
+
+OMX_ERRORTYPE PREFIX(OMXAndroid_GetHalFormat)( const char *comp_name, int* hal_format )
+{
+ if( !strncmp( comp_name, "OMX.SEC.", 8 ) ) {
+ switch( *hal_format ) {
+ case OMX_COLOR_FormatYUV420SemiPlanar:
+ *hal_format = 0x105; // HAL_PIXEL_FORMAT_YCbCr_420_SP
+ break;
+ case OMX_COLOR_FormatYUV420Planar:
+ *hal_format = 0x101; // HAL_PIXEL_FORMAT_YCbCr_420_P
+ break;
+ }
+ }
+ else if( !strcmp( comp_name, "OMX.TI.720P.Decoder" ) ||
+ !strcmp( comp_name, "OMX.TI.Video.Decoder" ) )
+ *hal_format = 0x14; // HAL_PIXEL_FORMAT_YCbCr_422_I
+#if ANDROID_API <= 13 // Required on msm8660 on 3.2, not required on 4.1
+ else if( !strcmp( comp_name, "OMX.qcom.video.decoder.avc" ))
+ *hal_format = 0x108;
+#endif
+
+ return OMX_ErrorNone;
+}
+
#endif
}
diff --git a/modules/codec/omxil/iomx_hwbuffer.c b/modules/codec/omxil/iomx_hwbuffer.c
deleted file mode 100644
index 575fb8c..0000000
--- a/modules/codec/omxil/iomx_hwbuffer.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*****************************************************************************
- * iomx_hwbuffer.c: Wrapper to android native window api used for IOMX
- *****************************************************************************
- * Copyright (C) 2011 VLC authors and VideoLAN
- *
- * Authors: Thomas Guillem <guillem at archos.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
-#include <errno.h>
-#include <stdio.h>
-
-#include <OMX_Core.h>
-#include <OMX_Component.h>
-
-#if ANDROID_API <= 13
-#include <ui/android_native_buffer.h>
-#include <ui/egl/android_natives.h>
-#else
-#include <system/window.h>
-#endif
-
-#include <hardware/gralloc.h>
-
-#include <android/log.h>
-
-#define NO_ERROR 0
-typedef int32_t status_t;
-
-#if ANDROID_API <= 13
-typedef android_native_buffer_t ANativeWindowBuffer_t;
-#endif
-
-#define LOG_TAG "VLC/IOMX"
-
-#define LOGD(...) __android_log_print( ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__ )
-#define LOGE(...) __android_log_print( ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__ )
-
-#define CHECK_ERR() do {\
- if( err != NO_ERROR ) {\
- LOGE( "IOMXHWBuffer: error %d in %s line %d\n", err, __FUNCTION__, __LINE__ );\
- return err;\
- }\
-} while (0)
-
-#define CHECK_ANW() do {\
- if( anw->common.magic != ANDROID_NATIVE_WINDOW_MAGIC &&\
- anw->common.version != sizeof(ANativeWindow) ) {\
- LOGE( "IOMXHWBuffer: 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) ) {\
- LOGE( "IOMXHWBuffer: error, buffer not valid\n" );\
- return -EINVAL;\
- }\
-} while (0)
-
-int IOMXHWBuffer_Connect( void *window )
-{
- ANativeWindow *anw = (ANativeWindow *)window;
- CHECK_ANW();
-
-#if ANDROID_API >= 14
- if (native_window_api_connect( anw, NATIVE_WINDOW_API_MEDIA ) != 0) {
- LOGE( "native_window_api_connect FAIL" );
- return -EINVAL;
- }
-#endif
-}
-
-int IOMXHWBuffer_Disconnect( void *window )
-{
- ANativeWindow *anw = (ANativeWindow *)window;
-
- CHECK_ANW();
-
-#if ANDROID_API >= 14
- native_window_api_disconnect( anw, NATIVE_WINDOW_API_MEDIA );
-#endif
-
- return 0;
-}
-
-
-int IOMXHWBuffer_GetHalFormat( const char *comp_name, int* hal_format )
-{
- if( !strncmp( comp_name, "OMX.SEC.", 8 ) ) {
- switch( *hal_format ) {
- case OMX_COLOR_FormatYUV420SemiPlanar:
- *hal_format = 0x105; // HAL_PIXEL_FORMAT_YCbCr_420_SP
- break;
- case OMX_COLOR_FormatYUV420Planar:
- *hal_format = 0x101; // HAL_PIXEL_FORMAT_YCbCr_420_P
- break;
- }
- }
- else if( !strcmp( comp_name, "OMX.TI.720P.Decoder" ) ||
- !strcmp( comp_name, "OMX.TI.Video.Decoder" ) )
- *hal_format = 0x14; // HAL_PIXEL_FORMAT_YCbCr_422_I
-#if ANDROID_API <= 13 // Required on msm8660 on 3.2, not required on 4.1
- else if( !strcmp( comp_name, "OMX.qcom.video.decoder.avc" ))
- *hal_format = 0x108;
-#endif
-
- return 0;
-}
-
-int IOMXHWBuffer_Setup( void *window, int w, int h, int hal_format, int hw_usage )
-{
- ANativeWindow *anw = (ANativeWindow *)window;
- int usage = 0;
- status_t err;
-
- CHECK_ANW();
-
- LOGD( "IOMXHWBuffer_setup: %p, %d, %d, %X, %X\n",
- 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 );
- CHECK_ERR();
-
-#if ANDROID_API <= 13
- err = native_window_set_buffers_geometry( anw, w, h, hal_format );
- CHECK_ERR();
-#else
- err = native_window_set_scaling_mode( anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW );
- CHECK_ERR();
-
- err = native_window_set_buffers_dimensions( anw, w, h );
- CHECK_ERR();
-
- err = native_window_set_buffers_format( anw, hal_format );
- CHECK_ERR();
-#endif
-
- return 0;
-}
-
-int IOMXHWBuffer_GetMinUndequeued( void *window, 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 );
- CHECK_ERR();
-#endif
- /* set a minimum value of min_undequeued in case query fails */
- if( *min_undequeued == 0 )
- *min_undequeued = 2;
-
- LOGD( "IOMXHWBuffer_GetMinUndequeued: %p %u", anw, *min_undequeued );
-
- return 0;
-}
-
-int IOMXHWBuffer_SetBufferCount(void *window, unsigned int count )
-{
- ANativeWindow *anw = (ANativeWindow *)window;
- status_t err;
-
- CHECK_ANW();
-
- LOGD( "IOMXHWBuffer_SetBufferCount: %p %u", anw, count );
-
- err = native_window_set_buffer_count( anw, count );
- CHECK_ERR();
-
- return 0;
-}
-
-int IOMXHWBuffer_Setcrop( void *window, 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 );
-}
-
-int IOMXHWBuffer_Dequeue( void *window, 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 );
-#else
- err = anw->dequeueBuffer( anw, &anb );
-#endif
- CHECK_ERR();
-
- *pp_handle = anb;
-
- return 0;
-}
-
-int IOMXHWBuffer_Lock( void *window, 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 );
-#else
- err = anw->lockBuffer( anw, anb );
-#endif
- CHECK_ERR();
-
- return 0;
-}
-
-int IOMXHWBuffer_Queue( void *window, 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 );
-#else
- err = anw->queueBuffer( anw, anb );
-#endif
- CHECK_ERR();
-
- return 0;
-}
-
-int IOMXHWBuffer_Cancel( void *window, 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 );
-#else
- err = anw->cancelBuffer( anw, anb );
-#endif
- CHECK_ERR();
-
- return 0;
-}
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 376aa44..e763f78 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -2050,12 +2050,7 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
msg_Dbg( p_dec, "HwBuffer_Init");
if( !(pf_enable_graphic_buffers && pf_get_graphic_buffer_usage &&
- pf_omx_hwbuffer_connect && pf_omx_hwbuffer_disconnect &&
- pf_omx_hwbuffer_setup && pf_omx_hwbuffer_get_min_undequeued &&
- pf_omx_hwbuffer_set_buffer_count && pf_omx_hwbuffer_setcrop &&
- pf_omx_hwbuffer_dequeue && pf_omx_hwbuffer_lock &&
- pf_omx_hwbuffer_queue && pf_omx_hwbuffer_cancel &&
- pf_omx_hwbuffer_get_hal_format &&
+ pf_get_hal_format &&
((OMX_COMPONENTTYPE*)p_port->omx_handle)->UseBuffer) )
{
msg_Warn( p_dec, "direct output port enabled but can't find "
@@ -2075,6 +2070,11 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
msg_Warn( p_dec, "LoadNativeWindowAPI failed" );
goto error;
}
+ if( LoadNativeWindowPrivAPI( &p_port->p_hwbuf->anwpriv ) != 0 )
+ {
+ msg_Warn( p_dec, "LoadNativeWindowPrivAPI failed" );
+ goto error;
+ }
surf = jni_LockAndGetAndroidJavaSurface();
if( !surf ) {
@@ -2092,7 +2092,7 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
msg_Warn( p_dec, "winFromSurface failed" );
goto error;
}
- pf_omx_hwbuffer_connect( p_port->p_hwbuf->window );
+ p_port->p_hwbuf->anwpriv.connect( p_port->p_hwbuf->window );
omx_error = pf_enable_graphic_buffers( p_port->omx_handle,
p_port->i_port_index, OMX_TRUE );
@@ -2127,7 +2127,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 );
- pf_omx_hwbuffer_disconnect( p_port->p_hwbuf->window );
+ p_port->p_hwbuf->anwpriv.disconnect( p_port->p_hwbuf->window );
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 );
@@ -2158,10 +2158,10 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
if( !p_port->p_hwbuf )
return 0;
- omx_error = pf_omx_hwbuffer_get_hal_format( p_sys->psz_component, &colorFormat );
+ omx_error = pf_get_hal_format( p_sys->psz_component, &colorFormat );
if( omx_error != OMX_ErrorNone )
{
- msg_Warn( p_dec, "pf_omx_hwbuffer_get_hal_format failed (Not fatal)" );
+ msg_Warn( p_dec, "pf_get_hal_format failed (Not fatal)" );
}
omx_error = pf_get_graphic_buffer_usage( p_port->omx_handle,
@@ -2173,18 +2173,18 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
i_hw_usage = 0;
}
- if( pf_omx_hwbuffer_setup( p_port->p_hwbuf->window,
- def->format.video.nFrameWidth,
- def->format.video.nFrameHeight,
- colorFormat,
- (int) i_hw_usage ) != 0 )
+ if( p_port->p_hwbuf->anwpriv.setup( p_port->p_hwbuf->window,
+ def->format.video.nFrameWidth,
+ def->format.video.nFrameHeight,
+ colorFormat,
+ (int) i_hw_usage ) != 0 )
{
msg_Err( p_dec, "can't setup OMXHWBuffer" );
goto error;
}
- if( pf_omx_hwbuffer_get_min_undequeued( p_port->p_hwbuf->window,
- &min_undequeued ) != 0 )
+ if( p_port->p_hwbuf->anwpriv.getMinUndequeued( p_port->p_hwbuf->window,
+ &min_undequeued ) != 0 )
{
msg_Err( p_dec, "can't get min_undequeued" );
goto error;
@@ -2205,8 +2205,8 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
omx_error, ErrorToString(omx_error) );
}
- if( pf_omx_hwbuffer_set_buffer_count( p_port->p_hwbuf->window,
- def->nBufferCountActual ) != 0 )
+ if( p_port->p_hwbuf->anwpriv.setBufferCount( p_port->p_hwbuf->window,
+ def->nBufferCountActual ) != 0 )
{
msg_Err( p_dec, "can't set buffer_count" );
goto error;
@@ -2240,7 +2240,8 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
{
void *p_handle = NULL;
- if( pf_omx_hwbuffer_dequeue( p_port->p_hwbuf->window, &p_handle ) != 0 )
+ if( p_port->p_hwbuf->anwpriv.dequeue( p_port->p_hwbuf->window,
+ &p_handle ) != 0 )
{
msg_Err( p_dec, "OMXHWBuffer_dequeue Fail" );
goto error;
@@ -2252,8 +2253,8 @@ 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 );
- pf_omx_hwbuffer_cancel( p_port->p_hwbuf->window,
- p_port->p_hwbuf->pp_handles[i] );
+ p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window,
+ p_port->p_hwbuf->pp_handles[i] );
}
return 0;
@@ -2283,7 +2284,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 )
{
- pf_omx_hwbuffer_cancel( p_port->p_hwbuf->window, p_handle );
+ p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, p_handle );
HwBuffer_ChangeState( p_dec, p_port, i, BUF_STATE_NOT_OWNED );
}
}
@@ -2323,8 +2324,8 @@ 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( pf_omx_hwbuffer_lock( p_port->p_hwbuf->window,
- p_header->pBuffer ) != 0 )
+ if( p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window,
+ p_header->pBuffer ) != 0 )
{
msg_Err( p_dec, "lock failed" );
HWBUFFER_UNLOCK();
@@ -2351,7 +2352,7 @@ static int HwBuffer_Start( decoder_t *p_dec, OmxPort *p_port )
/*****************************************************************************
* HwBuffer_Stop: stop DequeueThread and invalidate all pictures that are sent
- * to vlc core. The thread can be stuck in pf_omx_hwbuffer_dequeue, so don't
+ * to vlc core. The thread can be stuck in dequeue, so don't
* join it now since it can be unblocked later by HwBuffer_FreeBuffers.
*****************************************************************************/
static int HwBuffer_Stop( decoder_t *p_dec, OmxPort *p_port )
@@ -2373,7 +2374,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 )
{
- pf_omx_hwbuffer_cancel( p_port->p_hwbuf->window, p_handle );
+ p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, p_handle );
HwBuffer_ChangeState( p_dec, p_port, p_picsys->i_index,
BUF_STATE_NOT_OWNED );
}
@@ -2468,9 +2469,9 @@ static void HwBuffer_SetCrop( decoder_t *p_dec, OmxPort *p_port,
{
VLC_UNUSED( p_dec );
- pf_omx_hwbuffer_setcrop( p_port->p_hwbuf->window,
- p_rect->nLeft, p_rect->nTop,
- p_rect->nWidth, p_rect->nHeight );
+ p_port->p_hwbuf->anwpriv.setCrop( p_port->p_hwbuf->window,
+ p_rect->nLeft, p_rect->nTop,
+ p_rect->nWidth, p_rect->nHeight );
}
/*****************************************************************************
@@ -2503,9 +2504,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 = pf_omx_hwbuffer_dequeue( p_port->p_hwbuf->window, &p_handle );
+ err = p_port->p_hwbuf->anwpriv.dequeue( p_port->p_hwbuf->window, &p_handle );
if( err == 0 )
- err = pf_omx_hwbuffer_lock( p_port->p_hwbuf->window, p_handle );
+ err = p_port->p_hwbuf->anwpriv.lock( p_port->p_hwbuf->window, p_handle );
HWBUFFER_LOCK();
@@ -2517,7 +2518,7 @@ static void *DequeueThread( void *data )
if( !p_port->p_hwbuf->b_run )
{
- pf_omx_hwbuffer_cancel( p_port->p_hwbuf->window, p_handle );
+ p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, p_handle );
continue;
}
@@ -2532,7 +2533,7 @@ static void *DequeueThread( void *data )
}
if( i_index == -1 )
{
- msg_Err( p_dec, "pf_omx_hwbuffer_dequeue returned unknown handle" );
+ msg_Err( p_dec, "p_port->p_hwbuf->anwpriv.dequeue returned unknown handle" );
continue;
}
@@ -2581,9 +2582,9 @@ static void DisplayBuffer( picture_sys_t* p_picsys, bool b_render )
}
if( b_render )
- pf_omx_hwbuffer_queue( p_port->p_hwbuf->window, p_handle );
+ p_port->p_hwbuf->anwpriv.queue( p_port->p_hwbuf->window, p_handle );
else
- pf_omx_hwbuffer_cancel( p_port->p_hwbuf->window, p_handle );
+ p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window, 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 3e2ba70..6dc7d17 100644
--- a/modules/codec/omxil/omxil.h
+++ b/modules/codec/omxil/omxil.h
@@ -78,6 +78,7 @@ typedef struct HwBuffer
void *window;
#if defined(USE_IOMX)
native_window_api_t native_window;
+ native_window_priv_api_t anwpriv;
#endif
} HwBuffer;
diff --git a/modules/codec/omxil/omxil_core.c b/modules/codec/omxil/omxil_core.c
index c196ec2..d50f680 100644
--- a/modules/codec/omxil/omxil_core.c
+++ b/modules/codec/omxil/omxil_core.c
@@ -89,18 +89,7 @@ OMX_ERRORTYPE (*pf_component_enum)(OMX_STRING, OMX_U32, OMX_U32);
OMX_ERRORTYPE (*pf_get_roles_of_component)(OMX_STRING, OMX_U32 *, OMX_U8 **);
OMX_ERRORTYPE (*pf_enable_graphic_buffers)(OMX_HANDLETYPE, OMX_U32, OMX_BOOL);
OMX_ERRORTYPE (*pf_get_graphic_buffer_usage)(OMX_HANDLETYPE, OMX_U32, OMX_U32*);
-
-int (*pf_omx_hwbuffer_connect) (void *);
-int (*pf_omx_hwbuffer_disconnect) (void *);
-int (*pf_omx_hwbuffer_get_hal_format) (const char *, int *);
-int (*pf_omx_hwbuffer_setup) (void *, int, int, int, int );
-int (*pf_omx_hwbuffer_get_min_undequeued) (void *, unsigned int *);
-int (*pf_omx_hwbuffer_set_buffer_count) (void *, unsigned int );
-int (*pf_omx_hwbuffer_setcrop) (void *, int, int, int, int);
-int (*pf_omx_hwbuffer_dequeue) (void *, void **);
-int (*pf_omx_hwbuffer_lock) (void *, void *);
-int (*pf_omx_hwbuffer_queue) (void *, void *);
-int (*pf_omx_hwbuffer_cancel) (void *, void *);
+OMX_ERRORTYPE (*pf_get_hal_format) (const char *, int *);
#ifdef RPI_OMX
static void *extra_dll_handle;
@@ -177,18 +166,7 @@ int InitOmxCore(vlc_object_t *p_this)
#if defined(USE_IOMX)
pf_enable_graphic_buffers = dlsym( dll_handle, "OMXAndroid_EnableGraphicBuffers" );
pf_get_graphic_buffer_usage = dlsym( dll_handle, "OMXAndroid_GetGraphicBufferUsage" );
-
- pf_omx_hwbuffer_connect = dlsym( dll_handle, "OMXHWBuffer_Connect" );
- pf_omx_hwbuffer_disconnect = dlsym( dll_handle, "OMXHWBuffer_Disconnect" );
- pf_omx_hwbuffer_get_hal_format = dlsym( dll_handle, "OMXHWBuffer_GetHalFormat" );
- pf_omx_hwbuffer_setup = dlsym( dll_handle, "OMXHWBuffer_Setup" );
- pf_omx_hwbuffer_get_min_undequeued = dlsym( dll_handle, "OMXHWBuffer_GetMinUndequeued" );
- pf_omx_hwbuffer_set_buffer_count = dlsym( dll_handle, "OMXHWBuffer_SetBufferCount" );
- pf_omx_hwbuffer_setcrop = dlsym( dll_handle, "OMXHWBuffer_Setcrop" );
- pf_omx_hwbuffer_dequeue = dlsym( dll_handle, "OMXHWBuffer_Dequeue" );
- pf_omx_hwbuffer_lock = dlsym( dll_handle, "OMXHWBuffer_Lock" );
- pf_omx_hwbuffer_queue = dlsym( dll_handle, "OMXHWBuffer_Queue" );
- pf_omx_hwbuffer_cancel = dlsym( dll_handle, "OMXHWBuffer_Cancel" );
+ pf_get_hal_format = dlsym( dll_handle, "OMXAndroid_GetHalFormat" );
#endif
/* Initialise the OMX core */
diff --git a/modules/codec/omxil/omxil_core.h b/modules/codec/omxil/omxil_core.h
index 92d8caa..30ffdcf 100644
--- a/modules/codec/omxil/omxil_core.h
+++ b/modules/codec/omxil/omxil_core.h
@@ -36,19 +36,7 @@ OMX_ERRORTYPE (*pf_get_roles_of_component)(OMX_STRING, OMX_U32 *, OMX_U8 **);
/* Extra IOMX android functions. Can be NULL if we don't link with libiomx */
OMX_ERRORTYPE (*pf_enable_graphic_buffers)(OMX_HANDLETYPE, OMX_U32, OMX_BOOL);
OMX_ERRORTYPE (*pf_get_graphic_buffer_usage)(OMX_HANDLETYPE, OMX_U32, OMX_U32*);
-
-/* OMXHWBuffer functions */
-int (*pf_omx_hwbuffer_connect) (void *);
-int (*pf_omx_hwbuffer_disconnect) (void *);
-int (*pf_omx_hwbuffer_get_hal_format) (const char *, int *);
-int (*pf_omx_hwbuffer_setup) (void *, int, int, int, int );
-int (*pf_omx_hwbuffer_get_min_undequeued) (void *, unsigned int *);
-int (*pf_omx_hwbuffer_set_buffer_count) (void *, unsigned int );
-int (*pf_omx_hwbuffer_setcrop) (void *, int, int, int, int);
-int (*pf_omx_hwbuffer_dequeue) (void *, void **);
-int (*pf_omx_hwbuffer_lock) (void *, void *);
-int (*pf_omx_hwbuffer_queue) (void *, void *);
-int (*pf_omx_hwbuffer_cancel) (void *, void *);
+OMX_ERRORTYPE (*pf_get_hal_format) (const char *, int *);
int InitOmxCore(vlc_object_t *p_this);
void DeinitOmxCore(void);
diff --git a/modules/video_output/android/nativewindowpriv.c b/modules/video_output/android/nativewindowpriv.c
new file mode 100644
index 0000000..3fb9356
--- /dev/null
+++ b/modules/video_output/android/nativewindowpriv.c
@@ -0,0 +1,261 @@
+/*****************************************************************************
+ * nativewindowpriv.c: Wrapper to android native window private api
+ *****************************************************************************
+ * Copyright (C) 2011 VLC authors and VideoLAN
+ *
+ * Authors: Thomas Guillem <guillem at archos.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#include <errno.h>
+#include <stdio.h>
+
+#if ANDROID_API <= 13
+#include <ui/android_native_buffer.h>
+#include <ui/egl/android_natives.h>
+#else
+#include <system/window.h>
+#endif
+
+#include <hardware/gralloc.h>
+
+#include <android/log.h>
+
+#define NO_ERROR 0
+typedef int32_t status_t;
+
+#if ANDROID_API <= 13
+typedef android_native_buffer_t ANativeWindowBuffer_t;
+#endif
+
+#define LOG_TAG "VLC/ANW"
+
+#define LOGD(...) __android_log_print( ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__ )
+#define LOGE(...) __android_log_print( ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__ )
+
+#define CHECK_ERR() do {\
+ if( err != NO_ERROR ) {\
+ LOGE( "error %d in %s line %d\n", err, __FUNCTION__, __LINE__ );\
+ return err;\
+ }\
+} 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) ) {\
+ LOGE( "error, buffer not valid\n" );\
+ return -EINVAL;\
+ }\
+} while (0)
+
+int ANativeWindowPriv_connect( void *window )
+{
+ ANativeWindow *anw = (ANativeWindow *)window;
+ CHECK_ANW();
+
+#if ANDROID_API >= 14
+ if (native_window_api_connect( anw, NATIVE_WINDOW_API_MEDIA ) != 0) {
+ LOGE( "native_window_api_connect FAIL" );
+ return -EINVAL;
+ }
+#endif
+}
+
+int ANativeWindowPriv_disconnect( void *window )
+{
+ ANativeWindow *anw = (ANativeWindow *)window;
+
+ CHECK_ANW();
+
+#if ANDROID_API >= 14
+ native_window_api_disconnect( anw, NATIVE_WINDOW_API_MEDIA );
+#endif
+
+ return 0;
+}
+
+int ANativeWindowPriv_setup( void *window, 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 );
+
+ 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 );
+ CHECK_ERR();
+
+#if ANDROID_API <= 13
+ err = native_window_set_buffers_geometry( anw, w, h, hal_format );
+ CHECK_ERR();
+#else
+ err = native_window_set_scaling_mode( anw, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW );
+ CHECK_ERR();
+
+ err = native_window_set_buffers_dimensions( anw, w, h );
+ CHECK_ERR();
+
+ err = native_window_set_buffers_format( anw, hal_format );
+ CHECK_ERR();
+#endif
+
+ return 0;
+}
+
+int ANativeWindowPriv_getMinUndequeued( void *window, 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 );
+ 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 );
+
+ return 0;
+}
+
+int ANativeWindowPriv_setBufferCount(void *window, unsigned int count )
+{
+ ANativeWindow *anw = (ANativeWindow *)window;
+ status_t err;
+
+ CHECK_ANW();
+
+ LOGD( "setBufferCount: %p %u", anw, count );
+
+ err = native_window_set_buffer_count( anw, count );
+ CHECK_ERR();
+
+ return 0;
+}
+
+int ANativeWindowPriv_setCrop( void *window, 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 );
+}
+
+int ANativeWindowPriv_dequeue( void *window, 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 );
+#else
+ err = anw->dequeueBuffer( anw, &anb );
+#endif
+ CHECK_ERR();
+
+ *pp_handle = anb;
+
+ return 0;
+}
+
+int ANativeWindowPriv_lock( void *window, 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 );
+#else
+ err = anw->lockBuffer( anw, anb );
+#endif
+ CHECK_ERR();
+
+ return 0;
+}
+
+int ANativeWindowPriv_queue( void *window, 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 );
+#else
+ err = anw->queueBuffer( anw, anb );
+#endif
+ CHECK_ERR();
+
+ return 0;
+}
+
+int ANativeWindowPriv_cancel( void *window, 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 );
+#else
+ err = anw->cancelBuffer( anw, anb );
+#endif
+ CHECK_ERR();
+
+ return 0;
+}
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 21a62b7..a2239db 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -49,6 +49,25 @@ void *LoadNativeWindowAPI(native_window_api_t *native)
return NULL;
}
+int LoadNativeWindowPrivAPI(native_window_priv_api_t *native)
+{
+ native->connect = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_connect");
+ native->disconnect = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_disconnect");
+ native->setup = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_setup");
+ native->getMinUndequeued = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_getMinUndequeued");
+ native->setBufferCount = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_setBufferCount");
+ native->setCrop = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_setCrop");
+ native->dequeue = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_dequeue");
+ native->lock = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_lock");
+ native->queue = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_queue");
+ native->cancel = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_cancel");
+
+ return native->connect && native->disconnect && native->setup &&
+ native->getMinUndequeued && native->setBufferCount && native->setCrop &&
+ native->dequeue && native->lock && native->queue && native->cancel
+ ? 0 : -1;
+}
+
extern void jni_getMouseCoordinates(int *, int *, int *, int *);
void Manage(vout_display_t *vd)
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 9a72df6..2500c53 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -48,3 +48,31 @@ typedef struct
that should be destroyed with dlclose. */
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 struct
+{
+ ptr_ANativeWindowPriv_connect connect;
+ ptr_ANativeWindowPriv_disconnect disconnect;
+ ptr_ANativeWindowPriv_setup setup;
+ ptr_ANativeWindowPriv_getMinUndequeued getMinUndequeued;
+ ptr_ANativeWindowPriv_setBufferCount setBufferCount;
+ ptr_ANativeWindowPriv_setCrop setCrop;
+ ptr_ANativeWindowPriv_dequeue dequeue;
+ ptr_ANativeWindowPriv_lock lock;
+ ptr_ANativeWindowPriv_queue queue;
+ ptr_ANativeWindowPriv_cancel cancel;
+} native_window_priv_api_t;
+
+/* Fill the structure passed as parameter and return 0 if all symbols are
+ found. Don't need to call dlclose, the lib is already loaded. */
+int LoadNativeWindowPrivAPI(native_window_priv_api_t *native);
--
2.1.0
More information about the vlc-devel
mailing list