Volume handling in 2.1.0 onwards

This forum is about all development around libVLC.
sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Volume handling in 2.1.0 onwards

Postby sherington » 19 Sep 2012 19:39

Hello,

With vlc 2.0.x, when you invoke libvlc_audio_get_volume it will seemingly return a valid value whether an audio output is playing or not.

With vlc 2.1.x, when you invoke libvlc_audio_get_volume it will return -1 (error) until after the audio output has started, which will be some short time after the asynchronous libvlc_media_player_play function is invoked.

So I am wondering what is the right way to handle querying the volume via libvlc_audio_get_volume now? I can't invoke it immediately after invoking play (it's too soon), and I shouldn't do a short sleep() before invoking it, so I think I should wait until I receive a (new) event telling me the audio output has been created (much like the existing event for video output created).

The same applies to setting the volume - so even if instead I manage my own volume setting rather than querying libvlc, I still need to know the right moment (after the audio output is created) to invoke libvlc_audio_set_volume.

Such an event does not exist yet, if this is the right thing to do I am happy to try and contribute a patch for it.

Is this correct or am I missing something?

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Rémi Denis-Courmont » 19 Sep 2012 22:48

Internally, there is an event to report the volume status, but there is indeed no code to pass it to the application.

There should already be an "aout" event though.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Volume handling in 2.1.0 onwards

Postby sherington » 20 Sep 2012 08:32

Internally, there is an event to report the volume status, but there is indeed no code to pass it to the application.
I have seen aout_VolumeReport(), which sets the "volume" variable on the aout - is this what you are referring to here? First I was thinking to add a variable callback to listen for changes to this variable, but of course the aout does not exist yet so I need to do something else.
There should already be an "aout" event though.
Are you referring to input-events? I was thinking to translate INPUT_EVENT_AOUT to a new Libvlc_MediaPlayerAout event, in the same way as is currently done for INPUT_EVENT_VOUT. Existing code from lib/media_player.c:

Code: Select all

else if( newval.i_int == INPUT_EVENT_VOUT ) { [Some code was removed from here to keep it short] event.type = libvlc_MediaPlayerVout; event.u.media_player_vout.new_count = i_vout; libvlc_event_send( p_mi->p_event_manager, &event ); }
This part of it would be quite simple to implement in a patch, but...

I suppose it would be more useful (especially if external processes can change the volume?) if there was also a Libvlc_VolumeChanged event? And it would fire *any* time the volume changed, not just when the aout was created?

bunjee
Blank Cone
Blank Cone
Posts: 33
Joined: 01 Feb 2012 20:51
Contact:

Re: Volume handling in 2.1.0 onwards

Postby bunjee » 26 Sep 2013 15:32

Greetings guys :-D.

I've just updated to the 2.1.0 Sdk. The new volume rocks, congrats to the team.

I too have issue setting the volume before playback.

libvlc_audio_set_volume returns -1 until some point after playback started.

I haven't found the event to get notified when volume is ready to be set.

Sherington, have you found a workaround for this ?

Thanks.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Volume handling in 2.1.0 onwards

Postby sherington » 26 Sep 2013 16:31

Sherington, have you found a workaround for this ?
No.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Jean-Baptiste Kempf » 27 Sep 2013 01:22

Depends on the aout.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Volume handling in 2.1.0 onwards

Postby sherington » 27 Sep 2013 08:13

Depends on the aout.
From what I have seen, there is simply no way through libvlc to successfully set/get the volume for a media player before an aout has been created (which is some indterminant time after you play the media). It will always return an error (this is clear from the libvlc media player code actually).

So a reasonable approach would be to wait for a notification that an aout has been created, then get/set the volume - similar to the existing "vout has been created" event. The problem with that is there is no such event exposed at the moment.

I wrote a small libvlc patch to expose that event and it seems to work. Whether it's generally useful or not, or whether this is a "wrong" approach for this issue or not, I don't know.

Related to that is that there is no way at the moment to be notified that the volume has changed (by some other means). As was stated earlier in this thread internally a volume change notification *is* made, but exposing that through libvlc seems trickier to me and I have made no progress in that particular regard.

bunjee
Blank Cone
Blank Cone
Posts: 33
Joined: 01 Feb 2012 20:51
Contact:

Re: Volume handling in 2.1.0 onwards

Postby bunjee » 27 Sep 2013 12:23

On my side I previously reimplemented my video renderer.

The workaround I found is to initialize the volume right after the first frame unlock callback. Yes that's dirty :-).

I understand libVLC now supports multiple audio devices and that's great !

From my perspective there should be a way to set a "master volume" at any moment.

I'm curious how VLC player actually handles that for its volume slider.

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: Volume handling in 2.1.0 onwards

Postby mangokm40 » 27 Sep 2013 14:24

Thanks Sherington. This thread saved me a lot of time when I was trying to upgrade my code yesterday. :)

Thanks for the idea Bunjee. The frame unlock callback is better than a Win32 timer (what I did yesterday). :)

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Rémi Denis-Courmont » 27 Sep 2013 17:03

VLC uses basically the same underlying code path as LibVLC.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

bunjee
Blank Cone
Blank Cone
Posts: 33
Joined: 01 Feb 2012 20:51
Contact:

Re: Volume handling in 2.1.0 onwards

Postby bunjee » 25 Nov 2013 20:59

From what I have seen, there is simply no way through libvlc to successfully set/get the volume for a media player before an aout has been created (which is some indterminant time after you play the media). It will always return an error (this is clear from the libvlc media player code actually).
This is still true on 2.1.1.

Anyone made progress on this ?

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Rémi Denis-Courmont » 25 Nov 2013 22:17

The media player needs to create the audio output earlier, just like the playlist does. It should not be very hard to fix.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

bunjee
Blank Cone
Blank Cone
Posts: 33
Joined: 01 Feb 2012 20:51
Contact:

Re: Volume handling in 2.1.0 onwards

Postby bunjee » 26 Nov 2013 09:48

You're talking about changes to be made on libVLC side ?

If that's the case we should open a ticket on Trac ♥.

itzalive
New Cone
New Cone
Posts: 1
Joined: 12 Feb 2014 03:24

Re: Volume handling in 2.1.0 onwards

Postby itzalive » 12 Feb 2014 03:32

Has anyone got a good solution to this yet?

I'm trying to start videos muted but not being able to set audio properties before the video is playing is causing problems.

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Rémi Denis-Courmont » 12 Feb 2014 17:57

No patch to be seen so far.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Volume handling in 2.1.0 onwards

Postby sherington » 24 Jan 2015 16:12

I've been looking at this again with 2.2.0-git.

What I observe happening now (Linux, using Pulse Audio, I can't speak for other platforms) is that it *is* now possible to get/set the volume on a media player *before* playback begins.

But if you invoke libvlc_media_player_stop, then from that point onwards libvlc_audio_get_volume will return -1 and libvlc_audio_set_volume will no effect until you invoke libvlc_media_player_play - at which point the volume will be whatever was set before you stopped.

So in short you can't stop the media, change the volume, play the media and have the desired volume be applied, it will be whatever it was prior to stop.

I don't know if it's a problem, or if it's by design, but that's what it does at the moment.

Rémi Denis-Courmont
Developer
Developer
Posts: 15265
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Volume handling in 2.1.0 onwards

Postby Rémi Denis-Courmont » 25 Jan 2015 00:56

I think it affects all platforms but I have not tested, but this misfeature is really specific to stop. Maybe only the video should be terminated at stop, not the audio [output].
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Der_Knob
New Cone
New Cone
Posts: 3
Joined: 13 Dec 2009 22:21

Re: Volume handling in 2.1.0 onwards

Postby Der_Knob » 15 Jun 2015 09:58

I found a solution in the nVLC comments:

http://www.codeproject.com/Articles/109 ... x4967240xx

Option b is working for me.
You may need to adapt it to your programming language...


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 10 guests