This commit is contained in:
Vasiliy Doylov 2024-10-27 20:30:13 +03:00
parent 7f1afd715f
commit c0c94dc81e
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
2 changed files with 54 additions and 0 deletions

View file

@ -17,14 +17,67 @@
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
Alsa.ElemId speaker_id;
Alsa.ElemId earpiece_id;
void get_mixes (string earpiece, string speaker) {
var list = new List<Alsa.ElemId> ();
Alsa.Card card;
Alsa.ElemList elem_list;
Alsa.ElemId elem_id;
Alsa.Card.open (out card, "hw:0");
Alsa.ElemList.alloc (out elem_list);
Alsa.ElemId.alloc (out elem_id);
card.elem_list (elem_list); // Getting list without items
elem_list.alloc_space (elem_list.get_count ()); // Allocating items
card.elem_list (elem_list); // Getting list with items
for (uint i = 0; i < elem_list.get_count (); i++) {
elem_list.get_id (i, elem_id);
var elem_name = elem_id.get_name ();
if (elem_name == speaker) {
Alsa.ElemId.alloc (out speaker_id);
elem_list.get_id (i, speaker_id);
} else if (elem_name == earpiece) {
Alsa.ElemId.alloc (out earpiece_id);
elem_list.get_id (i, earpiece_id);
}
if (elem_name.contains ("Voice Mixer VoiceMMode1")) {
message ("Available %s", elem_id.get_name ());
}
}
if (speaker_id != null) {
message ("Speaker Setted %s", speaker_id.get_name ());
}
if (earpiece_id != null) {
message ("Earpiece Setted %s", earpiece_id.get_name ());
}
}
int main (string[] args) { int main (string[] args) {
Alsa.Card card;
message ("Card open: %d", Alsa.Card.open (out card, "hw:0", Alsa.CardOpenType.NONBLOCK));
get_mixes ("SLIMBUS_0_RX Voice Mixer VoiceMMode1", "QUAT_MI2S_RX Voice Mixer VoiceMMode1");
Q6MeowD q6meowd_proxy = Bus.get_proxy_sync (BusType.SYSTEM, "org.postmarketos.q6meowd", "/org/postmarketos/q6meowd", DBusProxyFlags.NONE); Q6MeowD q6meowd_proxy = Bus.get_proxy_sync (BusType.SYSTEM, "org.postmarketos.q6meowd", "/org/postmarketos/q6meowd", DBusProxyFlags.NONE);
CallAudioD callaudiod_proxy = Bus.get_proxy_sync (BusType.SESSION, "org.mobian_project.CallAudio", "/org/mobian_project/CallAudio", DBusProxyFlags.NONE); CallAudioD callaudiod_proxy = Bus.get_proxy_sync (BusType.SESSION, "org.mobian_project.CallAudio", "/org/mobian_project/CallAudio", DBusProxyFlags.NONE);
((DBusProxy) callaudiod_proxy).g_properties_changed.connect ((props, inv) => { ((DBusProxy) callaudiod_proxy).g_properties_changed.connect ((props, inv) => {
foreach (var prop in props) { foreach (var prop in props) {
var name = prop.get_child_value (0).get_string (); var name = prop.get_child_value (0).get_string ();
if (name == "SpeakerState") { if (name == "SpeakerState") {
var is_speaker = prop.get_child_value (1).get_variant ().get_uint32 () == 1;
q6meowd_proxy.stop_stream (); q6meowd_proxy.stop_stream ();
Alsa.ElemValue ctl;
Alsa.ElemValue.alloc (out ctl);
if (is_speaker) {
ctl.set_id (speaker_id);
message ("Enabling speaker %s", speaker_id.get_name ());
} else {
ctl.set_id (earpiece_id);
message ("Enabling earpiece %s", earpiece_id.get_name ());
}
ctl.set_boolean (1, true);
card.elem_write (ctl);
q6meowd_proxy.start_stream (); q6meowd_proxy.start_stream ();
} }
} }

View file

@ -8,6 +8,7 @@ q6meow_output_switcher_deps = [
dependency('glib-2.0'), dependency('glib-2.0'),
dependency('gobject-2.0'), dependency('gobject-2.0'),
dependency('gio-2.0'), dependency('gio-2.0'),
dependency('alsa')
] ]
executable('q6meow_output_switcher', q6meow_output_switcher_sources, executable('q6meow_output_switcher', q6meow_output_switcher_sources,