summaryrefslogtreecommitdiff
path: root/debian/patches/0034-match-match-rule-earlier-in-SINK_INPUT_NEW.patch
blob: e3eec8412ff6718be087fed2f1c8cd59a427328b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
From ea035c7695cda6ce47901ece500bbbb308c4c0a1 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@gmail.com>
Date: Wed, 13 May 2009 21:32:03 +0300
Subject: [PATCH 34/85] match: match rule earlier, in SINK_INPUT_NEW

---
 src/modules/module-match.c |   30 +++++++++++-------------------
 1 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/src/modules/module-match.c b/src/modules/module-match.c
index 0014dec..2fea4d0 100644
--- a/src/modules/module-match.c
+++ b/src/modules/module-match.c
@@ -38,7 +38,6 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/modargs.h>
 #include <pulsecore/log.h>
-#include <pulsecore/core-subscribe.h>
 #include <pulsecore/sink-input.h>
 #include <pulsecore/core-util.h>
 
@@ -72,7 +71,7 @@ struct rule {
 struct userdata {
     struct rule *rules;
     char *property_key;
-    pa_subscription *subscription;
+    pa_hook_slot *sink_input_new_hook_slot;
 };
 
 static int load_rules(struct userdata *u, const char *filename) {
@@ -186,23 +185,15 @@ finish:
     return ret;
 }
 
-static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
-    struct userdata *u =  userdata;
-    pa_sink_input *si;
+static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_new_data *si, struct userdata *u) {
     struct rule *r;
     const char *n;
 
     pa_assert(c);
     pa_assert(u);
 
-    if (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW))
-        return;
-
-    if (!(si = pa_idxset_get_by_index(c->sink_inputs, idx)))
-        return;
-
     if (!(n = pa_proplist_gets(si->proplist, u->property_key)))
-        return;
+        return PA_HOOK_OK;
 
     pa_log_debug("Matching with %s", n);
 
@@ -212,13 +203,14 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v
                 pa_log_debug("updating proplist of sink input '%s'", n);
                 pa_proplist_update(si->proplist, PA_UPDATE_MERGE, r->proplist);
             } else {
-                pa_cvolume cv;
                 pa_log_debug("changing volume of sink input '%s' to 0x%03x", n, r->volume);
-                pa_cvolume_set(&cv, si->sample_spec.channels, r->volume);
-                pa_sink_input_set_volume(si, &cv, TRUE, TRUE);
+                pa_cvolume_set(&si->volume, si->sample_spec.channels, r->volume);
+                si->volume_is_set = TRUE;
             }
         }
     }
+
+    return PA_HOOK_OK;
 }
 
 int pa__init(pa_module*m) {
@@ -234,7 +226,6 @@ int pa__init(pa_module*m) {
 
     u = pa_xnew(struct userdata, 1);
     u->rules = NULL;
-    u->subscription = NULL;
     m->userdata = u;
 
     u->property_key = pa_xstrdup(pa_modargs_get_value(ma, "key", PA_PROP_MEDIA_NAME));
@@ -242,7 +233,8 @@ int pa__init(pa_module*m) {
     if (load_rules(u, pa_modargs_get_value(ma, "table", NULL)) < 0)
         goto fail;
 
-    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);
+    /* hook EARLY - 1, to match before stream-restore */
+    u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], PA_HOOK_EARLY - 1, (pa_hook_cb_t) sink_input_new_hook_callback, u);
 
     pa_modargs_free(ma);
     return 0;
@@ -264,8 +256,8 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->subscription)
-        pa_subscription_free(u->subscription);
+    if (u->sink_input_new_hook_slot)
+        pa_hook_slot_free(u->sink_input_new_hook_slot);
 
     if (u->property_key)
         pa_xfree(u->property_key);
-- 
1.6.3.3