4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
36 #include <audio-session-manager.h>
37 #include <avsys-audio.h>
39 #include "../include/mm_sound_common.h"
40 #include "../include/mm_sound_utils.h"
41 #include "include/mm_sound_mgr_common.h"
42 #include "include/mm_sound_mgr_session.h"
43 #include "include/mm_sound_mgr_device.h"
44 #include "include/mm_sound_mgr_headset.h"
45 #include "include/mm_sound_mgr_pulse.h"
46 #include "include/mm_sound_mgr_asm.h"
47 #include "include/mm_sound_hal.h"
49 #define EARJACK_WITH_MIC 2
51 #define MAX_STRING_LEN 256
53 #define MM_SOUND_DEVICE_OUT_ANY 0x000FFF00
54 #define MM_SOUND_DEVICE_IN_ANY 0x000000FF
56 #define MM_SOUND_DEVICE_OUT_FILTER 0x000000FF
57 #define MM_SOUND_DEVICE_IN_FILTER 0x000FFF00
59 pthread_mutex_t g_mutex_session = PTHREAD_MUTEX_INITIALIZER;
61 #define LOCK_SESSION() do { debug_log("(*)LOCKING\n"); /*pthread_mutex_lock(&g_mutex_session);*/ debug_log("(+)LOCKED\n"); }while(0)
62 #define UNLOCK_SESSION() do { /* pthread_mutex_unlock(&g_mutex_session);*/ debug_log("(-)UNLOCKED\n"); }while(0)
64 #define RESET_ACTIVE(x) (g_info.device_active &= x)
65 #define RESET_AVAILABLE(x) (g_info.device_available &= x)
67 #define SET_ACTIVE(x) (g_info.device_active |= x)
68 #define SET_AVAILABLE(x) (g_info.device_available |= x)
70 #define SET_PLAYBACK_ONLY_ACTIVE(x) do { RESET_ACTIVE(MM_SOUND_DEVICE_OUT_FILTER); SET_ACTIVE(x); }while(0)
71 #define SET_CAPTURE_ONLY_ACTIVE(x) do { RESET_ACTIVE(MM_SOUND_DEVICE_IN_FILTER); SET_ACTIVE(x); }while(0)
74 #define UNSET_ACTIVE(x) (g_info.device_active &= (~x))
75 #define UNSET_AVAILABLE(x) (g_info.device_available &= (~x))
77 #define TOGGLE_ACTIVE(x) (g_info.device_active ^= x)
78 #define TOGGLE_AVAILABLE(x) (g_info.device_available ^= x)
80 #define IS_ACTIVE(x) (g_info.device_active & x)
81 #define IS_AVAILABLE(x) (g_info.device_available & x)
83 #define GET_AVAILABLE_PLAYBACK() IS_AVAILABLE(MM_SOUND_DEVICE_OUT_ANY)
84 #define GET_AVAILABLE_CAPTURE() IS_AVAILABLE(MM_SOUND_DEVICE_IN_ANY)
86 #define GET_ACTIVE_PLAYBACK() IS_ACTIVE(MM_SOUND_DEVICE_OUT_ANY)
87 #define GET_ACTIVE_CAPTURE() IS_ACTIVE(MM_SOUND_DEVICE_IN_ANY)
89 #define IS_COMMUNICATION_SESSION() ((g_info.session == SESSION_VOICECALL) || (g_info.session == SESSION_VOIP))
90 #define IS_NOTIFICATION_SESSION() (g_info.session == SESSION_NOTIFICATION)
91 #define IS_EMERGENCY_SESSION() (g_info.session == SESSION_EMERGENCY)
93 static int __set_sound_path_for_current_active ();
94 static int __set_sound_path_to_dual ();
95 static int __set_sound_path_to_speaker ();
96 static void __select_playback_active_device (void);
97 static void __select_capture_active_device (void);
99 #define ENABLE_CALLBACK
100 #ifndef ENABLE_CALLBACK
101 #define _mm_sound_mgr_device_available_device_callback(a,b,c) MM_ERROR_NONE
102 #define _mm_sound_mgr_device_active_device_callback(a,b) MM_ERROR_NONE
105 typedef struct _session_info_struct
108 int device_available;
113 subsession_t subsession;
115 char bt_name[MAX_STRING_LEN];
116 char default_sink_name[MAX_STRING_LEN];
119 } SESSION_INFO_STRUCT;
122 SESSION_INFO_STRUCT g_info;
131 static void dump_info ()
135 const char *playback_device_str[] = { "SPEAKER ", "RECEIVER ", "HEADSET ", "BTSCO ", "BTA2DP ", "DOCK ", "HDMI ", "WFD ", "USB " };
136 const char *capture_device_str[] = { "MAINMIC ", "HEADSET ", "BTMIC " };
138 int playback_max = sizeof (playback_device_str) / sizeof (char*);
139 int capture_max = sizeof (capture_device_str) / sizeof (char*);
141 static char tmp_str[128];
142 static char tmp_str2[128];
144 debug_log ("<----------------------------------------------------->\n");
147 strcpy (tmp_str, "PLAYBACK = [ ");
148 for (i=0; i<playback_max; i++) {
149 if (((g_info.device_available & MM_SOUND_DEVICE_OUT_ANY) >> 8) & (0x01 << i)) {
150 strcat (tmp_str, playback_device_str[i]);
153 strcat (tmp_str, "]");
155 strcpy (tmp_str2, "CAPTURE = [ ");
156 for (i=0; i<capture_max; i++) {
157 if ((g_info.device_available & MM_SOUND_DEVICE_IN_ANY) & (0x01 << i)) {
158 strcat (tmp_str2, capture_device_str[i]);
161 strcat (tmp_str2, "]");
162 debug_log ("*** Available = [0x%08x], %s %s", g_info.device_available, tmp_str, tmp_str2);
164 strcpy (tmp_str, "PLAYBACK = [ ");
165 for (i=0; i<playback_max; i++) {
166 if (((g_info.device_active & MM_SOUND_DEVICE_OUT_ANY) >> 8) & (0x01 << i)) {
167 strcat (tmp_str, playback_device_str[i]);
170 strcat (tmp_str, "]");
172 strcpy (tmp_str2, "CAPTURE = [ ");
173 for (i=0; i<capture_max; i++) {
174 if ((g_info.device_active & MM_SOUND_DEVICE_IN_ANY) & (0x01 << i)) {
175 strcat (tmp_str2, capture_device_str[i]);
178 strcat (tmp_str2, "]");
179 debug_log ("*** Active = [0x%08x], %s %s", g_info.device_active, tmp_str, tmp_str2);
182 debug_log ("*** Headset type = [%d], BT = [%s], default sink = [%s]\n", g_info.headset_type, g_info.bt_name, g_info.default_sink_name);
183 debug_log ("*** Session = [%d], SubSession = [%d]\n", g_info.session, g_info.subsession);
184 debug_log ("<----------------------------------------------------->\n");
187 /* ------------------------- ASM ------------------------------------*/
188 static pthread_mutex_t _asm_mutex = PTHREAD_MUTEX_INITIALIZER;
191 static bool _asm_register_for_headset (int * handle)
195 if (handle == NULL) {
196 debug_error ("Handle is not valid!!!\n");
200 if (!ASM_register_sound_ex (-1, handle, ASM_EVENT_EARJACK_UNPLUG, ASM_STATE_NONE, NULL, NULL, ASM_RESOURCE_NONE, &asm_error, __asm_process_message)) {
201 debug_warning("earjack event register failed with 0x%x\n", asm_error);
208 static void _asm_pause_process(int handle)
212 MMSOUND_ENTER_CRITICAL_SECTION( &_asm_mutex )
214 /* If no asm handle register here */
215 if (g_info.asm_handle == -1) {
216 debug_msg ("ASM handle is not valid, try to register once more\n");
218 /* This register should be success */
219 if (_asm_register_for_headset (&g_info.asm_handle)) {
220 debug_msg("_asm_register_for_headset() success\n");
222 debug_error("_asm_register_for_headset() failed\n");
227 debug_warning("Send earphone unplug event to Audio Session Manager Server for BT headset\n");
229 if (!ASM_set_sound_state_ex(handle, ASM_EVENT_EARJACK_UNPLUG, ASM_STATE_PLAYING, ASM_RESOURCE_NONE, &asm_error, __asm_process_message)) {
230 debug_error("earjack event set sound state to playing failed with 0x%x\n", asm_error);
233 if (!ASM_set_sound_state_ex(handle, ASM_EVENT_EARJACK_UNPLUG, ASM_STATE_STOP, ASM_RESOURCE_NONE, &asm_error, __asm_process_message)) {
234 debug_error("earjack event set sound state to stop failed with 0x%x\n", asm_error);
237 MMSOUND_LEAVE_CRITICAL_SECTION( &_asm_mutex )
240 static bool _asm_unregister_for_headset (int *handle)
244 if (handle == NULL) {
245 debug_error ("Handle is not valid!!!\n");
249 if (!ASM_unregister_sound_ex(*handle, ASM_EVENT_EARJACK_UNPLUG, &asm_error, __asm_process_message)) {
250 debug_error("earjack event unregister failed with 0x%x\n", asm_error);
258 /* ------------------------- INTERNAL FUNCTIONS ------------------------------------*/
260 static void __set_path_with_notification(noti_t noti)
262 int ret = MM_ERROR_NONE;
264 debug_msg ("[%s] noti=%d\n", __func__,noti);
266 /* Set path based on current active device */
267 ret = __set_sound_path_for_current_active();
268 if (ret != MM_ERROR_NONE) {
269 debug_error ("__set_sound_path_for_current_active() failed [%x]\n", ret);
273 if (noti == DO_NOTI) {
274 /* Notify current active device */
275 ret = _mm_sound_mgr_device_active_device_callback(GET_ACTIVE_CAPTURE(), GET_ACTIVE_PLAYBACK());
276 if (ret != MM_ERROR_NONE) {
277 debug_error ("_mm_sound_mgr_device_active_device_callback() failed [%x]\n", ret);
282 static int __set_playback_route_communication (session_state_t state)
284 int ret = MM_ERROR_NONE;
289 if (state == SESSION_START) {
290 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_RECEIVER);
291 debug_log ("voicecall session started...only receiver available set on...");
293 ret = _mm_sound_mgr_device_available_device_callback(MM_SOUND_DEVICE_IN_NONE, MM_SOUND_DEVICE_OUT_RECEIVER, 1);
294 if (ret != MM_ERROR_NONE) {
295 debug_error ("_mm_sound_mgr_device_available_device_callback() failed [%x]\n", ret);
296 goto ROUTE_COMM_EXIT;
299 /* Set default subsession as MEDIA */
300 g_info.subsession = SUBSESSION_MEDIA;
302 /* (speaker = receiver, headset = headset, bt a2dp = bt sco) */
304 if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_SPEAKER)) {
305 debug_log ("active out was SPEAKER => activate receiver!!\n");
306 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_RECEIVER);
308 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
309 debug_log ("active out was BT A2DP => activate BT SCO!!\n");
310 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO);
311 SET_CAPTURE_ONLY_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO);
313 /* FIXME : Do we have to set IN device ??? */
315 __set_path_with_notification(DO_NOTI);
319 } else { /* SESSION_END */
320 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_RECEIVER);
322 ret = _mm_sound_mgr_device_available_device_callback(MM_SOUND_DEVICE_IN_NONE, MM_SOUND_DEVICE_OUT_RECEIVER, 0);
323 if (ret != MM_ERROR_NONE) {
324 debug_error ("_mm_sound_mgr_device_available_device_callback() failed [%x]\n", ret);
325 goto ROUTE_COMM_EXIT;
329 if (g_info.session == SESSION_VOICECALL)
330 gain = AVSYS_AUDIO_GAIN_EX_VOICECALL;
331 else if (g_info.session == SESSION_VOIP)
332 gain = AVSYS_AUDIO_GAIN_EX_VIDEOCALL;
334 debug_warning ("Not valid session info....[%d]\n", g_info.session);
335 gain = AVSYS_AUDIO_GAIN_EX_VOICECALL;
339 if (audio_hal_set_sound_path(gain,
340 AVSYS_AUDIO_PATH_EX_NONE, AVSYS_AUDIO_PATH_EX_NONE,
341 AVSYS_AUDIO_PATH_OPTION_NONE)) {
342 debug_error ("audio_hal_set_sound_path() failed\n");
343 ret = MM_ERROR_SOUND_INTERNAL;
344 goto ROUTE_COMM_EXIT;
347 /* activate current available device based on priority */
348 debug_log ("Reset ACTIVE and find new one by priority.\n");
350 __select_playback_active_device();
351 __select_capture_active_device();
353 debug_log ("voicecall session stopped...set path based on current active device");
354 __set_path_with_notification(DO_NOTI);
366 static int __set_playback_route_fmradio (session_state_t state)
368 int ret = MM_ERROR_NONE;
369 int out = 0; // initizlize out
373 if (state == SESSION_START) {
375 if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_SPEAKER))
376 out = AVSYS_AUDIO_PATH_EX_SPK;
377 else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY))
378 out = AVSYS_AUDIO_PATH_EX_HEADSET;
379 else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP))
380 out = AVSYS_AUDIO_PATH_EX_A2DP;
383 if (audio_hal_set_sound_path(AVSYS_AUDIO_GAIN_EX_FMRADIO,
384 out, AVSYS_AUDIO_PATH_EX_FMINPUT,
385 AVSYS_AUDIO_PATH_OPTION_NONE)) {
386 debug_error ("audio_hal_set_sound_path() failed\n");
387 ret = MM_ERROR_SOUND_INTERNAL;
388 goto ROUTE_FMRADIO_EXIT;
391 } else { /* SESSION_END */
393 if (audio_hal_set_sound_path(AVSYS_AUDIO_GAIN_EX_FMRADIO,
394 AVSYS_AUDIO_PATH_EX_NONE, AVSYS_AUDIO_PATH_EX_NONE,
395 AVSYS_AUDIO_PATH_OPTION_NONE)) {
396 debug_error ("audio_hal_set_sound_path() failed\n");
397 ret = MM_ERROR_SOUND_INTERNAL;
398 goto ROUTE_FMRADIO_EXIT;
401 /* Set as current active status */
402 __set_path_with_notification (NO_NOTI);
405 if (AVSYS_FAIL(avsys_audio_set_ext_device_status(AVSYS_AUDIO_EXT_DEVICE_FMRADIO, state))) {
406 debug_error ("avsys_audio_set_ext_device_status() failed\n");
407 ret = MM_ERROR_SOUND_INTERNAL;
417 static int __set_playback_route_notification (session_state_t state)
419 int ret = MM_ERROR_NONE;
423 if (state == SESSION_START) {
424 ret = __set_sound_path_to_dual ();
425 if (ret != MM_ERROR_NONE) {
426 debug_error ("__set_sound_path_to_dual() failed [%x]\n", ret);
429 } else { /* SESSION_END */
430 __set_path_with_notification (NO_NOTI);
438 static int __set_playback_route_emergency (session_state_t state)
440 int ret = MM_ERROR_NONE;
444 if (state == SESSION_START) {
445 ret = __set_sound_path_to_speaker ();
446 if (ret != MM_ERROR_NONE) {
447 debug_error ("__set_sound_path_to_speaker() failed [%x]\n", ret);
450 } else { /* SESSION_END */
451 __set_path_with_notification (NO_NOTI);
459 static bool __is_forced_session ()
461 return (IS_NOTIFICATION_SESSION() || IS_EMERGENCY_SESSION())? true : false;
464 static int __set_sound_path_for_current_active (void)
466 int ret = MM_ERROR_NONE;
467 int option = AVSYS_AUDIO_PATH_OPTION_NONE;
468 int in = 0, out = 0, gain = 0;
473 if (__is_forced_session()) {
474 debug_log ("Current session is NOTI/EMER, pending path setting. path set will be done after session ends")
475 goto CURRENT_ACTIVE_END;
478 /* Pulseaudio route */
479 if (audio_hal_pulse_sink_route(g_info.device_active)) {
480 goto CURRENT_ACTIVE_END;
482 if (audio_hal_pulse_source_route(g_info.device_active)) {
483 goto CURRENT_ACTIVE_END;
487 if (IS_ACTIVE(MM_SOUND_DEVICE_IN_MIC)) {
488 in = AVSYS_AUDIO_PATH_EX_MIC;
489 } else if (IS_ACTIVE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY)) {
490 in = AVSYS_AUDIO_PATH_EX_HEADSETMIC;
491 } else if (IS_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO)) {
492 in = AVSYS_AUDIO_PATH_EX_BTMIC;
496 if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_SPEAKER)) {
497 out = AVSYS_AUDIO_PATH_EX_SPK;
498 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_RECEIVER)) {
499 out = AVSYS_AUDIO_PATH_EX_RECV;
500 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
501 out = AVSYS_AUDIO_PATH_EX_HEADSET;
502 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO)) {
503 out = AVSYS_AUDIO_PATH_EX_BTHEADSET;
504 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK)) {
505 out = AVSYS_AUDIO_PATH_EX_DOCK;
506 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI)) {
507 out = AVSYS_AUDIO_PATH_EX_HDMI;
508 } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_WFD)) {
509 #ifndef USE_PULSE_WFD
510 out = AVSYS_AUDIO_PATH_EX_HDMI;
515 switch (g_info.session) {
517 case SESSION_NOTIFICATION:
518 case SESSION_EMERGENCY:
519 gain = AVSYS_AUDIO_GAIN_EX_KEYTONE;
522 case SESSION_VOICECALL:
524 if (g_info.subsession == SUBSESSION_RINGTONE) {
525 gain = AVSYS_AUDIO_GAIN_EX_RINGTONE;
526 in = AVSYS_AUDIO_PATH_EX_NONE;
528 /* If sound is mute mode, force ringtone path to headset */
529 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_play);
531 /* Normal Ringtone */
532 out = AVSYS_AUDIO_PATH_EX_SPK;
533 option = AVSYS_AUDIO_PATH_OPTION_DUAL_OUT;
536 out = AVSYS_AUDIO_PATH_EX_HEADSET;
538 } else if (g_info.subsession == SUBSESSION_MEDIA) {
539 gain = AVSYS_AUDIO_GAIN_EX_CALLTONE;
540 in = AVSYS_AUDIO_PATH_EX_NONE;
541 } else if (g_info.subsession == SUBSESSION_VOICE) {
542 gain = (g_info.session == SESSION_VOICECALL)?
543 AVSYS_AUDIO_GAIN_EX_VOICECALL : AVSYS_AUDIO_GAIN_EX_VIDEOCALL;
545 if (out == AVSYS_AUDIO_PATH_EX_HEADSET) {
546 debug_log ("Fix in path to headsetmic when out path is headset\n");
547 in = AVSYS_AUDIO_PATH_EX_HEADSETMIC;
550 debug_warning ("Unexpected SUBSESSION [%d]\n", g_info.subsession);
554 case SESSION_FMRADIO:
555 gain = AVSYS_AUDIO_GAIN_EX_FMRADIO;
556 in = AVSYS_AUDIO_PATH_EX_FMINPUT;
560 debug_warning ("session [%d] is not handled...\n", g_info.session);
564 /* Set Path (GAIN, OUT, IN) */
565 if (audio_hal_set_sound_path(gain, out, in, option)) {
566 debug_error ("audio_hal_set_sound_path failed\n");
567 ret = MM_ERROR_SOUND_INTERNAL;
576 static int __set_sound_path_to_dual (void)
578 int ret = MM_ERROR_NONE;
582 /* Sound path for ALSA */
583 debug_log ("Set path to DUAL.\n");
584 if (audio_hal_set_sound_path(AVSYS_AUDIO_GAIN_EX_KEYTONE,
585 AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_NONE,
586 AVSYS_AUDIO_PATH_OPTION_DUAL_OUT)) {
587 debug_error ("audio_hal_set_sound_path() failed\n");
588 ret = MM_ERROR_SOUND_INTERNAL;
596 static int __set_sound_path_to_speaker (void)
598 int ret = MM_ERROR_NONE;
602 /* Sound path for ALSA */
603 debug_log ("Set path to SPEAKER.\n");
604 if (audio_hal_set_sound_path(AVSYS_AUDIO_GAIN_EX_KEYTONE,
605 AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_NONE,
606 AVSYS_AUDIO_PATH_OPTION_NONE)) {
607 debug_error ("audio_hal_set_sound_path failed\n");
608 ret = MM_ERROR_SOUND_INTERNAL;
616 static void __select_playback_active_device (void)
618 if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_ANY)) {
619 debug_log ("Active device exists. Nothing needed...\n");
623 debug_log ("No playback active device, set active based on priority!!\n");
625 /* set active device based on device priority (bt>ear>spk) */
626 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
627 debug_log ("BT A2DP available, set as active!!\n");
628 SET_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP);
629 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WFD)) {
630 debug_log ("WFD available, set as active!!\n");
631 SET_ACTIVE(MM_SOUND_DEVICE_OUT_WFD);
632 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
633 debug_log ("DOCK available, set as active!!\n");
634 SET_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
635 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_HDMI)) {
636 debug_log ("HDMI available, set as active!!\n");
637 SET_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI);
638 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
639 debug_log ("USB Audio available, set as active!!\n");
640 SET_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO);
641 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
642 debug_log ("WIRED available, set as active!!\n");
643 SET_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
645 debug_log ("SPEAKER available, set as active!!\n");
646 SET_ACTIVE(MM_SOUND_DEVICE_OUT_SPEAKER);
650 static void __select_capture_active_device (void)
652 if (IS_ACTIVE(MM_SOUND_DEVICE_IN_ANY)) {
653 debug_log ("Active device exists. Nothing needed...\n");
657 debug_log ("No capture active device, set active based on priority!!\n");
659 /* set active device based on device priority (bt>ear>spk) */
660 if (IS_AVAILABLE(MM_SOUND_DEVICE_IN_BT_SCO) && IS_COMMUNICATION_SESSION()) {
661 debug_log ("BT SCO available, set as active!!\n");
662 SET_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO);
663 } else if (IS_AVAILABLE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY)) {
664 debug_log ("WIRED available, set as active!!\n");
665 SET_ACTIVE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
667 debug_log ("MIC available, set as active!!\n");
668 SET_ACTIVE(MM_SOUND_DEVICE_IN_MIC);
672 static void __set_initial_active_device (void)
675 bool a2dp = 0, sco = 0;
677 /* Set SPK & MIC as default available device */
678 /* FIXME : spk & mic can be always on??? */
679 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_SPEAKER);
680 SET_AVAILABLE(MM_SOUND_DEVICE_IN_MIC);
682 /* Get wired status and set available status */
683 MMSoundMgrHeadsetGetType (&type);
685 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
686 if (type == EARJACK_WITH_MIC) {
687 SET_AVAILABLE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
691 /* Get BT status and set available status */
692 MMSoundMgrPulseGetInitialBTStatus (&a2dp, &sco);
694 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP);
697 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_SCO);
698 SET_AVAILABLE(MM_SOUND_DEVICE_IN_BT_SCO);
701 /* Set Active device based on priority */
702 __select_playback_active_device ();
703 __select_capture_active_device ();
705 __set_path_with_notification (NO_NOTI);
710 static void __handle_bt_a2dp_on (void)
712 int ret = MM_ERROR_NONE;
714 /* at this time, pulseaudio default sink is bt sink */
715 if (IS_COMMUNICATION_SESSION()) {
716 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
720 debug_log ("Activate BT_A2DP device\n");
721 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP);
723 ret = _mm_sound_mgr_device_active_device_callback(GET_ACTIVE_CAPTURE(), GET_ACTIVE_PLAYBACK());
724 if (ret != MM_ERROR_NONE) {
725 debug_error ("_mm_sound_mgr_device_active_device_callback() failed [%x]\n", ret);
731 static void __handle_bt_a2dp_off (void)
733 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
734 debug_msg("MM_SOUND_DEVICE_OUT_BT_A2DP was not active. nothing to do here.");
740 /* if bt was active, then do asm pause */
741 debug_msg("Do pause here");
742 _asm_pause_process (g_info.asm_handle);
745 /* set bt device to none */
746 debug_msg("Deactivate BT_A2DP device\n");
747 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP);
749 /* activate current available device based on priority */
750 __select_playback_active_device();
752 /* Do set path and notify result */
753 __set_path_with_notification(DO_NOTI);
758 static void __handle_bt_sco_off (void)
760 /* If sco is not activated, just return */
761 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO) && !IS_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO)) {
762 debug_msg("BT SCO was not active. nothing to do here.");
767 /* set bt device to none */
768 debug_msg("Deactivate BT_SCO device\n");
769 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO);
770 UNSET_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO);
772 /* activate current available device based on priority */
773 __select_playback_active_device();
774 __select_capture_active_device();
776 /* Do set path and notify result */
777 __set_path_with_notification(DO_NOTI);
782 static void __handle_headset_on (int type)
784 /* at this time, pulseaudio default sink is bt sink */
785 /* if fmradio session, do nothing */
787 /* Skip when noti session */
789 /* ToDo : alarm/notification session ???? */
790 if (IS_COMMUNICATION_SESSION()) {
791 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
795 debug_log ("Activate WIRED OUT device\n");
796 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
797 if (type == EARJACK_WITH_MIC) {
798 debug_log ("Activate WIRED IN device\n");
799 SET_CAPTURE_ONLY_ACTIVE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
802 /* Do set path and notify result */
803 __set_path_with_notification(DO_NOTI);
808 static void __handle_headset_off (void)
810 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
811 debug_msg("MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY was not active. nothing to do here.");
816 /* if bt was active, then do asm pause */
817 debug_msg("Do pause here");
818 _asm_pause_process (g_info.asm_handle);
821 /* set bt device to none */
822 debug_msg("Deactivate WIRED IN/OUT device\n");
823 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
824 UNSET_ACTIVE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
826 /* For voicecall session, activation device is up-to application policy */
827 if (IS_COMMUNICATION_SESSION()) {
828 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
832 /* activate current available device based on priority */
833 __select_playback_active_device();
834 __select_capture_active_device();
836 /* Do set path and notify result */
837 __set_path_with_notification(DO_NOTI);
842 static void __handle_dock_on (void)
844 /* ToDo : alarm/notification session ???? */
845 if (IS_COMMUNICATION_SESSION()) {
846 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
850 debug_log ("Activate DOCK device\n");
851 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
853 /* Do set path and notify result */
854 __set_path_with_notification(DO_NOTI);
859 static void __handle_dock_off (void)
861 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK)) {
862 debug_msg("MM_SOUND_DEVICE_OUT_DOCK was not active. nothing to do here.");
866 /* No PAUSE on Dock off case */
868 /* set DOCK device to none */
869 debug_msg("Deactivate DOCK device\n");
870 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
872 /* activate current available device based on priority */
873 __select_playback_active_device();
875 /* Do set path and notify result */
876 __set_path_with_notification(DO_NOTI);
881 static void __handle_hdmi_on (void)
883 /* ToDo : alarm/notification session ???? */
884 if (IS_COMMUNICATION_SESSION()) {
885 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
889 debug_log ("Activate HDMI device\n");
890 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI);
892 /* Do set path and notify result */
893 __set_path_with_notification(DO_NOTI);
898 static void __handle_hdmi_off (void)
900 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI)) {
901 debug_msg("MM_SOUND_DEVICE_OUT_HDMI was not active. nothing to do here.");
906 /* if HDMI was active, then do asm pause */
907 debug_msg("Do pause here");
908 _asm_pause_process (g_info.asm_handle);
911 /* set DOCK device to none */
912 debug_msg("Deactivate HDMIdevice\n");
913 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI);
915 /* activate current available device based on priority */
916 __select_playback_active_device();
918 /* Do set path and notify result */
919 __set_path_with_notification(DO_NOTI);
924 static void __handle_wfd_on (void)
926 /* ToDo : alarm/notification session ???? */
927 if (IS_COMMUNICATION_SESSION()) {
928 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
932 debug_log ("Activate WFD device\n");
933 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_WFD);
935 /* Do set path and notify result */
936 __set_path_with_notification(DO_NOTI);
941 static void __handle_wfd_off (void)
943 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_WFD)) {
944 debug_msg("MM_SOUND_DEVICE_OUT_WFD was not active. nothing to do here.");
949 /* if WFD was active, then do asm pause */
950 debug_msg("Do pause here");
951 _asm_pause_process (g_info.asm_handle);
954 /* set WFD device to none */
955 debug_msg("Deactivate WFD device\n");
956 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_WFD);
958 /* activate current available device based on priority */
959 __select_playback_active_device();
961 /* Do set path and notify result */
962 __set_path_with_notification(DO_NOTI);
967 static void __handle_usb_audio_on (void)
969 int ret = MM_ERROR_NONE;
971 if (IS_COMMUNICATION_SESSION()) {
972 debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
976 debug_log ("Activate USB Audio device\n");
977 SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO);
979 ret = _mm_sound_mgr_device_active_device_callback(GET_ACTIVE_CAPTURE(), GET_ACTIVE_PLAYBACK());
980 if (ret != MM_ERROR_NONE) {
981 debug_error ("_mm_sound_mgr_device_active_device_callback() failed [%x]\n", ret);
987 static void __handle_usb_audio_off (void)
989 if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
990 debug_msg("MM_SOUND_DEVICE_OUT_USB_AUDIO was not active. nothing to do here.");
996 /* if device was active, then do asm pause */
997 debug_msg("Do pause here");
998 _asm_pause_process (g_info.asm_handle);
1001 /* set bt device to none */
1002 debug_msg("Deactivate USB Audio device\n");
1003 UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO);
1005 /* activate current available device based on priority */
1006 __select_playback_active_device();
1008 /* Do set path and notify result */
1009 __set_path_with_notification(DO_NOTI);
1015 /* ------------------------- EXTERNAL FUNCTIONS ------------------------------------*/
1016 /* DEVICE : Called by mgr_pulse for updating current default_sink_name */
1017 int MMSoundMgrSessionSetDefaultSink (char *default_sink_name)
1021 strcpy (g_info.default_sink_name, default_sink_name);
1022 debug_msg ("[SESSION][%s][%d] default sink=[%s]\n", __func__, __LINE__, default_sink_name);
1024 /* ToDo: do something */
1028 return MM_ERROR_NONE;
1031 /* DEVICE : Called by mgr_pulse for bt and mgr_headset for headset */
1032 int MMSoundMgrSessionSetDeviceAvailable (device_type_t device, int available, int type, char* name)
1036 debug_msg ("[SESSION] device = %d, available = %d, type = %d, name = %s\n", device, available, type, name);
1041 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
1042 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
1043 if (type == EARJACK_WITH_MIC) {
1044 SET_AVAILABLE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
1045 _mm_sound_mgr_device_available_device_callback(
1046 MM_SOUND_DEVICE_IN_WIRED_ACCESSORY,
1047 MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,
1050 _mm_sound_mgr_device_available_device_callback(
1051 MM_SOUND_DEVICE_IN_NONE,
1052 MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,
1055 __handle_headset_on(type);
1057 debug_log ("Already device [%d] is available...\n", device);
1062 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
1063 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
1064 if (IS_AVAILABLE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY)) {
1065 UNSET_AVAILABLE(MM_SOUND_DEVICE_IN_WIRED_ACCESSORY);
1066 _mm_sound_mgr_device_available_device_callback(
1067 MM_SOUND_DEVICE_IN_WIRED_ACCESSORY,
1068 MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,
1072 _mm_sound_mgr_device_available_device_callback(
1073 MM_SOUND_DEVICE_IN_NONE,
1074 MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,
1077 __handle_headset_off();
1079 debug_log ("Already device [%d] is unavailable...\n", device);
1085 case DEVICE_BT_A2DP:
1086 strcpy (g_info.bt_name, (name)? name : "");
1088 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
1089 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP);
1090 _mm_sound_mgr_device_available_device_callback(
1091 MM_SOUND_DEVICE_IN_NONE,
1092 MM_SOUND_DEVICE_OUT_BT_A2DP,
1095 __handle_bt_a2dp_on();
1097 debug_log ("Already device [%d] is available...\n", device);
1100 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
1101 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP);
1102 _mm_sound_mgr_device_available_device_callback(
1103 MM_SOUND_DEVICE_IN_NONE,
1104 MM_SOUND_DEVICE_OUT_BT_A2DP,
1107 __handle_bt_a2dp_off();
1109 debug_log ("Already device [%d] is unavailable...\n", device);
1116 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_SCO)) {
1117 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_SCO);
1118 SET_AVAILABLE(MM_SOUND_DEVICE_IN_BT_SCO);
1119 _mm_sound_mgr_device_available_device_callback(
1120 MM_SOUND_DEVICE_IN_BT_SCO,
1121 MM_SOUND_DEVICE_OUT_BT_SCO,
1124 debug_log ("Already device [%d] is available...\n", device);
1127 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_SCO)) {
1128 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_SCO);
1129 UNSET_AVAILABLE(MM_SOUND_DEVICE_IN_BT_SCO);
1130 _mm_sound_mgr_device_available_device_callback(
1131 MM_SOUND_DEVICE_IN_BT_SCO,
1132 MM_SOUND_DEVICE_OUT_BT_SCO,
1135 __handle_bt_sco_off();
1137 debug_log ("Already device [%d] is unavailable...\n", device);
1144 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
1145 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK);
1146 _mm_sound_mgr_device_available_device_callback(
1147 MM_SOUND_DEVICE_IN_NONE,
1148 MM_SOUND_DEVICE_OUT_DOCK,
1152 debug_log ("Already device [%d] is available...\n", device);
1155 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
1156 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK);
1157 _mm_sound_mgr_device_available_device_callback(
1158 MM_SOUND_DEVICE_IN_NONE,
1159 MM_SOUND_DEVICE_OUT_DOCK,
1162 __handle_dock_off();
1164 debug_log ("Already device [%d] is unavailable...\n", device);
1171 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_HDMI)) {
1172 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_HDMI);
1173 _mm_sound_mgr_device_available_device_callback(
1174 MM_SOUND_DEVICE_IN_NONE,
1175 MM_SOUND_DEVICE_OUT_HDMI,
1179 debug_log ("Already device [%d] is available...\n", device);
1182 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_HDMI)) {
1183 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_HDMI);
1184 _mm_sound_mgr_device_available_device_callback(
1185 MM_SOUND_DEVICE_IN_NONE,
1186 MM_SOUND_DEVICE_OUT_HDMI,
1189 __handle_hdmi_off();
1191 debug_log ("Already device [%d] is unavailable...\n", device);
1198 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WFD)) {
1199 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_WFD);
1200 _mm_sound_mgr_device_available_device_callback(
1201 MM_SOUND_DEVICE_IN_NONE,
1202 MM_SOUND_DEVICE_OUT_WFD,
1206 debug_log ("Already device [%d] is available...\n", device);
1209 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WFD)) {
1210 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_WFD);
1211 _mm_sound_mgr_device_available_device_callback(
1212 MM_SOUND_DEVICE_IN_NONE,
1213 MM_SOUND_DEVICE_OUT_WFD,
1218 debug_log ("Already device [%d] is unavailable...\n", device);
1223 case DEVICE_USB_AUDIO:
1225 if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
1226 SET_AVAILABLE(MM_SOUND_DEVICE_OUT_USB_AUDIO);
1227 _mm_sound_mgr_device_available_device_callback(
1228 MM_SOUND_DEVICE_IN_NONE,
1229 MM_SOUND_DEVICE_OUT_USB_AUDIO,
1231 __handle_usb_audio_on();
1233 debug_log ("Already device [%d] is available...\n", device);
1236 if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
1237 UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_USB_AUDIO);
1238 _mm_sound_mgr_device_available_device_callback(
1239 MM_SOUND_DEVICE_IN_NONE,
1240 MM_SOUND_DEVICE_OUT_USB_AUDIO,
1243 __handle_usb_audio_off();
1245 debug_log ("Already device [%d] is unavailable...\n", device);
1251 debug_warning ("device [%d] is not handled...\n", device);
1257 return MM_ERROR_NONE;
1260 int MMSoundMgrSessionIsDeviceAvailableNoLock (mm_sound_device_out playback, mm_sound_device_in capture, bool *available)
1262 int ret = MM_ERROR_NONE;
1263 debug_log ("[SESSION][%s][%d] query playback=[0x%X] capture=[0x%X], current available = [0x%X]\n",
1264 __func__, __LINE__, playback, capture, g_info.device_available);
1267 if (playback == MM_SOUND_DEVICE_OUT_NONE) {
1268 *available = IS_AVAILABLE(capture);
1269 } else if (capture == MM_SOUND_DEVICE_IN_NONE) {
1270 *available = IS_AVAILABLE(playback);
1272 *available = (IS_AVAILABLE(playback) && IS_AVAILABLE(capture));
1274 debug_log ("[%s][%d] return available = [%d]\n", __func__, __LINE__, *available);
1276 debug_warning ("Invalid argument!!!\n");
1277 ret = MM_ERROR_INVALID_ARGUMENT;
1284 int MMSoundMgrSessionIsDeviceAvailable (mm_sound_device_out playback, mm_sound_device_in capture, bool *available)
1286 int ret = MM_ERROR_NONE;
1289 ret = MMSoundMgrSessionIsDeviceAvailableNoLock (playback, capture, available);
1295 int MMSoundMgrSessionGetAvailableDevices (int *playback, int *capture)
1297 if (playback == NULL || capture == NULL) {
1298 debug_error ("Invalid input parameter\n");
1299 return MM_ERROR_INVALID_ARGUMENT;
1304 *playback = GET_AVAILABLE_PLAYBACK();
1305 *capture = GET_AVAILABLE_CAPTURE();
1306 debug_msg ("[SESSION][%s][%d] return available playback=[0x%X]/capture=[0x%X]\n", __func__, __LINE__, *playback, *capture);
1310 return MM_ERROR_NONE;
1313 int MMSoundMgrSessionSetDeviceActive (mm_sound_device_out playback, mm_sound_device_in capture)
1315 int ret = MM_ERROR_NONE;
1316 int old_active = g_info.device_active;
1320 debug_msg ("[SESSION][%s][%d] playback=[0x%X] capture=[0x%X]\n", __func__, __LINE__, playback, capture);
1322 /* Check whether device is available */
1323 if ((playback && !IS_AVAILABLE(playback)) || (capture && !IS_AVAILABLE(capture))) {
1324 debug_warning ("Failed to set active state to unavailable device!!!\n");
1325 ret = MM_ERROR_INVALID_ARGUMENT;
1326 goto END_SET_DEVICE;
1329 /* Update active state */
1330 debug_log ("Update active device as request\n");
1332 SET_PLAYBACK_ONLY_ACTIVE(playback);
1335 SET_CAPTURE_ONLY_ACTIVE(capture);
1338 /* If there's changes do path set and inform callback */
1339 if (old_active != g_info.device_active) {
1340 debug_msg ("Changes happens....set path based on current active device and inform callback!!!\n");
1342 /* Do set path based on current active state */
1343 __set_path_with_notification(DO_NOTI);
1345 debug_msg ("No changes....nothing to do...\n");
1353 int MMSoundMgrSessionGetDeviceActive (mm_sound_device_out *playback, mm_sound_device_in *capture)
1355 if (playback == NULL || capture == NULL) {
1356 debug_error ("Invalid input parameter\n");
1357 return MM_ERROR_INVALID_ARGUMENT;
1362 *playback = GET_ACTIVE_PLAYBACK();
1363 *capture = GET_ACTIVE_CAPTURE();
1364 debug_msg ("[SESSION][%s][%d] return active playback=[0x%X]/capture=[0x%X]\n", __func__, __LINE__,
1365 *playback,*capture);
1368 return MM_ERROR_NONE;
1372 int MMSoundMgrSessionSetSession(session_t session, session_state_t state)
1376 debug_warning ("[SESSION][%s][%d] session=[%d] state=[%d]\n", __func__, __LINE__, session, state);
1378 /* Update session */
1380 g_info.session = session;
1382 g_info.session = SESSION_MEDIA;
1384 /* Do action based on new session */
1394 case SESSION_VOICECALL:
1396 __set_playback_route_communication (state);
1399 case SESSION_FMRADIO:
1400 __set_playback_route_fmradio (state);
1403 case SESSION_NOTIFICATION:
1404 __set_playback_route_notification (state);
1407 case SESSION_EMERGENCY:
1408 __set_playback_route_emergency (state);
1412 debug_warning ("session [%d] is not handled...\n", session);
1417 return MM_ERROR_NONE;
1420 int MMSoundMgrSessionGetSession(session_t *session)
1422 if (session == NULL) {
1423 debug_error ("Invalid input parameter\n");
1424 return MM_ERROR_INVALID_ARGUMENT;
1428 *session = g_info.session;
1431 return MM_ERROR_NONE;
1435 int MMSoundMgrSessionSetSubSession(subsession_t subsession)
1439 if (g_info.subsession == subsession) {
1440 debug_msg ("[SESSION][%s][%d] already subsession is [%d]. skip this!!\n", __func__, __LINE__, subsession);
1442 g_info.subsession = subsession;
1443 debug_msg ("[SESSION][%s][%d] subsession=[%d]\n", __func__, __LINE__, subsession);
1445 __set_path_with_notification (NO_NOTI);
1450 return MM_ERROR_NONE;
1453 int MMSoundMgrSessionGetSubSession(subsession_t *subsession)
1455 if (subsession == NULL) {
1456 debug_error ("Invalid input parameter\n");
1457 return MM_ERROR_INVALID_ARGUMENT;
1462 *subsession = g_info.subsession;
1466 return MM_ERROR_NONE;
1469 char* MMSoundMgrSessionGetBtA2DPName ()
1471 return g_info.bt_name;
1474 int MMSoundMgrSessionInit(void)
1480 memset (&g_info, 0, sizeof (SESSION_INFO_STRUCT));
1482 /* FIXME: Initial status should be updated */
1483 __set_initial_active_device ();
1486 /* Register for headset unplug */
1487 if (_asm_register_for_headset (&g_info.asm_handle) == false) {
1488 debug_error ("Failed to register ASM for headset\n");
1495 return MM_ERROR_NONE;
1498 int MMSoundMgrSessionFini(void)
1505 /* Unregister for headset unplug */
1506 _asm_unregister_for_headset (&g_info.asm_handle);
1513 return MM_ERROR_NONE;