delete sound policy API,sound_manager_get_current_sound_device
[framework/api/sound-manager.git] / include / sound_manager.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19
20 #ifndef __TIZEN_MEDIA_SOUND_MANAGER_H__
21 #define __TIZEN_MEDIA_SOUND_MANAGER_H__
22
23 #include <tizen.h>
24
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29
30 #define SOUND_MANAGER_ERROR_CLASS          TIZEN_ERROR_MULTIMEDIA_CLASS | 0x30
31
32 /**
33  * @file sound_manager.h
34  * @brief This file contains the Sound Manager API
35  */
36
37 /**
38  * @addtogroup CAPI_MEDIA_SOUND_MANAGER_MODULE
39  * @{
40  */
41
42 /**
43  * @brief Enumerations of sound type
44  */
45 typedef enum
46 {
47     SOUND_TYPE_SYSTEM,          /**< Sound type for system */
48     SOUND_TYPE_NOTIFICATION,    /**< Sound type for notifications */
49     SOUND_TYPE_ALARM,           /**< Sound type for alarm */
50     SOUND_TYPE_RINGTONE,        /**< Sound type for ringtones */
51     SOUND_TYPE_MEDIA,           /**< Sound type for media */
52     SOUND_TYPE_CALL,            /**< Sound type for call */
53 } sound_type_e;
54
55 /**
56  * @brief Enumerations of volume key type
57  */
58 typedef enum
59 {
60     VOLUME_KEY_TYPE_NONE=-1,          /**< Volume key type for current played sound */
61     VOLUME_KEY_TYPE_SYSTEM=0,          /**< Volume key type for system sound */
62     VOLUME_KEY_TYPE_NOTIFICATION,    /**< Volume key type for notifications sound*/
63     VOLUME_KEY_TYPE_ALARM,           /**< Volume key type for alarm sound */
64     VOLUME_KEY_TYPE_RINGTONE,        /**< Volume key type for ringtones sound */
65     VOLUME_KEY_TYPE_MEDIA,           /**< Volume key type for media sound */
66     VOLUME_KEY_TYPE_CALL,            /**< Volume key type for call sound */
67 } volume_key_type_e;
68
69 /**
70  * @brief error codes for sound manager
71  */
72 typedef enum{
73     SOUND_MANAGER_ERROR_NONE        = TIZEN_ERROR_NONE,                      /**< Successful */
74     SOUND_MANAGER_ERROR_OUT_OF_MEMORY       = TIZEN_ERROR_OUT_OF_MEMORY,           /**< Out of memory */
75     SOUND_MANAGER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,       /**< Invalid parameter */
76     SOUND_MANAGER_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,       /**< Invalid operation */
77     SOUND_MANAGER_ERROR_NO_PLAYING_SOUND  = SOUND_MANAGER_ERROR_CLASS | 01,    /**< No playing sound */
78 } sound_manager_error_e;
79
80 /**
81  * @brief Enumerations of session type
82  */
83 typedef enum{
84         SOUND_SESSION_TYPE_SHARE = 0,                   /**< Share type : shares it's session with other share type application. */
85         SOUND_SESSION_TYPE_EXCLUSIVE,                   /**< Exclusive type : make previous session stop.*/
86 } sound_session_type_e;
87
88 /**
89  * @brief Enumerations of session notification
90  */
91 typedef enum{
92         SOUND_SESSION_NOTIFY_STOP = 0,                  /**< Stop : session of application has interrupted by policy. */
93         SOUND_SESSION_NOTIFY_RESUME,               /**< Resume : session interrupt of application has ended. */
94 } sound_session_notify_e;
95
96 /**
97  * @brief Enumerations of audio input device type.
98  */
99 typedef enum{
100         SOUND_DEVICE_IN_MIC = 0x01, /**< Device builtin mic. */
101         SOUND_DEVICE_IN_WIRED_ACCESSORY = 0x02,         /**< Wired input devices */
102         SOUND_DEVICE_IN_BT_SCO = 0x04,          /**< Bluetooth SCO device */
103 } sound_device_in_e;
104
105 /**
106  * @brief Enumerations of audio output device type.
107  */
108 typedef enum{
109         SOUND_DEVICE_OUT_SPEAKER = 0x01<<8, /**< Device builtin speaker */
110         SOUND_DEVICE_OUT_RECEIVER = 0x02<<8, /**< Device builtin receiver */
111         SOUND_DEVICE_OUT_WIRED_ACCESSORY = 0x04<<8,     /**< Wired output devices such as headphone, headset, and so on. */
112         SOUND_DEVICE_OUT_BT_SCO = 0x08<<8, /**< Bluetooth SCO device */
113         SOUND_DEVICE_OUT_BT_A2DP = 0x10<<8,     /**< Bluetooth A2DP device */
114 } sound_device_out_e;
115
116 /**
117  * @brief Enumerations of route type.
118  */
119 typedef enum{
120         SOUND_ROUTE_OUT_SPEAKER = SOUND_DEVICE_OUT_SPEAKER, /**< Routing audio output to builtin device such as internal speaker. */
121         SOUND_ROUTE_OUT_WIRED_ACCESSORY = SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio output to wired accessory such as headphone, headset, and so on. */
122         SOUND_ROUTE_OUT_BLUETOOTH = SOUND_DEVICE_OUT_BT_A2DP, /**< Routing audio output to bluetooth A2DP. */
123         SOUND_ROUTE_IN_MIC = SOUND_DEVICE_IN_MIC, /**< Routing audio input to device builtin mic. */
124         SOUND_ROUTE_IN_WIRED_ACCESSORY = SOUND_DEVICE_IN_WIRED_ACCESSORY, /**< Routing audio input to wired accessory. */
125         SOUND_ROUTE_IN_MIC_OUT_RECEIVER = SOUND_DEVICE_IN_MIC |SOUND_DEVICE_OUT_RECEIVER, /**< Routing audio input to device builtin mic and routing audio output to builtin receiver*/
126         SOUND_ROUTE_IN_MIC_OUT_SPEAKER = SOUND_DEVICE_IN_MIC |SOUND_DEVICE_OUT_SPEAKER , /**< Routing audio input to device builtin mic and routing audio output to builtin speaker */
127         SOUND_ROUTE_IN_MIC_OUT_HEADPHONE = SOUND_DEVICE_IN_MIC | SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio input to device builtin mic and routing audio output to headphone */
128         SOUND_ROUTE_INOUT_HEADSET = SOUND_DEVICE_IN_WIRED_ACCESSORY | SOUND_DEVICE_OUT_WIRED_ACCESSORY, /**< Routing audio input and output to headset*/
129         SOUND_ROUTE_INOUT_BLUETOOTH = SOUND_DEVICE_IN_BT_SCO |SOUND_DEVICE_OUT_BT_SCO /**< Routing audio input and output to bluetooth SCO */
130 } sound_route_e;
131
132 /**
133  * @brief Enumerations of call session type
134  */
135 typedef enum{
136         SOUND_CALL_SESSION_TYPE_CALL = 0,       /**< call type */
137         SOUND_CALL_SESSION_TYPE_VOIP = 1,                       /**<  voip type */
138         SOUND_SESSION_TYPE_CALL = 0,
139         SOUND_SESSION_TYPE_VOIP = 1,
140 } sound_call_session_type_e;
141
142 /**
143  * @brief Enumerations of communication session type
144  */
145 typedef enum{
146         SOUND_CALL_SESSION_MODE_VOICE = 0,              /**< normal talking mode */
147         SOUND_CALL_SESSION_MODE_RINGTONE,               /**< ringtone mode */
148         SOUND_CALL_SESSION_MODE_MEDIA,                  /**< notification sound in call*/
149 } sound_call_session_mode_e;
150
151 /**
152  * @brief Enumerations of sound interrupted type
153  */
154 typedef enum
155 {
156                 SOUND_INTERRUPTED_COMPLETED = 0,                                /**< Interrupt completed*/
157        SOUND_INTERRUPTED_BY_OTHER_APP,                          /**< Interrupted by another application*/
158        SOUND_INTERRUPTED_BY_CALL,                                               /**< Interrupted by incoming call*/
159        SOUND_INTERRUPTED_BY_EARJACK_UNPLUG,                     /**< Interrupted by unplugging headphone*/
160        SOUND_INTERRUPTED_BY_RESOURCE_CONFLICT,          /**< Interrupted by resource conflict*/
161        SOUND_INTERRUPTED_BY_ALARM,                                      /**< Interrupted by alarm*/
162 } sound_interrupted_code_e;
163
164 /**
165  * @brief Sound call session handle type.
166  */
167 typedef struct sound_call_session_s *sound_call_session_h;
168
169 /**
170  * @brief Called when the sound session notification has occured.
171  * @param[in]   notify  The sound session notification
172  * @param[in]   user_data       The user data passed from the callback registration function
173  * @pre You should register this callback by sound_manager_set_session_notify_cb()
174  * @see sound_manager_set_session_notify_cb()
175  */
176 typedef void (*sound_session_notify_cb) (sound_session_notify_e notify, void *user_data);
177
178 /**
179  * @brief Called when the playing sound was interrupted.
180  * @param[in]   code    The interrupted code
181  * @param[in]   user_data       The user data passed from the callback registration function
182  * @pre You should register this callback by sound_manager_set_interrupted_cb()
183  * @see sound_manager_set_interrupted_cb()
184  */
185 typedef void(* sound_interrupted_cb)(sound_interrupted_code_e code, void *user_data);
186
187
188 /**
189  * @brief Called when the system volume has changed.
190  * @param[in]   type    The sound type of changed volume
191  * @param[in]   volume  The new volume value
192  * @param[in]   user_data       The user data passed from the callback registration function
193  * @pre sound_manager_set_volume() will invoke this callback if you register it using sound_manager_set_volume_changed_cb()
194  * @see sound_manager_set_volume_changed_cb()
195  * @see sound_manager_unset_volume_changed_cb()
196  */
197 typedef void (*sound_manager_volume_changed_cb)(sound_type_e type, unsigned int volume, void *user_data);
198
199 /**
200  * @brief Gets the maximum volume level supported for a particular sound type
201  * @param[in]           type The sound type
202  * @param[out]  max     The maximum volume level
203  * @return 0 on success, otherwise a negative error value.
204  * @retval #SOUND_MANAGER_ERROR_NONE Success
205  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
206  * @see sound_manager_set_volume()
207  */
208 int sound_manager_get_max_volume(sound_type_e type, int *max);
209
210 /**
211  * @brief Sets the volume level specified for a particular sound type
212  * @param[in]           type The sound type
213  * @param[out]  volume  The volume level to be set
214  * @return 0 on success, otherwise a negative error value.
215  * @retval #SOUND_MANAGER_ERROR_NONE Success
216  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
217  * @see sound_manager_get_max_volume()
218  * @see sound_manager_get_volume()
219  */
220 int sound_manager_set_volume(sound_type_e type, int volume);
221
222 /**
223  * @brief Gets the volume level specified for a particular sound type
224  * @param[in]           type The sound type
225  * @param[out]  volume  The current volume level
226  * @return 0 on success, otherwise a negative error value.
227  * @retval #SOUND_MANAGER_ERROR_NONE Success
228  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
229  * @see sound_manager_get_max_volume()
230  * @see sound_manager_set_volume()
231  */
232 int sound_manager_get_volume(sound_type_e type, int *volume);
233
234 /**
235  * @brief Gets the current playing sound type
236  * @param[out]          type The current sound type
237  * @return 0 on success, otherwise a negative error value.
238  * @retval #SOUND_MANAGER_ERROR_NONE Success
239  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
240  * @retval #SOUND_MANAGER_ERROR_NO_PLAYING_SOUND No playing sound
241  * @see player_set_sound_type()
242  * @see audio_out_create()
243  * @see wav_player_start()
244  */
245 int sound_manager_get_current_sound_type(sound_type_e *type);
246
247 /**
248  * @brief Registers a callback function to be invoked when the volume level is changed.
249  * @param[in]   callback        Callback function to indicate change in volume
250  * @param[in]   user_data       The user data to be passed to the callback function
251  * @return 0 on success, otherwise a negative error value.
252  * @retval #SOUND_MANAGER_ERROR_NONE Success
253  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
254  * @post  sound_manager_volume_changed_cb() will be invoked
255  * @see sound_manager_unset_volume_changed_cb()
256  * @see sound_manager_volume_changed_cb()
257  */
258 int sound_manager_set_volume_changed_cb(sound_manager_volume_changed_cb callback, void *user_data);
259
260 /**
261  * @brief Unregisters the volume change callback
262  * @see sound_manager_set_volume_changed_cb()
263  */
264 void sound_manager_unset_volume_changed_cb(void);
265
266 /**
267  * @brief Gets the A2DP activation information.
268  * @remarks If @a connected is @c true,  @a bt_name must be released with free() by you. If @a connected is @c false, @a bt_name is set to NULL.
269  * @param[out] connected The Bluetooth A2DP connection status (@c true = connected, @c false = disconnected)
270  * @param[out] bt_name The Bluetooth A2DP connected device name
271  * @return 0 on success, otherwise a negative error value.
272  * @retval #SOUND_MANAGER_ERROR_NONE Success
273  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
274  * @retval #SOUND_MANAGER_ERROR_INVALID_OPERATION Invalid operation
275  */
276 int sound_manager_get_a2dp_status(bool *connected, char **bt_name);
277
278
279 /**
280  * @brief Sets the application's sound session type
281  * @param[in] type The session type to set
282  * @return 0 on success, otherwise a negative error value.
283  * @retval #SOUND_MANAGER_ERROR_NONE Success
284  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
285  */
286 int sound_manager_set_session_type(sound_session_type_e type);
287
288 /**
289  * @brief Registers a callback function to be invoked when the sound session notification is occured.
290  * @param[in]   callback        The session notify callback function
291  * @param[in]   user_data       The user data to be passed to the callback function
292  * @return 0 on success, otherwise a negative error value.
293  * @retval #SOUND_MANAGER_ERROR_NONE Success
294  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
295  * @post  sound_session_notify_cb() will be invoked
296  * @see sound_manager_unset_session_notify_cb()
297  * @see sound_session_notify_cb()
298  */
299 int sound_manager_set_session_notify_cb(sound_session_notify_cb callback, void *user_data);
300
301 /**
302  * @brief Unregisters the callback function which is called when the session notification is occured
303  * @see sound_manager_set_session_notify_cb()
304  */
305 void sound_manager_unset_session_notify_cb(void);
306
307 /**
308  * @brief Registers a callback function to be invoked when the playing sound was interrupted.
309  * @param[in]   callback        The interrupted callback function
310  * @param[in]   user_data       The user data to be passed to the callback function
311  * @return 0 on success, otherwise a negative error value.
312  * @retval #SOUND_MANAGER_ERROR_NONE Success
313  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
314  * @post  sound_interrupted_cb() will be invoked
315  * @see sound_manager_unset_interrupted_cb()
316  * @see sound_interrupted_cb()
317  */
318 int sound_manager_set_interrupted_cb(sound_interrupted_cb callback, void *user_data);
319
320 /**
321  * @brief Unregisters the callback function which is called when the playing sound was interrupted
322  * @see sound_manager_set_interrupted_cb()
323  */
324 void sound_manager_unset_interrupted_cb(void);
325
326
327
328 /**
329  * @brief Sets the volume key type
330  * @param[in] type The volume key type to set
331  * @return 0 on success, otherwise a negative error value.
332  * @retval #SOUND_MANAGER_ERROR_NONE Success
333  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
334  */
335 int sound_manager_set_volume_key_type(volume_key_type_e type);
336
337 /**
338  * @brief Gets called iteratively to notify you of available route.
339  * @param[in]   route The available route
340  * @param[in]   user_data The user data passed from the foreach function
341  * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
342  * @pre  sound_manager_foreach_available_route() will invoke this callback.
343  * @see sound_manager_foreach_available_route()
344  */
345 typedef bool(* sound_available_route_cb)(sound_route_e route, void *user_data);
346
347 /**
348  * @brief Called when the available audio route is changed.
349  * @param[in]   route The audio route
350  * @param[in]   available The status of given route
351  * @param[in]   user_data The user data passed from the foreach function
352  * @pre  sound_manager_foreach_available_route() will invoke this callback.
353  * @see sound_manager_foreach_available_route()
354  */
355 typedef void(* sound_available_route_changed_cb)(sound_route_e route, bool available, void *user_data);
356
357 /**
358  * @brief Called when the audio route is changed.
359  * @param[in]   route The audio route
360  * @param[in]   user_data The user data passed from the callback registration function
361  * @pre  You should register this callback by sound_manager_set_active_device_changed_cb()
362  * @see sound_manager_set_active_device_changed_cb()
363  */
364 typedef void(* sound_active_device_changed_cb)(sound_device_in_e in, sound_device_out_e out, void *user_data);
365
366 /**
367  * @brief Retrieves all available audio routes by invoking a specific callback for each valid route.
368  * @param[in]   callback        The session notify callback function
369  * @param[in]   user_data       The user data to be passed to the callback function
370  * @return 0 on success, otherwise a negative error value.
371  * @retval #SOUND_MANAGER_ERROR_NONE Success
372  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
373  * @post  sound_available_route_cb() will be invoked
374  * @see sound_available_route_cb()
375  */
376 int sound_manager_foreach_available_route (sound_available_route_cb callback, void *user_data);
377
378 /**
379  * @brief Changes the audio routes.
380  * @param[in] route The route to set
381  * @return 0 on success, otherwise a negative error value.
382  * @retval #SOUND_MANAGER_ERROR_NONE Success
383  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
384  * @see sound_manager_get_active_device()
385  */
386 int sound_manager_set_active_route (sound_route_e route);
387
388 /**
389  * @brief Changes the audio route.
390  * @param[out] in The current sound input device
391  * @param[out] in The current sound output device
392  * @return 0 on success, otherwise a negative error value.
393  * @retval #SOUND_MANAGER_ERROR_NONE Success
394  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
395  * @see sound_manager_set_active_route()
396  */
397 int sound_manager_get_active_device (sound_device_in_e *in, sound_device_out_e *out);
398
399 /**
400  * @brief Check if given audio route is available or not.
401  * @param[in] route The route to set
402  * @return 0 on success, otherwise a negative error value.
403  * @return @c true if the specified route is supported, \n else @c false
404  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
405  */
406 bool sound_manager_is_route_available (sound_route_e route);
407
408 /**
409  * @brief Registers a callback function to be invoked when the available status is changed.
410  * @param[in]   callback        The available status changed callback function
411  * @param[in]   user_data       The user data to be passed to the callback function
412  * @return 0 on success, otherwise a negative error value.
413  * @retval #SOUND_MANAGER_ERROR_NONE Success
414  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
415  * @post  sound_available_route_changed_cb() will be invoked
416  * @see sound_manager_unset_available_route_changed_cb()
417  * @see sound_available_route_changed_cb()
418  */
419 int sound_manager_set_available_route_changed_cb (sound_available_route_changed_cb callback, void *user_data);
420
421 /**
422  * @brief Unregisters the callback function.
423  * @see sound_manager_set_available_route_changed_cb()
424  */
425 void sound_manager_unset_available_route_changed_cb (void);
426
427 /**
428  * @brief Registers a callback function to be invoked when the audio device is changed.
429  * @param[in]   callback        The session notify callback function
430  * @param[in]   user_data       The user data to be passed to the callback function
431  * @return 0 on success, otherwise a negative error value.
432  * @retval #SOUND_MANAGER_ERROR_NONE Success
433  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
434  * @post  sound_active_device_changed_cb() will be invoked
435  * @see sound_manager_unset_active_device_changed_cb()
436  * @see sound_active_device_changed_cb()
437  */
438 int sound_manager_set_active_device_changed_cb (sound_active_device_changed_cb callback, void *user_data);
439
440 /**
441  * @brief Unregisters the callback function which is called when the route notification is occured.
442  * @see sound_manager_set_active_device_changed_cb()
443  */
444 void sound_manager_unset_active_device_changed_cb (void);
445
446 /**
447  * @brief Creates a call session handle.
448  * @remarks @a session must be released sound_manager_call_session_destroy() by you.
449  * @param[out]  session  A new handle to call session
450  * @retval #SOUND_MANAGER_ERROR_NONE Successful
451  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
452  * @retval #SOUND_MANAGER_OUT_OF_MEMORY Out of memory
453  * @see sound_manager_call_session_destroy()
454  */
455 int sound_manager_call_session_create(sound_call_session_type_e type, sound_call_session_h *session);
456
457 /**
458  * @brief Sets the call session mode.
459  *
460  * @param[in]   session The handle to call session
461  * @param[in]   mode  The call session mode
462  * @return 0 on success, otherwise a negative error value.
463  * @retval #SOUND_MANAGER_ERROR_NONE Successful
464  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
465  * @see sound_manager_call_session_get_mode()
466  */
467 int sound_manager_call_session_set_mode(sound_call_session_h session, sound_call_session_mode_e mode);
468
469 /**
470  * @brief Gets the call session mode.
471  *
472  * @param[in]   session The handle to call session
473  * @param[out]   mode  The call session mode
474  * @return 0 on success, otherwise a negative error value.
475  * @retval #SOUND_MANAGER_ERROR_NONE Successful
476  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
477  * @see sound_manager_call_session_set_mode()
478  */
479 int  sound_manager_call_session_get_mode(sound_call_session_h session, sound_call_session_mode_e *mode);
480
481 /**
482  * @brief Destroys the call session handle.
483  *
484  * @param[in]           session The handle to call session to be destroyed
485  * @return 0 on success, otherwise a negative error value.
486  * @retval #SOUND_MANAGER_ERROR_NONE Successful
487  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
488  * @see sound_manager_call_session_create()
489  */
490 int sound_manager_call_session_destroy(sound_call_session_h session);
491
492 /**
493  * @}
494  */
495
496 #ifdef __cplusplus
497 }
498 #endif
499
500 #endif /* __TIZEN_MEDIA_SOUND_MANAGER_H__ */