[vlc-commits] vout/control: add Hold/Release helpers

Rémi Denis-Courmont git at videolan.org
Sun Jan 27 22:10:01 CET 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 27 15:29:57 2019 +0200| [eb4c341c190a05eb9b47e6c35186ca34a17f1b36] | committer: Rémi Denis-Courmont

vout/control: add Hold/Release helpers

Holding waits for the control loop to go idle, then preempts it.
Release resumes it.

This allows running code in synchronization with the video output
thread, without actually running on the video output thread. In
particular, this does not require any memory allocation, unlike pushing
a control request.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eb4c341c190a05eb9b47e6c35186ca34a17f1b36
---

 src/video_output/control.c | 18 +++++++++++++++++-
 src/video_output/control.h |  3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index c62d80b303..d3bc3666a7 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -163,6 +163,19 @@ void vout_control_PushString(vout_control_t *ctrl, int type, const char *string)
     vout_control_Push(ctrl, &cmd);
 }
 
+void vout_control_Hold(vout_control_t *ctrl)
+{
+    vlc_mutex_lock(&ctrl->lock);
+    while (!ctrl->is_waiting && !ctrl->is_dead)
+        vlc_cond_wait(&ctrl->wait_acknowledge, &ctrl->lock);
+    /* TODO: unlock to let other threads queue requests */
+}
+
+void vout_control_Release(vout_control_t *ctrl)
+{
+    vlc_mutex_unlock(&ctrl->lock);
+}
+
 int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
                      vlc_tick_t deadline)
 {
@@ -172,8 +185,11 @@ int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
         vlc_cond_broadcast(&ctrl->wait_acknowledge);
 
         /* Spurious wakeups are perfectly fine */
-        if (deadline != VLC_TICK_INVALID && ctrl->can_sleep)
+        if (deadline != VLC_TICK_INVALID && ctrl->can_sleep) {
+            ctrl->is_waiting = true;
             vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock, deadline);
+            ctrl->is_waiting = false;
+        }
     }
 
     bool has_cmd;
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 989ba9dd9a..ffeaf076f7 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -106,6 +106,7 @@ typedef struct {
     bool is_dead;
     bool can_sleep;
     bool is_processing;
+    bool is_waiting;
     DECL_ARRAY(vout_control_cmd_t) cmd;
 } vout_control_t;
 
@@ -124,6 +125,8 @@ void vout_control_PushTime(vout_control_t *, int type, vlc_tick_t time);
 void vout_control_PushPair(vout_control_t *, int type, int a, int b);
 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 *);
 
 /* control inside of the vout thread */
 int vout_control_Pop(vout_control_t *, vout_control_cmd_t *, vlc_tick_t deadline);



More information about the vlc-commits mailing list