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);
122 audio_return_t (*set_volume_ratio)(void *audio_handle, audio_stream_info_t *info, double ratio);
124 audio_return_t (*update_route)(void *audio_handle, audio_route_info_t *info);
125 audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option);
127 audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
129 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);
130 audio_return_t (*pcm_start)(void *audio_handle, void *pcm_handle);
131 audio_return_t (*pcm_stop)(void *audio_handle, void *pcm_handle);
132 audio_return_t (*pcm_close)(void *audio_handle, void *pcm_handle);
133 audio_return_t (*pcm_avail)(void *audio_handle, void *pcm_handle, uint32_t *avail);
134 audio_return_t (*pcm_write)(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
135 audio_return_t (*pcm_read)(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
136 audio_return_t (*pcm_get_fd)(void *audio_handle, void *pcm_handle, int *fd);
137 audio_return_t (*pcm_recover)(void *audio_handle, void *pcm_handle, int revents);
138 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);
139 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);
143 * @brief Initializes audio hal.
145 * @param[out] audio_handle The audio hal handle
147 * @return @c 0 on success,
148 * otherwise a negative error value
149 * @retval #AUDIO_RET_OK Success
150 * @see audio_deinit()
152 audio_return_t audio_init(void **audio_handle);
155 * @brief De-initializes audio hal.
157 * @param[in] audio_handle The audio hal handle
159 * @return @c 0 on success,
160 * otherwise a negative error value
161 * @retval #AUDIO_RET_OK Success
164 audio_return_t audio_deinit(void *audio_handle);
167 * @brief Gets the maximum volume level supported for a particular volume information.
169 * @param[in] audio_handle The audio hal handle
170 * @param[in] info The audio volume information
171 * @param[out] level The maximum volume level
173 * @return @c 0 on success,
174 * otherwise a negative error value
175 * @retval #AUDIO_RET_OK Success
176 * @see audio_set_volume_level()
177 * @see audio_get_volume_level()
178 * @see audio_get_volume_value()
180 audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
183 * @brief Gets the volume level specified for a particular volume information.
185 * @param[in] audio_handle The audio hal handle
186 * @param[in] info The audio volume information
187 * @param[out] level The current volume level
189 * @return @c 0 on success,
190 * otherwise a negative error value
191 * @retval #AUDIO_RET_OK Success
192 * @see audio_set_volume_level()
193 * @see audio_get_volume_level_max()
194 * @see audio_get_volume_value()
196 audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
199 * @brief Sets the volume level specified for a particular volume information.
201 * @param[in] audio_handle The audio hal handle
202 * @param[in] info The audio volume information
203 * @param[in] level The volume level to be set
205 * @return @c 0 on success,
206 * otherwise a negative error value
207 * @retval #AUDIO_RET_OK Success
208 * @see audio_get_volume_level()
209 * @see audio_get_volume_level_max()
210 * @see audio_get_volume_value()
212 audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
215 * @brief Gets the volume value specified for a particular volume information and level.
217 * @param[in] audio_handle The audio hal handle
218 * @param[in] info The audio volume information
219 * @param[in] level The volume level
220 * @param[out] value The volume value (range is from 0.0 to 1.0 inclusive, 1.0 = 100%)
222 * @return @c 0 on success,
223 * otherwise a negative error value
224 * @retval #AUDIO_RET_OK Success
225 * @see audio_set_volume_level()
226 * @see audio_get_volume_level()
227 * @see audio_get_volume_level_max()
229 audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
232 * @brief Gets the volume mute specified for a particular volume information.
234 * @param[in] audio_handle The audio hal handle
235 * @param[in] info The audio volume information
236 * @param[out] mute The volume mute state : (@c 0 = unmute, @c 1 = mute)
238 * @return @c 0 on success,
239 * otherwise a negative error value
240 * @retval #AUDIO_RET_OK Success
241 * @see audio_set_volume_mute()
243 audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
246 * @brief Sets 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[in] mute The volume mute state to be set : (@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_get_volume_mute()
257 audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
260 * @brief Updates the audio routing according to audio route information.
262 * @param[in] audio_handle The audio hal handle
263 * @param[in] info The audio route information including role and devices
265 * @return @c 0 on success,
266 * otherwise a negative error value
267 * @retval #AUDIO_RET_OK Success
268 * @see audio_update_route_option()
270 audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info);
273 * @brief Updates audio routing option according to audio route option.
275 * @param[in] audio_handle The audio hal handle
276 * @param[in] option The option that can be used for audio routing including role, name and value
278 * @remarks This option can be used for audio routing.\n
279 * It is recommended to apply this option for routing per each role.
281 * @return @c 0 on success,
282 * otherwise a negative error value
283 * @retval #AUDIO_RET_OK Success
284 * @see audio_update_route()
286 audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
289 * @brief Gets notified when a stream is connected and disconnected.
291 * @param[in] audio_handle The audio hal handle
292 * @param[in] info The stream information including role, direction, index
293 * @param[in] is_connected The connection state of this stream (@c true = connected, @c false = disconnected)
295 * @remarks This information can be used for audio routing, volume controls and so on.
297 * @return @c 0 on success,
298 * otherwise a negative error value
299 * @retval #AUDIO_RET_OK Success
301 audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
304 * @brief Opens a PCM device.
306 * @param[in] audio_handle The audio hal handle
307 * @param[in] card The card of PCM
308 * @param[in] device The device of PCM
309 * @param[in] direction The direction of PCM
310 * @param[in] sample_spec The sample specification
311 * @param[in] period_size The period size
312 * @param[in] periods The periods
313 * @param[out] pcm_handle The PCM handle
315 * @return @c 0 on success,
316 * otherwise a negative error value
317 * @retval #AUDIO_RET_OK Success
318 * @see audio_pcm_close()
320 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);
323 * @brief Starts a PCM device.
325 * @param[in] audio_handle The audio hal handle
326 * @param[in] pcm_handle The PCM handle to be started
328 * @return @c 0 on success,
329 * otherwise a negative error value
330 * @retval #AUDIO_RET_OK Success
331 * @see audio_pcm_avail()
332 * @see audio_pcm_write()
333 * @see audio_pcm_read()
334 * @see audio_pcm_stop()
335 * @see audio_pcm_recover()
337 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
340 * @brief Stops a PCM device.
342 * @param[in] audio_handle The audio hal handle
343 * @param[in] pcm_handle The PCM handle to be stopped
345 * @return @c 0 on success,
346 * otherwise a negative error value
347 * @retval #AUDIO_RET_OK Success
348 * @see audio_pcm_start()
350 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
353 * @brief Closes a PCM device.
355 * @param[in] audio_handle The audio hal handle
356 * @param[in] pcm_handle The PCM handle to be closed
358 * @return @c 0 on success,
359 * otherwise a negative error value
360 * @retval #AUDIO_RET_OK Success
361 * @see audio_pcm_open()
363 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
366 * @brief Gets available number of frames.
368 * @param[in] audio_handle The audio hal handle
369 * @param[in] pcm_handle The PCM handle
370 * @param[out] avail The available number of frames
372 * @return @c 0 on success,
373 * otherwise a negative error value
374 * @retval #AUDIO_RET_OK Success
375 * @see audio_pcm_write()
376 * @see audio_pcm_read()
378 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
381 * @brief Writes frames to a PCM device.
383 * @param[in] audio_handle The audio hal handle
384 * @param[in] pcm_handle The PCM handle
385 * @param[in] buffer The buffer containing frames
386 * @param[in] frames The number of frames to be written
388 * @return @c 0 on success,
389 * otherwise a negative error value
390 * @retval #AUDIO_RET_OK Success
391 * @see audio_pcm_avail()
392 * @see audio_pcm_recover()
394 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
397 * @brief Reads frames from a PCM device.
399 * @param[in] audio_handle The audio hal handle
400 * @param[in] pcm_handle The PCM handle
401 * @param[out] buffer The buffer containing frames
402 * @param[in] frames The number of frames to be read
404 * @return @c 0 on success,
405 * otherwise a negative error value
406 * @retval #AUDIO_RET_OK Success
407 * @see audio_pcm_avail()
408 * @see audio_pcm_recover()
410 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
413 * @brief Gets poll descriptor for a PCM handle.
415 * @param[in] audio_handle The audio hal handle
416 * @param[in] pcm_handle The PCM handle
417 * @param[out] fd The poll descriptor
419 * @return @c 0 on success,
420 * otherwise a negative error value
421 * @retval #AUDIO_RET_OK Success
422 * @see audio_pcm_open()
423 * @see audio_pcm_recover()
425 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd);
428 * @brief Recovers the PCM state.
430 * @param[in] audio_handle The audio hal handle
431 * @param[in] pcm_handle The PCM handle
432 * @param[in] revents The returned event from pollfd
434 * @return @c 0 on success,
435 * otherwise a negative error value
436 * @retval #AUDIO_RET_OK Success
437 * @see audio_pcm_start()
438 * @see audio_pcm_write()
439 * @see audio_pcm_read()
440 * @see audio_pcm_get_fd()
442 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents);
445 * @brief Gets parameters of a PCM device.
447 * @param[in] audio_handle The audio hal handle
448 * @param[in] pcm_handle The PCM handle
449 * @param[in] direction The direction of PCM
450 * @param[out] sample_spec The sample specification
451 * @param[out] period_size The period size
452 * @param[out] periods The periods
454 * @return @c 0 on success,
455 * otherwise a negative error value
456 * @retval #AUDIO_RET_OK Success
457 * @see audio_pcm_set_params()
459 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);
462 * @brief Sets hardware and software parameters of a PCM device.
464 * @param[in] audio_handle The audio hal handle
465 * @param[in] pcm_handle The PCM handle
466 * @param[in] direction The direction of PCM
467 * @param[in] sample_spec The sample specification
468 * @param[in] period_size The period size
469 * @param[in] periods The periods
471 * @return @c 0 on success,
472 * otherwise a negative error value
473 * @retval #AUDIO_RET_OK Success
474 * @see audio_pcm_set_params()
476 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);