pa_context_get_sink_info_by_name sometimes returns a null active sound card port
As asked in this merge request discussion !93 (merged) I am opening a new issue.
In order to automatically switch presets when a new default device is chosen by the user I am calling pa_context_get_sink_info_by_name
after a server changed event
(this seemed to be the way to know if the default device has changed). As long as the user switches sound cards everything is fine. Taking action when a wired headphone is plugged/unplugged has been more difficulty. At least on my hardware when I plug a wired headphone the server changed event
is always emitted and the active port returned by pa_context_get_sink_info_by_name
is never null. But on some users hardware this does not seem to be the case as can be seen here https://github.com/wwmm/pulseeffects/issues/520.
In case it helps this is how I am listening to the server changed event
https://github.com/wwmm/pulseeffects/blob/85002d3103ad1fff73a6e0e48a9da44672c6f562/src/pulse_manager.cpp#L257. And this is how I am using it https://github.com/wwmm/pulseeffects/blob/85002d3103ad1fff73a6e0e48a9da44672c6f562/src/application.cpp#L92. In this link you can see how I am using pa_context_get_sink_info_by_name
https://github.com/wwmm/pulseeffects/blob/85002d3103ad1fff73a6e0e48a9da44672c6f562/src/pulse_manager.cpp#L354
One of the affected users reported that Pavucontrols reads a non null value just fine. So I wonder if I am doing something wrong when using the threaded api
. As far as I remember Pavucontrol does not use it. Or could it be that the server changed event
is not the appropriate signal to be using for that? The idea is to take action after a change in default device. So the other signals did not seem the best choice.