~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/namereg.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-05-05 14:18:20 UTC
  • mfrom: (1.2.4 upstream) (1.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090505141820-rrr2mtdd1jkllvr8
Tags: 1:0.9.15-1ubuntu1
* Merge from unreleased Debian pulseaudio git, remaining changes:
  - epoch (my stupid fault :S)
  - Don't build against, and create jack package. Jack is not in main
  - use linear resampler to work better with lack of PREEMPT in jaunty's
    -generic kernel config, also change buffer size
  - Add alsa configuration files to route alsa applications via pulseaudio
  - Move libasound2-plugins from Recommends to Depends
  - Add pm-utils sleep hook to suspend (and resume) users' pulseaudio
    daemons
  - patch to fix source/sink and suspend-on-idle race
  - Make initscript more informative in the default case of per-user
    sessions
  - create /var/run/pulse, and make restart more robust
  - add status check for system wide pulseaudio instance
  - LSB {Required-*,Should-*} should specify hal instead of dbus,
    since hal is required (and already requires dbus)
  - indicate that the system pulseaudio instance is being started from the init
    script
  - Install more upstream man pages
  - Link to pacat for parec man page
  - check whether pulseaudio is running before preloading the padsp library
  - Add DEB_OPT_FLAG = -O3 as per recommendation from
    pulseaudio-discuss/2007-December/001017.html
  - cache /usr/share/sounds/ubuntu/stereo/ wav files on pulseaudio load
  - disable glitch free (use tsched=0)
  - Generate a PO template on build
  - add special case to disable pulseaudio loading if accessibility/speech
    is being used
  - the sd wrapper script should not load pulseaudio if pulseaudio is being
    used as a system service
  - add a pulseaudio apport hook
  - fix some typos in README.Debian
  - demote paprefs to suggests
  - drop padevchooser(Recommends) and pavucontrol (Suggests)
  - drop libasyncns-dev build dependency, its in universe
* add libudev-dev as a build-dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
  PulseAudio is free software; you can redistribute it and/or modify
7
7
  it under the terms of the GNU Lesser General Public License as published
8
 
  by the Free Software Foundation; either version 2 of the License,
 
8
  by the Free Software Foundation; either version 2.1 of the License,
9
9
  or (at your option) any later version.
10
10
 
11
11
  PulseAudio is distributed in the hope that it will be useful, but
30
30
 
31
31
#include <pulse/xmalloc.h>
32
32
 
33
 
#include <pulsecore/autoload.h>
34
33
#include <pulsecore/source.h>
35
34
#include <pulsecore/sink.h>
36
35
#include <pulsecore/core-subscribe.h>
88
87
    return n;
89
88
}
90
89
 
91
 
void pa_namereg_free(pa_core *c) {
92
 
    pa_assert(c);
93
 
 
94
 
    if (!c->namereg)
95
 
        return;
96
 
 
97
 
    pa_assert(pa_hashmap_size(c->namereg) == 0);
98
 
    pa_hashmap_free(c->namereg, NULL, NULL);
99
 
}
100
 
 
101
90
const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail) {
102
91
    struct namereg_entry *e;
103
92
    char *n = NULL;
109
98
    if (!*name)
110
99
        return NULL;
111
100
 
112
 
    if ((type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE) &&
 
101
    if ((type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE || type == PA_NAMEREG_CARD) &&
113
102
        !pa_namereg_is_valid_name(name)) {
114
103
 
115
104
        if (fail)
119
108
            return NULL;
120
109
    }
121
110
 
122
 
    if (!c->namereg)
123
 
        c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
124
 
 
125
111
    if ((e = pa_hashmap_get(c->namereg, name)) && fail) {
126
112
        pa_xfree(n);
127
113
        return NULL;
174
160
 
175
161
    pa_assert_se(e = pa_hashmap_remove(c->namereg, name));
176
162
 
 
163
    if (c->default_sink == e->data)
 
164
        pa_namereg_set_default_sink(c, NULL);
 
165
    else if (c->default_source == e->data)
 
166
        pa_namereg_set_default_source(c, NULL);
 
167
 
177
168
    pa_xfree(e->name);
178
169
    pa_xfree(e);
179
170
}
180
171
 
181
 
void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type, pa_bool_t autoload) {
 
172
void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
182
173
    struct namereg_entry *e;
183
174
    uint32_t idx;
184
175
    pa_assert(c);
185
176
 
186
 
    if (!name) {
187
 
 
188
 
        if (type == PA_NAMEREG_SOURCE)
189
 
            name = pa_namereg_get_default_source_name(c);
190
 
        else if (type == PA_NAMEREG_SINK)
191
 
            name = pa_namereg_get_default_sink_name(c);
192
 
 
193
 
    } else if (strcmp(name, "@DEFAULT_SINK@") == 0) {
194
 
        if (type == PA_NAMEREG_SINK)
195
 
               name = pa_namereg_get_default_sink_name(c);
196
 
 
197
 
    } else if (strcmp(name, "@DEFAULT_SOURCE@") == 0) {
198
 
        if (type == PA_NAMEREG_SOURCE)
199
 
            name = pa_namereg_get_default_source_name(c);
200
 
 
201
 
    } else if (strcmp(name, "@DEFAULT_MONITOR@") == 0) {
202
 
        if (type == PA_NAMEREG_SOURCE) {
203
 
            pa_sink *k;
204
 
 
205
 
            if ((k = pa_namereg_get(c, NULL, PA_NAMEREG_SINK, autoload)))
206
 
                return k->monitor_source;
207
 
        }
208
 
    } else if (*name == '@')
209
 
        name = NULL;
 
177
    if (type == PA_NAMEREG_SOURCE && (!name || pa_streq(name, "@DEFAULT_SOURCE@"))) {
 
178
        pa_source *s;
 
179
 
 
180
        if ((s = pa_namereg_get_default_source(c)))
 
181
            return s;
 
182
 
 
183
    } else if (type == PA_NAMEREG_SINK && (!name || pa_streq(name, "@DEFAULT_SINK@"))) {
 
184
        pa_sink *s;
 
185
 
 
186
        if ((s = pa_namereg_get_default_sink(c)))
 
187
            return s;
 
188
 
 
189
    } else if (type == PA_NAMEREG_SOURCE && name && pa_streq(name, "@DEFAULT_MONITOR@")) {
 
190
        pa_sink *s;
 
191
 
 
192
        if ((s = pa_namereg_get(c, NULL, PA_NAMEREG_SINK)))
 
193
            return s->monitor_source;
 
194
 
 
195
    }
210
196
 
211
197
    if (!name)
212
198
        return NULL;
213
199
 
214
 
    if (c->namereg && (e = pa_hashmap_get(c->namereg, name)))
 
200
    if ((type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE || type == PA_NAMEREG_CARD) &&
 
201
        !pa_namereg_is_valid_name(name))
 
202
        return NULL;
 
203
 
 
204
    if ((e = pa_hashmap_get(c->namereg, name)))
215
205
        if (e->type == type)
216
206
            return e->data;
217
207
 
218
 
    if (pa_atou(name, &idx) < 0) {
219
 
 
220
 
        if (autoload) {
221
 
            pa_autoload_request(c, name, type);
222
 
 
223
 
            if (c->namereg && (e = pa_hashmap_get(c->namereg, name)))
224
 
                if (e->type == type)
225
 
                    return e->data;
226
 
        }
227
 
 
 
208
    if (pa_atou(name, &idx) < 0)
228
209
        return NULL;
229
 
    }
230
210
 
231
211
    if (type == PA_NAMEREG_SINK)
232
212
        return pa_idxset_get_by_index(c->sinks, idx);
234
214
        return pa_idxset_get_by_index(c->sources, idx);
235
215
    else if (type == PA_NAMEREG_SAMPLE && c->scache)
236
216
        return pa_idxset_get_by_index(c->scache, idx);
 
217
    else if (type == PA_NAMEREG_CARD)
 
218
        return pa_idxset_get_by_index(c->cards, idx);
237
219
 
238
220
    return NULL;
239
221
}
240
222
 
241
 
int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type) {
242
 
    char **s;
243
 
 
244
 
    pa_assert(c);
245
 
    pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE);
246
 
 
247
 
    s = type == PA_NAMEREG_SINK ? &c->default_sink_name : &c->default_source_name;
248
 
 
249
 
    if (!name && !*s)
250
 
        return 0;
251
 
 
252
 
    if (name && *s && !strcmp(name, *s))
253
 
        return 0;
254
 
 
255
 
    if (!pa_namereg_is_valid_name(name))
256
 
        return -1;
257
 
 
258
 
    pa_xfree(*s);
259
 
    *s = pa_xstrdup(name);
260
 
    pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
261
 
 
262
 
    return 0;
263
 
}
264
 
 
265
 
const char *pa_namereg_get_default_sink_name(pa_core *c) {
 
223
pa_sink* pa_namereg_set_default_sink(pa_core*c, pa_sink *s) {
 
224
    pa_assert(c);
 
225
 
 
226
    if (c->default_sink != s) {
 
227
        c->default_sink = s;
 
228
        pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
 
229
    }
 
230
 
 
231
    return s;
 
232
}
 
233
 
 
234
pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s) {
 
235
    pa_assert(c);
 
236
 
 
237
    if (c->default_source != s) {
 
238
        c->default_source = s;
 
239
        pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
 
240
    }
 
241
 
 
242
    return s;
 
243
}
 
244
 
 
245
pa_sink *pa_namereg_get_default_sink(pa_core *c) {
266
246
    pa_sink *s;
267
247
 
268
248
    pa_assert(c);
269
249
 
270
 
    if (c->default_sink_name)
271
 
        return c->default_sink_name;
 
250
    if (c->default_sink)
 
251
        return c->default_sink;
272
252
 
273
253
    if ((s = pa_idxset_first(c->sinks, NULL)))
274
 
        pa_namereg_set_default(c, s->name, PA_NAMEREG_SINK);
 
254
        return pa_namereg_set_default_sink(c, s);
275
255
 
276
 
    return c->default_sink_name;
 
256
    return NULL;
277
257
}
278
258
 
279
 
const char *pa_namereg_get_default_source_name(pa_core *c) {
 
259
pa_source *pa_namereg_get_default_source(pa_core *c) {
280
260
    pa_source *s;
281
261
    uint32_t idx;
282
262
 
283
263
    pa_assert(c);
284
264
 
285
 
    if (c->default_source_name)
286
 
        return c->default_source_name;
287
 
 
288
 
    for (s = pa_idxset_first(c->sources, &idx); s; s = pa_idxset_next(c->sources, &idx))
289
 
        if (!s->monitor_of) {
290
 
            pa_namereg_set_default(c, s->name, PA_NAMEREG_SOURCE);
291
 
            break;
292
 
        }
293
 
 
294
 
    if (!c->default_source_name)
295
 
        if ((s = pa_idxset_first(c->sources, NULL)))
296
 
            pa_namereg_set_default(c, s->name, PA_NAMEREG_SOURCE);
297
 
 
298
 
    return c->default_source_name;
 
265
    if (c->default_source)
 
266
        return c->default_source;
 
267
 
 
268
    for (s = PA_SOURCE(pa_idxset_first(c->sources, &idx)); s; s = PA_SOURCE(pa_idxset_next(c->sources, &idx)))
 
269
        if (!s->monitor_of)
 
270
            return pa_namereg_set_default_source(c, s);
 
271
 
 
272
    if ((s = pa_idxset_first(c->sources, NULL)))
 
273
        return pa_namereg_set_default_source(c, s);
 
274
 
 
275
    return NULL;
299
276
}