Fix A2DP Bluetooth audio routing, stream migration, hotplug monitoring, and q6voice teardown
This commit is contained in:
1 parent
b2ade2dc42
commit
b8dea31b59
34 files changed
+533
-155
No files matched your search
+3
-3
@@ -22,10 +22,10 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
|
||||
- **SIP VoIP (`sip.so` / `xsip`) and IRCv3 (`irc.so` / `xirc`) upgrades**:
|
||||
- Upgraded **SIP (`sip.so` / `xsip`)** with direct accountless P2P/federated SIP URI calling (`user@host[:port]` or `sip:user@host[:port]`), alphanumeric username/password multi-tap entry, RFC 3263 DNS `SRV` (`_sip._udp.<domain>`) proxy discovery, RFC 3261 Timer A `INVITE` retransmission with multi-`A` proxy failover, `Record-Route`/`Contact` dialog routing, RFC 6189 **ZRTP** media-path key agreement (`DH3k` 3072-bit / `DH2k` 2048-bit Diffie-Hellman, `H0..H3` SHA-256 hash chain, Castagnoli CRC-32C framing, `a=zrtp-hash` SDP signaling, and 4-character Base32 `SAS` verification code) with RFC 3711 **SRTP** (`AES-128-CM` + `HMAC-SHA1-80`/`32`) encrypted voice media, incoming and active `[SIP/<codec>]` / `[SIP/<codec>:<sas>]` call badges in `xcallscreen`, wideband and narrowband multi-codec RTP/SRTP audio (`G.711 PCMU`/`PCMA` 8 kHz via PJSIP `pjmedia`, `GSM 06.10` Full Rate 8 kHz, `Opus` 16 kHz / 48 kHz RTP clock with in-band FEC, `ITU-T G.722` 16 kHz wideband SB-ADPCM via PJSIP `pjmedia-codec/g722`, `ITU-T G.726-32` 8 kHz ADPCM, `IMA ADPCM DVI4` 8/16 kHz, and `L16` uncompressed 16-bit PCM 8/16 kHz) with per-account and direct-mode codec preference selection, and seamless early-media (`183 Session Progress` -> `200 OK`) `arecord`/`aplay` stream continuity.
|
||||
- Upgraded **IRC (`irc.so` / `xirc`)** with `1:Chat` default tab ordering, `433` nick-in-use fallback, `470` channel forwarding tracking, `/close` and `/clear` commands, targeted buffer closing (`Menu -> Close Buffer` or `BackSpace` in `Buffers`), and notification hook integration in `BG Mode`.
|
||||
- **Bluetooth audio (`A2DP`, `HSP/HFP`), HID peripherals (keyboards, mice, gamepads), discoverability & alias settings, and active connection badges (`xnetworks`, `bananarchy-bt-obex`, `sxmo_audio.sh`, `dwm`, `libneoui.so`)**:
|
||||
- Configured BlueZ (`/etc/bluetooth/main.conf`, `/etc/bluetooth/input.conf`), WirePlumber (`50-bluetooth.conf` with `bluetooth.autoswitch-to-headset-profile = false`, `bluetooth.use-persistent-storage = false`, and `bluez5.enable-msbc = false`), and the `6.12.1-msm8916` QDSP6/ASoC/SMD kernel stack (`0005-msm8909-qdsp6-bt-sco-support.patch` adding `INTERNAL_BT_SCO_RX` `0x3000` / `INTERNAL_BT_SCO_TX` `0x3001` `dai@136`/`dai@137` AFE ports, `AFE_PARAM_ID_INTERNAL_BT_FM_CONFIG`, dynamic mid-call `q6voice` CVP port switching, codec-less DPCM backend links in `snd-soc-qcom-common.ko.zst` / `snd-soc-apq8016-sbc.ko.zst`, and `HCI_SCODATA_PKT` handling in `btqcomsmd.ko.zst`) with full **A2DP** (`a2dp_sink`, `a2dp_source` with `sbc_xq`, `aac`, `ldac`, `aptx`, `aptx_hd`), **HSP/HFP** (`hsp_hs`, `hsp_ag`, `hfp_hf`, `hfp_ag` 8 kHz CVSD over hardware LPASS `INT_BT_SCO_RX`/`INT_BT_SCO_TX` with automatic PipeWire SCO socket keepalive), and **HID / BLE HOGP** (`uhid`, `hidp`, `uinput`, `rfcomm`, `bnep`, `xpad`) profile support, and added `Bluetooth` as a selectable audio output/input route in `sxmo_audio.sh`, `sxmo_modemaudio.sh`, `xcallscreen` (`[3] Audio Out`), `xdrawer`, and `dmenu` Audio menu (plus automatic PipeWire `"default"` ALSA routing in `gambatte` and `remedy` when Bluetooth audio is active).
|
||||
- **Bluetooth audio (`A2DP`, `HSP/HFP`), HID peripherals (keyboards, mice, gamepads), discoverability & alias settings, and active connection badges (`xnetworks`, `bananarchy-bt-obex`, `sxmo_audio.sh`, `sxmo_soundmonitor.sh`, `dwm`, `libneoui.so`)**:
|
||||
- Configured BlueZ (`/etc/bluetooth/main.conf`, `/etc/bluetooth/input.conf`), WirePlumber (`50-bluetooth.conf` with `bluetooth.autoswitch-to-headset-profile = false`, `bluetooth.use-persistent-storage = false`, and `bluez5.enable-msbc = false`), and the `6.12.1-msm8916` QDSP6/ASoC/SMD kernel stack (`0005-msm8909-qdsp6-bt-sco-support.patch` adding `INTERNAL_BT_SCO_RX` `0x3000` / `INTERNAL_BT_SCO_TX` `0x3001` `dai@136`/`dai@137` AFE ports, `AFE_PARAM_ID_INTERNAL_BT_FM_CONFIG`, dynamic mid-call `q6voice` CVP port switching with idempotent `q6voice_path_stop` / `q6voice_path_start` null-session guards, codec-less DPCM backend links in `snd-soc-qcom-common.ko.zst` / `snd-soc-apq8016-sbc.ko.zst`, and `HCI_SCODATA_PKT` handling in `btqcomsmd.ko.zst`) with full **A2DP** (`a2dp_sink`, `a2dp_source` with `sbc_xq`, `aac`, `ldac`, `aptx`, `aptx_hd`), **HSP/HFP** (`hsp_hs`, `hsp_ag`, `hfp_hf`, `hfp_ag` 8 kHz CVSD over hardware LPASS `INT_BT_SCO_RX`/`INT_BT_SCO_TX` with automatic PipeWire SCO socket keepalive), and **HID / BLE HOGP** (`uhid`, `hidp`, `uinput`, `rfcomm`, `bnep`, `xpad`) profile support, and added `Bluetooth` as a selectable and hotplug-monitored audio output/input route in `sxmo_audio.sh`, `sxmo_soundmonitor.sh`, `sxmo_modemaudio.sh`, `sxmo_hook_ring.sh`, `xcallscreen` (`[3] Audio Out`), `xdrawer`, `xmusic`, `xringtones`, `xfiles`, `webarchy`, `gambatte`, `remedy`, and `dmenu` Audio menu (with automatic `pactl move-sink-input` stream migration, non-blocking post-ACL AVDTP sink readiness polling, and `SPK DAC Switch` muting when routing to Bluetooth or Headphones).
|
||||
- Added **Discoverable** (`ON (Visible)` / `OFF (Hidden)`, persisted in `~/.config/sxmo/bt_discoverable`) and **Bluetooth Device Name** (`Name: <Alias> [Edit]` with a multi-tap modal editor persisted in `~/.config/sxmo/bt_name` and applied via `bluetoothctl system-alias` independently of the system hostname) rows to the `3:Bluetooth` tab of `xnetworks`, alongside active connection count headers (`Bluetooth: ON (N Active)`), pinned active device cards with live profile and battery badges (`[ACTIVE: A2DP]`, `[ACTIVE: HSP/HFP]`, `[ACTIVE: HID Gamepad]`, `[ACTIVE: HID Keyboard]`, `[ACTIVE: HID Mouse]`), and a **Switch Audio (A2DP / HSP-HFP)** action.
|
||||
- Added a persistent BlueZ `NoInputNoOutput` default pairing/authorization agent (`/org/bananarchy/bt_agent`) and D-Bus `connect`/`pair` handler inside `/usr/bin/bananarchy-bt-obex` (with a 15-second discovery scan window) for seamless BLE HOGP (`00001812`) and Classic HID (`00001124`) keyboard/mouse/gamepad SMP/SSP Just-Works bonding and auto-reconnection, an automatic `/dev/uinput` gamepad-to-keypad bridge (`Bananarchy BT Gamepad Bridge`, excluding QWERTY keyboards) so Bluetooth/USB gamepads (`D-Pad` / `Left Stick` -> `Up`/`Down`/`Left`/`Right`, `South/A` -> `Enter`, `East/B` -> `8`, `West/X` -> `5`, `North/Y` -> `6`, `Start` -> `2`, `Select` -> `3`, `L1`/`R1` -> `Left`/`Right softkey`, `L2`/`R2` -> `*`/`0`, `Mode` -> `Escape`) control all NeoUI apps and games (`snake`, `tetris`, `scoundrel`, `gambatte`, `remedy`) out of the box, automatic `[KBD]` external keyboard detection (`isExternalKeyboardActive()`) in `fcitx5-t9`, `libneoui.so`, and DWM plugins so connecting a Bluetooth/USB QWERTY keyboard automatically bypasses T9 multi-tap and preedit popups for all keys (`0-9`, `*`, `#`, `Shift+0-9`, and letters), and automatic `XFixes` cursor display in `dwm` (`dwm_has_external_mouse()`) whenever a Bluetooth/USB mouse is connected.
|
||||
- Added a persistent BlueZ `NoInputNoOutput` default pairing/authorization agent (`/org/bananarchy/bt_agent`) and D-Bus `connect`/`pair` handler inside `/usr/bin/bananarchy-bt-obex` (skipping redundant pre-connect inquiry scans for known BlueZ devices and automatically recovering from stale `[LinkKey]` `br-connection-key-missing` errors) for seamless BLE HOGP (`00001812`), Classic HID (`00001124`), and A2DP/HFP bonding and reconnection, an automatic `/dev/uinput` gamepad-to-keypad bridge (`Bananarchy BT Gamepad Bridge`, excluding QWERTY keyboards) so Bluetooth/USB gamepads (`D-Pad` / `Left Stick` -> `Up`/`Down`/`Left`/`Right`, `South/A` -> `Enter`, `East/B` -> `8`, `West/X` -> `5`, `North/Y` -> `6`, `Start` -> `2`, `Select` -> `3`, `L1`/`R1` -> `Left`/`Right softkey`, `L2`/`R2` -> `*`/`0`, `Mode` -> `Escape`) control all NeoUI apps and games (`snake`, `tetris`, `scoundrel`, `gambatte`, `remedy`) out of the box, automatic `[KBD]` external keyboard detection (`isExternalKeyboardActive()`) in `fcitx5-t9`, `libneoui.so`, and DWM plugins so connecting a Bluetooth/USB QWERTY keyboard automatically bypasses T9 multi-tap and preedit popups for all keys (`0-9`, `*`, `#`, `Shift+0-9`, and letters), and automatic `XFixes` cursor display in `dwm` (`dwm_has_external_mouse()`) whenever a Bluetooth/USB mouse is connected.
|
||||
- **Universal Power button (`dmenu power`) access, lockscreen X11 grab preemption, ReMEdy `Call (green)` pause menu, JSR expansion, and 64 MB mark-and-sweep GC**:
|
||||
- Updated `dwm`, `dmenu`, `xdrawer`, `libneoui.so`, `sxmo_multikey.sh`, all standalone Xlib DWM plugins, and standalone games (`scoundrel`, `gambatte`, `remedy`) so pressing **End / Power (red)** (`XF86PowerOff`, keycode `124`) from any active window or menu immediately opens (or toggles) the system **Power menu (`dmenu power`)** while mapped **Call (green)** (`XF86Phone` / `XF86PickupPhone`) and `500 ms` **Right softkey** hold in `remedy` open the **ReMEdy Pause Menu**.
|
||||
- Updated `locker.so` (`xlocker`) and `dwm` to preempt active X11 keyboard grabs and window stacking over any running fullscreen application or game (`webarchy`, `remedy`, `gambatte`, `scoundrel`, `snake`, `tetris`, and all NeoUI plugins) when the screen locks, cleanly restoring the previously focused application upon unlock.
|
||||
|
||||
@@ -11,4 +11,4 @@ tty1::respawn:/sbin/getty 38400 tty1
|
||||
::ctrlaltdel:/sbin/reboot
|
||||
|
||||
# Stuff to do before rebooting
|
||||
::shutdown:/sbin/openrc shutdown
|
||||
::shutdown:/bin/sh -c 'timeout 8 /sbin/openrc shutdown || true'
|
||||
Binary file not shown.
@@ -1006,6 +1006,52 @@ def ensure_daemon_running():
|
||||
pass
|
||||
|
||||
|
||||
def clear_stale_linkkey(mac):
|
||||
mac = mac.strip().upper()
|
||||
if not mac:
|
||||
return False
|
||||
if os.geteuid() != 0:
|
||||
res = subprocess.run(
|
||||
["doas", "-n", "/usr/bin/bananarchy-bt-obex", "clear-linkkey", mac],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
return res.returncode == 0
|
||||
|
||||
bt_root = "/var/lib/bluetooth"
|
||||
changed = False
|
||||
if os.path.isdir(bt_root):
|
||||
for adapter in os.listdir(bt_root):
|
||||
info_path = os.path.join(bt_root, adapter, mac, "info")
|
||||
if not os.path.isfile(info_path):
|
||||
continue
|
||||
try:
|
||||
with open(info_path, "r", encoding="utf-8", errors="replace") as f:
|
||||
lines = f.readlines()
|
||||
out_lines = []
|
||||
skip_sec = False
|
||||
for ln in lines:
|
||||
s = ln.strip()
|
||||
if s.startswith("[") and s.endswith("]"):
|
||||
skip_sec = s.lower() in ("[linkkey]", "[longtermkey]", "[peripherallongtermkey]", "[slaveLongtermkey]")
|
||||
if not skip_sec:
|
||||
out_lines.append(ln)
|
||||
if len(out_lines) != len(lines):
|
||||
with open(info_path, "w", encoding="utf-8") as f:
|
||||
f.writelines(out_lines)
|
||||
changed = True
|
||||
except Exception:
|
||||
pass
|
||||
if changed:
|
||||
subprocess.run(["rc-service", "bluetooth", "restart"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
time.sleep(0.8)
|
||||
subprocess.run(["bluetoothctl", "power", "on"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
time.sleep(0.4)
|
||||
return changed
|
||||
|
||||
|
||||
def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
from jeepney import DBusAddress, new_method_call, MessageType
|
||||
from jeepney.io.blocking import open_dbus_connection
|
||||
@@ -1026,8 +1072,10 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
interface="org.freedesktop.DBus.ObjectManager")
|
||||
|
||||
conn = None
|
||||
nonlocal_conn = [None]
|
||||
try:
|
||||
conn = open_dbus_connection(bus="SYSTEM")
|
||||
nonlocal_conn[0] = conn
|
||||
aprop_addr = DBusAddress("/org/bluez/hci0", bus_name="org.bluez",
|
||||
interface="org.freedesktop.DBus.Properties")
|
||||
dbus_call_with_agent(
|
||||
@@ -1056,9 +1104,9 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
while time.time() < end_t:
|
||||
rem = max(0.05, min(0.25, end_t - time.time()))
|
||||
try:
|
||||
m = conn.receive(timeout=rem)
|
||||
m = nonlocal_conn[0].receive(timeout=rem)
|
||||
if m is not None:
|
||||
handle_agent_method_call(conn, m, cli_agent_path)
|
||||
handle_agent_method_call(nonlocal_conn[0], m, cli_agent_path)
|
||||
except TimeoutError:
|
||||
pass
|
||||
|
||||
@@ -1066,7 +1114,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
prop_addr = DBusAddress(dpath, bus_name="org.bluez",
|
||||
interface="org.freedesktop.DBus.Properties")
|
||||
rep = dbus_call_with_agent(
|
||||
conn,
|
||||
nonlocal_conn[0],
|
||||
new_method_call(prop_addr, "GetAll", "s", ("org.bluez.Device1",)),
|
||||
cli_agent_path,
|
||||
timeout=2.5
|
||||
@@ -1086,7 +1134,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
return None
|
||||
t_low = target_name.strip().lower()
|
||||
rep = dbus_call_with_agent(
|
||||
conn,
|
||||
nonlocal_conn[0],
|
||||
new_method_call(om_addr, "GetManagedObjects"),
|
||||
cli_agent_path,
|
||||
timeout=3.0
|
||||
@@ -1137,11 +1185,11 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
dev_addr = DBusAddress(dpath, bus_name="org.bluez",
|
||||
interface="org.bluez.Device1")
|
||||
dbus_call_with_agent(
|
||||
conn, new_method_call(dev_addr, "Disconnect"), cli_agent_path, timeout=2.0
|
||||
nonlocal_conn[0], new_method_call(dev_addr, "Disconnect"), cli_agent_path, timeout=2.0
|
||||
)
|
||||
|
||||
def attempt_connect_path(dpath, want_pair):
|
||||
trust_device_path(conn, dpath)
|
||||
trust_device_path(nonlocal_conn[0], dpath)
|
||||
p = get_dev_props(dpath)
|
||||
if p is None:
|
||||
return False
|
||||
@@ -1154,7 +1202,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
interface="org.bluez.Device1")
|
||||
if want_pair and not (p.get("Paired") or p.get("Bonded")):
|
||||
rep = dbus_call_with_agent(
|
||||
conn, new_method_call(dev_addr, "Pair"), cli_agent_path, timeout=8.0
|
||||
nonlocal_conn[0], new_method_call(dev_addr, "Pair"), cli_agent_path, timeout=8.0
|
||||
)
|
||||
if rep is None:
|
||||
cancel_pending_connect(dpath)
|
||||
@@ -1162,10 +1210,48 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
|
||||
if not p.get("Connected"):
|
||||
rep = dbus_call_with_agent(
|
||||
conn, new_method_call(dev_addr, "Connect"), cli_agent_path, timeout=8.0
|
||||
nonlocal_conn[0], new_method_call(dev_addr, "Connect"), cli_agent_path, timeout=8.0
|
||||
)
|
||||
if rep is None:
|
||||
cancel_pending_connect(dpath)
|
||||
elif rep.header.message_type == MessageType.error:
|
||||
err_str = " ".join(str(x) for x in (rep.body or ())).lower()
|
||||
if "key-missing" in err_str or "authentication" in err_str:
|
||||
dev_mac = dpath.split("dev_")[-1].replace("_", ":")
|
||||
if clear_stale_linkkey(dev_mac):
|
||||
try:
|
||||
nonlocal_conn[0].close()
|
||||
except Exception:
|
||||
pass
|
||||
conn_new = open_dbus_connection(bus="SYSTEM")
|
||||
nonlocal_conn[0] = conn_new
|
||||
dbus_call_with_agent(
|
||||
conn_new,
|
||||
new_method_call(aprop_addr, "Set", "ssv",
|
||||
("org.bluez.Adapter1", "Pairable", ("b", True))),
|
||||
cli_agent_path,
|
||||
timeout=2.0
|
||||
)
|
||||
dbus_call_with_agent(
|
||||
conn_new,
|
||||
new_method_call(am_addr, "RegisterAgent", "os",
|
||||
(cli_agent_path, "NoInputNoOutput")),
|
||||
cli_agent_path,
|
||||
timeout=2.5
|
||||
)
|
||||
dbus_call_with_agent(
|
||||
conn_new,
|
||||
new_method_call(am_addr, "RequestDefaultAgent", "o", (cli_agent_path,)),
|
||||
cli_agent_path,
|
||||
timeout=2.5
|
||||
)
|
||||
trust_device_path(conn_new, dpath)
|
||||
dbus_call_with_agent(
|
||||
conn_new, new_method_call(dev_addr, "Pair"), cli_agent_path, timeout=8.0
|
||||
)
|
||||
dbus_call_with_agent(
|
||||
conn_new, new_method_call(dev_addr, "Connect"), cli_agent_path, timeout=8.0
|
||||
)
|
||||
p = get_dev_props(dpath) or {}
|
||||
|
||||
if p.get("Connected") and not (p.get("Paired") or p.get("Bonded")):
|
||||
@@ -1179,7 +1265,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
|
||||
def scan_for_device(prefer_path, max_scan=15.0):
|
||||
dbus_call_with_agent(
|
||||
conn, new_method_call(adapter_addr, "StartDiscovery"), cli_agent_path, timeout=2.5
|
||||
nonlocal_conn[0], new_method_call(adapter_addr, "StartDiscovery"), cli_agent_path, timeout=2.5
|
||||
)
|
||||
scan_start = time.time()
|
||||
scan_deadline = scan_start + max_scan
|
||||
@@ -1196,11 +1282,11 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
ap = get_dev_props(alt)
|
||||
if ap and (ap.get("Connected") or ap.get("RSSI") is not None):
|
||||
discovered_path = alt
|
||||
trust_device_path(conn, discovered_path)
|
||||
trust_device_path(nonlocal_conn[0], discovered_path)
|
||||
if ap.get("Connected") or (time.time() - scan_start) >= 0.8:
|
||||
break
|
||||
dbus_call_with_agent(
|
||||
conn, new_method_call(adapter_addr, "StopDiscovery"), cli_agent_path, timeout=2.0
|
||||
nonlocal_conn[0], new_method_call(adapter_addr, "StopDiscovery"), cli_agent_path, timeout=2.0
|
||||
)
|
||||
pump_agent(0.15)
|
||||
return discovered_path
|
||||
@@ -1215,22 +1301,21 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
dev_path = alt
|
||||
props = get_dev_props(dev_path)
|
||||
|
||||
trust_device_path(conn, dev_path)
|
||||
trust_device_path(nonlocal_conn[0], dev_path)
|
||||
|
||||
# If the device is not currently connected and has no active scan RSSI,
|
||||
# run a discovery scan (up to 15s, stopping early as soon as seen) so BLE
|
||||
# peripherals are in the controller cache or caught if they rotated their MAC.
|
||||
if not (props and (props.get("Connected") or props.get("RSSI") is not None)):
|
||||
dev_path = scan_for_device(dev_path, max_scan=15.0)
|
||||
# Try connecting directly first when BlueZ already knows the device (avoids
|
||||
# blocking 15s in StartDiscovery for paired BR/EDR headsets in Page Scan).
|
||||
if props is None:
|
||||
dev_path = scan_for_device(dev_path, max_scan=8.0)
|
||||
|
||||
ok = attempt_connect_path(dev_path, do_pair)
|
||||
|
||||
if not ok:
|
||||
discovered_path = scan_for_device(dev_path, max_scan=15.0)
|
||||
discovered_path = scan_for_device(dev_path, max_scan=8.0)
|
||||
ok = attempt_connect_path(discovered_path, do_pair)
|
||||
if ok and discovered_path != orig_path and orig_unbonded:
|
||||
dbus_call_with_agent(
|
||||
conn,
|
||||
nonlocal_conn[0],
|
||||
new_method_call(adapter_addr, "RemoveDevice", "o", (orig_path,)),
|
||||
cli_agent_path,
|
||||
timeout=2.0
|
||||
@@ -1241,10 +1326,11 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
except Exception:
|
||||
return 1
|
||||
finally:
|
||||
if conn is not None:
|
||||
c_final = nonlocal_conn[0]
|
||||
if c_final is not None:
|
||||
try:
|
||||
dbus_call_with_agent(
|
||||
conn,
|
||||
c_final,
|
||||
new_method_call(am_addr, "UnregisterAgent", "o", (cli_agent_path,)),
|
||||
cli_agent_path,
|
||||
timeout=1.5
|
||||
@@ -1252,7 +1338,7 @@ def connect_or_pair_bt_device(mac, dev_name="", do_pair=False):
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
conn.close()
|
||||
c_final.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1295,6 +1381,10 @@ def main():
|
||||
return 1
|
||||
nm = sys.argv[3] if len(sys.argv) >= 4 else ""
|
||||
return connect_or_pair_bt_device(sys.argv[2], nm, do_pair=True)
|
||||
elif cmd == "clear-linkkey":
|
||||
if len(sys.argv) < 3:
|
||||
return 1
|
||||
return 0 if clear_stale_linkkey(sys.argv[2]) else 1
|
||||
elif cmd == "send":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage: bananarchy-bt-obex send <MAC> <filepath>", file=sys.stderr)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,14 @@
|
||||
|
||||
export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH"
|
||||
|
||||
if [ -z "${XDG_RUNTIME_DIR:-}" ] || [ ! -d "${XDG_RUNTIME_DIR}" ]; then
|
||||
if [ -d "/run/user/$(id -u)" ]; then
|
||||
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
|
||||
elif [ -d "/run/user/10000" ]; then
|
||||
export XDG_RUNTIME_DIR="/run/user/10000"
|
||||
fi
|
||||
fi
|
||||
|
||||
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
|
||||
. sxmo_hook_icons.sh
|
||||
. sxmo_common.sh
|
||||
@@ -94,6 +102,37 @@ find_bt_source() {
|
||||
pactl list short sources 2>/dev/null | awk '$2 ~ /^bluez_input\./ { print $2; exit }'
|
||||
}
|
||||
|
||||
move_streams_to_sink() {
|
||||
target_sink="$1"
|
||||
[ -z "$target_sink" ] && return 0
|
||||
for sid in $(pactl list short sink-inputs 2>/dev/null | awk '{print $1}'); do
|
||||
pactl move-sink-input "$sid" "$target_sink" >/dev/null 2>&1 || true
|
||||
done
|
||||
}
|
||||
|
||||
ensure_bt_a2dp_profile() {
|
||||
bt_card="$(find_bt_card)"
|
||||
[ -z "$bt_card" ] && return 1
|
||||
prof="$(find_bt_profile)"
|
||||
if [ "$prof" = "off" ] || [ -z "$prof" ]; then
|
||||
if ! pactl set-card-profile "$bt_card" a2dp-sink >/dev/null 2>&1; then
|
||||
avail_prof="$(pactl list cards 2>/dev/null | awk -v c="$bt_card" '
|
||||
$1 == "Name:" { in_c = ($2 == c); in_p = 0 }
|
||||
in_c && $1 == "Profiles:" { in_p = 1; next }
|
||||
in_c && in_p && /^[[:space:]]*Active Profile:/ { in_p = 0 }
|
||||
in_c && in_p && $1 ~ /^a2dp-sink/ && $0 !~ /available: no/ { sub(/:$/, "", $1); print $1; exit }
|
||||
')"
|
||||
if [ -n "$avail_prof" ]; then
|
||||
pactl set-card-profile "$bt_card" "$avail_prof" >/dev/null 2>&1 || true
|
||||
else
|
||||
pactl set-card-profile "$bt_card" headset-head-unit-cvsd >/dev/null 2>&1 ||
|
||||
pactl set-card-profile "$bt_card" headset-head-unit >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
vol_file_for_dev() {
|
||||
dev="$(normalize_out_dev "$1")"
|
||||
case "$dev" in
|
||||
@@ -172,9 +211,23 @@ deviceget() {
|
||||
read -r dev < /tmp/sxmo_audio_out_device 2>/dev/null || dev=""
|
||||
if [ -n "$dev" ]; then
|
||||
dev="$(normalize_out_dev "$dev")"
|
||||
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
|
||||
dev="Speaker"
|
||||
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
|
||||
if [ "$dev" = "Bluetooth" ]; then
|
||||
bt_sink="$(find_bt_sink)"
|
||||
if [ -n "$bt_sink" ]; then
|
||||
sco_mm=0
|
||||
[ -r /tmp/sxmo_bt_sco_mm_active ] && read -r sco_mm < /tmp/sxmo_bt_sco_mm_active 2>/dev/null || sco_mm=0
|
||||
if [ "$sco_mm" != "1" ]; then
|
||||
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
|
||||
move_streams_to_sink "$bt_sink"
|
||||
fi
|
||||
elif [ -z "$(find_bt_card)" ] && [ ! -e /tmp/sxmo_bt_connecting ]; then
|
||||
if [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" = "1" ]; then
|
||||
dev="Headphones"
|
||||
else
|
||||
dev="Speaker"
|
||||
fi
|
||||
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
printf "%s\n" "$dev"
|
||||
return 0
|
||||
@@ -184,7 +237,7 @@ deviceget() {
|
||||
read -r dev < "$CFG_DIR/audio_out_device" 2>/dev/null || dev=""
|
||||
if [ -n "$dev" ]; then
|
||||
dev="$(normalize_out_dev "$dev")"
|
||||
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
|
||||
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ] && [ -z "$(find_bt_card)" ]; then
|
||||
dev="Speaker"
|
||||
fi
|
||||
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
|
||||
@@ -520,16 +573,51 @@ sync_pipewire_profile() {
|
||||
pactl set-card-profile "$ALSA_CARD" "$prof" >/dev/null 2>&1 || true
|
||||
if [ "$out_dev" = "Bluetooth" ]; then
|
||||
if [ "$want_sco_mm" = "1" ]; then
|
||||
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
pactl set-default-sink "alsa_output.platform-7702000.sound.HiFi__Speaker__sink" >/dev/null 2>&1 || true
|
||||
move_streams_to_sink "alsa_output.platform-7702000.sound.HiFi__Speaker__sink"
|
||||
else
|
||||
if [ ! -r /tmp/sxmo_in_call ]; then
|
||||
ensure_bt_a2dp_profile || true
|
||||
fi
|
||||
bt_sink="$(find_bt_sink)"
|
||||
if [ -n "$bt_sink" ]; then
|
||||
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
|
||||
move_streams_to_sink "$bt_sink"
|
||||
else
|
||||
touch /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
(
|
||||
for _i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
|
||||
sleep 0.25
|
||||
cur_want="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
|
||||
[ "$cur_want" = "Bluetooth" ] || break
|
||||
if [ ! -r /tmp/sxmo_in_call ]; then
|
||||
ensure_bt_a2dp_profile || true
|
||||
fi
|
||||
bt_sink="$(find_bt_sink)"
|
||||
if [ -n "$bt_sink" ]; then
|
||||
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
|
||||
move_streams_to_sink "$bt_sink"
|
||||
out_vol="$(read_dev_vol Bluetooth)"
|
||||
apply_alsa_out Bluetooth "$out_vol"
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
if [ -p /tmp/dwm_plugin_networks.fifo ]; then
|
||||
printf "REFRESH\n" > /tmp/dwm_plugin_networks.fifo 2>/dev/null || true
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
) >/dev/null 2>&1 &
|
||||
fi
|
||||
fi
|
||||
else
|
||||
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
|
||||
sink_name="alsa_output.platform-7702000.sound.HiFi__${out_dev}__sink"
|
||||
pactl set-default-sink "$sink_name" >/dev/null 2>&1 || true
|
||||
move_streams_to_sink "$sink_name"
|
||||
fi
|
||||
if [ "$in_dev" = "Bluetooth" ]; then
|
||||
if [ "$want_sco_mm" = "1" ]; then
|
||||
@@ -714,7 +802,7 @@ devicesetinput() {
|
||||
}
|
||||
|
||||
devicelist() {
|
||||
if [ -n "$(find_bt_sink)" ]; then
|
||||
if [ -n "$(find_bt_sink)" ] || [ -n "$(find_bt_card)" ]; then
|
||||
printf "Bluetooth\nSpeaker\nEarpiece\nHeadphones\n"
|
||||
else
|
||||
printf "Speaker\nEarpiece\nHeadphones\n"
|
||||
@@ -733,7 +821,9 @@ devicecycle() {
|
||||
dir="${1:-next}"
|
||||
cur="$(deviceget)"
|
||||
has_bt=0
|
||||
[ -n "$(find_bt_sink)" ] && has_bt=1
|
||||
if [ -n "$(find_bt_sink)" ] || [ -n "$(find_bt_card)" ]; then
|
||||
has_bt=1
|
||||
fi
|
||||
if [ "$dir" = "prev" ]; then
|
||||
if [ "$has_bt" = "1" ]; then
|
||||
case "$cur" in
|
||||
|
||||
@@ -93,7 +93,11 @@ monitor_jack_events() {
|
||||
handle_jack_insert "$jdev"
|
||||
else
|
||||
printf "0\n" > /tmp/sxmo_jack_plugged 2>/dev/null || true
|
||||
sxmo_audio.sh device apply >/dev/null 2>&1 || true
|
||||
if [ -n "$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')" ]; then
|
||||
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_audio.sh device apply >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
evtest "$jdev" 2>/dev/null | while read -r line; do
|
||||
@@ -118,11 +122,50 @@ monitor_jack_events() {
|
||||
}
|
||||
|
||||
handle_change() {
|
||||
pactl subscribe 2>/dev/null |
|
||||
grep -E --line-buffered "Event 'change' on (sink|source)" |
|
||||
while read -r _; do
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
done
|
||||
prev_bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
|
||||
if [ -n "$prev_bt_sink" ]; then
|
||||
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
|
||||
if [ "$cur_out" != "Bluetooth" ]; then
|
||||
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_audio.sh device apply >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
pactl subscribe 2>/dev/null | while read -r line; do
|
||||
case "$line" in
|
||||
*"Event 'new' on sink"*|*"Event 'new' on card"*|*"Event 'change' on card"*)
|
||||
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
|
||||
if [ -n "$bt_sink" ] && [ "$bt_sink" != "$prev_bt_sink" ]; then
|
||||
prev_bt_sink="$bt_sink"
|
||||
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
|
||||
sxmo_log "Bluetooth sink $bt_sink detected -> routed audio to Bluetooth"
|
||||
fi
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
;;
|
||||
*"Event 'remove' on sink"*|*"Event 'remove' on card"*)
|
||||
bt_sink="$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\./ { print $2; exit }')"
|
||||
if [ -z "$bt_sink" ] && [ -n "$prev_bt_sink" ]; then
|
||||
prev_bt_sink=""
|
||||
cur_out="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
|
||||
if [ "$cur_out" = "Bluetooth" ]; then
|
||||
if [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" = "1" ]; then
|
||||
sxmo_audio.sh device set Headphones >/dev/null 2>&1 || true
|
||||
elif [ -r /tmp/sxmo_in_call ]; then
|
||||
sxmo_audio.sh device set Earpiece >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_audio.sh device set Speaker >/dev/null 2>&1 || true
|
||||
fi
|
||||
sxmo_log "Bluetooth sink removed -> restored local audio route"
|
||||
fi
|
||||
fi
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
;;
|
||||
*"Event 'change' on sink"*|*"Event 'change' on source"*)
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -173,13 +173,37 @@ ring() {
|
||||
return 0
|
||||
fi
|
||||
ring_rx3=$(( 56 + (SXMO_RINGVOL * 32 + 50) / 100 ))
|
||||
out_dev="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || printf 'Speaker')"
|
||||
|
||||
(
|
||||
rchild=""
|
||||
vhelper=""
|
||||
trap '[ -n "$rchild" ] && kill -TERM "$rchild" 2>/dev/null; [ -n "$vhelper" ] && kill -TERM "$vhelper" 2>/dev/null; exit 0' INT TERM EXIT
|
||||
|
||||
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
|
||||
if [ "$out_dev" = "Bluetooth" ]; then
|
||||
amixer -c 0 cset "name='SPK DAC Switch'" 0 >/dev/null 2>&1 || true
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
|
||||
elif [ "$out_dev" = "Headphones" ]; then
|
||||
ring_hp=$(( 52 + (SXMO_RINGVOL * 32 + 50) / 100 ))
|
||||
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
|
||||
cset "name='SPK DAC Switch'" 0
|
||||
cset "name='RX3 MIX1 INP1'" 0
|
||||
cset "name='RX3 Digital Volume'" 0
|
||||
cset "name='EAR_S'" 0
|
||||
cset "name='PRI_MI2S_RX Audio Mixer MultiMedia1'" 1
|
||||
cset "name='RDAC2 MUX'" 'RX2'
|
||||
cset "name='RX1 MIX1 INP1'" 'RX1'
|
||||
cset "name='RX2 MIX1 INP1'" 'RX2'
|
||||
cset "name='HPHL'" 'Switch'
|
||||
cset "name='HPHR'" 'Switch'
|
||||
cset "name='RX1 Digital Volume'" $ring_hp
|
||||
cset "name='RX2 Digital Volume'" $ring_hp
|
||||
EOF
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
else
|
||||
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
|
||||
cset "name='EAR_S'" 0
|
||||
cset "name='RX1 MIX1 INP1'" 0
|
||||
cset "name='PRI_MI2S_RX Audio Mixer MultiMedia1'" 1
|
||||
@@ -187,22 +211,23 @@ cset "name='SPK DAC Switch'" 1
|
||||
cset "name='RX3 MIX1 INP1'" 3
|
||||
cset "name='RX3 Digital Volume'" $ring_rx3
|
||||
EOF
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
|
||||
(
|
||||
for d in 0.15 0.40; do
|
||||
sleep "$d" || exit 0
|
||||
should_stop_ringing && exit 0
|
||||
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
|
||||
(
|
||||
for d in 0.15 0.40; do
|
||||
sleep "$d" || exit 0
|
||||
should_stop_ringing && exit 0
|
||||
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
|
||||
cset "name='SPK DAC Switch'" 1
|
||||
cset "name='RX3 MIX1 INP1'" 3
|
||||
cset "name='RX3 Digital Volume'" $ring_rx3
|
||||
EOF
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
done
|
||||
) &
|
||||
vhelper="$!"
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
done
|
||||
) &
|
||||
vhelper="$!"
|
||||
fi
|
||||
|
||||
ext="$(printf '%s' "${SXMO_RINGTONE##*.}" | tr '[:upper:]' '[:lower:]')"
|
||||
play_file="$SXMO_RINGTONE"
|
||||
@@ -226,8 +251,12 @@ EOF
|
||||
i=0
|
||||
while [ "$i" -lt "$loops" ]; do
|
||||
should_stop_ringing && break
|
||||
amixer -c 0 cset "name='RX3 Digital Volume'" "$ring_rx3" >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
if [ "$out_dev" = "Bluetooth" ]; then
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
|
||||
elif [ "$out_dev" != "Headphones" ]; then
|
||||
amixer -c 0 cset "name='RX3 Digital Volume'" "$ring_rx3" >/dev/null 2>&1 || true
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1 || true
|
||||
fi
|
||||
pw-play --volume=1.0 "$play_file" >/dev/null 2>&1 &
|
||||
rchild="$!"
|
||||
wait "$rchild" 2>/dev/null
|
||||
|
||||
@@ -412,7 +412,27 @@
|
||||
static unsigned int q6voice_reg_read(struct snd_soc_component *component,
|
||||
--- a/sound/soc/qcom/qdsp6/q6voice.c
|
||||
+++ b/sound/soc/qcom/qdsp6/q6voice.c
|
||||
@@ -252,11 +252,25 @@
|
||||
@@ -39,6 +39,9 @@
|
||||
struct q6voice_session *mvm, *cvp;
|
||||
int ret;
|
||||
|
||||
+ if (!p->tx_port || !p->rx_port)
|
||||
+ return 0;
|
||||
+
|
||||
dev_dbg(dev, "start path %d\n", p->type);
|
||||
|
||||
mvm = p->runtime->sessions[Q6VOICE_SERVICE_MVM];
|
||||
@@ -133,6 +136,9 @@
|
||||
struct q6voice_session *cvp = p->runtime->sessions[Q6VOICE_SERVICE_CVP];
|
||||
int ret;
|
||||
|
||||
+ if (!mvm || !cvp)
|
||||
+ return;
|
||||
+
|
||||
dev_dbg(dev, "stop path %d\n", p->type);
|
||||
|
||||
ret = q6mvm_start(mvm, false);
|
||||
@@ -252,11 +258,25 @@
|
||||
bool capture, int index)
|
||||
{
|
||||
struct q6voice_path *p = &v->paths[path];
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -561,7 +561,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
alsa.setBoolean("PRI_MI2S_RX Voice Mixer VoiceMMode1", false);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", false);
|
||||
alsa.setBoolean("INT_BT_SCO_RX Voice Mixer VoiceMMode1", true);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer INT_BT_SCO_TX", !micMuted);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer INT_BT_SCO_TX", true);
|
||||
} else {
|
||||
alsa.setBoolean("PRI_MI2S_RX Audio Mixer MultiMedia1", false);
|
||||
alsa.setBoolean("MultiMedia2 Mixer TERT_MI2S_TX", false);
|
||||
@@ -589,7 +589,7 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
alsa.setBoolean("INT_BT_SCO_RX Voice Mixer VoiceMMode1", false);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer INT_BT_SCO_TX", false);
|
||||
alsa.setBoolean("PRI_MI2S_RX Voice Mixer VoiceMMode1", true);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", !micMuted);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", true);
|
||||
} else {
|
||||
alsa.setBoolean("INT_BT_SCO_RX Audio Mixer MultiMedia1", false);
|
||||
alsa.setBoolean("MultiMedia2 Mixer INT_BT_SCO_TX", false);
|
||||
@@ -1412,17 +1412,6 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
writeActiveStateFiles();
|
||||
stopRingingJobs();
|
||||
btAudioOn = false;
|
||||
alsa.setBoolean("INT_BT_SCO_RX Voice Mixer VoiceMMode1", false);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer INT_BT_SCO_TX", false);
|
||||
alsa.setBoolean("PRI_MI2S_RX Voice Mixer VoiceMMode1", false);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", false);
|
||||
alsa.setEnum("EAR_S", 0);
|
||||
alsa.setEnum("RX1 MIX1 INP1", 0);
|
||||
alsa.setInteger("RX1 Digital Volume", 0);
|
||||
alsa.setEnum("RX3 MIX1 INP1", 3);
|
||||
alsa.setBoolean("SPK DAC Switch", true);
|
||||
int spkPct = readIntFile(getHomeDirPath() + "/.config/sxmo/speaker_vol", 85);
|
||||
alsa.setInteger("RX3 Digital Volume", pctToHwVol(spkPct, true, false));
|
||||
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
|
||||
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
|
||||
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
|
||||
|
||||
@@ -824,15 +824,30 @@ int runFilesApp(int argc, char** argv) {
|
||||
|
||||
int rvol = std::clamp(readRingVolumePct(), 0, 100);
|
||||
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100);
|
||||
runAsyncCmd("amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX1 MIX1 INP1'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
"wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1");
|
||||
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
|
||||
runAsyncCmd("outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
|
||||
"if [ \"$outdev\" = \"Bluetooth\" ]; then "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 0 >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ " + std::to_string(rvol) + "% >/dev/null 2>&1; "
|
||||
"elif [ \"$outdev\" = \"Headphones\" ]; then "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX1 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX2 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
"else "
|
||||
" amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX1 MIX1 INP1'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX3 Digital Volume'\" " + std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
"fi");
|
||||
|
||||
pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
|
||||
@@ -266,7 +266,12 @@ int readSavedSpeakerVol() {
|
||||
}
|
||||
std::string vfile = "/speaker_vol";
|
||||
int defv = 85;
|
||||
if (outDev.find("Headphone") != std::string::npos || outDev.find("Headset") != std::string::npos) {
|
||||
if (outDev.find("Bluetooth") != std::string::npos ||
|
||||
outDev.find("bluetooth") != std::string::npos) {
|
||||
vfile = "/bluetooth_vol";
|
||||
defv = 80;
|
||||
} else if (outDev.find("Headphone") != std::string::npos ||
|
||||
outDev.find("Headset") != std::string::npos) {
|
||||
vfile = "/headphones_vol";
|
||||
defv = 80;
|
||||
} else if (outDev.find("Earpiece") != std::string::npos) {
|
||||
@@ -502,10 +507,14 @@ int runMusicApp(int argc, char** argv) {
|
||||
isPaused = false;
|
||||
ignoreEofUntilMs = nowMs() + 450;
|
||||
|
||||
runAsyncCmd("amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
"wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1");
|
||||
runAsyncCmd("sxmo_audio.sh device apply >/dev/null 2>&1; "
|
||||
"(sleep 0.25; "
|
||||
"sink=$(pactl get-default-sink 2>/dev/null); "
|
||||
"if [ -n \"$sink\" ]; then "
|
||||
" for sid in $(pactl list short sink-inputs 2>/dev/null | awk '{print $1}'); do "
|
||||
" pactl move-sink-input \"$sid\" \"$sink\" >/dev/null 2>&1 || true; "
|
||||
" done; "
|
||||
"fi) >/dev/null 2>&1 &");
|
||||
|
||||
std::string loadTarget = tr.path;
|
||||
if (isMonotoneFile(tr.path)) {
|
||||
@@ -1333,11 +1342,11 @@ int runMusicApp(int argc, char** argv) {
|
||||
} else if (sym == XK_Right || sym == XK_KP_Right) {
|
||||
seekRelative(5);
|
||||
} else if (sym == XK_Up || sym == XK_KP_Up) {
|
||||
volumePct = std::clamp(volumePct + 5, 0, 100);
|
||||
volumePct = std::clamp(readSavedSpeakerVol() + 5, 0, 100);
|
||||
applySystemSpeakerVol(volumePct);
|
||||
setBanner("Volume: " + std::to_string(volumePct) + "%", 1200);
|
||||
} else if (sym == XK_Down || sym == XK_KP_Down) {
|
||||
volumePct = std::clamp(volumePct - 5, 0, 100);
|
||||
volumePct = std::clamp(readSavedSpeakerVol() - 5, 0, 100);
|
||||
applySystemSpeakerVol(volumePct);
|
||||
setBanner("Volume: " + std::to_string(volumePct) + "%", 1200);
|
||||
} else if (dch == '4') {
|
||||
|
||||
@@ -581,8 +581,8 @@ std::vector<BtDeviceEntry> queryBtDevices() {
|
||||
d.profileLabel = "HSP/HFP";
|
||||
} else if (hasPaSink) {
|
||||
d.profileLabel = "A2DP";
|
||||
} else if (hasA2dp && hasHfp) {
|
||||
d.profileLabel = "A2DP+HFP";
|
||||
} else if (hasA2dp) {
|
||||
d.profileLabel = "A2DP";
|
||||
} else if (hasHfp) {
|
||||
d.profileLabel = "HSP/HFP";
|
||||
} else {
|
||||
@@ -1561,8 +1561,9 @@ int runNetworksApp(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
if (isConn && targetBt.kind == BtDevKind::Audio) {
|
||||
runCaptureCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
refreshCurrentTab(false);
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(isConn ? ("Connected: " + targetBt.name) : "Connect failed");
|
||||
} else if (act == 1) {
|
||||
@@ -1592,8 +1593,9 @@ int runNetworksApp(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
if (isPairedOrConn && targetBt.kind == BtDevKind::Audio) {
|
||||
runCaptureCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
refreshCurrentTab(false);
|
||||
std::ofstream ofs("/tmp/sxmo_audio_out_device", std::ios::trunc);
|
||||
if (ofs) ofs << "Bluetooth\n";
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(isPairedOrConn ? ("Paired & connected: " + targetBt.name)
|
||||
: ("Pairing failed: " + targetBt.name));
|
||||
|
||||
@@ -500,20 +500,35 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
settings = loadRingSettings();
|
||||
int rvol = std::clamp(settings.ringVol, 0, 100);
|
||||
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100);
|
||||
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
|
||||
std::string volArg = "--volume=100";
|
||||
std::string loopArg = singleShot ? "--loop=no" : "--loop=2";
|
||||
runAsyncCmd("amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX1 MIX1 INP1'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
runAsyncCmd("outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
|
||||
"if [ \"$outdev\" = \"Bluetooth\" ]; then "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 0 >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ " + std::to_string(rvol) + "% >/dev/null 2>&1; "
|
||||
"elif [ \"$outdev\" = \"Headphones\" ]; then "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX1 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX2 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
"else "
|
||||
" amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX1 MIX1 INP1'\" 0 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX3 Digital Volume'\" " + std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
" wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
" (sleep 0.25; amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
"wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
"(sleep 0.25; amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1) &");
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1) & "
|
||||
"fi");
|
||||
pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
std::string runtimeDir = "/run/user/" + std::to_string(::getuid());
|
||||
@@ -981,10 +996,19 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
settings.ringVol = std::clamp(settings.ringVol + delta * 5, 0, 100);
|
||||
saveRingSettings(settings);
|
||||
if (previewPid > 0) {
|
||||
int rx3 = (settings.ringVol <= 0) ? 0 : (56 + (settings.ringVol * 32 + 50) / 100);
|
||||
runAsyncCmd("amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1");
|
||||
int rvol = settings.ringVol;
|
||||
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100);
|
||||
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
|
||||
runAsyncCmd("outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
|
||||
"if [ \"$outdev\" = \"Bluetooth\" ]; then "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ " + std::to_string(rvol) + "% >/dev/null 2>&1; "
|
||||
"elif [ \"$outdev\" = \"Headphones\" ]; then "
|
||||
" amixer -c 0 cset \"name='RX1 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
" amixer -c 0 cset \"name='RX2 Digital Volume'\" " + std::to_string(hp) + " >/dev/null 2>&1; "
|
||||
"else "
|
||||
" amixer -c 0 cset \"name='RX3 Digital Volume'\" " + std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
" wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1; "
|
||||
"fi");
|
||||
}
|
||||
setBanner("Ring volume: " + std::to_string(settings.ringVol) + "%");
|
||||
} else if (settingsRow == 4) {
|
||||
|
||||
@@ -809,15 +809,16 @@ void ensureAlsaMultimediaRouting() {
|
||||
runAsyncCmd(
|
||||
"outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
|
||||
"if [ \"$outdev\" = \"Earpiece\" ] || [ -z \"$outdev\" ]; then "
|
||||
" if [ \"$(cat /tmp/sxmo_jack_plugged 2>/dev/null)\" = \"1\" ]; then "
|
||||
" if [ -n \"$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\\./ { print $2; exit }')\" ]; then "
|
||||
" sxmo_audio.sh out set Bluetooth >/dev/null 2>&1; "
|
||||
" elif [ \"$(cat /tmp/sxmo_jack_plugged 2>/dev/null)\" = \"1\" ]; then "
|
||||
" sxmo_audio.sh out set Headphones >/dev/null 2>&1; "
|
||||
" else "
|
||||
" sxmo_audio.sh out set Speaker >/dev/null 2>&1; "
|
||||
" fi; "
|
||||
"fi; "
|
||||
"amixer -q -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
"amixer -q -c 0 cset \"name='RX3 MIX1 INP1'\" 'RX1' >/dev/null 2>&1; "
|
||||
"amixer -q -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1");
|
||||
"else "
|
||||
" sxmo_audio.sh device apply >/dev/null 2>&1; "
|
||||
"fi");
|
||||
}
|
||||
|
||||
bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
|
||||
|
||||
@@ -765,17 +765,46 @@ class PcmAudioOut {
|
||||
return sysMuted_;
|
||||
}
|
||||
|
||||
static std::string currentOutDev() {
|
||||
std::ifstream dfs("/tmp/sxmo_audio_out_device");
|
||||
std::string d = "Speaker";
|
||||
if (dfs) std::getline(dfs, d);
|
||||
if (d.find("Bluetooth") != std::string::npos ||
|
||||
d.find("bluetooth") != std::string::npos) {
|
||||
return "Bluetooth";
|
||||
}
|
||||
if (d.find("Headphone") != std::string::npos ||
|
||||
d.find("Headset") != std::string::npos) {
|
||||
return "Headphones";
|
||||
}
|
||||
if (d.find("Earpiece") != std::string::npos) {
|
||||
return "Earpiece";
|
||||
}
|
||||
return "Speaker";
|
||||
}
|
||||
|
||||
static std::string volFileForOutDev(const std::string& cfgDir,
|
||||
const std::string& outDev) {
|
||||
if (outDev == "Bluetooth") return cfgDir + "/bluetooth_vol";
|
||||
if (outDev == "Headphones") return cfgDir + "/headphones_vol";
|
||||
if (outDev == "Earpiece") return cfgDir + "/earpiece_vol";
|
||||
return cfgDir + "/speaker_vol";
|
||||
}
|
||||
|
||||
void refreshVolumeIfNeeded(int64_t tNow) {
|
||||
if (tNow - lastVolCheckMs_ < 500) return;
|
||||
lastVolCheckMs_ = tNow;
|
||||
const char* xdg = std::getenv("XDG_CONFIG_HOME");
|
||||
std::string path =
|
||||
((xdg && xdg[0]) ? (std::string(xdg) + "/sxmo")
|
||||
: (getHomeDir() + "/.config/sxmo")) +
|
||||
"/speaker_vol";
|
||||
std::string cfgDir =
|
||||
(xdg && xdg[0]) ? (std::string(xdg) + "/sxmo")
|
||||
: (getHomeDir() + "/.config/sxmo");
|
||||
std::string outDev = currentOutDev();
|
||||
std::string path = volFileForOutDev(cfgDir, outDev);
|
||||
struct stat st {};
|
||||
if (::stat(path.c_str(), &st) == 0 &&
|
||||
st.st_mtim.tv_sec != lastVolMtime_) {
|
||||
if (outDev != lastOutDev_ ||
|
||||
(::stat(path.c_str(), &st) == 0 &&
|
||||
st.st_mtim.tv_sec != lastVolMtime_)) {
|
||||
lastOutDev_ = outDev;
|
||||
lastVolMtime_ = st.st_mtim.tv_sec;
|
||||
refreshVolume(false);
|
||||
}
|
||||
@@ -788,10 +817,12 @@ class PcmAudioOut {
|
||||
std::string cfgDir =
|
||||
(xdg && xdg[0]) ? (std::string(xdg) + "/sxmo")
|
||||
: (getHomeDir() + "/.config/sxmo");
|
||||
std::string outDev = currentOutDev();
|
||||
lastOutDev_ = outDev;
|
||||
|
||||
int pct = -1;
|
||||
{
|
||||
std::string volPath = cfgDir + "/speaker_vol";
|
||||
std::string volPath = volFileForOutDev(cfgDir, outDev);
|
||||
struct stat st {};
|
||||
if (::stat(volPath.c_str(), &st) == 0) {
|
||||
lastVolMtime_ = st.st_mtim.tv_sec;
|
||||
@@ -805,7 +836,7 @@ class PcmAudioOut {
|
||||
bool spkSwitch = true;
|
||||
long rx3Cur = 84;
|
||||
snd_ctl_t* ctl = nullptr;
|
||||
if (snd_ctl_open(&ctl, "hw:0", 0) == 0 && ctl) {
|
||||
if (outDev == "Speaker" && snd_ctl_open(&ctl, "hw:0", 0) == 0 && ctl) {
|
||||
spkSwitch = readCtlBool(ctl, "SPK DAC Switch", true);
|
||||
rx3Cur = readCtlInt(ctl, "RX3 Digital Volume", 84);
|
||||
if (pct < 0 || pct > 100) {
|
||||
@@ -828,12 +859,19 @@ class PcmAudioOut {
|
||||
}
|
||||
snd_ctl_close(ctl);
|
||||
} else {
|
||||
if (pct < 0 || pct > 100) pct = 75;
|
||||
if (pct < 0 || pct > 100) pct = (outDev == "Bluetooth" || outDev == "Headphones") ? 80 : 85;
|
||||
pct = std::clamp((pct / 5) * 5, 0, 100);
|
||||
}
|
||||
|
||||
bool outMutedFile = false;
|
||||
{
|
||||
std::ifstream mfs("/tmp/sxmo_out_muted");
|
||||
int m = 0;
|
||||
if (mfs && (mfs >> m) && m == 1) outMutedFile = true;
|
||||
}
|
||||
|
||||
speakerPct_ = pct;
|
||||
sysMuted_ = !spkSwitch || (pct <= 0);
|
||||
sysMuted_ = outMutedFile || (outDev == "Speaker" && !spkSwitch) || (pct <= 0);
|
||||
if (sysMuted_) {
|
||||
volScale_ = 0;
|
||||
} else {
|
||||
@@ -849,8 +887,9 @@ class PcmAudioOut {
|
||||
(xdg && xdg[0]) ? (std::string(xdg) + "/sxmo")
|
||||
: (getHomeDir() + "/.config/sxmo");
|
||||
ensureDir(cfgDir);
|
||||
std::string outDev = currentOutDev();
|
||||
{
|
||||
std::ofstream ofs(cfgDir + "/speaker_vol", std::ios::trunc);
|
||||
std::ofstream ofs(volFileForOutDev(cfgDir, outDev), std::ios::trunc);
|
||||
if (ofs) ofs << nextPct << "\n";
|
||||
}
|
||||
char cmd[128];
|
||||
@@ -1026,27 +1065,16 @@ class PcmAudioOut {
|
||||
for (int di = 0; di < 3; ++di) {
|
||||
const char* dev = devs[di];
|
||||
if (snd_pcm_open(&h, dev, SND_PCM_STREAM_PLAYBACK, 0) >= 0) {
|
||||
if (configureLowLatency(h)) {
|
||||
if (configureLowLatency(h) ||
|
||||
snd_pcm_set_params(h, SND_PCM_FORMAT_S16_LE,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000, 1,
|
||||
25000) >= 0) {
|
||||
break;
|
||||
}
|
||||
snd_pcm_close(h);
|
||||
h = nullptr;
|
||||
}
|
||||
}
|
||||
if (!h) {
|
||||
for (int di = 0; di < 3; ++di) {
|
||||
const char* dev = devs[di];
|
||||
if (snd_pcm_open(&h, dev, SND_PCM_STREAM_PLAYBACK, 0) >= 0) {
|
||||
if (snd_pcm_set_params(h, SND_PCM_FORMAT_S16_LE,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED, 2, 48000, 1,
|
||||
25000) >= 0) {
|
||||
break;
|
||||
}
|
||||
snd_pcm_close(h);
|
||||
h = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!h) {
|
||||
threadRunning_.store(false, std::memory_order_release);
|
||||
return;
|
||||
@@ -1214,6 +1242,7 @@ class PcmAudioOut {
|
||||
std::atomic<int32_t> volScale_{21};
|
||||
int64_t lastVolCheckMs_ = 0;
|
||||
time_t lastVolMtime_ = 0;
|
||||
std::string lastOutDev_;
|
||||
unsigned accumSamples_ = 0;
|
||||
int32_t currentL_ = 0;
|
||||
int32_t currentR_ = 0;
|
||||
|
||||
@@ -83,17 +83,51 @@ class AlsaSoundEngine {
|
||||
// Cheap enough to call from the mixer thread every 500 ms: it stats the
|
||||
// file and only re-reads it when its mtime changes, and samples the two
|
||||
// ALSA controls directly.
|
||||
static std::string currentOutDev() {
|
||||
std::string d = "Speaker";
|
||||
FILE* f = std::fopen("/tmp/sxmo_audio_out_device", "r");
|
||||
if (f) {
|
||||
char buf[64] = {};
|
||||
if (std::fgets(buf, sizeof(buf), f)) {
|
||||
d = buf;
|
||||
}
|
||||
std::fclose(f);
|
||||
}
|
||||
if (d.find("Bluetooth") != std::string::npos ||
|
||||
d.find("bluetooth") != std::string::npos) {
|
||||
return "Bluetooth";
|
||||
}
|
||||
if (d.find("Headphone") != std::string::npos ||
|
||||
d.find("Headset") != std::string::npos) {
|
||||
return "Headphones";
|
||||
}
|
||||
if (d.find("Earpiece") != std::string::npos) {
|
||||
return "Earpiece";
|
||||
}
|
||||
return "Speaker";
|
||||
}
|
||||
|
||||
static std::string volFileForOutDev(const std::string& cfgDir,
|
||||
const std::string& outDev) {
|
||||
if (outDev == "Bluetooth") return cfgDir + "/bluetooth_vol";
|
||||
if (outDev == "Headphones") return cfgDir + "/headphones_vol";
|
||||
if (outDev == "Earpiece") return cfgDir + "/earpiece_vol";
|
||||
return cfgDir + "/speaker_vol";
|
||||
}
|
||||
|
||||
void refreshSystemVolume(bool force) {
|
||||
std::lock_guard<std::mutex> lk(volMu_);
|
||||
std::string path = sxmoConfigDir() + "/speaker_vol";
|
||||
std::string outDev = currentOutDev();
|
||||
std::string path = volFileForOutDev(sxmoConfigDir(), outDev);
|
||||
struct stat st {};
|
||||
bool haveFile = (::stat(path.c_str(), &st) == 0);
|
||||
int64_t mtimeNs = haveFile ? (static_cast<int64_t>(st.st_mtim.tv_sec) *
|
||||
1000000000LL +
|
||||
st.st_mtim.tv_nsec)
|
||||
: -1;
|
||||
if (force || mtimeNs != lastVolMtimeNs_) {
|
||||
if (force || mtimeNs != lastVolMtimeNs_ || outDev != lastOutDev_) {
|
||||
lastVolMtimeNs_ = mtimeNs;
|
||||
lastOutDev_ = outDev;
|
||||
filePct_ = -1;
|
||||
if (haveFile) {
|
||||
FILE* f = std::fopen(path.c_str(), "r");
|
||||
@@ -107,26 +141,26 @@ class AlsaSoundEngine {
|
||||
}
|
||||
}
|
||||
|
||||
bool spkOn = true;
|
||||
long rx3 = 92;
|
||||
snd_ctl_t* ctl = nullptr;
|
||||
if (snd_ctl_open(&ctl, "hw:0", 0) == 0 && ctl) {
|
||||
spkOn = readCtlBool(ctl, "SPK DAC Switch", true);
|
||||
rx3 = readCtlInt(ctl, "RX3 Digital Volume", 92);
|
||||
snd_ctl_close(ctl);
|
||||
}
|
||||
|
||||
int pct = filePct_;
|
||||
if (pct < 0) {
|
||||
// Same RX3 -> percentage mapping as xdrawer (60..92 => 0..100%)
|
||||
if (rx3 <= 0) {
|
||||
pct = 0;
|
||||
} else if (rx3 >= 92) {
|
||||
pct = 100;
|
||||
if (outDev == "Speaker") {
|
||||
long rx3 = 92;
|
||||
snd_ctl_t* ctl = nullptr;
|
||||
if (snd_ctl_open(&ctl, "hw:0", 0) == 0 && ctl) {
|
||||
rx3 = readCtlInt(ctl, "RX3 Digital Volume", 92);
|
||||
snd_ctl_close(ctl);
|
||||
}
|
||||
if (rx3 <= 0) {
|
||||
pct = 0;
|
||||
} else if (rx3 >= 92) {
|
||||
pct = 100;
|
||||
} else {
|
||||
pct = std::clamp(static_cast<int>(std::lround(((rx3 - 60) * 100.0) /
|
||||
32.0)),
|
||||
5, 100);
|
||||
}
|
||||
} else {
|
||||
pct = std::clamp(static_cast<int>(std::lround(((rx3 - 60) * 100.0) /
|
||||
32.0)),
|
||||
5, 100);
|
||||
pct = (outDev == "Bluetooth" || outDev == "Headphones") ? 80 : 85;
|
||||
}
|
||||
}
|
||||
volumePct.store(pct, std::memory_order_relaxed);
|
||||
@@ -141,8 +175,9 @@ class AlsaSoundEngine {
|
||||
pct = std::clamp(pct, 0, 100);
|
||||
std::string dir = sxmoConfigDir();
|
||||
::mkdir(dir.c_str(), 0755);
|
||||
std::string outDev = currentOutDev();
|
||||
{
|
||||
FILE* f = std::fopen((dir + "/speaker_vol").c_str(), "w");
|
||||
FILE* f = std::fopen(volFileForOutDev(dir, outDev).c_str(), "w");
|
||||
if (f) {
|
||||
std::fprintf(f, "%d\n", pct);
|
||||
std::fclose(f);
|
||||
@@ -374,6 +409,7 @@ class AlsaSoundEngine {
|
||||
// System speaker volume tracking (see refreshSystemVolume)
|
||||
std::mutex volMu_;
|
||||
int64_t lastVolMtimeNs_ = -2;
|
||||
std::string lastOutDev_;
|
||||
int filePct_ = -1;
|
||||
std::atomic<bool> sysMuted_{false};
|
||||
std::atomic<float> sysGain_{1.0f};
|
||||
@@ -1163,7 +1199,8 @@ class AlsaSoundEngine {
|
||||
}
|
||||
|
||||
if (!pcm) {
|
||||
bool preferDefault = (::access("/run/bluetoothd.pid", F_OK) == 0);
|
||||
bool preferDefault = (currentOutDev() == "Bluetooth") ||
|
||||
(::access("/run/bluetoothd.pid", F_OK) == 0);
|
||||
const char* devsHwFirst[] = {"hw:0,0", "default", "plughw:0,0"};
|
||||
const char* devsDefFirst[] = {"default", "hw:0,0", "plughw:0,0"};
|
||||
const char** devs = preferDefault ? devsDefFirst : devsHwFirst;
|
||||
|
||||
Reference in new issue
Block a user