[vlc-commits] vout: android: don't poll window size and mouse events
Thomas Guillem
git at videolan.org
Mon Nov 28 16:37:47 CET 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Nov 24 18:34:30 2016 +0100| [3d9f101c5bded52f243f655bbe86c686fe8f5f41] | committer: Thomas Guillem
vout: android: don't poll window size and mouse events
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3d9f101c5bded52f243f655bbe86c686fe8f5f41
---
modules/video_output/android/display.c | 43 +------------
modules/video_output/android/utils.c | 106 ++++++---------------------------
modules/video_output/android/utils.h | 35 ++++++-----
modules/video_output/android/window.c | 35 +++++++++--
4 files changed, 65 insertions(+), 154 deletions(-)
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index 16ab0c0..18ea4a2 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -77,7 +77,6 @@ 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;
@@ -643,19 +642,6 @@ static void SetRGBMask(video_format_t *p_fmt)
}
}
-static void SendEventDisplaySize(vout_display_t *vd)
-{
- vout_display_sys_t *sys = vd->sys;
- int i_display_width, i_display_height;
-
- if (AWindowHandler_getWindowSize(sys->p_awh, &i_display_width, &i_display_height)
- && i_display_width != 0 && i_display_height != 0
- && (i_display_width != sys->i_display_width
- || i_display_height != sys->i_display_height))
- vout_display_SendEventDisplaySize(vd, i_display_width,
- i_display_height);
-}
-
static int Open(vlc_object_t *p_this)
{
vout_display_t *vd = (vout_display_t*)p_this;
@@ -750,11 +736,11 @@ static int Open(vlc_object_t *p_this)
vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
- vd->manage = Manage;
+ vd->manage = NULL;
+ vd->info.has_event_thread = true;
/* Fix initial state */
vout_display_SendEventFullscreen(vd, true);
- SendEventDisplaySize(vd);
return VLC_SUCCESS;
@@ -1011,8 +997,6 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
vout_display_sys_t *sys = vd->sys;
VLC_UNUSED(picture);
- SendEventDisplaySize(vd);
-
if (subpicture && sys->p_sub_window) {
if (sys->b_sub_invalid) {
sys->b_sub_invalid = false;
@@ -1140,26 +1124,3 @@ static int Control(vout_display_t *vd, int query, va_list args)
return VLC_EGENERIC;
}
}
-
-static void Manage(vout_display_t *vd)
-{
- vout_display_sys_t *sys = vd->sys;
- int x, y, button, action;
-
- if (AWindowHandler_getMouseCoordinates(sys->p_awh,
- &action, &button, &x, &y))
- {
- 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;
- }
- }
-}
-
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 83a6e14..8a52b94 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -33,6 +33,7 @@ struct AWindowHandler
{
JavaVM *p_jvm;
jobject jobj;
+ vout_window_t *wnd;
struct {
jobject jsurface;
@@ -45,15 +46,9 @@ struct AWindowHandler
native_window_api_t anw_api;
native_window_priv_api_t anwpriv_api;
- vlc_mutex_t lock;
struct {
bool b_registered;
- struct {
- int i_action, i_button, i_x, i_y;
- } mouse;
- struct {
- int i_width, i_height;
- } window;
+ awh_events_t cb;
} event;
};
@@ -458,29 +453,29 @@ AWindowHandler_getEnv(AWindowHandler *p_awh)
}
AWindowHandler *
-AWindowHandler_new(vlc_object_t *p_obj)
+AWindowHandler_new(vout_window_t *wnd, awh_events_t *p_events)
{
AWindowHandler *p_awh;
JNIEnv *p_env;
- JavaVM *p_jvm = var_InheritAddress(p_obj, "android-jvm");
- jobject jobj = var_InheritAddress(p_obj, "drawable-androidwindow");
+ JavaVM *p_jvm = var_InheritAddress(wnd, "android-jvm");
+ jobject jobj = var_InheritAddress(wnd, "drawable-androidwindow");
if (!p_jvm || !jobj)
{
- msg_Err(p_obj, "libvlc_media_player options not set");
+ msg_Err(wnd, "libvlc_media_player options not set");
return NULL;
}
p_env = android_getEnvCommon(NULL, p_jvm, "AWindowHandler");
if (!p_env)
{
- msg_Err(p_obj, "can't get JNIEnv");
+ msg_Err(wnd, "can't get JNIEnv");
return NULL;
}
- if (InitJNIFields(p_env, p_obj, jobj) != VLC_SUCCESS)
+ if (InitJNIFields(p_env, VLC_OBJECT(wnd), jobj) != VLC_SUCCESS)
{
- msg_Err(p_obj, "InitJNIFields failed");
+ msg_Err(wnd, "InitJNIFields failed");
return NULL;
}
p_awh = calloc(1, sizeof(AWindowHandler));
@@ -489,10 +484,10 @@ AWindowHandler_new(vlc_object_t *p_obj)
p_awh->p_jvm = p_jvm;
p_awh->jobj = (*p_env)->NewGlobalRef(p_env, jobj);
LoadNativeWindowAPI(p_awh);
- vlc_mutex_init(&p_awh->lock);
- p_awh->event.mouse.i_action = p_awh->event.mouse.i_button =
- p_awh->event.mouse.i_x = p_awh->event.mouse.i_y = -1;
- p_awh->event.window.i_width = p_awh->event.window.i_height = -1;
+ p_awh->wnd = wnd;
+ p_awh->event.cb = *p_events;
+ p_awh->event.b_registered = JNI_CALL(CallBooleanMethod, setCallback,
+ (jlong)(intptr_t)p_awh);
return p_awh;
}
@@ -550,8 +545,6 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
(*p_env)->DeleteGlobalRef(p_env, p_awh->jobj);
}
- vlc_mutex_destroy(&p_awh->lock);
-
if (p_awh->p_anw_dl)
dlclose(p_awh->p_anw_dl);
@@ -638,12 +631,8 @@ AndroidNativeWindow_onMouseEvent(JNIEnv* env, jobject clazz, jlong handle,
(void) env; (void) clazz;
AWindowHandler *p_awh = jlong_AWindowHandler(handle);
- vlc_mutex_lock(&p_awh->lock);
- p_awh->event.mouse.i_action = action;
- p_awh->event.mouse.i_button = button;
- p_awh->event.mouse.i_x = x;
- p_awh->event.mouse.i_y = y;
- vlc_mutex_unlock(&p_awh->lock);
+ p_awh->event.cb.on_new_mouse_coords(p_awh->wnd,
+ & (struct awh_mouse_coords) { action, button, x, y });
}
static void
@@ -653,69 +642,8 @@ AndroidNativeWindow_onWindowSize(JNIEnv* env, jobject clazz, jlong handle,
(void) env; (void) clazz;
AWindowHandler *p_awh = jlong_AWindowHandler(handle);
- vlc_mutex_lock(&p_awh->lock);
- p_awh->event.window.i_width = width;
- p_awh->event.window.i_height = height;
- vlc_mutex_unlock(&p_awh->lock);
-}
-
-static bool
-AWindowHandler_registerCallback(AWindowHandler *p_awh)
-{
- if (!p_awh->event.b_registered)
- {
- JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
- if (!p_env)
- return false;
- p_awh->event.b_registered = JNI_CALL(CallBooleanMethod,
- setCallback,
- (jlong)(intptr_t)p_awh);
- }
- return p_awh->event.b_registered;
-}
-
-bool
-AWindowHandler_getMouseCoordinates(AWindowHandler *p_awh,
- int *p_action, int *p_button,
- int *p_x, int *p_y)
-{
- if (!AWindowHandler_registerCallback(p_awh))
- return false;
-
- vlc_mutex_lock(&p_awh->lock);
- if (p_awh->event.mouse.i_action == -1
- || p_awh->event.mouse.i_button == -1
- || p_awh->event.mouse.i_x <= 0 || p_awh->event.mouse.i_y <= 0)
- {
- vlc_mutex_unlock(&p_awh->lock);
- return false;
- }
- *p_action = p_awh->event.mouse.i_action;
- *p_button = p_awh->event.mouse.i_button;
- *p_x = p_awh->event.mouse.i_x;
- *p_y = p_awh->event.mouse.i_y;
- vlc_mutex_unlock(&p_awh->lock);
- return true;
-}
-
-bool
-AWindowHandler_getWindowSize(AWindowHandler *p_awh,
- int *p_width, int *p_height)
-{
- if (!AWindowHandler_registerCallback(p_awh))
- return false;
-
- vlc_mutex_lock(&p_awh->lock);
- if (p_awh->event.window.i_width <= 0
- || p_awh->event.window.i_height <= 0)
- {
- vlc_mutex_unlock(&p_awh->lock);
- return false;
- }
- *p_width = p_awh->event.window.i_width;
- *p_height = p_awh->event.window.i_height;
- vlc_mutex_unlock(&p_awh->lock);
- return true;
+ if (width >= 0 && height >= 0)
+ p_awh->event.cb.on_new_window_size(p_awh->wnd, width, height);
}
int
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 79cc15b..31d65e9 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -74,6 +74,22 @@ typedef struct
int (*setOrientation) (native_window_priv *, int);
} native_window_priv_api_t;
+struct awh_mouse_coords
+{
+ int i_action;
+ int i_button;
+ int i_x;
+ int i_y;
+};
+
+typedef struct
+{
+ void (*on_new_window_size)(vout_window_t *wnd, unsigned i_width,
+ unsigned i_height);
+ void (*on_new_mouse_coords)(vout_window_t *wnd,
+ const struct awh_mouse_coords *coords);
+} awh_events_t;
+
/**
* Load a private native window API
*
@@ -100,7 +116,7 @@ JNIEnv *android_getEnv(vlc_object_t *p_obj, const char *psz_thread_name);
* \return a valid AWindowHandler * or NULL. It must be released with
* AWindowHandler_destroy.
*/
-AWindowHandler *AWindowHandler_new(vlc_object_t *p_obj);
+AWindowHandler *AWindowHandler_new(vout_window_t *wnd, awh_events_t *p_events);
void AWindowHandler_destroy(AWindowHandler *p_awh);
/**
@@ -112,23 +128,6 @@ void AWindowHandler_destroy(AWindowHandler *p_awh);
native_window_api_t *AWindowHandler_getANativeWindowAPI(AWindowHandler *p_awh);
/**
- * Retrieves the mouse coordinates
- *
- * \return true if the coordinates are valid.
- */
-bool AWindowHandler_getMouseCoordinates(AWindowHandler *p_awh,
- int *p_action, int *p_button,
- int *p_x, int *p_y);
-
-/**
- * Retrieves the window size
- *
- * \return true if the size is valid.
- */
-bool AWindowHandler_getWindowSize(AWindowHandler *p_awh,
- int *p_width, int *p_height);
-
-/**
* Get the Video or the Subtitles Android Surface
*
* \return the surface in a jobject, or NULL. It should be released with
diff --git a/modules/video_output/android/window.c b/modules/video_output/android/window.c
index 38e9789..4b752ee 100644
--- a/modules/video_output/android/window.c
+++ b/modules/video_output/android/window.c
@@ -61,6 +61,29 @@ struct vout_window_sys_t
AWindowHandler *p_awh;
};
+static void OnNewWindowSize(vout_window_t *wnd,
+ unsigned i_width, unsigned i_height)
+{
+ vout_window_ReportSize(wnd, i_width, i_height);
+}
+
+static void OnNewMouseCoords(vout_window_t *wnd,
+ const struct awh_mouse_coords *coords)
+{
+ vout_window_ReportMouseMoved(wnd, coords->i_x, coords->i_y);
+ switch (coords->i_action)
+ {
+ case AMOTION_EVENT_ACTION_DOWN:
+ vout_window_ReportMousePressed(wnd, coords->i_button);
+ break;
+ case AMOTION_EVENT_ACTION_UP:
+ vout_window_ReportMouseReleased(wnd, coords->i_button);
+ break;
+ case AMOTION_EVENT_ACTION_MOVE:
+ break;
+ }
+}
+
/**
* Create an Android native window.
*/
@@ -73,22 +96,21 @@ static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
vout_window_sys_t *p_sys = malloc(sizeof (*p_sys));
if (p_sys == NULL)
return VLC_ENOMEM;
+ wnd->sys = p_sys;
- p_sys->p_awh = AWindowHandler_new(VLC_OBJECT(wnd));
+ p_sys->p_awh = AWindowHandler_new(wnd,
+ &(awh_events_t) { OnNewWindowSize, OnNewMouseCoords });
if (!p_sys->p_awh)
goto error;
wnd->type = VOUT_WINDOW_TYPE_ANDROID_NATIVE;
wnd->handle.anativewindow = p_sys->p_awh;
wnd->control = Control;
- wnd->sys = p_sys;
return VLC_SUCCESS;
error:
- if (p_sys->p_awh)
- AWindowHandler_destroy(p_sys->p_awh);
- free(p_sys);
+ Close(wnd);
return VLC_EGENERIC;
}
@@ -99,7 +121,8 @@ error:
static void Close(vout_window_t *wnd)
{
vout_window_sys_t *p_sys = wnd->sys;
- AWindowHandler_destroy(p_sys->p_awh);
+ if (p_sys->p_awh)
+ AWindowHandler_destroy(p_sys->p_awh);
free (p_sys);
}
More information about the vlc-commits
mailing list