Commit Graph

92 Commits

Author SHA1 Message Date
Jonas Dreßler
76bb9e3148 mixer-card: Allow setting profiles on card more than once
With the next commit, we'll start updating card profiles after the initial
creation of the GvcMixerCard, so get gvc_mixer_card_set_profiles() ready and
support replacing the list of profiles instead of only setting it a single
time.
2024-03-07 12:25:19 +01:00
Jonas Dreßler
f75ad37943 mixer-card: Return in set_profile() when profile is already set
When we change the card profile, there's two paths the current profile gets
updated after the change: From _pa_context_set_card_profile_by_index_cb()
and from update_card() in gvc-mixer-control.c. Both call
gvc_mixer_card_set_profile(), and if the profile change was initiated by us,
we might call set_profile() twice. Handle this a bit better in set_profile()
and early-return in case the current profile is already set.
2024-03-07 12:13:35 +01:00
Bastien Nocera
cc46b231cf mixer-control: Fix network devices not having icons
Fix Airplay devices not having icons in gnome-shell and
gnome-control-center.
2024-02-04 00:45:57 +01:00
Bastien Nocera
20b130c17f mixer-ui-device: Make debug for port available useful
The debug output would print the same value twice, instead of showing
the before and after values when setting the property.
2024-02-04 00:22:37 +01:00
Bastien Nocera
c72e46fc44 mixer-ui-device: Add debug for device type and icon name 2024-02-04 00:22:37 +01:00
Hui Wang
dbfbacc957 mixer-control: set max_volume to PA_VOLUME_NORM if no valid volume
Reproducers:
1. After a fresh install of Ubuntu 20.04, open a gnome-terminal
and press the Tab key, the system will output a bell notification
sound. Open gnome-control-center and check the sound page,
the output volume of 'System Sounds' is at 0, but the notification
sound is still output at max volume.

2. After a fresh install of Ubuntu 20.04, open gnome-control-center
directly, change to the sound page, the output volume of
'System Sounds' is at its max level. Click any 'Alert Sound' button
at the bottom of the page, the sound is output at max volume but
the UI slider for the output volume of 'System Sounds' changes to 0.
The notification sound can however still could be heard at max volume.

After a fresh install of the system, there is no saved entry for
"sink-input-by-media-role:event" in PulseAudio's module-stream-restore,
so libgvc will create a pa_ext_stream_restore_info in the
_pa_ext_stream_restore_read_cb(). When a notification sound stream
is sent to PA, PA will create an entry with name of
"sink-input-by-media-role:event" and save it to the database, but
volume_valid is false until gnome calls pa_ext_stream_restore_write().

So if users open the gnome-control-center before
pa_ext_stream_restore_write() is called, although there is an entry
named "sink-input-by-media-role:event" in the module-stream-restore,
the volume is not valid in that entry, and calling
pa_cvolume_max (&info->volume) will returns 0.

In this case, libgvc reports the max_volume is 0, but in PulseAudio,
the stream/sink-input volume is max (pa_sink_input_new() of the
sink-input.c).

Check if info->volume.channels is 0, which would mean the volume is
not valid in the entry, and set max_volume to PA_VOLUME_NORM like
_pa_ext_stream_restore_read_cb() does in this case.

Below is the PA log about the stream entry without a valid volume:
E: [pulseaudio] module-stream-restore.c: name=sink-input-by-media-role:event
E: [pulseaudio] module-stream-restore.c: device=(null) no
E: [pulseaudio] module-stream-restore.c: channel_map=(invalid)
E: [pulseaudio] module-stream-restore.c: volume=(invalid) no
E: [pulseaudio] module-stream-restore.c: mute=no no
2023-07-24 11:58:35 +02:00
Niels De Graef
000046e887 mixer-ui-device: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
2023-07-18 15:52:10 +00:00
Niels De Graef
ed28e761d5 mixer-stream: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
2023-07-18 15:52:10 +00:00
Niels De Graef
f6d6fe577f event-role: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
2023-07-18 15:52:10 +00:00
Niels De Graef
c73d7cf20c mixer-control: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
2023-07-18 15:52:10 +00:00
Niels De Graef
87a567eece mixer-card: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.

Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
2023-07-18 15:52:10 +00:00
Niels De Graef
9fa985ca25 mixer-control: Don't specify default c_marshaller
Apart from being less code, this actually gives us a tiny performance
improvement. Up until a few years ago, if you pass `NULL` as the
marshaller for a signal, GLib would fall back to
`g_cclosure_marshal_generic` which uses libffi to pack/unpack its
arguments. One could avoid this by specifying a more specific
marshaller which would then be used to immediately pack and unpack into
GValues with the correct type.

Lately however, as a way of optimizing signal emission (which can be
quite expensive), GLib added a possibility to set a `va_marshaller`,
which skips the unnecessary GValue packing and unpacking and just uses a
valist variant.

Since the performance difference is big enough, if the marshaller
argument is NULL, `g_signal_new()` will now check for the simple
marshallers (return type NONE and a single argument) and set both the
generic and the valist marshaller. In other words, less code for us with
behind-the-scenes optimizations.

In case you also want va_marshallers for more complex signals, you can
use `g_signal_set_va_marshaller()`.
2023-07-18 15:52:10 +00:00
Niels De Graef
dc5fd4f15e channel-map: Don't specify default c_marshaller
Apart from being less code, this actually gives us a tiny performance
improvement. Up until a few years ago, if you pass `NULL` as the
marshaller for a signal, GLib would fall back to
`g_cclosure_marshal_generic` which uses libffi to pack/unpack its
arguments. One could avoid this by specifying a more specific
marshaller which would then be used to immediately pack and unpack into
GValues with the correct type.

Lately however, as a way of optimizing signal emission (which can be
quite expensive), GLib added a possibility to set a `va_marshaller`,
which skips the unnecessary GValue packing and unpacking and just uses a
valist variant.

Since the performance difference is big enough, if the marshaller
argument is NULL, `g_signal_new()` will now check for the simple
marshallers (return type NONE and a single argument) and set both the
generic and the valist marshaller. In other words, less code for us with
behind-the-scenes optimizations.

In case you also want va_marshallers for more complex signals, you can
use `g_signal_set_va_marshaller()`.
2023-07-18 15:52:10 +00:00
Alberts Muktupāvels
cd76e021c2 mixer-control: remove unneeded cast
Stream id was changed to unsigned int in b7bce32944.
2023-07-18 15:37:06 +00:00
Alberts Muktupāvels
943998bc62 mixer-control: fix -Wsign-compare warning
Stream id property in GvcMixerUIDevice is unsigned int.
2023-07-18 15:37:06 +00:00
Bastien Nocera
90d6ddb7d1 mixer-control: Remove unused variable
subprojects/gvc/gvc-mixer-control.c:1325:22: warning: variable 'stream_port_count' set but not used [-Wunused-but-set-variable]
        gint         stream_port_count = 0;
                     ^
2023-07-18 17:30:01 +02:00
Bastien Nocera
20b8a46c39 ci: Build with clang as well 2023-07-18 16:34:32 +02:00
Marco Melorio
a1ae68ff11 mixer-control: Update default icons
As suggested in
https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/579#note_1617842, both the "System Sounds" icon and the default icon for streams are updated.
2023-07-18 14:15:15 +00:00
Pauli Virtanen
f3806ad5df mixer-control: remove objects properly when reconnecting to PA
GvcMixerCards are not removed when reconnecting to PA server, which
causes duplicate card entries to appear on PA restart.  Moreover, the
old GvcMixerCard instances have pointers to the old already freed
pa_context, resulting to use-after-free on operations.  Duplicate
entries are also caused by sink/source removal on reconnect not sending
right signals.

Make it clean up all Gvc objects as if we got subscribe remove events
for them all:

Use remove_sink/remove_source to remove sinks/sources so that the right
signals are emitted. Remove cards using remove_card, so that also they
get cleaned up. Remove also any leftover GvcMixerUIDevices.

Move cleanup of streams etc. before pa_context unref, so that we free
the objects referring the pa_context before freeing the context.

This fixes gnome-control-center crashing when PA server is restarted,
and one e.g. tries to do something that ends up in
gvc_mixer_card_change_profile such as selecting output device with port
in different profile.  It also fixes duplicate entries appearing in the
device lists on Pipewire restart (they don't appear with Pulseaudio
since PA device IDs don't change on restart).

It should also fix similar crashes in gnome-shell.
2023-07-13 20:45:00 +03:00
Pauli Virtanen
8e7a5a4c3e mixer-control: fix gvc_mixer_card_set_profiles API usage
In update_card, profile_list is incorrectly used also after its
ownership is transferred to the GvcMixerCard.  In practice, this causes
e.g. some profiles to go missing due to the list head being clobbered.

Fix this by calling gvc_mixer_card_set_profiles only after profiles_list
is no longer used for any other purpose.
2022-01-12 20:47:25 +02:00
Jonas Ådahl
c5ab6037f4 mixer-control: Rely on stream-id on device for cardless devices
Some devices don't have a card to match against, (e.g. network sinks),
which would make 'match_stream_with_devices()' get confused and log
warnings about missing card devices when trying to match streams with
devices.

Avoid this by marking a stream as 'in-possession' if there was already a
device with the stream ID set to it.

This fixes warning like

   (gnome-shell:3521215): Gvc-CRITICAL **: 10:57:07.155: gvc_mixer_card_get_index: assertion 'GVC_IS_MIXER_CARD (card)' failed
2021-03-15 11:07:22 +01:00
Jaroslav Kysela
7a621180b4 mixer-control: do not use port name string to select the headset ports
It is a bad idea to use the variable port name to check the port
type. Use only the new port type and availability group string
for the decision.

Also, select the ports by priority, if there multiple ports
with the similar type.
2020-09-17 15:31:07 +02:00
Hui Wang
960e01d957 mixer-control: consolidate port finding and setting with/without ucm
Recently Intel added a new audio driver in the Linux kernel, it is
called sof driver. This driver is needed on the laptops which
connects the digital mic to the PCH instead of the codec. To make the
sof driver work with pulseaudio, the ucm is mandatory.

With the ucm, the multi-function audio jack has different port names
in the pulseaudio from the one without ucm, these are the port names
with the ucm:
[In] Mic1: Digital Microphone
[In] Mic2: Headphones Stereo Microphone
[In] Headset: Headset Mono Microphone
[Out] Headphones: Headphones
[Out] Speaker: Speaker

To make the audio device selection work on the machines using the ucm,
the pulseaudio introduces a change to add 2 new members in the device
port structure from the PA_PROTOCOL_VERSION=34, with these 2 members'
help, we could consolidate the port finding and setting for both with
ucm and without ucm.

And this patch maintains the backward compatibility with the
PA_PROTOCOL_VERSION < 34.
2020-09-17 15:30:52 +02:00
Alberts Muktupāvels
0aab80a78c mixer-control: fix -Wsign-compare warnings
headset_card type is changed from int to guint32 to match uint32_t
used in PulseAudio's pa_card_info struct.
2020-04-09 13:53:36 +00:00
Alberts Muktupāvels
15980858d3 test-audio-device-selection: fix -Wdiscarded-qualifiers warnings 2020-04-09 13:53:36 +00:00
Alberts Muktupāvels
d8ba41f1d2 test-audio-device-selection: fix -Wsign-compare warning 2020-04-09 13:53:36 +00:00
Alberts Muktupāvels
342e366ede mixer-control: fix -Wswitch-enum warnings
Warnings introduced in ec5cf3e0de:
gvc-mixer-control.c:1457:9: warning: enumeration value ‘PA_SINK_INIT’ not handled in switch [-Wswitch-enum]
gvc-mixer-control.c:1457:9: warning: enumeration value ‘PA_SINK_UNLINKED’ not handled in switch [-Wswitch-enum]

Warning building with alsa:
gvc-mixer-control.c:2218:9: warning: enumeration value ‘GVC_HEADSET_PORT_CHOICE_NONE’ not handled in switch [-Wswitch-enum]
2020-04-09 13:53:36 +00:00
Alberts Muktupāvels
02cab4d3a3 build: ignore .dirstamp file 2020-04-09 13:53:36 +00:00
Carlos Garnacho
e2be83ee4a build: Bump pulseaudio dependency
We need 12.99.3 in order to avoid deadlocks on Xwayland startup, see
79a8efb45c

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2599
2020-04-09 12:14:25 +02:00
Florian Müllner
ec5cf3e0de mixer-control: Expose stream state
The state can be used to determine whether audio is currently playing
or not, which can be useful information.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/8
2019-11-23 02:42:51 +01:00
Florian Müllner
647e24625a build: Don't limit pulseaudio-fake header to introspection
We'll soon need the types for glib-mkenums as well.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/8
2019-11-23 02:42:51 +01:00
Florian Müllner
43be5d272c build: Drop autotools support
All of gnome-control-center, gnome-settings-daemon and gnome-shell
are meson-only nowadays, so there seems little point in supporting
two build systems.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/9
2019-11-22 19:40:27 +01:00
Florian Müllner
78d3f49f79 ci: Use meson for CI build
All consumers of the submodule switched to meson, except the CI build.
It neither seems useful to maintain a second build system just for that
purpose, nor to test a configuation that isn't used by anybody.

So set up a small fake project that includes gvc as a subproject, and
build that during CI.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/9
2019-11-22 19:37:31 +01:00
Georges Basile Stavracas Neto
468022b708
mixer-control: Use the "emblem-system-symbolic" icon
As suggested by the last round of design review [1], use the
"emblem-system-symbolic" icon with system sounds.

[1] https://gitlab.gnome.org/GNOME/gnome-control-center/issues/548
2019-06-14 15:02:17 -03:00
Robert Ancell
3f457453f0 Add missing guards for inputs to functions 2019-03-18 10:58:36 +13:00
Robert Ancell
b28ae07ae1 Add missing allow-none annotations 2019-03-18 10:58:36 +13:00
Bastien Nocera
0e1b4bdafc ci: Add CI
This just builds the "what-did-you-plugin" test application, but it's
good enough to catch the worst failures.
2019-02-27 14:26:26 +01:00
Andre Klapper
ae1a34aafc Comment invalid <category> in DOAP file to pass git pre-receive hook 2018-12-16 01:22:53 +01:00
Guido Günther
3513d37510 gvc-mixer-ui-device: Trim additional newlines in debug output
GVC logs a lot aready. No need to make it consume more screen space
with additional newlines.
2018-12-07 15:29:16 +01:00
Bastien Nocera
7de39e768e Merge branch 'wip/muktupavels/warnings' into 'master'
Fix build warnings

See merge request GNOME/libgnome-volume-control!2
2018-09-10 10:36:33 +00:00
Alberts Muktupāvels
4e9205d6f3 fix cast-function-type warnings
gvc-mixer-card.c: In function ‘gvc_mixer_card_finalize’:
gvc-mixer-card.c:571:53: warning: cast between incompatible function types from ‘void (*)(GvcMixerCardProfile *)’ {aka ‘void (*)(struct <anonymous> *)’} to ‘void (*)(void *, void *)’ [-Wcast-function-type]
         g_list_foreach (mixer_card->priv->profiles, (GFunc) free_profile, NULL);

gvc-mixer-stream.c: In function ‘gvc_mixer_stream_finalize’:
gvc-mixer-stream.c:1044:52: warning: cast between incompatible function types from ‘void (*)(GvcMixerStreamPort *)’ {aka ‘void (*)(struct <anonymous> *)’} to ‘void (*)(void *, void *)’ [-Wcast-function-type]
         g_list_foreach (mixer_stream->priv->ports, (GFunc) free_port, NULL);
2018-09-10 13:12:48 +03:00
Alberts Muktupāvels
13a4a9a5c2 avoid deprecated g_type_class_add_private 2018-09-09 00:02:41 +03:00
Bastien Nocera
3f30a641ef Merge branch 'wip/fmuellner/remove-rpath' into 'master'
build: Remove bogus rpath

See merge request GNOME/libgnome-volume-control!1
2018-09-07 13:33:22 +00:00
Bastien Nocera
172ccc40bb README: Add README
Closes: #1
2018-09-07 15:31:39 +02:00
Florian Müllner
eeaffe5c3d build: Remove bogus rpath
If anything it should be `pkglibdir`, but as it looks like nobody
lost their volume controls, it's apparently not needed at all.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/1
2018-08-20 14:26:18 +02:00
Iñigo Martínez
6a0ac9ba69 build: Remove config.h template file
The `config.h` can be generated without any template.

This patch removes the template file and modifies the build file
to not make any use of it.

It also removes the variable which holds the generated configuration
file target, as it will not be necessary for any packages building
libgnome-volume-control.

https://bugzilla.gnome.org/show_bug.cgi?id=792948
2018-01-30 13:16:22 +01:00
Iñigo Martínez
ef5d07fa21 build: Remove the include directory variable
The variable which holds the current directory is not necessary
because this is already included when building the library.

However, it might be interessant for any package using the library
to include the directory where headers are present, so the
current directory is appended to the library dependency without
the include directory variable.

https://bugzilla.gnome.org/show_bug.cgi?id=792948
2018-01-30 13:16:06 +01:00
Iñigo Martínez
69eac7d7cc build: Make use of assert function
meson has support for `assert` function, which halts meson's
execution showing a given message when a given condition is false.

This patch takes advantage of this function to slightly improve
meson's build file readibility.

It also removes a duplicated check for `pkglibdir` being set when
introspection is also set, because this check is already done when
a shared library is being created, that is a precondition for
introspection generation.

https://bugzilla.gnome.org/show_bug.cgi?id=792948
2018-01-30 13:15:58 +01:00
Iñigo Martínez
f764bb68e0 build: Do not use headers on library building
Headers are not necessary to be passed to the library compilation
function because the compiler will find them. On the other hand
they are necessary for the proper GIR generation.

This patch splits headers and sources, uses only sources for the
library building and uses both for GIR generation. It also allows
getting both separately.

https://bugzilla.gnome.org/show_bug.cgi?id=792948
2018-01-30 13:15:52 +01:00
Iñigo Martínez
68b7fccda8 build: Remove dependencies' variables
A set of different variables are used to hold dependencies. However,
no individual use of them is done.

This patch removes these variables and holds their objects directly
in the array of dependencies.

https://bugzilla.gnome.org/show_bug.cgi?id=792948
2018-01-30 13:15:45 +01:00