Debian Codegraph @

src/scripts/device/find-voice-call-profile.lua

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2022 Collabora Ltd.
4 -- Copyright © 2025 Richard Acayan
5 --
6 -- SPDX-License-Identifier: MIT
7 --
8 -- Find the best Voice Call profile for a device if there is an active call
9 -- (adapted from device/find-best-profile.lua)
10
11 cutils = require ("common-utils")
12 log = Log.open_topic ("s-device")
13 started = false
14
15 alsa_devs_om = ObjectManager {
16 Interest {
17 type = "device",
18 Constraint { "device.api", "=", "alsa" },
19 }
20 }
21
22 mm = Plugin.find ("modem-manager")
23 mm:connect ("voice-call-start", function ()
24 started = true
25 source = source or Plugin.find ("standard-event-source")
26
27 for device in alsa_devs_om:iterate () do
28 event = source:call ("push-event", "select-profile", device, nil)
29 end
30 end)
31
32 mm:connect ("voice-call-stop", function ()
33 started = false
34 source = source or Plugin.find ("standard-event-source")
35
36 for device in alsa_devs_om:iterate () do
37 event = source:call ("push-event", "select-profile", device, nil)
38 end
39 end)
40
41 SimpleEventHook {
42 name = "device/find-calling-profile",
43 before = "device/find-stored-profile",
44 interests = {
45 EventInterest {
46 Constraint { "event.type", "=", "select-profile" },
47 },
48 },
49 execute = function (event)
50 local selected_profile = event:get_data ("selected-profile")
51 if selected_profile then
52 return
53 end
54
55 if not started then
56 return
57 end
58
59 local device = event:get_subject ()
60 local dev_name = device.properties["device.name"] or ""
61
62 for p in device:iterate_params ("EnumProfile") do
63 local profile = cutils.parseParam (p, "EnumProfile")
64 local found = string.find (profile.name, "^Voice Call")
65 if profile.available == "yes" and found ~= nil then
66 if (not selected_profile) or selected_profile.priority < profile.priority then
67 selected_profile = profile
68 end
69 end
70 end
71
72 if selected_profile then
73 log:info (device, string.format (
74 "Found calling profile '%s' (%d) for device %s",
75 selected_profile.name, selected_profile.index, dev_name))
76 event:set_data ("selected-profile", selected_profile)
77 end
78 end
79 }:register ()
80
81 alsa_devs_om:activate ()