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 <pulsecore/sink.h>
21 #include <stddef.h>
22 #include <stdbool.h>
23
24 pa_sink *PaHdiSinkNew(pa_module *m, pa_modargs *ma, const char *driver);
25 void PaHdiSinkFree(pa_sink *s);
26
27 PA_MODULE_AUTHOR("OpenHarmony");
28 PA_MODULE_DESCRIPTION("OpenHarmony HDI Sink");
29 PA_MODULE_VERSION(PACKAGE_VERSION);
30 PA_MODULE_LOAD_ONCE(false);
31 PA_MODULE_USAGE(
32 "sink_name=<name for the sink> "
33 "device_class=<name for the device class> "
34 "sink_properties=<properties for the sink> "
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 writing>"
41 "adapter_name=<primary>"
42 "fixed_latency=<latency measure>"
43 "sink_latency=<hdi latency>"
44 "render_in_idle_state<renderer state>"
45 "open_mic_speaker<open mic and speaker>"
46 "test_mode_on<is test mode on>"
47 "network_id<device network id>"
48 "device_type<device type or port>"
49 );
50
51 static const char * const VALID_MODARGS[] = {
52 "sink_name",
53 "device_class",
54 "sink_properties",
55 "format",
56 "rate",
57 "channels",
58 "channel_map",
59 "buffer_size",
60 "file_path",
61 "adapter_name",
62 "fixed_latency",
63 "sink_latency",
64 "render_in_idle_state",
65 "open_mic_speaker",
66 "test_mode_on",
67 "network_id",
68 "device_type",
69 NULL
70 };
71
pa__init(pa_module * m)72 int pa__init(pa_module *m)
73 {
74 pa_modargs *ma = NULL;
75
76 pa_assert(m);
77
78 if (!(ma = pa_modargs_new(m->argument, VALID_MODARGS))) {
79 pa_log("Failed to parse module arguments");
80 goto fail;
81 }
82
83 if (!(m->userdata = PaHdiSinkNew(m, ma, __FILE__))) {
84 goto fail;
85 }
86
87 pa_modargs_free(ma);
88
89 return 0;
90
91 fail:
92 if (ma) {
93 pa_modargs_free(ma);
94 }
95
96 pa__done(m);
97
98 return -1;
99 }
100
pa__get_n_used(pa_module * m)101 int pa__get_n_used(pa_module *m)
102 {
103 pa_sink *sink = NULL;
104
105 pa_assert(m);
106 pa_assert_se(sink = m->userdata);
107
108 return pa_sink_linked_by(sink);
109 }
110
pa__done(pa_module * m)111 void pa__done(pa_module *m)
112 {
113 pa_sink *sink = NULL;
114
115 pa_assert(m);
116
117 if ((sink = m->userdata)) {
118 PaHdiSinkFree(sink);
119 }
120 }
121