i18n: remove unneeded files from POTFILES.in
[platform/upstream/pulseaudio.git] / 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 pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *data) {
30     pa_assert(data);
31
32     pa_zero(*data);
33     data->available = PA_AVAILABLE_UNKNOWN;
34     return data;
35 }
36
37 void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const char *name) {
38     pa_assert(data);
39
40     pa_xfree(data->name);
41     data->name = pa_xstrdup(name);
42 }
43
44 void pa_device_port_new_data_set_description(pa_device_port_new_data *data, const char *description) {
45     pa_assert(data);
46
47     pa_xfree(data->description);
48     data->description = pa_xstrdup(description);
49 }
50
51 void pa_device_port_new_data_set_available(pa_device_port_new_data *data, pa_available_t available) {
52     pa_assert(data);
53
54     data->available = available;
55 }
56
57 void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_direction_t direction) {
58     pa_assert(data);
59
60     data->direction = direction;
61 }
62
63 void pa_device_port_new_data_done(pa_device_port_new_data *data) {
64     pa_assert(data);
65
66     pa_xfree(data->name);
67     pa_xfree(data->description);
68 }
69
70 void pa_device_port_set_available(pa_device_port *p, pa_available_t status) {
71     pa_core *core;
72
73     pa_assert(p);
74
75     if (p->available == status)
76         return;
77
78 /*    pa_assert(status != PA_AVAILABLE_UNKNOWN); */
79
80     p->available = status;
81     pa_log_debug("Setting port %s to status %s", p->name, status == PA_AVAILABLE_YES ? "yes" :
82        status == PA_AVAILABLE_NO ? "no" : "unknown");
83
84     /* Post subscriptions to the card which owns us */
85     pa_assert_se(core = p->core);
86     pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
87
88     pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
89 }
90
91 static void device_port_free(pa_object *o) {
92     pa_device_port *p = PA_DEVICE_PORT(o);
93
94     pa_assert(p);
95     pa_assert(pa_device_port_refcnt(p) == 0);
96
97     if (p->proplist)
98         pa_proplist_free(p->proplist);
99
100     if (p->profiles)
101         pa_hashmap_free(p->profiles, NULL);
102
103     pa_xfree(p->name);
104     pa_xfree(p->description);
105     pa_xfree(p);
106 }
107
108 pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, size_t extra) {
109     pa_device_port *p;
110
111     pa_assert(data);
112     pa_assert(data->name);
113     pa_assert(data->description);
114     pa_assert(data->direction == PA_DIRECTION_OUTPUT || data->direction == PA_DIRECTION_INPUT);
115
116     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));
117     p->parent.free = device_port_free;
118
119     p->name = data->name;
120     data->name = NULL;
121     p->description = data->description;
122     data->description = NULL;
123     p->core = c;
124     p->card = NULL;
125     p->priority = 0;
126     p->available = data->available;
127     p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
128     p->direction = data->direction;
129
130     p->latency_offset = 0;
131     p->proplist = pa_proplist_new();
132
133     return p;
134 }
135
136 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
137     uint32_t state;
138     pa_core *core;
139
140     pa_assert(p);
141
142     if (offset == p->latency_offset)
143         return;
144
145     p->latency_offset = offset;
146
147     switch (p->direction) {
148         case PA_DIRECTION_OUTPUT: {
149             pa_sink *sink;
150
151             PA_IDXSET_FOREACH(sink, p->core->sinks, state) {
152                 if (sink->active_port == p) {
153                     pa_sink_set_latency_offset(sink, p->latency_offset);
154                     break;
155                 }
156             }
157
158             break;
159         }
160
161         case PA_DIRECTION_INPUT: {
162             pa_source *source;
163
164             PA_IDXSET_FOREACH(source, p->core->sources, state) {
165                 if (source->active_port == p) {
166                     pa_source_set_latency_offset(source, p->latency_offset);
167                     break;
168                 }
169             }
170
171             break;
172         }
173     }
174
175     pa_assert_se(core = p->core);
176     pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
177     pa_hook_fire(&core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], p);
178 }