[vlc-commits] [Git][videolan/vlc][master] 12 commits: vout: discard mouse events without display
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Thu May 5 13:10:19 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
f0f938f5 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: discard mouse events without display
If there is no display, then not only we cannot translate the
coordinates to something meaningful, but the filters and the mouse
event callback are not initialised yet, so there is also nothing to
pass the events onto (see what ProcessMouseState() does).
- - - - -
aa72e499 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: initialise mouse state just once
Unlike the event callback, which is only known at start time, there are
no particular reasons to reinitialise this every time. This
simplification preemptively avoids what would have been a third
dependency from mouse event processing on the display lock in following
changes.
- - - - -
59b26270 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: process mouse events on the event thread
This moves what was left of mouse event processing out of the video
output thread. Thus mouse events are processed directly from the
emitting thread (UI for embedded video, window provider otherwise),
just like keyboard events.
This removes the lesser bottleneck in mouse event processing (the
bigger bottleneck being the display lock to be removed further on).
Incidentally, this also removes the last remaining event type from the
video output queue.
- - - - -
1fc75b08 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: remove vout_control_PushMouse()
- - - - -
30671b46 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: remove vout_control_Clean()
This had become a no-op.
- - - - -
4322cf2f by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: remove old mouse event handling code
- - - - -
28994fc3 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout: simplify/rename vout_control_Pop()
The return value was always VLC_EGENERIC, so remove it. Rename the
function to vout_control_Wait() as all it ever does now is wait, now
that there is no control queue.
- - - - -
0e4ed0f6 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout/control: minor code factor
- - - - -
a2ad11fe by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout/control: non-functional simplification
- - - - -
d7b6277c by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout/control: favour holders over wakers
Holders typically expect to be processed as soon as possible (e.g.
toggling pause) as response to user interaction. Waking up the control
queue on the other hand was only meant to avoid dead lock, and nowadays
only serves to avoid waiting for the control deadline.
Note that we do not really need to recheck the pending count in the
original wait loop. If we get there, we will wait for the time-out and
let holders pass anyway.
- - - - -
4620c3d7 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout/control: lift constant predicate
The deadline is a constant for the span of the function call, so we
can check it once and notionally propagate the value within the for
loop.
Then the for loop is essentially a no-op when the deadline equals
VLC_TICK_INVALID, so that leaves only the case of a valid deadline.
- - - - -
4afe59d8 by Rémi Denis-Courmont at 2022-05-05T12:51:45+00:00
vout/control: cosmetic change
- - - - -
3 changed files:
- src/video_output/control.c
- src/video_output/control.h
- src/video_output/video_output.c
Changes:
=====================================
src/video_output/control.c
=====================================
@@ -40,21 +40,6 @@ void vout_control_Init(vout_control_t *ctrl)
ctrl->yielding = false;
ctrl->forced_awake = false;
ctrl->pending_count = 0;
- ARRAY_INIT(ctrl->cmd);
-}
-
-void vout_control_Clean(vout_control_t *ctrl)
-{
- /* */
- ARRAY_RESET(ctrl->cmd);
-}
-
-void vout_control_PushMouse(vout_control_t *ctrl, const vlc_mouse_t *video_mouse)
-{
- vlc_mutex_lock(&ctrl->lock);
- ARRAY_APPEND(ctrl->cmd, *video_mouse);
- vlc_cond_signal(&ctrl->wait_request);
- vlc_mutex_unlock(&ctrl->lock);
}
void vout_control_Wake(vout_control_t *ctrl)
@@ -88,54 +73,38 @@ void vout_control_Release(vout_control_t *ctrl)
vlc_mutex_unlock(&ctrl->lock);
}
-int vout_control_Pop(vout_control_t *ctrl, vlc_mouse_t *mouse, vlc_tick_t deadline)
+void vout_control_Wait(vout_control_t *ctrl, vlc_tick_t deadline)
{
- bool has_cmd = false;
vlc_mutex_lock(&ctrl->lock);
- bool timed_out = false;
- for (;;)
+ ctrl->yielding = true;
+
+ while (ctrl->pending_count != 0)
{
- if (ctrl->forced_awake)
- break;
+ /* Let vout_control_Hold() callers pass */
+ vlc_cond_signal(&ctrl->wait_available);
+ vlc_cond_wait(&ctrl->wait_request, &ctrl->lock);
+ }
- if (ctrl->pending_count != 0)
- {
- /* Let vout_control_Hold() callers pass */
- ctrl->yielding = true;
- vlc_cond_signal(&ctrl->wait_available);
- vlc_cond_wait(&ctrl->wait_request, &ctrl->lock);
- ctrl->yielding = false;
- }
- else if (timed_out)
- break;
- else if (ctrl->cmd.i_size <= 0 && deadline != VLC_TICK_INVALID)
+ if (deadline != VLC_TICK_INVALID)
+ {
+ do
{
- ctrl->yielding = true;
+ if (ctrl->forced_awake)
+ break;
+
vlc_cond_signal(&ctrl->wait_available);
- timed_out =
- vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock, deadline);
- ctrl->yielding = false;
}
- else
- break;
+ while (vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock,
+ deadline) == 0);
}
+ ctrl->yielding = false;
+
while (ctrl->is_held)
vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
- if (ctrl->cmd.i_size > 0) {
- has_cmd = true;
- *mouse = ARRAY_VAL(ctrl->cmd, 0);
- ARRAY_REMOVE(ctrl->cmd, 0);
- // keep forced_awake set, if it is, so we report all mouse states we have
- // after we were awaken when a new picture has been pushed by the decoder
- // see vout_control_Wake
- } else {
- ctrl->forced_awake = false;
- }
+ ctrl->forced_awake = false;
vlc_mutex_unlock(&ctrl->lock);
-
- return has_cmd ? VLC_SUCCESS : VLC_EGENERIC;
}
=====================================
src/video_output/control.h
=====================================
@@ -36,20 +36,17 @@ typedef struct {
bool yielding;
bool is_held;
unsigned pending_count;
- DECL_ARRAY(vlc_mouse_t) cmd;
} vout_control_t;
/* */
void vout_control_Init(vout_control_t *);
-void vout_control_Clean(vout_control_t *);
/* controls outside of the vout thread */
-void vout_control_PushMouse(vout_control_t *, const vlc_mouse_t *);
void vout_control_Wake(vout_control_t *);
void vout_control_Hold(vout_control_t *);
void vout_control_Release(vout_control_t *);
/* control inside of the vout thread */
-int vout_control_Pop(vout_control_t *, vlc_mouse_t *, vlc_tick_t deadline);
+void vout_control_Wait(vout_control_t *, vlc_tick_t deadline);
#endif
=====================================
src/video_output/video_output.c
=====================================
@@ -264,19 +264,53 @@ void vout_DisplayTitle(vout_thread_t *vout, const char *title)
void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
{
vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
+ vlc_mouse_t video_mouse, tmp[2];
+ const vlc_mouse_t *m = &video_mouse;
+ bool has_display;
+
assert(!sys->dummy);
assert(mouse);
/* Translate window coordinates to video coordinates */
vlc_mutex_lock(&sys->display_lock);
- vlc_mouse_t video_mouse;
- if (sys->display)
+ has_display = sys->display != NULL;
+ if (has_display)
vout_display_TranslateMouseState(sys->display, &video_mouse, mouse);
- else
- video_mouse = *mouse;
vlc_mutex_unlock(&sys->display_lock);
- vout_control_PushMouse(&sys->control, &video_mouse);
+ if (!has_display)
+ return;
+
+ /* Pass mouse events through the filter chains. */
+ vlc_mutex_lock(&sys->filter.lock);
+ if (sys->filter.chain_static != NULL
+ && sys->filter.chain_interactive != NULL) {
+ if (!filter_chain_MouseFilter(sys->filter.chain_interactive,
+ &tmp[0], m))
+ m = &tmp[0];
+ if (!filter_chain_MouseFilter(sys->filter.chain_static,
+ &tmp[1], m))
+ m = &tmp[1];
+ }
+ vlc_mutex_unlock(&sys->filter.lock);
+
+ /* Check if the mouse state actually changed and emit events. */
+ /* NOTE: sys->mouse is only used here, so no need to lock. */
+
+ if (vlc_mouse_HasMoved(&sys->mouse, m))
+ var_SetCoords(vout, "mouse-moved", m->i_x, m->i_y);
+ if (vlc_mouse_HasButton(&sys->mouse, m))
+ var_SetInteger(vout, "mouse-button-down", m->i_pressed);
+ if (m->b_double_click)
+ var_ToggleBool(vout, "fullscreen");
+
+ sys->mouse = *m;
+
+ vlc_mutex_lock(&sys->display_lock);
+ /* Mouse events are only initialised if the display exists. */
+ if (sys->display != NULL && sys->mouse_event != NULL)
+ sys->mouse_event(m, sys->mouse_opaque);
+ vlc_mutex_unlock(&sys->display_lock);
}
void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
@@ -1558,41 +1592,6 @@ void vout_ChangeSpuRate(vout_thread_t *vout, size_t channel_id, float rate)
spu_SetClockRate(sys->spu, channel_id, rate);
}
-static void ProcessMouseState(vout_thread_sys_t *p_vout,
- const vlc_mouse_t *win_mouse)
-{
- vlc_mouse_t tmp1, tmp2;
- const vlc_mouse_t *m;
- vout_thread_t *vout = &p_vout->obj;
- vout_thread_sys_t *sys = p_vout;
-
- /* pass mouse coordinates in the filter chains. */
- m = win_mouse;
- vlc_mutex_lock(&sys->filter.lock);
- if (sys->filter.chain_static && sys->filter.chain_interactive) {
- if (!filter_chain_MouseFilter(sys->filter.chain_interactive,
- &tmp1, m))
- m = &tmp1;
- if (!filter_chain_MouseFilter(sys->filter.chain_static,
- &tmp2, m))
- m = &tmp2;
- }
- vlc_mutex_unlock(&sys->filter.lock);
-
- if (vlc_mouse_HasMoved(&sys->mouse, m))
- var_SetCoords(vout, "mouse-moved", m->i_x, m->i_y);
-
- if (vlc_mouse_HasButton(&sys->mouse, m))
- var_SetInteger(vout, "mouse-button-down", m->i_pressed);
-
- if (m->b_double_click)
- var_ToggleBool(vout, "fullscreen");
- sys->mouse = *m;
-
- if (sys->mouse_event)
- sys->mouse_event(m, sys->mouse_opaque);
-}
-
static int vout_Start(vout_thread_sys_t *vout, vlc_video_context *vctx, const vout_configuration_t *cfg)
{
vout_thread_sys_t *sys = vout;
@@ -1600,7 +1599,6 @@ static int vout_Start(vout_thread_sys_t *vout, vlc_video_context *vctx, const vo
sys->mouse_event = cfg->mouse_event;
sys->mouse_opaque = cfg->mouse_opaque;
- vlc_mouse_Init(&sys->mouse);
sys->decoder_fifo = picture_fifo_New();
sys->private.display_pool = NULL;
@@ -1722,12 +1720,7 @@ static void *Thread(void *object)
vlc_tick_t deadline = VLC_TICK_INVALID;
for (;;) {
- vlc_mouse_t video_mouse;
- while (vout_control_Pop(&sys->control, &video_mouse, deadline) == VLC_SUCCESS) {
- if (atomic_load(&sys->control_is_terminated))
- break;
- ProcessMouseState(vout, &video_mouse);
- }
+ vout_control_Wait(&sys->control, deadline);
if (atomic_load(&sys->control_is_terminated))
break;
@@ -1869,8 +1862,6 @@ void vout_Release(vout_thread_t *vout)
assert(!sys->window_enabled);
vout_display_window_Delete(sys->display_cfg.window);
- vout_control_Clean(&sys->control);
-
/* */
vout_statistic_Clean(&sys->statistic);
@@ -1893,7 +1884,7 @@ static vout_thread_sys_t *vout_CreateCommon(vlc_object_t *object)
vout_thread_sys_t *sys = vout;
vlc_atomic_rc_init(&sys->rc);
-
+ vlc_mouse_Init(&sys->mouse);
return vout;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cefa4c00bef6b787f2ce4156219f24692632bc19...4afe59d8ee96fb4d1ac2266e42d327ff0c9dab2b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cefa4c00bef6b787f2ce4156219f24692632bc19...4afe59d8ee96fb4d1ac2266e42d327ff0c9dab2b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list