[vlc-devel] [PATCHv2 3/9] aout: use the vlc_audio_meter API
Thomas Guillem
thomas at gllm.fr
Wed Aug 19 21:25:57 CEST 2020
And expose internally:
- aout_AddMeterPlugin()
- aout_RemoveMeterPlugin().
This will allow the player to add and remove "audio meter" plugins.
---
src/audio_output/aout_internal.h | 11 ++++++++++-
src/audio_output/dec.c | 13 +++++++++++++
src/audio_output/output.c | 19 +++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 78db9857d31..b7569454dcf 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -26,6 +26,8 @@
# include <stdatomic.h>
# include <vlc_atomic.h>
+# include <vlc_filter.h>
+# include <vlc_list.h>
# include <vlc_viewpoint.h>
# include "../clock/clock.h"
@@ -94,6 +96,8 @@ typedef struct
aout_filters_cfg_t filters_cfg;
+ struct vlc_audio_meter meter;
+
atomic_uint buffers_lost;
atomic_uint buffers_played;
atomic_uchar restart;
@@ -133,6 +137,12 @@ void aout_Destroy (audio_output_t *);
int aout_OutputNew(audio_output_t *);
void aout_OutputDelete( audio_output_t * p_aout );
+vlc_audio_meter_plugin *
+aout_AddMeterPlugin(audio_output_t *aout, const char *chain,
+ const struct vlc_audio_meter_events *cbs, void *data);
+
+void
+aout_RemoveMeterPlugin(audio_output_t *aout, vlc_audio_meter_plugin *plugin);
/* From common.c : */
void aout_FormatsPrint(vlc_object_t *, const char *,
@@ -198,5 +208,4 @@ filter_t *aout_filter_Create(vlc_object_t *obj, const filter_owner_t *restrict o
const audio_sample_format_t *outfmt,
config_chain_t *cfg, bool const_fmt);
-
#endif /* !LIBVLC_AOUT_INTERNAL_H */
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 7aba7ae8dbc..993e3d6eeaa 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -104,6 +104,8 @@ int aout_DecNew(audio_output_t *p_aout, const audio_sample_format_t *p_format,
goto error;
aout_volume_SetFormat (owner->volume, owner->mixer_format.i_format);
+ vlc_audio_meter_Reset(&owner->meter, &owner->mixer_format);
+
if (!owner->bitexact)
{
/* Create the audio filtering "input" pipeline */
@@ -114,6 +116,8 @@ int aout_DecNew(audio_output_t *p_aout, const audio_sample_format_t *p_format,
if (owner->filters == NULL)
{
aout_OutputDelete (p_aout);
+ vlc_audio_meter_Reset(&owner->meter, NULL);
+
error:
aout_volume_Delete (owner->volume);
owner->volume = NULL;
@@ -203,6 +207,10 @@ static int aout_CheckReady (audio_output_t *aout)
}
aout_FiltersSetClockDelay(owner->filters, owner->sync.delay);
}
+
+ vlc_audio_meter_Reset(&owner->meter,
+ owner->mixer_format.i_format ? &owner->mixer_format : NULL);
+
/* TODO: This would be a good time to call clean up any video output
* left over by an audio visualization:
input_resource_TerminatVout(MAGIC HERE); */
@@ -486,6 +494,9 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
play_date = system_now;
}
+
+ vlc_audio_meter_Process(&owner->meter, block, play_date);
+
/* Output */
owner->sync.discontinuity = false;
aout->play(aout, block, play_date);
@@ -544,6 +555,8 @@ void aout_DecFlush(audio_output_t *aout)
if (owner->mixer_format.i_format)
{
+ vlc_audio_meter_Flush(&owner->meter);
+
if (owner->filters)
aout_FiltersFlush (owner->filters);
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 260e27700ef..21baf7b419b 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -224,6 +224,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
vlc_viewpoint_init (&owner->vp.value);
atomic_init (&owner->vp.update, false);
vlc_atomic_rc_init(&owner->rc);
+ vlc_audio_meter_Init(&owner->meter, aout);
/* Audio output module callbacks */
var_Create (aout, "volume", VLC_VAR_FLOAT);
@@ -363,6 +364,7 @@ void aout_Destroy (audio_output_t *aout)
aout->volume_set = NULL;
aout->mute_set = NULL;
aout->device_select = NULL;
+ vlc_audio_meter_Destroy(&owner->meter);
vlc_mutex_unlock(&owner->lock);
var_DelCallback (aout, "viewpoint", ViewpointCallback, NULL);
@@ -802,3 +804,20 @@ static void aout_ChangeViewpoint(audio_output_t *aout,
atomic_store_explicit(&owner->vp.update, true, memory_order_relaxed);
vlc_mutex_unlock(&owner->vp.lock);
}
+
+vlc_audio_meter_plugin *
+aout_AddMeterPlugin(audio_output_t *aout, const char *chain,
+ const struct vlc_audio_meter_events *cbs, void *data)
+{
+ aout_owner_t *owner = aout_owner(aout);
+
+ return vlc_audio_meter_AddPlugin(&owner->meter, chain, cbs, data);
+}
+
+void
+aout_RemoveMeterPlugin(audio_output_t *aout, vlc_audio_meter_plugin *plugin)
+{
+ aout_owner_t *owner = aout_owner(aout);
+
+ vlc_audio_meter_RemovePlugin(&owner->meter, plugin);
+}
--
2.28.0
More information about the vlc-devel
mailing list