2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "sound_manager.h"
18 #include "sound_manager_private.h"
19 #include <system_info.h>
21 #define FEATURE_MICROPHONE "http://tizen.org/feature/microphone"
23 _session_interrupt_info_s g_session_interrupt_cb_table = {0, 0, NULL, NULL};
24 _volume_changed_info_s g_volume_changed_cb_table = {0, NULL, NULL};
25 _device_connected_info_s g_device_connected_cb_table = {0, NULL, NULL};
26 _device_changed_info_s g_device_info_changed_cb_table = {0, NULL, NULL};
27 _focus_watch_info_s focus_watch_info_arr[SOUND_STREAM_INFO_ARR_MAX];
29 sound_session_type_e g_cached_session = -1;
30 _session_mode_e g_cached_session_mode = -1;
31 int g_cached_voip_device_id = -1;
32 extern sound_stream_info_s *g_voip_stream_info;
33 extern virtual_sound_stream_info_s *g_voip_vstream_h;
35 /* These variables will be removed when session features are deprecated. */
36 extern int g_stream_info_count;
37 extern pthread_mutex_t g_stream_info_count_mutex;
38 pthread_mutex_t g_interrupt_cb_mutex, g_device_info_cb_mutex, g_device_conn_cb_mutex, g_volume_cb_mutex;
40 int sound_manager_get_max_volume(sound_type_e type, int *max)
42 const char *volume_type = NULL;
43 unsigned int max_level = 0;
44 int ret = MM_ERROR_NONE;
46 SM_NULL_ARG_CHECK(max);
47 if (type >= SOUND_TYPE_NUM || type < 0)
48 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
50 ret = _convert_sound_type(type, &volume_type);
51 if (ret == MM_ERROR_NONE) {
52 ret = _get_volume_max_level(DIRECTION_OUT_STR, volume_type, &max_level);
53 if (ret == MM_ERROR_NONE)
54 *max = (int)max_level -1; /* actual volume step can be max step - 1 */
57 return _convert_sound_manager_error_code(__func__, ret);
60 int sound_manager_set_volume(sound_type_e type, int volume)
62 int ret = MM_ERROR_NONE;
64 if (type >= SOUND_TYPE_NUM || type < 0)
65 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
67 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
69 ret = mm_sound_volume_set_value(type, volume);
70 LOGI("type=%d, volume=%d", type, volume);
72 return _convert_sound_manager_error_code(__func__, ret);
75 int sound_manager_get_volume(sound_type_e type, int *volume)
77 int ret = MM_ERROR_NONE;
80 if (type >= SOUND_TYPE_NUM || type < 0)
81 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
83 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
85 ret = mm_sound_volume_get_value(type, &uvolume);
86 if (ret == MM_ERROR_NONE)
89 LOGI("type=%d, volume=%d", type, *volume);
91 return _convert_sound_manager_error_code(__func__, ret);
94 int sound_manager_set_current_sound_type(sound_type_e type)
96 int ret = MM_ERROR_NONE;
98 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
99 if (type >= SOUND_TYPE_NUM || type < 0)
100 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
102 ret = mm_sound_volume_primary_type_set(type);
104 return _convert_sound_manager_error_code(__func__, ret);
107 int sound_manager_get_current_sound_type(sound_type_e *type)
109 int ret = MM_ERROR_NONE;
110 volume_type_t mm_sound_vol_type = VOLUME_TYPE_UNKNOWN;
111 char *volume_type = NULL;
114 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
116 ret = mm_sound_volume_primary_type_get(&mm_sound_vol_type);
117 if (ret == MM_ERROR_NONE) {
118 if (mm_sound_vol_type == VOLUME_TYPE_UNKNOWN) {
119 /* get the volume type of the current playing stream */
120 ret = _get_current_volume_type(DIRECTION_OUT_STR, &volume_type);
121 if (ret == MM_ERROR_NONE)
122 ret = _convert_sound_type_to_enum((const char*)volume_type, type);
124 *type = mm_sound_vol_type;
127 LOGI("type=%d", *type);
129 return _convert_sound_manager_error_code(__func__, ret);
132 int sound_manager_unset_current_sound_type(void)
134 int ret = MM_ERROR_NONE;
136 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
137 ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_UNKNOWN);
139 return _convert_sound_manager_error_code(__func__, ret);
142 int sound_manager_set_volume_changed_cb(sound_manager_volume_changed_cb callback, void* user_data)
144 int ret = MM_ERROR_NONE;
145 unsigned int subs_id = 0;
147 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
148 "Use sound_manager_add_volume_changed_cb() instead.", __func__);
150 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_volume_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
152 ret = mm_sound_add_volume_changed_callback((mm_sound_volume_changed_cb)callback, user_data, &subs_id);
153 if (ret == MM_ERROR_NONE) {
154 g_volume_changed_cb_table.subs_id = subs_id;
155 g_volume_changed_cb_table.user_cb = (sound_manager_volume_changed_cb)callback;
156 g_volume_changed_cb_table.user_data = user_data;
159 SM_LEAVE_CRITICAL_SECTION(&g_volume_cb_mutex);
161 return _convert_sound_manager_error_code(__func__, ret);
164 int sound_manager_unset_volume_changed_cb(void)
166 int ret = MM_ERROR_NONE;
168 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
169 "Use sound_manager_remove_volume_changed_cb() instead.", __func__);
171 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_volume_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
173 if (g_volume_changed_cb_table.subs_id > 0) {
174 ret = mm_sound_remove_volume_changed_callback(g_volume_changed_cb_table.subs_id);
175 if (ret == MM_ERROR_NONE) {
176 g_volume_changed_cb_table.subs_id = 0;
177 g_volume_changed_cb_table.user_cb = NULL;
178 g_volume_changed_cb_table.user_data = NULL;
181 ret = MM_ERROR_SOUND_INTERNAL;
184 SM_LEAVE_CRITICAL_SECTION(&g_volume_cb_mutex);
186 return _convert_sound_manager_error_code(__func__, ret);
189 int sound_manager_add_volume_changed_cb(sound_manager_volume_changed_cb callback, void *user_data, int *id)
191 int ret = MM_ERROR_NONE;
193 if (!callback || !id)
194 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
196 ret = mm_sound_add_volume_changed_callback((mm_sound_volume_changed_cb)callback, user_data, (unsigned int*)id);
198 return _convert_sound_manager_error_code(__func__, ret);
201 int sound_manager_remove_volume_changed_cb(int id)
203 int ret = MM_ERROR_NONE;
206 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
208 ret = mm_sound_remove_volume_changed_callback(id);
210 return _convert_sound_manager_error_code(__func__, ret);
213 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)
215 int ret = MM_ERROR_NONE;
219 SM_NULL_ARG_CHECK(stream_info);
221 if (g_session_interrupt_cb_table.is_registered)
222 return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INTERNAL);
224 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
226 sound_stream_info_s *stream_h = malloc(sizeof(sound_stream_info_s));
228 ret = MM_ERROR_OUT_OF_MEMORY;
232 memset(stream_h, 0, sizeof(sound_stream_info_s));
233 ret = _convert_stream_type(stream_type, &stream_h->stream_type);
234 if (ret == MM_ERROR_NONE) {
235 ret = _make_pa_connection_and_register_focus(stream_h, callback, user_data);
236 if (ret == MM_ERROR_NONE) {
237 *stream_info = (sound_stream_info_h)stream_h;
238 SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
239 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);
247 SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
249 return _convert_sound_manager_error_code(__func__, ret);
252 int sound_manager_destroy_stream_information(sound_stream_info_h stream_info)
254 int ret = MM_ERROR_NONE;
255 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
259 SM_INSTANCE_CHECK(stream_h);
261 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
262 ret = _destroy_pa_connection_and_unregister_focus(stream_h);
263 if (ret == MM_ERROR_NONE) {
266 SM_UNREF_FOR_STREAM_INFO(g_stream_info_count);
268 SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
270 LOGD("cnt(%d)", g_stream_info_count);
272 return _convert_sound_manager_error_code(__func__, ret);
275 int sound_manager_get_sound_type(sound_stream_info_h stream_info, sound_type_e *sound_type)
277 int ret = MM_ERROR_NONE;
278 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
282 SM_INSTANCE_CHECK(stream_h);
283 SM_NULL_ARG_CHECK(sound_type);
285 if (stream_h->stream_conf_info.volume_type == NULL) {
286 ret = MM_ERROR_SOUND_NO_DATA;
290 ret = _convert_sound_type_to_enum(stream_h->stream_conf_info.volume_type, sound_type);
291 LOGI("sound type(%d)", *sound_type);
294 return _convert_sound_manager_error_code(__func__, ret);
297 int sound_manager_add_device_for_stream_routing(sound_stream_info_h stream_info, sound_device_h device)
299 int ret = MM_ERROR_NONE;
300 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
304 ret = _add_device_for_stream_routing(stream_h, device);
306 return _convert_sound_manager_error_code(__func__, ret);
309 int sound_manager_remove_device_for_stream_routing(sound_stream_info_h stream_info, sound_device_h device)
311 int ret = MM_ERROR_NONE;
312 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
316 ret = _remove_device_for_stream_routing(stream_h, device);
318 return _convert_sound_manager_error_code(__func__, ret);
321 int sound_manager_apply_stream_routing(sound_stream_info_h stream_info)
323 int ret = MM_ERROR_NONE;
324 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
328 ret = _apply_stream_routing(stream_h);
330 return _convert_sound_manager_error_code(__func__, ret);
333 int sound_manager_set_focus_reacquisition(sound_stream_info_h stream_info, bool enable)
335 int ret = MM_ERROR_NONE;
336 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
340 SM_INSTANCE_CHECK(stream_h);
342 ret = mm_sound_set_focus_reacquisition(stream_h->index, enable);
344 return _convert_sound_manager_error_code(__func__, ret);
347 int sound_manager_get_focus_reacquisition(sound_stream_info_h stream_info, bool *enabled)
349 int ret = MM_ERROR_NONE;
350 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
354 SM_INSTANCE_CHECK(stream_h);
355 SM_NULL_ARG_CHECK(enabled);
357 ret = mm_sound_get_focus_reacquisition(stream_h->index, enabled);
359 return _convert_sound_manager_error_code(__func__, ret);
362 int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info)
364 int ret = MM_ERROR_NONE;
365 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
369 SM_INSTANCE_CHECK(stream_h);
371 if (stream_h->is_focus_unavailable) {
372 LOGE("acquiring focus is not allowed for this strema type(%s)", stream_h->stream_type);
373 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
376 if (stream_h->user_cb == NULL) {
377 LOGE("focus state changed callback should be set before acquiring focus");
378 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
381 ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
382 if (ret == MM_ERROR_NONE) {
383 stream_h->acquired_focus |= focus_mask;
384 _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
387 return _convert_sound_manager_error_code(__func__, ret);
390 int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info)
392 int ret = MM_ERROR_NONE;
393 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
397 SM_INSTANCE_CHECK(stream_h);
399 ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
400 if (ret == MM_ERROR_NONE) {
401 stream_h->acquired_focus &= ~focus_mask;
402 _update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
405 return _convert_sound_manager_error_code(__func__, ret);
408 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)
410 int ret = MM_ERROR_NONE;
411 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
415 SM_INSTANCE_CHECK(stream_h);
416 if (!state_for_playback && !state_for_recording) {
417 ret = MM_ERROR_INVALID_ARGUMENT;
421 if (state_for_playback)
422 *state_for_playback = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_PLAYBACK) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED));
423 if (state_for_recording)
424 *state_for_recording = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_RECORDING) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED));
426 LOGI("acquired_focus(0x%x)", stream_h->acquired_focus);
429 return _convert_sound_manager_error_code(__func__, ret);
432 int sound_manager_is_stream_on_device(sound_stream_info_h stream_info, sound_device_h device, bool *is_on)
434 int ret = MM_ERROR_NONE;
435 sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
439 SM_NULL_ARG_CHECK(stream_h);
440 SM_NULL_ARG_CHECK(device);
441 SM_NULL_ARG_CHECK(is_on);
443 ret = mm_sound_get_device_id(device, &device_id);
444 if (ret == MM_ERROR_NONE)
445 ret = _is_using_device(stream_h->index, device_id, is_on);
447 if (ret == MM_ERROR_NONE)
448 LOGI("stream info index(%u), device_id(%d), is_on(%d)", stream_h->index, device_id, *is_on);
450 return _convert_sound_manager_error_code(__func__, ret);
453 int sound_manager_get_current_media_playback_device_type(sound_device_type_e *device_type)
455 int ret = MM_ERROR_NONE;
457 char *device_type_str = NULL;
462 SM_NULL_ARG_CHECK(device_type);
465 ret = _get_current_media_routing_path("out", &device_type_str);
466 if (ret == MM_ERROR_NONE)
467 ret = _convert_device_type_str_to_enum(device_type_str, device_type);
470 return _convert_sound_manager_error_code(__func__, ret);
473 int sound_manager_get_current_playback_focus(sound_stream_focus_change_reason_e *acquired_by, int *flags, char **extra_info)
475 int ret = MM_ERROR_NONE;
476 char *stream_type_str = NULL;
477 char *extra_info_str = NULL;
479 bool is_focus_cb_thread = false;
483 SM_NULL_ARG_CHECK(acquired_by);
484 SM_NULL_ARG_CHECK(flags);
486 if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
487 return _convert_sound_manager_error_code(__func__, ret);
489 if (is_focus_cb_thread) {
490 LOGE("this API should not be called in focus callback");
491 return SOUND_MANAGER_ERROR_INVALID_OPERATION;
494 ret = mm_sound_get_stream_type_of_acquired_focus((int)SOUND_STREAM_FOCUS_FOR_PLAYBACK, &stream_type_str, &option, &extra_info_str);
495 if (ret == MM_ERROR_NONE) {
496 LOGI("current acquired PLAYBACK focus : stream_type[%s]", stream_type_str);
497 ret = _convert_stream_type_to_change_reason(stream_type_str, acquired_by);
498 if (ret == MM_ERROR_NONE) {
499 LOGI(" : reason[%d], flags[0x%x], extra_info[%s]", *acquired_by, option, extra_info_str);
502 *extra_info = extra_info_str;
504 free(extra_info_str);
508 return _convert_sound_manager_error_code(__func__, ret);
511 int sound_manager_get_current_recording_focus(sound_stream_focus_change_reason_e *acquired_by, int *flags, char **extra_info)
513 int ret = MM_ERROR_NONE;
514 char *stream_type_str = NULL;
515 char *extra_info_str = NULL;
517 bool is_focus_cb_thread = false;
521 SM_NULL_ARG_CHECK(acquired_by);
522 SM_NULL_ARG_CHECK(flags);
524 if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
525 return _convert_sound_manager_error_code(__func__, ret);
527 if (is_focus_cb_thread) {
528 LOGE("this API should not be called in focus callback");
529 return SOUND_MANAGER_ERROR_INVALID_OPERATION;
532 ret = mm_sound_get_stream_type_of_acquired_focus((int)SOUND_STREAM_FOCUS_FOR_RECORDING, &stream_type_str, &option, &extra_info_str);
533 if (ret == MM_ERROR_NONE) {
534 LOGI("current acquired RECORDING focus : stream_type[%s]", stream_type_str);
535 ret = _convert_stream_type_to_change_reason(stream_type_str, acquired_by);
536 if (ret == MM_ERROR_NONE) {
537 LOGI(" : reason[%d], flags[0x%x], extra_info[%s]", *acquired_by, option, extra_info_str);
540 *extra_info = extra_info_str;
542 free(extra_info_str);
546 return _convert_sound_manager_error_code(__func__, ret);
549 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)
551 int ret = MM_ERROR_NONE;
556 SM_NULL_ARG_CHECK(callback);
557 SM_NULL_ARG_CHECK(id);
558 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, SOUND_MANAGER_ERROR_INTERNAL);
560 for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++)
561 if (focus_watch_info_arr[i].id == 0)
563 if (i == SOUND_STREAM_INFO_ARR_MAX) {
564 LOGE("focus watch info array is full");
565 ret = MM_ERROR_SOUND_INTERNAL;
569 ret = mm_sound_set_focus_watch_callback((mm_sound_focus_type_e)focus_mask, _focus_watch_callback, user_data, id);
570 if (ret == MM_ERROR_NONE) {
571 SM_REF_FOR_STREAM_INFO(g_stream_info_count, ret);
572 focus_watch_info_arr[i].id = *id;
573 focus_watch_info_arr[i].user_data = user_data;
574 focus_watch_info_arr[i].user_cb = callback;
578 SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
580 LOGD("cnt(%d), id(%d)", g_stream_info_count, *id);
582 return _convert_sound_manager_error_code(__func__, ret);
585 int sound_manager_remove_focus_state_watch_cb(int id)
587 int ret = MM_ERROR_NONE;
592 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, SOUND_MANAGER_ERROR_INTERNAL);
594 for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++)
595 if (focus_watch_info_arr[i].id == id)
597 if (i == SOUND_STREAM_INFO_ARR_MAX) {
598 LOGE("cound not find item in focus watch info array for this id(%d)", id);
599 ret = MM_ERROR_INVALID_ARGUMENT;
603 ret = mm_sound_unset_focus_watch_callback(id);
604 if (ret == MM_ERROR_NONE) {
605 SM_UNREF_FOR_STREAM_INFO(g_stream_info_count);
606 focus_watch_info_arr[i].id = 0;
607 focus_watch_info_arr[i].user_data = NULL;
608 focus_watch_info_arr[i].user_cb = NULL;
612 SM_LEAVE_CRITICAL_SECTION(&g_stream_info_count_mutex);
614 LOGD("cnt(%d)", g_stream_info_count);
616 return _convert_sound_manager_error_code(__func__, ret);
619 int sound_manager_set_session_type(sound_session_type_e type)
621 int ret = MM_ERROR_NONE;
622 int cur_session = -1;
623 int new_session = MM_SESSION_TYPE_MEDIA;
624 bool mic_enable = false;
626 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
627 LOGI(">> enter : type=%d", type);
629 if (type < SOUND_SESSION_TYPE_MEDIA || type > SOUND_SESSION_TYPE_VOIP)
630 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
632 /* If session type is VOIP but MIC is not enabled, return false */
633 if (type == SOUND_SESSION_TYPE_VOIP) {
634 ret = system_info_get_platform_bool(FEATURE_MICROPHONE, &mic_enable);
635 LOGI("system_info_platform [%s]=[%d], ret[%d]", FEATURE_MICROPHONE, mic_enable, ret);
636 if (ret != SYSTEM_INFO_ERROR_NONE || !mic_enable)
637 return _convert_sound_manager_error_code(__func__, MM_ERROR_NOT_SUPPORT_API);
640 /* it is not supported both session and stream feature at the same time */
641 if (g_stream_info_count) {
642 LOGE("Could not set this type(%d) because of being used stream feature", type);
643 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
647 case SOUND_SESSION_TYPE_MEDIA:
648 new_session = MM_SESSION_TYPE_MEDIA;
650 case SOUND_SESSION_TYPE_ALARM:
651 new_session = MM_SESSION_TYPE_ALARM;
653 case SOUND_SESSION_TYPE_NOTIFICATION:
654 new_session = MM_SESSION_TYPE_NOTIFY;
656 case SOUND_SESSION_TYPE_EMERGENCY:
657 new_session = MM_SESSION_TYPE_EMERGENCY;
659 case SOUND_SESSION_TYPE_VOIP:
660 new_session = MM_SESSION_TYPE_VOIP;
664 /* valid session check */
665 ret = mm_session_get_current_type(&cur_session);
666 if (ret == MM_ERROR_NONE) {
667 if (cur_session == MM_SESSION_TYPE_MEDIA_RECORD) {
668 if (type > SOUND_SESSION_TYPE_MEDIA) {
669 LOGE("Could not set this type(%d) during camera/recorder/audio-io(in)/radio", type);
670 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
675 if (g_session_interrupt_cb_table.is_registered) {
676 if (new_session == cur_session ||
677 ((new_session == SOUND_SESSION_TYPE_MEDIA) && (cur_session == MM_SESSION_TYPE_MEDIA_RECORD))) {
678 LOGI("already set type=%d, ret=0x%x", type, ret);
679 return SOUND_MANAGER_ERROR_NONE;
681 ret = mm_session_finish();
682 if (ret != MM_ERROR_NONE)
683 return _convert_sound_manager_error_code(__func__, ret);
685 g_session_interrupt_cb_table.is_registered = 0;
686 if (cur_session == MM_SESSION_TYPE_VOIP) {
687 g_cached_session_mode = -1;
688 g_cached_voip_device_id = -1;
689 if (g_voip_vstream_h) {
690 _stop_virtual_stream(g_voip_vstream_h);
691 _destroy_virtual_stream(g_voip_vstream_h);
692 g_voip_vstream_h = NULL;
694 /*voip stream destruction*/
695 if (g_voip_stream_info) {
696 ret = _destroy_pa_connection_and_unregister_focus(g_voip_stream_info);
697 free(g_voip_stream_info);
698 g_voip_stream_info = NULL;
699 if (ret != MM_ERROR_NONE)
700 return _convert_sound_manager_error_code(__func__, ret);
705 ret = mm_session_init(new_session);
706 if (ret == MM_ERROR_NONE)
707 g_session_interrupt_cb_table.is_registered = 1;
709 LOGI("type=%d", type);
711 return _convert_sound_manager_error_code(__func__, ret);
714 int sound_manager_get_session_type(sound_session_type_e *type)
716 int ret = MM_ERROR_NONE;
719 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
721 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
723 ret = mm_session_get_current_type(&cur_session);
724 if (ret != MM_ERROR_NONE) {
725 LOGW("session hasn't been set, setting default session");
726 cur_session = SOUND_SESSION_TYPE_DEFAULT;
727 ret = mm_session_init(cur_session);
728 if (ret == MM_ERROR_NONE)
729 g_session_interrupt_cb_table.is_registered = 1;
731 if ((cur_session > MM_SESSION_TYPE_EMERGENCY) &&
732 (cur_session != MM_SESSION_TYPE_VOIP)) {
733 if (g_cached_session != -1)
734 cur_session = g_cached_session;
735 else /* will be never reached here. just prevent code */
736 cur_session = SOUND_SESSION_TYPE_DEFAULT;
739 switch (cur_session) {
740 case MM_SESSION_TYPE_MEDIA:
741 case MM_SESSION_TYPE_MEDIA_RECORD:
742 *type = SOUND_SESSION_TYPE_MEDIA;
744 case MM_SESSION_TYPE_ALARM:
745 *type = SOUND_SESSION_TYPE_ALARM;
747 case MM_SESSION_TYPE_NOTIFY:
748 *type = SOUND_SESSION_TYPE_NOTIFICATION;
750 case MM_SESSION_TYPE_EMERGENCY:
751 *type = SOUND_SESSION_TYPE_EMERGENCY;
753 case MM_SESSION_TYPE_VOIP:
754 *type = SOUND_SESSION_TYPE_VOIP;
761 LOGI("type=%d", *type);
763 return SOUND_MANAGER_ERROR_NONE;
766 int sound_manager_set_media_session_option(sound_session_option_for_starting_e s_option, sound_session_option_for_during_play_e d_option)
768 int ret = MM_ERROR_NONE;
770 int session_option = 0;
773 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
774 LOGI(">> enter : option for starting=%d, for during play=%d", s_option, d_option);
776 if (s_option < 0 || s_option > SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START)
777 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
778 if (d_option < 0 || d_option > SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY)
779 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
781 ret = mm_session_get_current_information(&session, &session_option);
782 if (ret != 0 || !g_session_interrupt_cb_table.is_registered) {
783 LOGW("session hasn't been set, setting default session");
784 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
786 g_session_interrupt_cb_table.is_registered = 1;
788 } else if (ret == 0 && session > MM_SESSION_TYPE_MEDIA) {
789 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
790 if (!g_session_interrupt_cb_table.is_registered) {
791 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
792 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
795 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
800 case SOUND_SESSION_OPTION_MIX_WITH_OTHERS_WHEN_START:
801 if (session_option & MM_SESSION_OPTION_PAUSE_OTHERS) {
802 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_PAUSE_OTHERS);
804 return _convert_sound_manager_error_code(__func__, ret);
809 case SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START:
810 if (!(session_option & MM_SESSION_OPTION_PAUSE_OTHERS)) {
811 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_PAUSE_OTHERS);
813 return _convert_sound_manager_error_code(__func__, ret);
821 case SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY:
822 if (session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
823 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_UNINTERRUPTIBLE);
825 return _convert_sound_manager_error_code(__func__, ret);
830 case SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY:
831 if (!(session_option & MM_SESSION_OPTION_UNINTERRUPTIBLE)) {
832 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_UNINTERRUPTIBLE);
834 return _convert_sound_manager_error_code(__func__, ret);
844 LOGI("already set same option(%x), skip it", session_option);
846 return _convert_sound_manager_error_code(__func__, ret);
849 int sound_manager_get_media_session_option(sound_session_option_for_starting_e *s_option, sound_session_option_for_during_play_e *d_option)
851 int ret = MM_ERROR_NONE;
853 int session_options = 0;
855 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
858 if (s_option == NULL || d_option == NULL)
859 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
861 ret = mm_session_get_current_information(&session, &session_options);
863 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
865 g_session_interrupt_cb_table.is_registered = 1;
867 } else if (session > SOUND_SESSION_TYPE_MEDIA) {
868 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
869 if (!g_session_interrupt_cb_table.is_registered) {
870 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
871 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
874 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
877 if (session_options & MM_SESSION_OPTION_PAUSE_OTHERS)
878 *s_option = SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START;
880 *s_option = SOUND_SESSION_OPTION_MIX_WITH_OTHERS_WHEN_START;
882 if (session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE)
883 *d_option = SOUND_SESSION_OPTION_UNINTERRUPTIBLE_DURING_PLAY;
885 *d_option = SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY;
887 LOGI(" option for starting=%d, for during play=%d", *s_option, *d_option);
889 return SOUND_MANAGER_ERROR_NONE;
892 int sound_manager_set_media_session_resumption_option(sound_session_option_for_resumption_e option)
894 int ret = MM_ERROR_NONE;
896 int session_option = 0;
899 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
900 LOGI(">> enter : option for resumption=%d (0:by system, 1:by system or media paused)", option);
902 if (option < SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM || option > SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED)
903 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
905 ret = mm_session_get_current_information(&session, &session_option);
906 if (ret != 0 || !g_session_interrupt_cb_table.is_registered) {
907 LOGW("session hasn't been set, setting default session");
908 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
910 g_session_interrupt_cb_table.is_registered = 1;
912 } else if (ret == 0 && session > MM_SESSION_TYPE_MEDIA) {
913 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
914 if (!g_session_interrupt_cb_table.is_registered) {
915 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
916 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
919 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
924 case SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM:
925 if (session_option & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED) {
926 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_REMOVE, MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED);
928 return _convert_sound_manager_error_code(__func__, ret);
933 case SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED:
934 if (!(session_option & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)) {
935 ret = mm_session_update_option(MM_SESSION_UPDATE_TYPE_ADD, MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED);
937 return _convert_sound_manager_error_code(__func__, ret);
947 LOGI("already set same option(0x%x), skip it", session_option);
949 return _convert_sound_manager_error_code(__func__, ret);
952 int sound_manager_get_media_session_resumption_option(sound_session_option_for_resumption_e *option)
954 int ret = MM_ERROR_NONE;
956 int session_options = 0;
958 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
962 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
964 ret = mm_session_get_current_information(&session, &session_options);
966 LOGW("session hasn't been set, setting default session");
967 ret = mm_session_init(MM_SESSION_TYPE_MEDIA);
969 g_session_interrupt_cb_table.is_registered = 1;
971 } else if (session > SOUND_SESSION_TYPE_MEDIA) {
972 if (session == MM_SESSION_TYPE_MEDIA_RECORD) {
973 if (!g_session_interrupt_cb_table.is_registered) {
974 LOGE("Already set by camera/recorder/audio-io(in)/radio API, but need to set session to Media first");
975 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
978 return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
981 if (session_options & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)
982 *option = SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM_OR_MEDIA_PAUSED;
984 *option = SOUND_SESSION_OPTION_RESUMPTION_BY_SYSTEM;
986 LOGI("option for resumption=%d (0:by system, 1:by system or media paused)", *option);
988 return SOUND_MANAGER_ERROR_NONE;
991 int sound_manager_set_voip_session_mode(sound_session_voip_mode_e mode)
993 int ret = MM_ERROR_NONE;
995 int session_options = 0;
997 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
998 LOGI(">> enter : mode=%d", mode);
1000 ret = mm_session_get_current_information(&session, &session_options);
1001 if (ret != MM_ERROR_NONE)
1004 if (session != MM_SESSION_TYPE_VOIP) {
1005 ret = MM_ERROR_POLICY_INTERNAL;
1009 if (mode < SOUND_SESSION_VOIP_MODE_RINGTONE || mode > SOUND_SESSION_VOIP_MODE_VOICE_WITH_BLUETOOTH) {
1010 ret = MM_ERROR_INVALID_ARGUMENT;
1014 ret = _set_session_mode((_session_mode_e)mode);
1016 LOGI("session=%d, mode=%d", session, mode);
1019 return _convert_sound_manager_error_code(__func__, ret);
1022 int sound_manager_get_voip_session_mode(sound_session_voip_mode_e *mode)
1024 int ret = MM_ERROR_NONE;
1026 int session_options = 0;
1028 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
1030 LOGE("mode is null");
1031 ret = MM_ERROR_INVALID_ARGUMENT;
1035 ret = mm_session_get_current_information(&session, &session_options);
1036 if (ret != MM_ERROR_NONE) {
1037 LOGI("session = %d, option = %d", session, session_options);
1041 if (session != MM_SESSION_TYPE_VOIP || g_cached_session_mode == -1) {
1042 ret = MM_ERROR_POLICY_INTERNAL;
1046 *mode = (sound_session_voip_mode_e)g_cached_session_mode;
1048 LOGI("session=%d, mode=%d", session, *mode);
1051 return _convert_sound_manager_error_code(__func__, ret);
1054 int sound_manager_set_session_interrupted_cb(sound_session_interrupted_cb callback, void *user_data)
1056 int ret = MM_ERROR_NONE;
1057 unsigned int subs_id = 0;
1059 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_create_stream_information() instead.", __func__);
1060 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1062 if (callback == NULL) {
1063 ret = MM_ERROR_INVALID_ARGUMENT;
1067 /* it is not supported both session and stream feature at the same time */
1068 if (g_stream_info_count) {
1069 ret = MM_ERROR_POLICY_INTERNAL;
1073 if (g_session_interrupt_cb_table.user_cb == NULL) {
1074 ret = mm_sound_add_device_connected_callback(SOUND_DEVICE_ALL_MASK, (mm_sound_device_connected_cb)_device_connected_cb, NULL, &subs_id);
1077 ret = mm_sound_focus_set_session_interrupt_callback((mm_sound_focus_session_interrupt_cb)_focus_session_interrupt_cb, NULL);
1079 if (mm_sound_remove_device_connected_callback(subs_id) != MM_ERROR_NONE)
1080 LOGW("mm_sound_remove_device_connected_callback failed");
1083 g_session_interrupt_cb_table.subs_id = subs_id;
1085 g_session_interrupt_cb_table.user_cb = (sound_session_interrupted_cb)callback;
1086 g_session_interrupt_cb_table.user_data = user_data;
1089 SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
1091 return _convert_sound_manager_error_code(__func__, ret);
1094 int sound_manager_unset_session_interrupted_cb(void)
1096 int ret = MM_ERROR_NONE;
1098 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
1099 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1101 if (!g_session_interrupt_cb_table.user_cb) {
1102 ret = MM_ERROR_SOUND_INTERNAL;
1106 ret = mm_sound_focus_unset_session_interrupt_callback();
1108 if (mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id) != MM_ERROR_NONE)
1109 LOGW("mm_sound_remove_device_connected_callback failed");
1113 ret = mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id);
1117 g_session_interrupt_cb_table.subs_id = 0;
1118 g_session_interrupt_cb_table.user_cb = NULL;
1119 g_session_interrupt_cb_table.user_data = NULL;
1122 SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
1124 return _convert_sound_manager_error_code(__func__, ret);
1127 int sound_manager_get_current_device_list(sound_device_mask_e device_mask, sound_device_list_h *device_list)
1129 int ret = MM_ERROR_NONE;
1131 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. Use sound_manager_get_device_list() instead.", __func__);
1132 ret = mm_sound_get_device_list(device_mask, device_list);
1134 return _convert_sound_manager_error_code(__func__, ret);
1137 int sound_manager_get_device_list(int device_mask, sound_device_list_h *device_list)
1139 int ret = MM_ERROR_NONE;
1141 ret = mm_sound_get_device_list(device_mask, device_list);
1143 return _convert_sound_manager_error_code(__func__, ret);
1146 int sound_manager_free_device_list(sound_device_list_h device_list)
1148 int ret = MM_ERROR_NONE;
1150 ret = mm_sound_free_device_list(device_list);
1152 return _convert_sound_manager_error_code(__func__, ret);
1155 int sound_manager_get_next_device(sound_device_list_h device_list, sound_device_h *device)
1157 int ret = MM_ERROR_NONE;
1159 ret = mm_sound_get_next_device(device_list, device);
1161 return _convert_sound_manager_error_code(__func__, ret);
1164 int sound_manager_get_prev_device(sound_device_list_h device_list, sound_device_h *device)
1166 int ret = MM_ERROR_NONE;
1168 ret = mm_sound_get_prev_device(device_list, device);
1170 return _convert_sound_manager_error_code(__func__, ret);
1173 int sound_manager_get_device_type(sound_device_h device, sound_device_type_e *type)
1175 int ret = MM_ERROR_NONE;
1176 mm_sound_device_type_e mm_sound_device_type;
1178 ret = mm_sound_get_device_type(device, &mm_sound_device_type);
1179 if (ret == MM_ERROR_NONE)
1180 _convert_device_type(mm_sound_device_type, type);
1182 return _convert_sound_manager_error_code(__func__, ret);
1185 int sound_manager_get_device_io_direction(sound_device_h device, sound_device_io_direction_e *io_direction)
1187 int ret = MM_ERROR_NONE;
1188 mm_sound_device_io_direction_e mm_sound_io_direction;
1190 ret = mm_sound_get_device_io_direction(device, &mm_sound_io_direction);
1191 if (ret == MM_ERROR_NONE)
1192 ret = _convert_device_io_direction(mm_sound_io_direction, io_direction);
1194 return _convert_sound_manager_error_code(__func__, ret);
1197 int sound_manager_get_device_id(sound_device_h device, int *id)
1199 int ret = MM_ERROR_NONE;
1201 ret = mm_sound_get_device_id(device, id);
1203 return _convert_sound_manager_error_code(__func__, ret);
1206 int sound_manager_get_device_name(sound_device_h device, char **name)
1208 int ret = MM_ERROR_NONE;
1210 ret = mm_sound_get_device_name(device, name);
1212 return _convert_sound_manager_error_code(__func__, ret);
1215 int sound_manager_get_device_state(sound_device_h device, sound_device_state_e *state)
1217 int ret = MM_ERROR_NONE;
1219 ret = mm_sound_get_device_state(device, (mm_sound_device_state_e*)state);
1221 return _convert_sound_manager_error_code(__func__, ret);
1224 int sound_manager_set_device_connected_cb(sound_device_mask_e device_mask, sound_device_connected_cb callback, void *user_data)
1226 int ret = MM_ERROR_NONE;
1227 unsigned int subs_id = 0;
1229 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
1230 "Use sound_manager_add_device_connection_changed_cb() instead.", __func__);
1232 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_conn_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1234 ret = mm_sound_add_device_connected_callback((mm_sound_device_flags_e)device_mask, (mm_sound_device_connected_cb)callback, user_data, &subs_id);
1235 if (ret == MM_ERROR_NONE) {
1236 g_device_connected_cb_table.subs_id = subs_id;
1237 g_device_connected_cb_table.user_cb = (sound_device_connected_cb)callback;
1238 g_device_connected_cb_table.user_data = user_data;
1241 SM_LEAVE_CRITICAL_SECTION(&g_device_conn_cb_mutex);
1243 return _convert_sound_manager_error_code(__func__, ret);
1246 int sound_manager_unset_device_connected_cb(void)
1248 int ret = MM_ERROR_NONE;
1250 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
1251 "Use sound_manager_remove_device_connection_changed_cb() instead.", __func__);
1253 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_conn_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1255 if (g_device_connected_cb_table.subs_id == 0) {
1256 ret = MM_ERROR_SOUND_INTERNAL;
1260 ret = mm_sound_remove_device_connected_callback(g_device_connected_cb_table.subs_id);
1261 if (ret == MM_ERROR_NONE) {
1262 g_device_connected_cb_table.subs_id = 0;
1263 g_device_connected_cb_table.user_cb = NULL;
1264 g_device_connected_cb_table.user_data = NULL;
1268 SM_LEAVE_CRITICAL_SECTION(&g_device_conn_cb_mutex);
1270 return _convert_sound_manager_error_code(__func__, ret);
1273 int sound_manager_add_device_connection_changed_cb(int device_mask, sound_device_connected_cb callback, void *user_data, int *id)
1275 int ret = MM_ERROR_NONE;
1277 if (!callback || !id)
1278 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
1280 ret = mm_sound_add_device_connected_callback((mm_sound_device_flags_e)device_mask, (mm_sound_device_connected_cb)callback, user_data, (unsigned int*)id);
1282 return _convert_sound_manager_error_code(__func__, ret);
1285 int sound_manager_remove_device_connection_changed_cb(int id)
1287 int ret = MM_ERROR_NONE;
1290 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
1292 ret = mm_sound_remove_device_connected_callback((unsigned int)id);
1294 return _convert_sound_manager_error_code(__func__, ret);
1297 int sound_manager_set_device_information_changed_cb(sound_device_mask_e device_mask, sound_device_information_changed_cb callback, void *user_data)
1299 int ret = MM_ERROR_NONE;
1300 unsigned int subs_id = 0;
1302 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
1303 "Use sound_manager_add_device_state_changed_cb() instead.", __func__);
1304 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_info_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1306 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);
1307 if (ret == MM_ERROR_NONE) {
1308 g_device_info_changed_cb_table.subs_id = subs_id;
1309 g_device_info_changed_cb_table.user_cb = (sound_device_information_changed_cb)callback;
1310 g_device_info_changed_cb_table.user_data = user_data;
1313 SM_LEAVE_CRITICAL_SECTION(&g_device_info_cb_mutex);
1315 return _convert_sound_manager_error_code(__func__, ret);
1318 int sound_manager_unset_device_information_changed_cb(void)
1320 int ret = MM_ERROR_NONE;
1322 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed from next release. "
1323 "Use sound_manager_remove_device_state_changed_cb() instead.", __func__);
1324 SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_info_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
1326 if (g_device_info_changed_cb_table.subs_id == 0) {
1327 ret = MM_ERROR_SOUND_INTERNAL;
1331 ret = mm_sound_remove_device_information_changed_callback(g_device_info_changed_cb_table.subs_id);
1332 if (ret == MM_ERROR_NONE) {
1333 g_device_info_changed_cb_table.subs_id = 0;
1334 g_device_info_changed_cb_table.user_cb = NULL;
1335 g_device_info_changed_cb_table.user_data = NULL;
1339 SM_LEAVE_CRITICAL_SECTION(&g_device_info_cb_mutex);
1341 return _convert_sound_manager_error_code(__func__, ret);
1344 int sound_manager_add_device_state_changed_cb(int device_mask, sound_device_state_changed_cb callback, void *user_data, int *id)
1346 int ret = MM_ERROR_NONE;
1348 if (!callback || !id)
1349 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
1351 ret = mm_sound_add_device_state_changed_callback(device_mask, (mm_sound_device_state_changed_cb)callback, user_data, (unsigned int*)id);
1353 return _convert_sound_manager_error_code(__func__, ret);
1356 int sound_manager_remove_device_state_changed_cb(int id)
1358 int ret = MM_ERROR_NONE;
1361 return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
1363 ret = mm_sound_remove_device_state_changed_callback((unsigned int)id);
1365 return _convert_sound_manager_error_code(__func__, ret);
1368 __attribute__ ((destructor))
1369 void __sound_manager_finalize(void)
1371 int ret = MM_ERROR_NONE;
1373 if (g_session_interrupt_cb_table.is_registered) {
1375 ret = mm_session_finish();
1376 if (ret != MM_ERROR_NONE)
1377 LOGE("[%s] failed to mm_session_finish(), ret(0x%x)", __func__, ret);
1379 g_session_interrupt_cb_table.is_registered = 0;
1384 __attribute__ ((constructor))
1385 void __sound_manager_initialize(void)