Name Chrome streams after their browser tabs

A browser extension reports audible tabs to moonmix-tabs-host, which matches
them to PipeWire streams by time and publishes the names for the mixer; streams
of one tab share a row. Ambiguous streams keep the browser's name. Without the
extension, a browser's only running stream shows its MPRIS title.

The smoke test no longer claims real audio hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 19:26:29 -08:00
1 parent b61d504234
commit e16cc1b2ad
31 files changed
+1830 -15

No files matched your search

+34
View File
@@ -16,6 +16,7 @@
* details it needs through small accessor functions. All calls happen on the
* GLib default main context (shared with GTK), so no locking is needed.
*/
#include <stdio.h>
#include <string.h>
#include <wp/wp.h>
#include <pipewire/keys.h>
@@ -104,12 +105,21 @@ static void on_node_props(GObject *obj, GParamSpec *pspec, gpointer data) {
emit(MM_EV_NODE_CHANGED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
}
static void on_node_state(WpNode *node, WpNodeState old, WpNodeState now,
gpointer data) {
(void)data;
/* Only running / not running matters. */
if ((old == WP_NODE_STATE_RUNNING) != (now == WP_NODE_STATE_RUNNING))
emit(MM_EV_NODE_CHANGED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(node)));
}
static void on_object_added(WpObjectManager *om, GObject *obj, gpointer d) {
(void)om;
(void)d;
if (WP_IS_NODE(obj)) {
g_signal_connect(obj, "notify::properties", G_CALLBACK(on_node_props),
NULL);
g_signal_connect(obj, "state-changed", G_CALLBACK(on_node_state), NULL);
emit(MM_EV_NODE_ADDED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
} else if (WP_IS_LINK(obj)) {
emit(MM_EV_LINKS_CHANGED, 0);
@@ -121,6 +131,7 @@ static void on_object_removed(WpObjectManager *om, GObject *obj, gpointer d) {
(void)d;
if (WP_IS_NODE(obj)) {
g_signal_handlers_disconnect_by_func(obj, on_node_props, NULL);
g_signal_handlers_disconnect_by_func(obj, on_node_state, NULL);
emit(MM_EV_NODE_REMOVED, (int32_t)wp_proxy_get_bound_id(WP_PROXY(obj)));
} else if (WP_IS_LINK(obj)) {
emit(MM_EV_LINKS_CHANGED, 0);
@@ -300,6 +311,29 @@ MOONBIT_FFI_EXPORT moonbit_bytes_t mm_wp_node_prop(int32_t id,
return to_bytes(v);
}
MOONBIT_FFI_EXPORT int32_t mm_wp_node_running(int32_t id) {
g_autoptr(WpNode) node = lookup_node((guint32)id);
return node && wp_node_get_state(node, NULL) == WP_NODE_STATE_RUNNING;
}
/* Parent of a process (Chrome's audio service -> the browser); 0 if unknown,
* e.g. in a container with its own pid namespace. */
MOONBIT_FFI_EXPORT int32_t mm_wp_parent_pid(int32_t pid) {
char path[64];
g_autofree char *stat = NULL;
int ppid = 0;
if (pid <= 0)
return 0;
g_snprintf(path, sizeof path, "/proc/%d/stat", pid);
if (!g_file_get_contents(path, &stat, NULL, NULL))
return 0;
/* "pid (comm) state ppid ...": comm may itself contain ") ". */
const char *p = strrchr(stat, ')');
if (!p || sscanf(p + 1, " %*c %d", &ppid) != 1)
return 0;
return ppid;
}
/* Volume of the last queried node. */
#define MM_MAX_CH 64
static double g_vol[MM_MAX_CH];