1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci/**
17094332d3Sopenharmony_ci * @addtogroup Audio
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Defines audio-related APIs, including custom data types and functions for loading drivers,
21094332d3Sopenharmony_ci * accessing a driver adapter, and rendering and capturing audios.
22094332d3Sopenharmony_ci *
23094332d3Sopenharmony_ci * @since 1.0
24094332d3Sopenharmony_ci * @version 1.0
25094332d3Sopenharmony_ci */
26094332d3Sopenharmony_ci
27094332d3Sopenharmony_ci/**
28094332d3Sopenharmony_ci * @file audio_adapter.h
29094332d3Sopenharmony_ci *
30094332d3Sopenharmony_ci * @brief Declares APIs for operations related to the audio adapter.
31094332d3Sopenharmony_ci *
32094332d3Sopenharmony_ci * @since 1.0
33094332d3Sopenharmony_ci * @version 1.0
34094332d3Sopenharmony_ci */
35094332d3Sopenharmony_ci
36094332d3Sopenharmony_ci#ifndef AUDIO_ADAPTER_H
37094332d3Sopenharmony_ci#define AUDIO_ADAPTER_H
38094332d3Sopenharmony_ci
39094332d3Sopenharmony_ci#include "audio_types.h"
40094332d3Sopenharmony_ci#include "audio_render.h"
41094332d3Sopenharmony_ci#include "audio_capture.h"
42094332d3Sopenharmony_ci
43094332d3Sopenharmony_ci/**
44094332d3Sopenharmony_ci * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks,
45094332d3Sopenharmony_ci * and obtaining the port capability set.
46094332d3Sopenharmony_ci *
47094332d3Sopenharmony_ci * @see AudioRender
48094332d3Sopenharmony_ci * @see AudioCapture
49094332d3Sopenharmony_ci * @since 1.0
50094332d3Sopenharmony_ci * @version 1.0
51094332d3Sopenharmony_ci */
52094332d3Sopenharmony_cistruct AudioAdapter {
53094332d3Sopenharmony_ci    /**
54094332d3Sopenharmony_ci     * @brief Initializes all ports of an audio adapter.
55094332d3Sopenharmony_ci     *
56094332d3Sopenharmony_ci     * Call this function before calling other driver functions to check whether the initialization is complete.
57094332d3Sopenharmony_ci     * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again
58094332d3Sopenharmony_ci     * until the port initialization is complete.
59094332d3Sopenharmony_ci     *
60094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
61094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the initialization is successful; returns a negative value otherwise.
62094332d3Sopenharmony_ci     */
63094332d3Sopenharmony_ci    int32_t (*InitAllPorts)(struct AudioAdapter *adapter);
64094332d3Sopenharmony_ci
65094332d3Sopenharmony_ci    /**
66094332d3Sopenharmony_ci     * @brief Creates an <b>AudioRender</b> object.
67094332d3Sopenharmony_ci     *
68094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
69094332d3Sopenharmony_ci     * @param desc Indicates the pointer to the descriptor of the audio adapter to start.
70094332d3Sopenharmony_ci     * @param attrs Indicates the pointer to the audio sampling attributes to open.
71094332d3Sopenharmony_ci     * @param render Indicates the double pointer to the <b>AudioRender</b> object.
72094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the <b>AudioRender</b> object is created successfully;
73094332d3Sopenharmony_ci     * returns a negative value otherwise.
74094332d3Sopenharmony_ci     * @see GetPortCapability
75094332d3Sopenharmony_ci     * @see DestroyRender
76094332d3Sopenharmony_ci     */
77094332d3Sopenharmony_ci    int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc,
78094332d3Sopenharmony_ci                            const struct AudioSampleAttributes *attrs, struct AudioRender **render);
79094332d3Sopenharmony_ci
80094332d3Sopenharmony_ci    /**
81094332d3Sopenharmony_ci     * @brief Destroys an <b>AudioRender</b> object.
82094332d3Sopenharmony_ci     *
83094332d3Sopenharmony_ci     * @attention Do not destroy the object during audio rendering.
84094332d3Sopenharmony_ci     *
85094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
86094332d3Sopenharmony_ci     * @param render Indicates the pointer to the <b>AudioRender</b> object to operate.
87094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the <b>AudioRender</b> object is destroyed; returns a negative value otherwise.
88094332d3Sopenharmony_ci     * @see CreateRender
89094332d3Sopenharmony_ci     */
90094332d3Sopenharmony_ci    int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render);
91094332d3Sopenharmony_ci
92094332d3Sopenharmony_ci    /**
93094332d3Sopenharmony_ci     * @brief Creates an <b>AudioCapture</b> object.
94094332d3Sopenharmony_ci     *
95094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
96094332d3Sopenharmony_ci     * @param desc Indicates the pointer to the descriptor of the audio adapter to start.
97094332d3Sopenharmony_ci     * @param attrs Indicates the pointer to the audio sampling attributes to open.
98094332d3Sopenharmony_ci     * @param capture Indicates the double pointer to the <b>AudioCapture</b> object.
99094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the <b>AudioCapture</b> object is created successfully;
100094332d3Sopenharmony_ci     * returns a negative value otherwise.
101094332d3Sopenharmony_ci     * @see GetPortCapability
102094332d3Sopenharmony_ci     * @see DestroyCapture
103094332d3Sopenharmony_ci     */
104094332d3Sopenharmony_ci    int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc,
105094332d3Sopenharmony_ci                             const struct AudioSampleAttributes *attrs, struct AudioCapture **capture);
106094332d3Sopenharmony_ci
107094332d3Sopenharmony_ci    /**
108094332d3Sopenharmony_ci     * @brief Destroys an <b>AudioCapture</b> object.
109094332d3Sopenharmony_ci     *
110094332d3Sopenharmony_ci     * @attention Do not destroy the object during audio capturing.
111094332d3Sopenharmony_ci     *
112094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
113094332d3Sopenharmony_ci     * @param capture Indicates the pointer to the <b>AudioCapture</b> object to operate.
114094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the <b>AudioCapture</b> object is destroyed; returns a negative value otherwise.
115094332d3Sopenharmony_ci     * @see CreateCapture
116094332d3Sopenharmony_ci     */
117094332d3Sopenharmony_ci    int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture);
118094332d3Sopenharmony_ci
119094332d3Sopenharmony_ci    /**
120094332d3Sopenharmony_ci     * @brief Obtains the capability set of the port driver for the audio adapter.
121094332d3Sopenharmony_ci     *
122094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
123094332d3Sopenharmony_ci     * @param port Indicates the pointer to the port.
124094332d3Sopenharmony_ci     * @param capability Indicates the pointer to the capability set to obtain.
125094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the capability set is successfully obtained; returns a negative value otherwise.
126094332d3Sopenharmony_ci     */
127094332d3Sopenharmony_ci    int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port,
128094332d3Sopenharmony_ci                                 struct AudioPortCapability *capability);
129094332d3Sopenharmony_ci
130094332d3Sopenharmony_ci    /**
131094332d3Sopenharmony_ci     * @brief Sets the passthrough data transmission mode of the audio port driver.
132094332d3Sopenharmony_ci     *
133094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
134094332d3Sopenharmony_ci     * @param port Indicates the pointer to the port.
135094332d3Sopenharmony_ci     * @param mode Indicates the passthrough transmission mode to set.
136094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
137094332d3Sopenharmony_ci     * @see GetPassthroughMode
138094332d3Sopenharmony_ci     */
139094332d3Sopenharmony_ci    int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port,
140094332d3Sopenharmony_ci                                  enum AudioPortPassthroughMode mode);
141094332d3Sopenharmony_ci
142094332d3Sopenharmony_ci    /**
143094332d3Sopenharmony_ci     * @brief Obtains the passthrough data transmission mode of the audio port driver.
144094332d3Sopenharmony_ci     *
145094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
146094332d3Sopenharmony_ci     * @param port Indicates the pointer to the port.
147094332d3Sopenharmony_ci     * @param mode Indicates the pointer to the passthrough transmission mode to obtain.
148094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
149094332d3Sopenharmony_ci     * @see SetPassthroughMode
150094332d3Sopenharmony_ci     */
151094332d3Sopenharmony_ci    int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port,
152094332d3Sopenharmony_ci                                  enum AudioPortPassthroughMode *mode);
153094332d3Sopenharmony_ci
154094332d3Sopenharmony_ci    /**
155094332d3Sopenharmony_ci     * @brief Update audio route on several source and sink ports.
156094332d3Sopenharmony_ci     *
157094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
158094332d3Sopenharmony_ci     * @param route Indicates route information.
159094332d3Sopenharmony_ci     * @param routeHandle Indicates route handle.
160094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
161094332d3Sopenharmony_ci     * @see SetPassthroughMode
162094332d3Sopenharmony_ci     */
163094332d3Sopenharmony_ci    int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle);
164094332d3Sopenharmony_ci
165094332d3Sopenharmony_ci    /**
166094332d3Sopenharmony_ci     * @brief Release an audio route.
167094332d3Sopenharmony_ci     *
168094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
169094332d3Sopenharmony_ci     * @param routeHandle Indicates route handle.
170094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mode is successfully obtained; returns a negative value otherwise.
171094332d3Sopenharmony_ci     * @see SetPassthroughMode
172094332d3Sopenharmony_ci     */
173094332d3Sopenharmony_ci    int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle);
174094332d3Sopenharmony_ci
175094332d3Sopenharmony_ci    /**
176094332d3Sopenharmony_ci     * @brief Sets the mute operation for the audio.
177094332d3Sopenharmony_ci     *
178094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
179094332d3Sopenharmony_ci     * @param mute Specifies whether to mute the audio. Value <b>true</b> means to mute the audio,
180094332d3Sopenharmony_ci     * and <b>false</b> means the opposite.
181094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
182094332d3Sopenharmony_ci     * @see GetMute
183094332d3Sopenharmony_ci     */
184094332d3Sopenharmony_ci    int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute);
185094332d3Sopenharmony_ci
186094332d3Sopenharmony_ci    /**
187094332d3Sopenharmony_ci     * @brief Obtains the mute operation set for the audio.
188094332d3Sopenharmony_ci     *
189094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
190094332d3Sopenharmony_ci     * @param mute Indicates the pointer to the mute operation set for the audio. Value <b>true</b> means that
191094332d3Sopenharmony_ci     * the audio is muted, and <b>false</b> means the opposite.
192094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise.
193094332d3Sopenharmony_ci     * @see SetMute
194094332d3Sopenharmony_ci     */
195094332d3Sopenharmony_ci    int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute);
196094332d3Sopenharmony_ci
197094332d3Sopenharmony_ci    /**
198094332d3Sopenharmony_ci     * @brief Sets the audio volume for voice call.
199094332d3Sopenharmony_ci     *
200094332d3Sopenharmony_ci     * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15,
201094332d3Sopenharmony_ci     * <b>0.0</b> indicates that the audio is muted, and <b>1.0</b> indicates the maximum volume level (15).
202094332d3Sopenharmony_ci     *
203094332d3Sopenharmony_ci     * @param adapter Indicates the pointer to the audio adapter to operate.
204094332d3Sopenharmony_ci     * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0.
205094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
206094332d3Sopenharmony_ci     * @see GetVolume
207094332d3Sopenharmony_ci     */
208094332d3Sopenharmony_ci    int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume);
209094332d3Sopenharmony_ci
210094332d3Sopenharmony_ci    /**
211094332d3Sopenharmony_ci     * @brief Sets extra audio parameters.
212094332d3Sopenharmony_ci     *
213094332d3Sopenharmony_ci     * @param adapter Indicates the audio adapter.
214094332d3Sopenharmony_ci     * @param key Indicates what kind of parameter type will be set.
215094332d3Sopenharmony_ci     * @param condition Indicates the specific extend parameter condition of AudioExtParamKey.
216094332d3Sopenharmony_ci     * @param value Indicates the value of the specified condition.
217094332d3Sopenharmony_ci     *
218094332d3Sopenharmony_ci     * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;).
219094332d3Sopenharmony_ci     * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this:
220094332d3Sopenharmony_ci     * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i>
221094332d3Sopenharmony_ci     * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4;
222094332d3Sopenharmony_ci     * VOLUME_GROUP_ID indicates which volume group will be set;
223094332d3Sopenharmony_ci     * AUDIO_VOLUME_TYPE indicates which volume type will be set;
224094332d3Sopenharmony_ci     *
225094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
226094332d3Sopenharmony_ci     */
227094332d3Sopenharmony_ci    int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key,
228094332d3Sopenharmony_ci                              const char *condition, const char *value);
229094332d3Sopenharmony_ci
230094332d3Sopenharmony_ci    /**
231094332d3Sopenharmony_ci     * @brief Get extra audio parameters.
232094332d3Sopenharmony_ci     *
233094332d3Sopenharmony_ci     * @param adapter Indicates the audio adapter.
234094332d3Sopenharmony_ci     * @param key Indicates what kind of parameter type will be get.
235094332d3Sopenharmony_ci     * @param condition Indicates the specific extend parameter condition of AudioExtParamKey.
236094332d3Sopenharmony_ci     * @param value Indicates the value of the specified condition.
237094332d3Sopenharmony_ci     * @param lenth Indicates the length of the value pointer.
238094332d3Sopenharmony_ci     *
239094332d3Sopenharmony_ci     * The format of condition is <i>key=value</i>. Separate multiple key-value pairs by semicolons (;).
240094332d3Sopenharmony_ci     * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this:
241094332d3Sopenharmony_ci     * <i>"EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;"</i>
242094332d3Sopenharmony_ci     * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4;
243094332d3Sopenharmony_ci     * VOLUME_GROUP_ID indicates which volume group want get;
244094332d3Sopenharmony_ci     * AUDIO_VOLUME_TYPE indicates which volume type want get;
245094332d3Sopenharmony_ci     *
246094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
247094332d3Sopenharmony_ci     */
248094332d3Sopenharmony_ci    int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key,
249094332d3Sopenharmony_ci                              const char *condition, char *value, int32_t lenth);
250094332d3Sopenharmony_ci
251094332d3Sopenharmony_ci    /**
252094332d3Sopenharmony_ci     * @brief Register extra audio parameters observer.
253094332d3Sopenharmony_ci     *
254094332d3Sopenharmony_ci     * @param adapter Indicates the audio adapter.
255094332d3Sopenharmony_ci     * @param callback Indicates param observer.
256094332d3Sopenharmony_ci     * @param cookie Indicates the pointer to the callback parameters;
257094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
258094332d3Sopenharmony_ci     */
259094332d3Sopenharmony_ci    int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie);
260094332d3Sopenharmony_ci    /**
261094332d3Sopenharmony_ci     * @brief Get the device status of an adapter.
262094332d3Sopenharmony_ci     *
263094332d3Sopenharmony_ci     * @param adapter Indicates the audio adapter.
264094332d3Sopenharmony_ci     * @param status Indicates the status of device .
265094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
266094332d3Sopenharmony_ci     */
267094332d3Sopenharmony_ci    int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status);
268094332d3Sopenharmony_ci};
269094332d3Sopenharmony_ci#endif /* AUDIO_ADAPTER_H */
270094332d3Sopenharmony_ci/** @} */
271