4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef footizenaudiofoo
21 #define footizenaudiofoo
27 * @brief This file contains the Audio Hardware Abstraction Layer Interfaces.
31 * @addtogroup TIZEN_AUDIO_HAL_MODULE
36 * @brief Enumeration for return codes.
39 typedef enum audio_return {
41 AUDIO_ERR_UNDEFINED = (int32_t)0x80001000,
42 AUDIO_ERR_RESOURCE = (int32_t)0x80001001,
43 AUDIO_ERR_PARAMETER = (int32_t)0x80001002,
44 AUDIO_ERR_IOCTL = (int32_t)0x80001003,
45 AUDIO_ERR_INVALID_STATE = (int32_t)0x80001004,
46 AUDIO_ERR_INTERNAL = (int32_t)0x80001005,
47 /* add new enemerator here */
48 AUDIO_ERR_NOT_IMPLEMENTED = (int32_t)0x80001100,
52 * @brief Enumeration for audio direction.
55 typedef enum audio_direction {
56 AUDIO_DIRECTION_IN, /**< Capture */
57 AUDIO_DIRECTION_OUT, /**< Playback */
61 * @brief Device information including type, direction and id.
64 typedef struct device_info {
71 * @brief Volume information including type, gain and direction.
74 typedef struct audio_volume_info {
78 } audio_volume_info_t ;
81 * @brief Route information including role and device.
84 typedef struct audio_route_info {
86 device_info_t *device_infos;
87 uint32_t num_of_devices;
91 * @brief Route option including role, name and value.
94 typedef struct audio_route_option {
98 } audio_route_option_t;
101 * @brief Stream information including role, direction and index.
104 typedef struct audio_stream_info {
108 } audio_stream_info_t ;
111 typedef struct audio_interface {
112 /* Initialization & de-initialization */
113 audio_return_t (*init)(void **audio_handle);
114 audio_return_t (*deinit)(void *audio_handle);
116 audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
117 audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
118 audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level);
119 audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
120 audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
121 audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
123 audio_return_t (*update_route)(void *audio_handle, audio_route_info_t *info);
124 audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option);
126 audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
128 audio_return_t (*pcm_open)(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **pcm_handle);
129 audio_return_t (*pcm_start)(void *audio_handle, void *pcm_handle);
130 audio_return_t (*pcm_stop)(void *audio_handle, void *pcm_handle);
131 audio_return_t (*pcm_close)(void *audio_handle, void *pcm_handle);
132 audio_return_t (*pcm_avail)(void *audio_handle, void *pcm_handle, uint32_t *avail);
133 audio_return_t (*pcm_write)(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
134 audio_return_t (*pcm_read)(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
135 audio_return_t (*pcm_get_fd)(void *audio_handle, void *pcm_handle, int *fd);
136 audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents);
137 audio_return_t (*pcm_get_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods);
138 audio_return_t (*pcm_set_params)(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
142 * @brief Initializes audio hal.
144 * @param[out] audio_handle The audio hal handle
146 * @return @c 0 on success,
147 * otherwise a negative error value
148 * @retval #AUDIO_RET_OK Success
149 * @see audio_deinit()
151 audio_return_t audio_init(void **audio_handle);
154 * @brief De-initializes audio hal.
156 * @param[in] audio_handle The audio hal handle
158 * @return @c 0 on success,
159 * otherwise a negative error value
160 * @retval #AUDIO_RET_OK Success
163 audio_return_t audio_deinit(void *audio_handle);
166 * @brief Gets the maximum volume level supported for a particular volume information.
168 * @param[in] audio_handle The audio hal handle
169 * @param[in] info The audio volume information
170 * @param[out] level The maximum volume level
172 * @return @c 0 on success,
173 * otherwise a negative error value
174 * @retval #AUDIO_RET_OK Success
175 * @see audio_set_volume_level()
176 * @see audio_get_volume_level()
177 * @see audio_get_volume_value()
179 audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
182 * @brief Gets the volume level specified for a particular volume information.
184 * @param[in] audio_handle The audio hal handle
185 * @param[in] info The audio volume information
186 * @param[out] level The current volume level
188 * @return @c 0 on success,
189 * otherwise a negative error value
190 * @retval #AUDIO_RET_OK Success
191 * @see audio_set_volume_level()
192 * @see audio_get_volume_level_max()
193 * @see audio_get_volume_value()
195 audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
198 * @brief Sets the volume level specified for a particular volume information.
200 * @param[in] audio_handle The audio hal handle
201 * @param[in] info The audio volume information
202 * @param[in] level The volume level to be set
204 * @return @c 0 on success,
205 * otherwise a negative error value
206 * @retval #AUDIO_RET_OK Success
207 * @see audio_get_volume_level()
208 * @see audio_get_volume_level_max()
209 * @see audio_get_volume_value()
211 audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
214 * @brief Gets the volume value specified for a particular volume information and level.
216 * @param[in] audio_handle The audio hal handle
217 * @param[in] info The audio volume information
218 * @param[in] level The volume level
219 * @param[out] value The volume value (range is from 0.0 to 1.0 inclusive, 1.0 = 100%)
221 * @return @c 0 on success,
222 * otherwise a negative error value
223 * @retval #AUDIO_RET_OK Success
224 * @see audio_set_volume_level()
225 * @see audio_get_volume_level()
226 * @see audio_get_volume_level_max()
228 audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
231 * @brief Gets the volume mute specified for a particular volume information.
233 * @param[in] audio_handle The audio hal handle
234 * @param[in] info The audio volume information
235 * @param[out] mute The volume mute state : (@c 0 = unmute, @c 1 = mute)
237 * @return @c 0 on success,
238 * otherwise a negative error value
239 * @retval #AUDIO_RET_OK Success
240 * @see audio_set_volume_mute()
242 audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
245 * @brief Sets the volume mute specified for a particular volume information.
247 * @param[in] audio_handle The audio hal handle
248 * @param[in] info The audio volume information
249 * @param[in] mute The volume mute state to be set : (@c 0 = unmute, @c 1 = mute)
251 * @return @c 0 on success,
252 * otherwise a negative error value
253 * @retval #AUDIO_RET_OK Success
254 * @see audio_get_volume_mute()
256 audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
259 * @brief Updates the audio routing according to audio route information.
261 * @param[in] audio_handle The audio hal handle
262 * @param[in] info The audio route information including role and devices
264 * @return @c 0 on success,
265 * otherwise a negative error value
266 * @retval #AUDIO_RET_OK Success
267 * @see audio_update_route_option()
269 audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info);
272 * @brief Updates audio routing option according to audio route option.
274 * @param[in] audio_handle The audio hal handle
275 * @param[in] option The option that can be used for audio routing including role, name and value
277 * @remarks This option can be used for audio routing.\n
278 * It is recommended to apply this option for routing per each role.
280 * @return @c 0 on success,
281 * otherwise a negative error value
282 * @retval #AUDIO_RET_OK Success
283 * @see audio_update_route()
285 audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
288 * @brief Gets notified when a stream is connected and disconnected.
290 * @param[in] audio_handle The audio hal handle
291 * @param[in] info The stream information including role, direction, index
292 * @param[in] is_connected The connection state of this stream (@c true = connected, @c false = disconnected)
294 * @remarks This information can be used for audio routing, volume controls and so on.
296 * @return @c 0 on success,
297 * otherwise a negative error value
298 * @retval #AUDIO_RET_OK Success
300 audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
303 * @brief Opens a PCM device.
305 * @param[in] audio_handle The audio hal handle
306 * @param[in] card The card of PCM
307 * @param[in] device The device of PCM
308 * @param[in] direction The direction of PCM
309 * @param[in] sample_spec The sample specification
310 * @param[in] period_size The period size
311 * @param[in] periods The periods
312 * @param[out] pcm_handle The PCM handle
314 * @return @c 0 on success,
315 * otherwise a negative error value
316 * @retval #AUDIO_RET_OK Success
317 * @see audio_pcm_close()
319 audio_return_t audio_pcm_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **pcm_handle);
322 * @brief Starts a PCM device.
324 * @param[in] audio_handle The audio hal handle
325 * @param[in] pcm_handle The PCM handle to be started
327 * @return @c 0 on success,
328 * otherwise a negative error value
329 * @retval #AUDIO_RET_OK Success
330 * @see audio_pcm_avail()
331 * @see audio_pcm_write()
332 * @see audio_pcm_read()
333 * @see audio_pcm_stop()
334 * @see audio_pcm_recover()
336 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
339 * @brief Stops a PCM device.
341 * @param[in] audio_handle The audio hal handle
342 * @param[in] pcm_handle The PCM handle to be stopped
344 * @return @c 0 on success,
345 * otherwise a negative error value
346 * @retval #AUDIO_RET_OK Success
347 * @see audio_pcm_start()
349 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
352 * @brief Closes a PCM device.
354 * @param[in] audio_handle The audio hal handle
355 * @param[in] pcm_handle The PCM handle to be closed
357 * @return @c 0 on success,
358 * otherwise a negative error value
359 * @retval #AUDIO_RET_OK Success
360 * @see audio_pcm_open()
362 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
365 * @brief Gets available number of frames.
367 * @param[in] audio_handle The audio hal handle
368 * @param[in] pcm_handle The PCM handle
369 * @param[out] avail The available number of frames
371 * @return @c 0 on success,
372 * otherwise a negative error value
373 * @retval #AUDIO_RET_OK Success
374 * @see audio_pcm_write()
375 * @see audio_pcm_read()
377 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
380 * @brief Writes frames to a PCM device.
382 * @param[in] audio_handle The audio hal handle
383 * @param[in] pcm_handle The PCM handle
384 * @param[in] buffer The buffer containing frames
385 * @param[in] frames The number of frames to be written
387 * @return @c 0 on success,
388 * otherwise a negative error value
389 * @retval #AUDIO_RET_OK Success
390 * @see audio_pcm_avail()
391 * @see audio_pcm_recover()
393 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
396 * @brief Reads frames from a PCM device.
398 * @param[in] audio_handle The audio hal handle
399 * @param[in] pcm_handle The PCM handle
400 * @param[out] buffer The buffer containing frames
401 * @param[in] frames The number of frames to be read
403 * @return @c 0 on success,
404 * otherwise a negative error value
405 * @retval #AUDIO_RET_OK Success
406 * @see audio_pcm_avail()
407 * @see audio_pcm_recover()
409 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
412 * @brief Gets poll descriptor for a PCM handle.
414 * @param[in] audio_handle The audio hal handle
415 * @param[in] pcm_handle The PCM handle
416 * @param[out] fd The poll descriptor
418 * @return @c 0 on success,
419 * otherwise a negative error value
420 * @retval #AUDIO_RET_OK Success
421 * @see audio_pcm_open()
422 * @see audio_pcm_recover()
424 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd);
427 * @brief Recovers the PCM state.
429 * @param[in] audio_handle The audio hal handle
430 * @param[in] pcm_handle The PCM handle
431 * @param[in] revents The returned event from pollfd
433 * @return @c 0 on success,
434 * otherwise a negative error value
435 * @retval #AUDIO_RET_OK Success
436 * @see audio_pcm_start()
437 * @see audio_pcm_write()
438 * @see audio_pcm_read()
439 * @see audio_pcm_get_fd()
441 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents);
444 * @brief Gets parameters of a PCM device.
446 * @param[in] audio_handle The audio hal handle
447 * @param[in] pcm_handle The PCM handle
448 * @param[in] direction The direction of PCM
449 * @param[out] sample_spec The sample specification
450 * @param[out] period_size The period size
451 * @param[out] periods The periods
453 * @return @c 0 on success,
454 * otherwise a negative error value
455 * @retval #AUDIO_RET_OK Success
456 * @see audio_pcm_set_params()
458 audio_return_t audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods);
461 * @brief Sets hardware and software parameters of a PCM device.
463 * @param[in] audio_handle The audio hal handle
464 * @param[in] pcm_handle The PCM handle
465 * @param[in] direction The direction of PCM
466 * @param[in] sample_spec The sample specification
467 * @param[in] period_size The period size
468 * @param[in] periods The periods
470 * @return @c 0 on success,
471 * otherwise a negative error value
472 * @retval #AUDIO_RET_OK Success
473 * @see audio_pcm_set_params()
475 audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);