[vlc-commits] filter: add aout_FiltersDrain and aout_FiltersFlush

Thomas Guillem git at videolan.org
Tue Nov 3 16:26:44 CET 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Nov  3 15:28:21 2015 +0100| [068958cf76fe80b06171061301845ea178a7e9c2] | committer: Thomas Guillem

filter: add aout_FiltersDrain and aout_FiltersFlush

These function will drain/flush the chain of filters of the audio output.

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

 include/vlc_aout.h         |    2 ++
 src/audio_output/filters.c |   83 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym         |    2 ++
 3 files changed, 87 insertions(+)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 630be72..b6e3ea6 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -336,6 +336,8 @@ VLC_API void aout_FiltersDelete(vlc_object_t *, aout_filters_t *);
         aout_FiltersDelete(VLC_OBJECT(o),f)
 VLC_API bool aout_FiltersAdjustResampling(aout_filters_t *, int);
 VLC_API block_t *aout_FiltersPlay(aout_filters_t *, block_t *, int rate);
+VLC_API block_t *aout_FiltersDrain(aout_filters_t *);
+VLC_API void     aout_FiltersFlush(aout_filters_t *);
 
 VLC_API vout_thread_t * aout_filter_RequestVout( filter_t *, vout_thread_t *p_vout, video_format_t *p_fmt );
 
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 74c5a6a..8bb8630 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -269,6 +269,49 @@ static block_t *aout_FiltersPipelinePlay(filter_t *const *filters,
     return block;
 }
 
+
+/**
+ * Drain the chain of filters.
+ */
+static block_t *aout_FiltersPipelineDrain(filter_t *const *filters,
+                                          unsigned count)
+{
+    block_t *chain = NULL;
+
+    for (unsigned i = 0; i < count; i++)
+    {
+        filter_t *filter = filters[i];
+
+        block_t *block = filter_DrainAudio (filter);
+        if (block)
+        {
+            /* If there is a drained block, filter it through the following
+             * chain of filters  */
+            if (i + 1 < count)
+                block = aout_FiltersPipelinePlay (&filters[i + 1],
+                                                  count - i - 1, block);
+            if (block)
+                block_ChainAppend (&chain, block);
+        }
+    }
+
+    if (chain)
+        return block_ChainGather(chain);
+    else
+        return NULL;
+}
+
+/**
+ * Flush the chain of filters.
+ */
+static void aout_FiltersPipelineFlush(filter_t *const *filters,
+                                      unsigned count)
+{
+    for (unsigned i = 0; i < count; i++)
+        filter_FlushAudio (filters[i]);
+}
+
+
 #define AOUT_MAX_FILTERS 10
 
 struct aout_filters
@@ -549,3 +592,43 @@ drop:
     block_Release (block);
     return NULL;
 }
+
+block_t *aout_FiltersDrain (aout_filters_t *filters)
+{
+    /* Drain the filters pipeline */
+    block_t *block = aout_FiltersPipelineDrain (filters->tab, filters->count);
+
+    if (filters->resampler != NULL)
+    {
+        block_t *chain = NULL;
+
+        filters->resampler->fmt_in.audio.i_rate += filters->resampling;
+
+        if (block)
+        {
+            /* Resample the drained block from the filters pipeline */
+            block = aout_FiltersPipelinePlay (&filters->resampler, 1, block);
+            if (block)
+                block_ChainAppend (&chain, block);
+        }
+
+        /* Drain the resampler filter */
+        block = aout_FiltersPipelineDrain (&filters->resampler, 1);
+        if (block)
+            block_ChainAppend (&chain, block);
+
+        filters->resampler->fmt_in.audio.i_rate -= filters->resampling;
+
+        return chain ? block_ChainGather (chain) : NULL;
+    }
+    else
+        return block;
+}
+
+void aout_FiltersFlush (aout_filters_t *filters)
+{
+    aout_FiltersPipelineFlush (filters->tab, filters->count);
+
+    if (filters->resampler != NULL)
+        aout_FiltersPipelineFlush (&filters->resampler, 1);
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 185f02e..a9e2636 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -22,6 +22,8 @@ aout_DeviceSet
 aout_DevicesList
 aout_FiltersNew
 aout_FiltersDelete
+aout_FiltersDrain
+aout_FiltersFlush
 aout_FiltersPlay
 aout_FiltersAdjustResampling
 block_Alloc



More information about the vlc-commits mailing list