Add sound_manager_add[remove]_focus_state_watch_cb()
[platform/core/api/sound-manager.git] / src / sound_manager.c
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 #include "sound_manager.h"
18 #include "sound_manager_private.h"
19
20
21 _session_interrupt_info_s g_session_interrupt_cb_table = {0, 0, NULL, NULL};
22 _volume_changed_info_s g_volume_changed_cb_table = {0, NULL, NULL};
23 _device_connected_info_s g_device_connected_cb_table = {0, NULL, NULL};
24 _device_changed_info_s g_device_info_changed_cb_table = {0, NULL, NULL};
25 _focus_watch_info_s focus_watch_info_arr[SOUND_STREAM_INFO_ARR_MAX];
26
27 sound_session_type_e g_cached_session = -1;
28 _session_mode_e g_cached_session_mode = -1;
29 int g_cached_voip_device_id = -1;
30 extern sound_stream_info_s *g_voip_stream_info;
31 extern virtual_sound_stream_info_s *g_voip_vstream_h;
32
33 /* These variables will be removed when session features are deprecated. */
34 extern int g_stream_info_count;
35 extern pthread_mutex_t g_stream_info_count_mutex;
36 pthread_mutex_t g_interrupt_cb_mutex, g_device_info_cb_mutex, g_device_conn_cb_mutex, g_volume_cb_mutex;
37
38 int sound_manager_get_max_volume(sound_type_e type, int *max)
39 {
40         const char *volume_type = NULL;
41         unsigned int max_level = 0;
42         int ret = MM_ERROR_NONE;
43
44         SM_NULL_ARG_CHECK(max);
45         if (type >= SOUND_TYPE_NUM || type < 0)
46                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
47
48         ret = _convert_sound_type(type, &volume_type);
49         if (ret == MM_ERROR_NONE) {
50                 ret = _get_volume_max_level(DIRECTION_OUT_STR, volume_type, &max_level);
51                 if (ret == MM_ERROR_NONE)
52                         *max = (int)max_level -1;       /* actual volume step can be max step - 1 */
53         }
54
55         return _convert_sound_manager_error_code(__func__, ret);
56 }
57
58 int sound_manager_set_volume(sound_type_e type, int volume)
59 {
60         int ret = MM_ERROR_NONE;
61
62         if (type >= SOUND_TYPE_NUM || type < 0)
63                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
64         if (volume < 0)
65                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
66
67         ret = mm_sound_volume_set_value(type, volume);
68         LOGI("type=%d, volume=%d", type, volume);
69
70         return _convert_sound_manager_error_code(__func__, ret);
71 }
72
73 int sound_manager_get_volume(sound_type_e type, int *volume)
74 {
75         int ret = MM_ERROR_NONE;
76         unsigned int uvolume;
77
78         if (type >= SOUND_TYPE_NUM || type < 0)
79                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
80         if (volume == NULL)
81                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
82
83         ret = mm_sound_volume_get_value(type, &uvolume);
84         if (ret == MM_ERROR_NONE)
85                 *volume = uvolume;
86
87         LOGI("type=%d, volume=%d", type, *volume);
88
89         return _convert_sound_manager_error_code(__func__, ret);
90 }
91
92 int sound_manager_set_current_sound_type(sound_type_e type)
93 {
94         int ret = MM_ERROR_NONE;
95
96         if (type >= SOUND_TYPE_NUM || type < 0)
97                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
98
99         ret = mm_sound_volume_primary_type_set(type);
100
101         return _convert_sound_manager_error_code(__func__, ret);
102 }
103
104 int sound_manager_get_current_sound_type(sound_type_e *type)
105 {
106         int ret = MM_ERROR_NONE;
107         volume_type_t mm_sound_vol_type = VOLUME_TYPE_UNKNOWN;
108         char *volume_type = NULL;
109
110         if (type == NULL)
111                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
112
113         ret  = mm_sound_volume_primary_type_get(&mm_sound_vol_type);
114         if (ret == MM_ERROR_NONE) {
115                 if (mm_sound_vol_type == VOLUME_TYPE_UNKNOWN) {
116                         /* get the volume type of the current playing stream */
117                         ret = _get_current_volume_type(DIRECTION_OUT_STR, &volume_type);
118                         if (ret == MM_ERROR_NONE)
119                                 ret = _convert_sound_type_to_enum((const char*)volume_type, type);
120                 } else {
121                         *type = mm_sound_vol_type;
122                 }
123         }
124         LOGI("type=%d", *type);
125
126         return _convert_sound_manager_error_code(__func__, ret);
127 }
128
129 int sound_manager_unset_current_sound_type(void)
130 {
131         int ret = MM_ERROR_NONE;
132
133         ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_UNKNOWN);
134
135         return _convert_sound_manager_error_code(__func__, ret);
136 }
137
138 int sound_manager_set_volume_changed_cb(sound_manager_volume_changed_cb callback, void* user_data)
139 {
140         int ret = MM_ERROR_NONE;
141         unsigned int subs_id = 0;
142
143         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_volume_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
144
145         ret = mm_sound_add_volume_changed_callback((mm_sound_volume_changed_cb)callback, user_data, &subs_id);
146         if (ret == MM_ERROR_NONE) {
147                 g_volume_changed_cb_table.subs_id = subs_id;
148                 g_volume_changed_cb_table.user_cb = (sound_manager_volume_changed_cb)callback;
149                 g_volume_changed_cb_table.user_data = user_data;
150         }
151
152         SM_LEAVE_CRITICAL_SECTION(&g_volume_cb_mutex);
153
154         return _convert_sound_manager_error_code(__func__, ret);
155 }
156
157 int sound_manager_unset_volume_changed_cb(void)
158 {
159         int ret = MM_ERROR_NONE;
160
161         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_volume_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
162
163         if (g_volume_changed_cb_table.subs_id > 0) {
164                 ret = mm_sound_remove_volume_changed_callback(g_volume_changed_cb_table.subs_id);
165                 if (ret == MM_ERROR_NONE) {
166                         g_volume_changed_cb_table.subs_id = 0;
167                         g_volume_changed_cb_table.user_cb = NULL;
168                         g_volume_changed_cb_table.user_data = NULL;
169                 }
170         } else {
171                 ret = MM_ERROR_SOUND_INTERNAL;
172         }
173
174         SM_LEAVE_CRITICAL_SECTION(&g_volume_cb_mutex);
175
176         return _convert_sound_manager_error_code(__func__, ret);
177 }
178
179 int sound_manager_create_stream_information(sound_stream_type_e stream_type, sound_stream_focus_state_changed_cb callback, void *user_data, sound_stream_info_h *stream_info)
180 {
181         int ret = MM_ERROR_NONE;
182
183         LOGI(">> enter");
184
185         SM_NULL_ARG_CHECK(stream_info);
186         SM_NULL_ARG_CHECK(callback);
187
188         if (g_session_interrupt_cb_table.is_registered)
189                 return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INTERNAL);
190
191         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
192
193         sound_stream_info_s *stream_h = malloc(sizeof(sound_stream_info_s));
194         if (!stream_h) {
195                 ret = MM_ERROR_OUT_OF_MEMORY;
196                 goto LEAVE;
197         }
198
199         memset(stream_h, 0, sizeof(sound_stream_info_s));
200         ret = _convert_stream_type(stream_type, &stream_h->stream_type);
201         if (ret == MM_ERROR_NONE) {
202                 ret = _make_pa_connection_and_register_focus(stream_h, callback, user_data);
203                 if (ret == MM_ERROR_NONE) {
204                         *stream_info = (sound_stream_info_h)stream_h;
205                         SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
206                         LOGI("stream_h(%p), index(%u), user_cb(%p), cnt(%d), ret(0x%x)", stream_h, stream_h->index, stream_h->user_cb, g_stream_info_count, ret);
207                 }
208         }
209
210 LEAVE:
211         if (ret && stream_h)
212                 free(stream_h);
213
214         SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
215
216         return _convert_sound_manager_error_code(__func__, ret);
217 }
218
219 int sound_manager_destroy_stream_information(sound_stream_info_h stream_info)
220 {
221         int ret = MM_ERROR_NONE;
222         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
223
224         LOGI(">> enter");
225
226         SM_INSTANCE_CHECK(stream_h);
227
228         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
229         ret = _destroy_pa_connection_and_unregister_focus(stream_h);
230         if (ret == MM_ERROR_NONE) {
231                 free(stream_h);
232                 stream_h = NULL;
233                 SM_UNREF_FOR_STREAM_INFO(g_stream_info_count);
234         }
235         SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
236
237         LOGD("cnt(%d)", g_stream_info_count);
238
239         return _convert_sound_manager_error_code(__func__, ret);
240 }
241
242 int sound_manager_add_device_for_stream_routing(sound_stream_info_h stream_info, sound_device_h device)
243 {
244         int ret = MM_ERROR_NONE;
245         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
246
247         LOGI(">> enter");
248
249         ret = _add_device_for_stream_routing(stream_h, device);
250
251         return _convert_sound_manager_error_code(__func__, ret);
252 }
253
254 int sound_manager_remove_device_for_stream_routing(sound_stream_info_h stream_info, sound_device_h device)
255 {
256         int ret = MM_ERROR_NONE;
257         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
258
259         LOGI(">> enter");
260
261         ret = _remove_device_for_stream_routing(stream_h, device);
262
263         return _convert_sound_manager_error_code(__func__, ret);
264 }
265
266 int sound_manager_apply_stream_routing(sound_stream_info_h stream_info)
267 {
268         int ret = MM_ERROR_NONE;
269         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
270
271         LOGI(">> enter");
272
273         ret = _apply_stream_routing(stream_h);
274
275         return _convert_sound_manager_error_code(__func__, ret);
276 }
277
278 int sound_manager_set_focus_reacquisition(sound_stream_info_h stream_info, bool enable)
279 {
280         int ret = MM_ERROR_NONE;
281         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
282
283         LOGI(">> enter");
284
285         SM_INSTANCE_CHECK(stream_h);
286
287         ret = mm_sound_set_focus_reacquisition(stream_h->index, enable);
288
289         return _convert_sound_manager_error_code(__func__, ret);
290 }
291
292 int sound_manager_get_focus_reacquisition(sound_stream_info_h stream_info, bool *enabled)
293 {
294         int ret = MM_ERROR_NONE;
295         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
296
297         LOGI(">> enter");
298
299         SM_INSTANCE_CHECK(stream_h);
300         SM_NULL_ARG_CHECK(enabled);
301
302         ret = mm_sound_get_focus_reacquisition(stream_h->index, enabled);
303
304         return _convert_sound_manager_error_code(__func__, ret);
305 }
306
307 int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, const char *extra_info)
308 {
309         int ret = MM_ERROR_NONE;
310         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
311
312         LOGI(">> enter");
313
314         SM_INSTANCE_CHECK(stream_h);
315
316         if (stream_h->is_focus_unavailable)
317                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
318
319         ret = mm_sound_acquire_focus(stream_h->index, (mm_sound_focus_type_e)focus_mask, extra_info);
320         if (ret == MM_ERROR_NONE) {
321                 stream_h->acquired_focus |= focus_mask;
322                 _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
323         }
324
325         return _convert_sound_manager_error_code(__func__, ret);
326 }
327
328 int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, const char *extra_info)
329 {
330         int ret = MM_ERROR_NONE;
331         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
332
333         LOGI(">> enter");
334
335         SM_INSTANCE_CHECK(stream_h);
336
337         ret = mm_sound_release_focus(stream_h->index, (mm_sound_focus_type_e)focus_mask, extra_info);
338         if (ret == MM_ERROR_NONE) {
339                 stream_h->acquired_focus &= ~focus_mask;
340                 _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
341         }
342
343         return _convert_sound_manager_error_code(__func__, ret);
344 }
345
346 int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_focus_state_e *state_for_playback, sound_stream_focus_state_e *state_for_recording)
347 {
348         int ret = MM_ERROR_NONE;
349         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
350
351         LOGI(">> enter");
352
353         SM_INSTANCE_CHECK(stream_h);
354         if (!state_for_playback && !state_for_recording) {
355                 ret = MM_ERROR_INVALID_ARGUMENT;
356                 goto LEAVE;
357         }
358
359         if (state_for_playback)
360                 *state_for_playback = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_PLAYBACK) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED));
361         if (state_for_recording)
362                 *state_for_recording = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_RECORDING) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED));
363
364         LOGI("acquired_focus(0x%x)", stream_h->acquired_focus);
365
366 LEAVE:
367         return _convert_sound_manager_error_code(__func__, ret);
368 }
369
370 int sound_manager_get_sound_type(sound_stream_info_h stream_info, sound_type_e *sound_type)
371 {
372         int ret = MM_ERROR_NONE;
373         sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
374
375         LOGI(">> enter");
376
377         SM_INSTANCE_CHECK(stream_h);
378         SM_NULL_ARG_CHECK(sound_type);
379
380         if (stream_h->stream_conf_info.volume_type == NULL) {
381                 ret = MM_ERROR_SOUND_NO_DATA;
382                 goto LEAVE;
383         }
384
385         ret = _convert_sound_type_to_enum(stream_h->stream_conf_info.volume_type, sound_type);
386         LOGI("sound type(%d)", *sound_type);
387
388 LEAVE:
389         return _convert_sound_manager_error_code(__func__, ret);
390 }
391
392 int sound_manager_add_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_watch_cb callback, void *user_data, int *id)
393 {
394         int ret = MM_ERROR_NONE;
395         int i = 0;
396
397         LOGI(">> enter");
398
399         SM_NULL_ARG_CHECK(callback);
400         SM_NULL_ARG_CHECK(id);
401         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, SOUND_MANAGER_ERROR_INTERNAL);
402
403         for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++)
404                 if (focus_watch_info_arr[i].id == 0)
405                         break;
406         if (i == SOUND_STREAM_INFO_ARR_MAX) {
407                 LOGE("focus watch info array is full");
408                 ret = MM_ERROR_SOUND_INTERNAL;
409                 goto LEAVE;
410         }
411
412         ret = mm_sound_set_focus_watch_callback((mm_sound_focus_type_e)focus_mask, _focus_watch_callback, user_data, id);
413         if (ret == MM_ERROR_NONE) {
414                 SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
415                 focus_watch_info_arr[i].id = *id;
416                 focus_watch_info_arr[i].user_data = user_data;
417                 focus_watch_info_arr[i].user_cb = callback;
418         }
419
420 LEAVE:
421         SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
422
423         LOGD("cnt(%d), id(%d)", g_stream_info_count, *id);
424
425         return _convert_sound_manager_error_code(__func__, ret);
426 }
427
428 int sound_manager_remove_focus_state_watch_cb(int id)
429 {
430         int ret = MM_ERROR_NONE;
431         int i = 0;
432
433         LOGI(">> enter");
434
435         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, SOUND_MANAGER_ERROR_INTERNAL);
436
437         for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++)
438                 if (focus_watch_info_arr[i].id == id)
439                         break;
440         if (i == SOUND_STREAM_INFO_ARR_MAX) {
441                 LOGE("cound not find item in focus watch info array for this id(%d)", id);
442                 ret = MM_ERROR_SOUND_INTERNAL;
443                 goto LEAVE;
444         }
445
446         ret = mm_sound_unset_focus_watch_callback(id);
447         if (ret == MM_ERROR_NONE) {
448                 SM_UNREF_FOR_STREAM_INFO(g_stream_info_count);
449                 focus_watch_info_arr[i].id = 0;
450                 focus_watch_info_arr[i].user_data = NULL;
451                 focus_watch_info_arr[i].user_cb = NULL;
452         }
453
454 LEAVE:
455         SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
456
457         LOGD("cnt(%d)", g_stream_info_count);
458
459         return _convert_sound_manager_error_code(__func__, ret);
460 }
461
462 int sound_manager_set_session_type(sound_session_type_e type)
463 {
464         int ret = MM_ERROR_NONE;
465         int cur_session = -1;
466         int new_session = MM_SESSION_TYPE_MEDIA;
467
468         LOGI(">> enter : type=%d", type);
469
470         if (type < SOUND_SESSION_TYPE_MEDIA || type >  SOUND_SESSION_TYPE_VOIP)
471                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
472
473         /* it is not supported both session and stream feature at the same time */
474         if (g_stream_info_count) {
475                 LOGE("Could not set this type(%d) because of being used stream feature", type);
476                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
477         }
478
479         switch (type) {
480         case SOUND_SESSION_TYPE_MEDIA:
481                 new_session = MM_SESSION_TYPE_MEDIA;
482                 break;
483         case SOUND_SESSION_TYPE_ALARM:
484                 new_session = MM_SESSION_TYPE_ALARM;
485                 break;
486         case SOUND_SESSION_TYPE_NOTIFICATION:
487                 new_session = MM_SESSION_TYPE_NOTIFY;
488                 break;
489         case SOUND_SESSION_TYPE_EMERGENCY:
490                 new_session = MM_SESSION_TYPE_EMERGENCY;
491                 break;
492         case SOUND_SESSION_TYPE_VOIP:
493                 new_session = MM_SESSION_TYPE_VOIP;
494                 break;
495         }
496
497         /* valid session check */
498         ret = mm_session_get_current_type(&cur_session);
499         if (ret == MM_ERROR_NONE) {
500                 if (cur_session == MM_SESSION_TYPE_MEDIA_RECORD) {
501                         if (type > SOUND_SESSION_TYPE_MEDIA) {
502                                 LOGE("Could not set this type(%d) during camera/recorder/audio-io(in)/radio", type);
503                                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
504                         }
505                 }
506         }
507
508         if (g_session_interrupt_cb_table.is_registered) {
509                 if (new_session == cur_session ||
510                         ((new_session == SOUND_SESSION_TYPE_MEDIA) && (cur_session == MM_SESSION_TYPE_MEDIA_RECORD))) {
511                         LOGI("already set type=%d, ret=0x%x", type, ret);
512                         return SOUND_MANAGER_ERROR_NONE;
513                 } else {
514                         ret = mm_session_finish();
515                         if (ret != MM_ERROR_NONE)
516                                 return _convert_sound_manager_error_code(__func__, ret);
517
518                         g_session_interrupt_cb_table.is_registered = 0;
519                         if (cur_session == MM_SESSION_TYPE_VOIP) {
520                                 g_cached_session_mode = -1;
521                                 g_cached_voip_device_id = -1;
522                                 if (g_voip_vstream_h) {
523                                         _stop_virtual_stream(g_voip_vstream_h);
524                                         _destroy_virtual_stream(g_voip_vstream_h);
525                                         g_voip_vstream_h = NULL;
526                                 }
527                                 /*voip stream destruction*/
528                                 if (g_voip_stream_info) {
529                                         ret = _destroy_pa_connection_and_unregister_focus(g_voip_stream_info);
530                                         free(g_voip_stream_info);
531                                         g_voip_stream_info = NULL;
532                                         if (ret != MM_ERROR_NONE)
533                                                 return _convert_sound_manager_error_code(__func__, ret);
534                                 }
535                         }
536                 }
537         }
538         ret = mm_session_init(new_session);
539         if (ret == MM_ERROR_NONE)
540                 g_session_interrupt_cb_table.is_registered = 1;
541
542         LOGI("type=%d", type);
543
544         return _convert_sound_manager_error_code(__func__, ret);
545 }
546
547 int sound_manager_get_session_type(sound_session_type_e *type)
548 {
549         int ret = MM_ERROR_NONE;
550         int cur_session;
551
552         if (type == NULL)
553                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
554
555         ret = mm_session_get_current_type(&cur_session);
556         if (ret != MM_ERROR_NONE) {
557                 LOGW("session hasn't been set, setting default session");
558                 cur_session = SOUND_SESSION_TYPE_DEFAULT;
559                 ret = mm_session_init(cur_session);
560                 if (ret == MM_ERROR_NONE)
561                         g_session_interrupt_cb_table.is_registered = 1;
562         }
563         if ((cur_session > MM_SESSION_TYPE_EMERGENCY) &&
564                         (cur_session != MM_SESSION_TYPE_VOIP)) {
565                 if (g_cached_session != -1)
566                         cur_session = g_cached_session;
567                 else /* will be never reached here. just prevent code */
568                         cur_session = SOUND_SESSION_TYPE_DEFAULT;
569         }
570
571         switch (cur_session) {
572         case MM_SESSION_TYPE_MEDIA:
573         case MM_SESSION_TYPE_MEDIA_RECORD:
574                 *type = SOUND_SESSION_TYPE_MEDIA;
575                 break;
576         case MM_SESSION_TYPE_ALARM:
577                 *type = SOUND_SESSION_TYPE_ALARM;
578                 break;
579         case MM_SESSION_TYPE_NOTIFY:
580                 *type = SOUND_SESSION_TYPE_NOTIFICATION;
581                 break;
582         case MM_SESSION_TYPE_EMERGENCY:
583                 *type = SOUND_SESSION_TYPE_EMERGENCY;
584                 break;
585         case MM_SESSION_TYPE_VOIP:
586                 *type = SOUND_SESSION_TYPE_VOIP;
587                 break;
588         default:
589                 *type = cur_session;
590                 break;
591         }
592
593         LOGI("type=%d", *type);
594
595         return SOUND_MANAGER_ERROR_NONE;
596 }
597
598 int sound_manager_set_media_session_option(sound_session_option_for_starting_e s_option, sound_session_option_for_during_play_e d_option)
599 {
600         int ret = MM_ERROR_NONE;
601         int session = 0;
602         int session_option = 0;
603         int updated = 0;
604
605         LOGI(">> enter : option for starting=%d, for during play=%d", s_option, d_option);
606
607         if (s_option < 0 || s_option >  SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START)
608                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
609         if (d_option < 0 || d_option >  SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY)
610                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
611
612         ret = mm_session_get_current_information(&session, &session_option);
613         if (ret != 0 || !g_session_interrupt_cb_table.is_registered) {
614                 LOGW("session hasn't been set, setting default session");
615                 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
616                 if (ret == 0)
617                         g_session_interrupt_cb_table.is_registered = 1;
618
619         } else if (ret == 0 && session > MM_SESSION_TYPE_MEDIA) {
620                 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
621                         if (!g_session_interrupt_cb_table.is_registered) {
622                                 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
623                                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
624                         }
625                 } else {
626                         return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
627                 }
628         }
629
630         switch (s_option) {
631         case SOUND_SESSION_OPTION_MIX_WITH_OTHERS_WHEN_START:
632                 if (session_option & MM_SESSION_OPTION_PAUSE_OTHERS) {
633                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_PAUSE_OTHERS);
634                         if (ret)
635                                 return _convert_sound_manager_error_code(__func__, ret);
636
637                         updated = 1;
638                 }
639                 break;
640         case SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START:
641                 if (!(session_option & MM_SESSION_OPTION_PAUSE_OTHERS)) {
642                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_PAUSE_OTHERS);
643                         if (ret)
644                                 return _convert_sound_manager_error_code(__func__, ret);
645
646                         updated = 1;
647                 }
648                 break;
649         }
650
651         switch (d_option) {
652         case SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY:
653                 if (session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
654                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_UNINTERRUPTIBLE);
655                         if (ret)
656                                 return _convert_sound_manager_error_code(__func__, ret);
657
658                         updated = 1;
659                 }
660                 break;
661         case SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY:
662                 if (!(session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE)) {
663                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_UNINTERRUPTIBLE);
664                         if (ret)
665                                 return _convert_sound_manager_error_code(__func__, ret);
666
667                         updated = 1;
668                 }
669                 break;
670         }
671
672         if (updated)
673                 LOGI("updated");
674         else
675                 LOGI("already set same option(%x), skip it", session_option);
676
677         return _convert_sound_manager_error_code(__func__, ret);
678 }
679
680 int sound_manager_get_media_session_option(sound_session_option_for_starting_e *s_option, sound_session_option_for_during_play_e *d_option)
681 {
682         int ret = MM_ERROR_NONE;
683         int session = 0;
684         int session_options = 0;
685
686         LOGI(">> enter");
687
688         if (s_option == NULL || d_option == NULL)
689                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
690
691         ret = mm_session_get_current_information(&session, &session_options);
692         if (ret != 0) {
693                 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
694                 if (ret == 0)
695                         g_session_interrupt_cb_table.is_registered = 1;
696
697         } else if (session > SOUND_SESSION_TYPE_MEDIA) {
698                 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
699                         if (!g_session_interrupt_cb_table.is_registered) {
700                                 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
701                                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
702                         }
703                 } else
704                         return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
705         }
706         /* get option */
707         if (session_options & MM_SESSION_OPTION_PAUSE_OTHERS)
708                 *s_option = SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START;
709         else
710                 *s_option = SOUND_SESSION_OPTION_MIX_WITH_OTHERS_WHEN_START;
711
712         if (session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE)
713                 *d_option = SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY;
714         else
715                 *d_option = SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY;
716
717         LOGI(" option for starting=%d, for during play=%d", *s_option, *d_option);
718
719         return SOUND_MANAGER_ERROR_NONE;
720 }
721
722 int sound_manager_set_media_session_resumption_option(sound_session_option_for_resumption_e option)
723 {
724         int ret = MM_ERROR_NONE;
725         int session = 0;
726         int session_option = 0;
727         int updated = 0;
728
729         LOGI(">> enter : option for resumption=%d (0:by system, 1:by system or media paused)", option);
730
731         if (option < SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM || option > SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED)
732                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
733
734         ret = mm_session_get_current_information(&session, &session_option);
735         if (ret != 0 || !g_session_interrupt_cb_table.is_registered) {
736                 LOGW("session hasn't been set, setting default session");
737                 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
738                 if (ret == 0)
739                         g_session_interrupt_cb_table.is_registered = 1;
740
741         } else if (ret == 0 && session > MM_SESSION_TYPE_MEDIA) {
742                 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
743                         if (!g_session_interrupt_cb_table.is_registered) {
744                                 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
745                                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
746                         }
747                 } else
748                         return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
749
750         }
751
752         switch (option) {
753         case SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM:
754                 if (session_option & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED) {
755                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED);
756                         if (ret)
757                                 return _convert_sound_manager_error_code(__func__, ret);
758
759                         updated = 1;
760                 }
761                 break;
762         case SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED:
763                 if (!(session_option & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)) {
764                         ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED);
765                         if (ret)
766                                 return _convert_sound_manager_error_code(__func__, ret);
767
768                         updated = 1;
769                 }
770                 break;
771         }
772
773         if (updated)
774                 LOGI("updated");
775         else
776                 LOGI("already set same option(0x%x), skip it", session_option);
777
778         return _convert_sound_manager_error_code(__func__, ret);
779 }
780
781 int sound_manager_get_media_session_resumption_option(sound_session_option_for_resumption_e *option)
782 {
783         int ret = MM_ERROR_NONE;
784         int session = 0;
785         int session_options = 0;
786
787         LOGI(">> enter");
788
789         if (option == NULL)
790                 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
791
792         ret = mm_session_get_current_information(&session, &session_options);
793         if (ret != 0) {
794                 LOGW("session hasn't been set, setting default session");
795                 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
796                 if (ret == 0)
797                         g_session_interrupt_cb_table.is_registered = 1;
798
799         } else if (session > SOUND_SESSION_TYPE_MEDIA) {
800                 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
801                         if (!g_session_interrupt_cb_table.is_registered) {
802                                 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
803                                 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
804                         }
805                 } else
806                         return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
807         }
808         /* get option */
809         if (session_options & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)
810                 *option = SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED;
811         else
812                 *option = SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM;
813
814         LOGI("option for resumption=%d (0:by system, 1:by system or media paused)", *option);
815
816         return SOUND_MANAGER_ERROR_NONE;
817 }
818
819 int sound_manager_set_voip_session_mode(sound_session_voip_mode_e mode)
820 {
821         int ret = MM_ERROR_NONE;
822         int session = 0;
823         int session_options = 0;
824
825         LOGI(">> enter : mode=%d", mode);
826
827         ret = mm_session_get_current_information(&session, &session_options);
828         if (ret != MM_ERROR_NONE)
829                 goto LEAVE;
830
831         if (session != MM_SESSION_TYPE_VOIP) {
832                 ret = MM_ERROR_POLICY_INTERNAL;
833                 goto LEAVE;
834         }
835
836         if (mode < SOUND_SESSION_VOIP_MODE_RINGTONE || mode > SOUND_SESSION_VOIP_MODE_VOICE_WITH_BLUETOOTH) {
837                 ret = MM_ERROR_INVALID_ARGUMENT;
838                 goto LEAVE;
839         }
840
841         ret = _set_session_mode((_session_mode_e)mode);
842
843         LOGI("session=%d, mode=%d", session, mode);
844
845 LEAVE:
846         return _convert_sound_manager_error_code(__func__, ret);
847 }
848
849 int sound_manager_get_voip_session_mode(sound_session_voip_mode_e *mode)
850 {
851         int ret = MM_ERROR_NONE;
852         int session = 0;
853         int session_options = 0;
854
855         if (mode == NULL) {
856                 LOGE("mode is null");
857                 ret = MM_ERROR_INVALID_ARGUMENT;
858                 goto LEAVE;
859         }
860
861         ret = mm_session_get_current_information(&session, &session_options);
862         if (ret != MM_ERROR_NONE) {
863                 LOGI("session = %d, option = %d", session, session_options);
864                 goto LEAVE;
865         }
866
867         if (session != MM_SESSION_TYPE_VOIP || g_cached_session_mode == -1) {
868                 ret = MM_ERROR_POLICY_INTERNAL;
869                 goto LEAVE;
870         }
871
872         *mode = (sound_session_voip_mode_e)g_cached_session_mode;
873
874         LOGI("session=%d, mode=%d", session, *mode);
875
876 LEAVE:
877         return _convert_sound_manager_error_code(__func__, ret);
878 }
879
880 int sound_manager_set_session_interrupted_cb(sound_session_interrupted_cb callback, void *user_data)
881 {
882         int ret = MM_ERROR_NONE;
883         unsigned int subs_id = 0;
884
885         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
886
887         if (callback == NULL) {
888                 ret = MM_ERROR_INVALID_ARGUMENT;
889                 goto LEAVE;
890         }
891
892         /* it is not supported both session and stream feature at the same time */
893         if (g_stream_info_count) {
894                 ret =  MM_ERROR_POLICY_INTERNAL;
895                 goto LEAVE;
896         }
897
898         if (g_session_interrupt_cb_table.user_cb == NULL) {
899                 ret = mm_sound_add_device_connected_callback(SOUND_DEVICE_ALL_MASK, (mm_sound_device_connected_cb)_device_connected_cb, NULL, &subs_id);
900                 if (ret)
901                         goto LEAVE;
902                 ret = mm_sound_focus_set_session_interrupt_callback((mm_sound_focus_session_interrupt_cb)_focus_session_interrupt_cb, NULL);
903                 if (ret) {
904                         if (mm_sound_remove_device_connected_callback(subs_id) != MM_ERROR_NONE)
905                                 LOGW("mm_sound_remove_device_connected_callback failed");
906                         goto LEAVE;
907                 }
908                 g_session_interrupt_cb_table.subs_id = subs_id;
909         }
910         g_session_interrupt_cb_table.user_cb = (sound_session_interrupted_cb)callback;
911         g_session_interrupt_cb_table.user_data = user_data;
912
913 LEAVE:
914         SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
915
916         return _convert_sound_manager_error_code(__func__, ret);
917 }
918
919 int sound_manager_unset_session_interrupted_cb(void)
920 {
921         int ret = MM_ERROR_NONE;
922
923         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
924
925         if (!g_session_interrupt_cb_table.user_cb) {
926                 ret = MM_ERROR_SOUND_INTERNAL;
927                 goto LEAVE;
928         }
929
930         ret = mm_sound_focus_unset_session_interrupt_callback();
931         if (ret) {
932                 if (mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id) != MM_ERROR_NONE)
933                         LOGW("mm_sound_remove_device_connected_callback failed");
934                 goto LEAVE;
935         }
936
937         ret = mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id);
938         if (ret)
939                 goto LEAVE;
940
941         g_session_interrupt_cb_table.subs_id = 0;
942         g_session_interrupt_cb_table.user_cb = NULL;
943         g_session_interrupt_cb_table.user_data = NULL;
944
945 LEAVE:
946         SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
947
948         return _convert_sound_manager_error_code(__func__, ret);
949 }
950
951 int sound_manager_get_current_device_list(sound_device_mask_e device_mask, sound_device_list_h *device_list)
952 {
953         int ret = MM_ERROR_NONE;
954
955         ret = mm_sound_get_current_device_list((mm_sound_device_flags_e)device_mask, device_list);
956
957         return _convert_sound_manager_error_code(__func__, ret);
958 }
959
960 int sound_manager_free_device_list(sound_device_list_h device_list)
961 {
962         int ret = MM_ERROR_NONE;
963
964         ret = mm_sound_free_device_list(device_list);
965
966         return _convert_sound_manager_error_code(__func__, ret);
967 }
968
969 int sound_manager_get_next_device(sound_device_list_h device_list, sound_device_h *device)
970 {
971         int ret = MM_ERROR_NONE;
972
973         ret = mm_sound_get_next_device(device_list, device);
974
975         return _convert_sound_manager_error_code(__func__, ret);
976 }
977
978 int sound_manager_get_prev_device(sound_device_list_h device_list, sound_device_h *device)
979 {
980         int ret = MM_ERROR_NONE;
981
982         ret = mm_sound_get_prev_device(device_list, device);
983
984         return _convert_sound_manager_error_code(__func__, ret);
985 }
986
987 int sound_manager_get_device_type(sound_device_h device, sound_device_type_e *type)
988 {
989         int ret = MM_ERROR_NONE;
990
991         ret = mm_sound_get_device_type(device, (mm_sound_device_type_e*)type);
992
993         return _convert_sound_manager_error_code(__func__, ret);
994 }
995
996 int sound_manager_get_device_io_direction(sound_device_h device, sound_device_io_direction_e *io_direction)
997 {
998         int ret = MM_ERROR_NONE;
999         mm_sound_device_io_direction_e mm_sound_io_direction;
1000
1001         ret = mm_sound_get_device_io_direction(device, &mm_sound_io_direction);
1002         if (ret == MM_ERROR_NONE)
1003                 ret = _convert_device_io_direction(mm_sound_io_direction, io_direction);
1004
1005         return _convert_sound_manager_error_code(__func__, ret);
1006 }
1007
1008 int sound_manager_get_device_id(sound_device_h device, int *id)
1009 {
1010         int ret = MM_ERROR_NONE;
1011
1012         ret = mm_sound_get_device_id(device, id);
1013
1014         return _convert_sound_manager_error_code(__func__, ret);
1015 }
1016
1017 int sound_manager_get_device_name(sound_device_h device, char **name)
1018 {
1019         int ret = MM_ERROR_NONE;
1020
1021         ret = mm_sound_get_device_name(device, name);
1022
1023         return _convert_sound_manager_error_code(__func__, ret);
1024 }
1025
1026 int sound_manager_get_device_state(sound_device_h device, sound_device_state_e *state)
1027 {
1028         int ret = MM_ERROR_NONE;
1029
1030         ret = mm_sound_get_device_state(device, (mm_sound_device_state_e*)state);
1031
1032         return _convert_sound_manager_error_code(__func__, ret);
1033 }
1034
1035 int sound_manager_set_device_connected_cb(sound_device_mask_e device_mask, sound_device_connected_cb callback, void *user_data)
1036 {
1037         int ret = MM_ERROR_NONE;
1038         unsigned int subs_id = 0;
1039
1040         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_conn_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1041
1042         ret = mm_sound_add_device_connected_callback((mm_sound_device_flags_e)device_mask, (mm_sound_device_connected_cb)callback, user_data, &subs_id);
1043         if (ret == MM_ERROR_NONE) {
1044                 g_device_connected_cb_table.subs_id = subs_id;
1045                 g_device_connected_cb_table.user_cb = (sound_device_connected_cb)callback;
1046                 g_device_connected_cb_table.user_data = user_data;
1047         }
1048
1049         SM_LEAVE_CRITICAL_SECTION(&g_device_conn_cb_mutex);
1050
1051         return _convert_sound_manager_error_code(__func__, ret);
1052 }
1053
1054 int sound_manager_unset_device_connected_cb(void)
1055 {
1056         int ret = MM_ERROR_NONE;
1057
1058         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_conn_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1059
1060         if (g_device_connected_cb_table.subs_id == 0) {
1061                 ret = MM_ERROR_SOUND_INTERNAL;
1062                 goto LEAVE;
1063         }
1064
1065         ret = mm_sound_remove_device_connected_callback(g_device_connected_cb_table.subs_id);
1066         if (ret == MM_ERROR_NONE) {
1067                 g_device_connected_cb_table.subs_id = 0;
1068                 g_device_connected_cb_table.user_cb = NULL;
1069                 g_device_connected_cb_table.user_data = NULL;
1070         }
1071
1072 LEAVE:
1073         SM_LEAVE_CRITICAL_SECTION(&g_device_conn_cb_mutex);
1074
1075         return _convert_sound_manager_error_code(__func__, ret);
1076 }
1077
1078 int sound_manager_set_device_information_changed_cb(sound_device_mask_e device_mask, sound_device_information_changed_cb callback, void *user_data)
1079 {
1080         int ret = MM_ERROR_NONE;
1081         unsigned int subs_id = 0;
1082
1083         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_info_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1084
1085         ret = mm_sound_add_device_information_changed_callback((mm_sound_device_flags_e)device_mask, (mm_sound_device_info_changed_cb)callback, user_data, &subs_id);
1086         if (ret == MM_ERROR_NONE) {
1087                 g_device_info_changed_cb_table.subs_id = subs_id;
1088                 g_device_info_changed_cb_table.user_cb = (sound_device_information_changed_cb)callback;
1089                 g_device_info_changed_cb_table.user_data = user_data;
1090         }
1091
1092         SM_LEAVE_CRITICAL_SECTION(&g_device_info_cb_mutex);
1093
1094         return _convert_sound_manager_error_code(__func__, ret);
1095 }
1096
1097 int sound_manager_unset_device_information_changed_cb(void)
1098 {
1099         int ret = MM_ERROR_NONE;
1100
1101         SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_info_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1102
1103         if (g_device_info_changed_cb_table.subs_id == 0) {
1104                 ret = MM_ERROR_SOUND_INTERNAL;
1105                 goto LEAVE;
1106         }
1107
1108         ret = mm_sound_remove_device_information_changed_callback(g_device_info_changed_cb_table.subs_id);
1109         if (ret == MM_ERROR_NONE) {
1110                 g_device_info_changed_cb_table.subs_id = 0;
1111                 g_device_info_changed_cb_table.user_cb = NULL;
1112                 g_device_info_changed_cb_table.user_data = NULL;
1113         }
1114
1115 LEAVE:
1116         SM_LEAVE_CRITICAL_SECTION(&g_device_info_cb_mutex);
1117
1118         return _convert_sound_manager_error_code(__func__, ret);
1119 }
1120
1121 __attribute__ ((destructor))
1122 void __sound_manager_finalize(void)
1123 {
1124         int ret = MM_ERROR_NONE;
1125
1126         if (g_session_interrupt_cb_table.is_registered) {
1127                 LOGI("<ENTER>");
1128                 ret = mm_session_finish();
1129                 if (ret != MM_ERROR_NONE)
1130                         LOGE("[%s] failed to mm_session_finish(), ret(0x%x)", __func__, ret);
1131
1132                 g_session_interrupt_cb_table.is_registered = 0;
1133                 LOGI("<LEAVE>");
1134         }
1135 }
1136
1137 __attribute__ ((constructor))
1138 void __sound_manager_initialize(void)
1139 {
1140
1141 }