2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6 Copyright 2011 David Henningsson, Canonical Ltd.
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.
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.
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
24 #include "device-port.h"
25 #include <pulsecore/card.h>
27 PA_DEFINE_PUBLIC_CLASS(pa_device_port
, pa_object
);
29 pa_device_port_new_data
*pa_device_port_new_data_init(pa_device_port_new_data
*data
) {
33 data
->available
= PA_AVAILABLE_UNKNOWN
;
37 void pa_device_port_new_data_set_name(pa_device_port_new_data
*data
, const char *name
) {
41 data
->name
= pa_xstrdup(name
);
44 void pa_device_port_new_data_set_description(pa_device_port_new_data
*data
, const char *description
) {
47 pa_xfree(data
->description
);
48 data
->description
= pa_xstrdup(description
);
51 void pa_device_port_new_data_set_available(pa_device_port_new_data
*data
, pa_available_t available
) {
54 data
->available
= available
;
57 void pa_device_port_new_data_set_direction(pa_device_port_new_data
*data
, pa_direction_t direction
) {
60 data
->direction
= direction
;
63 void pa_device_port_new_data_done(pa_device_port_new_data
*data
) {
67 pa_xfree(data
->description
);
70 void pa_device_port_set_available(pa_device_port
*p
, pa_available_t status
)
76 if (p
->available
== status
)
79 /* pa_assert(status != PA_AVAILABLE_UNKNOWN); */
81 p
->available
= status
;
82 pa_log_debug("Setting port %s to status %s", p
->name
, status
== PA_AVAILABLE_YES
? "yes" :
83 status
== PA_AVAILABLE_NO
? "no" : "unknown");
85 /* Post subscriptions to the card which owns us */
86 pa_assert_se(core
= p
->core
);
87 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_CARD
|PA_SUBSCRIPTION_EVENT_CHANGE
, p
->card
->index
);
89 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED
], p
);
92 static void device_port_free(pa_object
*o
) {
93 pa_device_port
*p
= PA_DEVICE_PORT(o
);
96 pa_assert(pa_device_port_refcnt(p
) == 0);
99 pa_proplist_free(p
->proplist
);
102 pa_hashmap_free(p
->profiles
, NULL
);
105 pa_xfree(p
->description
);
110 pa_device_port
*pa_device_port_new(pa_core
*c
, pa_device_port_new_data
*data
, size_t extra
) {
114 pa_assert(data
->name
);
115 pa_assert(data
->direction
== PA_DIRECTION_OUTPUT
|| data
->direction
== PA_DIRECTION_INPUT
);
117 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
));
118 p
->parent
.free
= device_port_free
;
120 p
->name
= data
->name
;
122 p
->description
= data
->description
;
123 data
->description
= NULL
;
127 p
->available
= data
->available
;
128 p
->profiles
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
129 p
->direction
= data
->direction
;
131 p
->latency_offset
= 0;
132 p
->proplist
= pa_proplist_new();
137 void pa_device_port_set_latency_offset(pa_device_port
*p
, int64_t offset
) {
143 if (offset
== p
->latency_offset
)
146 p
->latency_offset
= offset
;
148 switch (p
->direction
) {
149 case PA_DIRECTION_OUTPUT
: {
152 PA_IDXSET_FOREACH(sink
, p
->core
->sinks
, state
) {
153 if (sink
->active_port
== p
) {
154 pa_sink_set_latency_offset(sink
, p
->latency_offset
);
162 case PA_DIRECTION_INPUT
: {
165 PA_IDXSET_FOREACH(source
, p
->core
->sources
, state
) {
166 if (source
->active_port
== p
) {
167 pa_source_set_latency_offset(source
, p
->latency_offset
);
176 pa_assert_se(core
= p
->core
);
177 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_CARD
|PA_SUBSCRIPTION_EVENT_CHANGE
, p
->card
->index
);
178 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED
], p
);