2 * @file androidnativewindow.c
3 * @brief Android native window provider module for VLC media player
5 /*****************************************************************************
6 * Copyright © 2013 VLC authors and VideoLAN
8 * Author: Adrien Maglo <magsoft@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout_window.h>
41 extern jobject jni_LockAndGetAndroidJavaSurface();
42 extern void jni_UnlockAndroidSurface();
43 extern void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
45 static int Open(vout_window_t *, const vout_window_cfg_t *);
46 static void Close(vout_window_t *);
47 static int Control(vout_window_t *, int, va_list ap);
53 set_shortname(N_("ANativeWindow"))
54 set_description(N_("Android native window"))
55 set_category(CAT_VIDEO)
56 set_subcategory(SUBCAT_VIDEO_VOUT)
57 set_capability("vout window anative", 10)
58 set_callbacks(Open, Close)
62 struct vout_window_sys_t
65 native_window_api_t native_window;
67 ANativeWindow *window;
71 * Create an Android native window.
73 static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
75 vout_window_sys_t *p_sys = malloc(sizeof (*p_sys));
79 p_sys->p_library = LoadNativeWindowAPI(&p_sys->native_window);
80 if (p_sys->p_library == NULL)
86 // Create the native window by first getting the Java surface.
87 jobject javaSurface = jni_LockAndGetAndroidJavaSurface();
88 if (javaSurface == NULL)
92 (*myVm)->AttachCurrentThread(myVm, &p_env, NULL);
93 p_sys->window = p_sys->native_window.winFromSurface(p_env, javaSurface); // ANativeWindow_fromSurface call.
94 (*myVm)->DetachCurrentThread(myVm);
96 jni_UnlockAndroidSurface();
98 if (p_sys->window == NULL)
101 wnd->handle.anativewindow = p_sys->window;
102 wnd->control = Control;
105 // Set the Java surface size.
106 jni_SetAndroidSurfaceSize(cfg->width, cfg->height, cfg->width, cfg->height, 1, 1);
111 dlclose(p_sys->p_library);
118 * Destroys the Android native window.
120 static void Close(vout_window_t *wnd)
122 vout_window_sys_t *p_sys = wnd->sys;
123 p_sys->native_window.winRelease(p_sys->window); // Release the native window.
124 dlclose(p_sys->p_library); // Close the library.
132 static int Control(vout_window_t *wnd, int cmd, va_list ap)
136 case VOUT_WINDOW_SET_SIZE:
138 unsigned width = va_arg(ap, unsigned);
139 unsigned height = va_arg(ap, unsigned);
140 jni_SetAndroidSurfaceSize(width, height, width, height, 1, 1);
143 case VOUT_WINDOW_SET_STATE:
144 case VOUT_WINDOW_SET_FULLSCREEN:
147 msg_Err (wnd, "request %d not implemented", cmd);