Page 1 of 1

Getting an audio activity flag from LibVLC

Posted: 26 Jul 2020 16:25
by Nothsa
I am writing a LibVLCSharp based Windows application for listening to multiple voice audio streams simultaneously. Each stream will carry a single 2-way radio or intercom channel, and may be silent for minutes or hours at a time. The application can monitor a dozen or more channels, and I would like to visually indicate which channels are currently active.

Ideally I would like to poll the audio level of each stream, so that I may detect audio activity, (100-500ms intervals should be sufficient). The maximum amplitude of the last audio frame, or a simple flag indicating amplitude above a threshold is all that I require.

There doesn't appear to be a way to achieve this using vanilla LibVLC, and my initial thought was to write a custom audio filter to do this. After some research, it's not clear to me whether this approach would work.

There are two areas which I'm hoping someone with more VLC experience can help me with:

  • Enabling a custom audio filter
    I've had no success enabling any of the supplied audio filters using LibVLC, either by passing an argument to libvlc_new(), or via libvlc_media_add_option(); however, I can successfully use both methods with VLC. I have recently found this comment by Rémi Denis-Courmon, which may indicate why:
    https://forum.videolan.org/viewtopic.php?t=143056
    "This is explicitly not supported by the libvlc_new() documentation. LibVLC controls audio filters (and many other things) internally."

    Can anyone tell me how I control LibVLC audio filter selection, and if there is any way for me to specify a custom filter?
  • Passing data between the application and the custom filter
    Is there a way for an application to access data within a custom module via LibVLC, (e.g. read the value of my custom filter's audio activity flag)?
    If this is not possible, then I may be able to use IPC to send the activity flag from the filter to my application; however, with multiple instances of the filter running, I would need a way for each filter to uniquely identify itself to the application. To this end:
    Has the filter got access to the MRL, or is there a way to pass data from the application to the audio filter, (e.g. a UUID)?
Of course, I may well be going about this in completely the wrong way. If you know of a better way for my application to discover audio stream activity, please let me know.

Re: Getting an audio activity flag from LibVLC

Posted: 27 Jul 2020 09:30
by mfkl
Hi,

Not sure about the exact libvlc string syntax for audio filters but it's certainly doable. Can you share the code you tried?

Have you seen https://code.videolan.org/mfkl/libvlcsh ... Program.cs?

Re: Getting an audio activity flag from LibVLC

Posted: 29 Jul 2020 15:33
by Jean-Baptiste Kempf
You can use a custom filter, but it might break when updating VLC. So it is at your own risk.

Re: Getting an audio activity flag from LibVLC

Posted: 21 Sep 2020 11:03
by silentbrown
I've been trying to do something very similar, and keep running into walls.
I'm playing media with audio and video normally output to the regular windows display/sound device. Here's what I've tried so far.

#1: Using libvlc_audio_set_callbacks to read and process the audio data.
BUT, this stops the audio actually playing :(

#2: Using smem and duplicate modules to get a copy of the audio data.
Audio now keeps playing, BUT audio muting with libvlc_audio_set_mute now stops working. :(

#3: Using smem and duplicate, but setting/clearing the callback as a way of muting the audio
Audio still doesn't mute. I think changing the callback when media is already playing has no effect.

I think my only option now is to use #1, but manually play the audio out using WAVEOUT. A/V sync is likely to be a problem....

Any other suggestions?

Re: Getting an audio activity flag from LibVLC

Posted: 21 Sep 2020 15:42
by mfkl
#1: Using libvlc_audio_set_callbacks to read and process the audio data.
BUT, this stops the audio actually playing
It stops playing because it is on you to forward the decoded audio data to a device, as the documentation states.

Re: Getting an audio activity flag from LibVLC

Posted: 21 Sep 2020 15:52
by silentbrown
Sure, I know that now. What about libvlc_audio_set_mute with smem and duplicate, though?

There's no log message or error return - but the audio keeps on coming out.

Re: Getting an audio activity flag from LibVLC

Posted: 21 Sep 2020 19:43
by Rémi Denis-Courmont
You can't have the cake and eat it. If you use stream output, then the normal VLC audio decoding and output are no longer used. So yeah, audio controls won't work.