[vlc-devel] [PATCH v2 04/13] video_output: apply the mouse state just before rendering
Steve Lhomme
robux4 at ycbcr.xyz
Mon Aug 17 15:15:23 CEST 2020
We use the value just before the filters are applied. We wait until the display
deadline in case the mouse value changes again so we use the latest value when
doing the rendering.
If the mouse changes while the picture has been rendered and we wait until we
display it, the mouse state will be applied to the next picture. This is
already the case: as soon as a picture is available we don't handle control
commands anymore.
The mouse value is modified under the display_lock as that's what
ThreadProcessMouseState uses to process the value. We don't need the control lock
for that anymore.
The mouse state is now applied in frame by frame mode as well.
It replaces the VOUT_CONTROL_MOUSE_STATE handling.
---
src/video_output/control.h | 6 ------
src/video_output/video_output.c | 35 +++++++++++++++++++++++----------
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 5d84db34d13..a6d233c4f53 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -28,16 +28,10 @@
/* */
enum {
VOUT_CONTROL_TERMINATE,
-
- VOUT_CONTROL_MOUSE_STATE, /* vlc_mouse_t */
};
typedef struct {
int type;
-
- union {
- vlc_mouse_t mouse;
- };
} vout_control_cmd_t;
void vout_control_cmd_Init(vout_control_cmd_t *, int type);
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index f3f7197cf3f..51dfe2df9ca 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -168,6 +168,8 @@ typedef struct vout_thread_sys_t
vout_display_cfg_t display_cfg;
vout_display_t *display;
vlc_mutex_t display_lock;
+ atomic_bool mouse_changed;
+ vlc_mouse_t new_mouse;
/* Video filter2 chain */
struct {
@@ -389,11 +391,14 @@ void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
assert(!sys->dummy);
assert(mouse);
- vout_control_cmd_t cmd;
- vout_control_cmd_Init(&cmd, VOUT_CONTROL_MOUSE_STATE);
- cmd.mouse = *mouse;
- vout_control_Push(&sys->control, &cmd);
+ vlc_mutex_lock(&sys->display_lock);
+ if (memcmp(&sys->new_mouse, mouse, sizeof(sys->new_mouse)))
+ {
+ sys->new_mouse = *mouse;
+ atomic_store(&sys->mouse_changed, true);
+ }
+ vlc_mutex_unlock(&sys->display_lock);
}
void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
@@ -1446,6 +1451,8 @@ static int ThreadDisplayRenderPicture(vout_thread_sys_t *vout, bool is_forced)
return VLC_SUCCESS;
}
+static void ThreadProcessMouseState(vout_thread_sys_t *);
+
static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
{
vout_thread_sys_t *sys = vout;
@@ -1455,6 +1462,16 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
assert(sys->clock);
+ if (atomic_load(&sys->mouse_changed))
+ {
+ if (deadline)
+ {
+ // wait in case the mouse state changes just before display
+ vlc_tick_wait(*deadline);
+ }
+ ThreadProcessMouseState(vout);
+ }
+
vlc_mutex_lock(&sys->filter.lock);
if (sys->filter.filters_changed ||
sys->filter.new_interlaced != sys->private.interlacing.has_deint)
@@ -1669,8 +1686,7 @@ void vout_ChangeSpuRate(vout_thread_t *vout, size_t channel_id, float rate)
spu_SetClockRate(sys->spu, channel_id, rate);
}
-static void ThreadProcessMouseState(vout_thread_sys_t *p_vout,
- const vlc_mouse_t *win_mouse)
+static void ThreadProcessMouseState(vout_thread_sys_t *p_vout)
{
vlc_mouse_t vid_mouse, tmp1, tmp2, *m;
vout_thread_t *vout = &p_vout->obj;
@@ -1678,7 +1694,8 @@ static void ThreadProcessMouseState(vout_thread_sys_t *p_vout,
/* Translate window coordinates to video coordinates */
vlc_mutex_lock(&sys->display_lock);
- vout_display_TranslateMouseState(sys->display, &vid_mouse, win_mouse);
+ vout_display_TranslateMouseState(sys->display, &vid_mouse, &sys->new_mouse);
+ atomic_store(&sys->mouse_changed, false);
vlc_mutex_unlock(&sys->display_lock);
/* Then pass up the filter chains. */
@@ -1881,9 +1898,6 @@ static void *Thread(void *object)
switch(cmd.type) {
case VOUT_CONTROL_TERMINATE:
return NULL; /* no need to clean &cmd */
- case VOUT_CONTROL_MOUSE_STATE:
- ThreadProcessMouseState(vout, &cmd.mouse);
- break;
}
}
@@ -2107,6 +2121,7 @@ vout_thread_t *vout_Create(vlc_object_t *object)
/* Display */
sys->display = NULL;
vlc_mutex_init(&sys->display_lock);
+ atomic_init(&sys->mouse_changed, false);
/* Window */
sys->window_width = sys->window_height = 0;
--
2.26.2
More information about the vlc-devel
mailing list