[vlc-devel] [PATCH v2 01/13] video_output: use filter lock to change filters in the vout thread

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 17 15:24:44 CEST 2020


New patchset of the vout control code cleaning (ie complete removal).

The lock/condition are moved out of the control code to keep the same 
behavior we had so far. Further cleaning may be applied for all the 
vout_Change calls that may not need this lock.

On 2020-08-17 15:15, Steve Lhomme wrote:
> We don't need to wait when enabling filters, it's OK if we miss the current
> frame and apply it in the next loop iteration.
> 
> We don't use the control lock anymore, just the filters lock.
> 
> Now the filter changes are applied even in frame by frame mode.
> 
> Remove related control push/clean functions.
> ---
>   src/video_output/control.c      | 26 --------------------------
>   src/video_output/control.h      |  4 ----
>   src/video_output/video_output.c | 29 +++++++++++++++++++++++------
>   3 files changed, 23 insertions(+), 36 deletions(-)
> 
> diff --git a/src/video_output/control.c b/src/video_output/control.c
> index fd0c80fe6eb..db9c30b32ad 100644
> --- a/src/video_output/control.c
> +++ b/src/video_output/control.c
> @@ -35,17 +35,6 @@ void vout_control_cmd_Init(vout_control_cmd_t *cmd, int type)
>       cmd->type = type;
>   }
>   
> -void vout_control_cmd_Clean(vout_control_cmd_t *cmd)
> -{
> -    switch (cmd->type) {
> -    case VOUT_CONTROL_CHANGE_FILTERS:
> -        free(cmd->string);
> -        break;
> -    default:
> -        break;
> -    }
> -}
> -
>   /* */
>   void vout_control_Init(vout_control_t *ctrl)
>   {
> @@ -63,10 +52,6 @@ void vout_control_Init(vout_control_t *ctrl)
>   void vout_control_Clean(vout_control_t *ctrl)
>   {
>       /* */
> -    for (int i = 0; i < ctrl->cmd.i_size; i++) {
> -        vout_control_cmd_t cmd = ARRAY_VAL(ctrl->cmd, i);
> -        vout_control_cmd_Clean(&cmd);
> -    }
>       ARRAY_RESET(ctrl->cmd);
>   }
>   
> @@ -83,8 +68,6 @@ void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
>       if (!ctrl->is_dead) {
>           ARRAY_APPEND(ctrl->cmd, *cmd);
>           vlc_cond_signal(&ctrl->wait_request);
> -    } else {
> -        vout_control_cmd_Clean(cmd);
>       }
>       vlc_mutex_unlock(&ctrl->lock);
>   }
> @@ -113,15 +96,6 @@ void vout_control_PushBool(vout_control_t *ctrl, int type, bool boolean)
>       vout_control_Push(ctrl, &cmd);
>   }
>   
> -void vout_control_PushString(vout_control_t *ctrl, int type, const char *string)
> -{
> -    vout_control_cmd_t cmd;
> -
> -    vout_control_cmd_Init(&cmd, type);
> -    cmd.string = string ? strdup(string) : NULL;
> -    vout_control_Push(ctrl, &cmd);
> -}
> -
>   void vout_control_Hold(vout_control_t *ctrl)
>   {
>       vlc_mutex_lock(&ctrl->lock);
> diff --git a/src/video_output/control.h b/src/video_output/control.h
> index eee86c4ca93..ed4613d6c14 100644
> --- a/src/video_output/control.h
> +++ b/src/video_output/control.h
> @@ -28,7 +28,6 @@
>   /* */
>   enum {
>       VOUT_CONTROL_TERMINATE,
> -    VOUT_CONTROL_CHANGE_FILTERS,        /* string */
>       VOUT_CONTROL_CHANGE_INTERLACE,      /* boolean */
>   
>       VOUT_CONTROL_MOUSE_STATE,           /* vlc_mouse_t */
> @@ -39,13 +38,11 @@ typedef struct {
>   
>       union {
>           bool    boolean;
> -        char    *string;
>           vlc_mouse_t mouse;
>       };
>   } vout_control_cmd_t;
>   
>   void vout_control_cmd_Init(vout_control_cmd_t *, int type);
> -void vout_control_cmd_Clean(vout_control_cmd_t *);
>   
>   typedef struct {
>       vlc_mutex_t lock;
> @@ -70,7 +67,6 @@ 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_PushBool(vout_control_t *, int type, bool boolean);
> -void vout_control_PushString(vout_control_t *, int type, const char *string);
>   void vout_control_Wake(vout_control_t *);
>   void vout_control_Hold(vout_control_t *);
>   void vout_control_Release(vout_control_t *);
> diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
> index 6cf7a426673..c934430dae8 100644
> --- a/src/video_output/video_output.c
> +++ b/src/video_output/video_output.c
> @@ -172,6 +172,8 @@ typedef struct vout_thread_sys_t
>       /* Video filter2 chain */
>       struct {
>           vlc_mutex_t     lock;
> +        bool            filters_changed;
> +        char            *new_filters;
>           char            *configuration;
>           video_format_t    src_fmt;
>           vlc_video_context *src_vctx;
> @@ -740,8 +742,22 @@ void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
>   {
>       vout_thread_sys_t *sys = VOUT_THREAD_TO_SYS(vout);
>       assert(!sys->dummy);
> -    vout_control_PushString(&sys->control, VOUT_CONTROL_CHANGE_FILTERS,
> -                            filters);
> +    vlc_mutex_lock(&sys->filter.lock);
> +    if (sys->filter.new_filters)
> +    {
> +        if (filters == NULL || strcmp(sys->filter.new_filters, filters))
> +        {
> +            free(sys->filter.new_filters);
> +            sys->filter.new_filters = filters ? strdup(filters) : NULL;
> +            sys->filter.filters_changed = true;
> +        }
> +    }
> +    else if (filters != NULL)
> +    {
> +        sys->filter.new_filters = strdup(filters);
> +        sys->filter.filters_changed = true;
> +    }
> +    vlc_mutex_unlock(&sys->filter.lock);
>   }
>   
>   void vout_ControlChangeInterlacing(vout_thread_t *vout, bool set)
> @@ -1443,6 +1459,11 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
>   
>       assert(sys->clock);
>   
> +    vlc_mutex_lock(&sys->filter.lock);
> +    if (sys->filter.filters_changed)
> +        ThreadChangeFilters(vout, sys->filter.new_filters, NULL, true);
> +    vlc_mutex_unlock(&sys->filter.lock);
> +
>       if (first)
>           if (ThreadDisplayPreparePicture(vout, true, frame_by_frame, &paused)) /* FIXME not sure it is ok */
>               return VLC_EGENERIC;
> @@ -1863,9 +1884,6 @@ static void *Thread(void *object)
>               switch(cmd.type) {
>                   case VOUT_CONTROL_TERMINATE:
>                       return NULL; /* no need to clean &cmd */
> -                case VOUT_CONTROL_CHANGE_FILTERS:
> -                    ThreadChangeFilters(vout, cmd.string, NULL, false);
> -                    break;
>                   case VOUT_CONTROL_CHANGE_INTERLACE:
>                       ThreadChangeFilters(vout, NULL, &cmd.boolean, false);
>                       break;
> @@ -1873,7 +1891,6 @@ static void *Thread(void *object)
>                       ThreadProcessMouseState(vout, &cmd.mouse);
>                       break;
>               }
> -            vout_control_cmd_Clean(&cmd);
>           }
>   
>           deadline = VLC_TICK_INVALID;
> -- 
> 2.26.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list