]> git.sesse.net Git - vlc/blobdiff - modules/video_output/androidsurface.c
macosx: save 19 l10n strings by replacing them with already present strings from...
[vlc] / modules / video_output / androidsurface.c
index d7c433162edec321420efa325d243bca5b7390ee..6784ab92409e2f640e8af32788bd890ffa42c388 100644 (file)
@@ -115,8 +115,7 @@ struct vout_display_sys_t {
     int i_sar_den;
 };
 
-struct picture_sys_t
-{
+struct picture_sys_t {
     void *surf;
     SurfaceInfo info;
     vout_display_sys_t *sys;
@@ -127,34 +126,43 @@ static void AndroidUnlockSurface(picture_t *);
 
 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);
-    if (p_library) {
-        sys->s_lock = (Surface_lock)(dlsym(p_library, ANDROID_SYM_S_LOCK));
-        sys->s_lock2 = (Surface_lock2)(dlsym(p_library, ANDROID_SYM_S_LOCK2));
-        sys->s_unlockAndPost =
-            (Surface_unlockAndPost)(dlsym(p_library, ANDROID_SYM_S_UNLOCK));
-        if ((sys->s_lock || sys->s_lock2) && sys->s_unlockAndPost) {
-            return p_library;
-        }
-        dlclose(p_library);
-    }
+    if (!p_library)
+        return NULL;
+
+    sys->s_lock = (Surface_lock)(dlsym(p_library, ANDROID_SYM_S_LOCK));
+    sys->s_lock2 = (Surface_lock2)(dlsym(p_library, ANDROID_SYM_S_LOCK2));
+    sys->s_unlockAndPost =
+        (Surface_unlockAndPost)(dlsym(p_library, ANDROID_SYM_S_UNLOCK));
+
+    if ((sys->s_lock || sys->s_lock2) && sys->s_unlockAndPost)
+        return p_library;
+
+    dlclose(p_library);
     return NULL;
 }
 
-static void *InitLibrary(vout_display_sys_t *sys) {
-    void *p_library;
-    if ((p_library = LoadSurface("libsurfaceflinger_client.so", sys)))
-        return p_library;
-    if ((p_library = LoadSurface("libgui.so", sys)))
-        return p_library;
-    return LoadSurface("libui.so", sys);
+static void *InitLibrary(vout_display_sys_t *sys)
+{
+    static const char *libs[] = {
+        "libsurfaceflinger_client.so",
+        "libgui.so",
+        "libui.so"
+    };
+
+    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_sys_t *sys;
-    void *p_library;
 
     /* */
     if (vlc_mutex_trylock(&single_instance) != 0) {
@@ -163,15 +171,15 @@ static int Open(vlc_object_t *p_this) {
     }
 
     /* 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) {
         vlc_mutex_unlock(&single_instance);
         return VLC_ENOMEM;
     }
 
     /* */
-    sys->p_library = p_library = InitLibrary(sys);
-    if (!p_library) {
+    sys->p_library = InitLibrary(sys);
+    if (!sys->p_library) {
         free(sys);
         msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!");
         vlc_mutex_unlock(&single_instance);
@@ -264,13 +272,14 @@ static int Open(vlc_object_t *p_this) {
 
 enomem:
     free(rsc->p_sys);
+    dlclose(sys->p_library);
     free(sys);
-    dlclose(p_library);
     vlc_mutex_unlock(&single_instance);
     return VLC_ENOMEM;
 }
 
-static void Close(vlc_object_t *p_this) {
+static void Close(vlc_object_t *p_this)
+{
     vout_display_t *vd = (vout_display_t *)p_this;
     vout_display_sys_t *sys = vd->sys;
 
@@ -280,10 +289,11 @@ static void Close(vlc_object_t *p_this) {
     vlc_mutex_unlock(&single_instance);
 }
 
-static picture_pool_t *Pool(vout_display_t *vd, unsigned count) {
-    vout_display_sys_t *sys = vd->sys;
+static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
+{
     VLC_UNUSED(count);
-    return sys->pool;
+
+    return vd->sys->pool;
 }
 
 #define ALIGN_16_PIXELS( x ) ( ( ( x ) + 15 ) / 16 * 16 )
@@ -314,7 +324,8 @@ static void SetupPictureYV12( SurfaceInfo* p_surfaceInfo, picture_t *p_picture )
     }
 }
 
-static int  AndroidLockSurface(picture_t *picture) {
+static int  AndroidLockSurface(picture_t *picture)
+{
     picture_sys_t *picsys = picture->p_sys;
     vout_display_sys_t *sys = picsys->sys;
     SurfaceInfo *info;
@@ -359,7 +370,8 @@ static int  AndroidLockSurface(picture_t *picture) {
     return VLC_SUCCESS;
 }
 
-static void AndroidUnlockSurface(picture_t *picture) {
+static void AndroidUnlockSurface(picture_t *picture)
+{
     picture_sys_t *picsys = picture->p_sys;
     vout_display_sys_t *sys = picsys->sys;
 
@@ -368,29 +380,35 @@ static void AndroidUnlockSurface(picture_t *picture) {
     jni_UnlockAndroidSurface();
 }
 
-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)
+{
     VLC_UNUSED(vd);
     VLC_UNUSED(subpicture);
+
+    /* refcount lowers to 0, and pool_cfg.unlock is called */
+
     picture_Release(picture);
 }
 
-static int Control(vout_display_t *vd, int query, va_list args) {
+static int Control(vout_display_t *vd, int query, va_list args)
+{
     VLC_UNUSED(args);
 
     switch (query) {
-        case VOUT_DISPLAY_CHANGE_FULLSCREEN:
-        case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
-        case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
-        case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
-        case VOUT_DISPLAY_CHANGE_ZOOM:
-        case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
-        case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
-        case VOUT_DISPLAY_GET_OPENGL:
-            return VLC_EGENERIC;
-        case VOUT_DISPLAY_HIDE_MOUSE:
-            return VLC_SUCCESS;
-        default:
-            msg_Err(vd, "Unknown request in android vout display");
-            return VLC_EGENERIC;
+    case VOUT_DISPLAY_HIDE_MOUSE:
+        return VLC_SUCCESS;
+
+    default:
+        msg_Err(vd, "Unknown request in android vout display");
+
+    case VOUT_DISPLAY_CHANGE_FULLSCREEN:
+    case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
+    case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
+    case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
+    case VOUT_DISPLAY_CHANGE_ZOOM:
+    case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
+    case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
+    case VOUT_DISPLAY_GET_OPENGL:
+        return VLC_EGENERIC;
     }
 }