blob: 595a89fbbb6ec03e0e31e5277a9ee84623412604 [file] [log] [blame]
Derek Chenb2b9d2e2014-11-10 12:40:05 -08001/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef AUDIO_HAL_PLUGIN_H
30#define AUDIO_HAL_PLUGIN_H
31
32#if defined(__cplusplus)
33extern "C" {
34#endif
35
Derek Chen0b580312020-03-22 21:17:17 -070036#include <system/audio.h>
Derek Chenb2b9d2e2014-11-10 12:40:05 -080037
38#define AUDIO_HAL_PLUGIN_EOK (0)
39#define AUDIO_HAL_PLUGIN_EFAIL (-1) /**< Undefined error */
40#define AUDIO_HAL_PLUGIN_ENOMEM (-2) /**< Out of memory */
41#define AUDIO_HAL_PLUGIN_EINVAL (-3) /**< Invalid argument */
42#define AUDIO_HAL_PLUGIN_EBUSY (-4) /**< Plugin driver is busy */
43#define AUDIO_HAL_PLUGIN_ENODEV (-5) /**< No device */
44#define AUDIO_HAL_PLUGIN_EALREADY (-6) /**< Already done */
45
46#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_MSG_TYPE "ext_hw_plugin_msg_type"
47#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_UC "ext_hw_plugin_usecase"
48#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_SND_DEVICE "ext_hw_plugin_snd_device"
49#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_DIRECTION "ext_hw_plugin_direction"
50#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_CMASK "ext_hw_plugin_channel_mask"
51#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_GAIN "ext_hw_plugin_gain"
52#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_MUTE_FLAG "ext_hw_plugin_mute_flag"
53#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_FADE "ext_hw_plugin_fade"
54#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_BALANCE "ext_hw_plugin_balance"
55#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_BMT_FTYPE "ext_hw_plugin_bmt_filter_type"
56#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_BMT_FLAG "ext_hw_plugin_bmt_flag"
57#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_BMT_VAL "ext_hw_plugin_bmt_value"
58#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_EQ_FLAG "ext_hw_plugin_eq_flag"
59#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_EQ_ID "ext_hw_plugin_eq_id"
60#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_EQ_NUM_BANDS "ext_hw_plugin_eq_num_bands"
61#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_EQ_BAND_DATA "ext_hw_plugin_eq_band_data"
62#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_TUNNEL_SIZE "ext_hw_plugin_tunnel_size"
63#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_TUNNEL_DATA "ext_hw_plugin_tunnel_data"
64#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_GETPARAM_RESULT "ext_hw_plugin_getparam_result"
65#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_GETPARAM_DATA "ext_hw_plugin_getparam_data"
66#define AUDIO_PARAMETER_KEY_EXT_HW_PLUGIN_TUNNEL_GET_SIZE "ext_hw_plugin_tunnel_get_size"
67/**
68 * Type of audio hal plug-in messages
69 */
70typedef enum
71{
72 AUDIO_HAL_PLUGIN_MSG_INVALID = 0,
73 AUDIO_HAL_PLUGIN_MSG_CODEC_ENABLE, /**< setup codec routing path */
74 AUDIO_HAL_PLUGIN_MSG_CODEC_DISABLE, /**< tear down routing path */
75 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_VOLUME, /**< set volume */
76 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_MUTE, /**< mute/unmute control */
77 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_FADE, /**< fade out control */
78 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_BALANCE, /**< left/right balance control */
79 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_BMT, /**< base/mid/treble control */
80 AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_EQ, /**< EQ control */
81 AUDIO_HAL_PLUGIN_MSG_CODEC_TUNNEL_CMD, /**< pass through cmds */
82 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_VOLUME, /**< get volume params */
83 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_FADE, /**< get fade params */
84 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_BALANCE, /**< get balance params */
85 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_BMT, /**< get bmt params */
86 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_EQ, /**< get EQ params */
87 AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_EQ_SUBBANDS, /**< get EQ subbands params */
88 AUDIO_HAL_PLUGIN_MSG_CODEC_TUNNEL_GET_CMD, /**< pass through get cmds */
89 AUDIO_HAL_PLUGIN_MSG_MAX
90} audio_hal_plugin_msg_type_t;
91
92/**
93 * Type of audio hal plug-in use cases
94 */
95typedef enum
96{
97 AUDIO_HAL_PLUGIN_USECASE_INVALID = -1,
98 AUDIO_HAL_PLUGIN_USECASE_DEFAULT_PLAYBACK = 0,
99 AUDIO_HAL_PLUGIN_USECASE_DEFAULT_CAPTURE,
100 AUDIO_HAL_PLUGIN_USECASE_DRIVER_SIDE_PLAYBACK,
101 AUDIO_HAL_PLUGIN_USECASE_HFP_VOICE_CALL,
102 AUDIO_HAL_PLUGIN_USECASE_CS_VOICE_CALL,
103 AUDIO_HAL_PLUGIN_USECASE_FM_TUNER,
104 AUDIO_HAL_PLUGIN_USECASE_ICC,
105 AUDIO_HAL_PLUGIN_USECASE_EC_CAPTURE,
106 AUDIO_HAL_PLUGIN_USECASE_EC_REF_CAPTURE,
107 AUDIO_HAL_PLUGIN_USECASE_ANC,
108 AUDIO_HAL_PLUGIN_USECASE_LINE_IN_PASSTHROUGH,
109 AUDIO_HAL_PLUGIN_USECASE_HDMI_IN_PASSTHROUGH,
110 AUDIO_HAL_PLUGIN_USECASE_PHONE_PLAYBACK,
111 AUDIO_HAL_PLUGIN_USECASE_MAX
112} audio_hal_plugin_usecase_type_t;
113
114/**
115 * Type of audio hal plug-in direction used in set_param
116 */
117typedef enum
118{
119 AUDIO_HAL_PLUGIN_DIRECTION_INVALID = -1,
120 AUDIO_HAL_PLUGIN_DIRECTION_PLAYBACK = 0,
121 AUDIO_HAL_PLUGIN_DIRECTION_CAPTURE,
122 AUDIO_HAL_PLUGIN_DIRECTION_MAX
123} audio_hal_plugin_direction_type_t;
124
125/**
126 * Type of query status mask
127 */
128#define QUERY_VALUE_VALID (0x0)
129#define QUERY_VALUE_NOT_SUPPORTED (0x1)
130#define QUERY_VALUE_NOT_SET (0x2)
131
132/**
133 * Type of signed 32-bit bounded value used in get_param
134 */
135typedef struct audio_hal_plugin_bint32
136{
137 uint32_t query_status_mask; /**< status of returned actual value */
138 int32_t value; /**< actual value */
139 int32_t min; /**< minimum for value */
140 int32_t max; /**< maximum for value */
141} audio_hal_plugin_bint32_t;
142
143/**
144 * Type of unsigned 32-bit bounded value used in get_param
145 */
146typedef struct audio_hal_plugin_buint32
147{
148 uint32_t query_status_mask; /**< status of returned actual value */
149 uint32_t value; /**< actual value */
150 uint32_t min; /**< minimum for value */
151 uint32_t max; /**< maximum for value */
152} audio_hal_plugin_buint32_t;
153
154/**
155 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_ENABLE message
156 */
157typedef struct audio_hal_plugin_codec_enable
158{
Derek Chen0b580312020-03-22 21:17:17 -0700159 int snd_dev; /**< Requested endpoint device to be enabled. @enum: SND_DEVICE_XXX */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800160 audio_hal_plugin_usecase_type_t usecase;
161 /**< Requested use case. @enum: AUDIO_HAL_PLUGIN_USECASE_XXX */
162 uint32_t sample_rate; /**< Requested sample rate for the endpoint device */
163 uint32_t bit_width; /**< Requested bit width per sample for the endpoint device */
164 uint32_t num_chs; /**< Requested number of channels for the endpoint device */
165} audio_hal_plugin_codec_enable_t;
166
167/**
168 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_DISABLE message
169 */
170typedef struct audio_hal_plugin_codec_disable
171{
Derek Chen0b580312020-03-22 21:17:17 -0700172 int snd_dev; /**< Requested the endpoint device to be disabled */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800173 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
174} audio_hal_plugin_codec_disable_t;
175
176/**
177 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_VOLUME message
178 */
179typedef struct audio_hal_plugin_codec_set_pp_vol
180{
Derek Chen0b580312020-03-22 21:17:17 -0700181 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800182 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
183 audio_channel_mask_t ch_mask; /**< Requested audio channel mask */
184 uint32_t gain; /**< The requested volume setting. */
185} audio_hal_plugin_codec_set_pp_vol_t;
186
187/**
188 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_MUTE message
189 */
190typedef struct audio_hal_plugin_codec_set_pp_mute
191{
Derek Chen0b580312020-03-22 21:17:17 -0700192 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800193 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
194 audio_channel_mask_t ch_mask; /**< Requested audio channel mask */
195 bool flag; /**< Enable/Disable mute flag. 1: mute, 0: unmute */
196} audio_hal_plugin_codec_set_pp_mute_t;
197
198/**
199 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_FADE message
200 */
201typedef struct audio_hal_plugin_codec_set_pp_fade
202{
Derek Chen0b580312020-03-22 21:17:17 -0700203 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800204 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
205 int32_t fade; /**< The requested fade configuration. */
206} audio_hal_plugin_codec_set_pp_fade_t;
207
208/**
209 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_BALANCE message
210 */
211typedef struct audio_hal_plugin_codec_set_pp_balance
212{
Derek Chen0b580312020-03-22 21:17:17 -0700213 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800214 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
215 int32_t balance; /**< The requested balance configuration. */
216} audio_hal_plugin_codec_set_pp_balance_t;
217
218/**
219 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_BMT message
220 */
221typedef enum
222{
223 AUDIO_HAL_PLUGIN_CODEC_PP_FILTER_TYPE_INVALID = 0,
224 AUDIO_HAL_PLUGIN_CODEC_PP_FILTER_TYPE_BASS,
225 AUDIO_HAL_PLUGIN_CODEC_PP_FILTER_TYPE_MID,
226 AUDIO_HAL_PLUGIN_CODEC_PP_FILTER_TYPE_TREBLE,
227 AUDIO_HAL_PLUGIN_CODEC_PP_FILTER_TYPE_MAX
228} audio_hal_plugin_codec_pp_filter_type_t;
229
230typedef struct audio_hal_plugin_codec_set_pp_bmt
231{
Derek Chen0b580312020-03-22 21:17:17 -0700232 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800233 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
234 audio_hal_plugin_codec_pp_filter_type_t filter_type; /**< Requested filter type */
235 bool enable_flag; /**< Enable flag. 0 - Disable, 1 - Enable */
236 int32_t value; /**< Requested value to be set */
237} audio_hal_plugin_codec_set_pp_bmt_t;
238
239/**
240 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_SET_PP_EQ message
241 */
242typedef struct audio_hal_plugin_codec_pp_eq_subband
243{
244 uint32_t band_idx; /**< Band index. Supported value: 0 to (num_bands - 1) */
245 uint32_t center_freq; /**< Filter band center frequency in millihertz */
246 int32_t band_level; /**< Filter band gain in millibels */
247} audio_hal_plugin_codec_pp_eq_subband_t;
248
249typedef struct audio_hal_plugin_codec_set_pp_eq
250{
Derek Chen0b580312020-03-22 21:17:17 -0700251 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800252 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
253 bool enable_flag; /**< Enable flag. 0 - Disable, 1 - Enable */
254 int32_t preset_id; /**< Specify to use either pre-defined preset EQ or
255 user-customized equalizers:
256 -1 - custom equalizer speficied through 'bands' struct
257 0 to N - pre-defined preset EQ index: ROCK/JAZZ/POP, etc */
258 uint32_t num_bands; /**< Number of EQ subbands when a custom preset_id is selected */
259 audio_hal_plugin_codec_pp_eq_subband_t *bands; /**< Equalizer sub-band struct list */
260} audio_hal_plugin_codec_set_pp_eq_t;
261
262/**
263 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_VOLUME message
264 */
265typedef struct audio_hal_plugin_codec_get_pp_vol
266{
Derek Chen0b580312020-03-22 21:17:17 -0700267 int snd_dev; /**< Requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800268 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
269 audio_channel_mask_t ch_mask; /**< Requested audio channel mask */
270 audio_hal_plugin_buint32_t ret_gain; /**< Returned volume range and value */
271} audio_hal_plugin_codec_get_pp_vol_t;
272
273/**
274 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_FADE message
275 */
276typedef struct audio_hal_plugin_codec_get_pp_fade
277{
Derek Chen0b580312020-03-22 21:17:17 -0700278 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800279 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
280 audio_hal_plugin_bint32_t ret_fade; /**< Returned fade range and value. */
281} audio_hal_plugin_codec_get_pp_fade_t;
282
283/**
284 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_BALANCE message
285 */
286typedef struct audio_hal_plugin_codec_get_pp_balance
287{
Derek Chen0b580312020-03-22 21:17:17 -0700288 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800289 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
290 audio_hal_plugin_bint32_t ret_balance; /**< Returned balance range and value. */
291} audio_hal_plugin_codec_get_pp_balance_t;
292
293/**
294 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_BMT message
295 */
296typedef struct audio_hal_plugin_codec_get_pp_bmt
297{
Derek Chen0b580312020-03-22 21:17:17 -0700298 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800299 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
300 audio_hal_plugin_codec_pp_filter_type_t filter_type; /**< Requested filter type */
301 audio_hal_plugin_bint32_t ret_value; /**< Returned range and value */
302} audio_hal_plugin_codec_get_pp_bmt_t;
303
304/**
305 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_EQ message
306 */
307typedef struct audio_hal_plugin_codec_get_pp_eq
308{
Derek Chen0b580312020-03-22 21:17:17 -0700309 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800310 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
311 audio_hal_plugin_bint32_t ret_preset_id; /**< Returned preset id
312 -1 - custom equalizer speficied through 'bands' struct
313 0 to N - pre-defined preset EQ index: ROCK/JAZZ/POP, etc */
314 uint32_t ret_num_bands; /**< Returned number of EQ subbands supported
315 when a custom preset_id is selected */
316} audio_hal_plugin_codec_get_pp_eq_t;
317
318/**
319 * Eq_subband struct used in the following payload
320 */
321typedef struct audio_hal_plugin_pp_eq_subband_binfo
322{
323 audio_hal_plugin_buint32_t ret_center_freq; /**< Returned band center frequency range
324 and value in millihertz */
325 audio_hal_plugin_bint32_t ret_band_level; /**< Returned band gain range and value in millibels */
326} audio_hal_plugin_pp_eq_subband_binfo_t;
327
328/**
329 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_GET_PP_EQ_SUBBANDS message
330 */
331typedef struct audio_hal_plugin_codec_get_pp_eq_subbands
332{
Derek Chen0b580312020-03-22 21:17:17 -0700333 int snd_dev; /**< The requested endpoint device */
Derek Chenb2b9d2e2014-11-10 12:40:05 -0800334 audio_hal_plugin_usecase_type_t usecase; /**< Requested use case */
335 uint32_t num_bands; /**< number of EQ subbands supported for custom eq
336 returned from get_pp_eq query */
337 audio_hal_plugin_pp_eq_subband_binfo_t *ret_bands; /**< Returned subband info list */
338} audio_hal_plugin_codec_get_pp_eq_subbands_t;
339
340/**
341 * Payload of AUDIO_HAL_PLUGIN_MSG_CODEC_TUNNEL_GET_CMD message
342 */
343typedef struct audio_hal_plugin_codec_tunnel_get
344{
345 int32_t *param_data; /**< Request param data from client */
346 uint32_t param_size; /**< Request 32-bit data size from client */
347 uint32_t size_to_get; /**< Expected 32-bit data size to get from cleint */
348 int32_t *ret_data; /**< Returned data */
349 uint32_t ret_size; /**< Returned 32-bit data size */
350} audio_hal_plugin_codec_tunnel_get_t;
351
352/**
353 * Initialize the audio hal plug-in module and underlying hw driver
354 * One time call at audio hal boot up time
355 */
356int32_t audio_hal_plugin_init (void);
357
358/**
359 * De-Initialize the audio hal plug-in module and underlying hw driver
360 * One time call when audio hal get unloaded from system
361 */
362int32_t audio_hal_plugin_deinit (void);
363
364/**
365 * Function to invoke the underlying HW driver realizing the functionality for a given use case.
366 */
367int32_t audio_hal_plugin_send_msg (
368 audio_hal_plugin_msg_type_t msg,
369 void * payload, uint32_t payload_size);
370
371#if defined(__cplusplus)
372} /* extern "C" */
373#endif
374
375#endif