]> code.delx.au - pulseaudio/blob - src/pulsecore/device-port.c
device-port: Make it impossible to have dual-direction ports
[pulseaudio] / src / pulsecore / device-port.c
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 PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
28
29 void pa_device_port_set_available(pa_device_port *p, pa_available_t status)
30 {
31 pa_core *core;
32
33 pa_assert(p);
34
35 if (p->available == status)
36 return;
37
38 /* pa_assert(status != PA_AVAILABLE_UNKNOWN); */
39
40 p->available = status;
41 pa_log_debug("Setting port %s to status %s", p->name, status == PA_AVAILABLE_YES ? "yes" :
42 status == PA_AVAILABLE_NO ? "no" : "unknown");
43
44 /* Post subscriptions to the card which owns us */
45 pa_assert_se(core = p->core);
46 pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
47
48 pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
49 }
50
51 static void device_port_free(pa_object *o) {
52 pa_device_port *p = PA_DEVICE_PORT(o);
53
54 pa_assert(p);
55 pa_assert(pa_device_port_refcnt(p) == 0);
56
57 if (p->proplist)
58 pa_proplist_free(p->proplist);
59
60 if (p->profiles)
61 pa_hashmap_free(p->profiles, NULL);
62
63 pa_xfree(p->name);
64 pa_xfree(p->description);
65 pa_xfree(p);
66 }
67
68
69 pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, pa_direction_t direction, size_t extra) {
70 pa_device_port *p;
71
72 pa_assert(name);
73
74 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));
75 p->parent.free = device_port_free;
76
77 p->core = c;
78 p->name = pa_xstrdup(name);
79 p->description = pa_xstrdup(description);
80 p->core = c;
81 p->card = NULL;
82 p->priority = 0;
83 p->available = PA_AVAILABLE_UNKNOWN;
84 p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
85 p->direction = direction;
86 p->latency_offset = 0;
87 p->proplist = pa_proplist_new();
88
89 return p;
90 }
91
92 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
93 uint32_t state;
94 pa_core *core;
95
96 pa_assert(p);
97
98 if (offset == p->latency_offset)
99 return;
100
101 p->latency_offset = offset;
102
103 switch (p->direction) {
104 case PA_DIRECTION_OUTPUT: {
105 pa_sink *sink;
106
107 PA_IDXSET_FOREACH(sink, p->core->sinks, state) {
108 if (sink->active_port == p) {
109 pa_sink_set_latency_offset(sink, p->latency_offset);
110 break;
111 }
112 }
113
114 break;
115 }
116
117 case PA_DIRECTION_INPUT: {
118 pa_source *source;
119
120 PA_IDXSET_FOREACH(source, p->core->sources, state) {
121 if (source->active_port == p) {
122 pa_source_set_latency_offset(source, p->latency_offset);
123 break;
124 }
125 }
126
127 break;
128 }
129 }
130
131 pa_assert_se(core = p->core);
132 pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
133 pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], p);
134 }