Commit 5182f4f5 authored by Rafaël Carré's avatar Rafaël Carré

androidsurface: simplify dlopen code

parent aa037641
...@@ -129,34 +129,40 @@ static vlc_mutex_t single_instance = VLC_STATIC_MUTEX; ...@@ -129,34 +129,40 @@ static vlc_mutex_t single_instance = VLC_STATIC_MUTEX;
static inline void *LoadSurface(const char *psz_lib, vout_display_sys_t *sys) static inline void *LoadSurface(const char *psz_lib, vout_display_sys_t *sys)
{ {
void *p_library = dlopen(psz_lib, RTLD_NOW); void *p_library = dlopen(psz_lib, RTLD_NOW);
if (p_library) { if (!p_library)
sys->s_lock = (Surface_lock)(dlsym(p_library, ANDROID_SYM_S_LOCK)); return NULL;
sys->s_lock2 = (Surface_lock2)(dlsym(p_library, ANDROID_SYM_S_LOCK2));
sys->s_unlockAndPost = sys->s_lock = (Surface_lock)(dlsym(p_library, ANDROID_SYM_S_LOCK));
(Surface_unlockAndPost)(dlsym(p_library, ANDROID_SYM_S_UNLOCK)); sys->s_lock2 = (Surface_lock2)(dlsym(p_library, ANDROID_SYM_S_LOCK2));
if ((sys->s_lock || sys->s_lock2) && sys->s_unlockAndPost) { sys->s_unlockAndPost =
return p_library; (Surface_unlockAndPost)(dlsym(p_library, ANDROID_SYM_S_UNLOCK));
}
dlclose(p_library); if ((sys->s_lock || sys->s_lock2) && sys->s_unlockAndPost)
} return p_library;
dlclose(p_library);
return NULL; return NULL;
} }
static void *InitLibrary(vout_display_sys_t *sys) static void *InitLibrary(vout_display_sys_t *sys)
{ {
void *p_library; static const char *libs[] = {
if ((p_library = LoadSurface("libsurfaceflinger_client.so", sys))) "libsurfaceflinger_client.so",
return p_library; "libgui.so",
if ((p_library = LoadSurface("libgui.so", sys))) "libui.so"
return p_library; };
return LoadSurface("libui.so", sys);
for (size_t i = 0; i < sizeof(libs) / sizeof(*libs); i++) {
void *lib = LoadSurface(libs[i], sys);
if (lib)
return lib;
}
return NULL;
} }
static int Open(vlc_object_t *p_this) static int Open(vlc_object_t *p_this)
{ {
vout_display_t *vd = (vout_display_t *)p_this; vout_display_t *vd = (vout_display_t *)p_this;
vout_display_sys_t *sys;
void *p_library;
/* */ /* */
if (vlc_mutex_trylock(&single_instance) != 0) { if (vlc_mutex_trylock(&single_instance) != 0) {
...@@ -165,15 +171,15 @@ static int Open(vlc_object_t *p_this) ...@@ -165,15 +171,15 @@ static int Open(vlc_object_t *p_this)
} }
/* Allocate structure */ /* Allocate structure */
sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys)); vout_display_sys_t *sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys));
if (!sys) { if (!sys) {
vlc_mutex_unlock(&single_instance); vlc_mutex_unlock(&single_instance);
return VLC_ENOMEM; return VLC_ENOMEM;
} }
/* */ /* */
sys->p_library = p_library = InitLibrary(sys); sys->p_library = InitLibrary(sys);
if (!p_library) { if (!sys->p_library) {
free(sys); free(sys);
msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!"); msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!");
vlc_mutex_unlock(&single_instance); vlc_mutex_unlock(&single_instance);
...@@ -266,8 +272,8 @@ static int Open(vlc_object_t *p_this) ...@@ -266,8 +272,8 @@ static int Open(vlc_object_t *p_this)
enomem: enomem:
free(rsc->p_sys); free(rsc->p_sys);
dlclose(sys->p_library);
free(sys); free(sys);
dlclose(p_library);
vlc_mutex_unlock(&single_instance); vlc_mutex_unlock(&single_instance);
return VLC_ENOMEM; return VLC_ENOMEM;
} }
...@@ -285,9 +291,9 @@ static void Close(vlc_object_t *p_this) ...@@ -285,9 +291,9 @@ static void Close(vlc_object_t *p_this)
static picture_pool_t *Pool(vout_display_t *vd, unsigned count) static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
{ {
vout_display_sys_t *sys = vd->sys;
VLC_UNUSED(count); VLC_UNUSED(count);
return sys->pool;
return vd->sys->pool;
} }
#define ALIGN_16_PIXELS( x ) ( ( ( x ) + 15 ) / 16 * 16 ) #define ALIGN_16_PIXELS( x ) ( ( ( x ) + 15 ) / 16 * 16 )
...@@ -376,6 +382,8 @@ static void AndroidUnlockSurface(picture_t *picture) ...@@ -376,6 +382,8 @@ static void AndroidUnlockSurface(picture_t *picture)
static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture) static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
{ {
/* FIXME ? */
VLC_UNUSED(vd); VLC_UNUSED(vd);
VLC_UNUSED(subpicture); VLC_UNUSED(subpicture);
picture_Release(picture); picture_Release(picture);
......
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