• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *PaHdiSourceNew(pa_module *m, pa_modargs *ma, const char *driver);
24 void PaHdiSourceFree(pa_source *s);
25 
26 PA_MODULE_AUTHOR("OpenHarmony");
27 PA_MODULE_DESCRIPTION("OpenHarmony HDI Source");
28 PA_MODULE_VERSION(PACKAGE_VERSION);
29 PA_MODULE_LOAD_ONCE(false);
30 PA_MODULE_USAGE(
31         "source_name=<name for the source> "
32         "device_class=<name for the device class> "
33         "source_properties=<properties for the source> "
34         "format=<sample format> "
35         "rate=<sample rate> "
36         "channels=<number of channels> "
37         "channel_map=<channel map>"
38         "buffer_size=<custom buffer size>"
39         "file_path=<file path for data reading>"
40         "adapter_name=<primary>"
41         "open_mic_speaker<open mic>"
42         "network_id<device network id>"
43         "device_type<device type or port>"
44         "source_type<source 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     "source_type",
62     NULL
63 };
64 
pa__init(pa_module * m)65 int pa__init(pa_module *m)
66 {
67     pa_modargs *ma = NULL;
68 
69     pa_assert(m);
70 
71     if (!(ma = pa_modargs_new(m->argument, VALID_MODARGS))) {
72         pa_log("Failed to parse module arguments");
73         goto fail;
74     }
75 
76     if (!(m->userdata = PaHdiSourceNew(m, ma, __FILE__))) {
77         goto fail;
78     }
79 
80     pa_modargs_free(ma);
81 
82     return 0;
83 
84 fail:
85 
86     if (ma) {
87         pa_modargs_free(ma);
88     }
89 
90     pa__done(m);
91 
92     return -1;
93 }
94 
pa__get_n_used(pa_module * m)95 int pa__get_n_used(pa_module *m)
96 {
97     pa_source *source = NULL;
98 
99     pa_assert(m);
100     pa_assert_se(source = m->userdata);
101 
102     return pa_source_linked_by(source);
103 }
104 
pa__done(pa_module * m)105 void pa__done(pa_module *m)
106 {
107     pa_source *source = NULL;
108 
109     pa_assert(m);
110 
111     if ((source = m->userdata)) {
112         PaHdiSourceFree(source);
113     }
114 }
115