Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006 Lennart Poettering
5 : : Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6 : : Copyright 2011 David Henningsson, Canonical Ltd.
7 : :
8 : : PulseAudio is free software; you can redistribute it and/or modify
9 : : it under the terms of the GNU Lesser General Public License as published
10 : : by the Free Software Foundation; either version 2.1 of the License,
11 : : or (at your option) any later version.
12 : :
13 : : PulseAudio is distributed in the hope that it will be useful, but
14 : : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : : General Public License for more details.
17 : :
18 : : You should have received a copy of the GNU Lesser General Public License
19 : : along with PulseAudio; if not, write to the Free Software
20 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 : : USA.
22 : : ***/
23 : :
24 : : #include "device-port.h"
25 : : #include <pulsecore/card.h>
26 : :
27 [ # # ]: 0 : PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
28 : :
29 : 0 : void pa_device_port_set_available(pa_device_port *p, pa_port_available_t status)
30 : : {
31 : : uint32_t state;
32 : : pa_card *card;
33 : : /* pa_source *source;
34 : : pa_sink *sink; */
35 : : pa_core *core;
36 : :
37 [ # # ]: 0 : pa_assert(p);
38 : :
39 [ # # ]: 0 : if (p->available == status)
40 : 0 : return;
41 : :
42 : : /* pa_assert(status != PA_PORT_AVAILABLE_UNKNOWN); */
43 : :
44 : 0 : p->available = status;
45 [ # # ][ # # ]: 0 : pa_log_debug("Setting port %s to status %s", p->name, status == PA_PORT_AVAILABLE_YES ? "yes" :
46 : : status == PA_PORT_AVAILABLE_NO ? "no" : "unknown");
47 : :
48 : : /* Post subscriptions to the card which owns us */
49 [ # # ]: 0 : pa_assert_se(core = p->core);
50 [ # # ]: 0 : PA_IDXSET_FOREACH(card, core->cards, state)
51 [ # # ]: 0 : if (p == pa_hashmap_get(card->ports, p->name))
52 : 0 : pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
53 : : #if 0
54 : : /* This stuff is temporarily commented out while figuring out whether to actually do this */
55 : : if (p->is_output)
56 : : PA_IDXSET_FOREACH(sink, core->sinks, state)
57 : : if (p == pa_hashmap_get(sink->ports, p->name))
58 : : pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index);
59 : : if (p->is_input)
60 : : PA_IDXSET_FOREACH(source, core->sources, state)
61 : : if (p == pa_hashmap_get(source->ports, p->name))
62 : : pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, source->index);
63 : : #endif
64 : :
65 : 0 : pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
66 : : }
67 : :
68 : 0 : static void device_port_free(pa_object *o) {
69 : 0 : pa_device_port *p = PA_DEVICE_PORT(o);
70 : :
71 [ # # ]: 0 : pa_assert(p);
72 [ # # ]: 0 : pa_assert(pa_device_port_refcnt(p) == 0);
73 : :
74 [ # # ]: 0 : if (p->proplist)
75 : 0 : pa_proplist_free(p->proplist);
76 [ # # ]: 0 : if (p->profiles)
77 : 0 : pa_hashmap_free(p->profiles, NULL, NULL);
78 : 0 : pa_xfree(p->name);
79 : 0 : pa_xfree(p->description);
80 : 0 : pa_xfree(p);
81 : 0 : }
82 : :
83 : :
84 : 0 : pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, size_t extra) {
85 : : pa_device_port *p;
86 : :
87 [ # # ]: 0 : pa_assert(name);
88 : :
89 : 0 : p = PA_DEVICE_PORT(pa_object_new_internal(PA_ALIGN(sizeof(pa_device_port)) + extra, pa_device_port_type_id, pa_device_port_check_type));
90 : 0 : p->parent.free = device_port_free;
91 : :
92 : 0 : p->name = pa_xstrdup(name);
93 : 0 : p->description = pa_xstrdup(description);
94 : 0 : p->core = c;
95 : 0 : p->priority = 0;
96 : 0 : p->available = PA_PORT_AVAILABLE_UNKNOWN;
97 : 0 : p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
98 : 0 : p->is_input = FALSE;
99 : 0 : p->is_output = FALSE;
100 : 0 : p->latency_offset = 0;
101 : 0 : p->proplist = pa_proplist_new();
102 : :
103 : 0 : return p;
104 : : }
105 : :
106 : 0 : void pa_device_port_hashmap_free(pa_hashmap *h) {
107 : : pa_device_port *p;
108 : :
109 [ # # ]: 0 : pa_assert(h);
110 : :
111 [ # # ]: 0 : while ((p = pa_hashmap_steal_first(h)))
112 : : pa_device_port_unref(p);
113 : :
114 : 0 : pa_hashmap_free(h, NULL, NULL);
115 : 0 : }
116 : :
117 : 0 : void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
118 : : uint32_t state;
119 : : pa_core *core;
120 : : pa_card *card;
121 : :
122 [ # # ]: 0 : pa_assert(p);
123 : :
124 : 0 : p->latency_offset = offset;
125 : :
126 [ # # ]: 0 : if (p->is_output) {
127 : : pa_sink *sink;
128 : :
129 [ # # ]: 0 : PA_IDXSET_FOREACH(sink, p->core->sinks, state)
130 [ # # ]: 0 : if (sink->active_port == p) {
131 : 0 : pa_sink_set_latency_offset(sink, p->latency_offset);
132 : 0 : break;
133 : : }
134 : :
135 : : } else {
136 : : pa_source *source;
137 : :
138 [ # # ]: 0 : PA_IDXSET_FOREACH(source, p->core->sources, state)
139 [ # # ]: 0 : if (source->active_port == p) {
140 : 0 : pa_source_set_latency_offset(source, p->latency_offset);
141 : 0 : break;
142 : : }
143 : : }
144 : :
145 [ # # ]: 0 : pa_assert_se(core = p->core);
146 [ # # ]: 0 : PA_IDXSET_FOREACH(card, core->cards, state)
147 [ # # ]: 0 : if (p == pa_hashmap_get(card->ports, p->name))
148 : 0 : pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
149 : 0 : }
|