~binli/ubuntu/vivid/pulseaudio/load-extcon-module

« back to all changes in this revision

Viewing changes to src/modules/alsa/module-alsa-source.c

  • Committer: Bin Li
  • Date: 2016-01-23 15:04:48 UTC
  • Revision ID: bin.li@canonical.com-20160123150448-5ockvw4p5xxntda4
init the 1:6.0-0ubuntu9.15 from silo 12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***
 
2
  This file is part of PulseAudio.
 
3
 
 
4
  Copyright 2004-2008 Lennart Poettering
 
5
  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
6
 
 
7
  PulseAudio is free software; you can redistribute it and/or modify
 
8
  it under the terms of the GNU Lesser General Public License as published
 
9
  by the Free Software Foundation; either version 2.1 of the License,
 
10
  or (at your option) any later version.
 
11
 
 
12
  PulseAudio is distributed in the hope that it will be useful, but
 
13
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
  General Public License for more details.
 
16
 
 
17
  You should have received a copy of the GNU Lesser General Public License
 
18
  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 
19
***/
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
 
 
27
#include <asoundlib.h>
 
28
 
 
29
#ifdef HAVE_VALGRIND_MEMCHECK_H
 
30
#include <valgrind/memcheck.h>
 
31
#endif
 
32
 
 
33
#include <pulsecore/module.h>
 
34
#include <pulsecore/modargs.h>
 
35
#include <pulsecore/log.h>
 
36
#include <pulsecore/macro.h>
 
37
 
 
38
#include "alsa-util.h"
 
39
#include "alsa-source.h"
 
40
#include "module-alsa-source-symdef.h"
 
41
 
 
42
PA_MODULE_AUTHOR("Lennart Poettering");
 
43
PA_MODULE_DESCRIPTION("ALSA Source");
 
44
PA_MODULE_VERSION(PACKAGE_VERSION);
 
45
PA_MODULE_LOAD_ONCE(false);
 
46
PA_MODULE_USAGE(
 
47
        "name=<name for the source, to be prefixed> "
 
48
        "source_name=<name for the source> "
 
49
        "source_properties=<properties for the source> "
 
50
        "namereg_fail=<when false attempt to synthesise new source_name if it is already taken> "
 
51
        "device=<ALSA device> "
 
52
        "device_id=<ALSA card index> "
 
53
        "format=<sample format> "
 
54
        "rate=<sample rate> "
 
55
        "alternate_rate=<alternate sample rate> "
 
56
        "channels=<number of channels> "
 
57
        "channel_map=<channel map> "
 
58
        "fragments=<number of fragments> "
 
59
        "fragment_size=<fragment size> "
 
60
        "mmap=<enable memory mapping?> "
 
61
        "tsched=<enable system timer based scheduling mode?> "
 
62
        "tsched_buffer_size=<buffer size when using timer based scheduling> "
 
63
        "tsched_buffer_watermark=<upper fill watermark> "
 
64
        "ignore_dB=<ignore dB information from the device?> "
 
65
        "control=<name of mixer control>"
 
66
        "deferred_volume=<Synchronize software and hardware volume changes to avoid momentary jumps?> "
 
67
        "deferred_volume_safety_margin=<usec adjustment depending on volume direction> "
 
68
        "deferred_volume_extra_delay=<usec adjustment to HW volume changes> "
 
69
        "fixed_latency_range=<disable latency range changes on overrun?>");
 
70
 
 
71
static const char* const valid_modargs[] = {
 
72
    "name",
 
73
    "source_name",
 
74
    "source_properties",
 
75
    "namereg_fail",
 
76
    "device",
 
77
    "device_id",
 
78
    "format",
 
79
    "rate",
 
80
    "alternate_rate",
 
81
    "channels",
 
82
    "channel_map",
 
83
    "fragments",
 
84
    "fragment_size",
 
85
    "mmap",
 
86
    "tsched",
 
87
    "tsched_buffer_size",
 
88
    "tsched_buffer_watermark",
 
89
    "ignore_dB",
 
90
    "control",
 
91
    "deferred_volume",
 
92
    "deferred_volume_safety_margin",
 
93
    "deferred_volume_extra_delay",
 
94
    "fixed_latency_range",
 
95
    NULL
 
96
};
 
97
 
 
98
int pa__init(pa_module*m) {
 
99
    pa_modargs *ma = NULL;
 
100
 
 
101
    pa_assert(m);
 
102
 
 
103
    pa_alsa_refcnt_inc();
 
104
 
 
105
    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
 
106
        pa_log("Failed to parse module arguments");
 
107
        goto fail;
 
108
    }
 
109
 
 
110
    if (!(m->userdata = pa_alsa_source_new(m, ma, __FILE__, NULL, NULL)))
 
111
        goto fail;
 
112
 
 
113
    pa_modargs_free(ma);
 
114
 
 
115
    return 0;
 
116
 
 
117
fail:
 
118
 
 
119
    if (ma)
 
120
        pa_modargs_free(ma);
 
121
 
 
122
    pa__done(m);
 
123
 
 
124
    return -1;
 
125
}
 
126
 
 
127
int pa__get_n_used(pa_module *m) {
 
128
    pa_source *source;
 
129
 
 
130
    pa_assert(m);
 
131
    pa_assert_se(source = m->userdata);
 
132
 
 
133
    return pa_source_linked_by(source);
 
134
}
 
135
 
 
136
void pa__done(pa_module*m) {
 
137
    pa_source *source;
 
138
 
 
139
    pa_assert(m);
 
140
 
 
141
    if ((source = m->userdata))
 
142
        pa_alsa_source_free(source);
 
143
 
 
144
    pa_alsa_refcnt_dec();
 
145
}