Separate tizenaudio-sink2 and module-tizenaudio-sink2
[platform/core/multimedia/pulseaudio-modules-tizen.git] / src / module-tizenaudio-source2.c
1 /***
2   This file is part of PulseAudio.
3
4   Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
5
6   PulseAudio is free software; you can redistribute it and/or modify
7   it under the terms of the GNU Lesser General Public License as published
8   by the Free Software Foundation; either version 2.1 of the License,
9   or (at your option) any later version.
10
11   PulseAudio is distributed in the hope that it will be useful, but
12   WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public License
17   along with PulseAudio; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19   USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <pulsecore/log.h>
27
28 #include "tizenaudio-source2.h"
29
30 PA_MODULE_AUTHOR("Tizen");
31 PA_MODULE_DESCRIPTION("Tizen Audio Source2");
32 PA_MODULE_VERSION(PACKAGE_VERSION);
33 PA_MODULE_LOAD_ONCE(false);
34 PA_MODULE_USAGE(
35         "source_name=<name of source> "
36         "source_properties=<properties for the source> "
37         "device=<device to use, card comma device (e.g. 0,0)> "
38         "format=<sample format> "
39         "rate=<sample rate> "
40         "channels=<number of channels> "
41         "channel_map=<channel map>"
42         "fragments=<number of fragments> "
43         "fragment_size=<fragment size> ");
44
45 static const char* const valid_modargs[] = {
46     "source_name",
47     "source_properties",
48     "device",
49     "format",
50     "rate",
51     "channels",
52     "channel_map",
53     "fragments",
54     "fragment_size",
55     NULL
56 };
57
58 int pa__init(pa_module *m) {
59     pa_modargs *ma = NULL;
60
61     pa_assert(m);
62
63     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
64         pa_log("Failed to parse module arguments");
65         goto fail;
66     }
67
68     if (!(m->userdata = pa_tizenaudio_source2_new(m, ma, __FILE__)))
69         goto fail;
70
71     pa_modargs_free(ma);
72
73     return 0;
74
75 fail:
76     if (ma)
77         pa_modargs_free(ma);
78
79     pa__done(m);
80
81     return -1;
82 }
83
84 int pa__get_n_used(pa_module *m) {
85     pa_source *s;
86
87     pa_assert(m);
88     pa_assert_se((s = m->userdata));
89
90     return pa_source_linked_by(s);
91 }
92
93 void pa__done(pa_module *m) {
94     pa_source *s;
95
96     pa_assert(m);
97
98     if ((s = m->userdata))
99         pa_tizenaudio_source2_free(s);
100 }