Commit 918ed4d1 authored by Thomas Guillem's avatar Thomas Guillem

android: merge android_surface with android_window

This commits remove the android_surface module. The old android surface API is
now used by the android_window module via native_window_api_t.
parent 7d72f2c9
......@@ -3251,16 +3251,6 @@ dnl
PKG_ENABLE_MODULES_VLC([SVG], [], [librsvg-2.0 >= 2.9.0], [SVG rendering library],[auto])
PKG_ENABLE_MODULES_VLC([SVGDEC], [], [librsvg-2.0 >= 2.9.0 cairo >= 1.13.1], [SVG image decoder library],[auto])
dnl
dnl android surface module
dnl
AC_ARG_ENABLE(android-surface,
[ --enable-android-surface Android Surface video output module (default disabled)])
if test "${enable_android_surface}" = "yes"; then
VLC_ADD_PLUGIN([android_surface])
VLC_ADD_PLUGIN([android_window])
fi
dnl
dnl Windows DirectX module
dnl
......
......@@ -36,7 +36,6 @@ $Id$
* android_audiotrack: audio output for Android, based on AudioTrack
* android_logger: logger output to native Android logs (adb logcat)
* android_native_window: Android native window provider module
* android_surface: video output for Android, based on Surface
* android_window: Android direct/undirect rendering video output
* antiflicker: anti-flicker video filter
* araw: Pseudo audio decoder for raw PCM
......
......@@ -276,16 +276,9 @@ libandroid_window_plugin_la_LIBADD = $(LIBDL)
libandroid_window_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
EXTRA_LTLIBRARIES += libandroid_window_plugin.la
libandroid_surface_plugin_la_SOURCES = video_output/android/surface.c video_output/android/utils.c video_output/android/utils.h
libandroid_surface_plugin_la_CFLAGS = $(AM_CFLAGS)
libandroid_surface_plugin_la_LIBADD = $(LIBDL)
libandroid_surface_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
EXTRA_LTLIBRARIES += libandroid_surface_plugin.la
if HAVE_ANDROID
vout_LTLIBRARIES += libandroid_native_window_plugin.la
vout_LTLIBRARIES += $(LTLIBandroid_window)
vout_LTLIBRARIES += $(LTLIBandroid_surface)
if HAVE_EGL
vout_LTLIBRARIES += libegl_android_plugin.la
endif
......
......@@ -75,6 +75,7 @@ extern void jni_UnlockAndroidSurface();
extern void jni_SetSurfaceLayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
extern int jni_ConfigureSurface(jobject jsurf, int width, int height, int hal, bool *configured);
extern int jni_GetWindowSize(int *width, int *height);
extern void jni_getMouseCoordinates(int *, int *, int *, int *);
static const vlc_fourcc_t subpicture_chromas[] =
{
......@@ -85,6 +86,7 @@ static const vlc_fourcc_t subpicture_chromas[] =
static picture_pool_t *Pool (vout_display_t *, unsigned);
static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
static void Display(vout_display_t *, picture_t *, subpicture_t *);
static void Manage(vout_display_t *vd);
static int Control(vout_display_t *, int, va_list);
typedef struct android_window android_window;
......@@ -137,6 +139,25 @@ struct vout_display_sys_t
uint8_t hash[16];
};
#define PRIV_WINDOW_FORMAT_YV12 0x32315659
static inline int ChromaToAndroidHal(vlc_fourcc_t i_chroma)
{
switch (i_chroma) {
case VLC_CODEC_YV12:
case VLC_CODEC_I420:
return PRIV_WINDOW_FORMAT_YV12;
case VLC_CODEC_RGB16:
return WINDOW_FORMAT_RGB_565;
case VLC_CODEC_RGB32:
return WINDOW_FORMAT_RGBX_8888;
case VLC_CODEC_RGBA:
return WINDOW_FORMAT_RGBA_8888;
default:
return -1;
}
}
static int UpdateWindowSize(video_format_t *p_fmt, bool b_cropped)
{
unsigned int i_width, i_height;
......@@ -479,7 +500,7 @@ static int AndroidWindow_SetupANW(vout_display_sys_t *sys,
p_window->i_pic_count = 1;
p_window->i_min_undequeued = 0;
if (!b_java_configured)
if (!b_java_configured && sys->anw.setBuffersGeometry)
return sys->anw.setBuffersGeometry(p_window->p_handle,
p_window->fmt.i_width,
p_window->fmt.i_height,
......@@ -631,9 +652,10 @@ static int Open(vlc_object_t *p_this)
return VLC_ENOMEM;
sys->p_library = LoadNativeWindowAPI(&sys->anw);
if (!sys->p_library) {
msg_Err(vd, "Could not initialize NativeWindow API.");
goto error;
if (!sys->p_library)
{
msg_Warn(vd, "Using old Android Surface");
LoadNativeSurfaceAPI(&sys->anw);
}
#ifdef USE_ANWP
......@@ -1103,3 +1125,24 @@ static int Control(vout_display_t *vd, int query, va_list args)
return VLC_EGENERIC;
}
}
static void Manage(vout_display_t *vd)
{
int x, y, button, action;
jni_getMouseCoordinates(&action, &button, &x, &y);
if (x >= 0 && y >= 0)
{
switch( action )
{
case AMOTION_EVENT_ACTION_DOWN:
vout_display_SendEventMouseMoved(vd, x, y);
vout_display_SendEventMousePressed(vd, button); break;
case AMOTION_EVENT_ACTION_UP:
vout_display_SendEventMouseMoved(vd, x, y);
vout_display_SendEventMouseReleased(vd, button); break;
case AMOTION_EVENT_ACTION_MOVE:
vout_display_SendEventMouseMoved(vd, x, y); break;
}
}
}
This diff is collapsed.
......@@ -22,6 +22,151 @@
#include "utils.h"
#include <dlfcn.h>
/*
* Android Surface (pre android 2.3)
*/
extern void *jni_AndroidJavaSurfaceToNativeSurface(jobject surf);
#ifndef ANDROID_SYM_S_LOCK
# define ANDROID_SYM_S_LOCK "_ZN7android7Surface4lockEPNS0_11SurfaceInfoEb"
#endif
#ifndef ANDROID_SYM_S_LOCK2
# define ANDROID_SYM_S_LOCK2 "_ZN7android7Surface4lockEPNS0_11SurfaceInfoEPNS_6RegionE"
#endif
#ifndef ANDROID_SYM_S_UNLOCK
# define ANDROID_SYM_S_UNLOCK "_ZN7android7Surface13unlockAndPostEv"
#endif
typedef void (*AndroidSurface_lock)(void *, void *, int);
typedef void (*AndroidSurface_lock2)(void *, void *, void *);
typedef void (*AndroidSurface_unlockAndPost)(void *);
typedef struct {
void *p_dl_handle;
void *p_surface_handle;
AndroidSurface_lock pf_lock;
AndroidSurface_lock2 pf_lock2;
AndroidSurface_unlockAndPost pf_unlockAndPost;
} NativeSurface;
static inline void *
NativeSurface_Load(const char *psz_lib, NativeSurface *p_ns)
{
void *p_lib = dlopen(psz_lib, RTLD_NOW);
if (!p_lib)
return NULL;
p_ns->pf_lock = (AndroidSurface_lock)(dlsym(p_lib, ANDROID_SYM_S_LOCK));
p_ns->pf_lock2 = (AndroidSurface_lock2)(dlsym(p_lib, ANDROID_SYM_S_LOCK2));
p_ns->pf_unlockAndPost =
(AndroidSurface_unlockAndPost)(dlsym(p_lib, ANDROID_SYM_S_UNLOCK));
if ((p_ns->pf_lock || p_ns->pf_lock2) && p_ns->pf_unlockAndPost)
return p_lib;
dlclose(p_lib);
return NULL;
}
static ANativeWindow*
NativeSurface_fromSurface(JNIEnv *env, jobject jsurf)
{
(void) env;
void *p_surface_handle;
NativeSurface *p_ns;
static const char *libs[] = {
"libsurfaceflinger_client.so",
"libgui.so",
"libui.so"
};
p_surface_handle = jni_AndroidJavaSurfaceToNativeSurface(jsurf);
if (!p_surface_handle)
return NULL;
p_ns = malloc(sizeof(NativeSurface));
if (!p_ns)
return NULL;
p_ns->p_surface_handle = p_surface_handle;
for (size_t i = 0; i < sizeof(libs) / sizeof(*libs); i++)
{
void *p_dl_handle = NativeSurface_Load(libs[i], p_ns);
if (p_dl_handle)
{
p_ns->p_dl_handle = p_dl_handle;
return (ANativeWindow*)p_ns;
}
}
free(p_ns);
return NULL;
}
static void
NativeSurface_release(ANativeWindow* p_anw)
{
NativeSurface *p_ns = (NativeSurface *)p_anw;
dlclose(p_ns->p_dl_handle);
free(p_ns);
}
static int32_t
NativeSurface_lock(ANativeWindow *p_anw, ANativeWindow_Buffer *p_anb,
ARect *p_rect)
{
(void) p_rect;
NativeSurface *p_ns = (NativeSurface *)p_anw;
struct {
uint32_t w;
uint32_t h;
uint32_t s;
uint32_t usage;
uint32_t format;
uint32_t* bits;
uint32_t reserved[2];
} info = { 0 };
if (p_ns->pf_lock)
p_ns->pf_lock(p_ns->p_surface_handle, &info, 1);
else
p_ns->pf_lock2(p_ns->p_surface_handle, &info, NULL);
if (!info.w || !info.h) {
p_ns->pf_unlockAndPost(p_ns->p_surface_handle);
return -1;
}
if (p_anb) {
p_anb->bits = info.bits;
p_anb->width = info.w;
p_anb->height = info.h;
p_anb->stride = info.s;
p_anb->format = info.format;
}
return 0;
}
static void
NativeSurface_unlockAndPost(ANativeWindow *p_anw)
{
NativeSurface *p_ns = (NativeSurface *)p_anw;
p_ns->pf_unlockAndPost(p_ns->p_surface_handle);
}
void LoadNativeSurfaceAPI(native_window_api_t *native)
{
native->winFromSurface = NativeSurface_fromSurface;
native->winRelease = NativeSurface_release;
native->winLock = NativeSurface_lock;
native->unlockAndPost = NativeSurface_unlockAndPost;
native->setBuffersGeometry = NULL;
}
/*
* Android NativeWindow (post android 2.3)
*/
void *LoadNativeWindowAPI(native_window_api_t *native)
{
void *p_library = dlopen("libandroid.so", RTLD_NOW);
......@@ -53,6 +198,10 @@ void *LoadNativeWindowAPI(native_window_api_t *native)
return NULL;
}
/*
* Android private NativeWindow (post android 2.3)
*/
int LoadNativeWindowPrivAPI(native_window_priv_api_t *native)
{
native->connect = dlsym(RTLD_DEFAULT, "ANativeWindowPriv_connect");
......@@ -77,26 +226,3 @@ int LoadNativeWindowPrivAPI(native_window_priv_api_t *native)
native->dequeue && native->lock && native->lockData && native->unlockData &&
native->queue && native->cancel && native->setOrientation ? 0 : -1;
}
extern void jni_getMouseCoordinates(int *, int *, int *, int *);
void Manage(vout_display_t *vd)
{
int x, y, button, action;
jni_getMouseCoordinates(&action, &button, &x, &y);
if (x >= 0 && y >= 0)
{
switch( action )
{
case AMOTION_EVENT_ACTION_DOWN:
vout_display_SendEventMouseMoved(vd, x, y);
vout_display_SendEventMousePressed(vd, button); break;
case AMOTION_EVENT_ACTION_UP:
vout_display_SendEventMouseMoved(vd, x, y);
vout_display_SendEventMouseReleased(vd, button); break;
case AMOTION_EVENT_ACTION_MOVE:
vout_display_SendEventMouseMoved(vd, x, y); break;
}
}
}
......@@ -43,32 +43,16 @@ typedef struct
ptr_ANativeWindow_release winRelease;
ptr_ANativeWindow_lock winLock;
ptr_ANativeWindow_unlockAndPost unlockAndPost;
ptr_ANativeWindow_setBuffersGeometry setBuffersGeometry;
ptr_ANativeWindow_setBuffersGeometry setBuffersGeometry; /* can be NULL */
} native_window_api_t;
/* Fill the structure passed as parameter and return a library handle
that should be destroyed with dlclose. */
void *LoadNativeWindowAPI(native_window_api_t *native);
void Manage(vout_display_t *);
#define PRIV_WINDOW_FORMAT_YV12 0x32315659
static inline int ChromaToAndroidHal(vlc_fourcc_t i_chroma)
{
switch (i_chroma) {
case VLC_CODEC_YV12:
case VLC_CODEC_I420:
return PRIV_WINDOW_FORMAT_YV12;
case VLC_CODEC_RGB16:
return WINDOW_FORMAT_RGB_565;
case VLC_CODEC_RGB32:
return WINDOW_FORMAT_RGBX_8888;
case VLC_CODEC_RGBA:
return WINDOW_FORMAT_RGBA_8888;
default:
return -1;
}
}
/* Pre Android 2.3 NativeSurface, no need to free a handle,
* native->sys->anwp.setBuffersGeometry will be NULL. */
void LoadNativeSurfaceAPI(native_window_api_t *native);
typedef struct native_window_priv native_window_priv;
typedef native_window_priv *(*ptr_ANativeWindowPriv_connect) (void *);
......
......@@ -1168,7 +1168,6 @@ modules/video_filter/yuvp.c
modules/video_output/aa.c
modules/video_output/android/android_window.c
modules/video_output/android/nativewindow.c
modules/video_output/android/surface.c
modules/video_output/caca.c
modules/video_output/caopengllayer.m
modules/video_output/decklink.cpp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment