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 * @brief Called when audio hal implementation needs to send a message.
113 * @param[in] name The message name
114 * @param[in] value The message value
115 * @param[in] user_data The user data passed from the callback registration function
117 * @see audio_add_message_cb()
118 * @see audio_remove_message_cb()
120 typedef void (*message_cb)(const char *name, int value, void *user_data);
123 typedef struct audio_interface {
124 /* Initialization & de-initialization */
125 audio_return_t (*init)(void **audio_handle);
126 audio_return_t (*deinit)(void *audio_handle);
128 audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
129 audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
130 audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level);
131 audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
132 audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
133 audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
135 audio_return_t (*update_route)(void *audio_handle, audio_route_info_t *info);
136 audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option);
138 audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
140 audio_return_t (*pcm_open)(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
141 audio_return_t (*pcm_start)(void *audio_handle, void *pcm_handle);
142 audio_return_t (*pcm_stop)(void *audio_handle, void *pcm_handle);
143 audio_return_t (*pcm_close)(void *audio_handle, void *pcm_handle);
144 audio_return_t (*pcm_avail)(void *audio_handle, void *pcm_handle, uint32_t *avail);
145 audio_return_t (*pcm_write)(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
146 audio_return_t (*pcm_read)(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
147 audio_return_t (*pcm_get_fd)(void *audio_handle, void *pcm_handle, int *fd);
148 audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents);
149 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);
150 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);
151 /* Message callback */
152 audio_return_t (*add_message_cb)(void *audio_handle, message_cb callback, void *user_data);
153 audio_return_t (*remove_message_cb)(void *audio_handle, message_cb callback);
157 * @brief Initializes audio hal.
159 * @param[out] audio_handle The audio hal handle
161 * @return @c 0 on success,
162 * otherwise a negative error value
163 * @retval #AUDIO_RET_OK Success
164 * @see audio_deinit()
166 audio_return_t audio_init(void **audio_handle);
169 * @brief De-initializes audio hal.
171 * @param[in] audio_handle The audio hal handle
173 * @return @c 0 on success,
174 * otherwise a negative error value
175 * @retval #AUDIO_RET_OK Success
178 audio_return_t audio_deinit(void *audio_handle);
181 * @brief Gets the maximum volume level supported for a particular volume information.
183 * @param[in] audio_handle The audio hal handle
184 * @param[in] info The audio volume information
185 * @param[out] level The maximum volume level
187 * @return @c 0 on success,
188 * otherwise a negative error value
189 * @retval #AUDIO_RET_OK Success
190 * @see audio_set_volume_level()
191 * @see audio_get_volume_level()
192 * @see audio_get_volume_value()
194 audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
197 * @brief Gets the volume level specified for a particular volume information.
199 * @param[in] audio_handle The audio hal handle
200 * @param[in] info The audio volume information
201 * @param[out] level The current volume level
203 * @return @c 0 on success,
204 * otherwise a negative error value
205 * @retval #AUDIO_RET_OK Success
206 * @see audio_set_volume_level()
207 * @see audio_get_volume_level_max()
208 * @see audio_get_volume_value()
210 audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
213 * @brief Sets the volume level specified for a particular volume information.
215 * @param[in] audio_handle The audio hal handle
216 * @param[in] info The audio volume information
217 * @param[in] level The volume level to be set
219 * @return @c 0 on success,
220 * otherwise a negative error value
221 * @retval #AUDIO_RET_OK Success
222 * @see audio_get_volume_level()
223 * @see audio_get_volume_level_max()
224 * @see audio_get_volume_value()
226 audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
229 * @brief Gets the volume value specified for a particular volume information and level.
231 * @param[in] audio_handle The audio hal handle
232 * @param[in] info The audio volume information
233 * @param[in] level The volume level
234 * @param[out] value The volume value (range is from 0.0 to 1.0 inclusive, 1.0 = 100%)
236 * @return @c 0 on success,
237 * otherwise a negative error value
238 * @retval #AUDIO_RET_OK Success
239 * @see audio_set_volume_level()
240 * @see audio_get_volume_level()
241 * @see audio_get_volume_level_max()
243 audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
246 * @brief Gets the volume mute specified for a particular volume information.
248 * @param[in] audio_handle The audio hal handle
249 * @param[in] info The audio volume information
250 * @param[out] mute The volume mute state : (@c 0 = unmute, @c 1 = mute)
252 * @return @c 0 on success,
253 * otherwise a negative error value
254 * @retval #AUDIO_RET_OK Success
255 * @see audio_set_volume_mute()
257 audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
260 * @brief Sets the volume mute specified for a particular volume information.
262 * @param[in] audio_handle The audio hal handle
263 * @param[in] info The audio volume information
264 * @param[in] mute The volume mute state to be set : (@c 0 = unmute, @c 1 = mute)
266 * @return @c 0 on success,
267 * otherwise a negative error value
268 * @retval #AUDIO_RET_OK Success
269 * @see audio_get_volume_mute()
271 audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
274 * @brief Updates the audio routing according to audio route information.
276 * @param[in] audio_handle The audio hal handle
277 * @param[in] info The audio route information including role and devices
279 * @return @c 0 on success,
280 * otherwise a negative error value
281 * @retval #AUDIO_RET_OK Success
282 * @see audio_update_route_option()
284 audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info);
287 * @brief Updates audio routing option according to audio route option.
289 * @param[in] audio_handle The audio hal handle
290 * @param[in] option The option that can be used for audio routing including role, name and value
292 * @remarks This option can be used for audio routing.\n
293 * It is recommended to apply this option for routing per each role.
295 * @return @c 0 on success,
296 * otherwise a negative error value
297 * @retval #AUDIO_RET_OK Success
298 * @see audio_update_route()
300 audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
303 * @brief Gets notified when a stream is connected and disconnected.
305 * @param[in] audio_handle The audio hal handle
306 * @param[in] info The stream information including role, direction, index
307 * @param[in] is_connected The connection state of this stream (@c true = connected, @c false = disconnected)
309 * @remarks This information can be used for audio routing, volume controls and so on.
311 * @return @c 0 on success,
312 * otherwise a negative error value
313 * @retval #AUDIO_RET_OK Success
315 audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
318 * @brief Opens a PCM device.
320 * @param[in] audio_handle The audio hal handle
321 * @param[out] pcm_handle The PCM handle
322 * @param[in] direction The direction of PCM
323 * @param[in] sample_spec The sample specification
324 * @param[in] period_size The period size
325 * @param[in] periods The periods
327 * @return @c 0 on success,
328 * otherwise a negative error value
329 * @retval #AUDIO_RET_OK Success
330 * @see audio_pcm_close()
332 audio_return_t audio_pcm_open(void *audio_handle, void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
335 * @brief Starts a PCM device.
337 * @param[in] audio_handle The audio hal handle
338 * @param[in] pcm_handle The PCM handle to be started
340 * @return @c 0 on success,
341 * otherwise a negative error value
342 * @retval #AUDIO_RET_OK Success
343 * @see audio_pcm_avail()
344 * @see audio_pcm_write()
345 * @see audio_pcm_read()
346 * @see audio_pcm_stop()
347 * @see audio_pcm_recover()
349 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
352 * @brief Stops a PCM device.
354 * @param[in] audio_handle The audio hal handle
355 * @param[in] pcm_handle The PCM handle to be stopped
357 * @return @c 0 on success,
358 * otherwise a negative error value
359 * @retval #AUDIO_RET_OK Success
360 * @see audio_pcm_start()
362 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
365 * @brief Closes a PCM device.
367 * @param[in] audio_handle The audio hal handle
368 * @param[in] pcm_handle The PCM handle to be closed
370 * @return @c 0 on success,
371 * otherwise a negative error value
372 * @retval #AUDIO_RET_OK Success
373 * @see audio_pcm_open()
375 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
378 * @brief Gets available number of frames.
380 * @param[in] audio_handle The audio hal handle
381 * @param[in] pcm_handle The PCM handle
382 * @param[out] avail The available number of frames
384 * @return @c 0 on success,
385 * otherwise a negative error value
386 * @retval #AUDIO_RET_OK Success
387 * @see audio_pcm_write()
388 * @see audio_pcm_read()
390 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
393 * @brief Writes frames to a PCM device.
395 * @param[in] audio_handle The audio hal handle
396 * @param[in] pcm_handle The PCM handle
397 * @param[in] buffer The buffer containing frames
398 * @param[in] frames The number of frames to be written
400 * @return @c 0 on success,
401 * otherwise a negative error value
402 * @retval #AUDIO_RET_OK Success
403 * @see audio_pcm_avail()
404 * @see audio_pcm_recover()
406 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
409 * @brief Reads frames from a PCM device.
411 * @param[in] audio_handle The audio hal handle
412 * @param[in] pcm_handle The PCM handle
413 * @param[out] buffer The buffer containing frames
414 * @param[in] frames The number of frames to be read
416 * @return @c 0 on success,
417 * otherwise a negative error value
418 * @retval #AUDIO_RET_OK Success
419 * @see audio_pcm_avail()
420 * @see audio_pcm_recover()
422 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
425 * @brief Gets poll descriptor for a PCM handle.
427 * @param[in] audio_handle The audio hal handle
428 * @param[in] pcm_handle The PCM handle
429 * @param[out] fd The poll descriptor
431 * @return @c 0 on success,
432 * otherwise a negative error value
433 * @retval #AUDIO_RET_OK Success
434 * @see audio_pcm_open()
435 * @see audio_pcm_recover()
437 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd);
440 * @brief Recovers the PCM state.
442 * @param[in] audio_handle The audio hal handle
443 * @param[in] pcm_handle The PCM handle
444 * @param[in] revents The returned event from pollfd
446 * @return @c 0 on success,
447 * otherwise a negative error value
448 * @retval #AUDIO_RET_OK Success
449 * @see audio_pcm_start()
450 * @see audio_pcm_write()
451 * @see audio_pcm_read()
452 * @see audio_pcm_get_fd()
454 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents);
457 * @brief Gets parameters of a PCM device.
459 * @param[in] audio_handle The audio hal handle
460 * @param[in] pcm_handle The PCM handle
461 * @param[in] direction The direction of PCM
462 * @param[out] sample_spec The sample specification
463 * @param[out] period_size The period size
464 * @param[out] periods The periods
466 * @return @c 0 on success,
467 * otherwise a negative error value
468 * @retval #AUDIO_RET_OK Success
469 * @see audio_pcm_set_params()
471 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);
474 * @brief Sets hardware and software parameters of a PCM device.
476 * @param[in] audio_handle The audio hal handle
477 * @param[in] pcm_handle The PCM handle
478 * @param[in] direction The direction of PCM
479 * @param[in] sample_spec The sample specification
480 * @param[in] period_size The period size
481 * @param[in] periods The periods
483 * @return @c 0 on success,
484 * otherwise a negative error value
485 * @retval #AUDIO_RET_OK Success
486 * @see audio_pcm_set_params()
488 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);
491 * @brief Adds the message callback function.
493 * @param[in] audio_handle The audio hal handle
494 * @param[in] message_cb The message callback function
495 * @param[in] user_data The user data passed to the callback function
498 * @see audio_remove_message_cb()
500 audio_return_t audio_add_message_cb(void *audio_handle, message_cb callback, void *user_data);
503 * @brief Removes the message callback function.
505 * @param[in] audio_handle The audio hal handle
506 * @param[in] message_cb The message callback function to be removed
509 * @see audio_add_message_cb()
511 audio_return_t audio_remove_message_cb(void *audio_handle, message_cb callback);