summaryrefslogtreecommitdiffstats
path: root/meta-agl-profile-core/recipes-multimedia/pulseaudio/pulseaudio/0022-device-port-Add-pa_device_port.active.patch
blob: 4a8143f6159739003e0bf6f8cc9a05a15c4c59c6 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
--- a/src/pulsecore/core.h	2016-04-13 16:38:56.392014788 +0200
+++ b/src/pulsecore/core.h	2016-04-13 16:41:50.331014498 +0200
@@ -125,6 +125,7 @@
     PA_CORE_HOOK_CARD_PROFILE_ADDED,
     PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED,
     PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,
+    PA_CORE_HOOK_PORT_ACTIVE_CHANGED,
     PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED,
     PA_CORE_HOOK_MAX
 } pa_core_hook_t;
--- a/src/pulsecore/device-port.c	2016-04-13 16:39:37.411014719 +0200
+++ b/src/pulsecore/device-port.c	2016-04-13 17:06:47.393011999 +0200
@@ -175,6 +175,21 @@
     pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], p);
 }
 
+void pa_device_port_active_changed(pa_device_port *port, bool new_active) {
+    bool old_active;
+
+    pa_assert(port);
+
+    old_active = port->active;
+
+    if (new_active == old_active)
+        return;
+
+    port->active = new_active;
+    pa_log_debug("Port %s %s.", port->name, new_active ? "activated" : "deactivated");
+    pa_hook_fire(&port->core->hooks[PA_CORE_HOOK_PORT_ACTIVE_CHANGED], port);
+}
+
 pa_device_port *pa_device_port_find_best(pa_hashmap *ports)
 {
     void *state;
--- a/src/pulsecore/device-port.h	2016-04-13 16:39:51.603014696 +0200
+++ b/src/pulsecore/device-port.h	2016-04-13 17:07:12.649011957 +0200
@@ -46,6 +46,7 @@
 
     unsigned priority;
     pa_available_t available;         /* PA_AVAILABLE_UNKNOWN, PA_AVAILABLE_NO or PA_AVAILABLE_YES */
+    bool active;
 
     pa_proplist *proplist;
     pa_hashmap *profiles; /* Does not own the profiles */
--- a/src/pulsecore/sink.c	2016-04-13 16:40:11.131014663 +0200
+++ b/src/pulsecore/sink.c	2016-04-13 17:14:30.963011225 +0200
@@ -658,6 +658,9 @@
     else
         pa_assert_se(sink_set_state(s, PA_SINK_IDLE) == 0);
 
+    if (s->active_port)
+        pa_device_port_active_changed(s->active_port, true);
+
     pa_source_put(s->monitor_source);
 
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index);
@@ -685,6 +688,9 @@
     if (linked)
         pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_UNLINK], s);
 
+    if (s->active_port)
+        pa_device_port_active_changed(s->active_port, false);
+
     if (s->state != PA_SINK_UNLINKED)
         pa_namereg_unregister(s->core, s->name);
     pa_idxset_remove_by_data(s->core->sinks, s, NULL);
@@ -3297,6 +3303,7 @@
 /* Called from main context */
 int pa_sink_set_port(pa_sink *s, const char *name, bool save) {
     pa_device_port *port;
+    pa_device_port *old_port;
     int ret;
 
     pa_sink_assert_ref(s);
@@ -3313,11 +3320,15 @@
     if (!(port = pa_hashmap_get(s->ports, name)))
         return -PA_ERR_NOENTITY;
 
-    if (s->active_port == port) {
+    old_port = s->active_port;
+
+    if (port == old_port) {
         s->save_port = s->save_port || save;
         return 0;
     }
 
+    pa_device_port_active_changed(old_port, false);
+
     if (s->flags & PA_SINK_DEFERRED_VOLUME) {
         struct sink_message_set_port msg = { .port = port, .ret = 0 };
         pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_PORT, &msg, 0, NULL) == 0);
@@ -3326,17 +3337,26 @@
     else
         ret = s->set_port(s, port);
 
-    if (ret < 0)
-        return -PA_ERR_NOENTITY;
+    if (ret < 0) {
+        pa_log("Failed to set the port of sink %s from %s to %s.", s->name, old_port->name, port->name);
+
+        /* We don't know the real state of the device, but let's assume that
+         * the old port is still active, because s->active_port is left to
+         * point to the old port anyway. */
+        pa_device_port_active_changed(old_port, true);
+
+        return ret;
+    }
 
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 
-    pa_log_info("Changed port of sink %u \"%s\" to %s", s->index, s->name, port->name);
+    pa_log_info("Changed port of sink %u \"%s\" from %s to %s", s->index, s->name, old_port->name, port->name);
 
     s->active_port = port;
     s->save_port = save;
 
     pa_sink_set_latency_offset(s, s->active_port->latency_offset);
+    pa_device_port_active_changed(port, true);
 
     pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], s);
 
--- a/src/pulsecore/source.c	2016-04-13 16:40:25.290014640 +0200
+++ b/src/pulsecore/source.c	2016-04-13 17:21:26.051010533 +0200
@@ -603,6 +603,9 @@
     else
         pa_assert_se(source_set_state(s, PA_SOURCE_IDLE) == 0);
 
+    if (s->active_port)
+        pa_device_port_active_changed(s->active_port, true);
+
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index);
     pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PUT], s);
 }
@@ -623,6 +626,9 @@
     if (linked)
         pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], s);
 
+    if (s->active_port)
+        pa_device_port_active_changed(s->active_port, false);
+
     if (s->state != PA_SOURCE_UNLINKED)
         pa_namereg_unregister(s->core, s->name);
     pa_idxset_remove_by_data(s->core->sources, s, NULL);
@@ -2576,6 +2582,7 @@
 /* Called from main context */
 int pa_source_set_port(pa_source *s, const char *name, bool save) {
     pa_device_port *port;
+    pa_device_port *old_port;
     int ret;
 
     pa_source_assert_ref(s);
@@ -2592,11 +2599,15 @@
     if (!(port = pa_hashmap_get(s->ports, name)))
         return -PA_ERR_NOENTITY;
 
-    if (s->active_port == port) {
+    old_port = s->active_port;
+
+    if (port == old_port) {
         s->save_port = s->save_port || save;
         return 0;
     }
 
+    pa_device_port_active_changed(old_port, false);
+
     if (s->flags & PA_SOURCE_DEFERRED_VOLUME) {
         struct source_message_set_port msg = { .port = port, .ret = 0 };
         pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_PORT, &msg, 0, NULL) == 0);
@@ -2605,16 +2616,26 @@
     else
         ret = s->set_port(s, port);
 
-    if (ret < 0)
-        return -PA_ERR_NOENTITY;
+    if (ret < 0) {
+        pa_log("Failed to set the port of sink %s from %s to %s.", s->name, old_port->name, port->name);
+
+        /* We don't know the real state of the device, but let's assume that
+         * the old port is still active, because s->active_port is left to
+         * point to the old port anyway. */
+        pa_device_port_active_changed(old_port, true);
+
+        return ret;
+    }
 
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
 
-    pa_log_info("Changed port of source %u \"%s\" to %s", s->index, s->name, port->name);
+    pa_log_info("Changed port of source %u \"%s\" from %s to %s", s->index, s->name, old_port->name, port->name);
 
     s->active_port = port;
     s->save_port = save;
 
+    pa_device_port_active_changed(port, true);
+
     pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], s);
 
     return 0;