[vlc-devel] [PATCH 8/8] aout: pass viewpoint via Async API

Thomas Guillem thomas at gllm.fr
Fri Mar 8 17:24:46 CET 2019


The viewpoint async cmd is prepended instead of appended since it generally
need to be applied the earliest possible.
---
 src/audio_output/aout_internal.h |  6 ++++--
 src/audio_output/async.c         | 16 ++++++++++++++++
 src/audio_output/output.c        | 17 +----------------
 src/audio_output/stream.c        | 16 +++++++++++-----
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index ccdbd967b0..e5b6d427a3 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -68,8 +68,7 @@ typedef struct
 
     struct
     {
-        atomic_bool update;
-        vlc_mutex_t lock;
+        bool update;
         vlc_viewpoint_t value;
     } vp;
 
@@ -156,6 +155,8 @@ void aout_StreamFlush(audio_output_t *, bool wait);
 void aout_StreamRestart (audio_output_t *, unsigned);
 void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t system_ts,
                           vlc_tick_t audio_ts);
+void aout_StreamChangeViewpoint(audio_output_t *aout,
+                                const vlc_viewpoint_t *viewpoint);
 
 static inline void aout_SetWavePhysicalChannels(audio_sample_format_t *fmt)
 {
@@ -182,6 +183,7 @@ void aout_Flush(audio_output_t *, bool wait);
 void aout_ChangePause(audio_output_t *, bool paused, vlc_tick_t date);
 void aout_ChangeRate(audio_output_t *, float rate);
 void aout_ChangeDelay(audio_output_t *, vlc_tick_t delay);
+void aout_ChangeViewpoint(audio_output_t *, const vlc_viewpoint_t *viewpoint);
 
 static inline void aout_InputRequestRestart(audio_output_t *aout)
 {
diff --git a/src/audio_output/async.c b/src/audio_output/async.c
index bd98955978..dfe3771454 100644
--- a/src/audio_output/async.c
+++ b/src/audio_output/async.c
@@ -44,6 +44,7 @@ enum aout_async_cmd_type
     AOUT_ASYNC_CMD_CHANGE_PAUSE,
     AOUT_ASYNC_CMD_CHANGE_RATE,
     AOUT_ASYNC_CMD_CHANGE_DELAY,
+    AOUT_ASYNC_CMD_CHANGE_VIEWPOINT,
     AOUT_ASYNC_CMD_CLOSE,
 };
 
@@ -76,6 +77,9 @@ union aout_async_cmd_arg
 
     /* AOUT_ASYNC_CMD_CHANGE_DELAY */
     vlc_tick_t delay;
+
+    /* AOUT_ASYNC_CMD_CHANGE_VIEWPOINT */
+    vlc_viewpoint_t viewpoint;
 };
 
 struct aout_async_cmd
@@ -138,6 +142,9 @@ aout_Thread(void *data)
             case AOUT_ASYNC_CMD_CHANGE_DELAY:
                 aout_StreamChangeDelay(aout, arg->delay);
                 break;
+            case AOUT_ASYNC_CMD_CHANGE_VIEWPOINT:
+                aout_StreamChangeViewpoint(aout, &arg->viewpoint);
+                break;
             case AOUT_ASYNC_CMD_CLOSE:
                 stop = true;
                 break;
@@ -265,6 +272,15 @@ aout_ChangeDelay(audio_output_t *aout, vlc_tick_t delay)
         }, false, false);
 }
 
+void
+aout_ChangeViewpoint(audio_output_t *aout, const vlc_viewpoint_t *viewpoint)
+{
+    aout_AsyncRun(aout, AOUT_ASYNC_CMD_CHANGE_VIEWPOINT,
+        (union aout_async_cmd_arg) {
+            .viewpoint = *viewpoint
+        }, false, true);
+}
+
 int
 aout_AsyncInit(audio_output_t *aout)
 {
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index c032ff8c08..7c7e223235 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -199,8 +199,6 @@ static int StereoModeCallback (vlc_object_t *obj, const char *varname,
     return 0;
 }
 
-static void aout_ChangeViewpoint(audio_output_t *, const vlc_viewpoint_t *);
-
 static int ViewpointCallback (vlc_object_t *obj, const char *var,
                               vlc_value_t prev, vlc_value_t cur, void *data)
 {
@@ -247,9 +245,8 @@ audio_output_t *aout_New (vlc_object_t *parent)
 
     vlc_mutex_init (&owner->lock);
     vlc_mutex_init (&owner->dev.lock);
-    vlc_mutex_init (&owner->vp.lock);
     vlc_viewpoint_init (&owner->vp.value);
-    atomic_init (&owner->vp.update, false);
+    owner->vp.update = false;
 
     vlc_object_set_destructor (aout, aout_Destructor);
 
@@ -412,7 +409,6 @@ static void aout_Destructor (vlc_object_t *obj)
         free (dev);
     }
 
-    vlc_mutex_destroy (&owner->vp.lock);
     vlc_mutex_destroy (&owner->lock);
 }
 
@@ -773,14 +769,3 @@ error:
     free(tabid);
     return -1;
 }
-
-static void aout_ChangeViewpoint(audio_output_t *aout,
-                                 const vlc_viewpoint_t *p_viewpoint)
-{
-    aout_owner_t *owner = aout_owner(aout);
-
-    vlc_mutex_lock(&owner->vp.lock);
-    owner->vp.value = *p_viewpoint;
-    atomic_store_explicit(&owner->vp.update, true, memory_order_relaxed);
-    vlc_mutex_unlock(&owner->vp.lock);
-}
diff --git a/src/audio_output/stream.c b/src/audio_output/stream.c
index 0dae4d3116..207a8c48f2 100644
--- a/src/audio_output/stream.c
+++ b/src/audio_output/stream.c
@@ -109,7 +109,7 @@ error:
 
     atomic_init (&owner->buffers_lost, 0);
     atomic_init (&owner->buffers_played, 0);
-    atomic_store_explicit(&owner->vp.update, true, memory_order_relaxed);
+    owner->vp.update = true;
     return 0;
 }
 
@@ -197,6 +197,14 @@ void aout_StreamRestart (audio_output_t *aout, unsigned mode)
     msg_Dbg (aout, "restart requested (%u)", mode);
 }
 
+void aout_StreamChangeViewpoint(audio_output_t *aout,
+                                const vlc_viewpoint_t *viewpoint)
+{
+    aout_owner_t *owner = aout_owner(aout);
+
+    owner->vp.value = *viewpoint;
+    owner->vp.update = true;
+}
 /*
  * Buffer management
  */
@@ -404,12 +412,10 @@ int aout_StreamPlay(audio_output_t *aout, block_t *block)
         owner->original_pts = VLC_TICK_INVALID;
     }
 
-    if (atomic_load_explicit(&owner->vp.update, memory_order_relaxed))
+    if (owner->vp.update)
     {
-        vlc_mutex_lock (&owner->vp.lock);
         aout_FiltersChangeViewpoint (owner->filters, &owner->vp.value);
-        atomic_store_explicit(&owner->vp.update, false, memory_order_relaxed);
-        vlc_mutex_unlock (&owner->vp.lock);
+        owner->vp.update = false;
     }
 
     if (owner->original_pts == VLC_TICK_INVALID)
-- 
2.20.1



More information about the vlc-devel mailing list