1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <config.h>
17 #include <pulsecore/log.h>
18 #include <pulsecore/modargs.h>
19 #include <pulsecore/module.h>
20 #include <stddef.h>
21 #include <stdbool.h>
22
23 pa_source *pa_hdi_source_new(pa_module *m, pa_modargs *ma, const char *driver);
24
25 void pa_hdi_source_free(pa_source *s);
26
27 PA_MODULE_AUTHOR("OpenHarmony");
28 PA_MODULE_DESCRIPTION("OpenHarmony HDI Source");
29 PA_MODULE_VERSION(PACKAGE_VERSION);
30 PA_MODULE_LOAD_ONCE(false);
31 PA_MODULE_USAGE(
32 "source_name=<name for the source> "
33 "device_class=<name for the device class> "
34 "source_properties=<properties for the source> "
35 "format=<sample format> "
36 "rate=<sample rate> "
37 "channels=<number of channels> "
38 "channel_map=<channel map>"
39 "buffer_size=<custom buffer size>"
40 "file_path=<file path for data reading>"
41 "adapter_name=<primary1>"
42 "open_mic_speaker<open mic>"
43 "network_id<device network id>"
44 "device_type<device type or port>"
45 );
46
47 static const char * const VALID_MODARGS[] = {
48 "source_name",
49 "device_class",
50 "source_properties",
51 "format",
52 "rate",
53 "channels",
54 "channel_map",
55 "buffer_size",
56 "file_path",
57 "adapter_name",
58 "open_mic_speaker",
59 "network_id",
60 "device_type",
61 NULL
62 };
63
pa__init(pa_module * m)64 int pa__init(pa_module *m)
65 {
66 pa_modargs *ma = NULL;
67
68 pa_assert(m);
69
70 if (!(ma = pa_modargs_new(m->argument, VALID_MODARGS))) {
71 pa_log("Failed to parse module arguments");
72 goto fail;
73 }
74
75 if (!(m->userdata = pa_hdi_source_new(m, ma, __FILE__))) {
76 goto fail;
77 }
78
79 pa_modargs_free(ma);
80
81 return 0;
82
83 fail:
84
85 if (ma) {
86 pa_modargs_free(ma);
87 }
88
89 pa__done(m);
90
91 return -1;
92 }
93
pa__get_n_used(pa_module * m)94 int pa__get_n_used(pa_module *m)
95 {
96 pa_source *source = NULL;
97
98 pa_assert(m);
99 pa_assert_se(source = m->userdata);
100
101 return pa_source_linked_by(source);
102 }
103
pa__done(pa_module * m)104 void pa__done(pa_module *m)
105 {
106 pa_source *source = NULL;
107
108 pa_assert(m);
109
110 if ((source = m->userdata)) {
111 pa_hdi_source_free(source);
112 }
113 }
114