[vlc-commits] aout: recycle output and pipeline if possible

Rémi Denis-Courmont git at videolan.org
Wed Aug 10 18:50:40 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Aug 10 19:48:44 2011 +0300| [c6b07475da8c3df6b6d1018b254aead67b29cc83] | committer: Rémi Denis-Courmont

aout: recycle output and pipeline if possible

The decoder thread drains the output at end of stream. So there is
always an underflow between consequent audio inputs.
Thus this does not provide gap-less audio as is.

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

 src/audio_output/aout_internal.h |    1 +
 src/audio_output/common.c        |    4 ++++
 src/audio_output/dec.c           |   38 ++++++++++++++++++++++++++++++++++----
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index fc1c7c2..928aa39 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -206,6 +206,7 @@ bool aout_DecIsEmpty(audio_output_t *);
 
 void aout_InputRequestRestart(audio_output_t *);
 void aout_RequestRestart(audio_output_t *);
+void aout_Shutdown (audio_output_t *);
 
 /* Audio output locking */
 
diff --git a/src/audio_output/common.c b/src/audio_output/common.c
index d160ad0..a7a4f19 100644
--- a/src/audio_output/common.c
+++ b/src/audio_output/common.c
@@ -170,6 +170,10 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
 
 void aout_Destroy (audio_output_t *aout)
 {
+    aout_owner_t *owner = aout_owner (aout);
+
+    if (owner->module != NULL)
+        aout_Shutdown (aout);
     vlc_object_release (aout);
 }
 
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 069d02b..fb7340f 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -81,9 +81,27 @@ int aout_DecNew( audio_output_t *p_aout,
     }
 
     aout_owner_t *owner = aout_owner(p_aout);
+
+    /* Calling decoder is responsible for serializing aout_DecNew() and
+     * aout_DecDelete(). So no need to lock to _read_ those properties. */
+    if (owner->module != NULL) /* <- output exists */
+    {   /* Check if we can recycle the existing output and pipelines */
+        if (AOUT_FMTS_IDENTICAL(&owner->input_format, p_format))
+            return 0;
+
+        /* TODO? If the new input format is closer to the output format than
+         * the old input format was, then the output could be recycled. The
+         * input pipeline however would need to be restarted. */
+
+        /* No recycling: delete everything and restart from scratch */
+        aout_Shutdown (p_aout);
+    }
+
     int ret = -1;
 
+    /* TODO: reduce lock scope depending on decoder's real need */
     aout_lock( p_aout );
+    assert (owner->module == NULL);
 
     /* Create the audio output stream */
     var_Destroy( p_aout, "audio-device" );
@@ -119,10 +137,10 @@ error:
     return ret;
 }
 
-/*****************************************************************************
- * aout_DecDelete : delete a decoder
- *****************************************************************************/
-void aout_DecDelete( audio_output_t * p_aout )
+/**
+ * Stops all plugins involved in the audio output.
+ */
+void aout_Shutdown (audio_output_t *p_aout)
 {
     aout_owner_t *owner = aout_owner (p_aout);
     aout_input_t *input;
@@ -150,6 +168,18 @@ void aout_DecDelete( audio_output_t * p_aout )
     free (input);
 }
 
+/**
+ * Stops the decoded audio input.
+ * @note Due to output recycling, this function is esssentially a stub.
+ */
+void aout_DecDelete (audio_output_t *aout)
+{
+    aout_owner_t *owner = aout_owner (aout);
+
+    assert (owner->module != NULL);
+    (void) owner;
+}
+
 #define AOUT_RESTART_OUTPUT 1
 #define AOUT_RESTART_INPUT  2
 static void aout_CheckRestart (audio_output_t *aout)



More information about the vlc-commits mailing list