Sync with latest HAL codes
[platform/adaptation/ap_broadcom/audio-hal-bcm2837.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     audio_return_t (*set_volume_ratio)(void *audio_handle, audio_stream_info_t *info, double ratio);
123     /* Routing */
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);
126     /* Stream */
127     audio_return_t (*notify_stream_connection_changed)(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
128     /* PCM */
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);
140 } audio_interface_t;
141
142 /**
143  * @brief Initializes audio hal.
144  * @since_tizen 3.0
145  * @param[out] audio_handle The audio hal handle
146  *
147  * @return @c 0 on success,
148  *         otherwise a negative error value
149  * @retval #AUDIO_RET_OK Success
150  * @see audio_deinit()
151  */
152 audio_return_t audio_init(void **audio_handle);
153
154 /**
155  * @brief De-initializes audio hal.
156  * @since_tizen 3.0
157  * @param[in] audio_handle The audio hal handle
158  *
159  * @return @c 0 on success,
160  *         otherwise a negative error value
161  * @retval #AUDIO_RET_OK Success
162  * @see audio_init()
163  */
164 audio_return_t audio_deinit(void *audio_handle);
165
166 /**
167  * @brief Gets the maximum volume level supported for a particular volume information.
168  * @since_tizen 3.0
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
172  *
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()
179  */
180 audio_return_t audio_get_volume_level_max(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
181
182 /**
183  * @brief Gets the volume level specified for a particular volume information.
184  * @since_tizen 3.0
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
188  *
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()
195  */
196 audio_return_t audio_get_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
197
198 /**
199  * @brief Sets the volume level specified for a particular volume information.
200  * @since_tizen 3.0
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
204  *
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()
211  */
212 audio_return_t audio_set_volume_level(void *audio_handle, audio_volume_info_t *info, uint32_t level);
213
214 /**
215  * @brief Gets the volume value specified for a particular volume information and level.
216  * @since_tizen 3.0
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%)
221  *
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()
228  */
229 audio_return_t audio_get_volume_value(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
230
231 /**
232  * @brief Gets the volume mute specified for a particular volume information.
233  * @since_tizen 3.0
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)
237  *
238  * @return @c 0 on success,
239  *         otherwise a negative error value
240  * @retval #AUDIO_RET_OK Success
241  * @see audio_set_volume_mute()
242  */
243 audio_return_t audio_get_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
244
245 /**
246  * @brief Sets the volume mute specified for a particular volume information.
247  * @since_tizen 3.0
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)
251  *
252  * @return @c 0 on success,
253  *         otherwise a negative error value
254  * @retval #AUDIO_RET_OK Success
255  * @see audio_get_volume_mute()
256  */
257 audio_return_t audio_set_volume_mute(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
258
259 /**
260  * @brief Updates the audio routing according to audio route information.
261  * @since_tizen 3.0
262  * @param[in] audio_handle The audio hal handle
263  * @param[in] info The audio route information including role and devices
264  *
265  * @return @c 0 on success,
266  *         otherwise a negative error value
267  * @retval #AUDIO_RET_OK Success
268  * @see audio_update_route_option()
269  */
270 audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info);
271
272 /**
273  * @brief Updates audio routing option according to audio route option.
274  * @since_tizen 3.0
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
277  *
278  * @remarks This option can be used for audio routing.\n
279  * It is recommended to apply this option for routing per each role.
280  *
281  * @return @c 0 on success,
282  *         otherwise a negative error value
283  * @retval #AUDIO_RET_OK Success
284  * @see audio_update_route()
285  */
286 audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option);
287
288 /**
289  * @brief Gets notified when a stream is connected and disconnected.
290  * @since_tizen 3.0
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)
294  *
295  * @remarks This information can be used for audio routing, volume controls and so on.
296  *
297  * @return @c 0 on success,
298  *         otherwise a negative error value
299  * @retval #AUDIO_RET_OK Success
300  */
301 audio_return_t audio_notify_stream_connection_changed(void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
302
303 /**
304  * @brief Opens a PCM device.
305  * @since_tizen 3.0
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
314  *
315  * @return @c 0 on success,
316  *         otherwise a negative error value
317  * @retval #AUDIO_RET_OK Success
318  * @see audio_pcm_close()
319  */
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);
321
322 /**
323  * @brief Starts a PCM device.
324  * @since_tizen 3.0
325  * @param[in] audio_handle The audio hal handle
326  * @param[in] pcm_handle The PCM handle to be started
327  *
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()
336  */
337 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle);
338
339 /**
340  * @brief Stops a PCM device.
341  * @since_tizen 3.0
342  * @param[in] audio_handle The audio hal handle
343  * @param[in] pcm_handle The PCM handle to be stopped
344  *
345  * @return @c 0 on success,
346  *         otherwise a negative error value
347  * @retval #AUDIO_RET_OK Success
348  * @see audio_pcm_start()
349  */
350 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle);
351
352 /**
353  * @brief Closes a PCM device.
354  * @since_tizen 3.0
355  * @param[in] audio_handle The audio hal handle
356  * @param[in] pcm_handle The PCM handle to be closed
357  *
358  * @return @c 0 on success,
359  *         otherwise a negative error value
360  * @retval #AUDIO_RET_OK Success
361  * @see audio_pcm_open()
362  */
363 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle);
364
365 /**
366  * @brief Gets available number of frames.
367  * @since_tizen 3.0
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
371  *
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()
377  */
378 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail);
379
380 /**
381  * @brief Writes frames to a PCM device.
382  * @since_tizen 3.0
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
387  *
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()
393  */
394 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames);
395
396 /**
397  * @brief Reads frames from a PCM device.
398  * @since_tizen 3.0
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
403  *
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()
409  */
410 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames);
411
412 /**
413  * @brief Gets poll descriptor for a PCM handle.
414  * @since_tizen 3.0
415  * @param[in] audio_handle The audio hal handle
416  * @param[in] pcm_handle The PCM handle
417  * @param[out] fd The poll descriptor
418  *
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()
424  */
425 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd);
426
427 /**
428  * @brief Recovers the PCM state.
429  * @since_tizen 3.0
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
433  *
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()
441  */
442 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents);
443
444 /**
445  * @brief Gets parameters of a PCM device.
446  * @since_tizen 3.0
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
453  *
454  * @return @c 0 on success,
455  *         otherwise a negative error value
456  * @retval #AUDIO_RET_OK Success
457  * @see audio_pcm_set_params()
458  */
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);
460
461 /**
462  * @brief Sets hardware and software parameters of a PCM device.
463  * @since_tizen 3.0
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
470  *
471  * @return @c 0 on success,
472  *         otherwise a negative error value
473  * @retval #AUDIO_RET_OK Success
474  * @see audio_pcm_set_params()
475  */
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);
477
478 /**
479 * @}
480 */
481
482 /**
483 * @}
484 */
485
486 #endif