Skip to content

HTML5, GStreamer & PulseAudio

Jiří Janoušek edited this page Aug 2, 2015 · 2 revisions

Notes about HTML5 audio playback in WebKit2GTK+: A GStreamer backend is used to play music via HTML5 Audio and the GStreamer audio output stream is usually played via PulseAudio sound system.

  • Each HTML5 Audio element creates one GStreamer stream with an initial volume according to web app volume slider (Rdio).
  • TODO: Investigate: Rdio: When volume of the GStreamer stream is changed via pavucontrol, this change is not reflected in Rdio web app volume slider.

PulseAudio Flat Volumes

PulseAudio has a magical flat-volumes option: $ grep flat-volumes /etc/pulse/* ~/.pulse/* 2>/dev/null

From http://freedesktop.org/software/pulseaudio/doxygen/volume.html

There is no single well-defined meaning attached to the 100% volume for a sink input. In fact, it depends on the server configuration. With flat volumes enabled (the default in most Linux distributions), it means the maximum volume that the sound hardware is capable of, which is usually so high that you absolutely must not set sink input volume to 100% unless the the user explicitly requests that (note that usually you shouldn't set the volume anyway if the user doesn't explicitly request it, instead, let PulseAudio decide the volume for the sink input). With flat volumes disabled (the default in Ubuntu), the sink input volume is relative to the sink volume, so 100% sink input volume means that the sink input is played at the current sink volume level. In this case 100% is often a good default volume for a sink input, although you still should let PulseAudio decide the default volume. It is possible to figure out whether flat volume mode is in effect for a given sink by calling pa_context_get_sink_info_by_name().

Definitions

  • The input stream (also called application stream or per-app stream) is the audio stream produced by applications. One application can create one or more input streams. How the volume of these streams (also called application volume or per-app volume) is interpreted depends on flat-volumes configuration option (see bellow).
  • The output stream (also called master/system stream) is the audio stream produced by PulseAudio by mixing of input streams. Output stream is sent to a output device (sound card). The volume of the output stream (also called master or system volume) is interpreted relative to the maximal possible volume of the output device (sound card).

Flat volumes:

  • flat-volumes = yes (the default in most Linux distributions):

    • The volume of input streams is relative to the maximal hardware volume.
    • The volume of the output stream is set to the volume of the loudest input stream.
    • Example: You have set the volume of the output stream to 50%. An application creates a new input stream with volume 100% and playback starts. The new input stream sets the volume of the output stream to 100% of the maximal hardware volume, music plays with that volume and blows your ears off.
  • flat-volumes = no (the default in Ubuntu):

    • The volume of input streams is relative to the volume of the output stream.
    • The volume of the output stream is not affected by a volume of input streams.
    • Example: You have set the volume of the output stream to 50%. An application creates a new input stream with volume 100% and playback starts. The volume of the output stream is unchanged, music plays with volume 100% * 50% = 50% of the maximal hardware volume and your ears are safe.