[vlc-devel] [PATCH v4 18/23] video_output: use an internal bool to detect when we must exit the vout thread
Steve Lhomme
robux4 at ycbcr.xyz
Fri Aug 21 11:59:36 CEST 2020
Remove the related push functions and vout_control_Dead() since we won't process
any more commands if we have the terminate flag.
---
src/video_output/control.c | 16 +---------------
src/video_output/control.h | 5 -----
src/video_output/video_output.c | 16 +++++++++-------
3 files changed, 10 insertions(+), 27 deletions(-)
diff --git a/src/video_output/control.c b/src/video_output/control.c
index 4950da5aae6..83a08043e3a 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -39,7 +39,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *cmd, int type)
/* */
void vout_control_Init(vout_control_t *ctrl)
{
- ctrl->is_dead = false;
ctrl->can_sleep = true;
ARRAY_INIT(ctrl->cmd);
}
@@ -50,14 +49,9 @@ void vout_control_Clean(vout_control_t *ctrl)
ARRAY_RESET(ctrl->cmd);
}
-void vout_control_Dead(vout_control_t *ctrl)
-{
- ctrl->is_dead = true;
-}
-
void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
{
- if (!ctrl->is_dead) {
+ {
ARRAY_APPEND(ctrl->cmd, *cmd);
}
}
@@ -67,14 +61,6 @@ void vout_control_Wake(vout_control_t *ctrl)
ctrl->can_sleep = false;
}
-void vout_control_PushVoid(vout_control_t *ctrl, int type)
-{
- vout_control_cmd_t cmd;
-
- vout_control_cmd_Init(&cmd, type);
- vout_control_Push(ctrl, &cmd);
-}
-
int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
vlc_tick_t deadline, vlc_cond_t *wait_request, vlc_mutex_t *lock)
{
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 55906f84723..a5bbef577b6 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -27,8 +27,6 @@
/* */
enum {
- VOUT_CONTROL_TERMINATE,
-
VOUT_CONTROL_MOUSE_STATE, /* vlc_mouse_t */
};
@@ -44,7 +42,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *, int type);
typedef struct {
/* */
- bool is_dead;
bool can_sleep;
DECL_ARRAY(vout_control_cmd_t) cmd;
} vout_control_t;
@@ -57,13 +54,11 @@ void vout_control_Clean(vout_control_t *);
void vout_control_WaitEmpty(vout_control_t *);
void vout_control_Push(vout_control_t *, vout_control_cmd_t *);
-void vout_control_PushVoid(vout_control_t *, int type);
void vout_control_Wake(vout_control_t *);
/* control inside of the vout thread */
#define INVALID_DEADLINE ((vlc_tick_t) INT64_MAX)
int vout_control_Pop(vout_control_t *, vout_control_cmd_t *, vlc_tick_t deadline, vlc_cond_t *, vlc_mutex_t *);
-void vout_control_Dead(vout_control_t *);
#endif
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 390fabc43c4..571e86f6248 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -122,6 +122,7 @@ typedef struct vout_thread_sys_t
/* Thread & synchronization */
vlc_mutex_t control_lock;
vlc_cond_t has_pictures;
+ bool terminate;
vout_control_t control;
vlc_thread_t thread;
@@ -1854,10 +1855,13 @@ static void *Thread(void *object)
vlc_mutex_lock(&sys->control_lock);
while (!vout_control_Pop(&sys->control, &cmd, deadline,
&sys->has_pictures, &sys->control_lock)) {
+ if (sys->terminate)
+ {
+ vlc_mutex_unlock(&sys->control_lock);
+ return NULL;
+ }
+
switch(cmd.type) {
- case VOUT_CONTROL_TERMINATE:
- vlc_mutex_unlock(&sys->control_lock);
- return NULL; /* no need to clean &cmd */
case VOUT_CONTROL_MOUSE_STATE:
ThreadProcessMouseState(vout, &cmd.mouse);
break;
@@ -1925,7 +1929,7 @@ void vout_StopDisplay(vout_thread_t *vout)
vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
vlc_mutex_lock(&sys->control_lock);
- vout_control_PushVoid(&sys->control, VOUT_CONTROL_TERMINATE);
+ sys->terminate = true;
// stop waiting for pictures
vlc_cond_signal(&sys->has_pictures);
vlc_mutex_unlock(&sys->control_lock);
@@ -1967,9 +1971,6 @@ void vout_Close(vout_thread_t *vout)
vout_IntfDeinit(VLC_OBJECT(vout));
vout_snapshot_End(sys->snapshot);
- vlc_mutex_lock(&sys->control_lock);
- vout_control_Dead(&sys->control);
- vlc_mutex_unlock(&sys->control_lock);
vout_chrono_Clean(&sys->render);
if (sys->spu)
@@ -2078,6 +2079,7 @@ vout_thread_t *vout_Create(vlc_object_t *object)
vlc_mutex_init(&sys->control_lock);
vlc_cond_init(&sys->has_pictures);
vout_control_Init(&sys->control);
+ sys->terminate = false;
sys->title.show = var_InheritBool(vout, "video-title-show");
sys->title.timeout = var_InheritInteger(vout, "video-title-timeout");
--
2.26.2
More information about the vlc-devel
mailing list