Apply focus for session interfaces to codec playing 72/47972/3
authorinhyeok <i_bc.kim@samsung.com>
Thu, 10 Sep 2015 11:21:19 +0000 (20:21 +0900)
committerinhyeok <i_bc.kim@samsung.com>
Mon, 14 Sep 2015 07:38:11 +0000 (16:38 +0900)
[Version] Release 0.9.260
[Profile] Common
[Issue Type] Refactoring

Change-Id: I9cf9b96b91d3fce2e8217dc5f9162879b6d47bd3
Signed-off-by: inhyeok <i_bc.kim@samsung.com>
include/mm_sound_focus.h
packaging/libmm-sound.spec
server/mm_sound_mgr_codec.c

index 71aecb1..1de4c5a 100644 (file)
@@ -40,7 +40,8 @@ typedef enum {
 } mm_sound_focus_state_e;
 
 typedef enum {
-       FOCUS_FOR_PLAYBACK = 1,
+       FOCUS_NONE,
+       FOCUS_FOR_PLAYBACK,
        FOCUS_FOR_CAPTURE,
        FOCUS_FOR_BOTH,
 } mm_sound_focus_type_e;
index 4ba079b..a706a55 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.9.259
+Version:    0.9.260
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 1a49ea4..bb4ba60 100644 (file)
@@ -57,6 +57,7 @@ typedef struct {
        int session_options;
        int focus_handle;
        int focus_wcb_id;
+       mm_sound_focus_type_e current_focus_type;
 
        bool enable_session;
  } __mmsound_mgr_codec_handle_t;
@@ -88,6 +89,7 @@ void sound_codec_focus_callback(int id, mm_sound_focus_type_e focus_type, mm_sou
                return;
        }
        if (focus_state == FOCUS_IS_RELEASED) {
+               g_slots[slotid].current_focus_type = FOCUS_FOR_BOTH&(~focus_type);
                debug_warning ("focus is released -> stop playing");
                result = MMSoundMgrCodecStop(slotid);
                if (result != MM_ERROR_NONE) {
@@ -242,9 +244,9 @@ int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
                if ((param->session_options & MM_SESSION_OPTION_PAUSE_OTHERS) || param->session_type == MM_SESSION_TYPE_ALARM || param->session_type == MM_SESSION_TYPE_NOTIFY || param->session_type == MM_SESSION_TYPE_EMERGENCY) {
                        debug_warning("session option is PAUSE_OTHERS -> acquire focus");
                        err = mm_sound_focus_get_id((int *)(&param->focus_handle));
-                       err = mm_sound_register_focus(param->focus_handle, "media", sound_codec_focus_callback, (void*)*slotid);
+                       err = mm_sound_register_focus_for_session(param->focus_handle, (int)param->param, "media", sound_codec_focus_callback, (void*)*slotid);
                        if (err) {
-                               debug_error("mm_sound_register_focus failed [0x%x]", err);
+                               debug_error("mm_sound_register_focus_for_session failed [0x%x]", err);
                                pthread_mutex_unlock(&g_slot_mutex);
                                return MM_ERROR_POLICY_INTERNAL;
                        }
@@ -255,14 +257,15 @@ int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
                                pthread_mutex_unlock(&g_slot_mutex);
                                return MM_ERROR_POLICY_INTERNAL;
                        }
+                       g_slots[*slotid].current_focus_type = FOCUS_FOR_BOTH;
                } else if (param->session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
                        /* do nothing */
                        debug_warning("session option is UNINTERRUPTIBLE, nothing to do with focus");
                } else {
                        debug_warning("need to set focus watch callback");
-                       err = mm_sound_set_focus_watch_callback(FOCUS_FOR_BOTH, sound_codec_focus_watch_callback, (void*)*slotid, (int *)(&param->focus_wcb_id));
+                       err = mm_sound_set_focus_watch_callback_for_session((int)param->param, FOCUS_FOR_BOTH, sound_codec_focus_watch_callback, (void*)*slotid, (int *)(&param->focus_wcb_id));
                        if (err) {
-                               debug_error("mm_sound_set_focus_watch_callback failed [0x%x]", err);
+                               debug_error("mm_sound_set_focus_watch_callback_for_session failed [0x%x]", err);
                                err = mm_sound_unregister_focus(param->focus_handle);
                                pthread_mutex_unlock(&g_slot_mutex);
                                return MM_ERROR_POLICY_INTERNAL;
@@ -498,7 +501,7 @@ int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
                if ((param->session_options & MM_SESSION_OPTION_PAUSE_OTHERS) || param->session_type == MM_SESSION_TYPE_ALARM || param->session_type == MM_SESSION_TYPE_NOTIFY || param->session_type == MM_SESSION_TYPE_EMERGENCY) {
                        debug_warning("session option is PAUSE_OTHERS -> acquire focus");
                        err = mm_sound_focus_get_id((int *)(&param->focus_handle));
-                       err = mm_sound_register_focus(param->focus_handle, "media", sound_codec_focus_callback, (void*)*slotid);
+                       err = mm_sound_register_focus_for_session(param->focus_handle, (int)param->param, "media", sound_codec_focus_callback, (void*)*slotid);
                        if (err) {
                                debug_error("mm_sound_register_focus failed [0x%x]", err);
                                pthread_mutex_unlock(&g_slot_mutex);
@@ -511,12 +514,13 @@ int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
                                pthread_mutex_unlock(&g_slot_mutex);
                                return MM_ERROR_POLICY_INTERNAL;
                        }
+                       g_slots[*slotid].current_focus_type = FOCUS_FOR_BOTH;
                } else if (param->session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
                        /* do nothing */
                        debug_warning("session option is UNINTERRUPTIBLE, nothing to do with focus");
                } else {
                        debug_warning("need to set focus watch callback");
-                       err = mm_sound_set_focus_watch_callback(FOCUS_FOR_BOTH, sound_codec_focus_watch_callback, (void*)*slotid, (int *)(&param->focus_wcb_id));
+                       err = mm_sound_set_focus_watch_callback_for_session((int)param->param, FOCUS_FOR_BOTH, sound_codec_focus_watch_callback, (void*)*slotid, (int *)(&param->focus_wcb_id));
                        if (err) {
                                debug_error("mm_sound_set_focus_watch_callback failed [0x%x]", err);
                                err = mm_sound_unregister_focus(param->focus_handle);
@@ -799,9 +803,11 @@ static int _MMSoundMgrCodecStopCallback(int param)
                        g_slots[param].session_type != MM_SESSION_TYPE_VOICE_RECOGNITION &&
                        g_slots[param].enable_session ) {
                        if ((g_slots[param].session_options & MM_SESSION_OPTION_PAUSE_OTHERS) || g_slots[param].session_type == MM_SESSION_TYPE_ALARM || g_slots[param].session_type == MM_SESSION_TYPE_NOTIFY || g_slots[param].session_type == MM_SESSION_TYPE_EMERGENCY) {
-                               err = mm_sound_release_focus(g_slots[param].focus_handle, FOCUS_FOR_BOTH, NULL);
-                               if (err) {
-                                       debug_error("mm_sound_release_focus failed [0x%x]", err);
+                               if(g_slots[param].current_focus_type != FOCUS_NONE) {
+                                       err = mm_sound_release_focus(g_slots[param].focus_handle, g_slots[param].current_focus_type, NULL);
+                                       if (err) {
+                                               debug_error("mm_sound_release_focus failed [0x%x]", err);
+                                       }
                                }
                                if(mm_sound_unregister_focus(g_slots[param].focus_handle) || err) {
                                        debug_error("Focus clean up failed [0x%x]", err);