Fix invalid format string
[platform/adaptation/samsung_exynos/audio-hal-wm1831.git] / tizen-audio.h
1 /*
2  * audio-hal
3  *
4  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #ifndef footizenaudiofoo
21 #define footizenaudiofoo
22
23 #include <stdint.h>
24
25 /**
26  * @file tizen-audio.h
27  * @brief This file contains the Audio Hardware Abstraction Layer Interfaces.
28  */
29
30 /**
31  * @addtogroup TIZEN_AUDIO_HAL_MODULE
32  * @{
33  */
34
35 /**
36  * @brief Enumeration for return codes.
37  * @since_tizen 3.0
38  */
39 typedef enum audio_return {
40     AUDIO_RET_OK                        = 0,
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,
49 } audio_return_t ;
50
51 /**
52  * @brief Enumeration for audio direction.
53  * @since_tizen 3.0
54  */
55 typedef enum audio_direction {
56     AUDIO_DIRECTION_IN,                 /**< Capture */
57     AUDIO_DIRECTION_OUT,                /**< Playback */
58 } audio_direction_t;
59
60 /**
61  * @brief Device information including type, direction and id.
62  * @since_tizen 3.0
63  */
64 typedef struct device_info {
65     const char *type;
66     uint32_t direction;
67     uint32_t id;
68 } device_info_t;
69
70 /**
71  * @brief Volume information including type, gain and direction.
72  * @since_tizen 3.0
73  */
74 typedef struct audio_volume_info {
75     const char *type;
76     const char *gain;
77     uint32_t direction;
78 } audio_volume_info_t ;
79
80 /**
81  * @brief Route information including role and device.
82  * @since_tizen 3.0
83  */
84 typedef struct audio_route_info {
85     const char *role;
86     device_info_t *device_infos;
87     uint32_t num_of_devices;
88 } audio_route_info_t;
89
90 /**
91  * @brief Route option including role, name and value.
92  * @since_tizen 3.0
93  */
94 typedef struct audio_route_option {
95     const char *role;
96     const char *name;
97     int32_t value;
98 } audio_route_option_t;
99
100 /**
101  * @brief Stream information including role, direction and index.
102  * @since_tizen 3.0
103  */
104 typedef struct audio_stream_info {
105     const char *role;
106     uint32_t direction;
107     uint32_t idx;
108 } audio_stream_info_t ;
109
110 /* Overall */
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);
115     /* Volume */
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     /* Routing */
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);
125     /* Stream */
126     audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
127     /* PCM */
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);
139 } audio_interface_t;
140
141 /**
142  * @brief Initializes audio hal.
143  * @since_tizen 3.0
144  * @param[out] audio_handle The audio hal handle
145  *
146  * @return @c 0 on success,
147  *         otherwise a negative error value
148  * @retval #AUDIO_RET_OK Success
149  * @see audio_deinit()
150  */
151 audio_return_t audio_init(void **audio_handle);
152
153 /**
154  * @brief De-initializes audio hal.
155  * @since_tizen 3.0
156  * @param[in] audio_handle The audio hal handle
157  *
158  * @return @c 0 on success,
159  *         otherwise a negative error value
160  * @retval #AUDIO_RET_OK Success
161  * @see audio_init()
162  */
163 audio_return_t audio_deinit(void *audio_handle);
164
165 /**
166  * @brief Gets the maximum volume level supported for a particular volume information.
167  * @since_tizen 3.0
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
171  *
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()
178  */
179 audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
180
181 /**
182  * @brief Gets the volume level specified for a particular volume information.
183  * @since_tizen 3.0
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
187  *
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()
194  */
195 audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
196
197 /**
198  * @brief Sets the volume level specified for a particular volume information.
199  * @since_tizen 3.0
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
203  *
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()
210  */
211 audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
212
213 /**
214  * @brief Gets the volume value specified for a particular volume information and level.
215  * @since_tizen 3.0
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%)
220  *
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()
227  */
228 audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
229
230 /**
231  * @brief Gets the volume mute specified for a particular volume information.
232  * @since_tizen 3.0
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)
236  *
237  * @return @c 0 on success,
238  *         otherwise a negative error value
239  * @retval #AUDIO_RET_OK Success
240  * @see audio_set_volume_mute()
241  */
242 audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
243
244 /**
245  * @brief Sets the volume mute specified for a particular volume information.
246  * @since_tizen 3.0
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)
250  *
251  * @return @c 0 on success,
252  *         otherwise a negative error value
253  * @retval #AUDIO_RET_OK Success
254  * @see audio_get_volume_mute()
255  */
256 audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
257
258 /**
259  * @brief Updates the audio routing according to audio route information.
260  * @since_tizen 3.0
261  * @param[in] audio_handle The audio hal handle
262  * @param[in] info The audio route information including role and devices
263  *
264  * @return @c 0 on success,
265  *         otherwise a negative error value
266  * @retval #AUDIO_RET_OK Success
267  * @see audio_update_route_option()
268  */
269 audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info);
270
271 /**
272  * @brief Updates audio routing option according to audio route option.
273  * @since_tizen 3.0
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
276  *
277  * @remarks This option can be used for audio routing.\n
278  * It is recommended to apply this option for routing per each role.
279  *
280  * @return @c 0 on success,
281  *         otherwise a negative error value
282  * @retval #AUDIO_RET_OK Success
283  * @see audio_update_route()
284  */
285 audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
286
287 /**
288  * @brief Gets notified when a stream is connected and disconnected.
289  * @since_tizen 3.0
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)
293  *
294  * @remarks This information can be used for audio routing, volume controls and so on.
295  *
296  * @return @c 0 on success,
297  *         otherwise a negative error value
298  * @retval #AUDIO_RET_OK Success
299  */
300 audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
301
302 /**
303  * @brief Opens a PCM device.
304  * @since_tizen 3.0
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
313  *
314  * @return @c 0 on success,
315  *         otherwise a negative error value
316  * @retval #AUDIO_RET_OK Success
317  * @see audio_pcm_close()
318  */
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);
320
321 /**
322  * @brief Starts a PCM device.
323  * @since_tizen 3.0
324  * @param[in] audio_handle The audio hal handle
325  * @param[in] pcm_handle The PCM handle to be started
326  *
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()
335  */
336 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
337
338 /**
339  * @brief Stops a PCM device.
340  * @since_tizen 3.0
341  * @param[in] audio_handle The audio hal handle
342  * @param[in] pcm_handle The PCM handle to be stopped
343  *
344  * @return @c 0 on success,
345  *         otherwise a negative error value
346  * @retval #AUDIO_RET_OK Success
347  * @see audio_pcm_start()
348  */
349 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
350
351 /**
352  * @brief Closes a PCM device.
353  * @since_tizen 3.0
354  * @param[in] audio_handle The audio hal handle
355  * @param[in] pcm_handle The PCM handle to be closed
356  *
357  * @return @c 0 on success,
358  *         otherwise a negative error value
359  * @retval #AUDIO_RET_OK Success
360  * @see audio_pcm_open()
361  */
362 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
363
364 /**
365  * @brief Gets available number of frames.
366  * @since_tizen 3.0
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
370  *
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()
376  */
377 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
378
379 /**
380  * @brief Writes frames to a PCM device.
381  * @since_tizen 3.0
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
386  *
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()
392  */
393 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
394
395 /**
396  * @brief Reads frames from a PCM device.
397  * @since_tizen 3.0
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
402  *
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()
408  */
409 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
410
411 /**
412  * @brief Gets poll descriptor for a PCM handle.
413  * @since_tizen 3.0
414  * @param[in] audio_handle The audio hal handle
415  * @param[in] pcm_handle The PCM handle
416  * @param[out] fd The poll descriptor
417  *
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()
423  */
424 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd);
425
426 /**
427  * @brief Recovers the PCM state.
428  * @since_tizen 3.0
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
432  *
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()
440  */
441 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents);
442
443 /**
444  * @brief Gets parameters of a PCM device.
445  * @since_tizen 3.0
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
452  *
453  * @return @c 0 on success,
454  *         otherwise a negative error value
455  * @retval #AUDIO_RET_OK Success
456  * @see audio_pcm_set_params()
457  */
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);
459
460 /**
461  * @brief Sets hardware and software parameters of a PCM device.
462  * @since_tizen 3.0
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
469  *
470  * @return @c 0 on success,
471  *         otherwise a negative error value
472  * @retval #AUDIO_RET_OK Success
473  * @see audio_pcm_set_params()
474  */
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);
476
477 /**
478 * @}
479 */
480
481 /**
482 * @}
483 */
484
485 #endif