[vlc-devel] [PATCH] nativewindowpriv: use fence_fd
Thomas Guillem
thomas at gllm.fr
Wed Nov 19 16:02:35 CET 2014
And don't call deprecated functions after android 4.3.
---
modules/codec/omxil/omxil.c | 20 +++----
modules/video_output/android/android_window.c | 14 +++--
modules/video_output/android/android_window.h | 1 +
modules/video_output/android/nativewindowpriv.c | 72 +++++++++++++++++++------
modules/video_output/android/utils.h | 8 +--
5 files changed, 82 insertions(+), 33 deletions(-)
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 95abfb2..936049d 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -2277,7 +2277,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,
- &p_handle ) != 0 )
+ &p_handle, NULL ) != 0 )
{
msg_Err( p_dec, "OMXHWBuffer_dequeue Fail" );
goto error;
@@ -2290,7 +2290,7 @@ static int HwBuffer_AllocateBuffers( decoder_t *p_dec, OmxPort *p_port )
{
OMX_DBG( "canceling buffer(%d)", i );
p_port->p_hwbuf->anwpriv.cancel( p_port->p_hwbuf->window_priv,
- p_port->p_hwbuf->pp_handles[i] );
+ p_port->p_hwbuf->pp_handles[i], -1 );
}
return 0;
@@ -2320,7 +2320,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, -1 );
HwBuffer_ChangeState( p_dec, p_port, i, BUF_STATE_NOT_OWNED );
}
}
@@ -2361,7 +2361,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,
- p_header->pBuffer ) != 0 )
+ p_header->pBuffer, -1 ) != 0 )
{
msg_Err( p_dec, "lock failed" );
HWBUFFER_UNLOCK();
@@ -2410,7 +2410,7 @@ static int HwBuffer_Stop( decoder_t *p_dec, OmxPort *p_port )
void *p_handle = p_port->pp_buffers[p_picsys->priv.hw.i_index]->pBuffer;
if( p_handle )
{
- 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, -1 );
HwBuffer_ChangeState( p_dec, p_port, p_picsys->priv.hw.i_index,
BUF_STATE_NOT_OWNED );
}
@@ -2540,9 +2540,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, NULL );
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, -1 );
HWBUFFER_LOCK();
@@ -2554,7 +2554,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, -1 );
continue;
}
@@ -2619,9 +2619,9 @@ static void UnlockPicture( picture_t* p_pic )
}
if( p_picsys->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, -1 );
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, -1 );
HwBuffer_ChangeState( p_dec, p_port, p_picsys->priv.hw.i_index, BUF_STATE_NOT_OWNED );
HWBUFFER_BROADCAST( p_port );
diff --git a/modules/video_output/android/android_window.c b/modules/video_output/android/android_window.c
index d2ac522..101271b 100644
--- a/modules/video_output/android/android_window.c
+++ b/modules/video_output/android/android_window.c
@@ -472,6 +472,7 @@ static void AndroidWindow_UnlockPicture(vout_display_sys_t *sys,
if (p_window->b_use_priv) {
int err = 0;
void *p_handle = p_picsys->priv.sw.p_handle;
+ int i_fence_fd = p_picsys->priv.sw.i_fence_fd;
if (p_handle == NULL)
return;
@@ -480,9 +481,11 @@ static void AndroidWindow_UnlockPicture(vout_display_sys_t *sys,
if (err == 0) {
if (p_picsys->b_render)
- err = sys->anwp.queue(p_window->p_handle_priv, p_handle);
+ err = sys->anwp.queue(p_window->p_handle_priv, p_handle,
+ i_fence_fd);
else
- err = sys->anwp.cancel(p_window->p_handle_priv, p_handle);
+ err = sys->anwp.cancel(p_window->p_handle_priv, p_handle,
+ i_fence_fd);
}
} else
sys->anw.unlockAndPost(p_window->p_handle);
@@ -496,16 +499,19 @@ static int AndroidWindow_LockPicture(vout_display_sys_t *sys,
if (p_window->b_use_priv) {
void *p_handle;
+ int i_fence_fd = -1;
int err;
- err = sys->anwp.dequeue(p_window->p_handle_priv, &p_handle);
- err = err == 0 ? sys->anwp.lock(p_window->p_handle_priv, p_handle) : err;
+ err = sys->anwp.dequeue(p_window->p_handle_priv, &p_handle, &i_fence_fd);
+ err = err == 0 ? sys->anwp.lock(p_window->p_handle_priv,
+ p_handle, i_fence_fd) : err;
err = err == 0 ? sys->anwp.lockData(p_window->p_handle_priv,
p_handle,
&p_picsys->priv.sw.buf) : err;
if (err != 0)
return -1;
p_picsys->priv.sw.p_handle = p_handle;
+ p_picsys->priv.sw.i_fence_fd = i_fence_fd;
} else {
if (sys->anw.winLock(p_window->p_handle,
&p_picsys->priv.sw.buf, NULL) != 0)
diff --git a/modules/video_output/android/android_window.h b/modules/video_output/android/android_window.h
index 68101c8..f4d1d90 100644
--- a/modules/video_output/android/android_window.h
+++ b/modules/video_output/android/android_window.h
@@ -50,6 +50,7 @@ struct picture_sys_t
} hw;
struct {
void *p_handle;
+ int i_fence_fd;
ANativeWindow_Buffer buf;
} sw;
} priv;
diff --git a/modules/video_output/android/nativewindowpriv.c b/modules/video_output/android/nativewindowpriv.c
index bcf5c03..712d198 100644
--- a/modules/video_output/android/nativewindowpriv.c
+++ b/modules/video_output/android/nativewindowpriv.c
@@ -24,17 +24,23 @@
* Preamble
*****************************************************************************/
+#define ANDROID_HC_OR_LATER (ANDROID_API >= 11)
+#define ANDROID_ICS_OR_LATER (ANDROID_API >= 14)
+#define ANDROID_JBMR2_OR_LATER (ANDROID_API >= 18)
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
+#if ANDROID_JBMR2_OR_LATER
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
#include <android/native_window.h>
-#define ANDROID_HC_OR_LATER (ANDROID_API >= 11)
-#define ANDROID_ICS_OR_LATER (ANDROID_API >= 14)
-#define ANDROID_JBMR2_OR_LATER (ANDROID_API >= 18)
-
#if ANDROID_ICS_OR_LATER
#include <system/window.h>
#else
@@ -65,6 +71,7 @@ struct native_window_priv
#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 LOGW(...) __android_log_print( ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__ )
#define CHECK_ERR() do {\
if( err != NO_ERROR ) {\
@@ -221,15 +228,49 @@ int ANativeWindowPriv_setCrop( native_window_priv *priv, int ofs_x, int ofs_y, i
return native_window_set_crop( priv->anw, &crop );
}
-int ANativeWindowPriv_dequeue( native_window_priv *priv, void **pp_handle )
+int ANativeWindowPriv_dequeue( native_window_priv *priv, void **pp_handle,
+ int *p_fence_fd )
{
ANativeWindowBuffer_t *anb;
status_t err = NO_ERROR;
#if ANDROID_JBMR2_OR_LATER
- err = priv->anw->dequeueBuffer_DEPRECATED( priv->anw, &anb );
+ int i_fence_fd = -1;
+ err = priv->anw->dequeueBuffer( priv->anw, &anb, &i_fence_fd );
+ if( p_fence_fd )
+ {
+ *p_fence_fd = i_fence_fd;
+ }
+ else if( i_fence_fd != -1 )
+ {
+ fd_set rfds;
+ struct timeval tv;
+ int ret;
+
+ LOGW("dequeue: fence_fd != -1 and not handled");
+
+ FD_ZERO(&rfds);
+ FD_SET(i_fence_fd, &rfds);
+
+ /* Wait up to 5 seconds. */
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+
+ ret = select(i_fence_fd + 1, &rfds, NULL, NULL, &tv);
+ if (ret == -1) {
+ priv->anw->cancelBuffer( priv->anw, anb, i_fence_fd );
+ LOGE("dequeue: select error on fence_fd");
+ return -1;
+ } else if (ret == 0) {
+ LOGW("dequeue: fence_fd timed out");
+ }
+
+ close(i_fence_fd);
+ }
#else
err = priv->anw->dequeueBuffer( priv->anw, &anb );
+ if (p_fence_fd)
+ *p_fence_fd = -1;
#endif
CHECK_ERR();
@@ -238,20 +279,19 @@ int ANativeWindowPriv_dequeue( native_window_priv *priv, void **pp_handle )
return 0;
}
-int ANativeWindowPriv_lock( native_window_priv *priv, void *p_handle )
+int ANativeWindowPriv_lock( native_window_priv *priv, void *p_handle,
+ int i_fence_fd )
{
+#if !ANDROID_JBMR2_OR_LATER
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
status_t err = NO_ERROR;
CHECK_ANB();
-#if ANDROID_JBMR2_OR_LATER
- err = priv->anw->lockBuffer_DEPRECATED( priv->anw, anb );
-#else
err = priv->anw->lockBuffer( priv->anw, anb );
-#endif
CHECK_ERR();
+#endif
return 0;
}
@@ -291,7 +331,8 @@ int ANativeWindowPriv_unlockData( native_window_priv *priv, void *p_handle )
return 0;
}
-int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle )
+int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle,
+ int i_fence_fd )
{
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
status_t err = NO_ERROR;
@@ -299,7 +340,7 @@ int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle )
CHECK_ANB();
#if ANDROID_JBMR2_OR_LATER
- err = priv->anw->queueBuffer_DEPRECATED( priv->anw, anb );
+ err = priv->anw->queueBuffer( priv->anw, anb, i_fence_fd );
#else
err = priv->anw->queueBuffer( priv->anw, anb );
#endif
@@ -308,7 +349,8 @@ int ANativeWindowPriv_queue( native_window_priv *priv, void *p_handle )
return 0;
}
-int ANativeWindowPriv_cancel( native_window_priv *priv, void *p_handle )
+int ANativeWindowPriv_cancel( native_window_priv *priv, void *p_handle,
+ int i_fence_fd )
{
ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
status_t err = NO_ERROR;
@@ -316,7 +358,7 @@ int ANativeWindowPriv_cancel( native_window_priv *priv, void *p_handle )
CHECK_ANB();
#if ANDROID_JBMR2_OR_LATER
- err = priv->anw->cancelBuffer_DEPRECATED( priv->anw, anb );
+ err = priv->anw->cancelBuffer( priv->anw, anb, i_fence_fd );
#else
err = priv->anw->cancelBuffer( priv->anw, anb );
#endif
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 97b74bf..148cc48 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -78,12 +78,12 @@ typedef int (*ptr_ANativeWindowPriv_getMinUndequeued) (native_window_priv *, uns
typedef int (*ptr_ANativeWindowPriv_getMaxBufferCount) (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_dequeue) (native_window_priv *, void **, int *);
+typedef int (*ptr_ANativeWindowPriv_lock) (native_window_priv *, void *, int);
typedef int (*ptr_ANativeWindowPriv_lockData) (native_window_priv *, void *, ANativeWindow_Buffer *);
typedef int (*ptr_ANativeWindowPriv_unlockData) (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_queue) (native_window_priv *, void *, int);
+typedef int (*ptr_ANativeWindowPriv_cancel) (native_window_priv *, void *, int);
typedef int (*ptr_ANativeWindowPriv_setOrientation) (native_window_priv *, int);
typedef struct
--
2.1.1
More information about the vlc-devel
mailing list