Revise logic in focus callback and focus watch callback 73/118973/6 accepted/tizen/unified/20170406.054958 submit/tizen/20170405.072228
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Mar 2017 04:34:45 +0000 (13:34 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 5 Apr 2017 02:29:04 +0000 (11:29 +0900)
[Version] Release 1.17.2-6
[Profile] Common
[Issue Type] Refactorying

Change-Id: Id374423acc0f0d2610ee6372e5290794ad297b4b
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
Alc/backends/pulseaudio.c
include/AL/alc.h
packaging/openal-soft.spec

index 970fe8e..9ce8b72 100644 (file)
@@ -832,14 +832,14 @@ static pa_stream *ALCpulsePlayback_connectStream(const char *device_name,
 }
 
 #ifdef __TIZEN__
-static void stream_success_cb (pa_stream *s, int success, void *userdata)
+static void stream_success_cb(pa_stream *stream, int success, void *userdata)
 {
-    ALCpulsePlayback  *self = userdata;
+    ALCpulsePlayback *self = userdata;
     if(!self)
     {
         return;
     }
-    TRACE("context_success_cb(success:%d)\n", success);
+    TRACE("context_success_cb(stream:%p, success:%d)\n", stream, success);
     ppa_threaded_mainloop_signal(self->loop, 0);
 }
 #endif
@@ -926,223 +926,59 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
     return 0;
 }
 #ifdef __TIZEN__
-void focus_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *ext_info, void *user_data)
+static int g_acquired_focus_type;
+static void focus_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, int option, const char *ext_info, void *user_data)
 {
-    static ALCboolean play_or_capture_acquired,play_released,capture_released;
-    TRACE("focus_cb is called \n");
+    TRACE("focus_cb is called, index(%d), type(%d), state(%d), reason_for_change(%s), option(%d), ext_info(%s), user_data(%p)\n",
+          index, type, state, reason_for_change, option, ext_info, user_data);
     if(g_session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE)
     {
-        TRACE("Session uninterruptaible\n");
+        TRACE("Session uninterruptible\n");
     }
     else
     {
-        TRACE("Session interruptaible\n");
-        if(state == FOCUS_IS_RELEASED)
+        TRACE("Session interruptible\n");
+        if (state == FOCUS_IS_RELEASED)
         {
-            if(type == FOCUS_FOR_PLAYBACK)
-            {
-                play_released = ALC_TRUE;
-            }
-            else if(type == FOCUS_FOR_CAPTURE)
-            {
-                capture_released = ALC_TRUE;
-            }
-            else if(type == FOCUS_FOR_BOTH)
-            {
-                play_released = ALC_TRUE;
-                capture_released = ALC_TRUE;
-            }
-            else
-            {
-                TRACE("Invalid focus type\n");
-                return;
-            }
-            g_mute = ALC_TRUE;
-            TRACE("focus state is released so Set mute \n");
+            g_acquired_focus_type &= ~type;
+            if (g_acquired_focus_type != FOCUS_FOR_BOTH)
+                g_mute = ALC_TRUE;
+            TRACE("focus state is released, g_acquired_focus_type(%d), g_mute(%d)\n", g_acquired_focus_type, g_mute);
         }
         else
         {
-            if(type == FOCUS_FOR_BOTH)
-            {
+            g_acquired_focus_type |= type;
+            if (g_acquired_focus_type == FOCUS_FOR_BOTH)
                 g_mute = ALC_FALSE;
-                TRACE("focus type is both so UnSet mute \n");
-                play_released = ALC_FALSE;
-                capture_released = ALC_FALSE;
-                play_or_capture_acquired = ALC_FALSE;
-
-            }
-            else
-            {
-                TRACE("focus type is not both , it is %d \n",type);
-                if(type == FOCUS_FOR_PLAYBACK)
-                {
-                    if(play_or_capture_acquired)
-                    {
-                        g_mute = ALC_FALSE;
-                        play_or_capture_acquired = ALC_FALSE;
-                        play_released = ALC_FALSE;
-                        capture_released = ALC_FALSE;
-                        TRACE("focus type is capture and playback so UnSet mute \n");
-                    }
-                    else
-                    {
-                        if(play_released && !capture_released)
-                        {
-                            g_mute = ALC_FALSE;
-                            play_or_capture_acquired = ALC_FALSE;
-                            play_released = ALC_FALSE;
-                            TRACE("only play released previoulsy, so UnSet mute \n");
-                        }
-                        else
-                        {
-                            play_or_capture_acquired = ALC_TRUE;
-                            TRACE("flag play_or_capture_aquired set \n");
-                        }
-                    }
-                }
-                else if(type == FOCUS_FOR_CAPTURE)
-                {
-                    if(play_or_capture_acquired)
-                    {
-                        g_mute = ALC_FALSE;
-                        play_or_capture_acquired = ALC_FALSE;
-                        play_released = ALC_FALSE;
-                        capture_released = ALC_FALSE;
-                        TRACE("focus type is play and capture , so  UnSet mute \n");
-                    }
-                    else
-                    {
-                        if(capture_released && !play_released)
-                        {
-                            g_mute = ALC_FALSE;
-                            play_or_capture_acquired = ALC_FALSE;
-                            capture_released =  ALC_FALSE;
-                            TRACE("only capture released previously, UnSet mute \n");
-                        }
-                        else
-                        {
-                            play_or_capture_acquired = ALC_TRUE;
-                            TRACE("flag play_or_capture_acquired set \n");
-                        }
-                    }
-                }
-                else
-                {
-                    TRACE("focus type is none ,should not come here. is its %d \n", type);
-                }
-            }
+            TRACE("focus state is acquired, g_acquired_focus_type(%d), g_mute(%d)\n", g_acquired_focus_type, g_mute);
         }
     }
-
 }
 
-void focus_watch_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *ext_info, void *user_data)
+static void focus_watch_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *ext_info, void *user_data)
 {
-    static ALCboolean play_or_capture_released,play_acquired,capture_acquired;
-
-    TRACE("focus_watch_cb is called \n");
+    TRACE("focus_watch_cb is called, index(%d), type(%d), state(%d), reason_for_change(%s), ext_info(%s), user_data(%p)\n",
+          index, type, state, reason_for_change, ext_info, user_data);
     if(g_session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE)
     {
-        TRACE("Session uninterruptaible\n");
+        TRACE("Session uninterruptible\n");
     }
     else
     {
-        TRACE("Session interruptaible\n");
-        if(state == FOCUS_IS_ACQUIRED)
+        TRACE("Session interruptible\n");
+        if (state == FOCUS_IS_RELEASED)
         {
-            if(type == FOCUS_FOR_PLAYBACK)
-            {
-                play_acquired = ALC_TRUE;
-            }
-            else if(type == FOCUS_FOR_CAPTURE)
-            {
-                capture_acquired = ALC_TRUE;
-            }
-            else if(type == FOCUS_FOR_BOTH)
-            {
-                play_acquired = ALC_TRUE;
-                capture_acquired = ALC_TRUE;
-            }
-            else
-            {
-                TRACE("Invalid focus type\n");
-                return;
-            }
-
-            g_mute = ALC_TRUE;
-            TRACE("focus state is acquired so Set mute \n");
+            g_acquired_focus_type &= ~type;
+            if (g_acquired_focus_type == FOCUS_NONE)
+                g_mute = ALC_FALSE;
+            TRACE("focus state is released, g_acquired_focus_type(%d), g_mute(%d)\n", g_acquired_focus_type, g_mute);
         }
         else
         {
-            if(type == FOCUS_FOR_BOTH)
-            {
-                g_mute = ALC_FALSE;
-                TRACE("focus type is both so UnSet mute\n");
-                play_acquired = ALC_FALSE;
-                capture_acquired = ALC_FALSE;
-                play_or_capture_released = ALC_FALSE;
-
-            }
-            else
-            {
-                TRACE("focus type is not both , it is %d \n",type);
-                if(type == FOCUS_FOR_PLAYBACK)
-                {
-                    if(play_or_capture_released)
-                    {
-                        g_mute = ALC_FALSE;
-                        play_or_capture_released = ALC_FALSE;
-                        play_acquired = ALC_FALSE;
-                        capture_acquired = ALC_FALSE;
-                        TRACE("focus type is capture and playback so UnSet mute \n");
-                    }
-                    else
-                    {
-                        if(play_acquired && !capture_acquired)
-                        {
-                            g_mute = ALC_FALSE;
-                            play_or_capture_released = ALC_FALSE;
-                            play_acquired = ALC_FALSE;
-                            TRACE("only play acquired previoulsy, so UnSet mute \n");
-                        }
-                        else
-                        {
-                            play_or_capture_released = ALC_TRUE;
-                            TRACE("flag play_or_capture_released set \n");
-                        }
-                    }
-                }
-                else if(type == FOCUS_FOR_CAPTURE)
-                {
-                    if(play_or_capture_released)
-                    {
-                        g_mute = ALC_FALSE;
-                        play_or_capture_released  =  ALC_FALSE;
-                        play_acquired = ALC_FALSE;
-                        capture_acquired = ALC_FALSE;
-                        TRACE("focus type is play and capture , so  UnSet mute \n");
-                    }
-                    else
-                    {
-                        if(capture_acquired && !play_acquired)
-                        {
-                            g_mute = ALC_FALSE;
-                            play_or_capture_released = ALC_FALSE;
-                            capture_acquired =  ALC_FALSE;
-                            TRACE("only capture acqired previously, UnSet mute \n");
-                        }
-                        else
-                        {
-                            play_or_capture_released = ALC_TRUE;
-                            TRACE("flag play_or_capture_released set \n");
-                        }
-                    }
-                }
-                else
-                {
-                    TRACE("focus type is none ,should not come here. is its %d \n", type);
-                }
-            }
+            g_acquired_focus_type |= type;
+            if (g_acquired_focus_type != FOCUS_NONE)
+                g_mute = ALC_TRUE;
+            TRACE("focus state is acquired, g_acquired_focus_type(%d), g_mute(%d)\n", g_acquired_focus_type, g_mute);
         }
     }
 }
@@ -1151,7 +987,6 @@ static int focus_register(void)
 {
     int ret = MM_ERROR_NONE;
     int session_type = 0;
-    const char *user_data = "NULL";
 
     /* read session information */
     ret = _mm_session_util_read_information(-1, &session_type, &g_session_options);
@@ -1160,7 +995,7 @@ static int focus_register(void)
     {
         TRACE(" No session presnt, Registering focus_watch_cb() function \n");
         /* case 1. if there is no session */
-        ret = mm_sound_set_focus_watch_callback_for_session(getpid(), FOCUS_FOR_BOTH, focus_watch_cb, (void*)user_data, &g_focus_watch_id);
+        ret = mm_sound_set_focus_watch_callback_for_session(getpid(), FOCUS_FOR_BOTH, focus_watch_cb, NULL, &g_focus_watch_id);
         if(ret!= MM_ERROR_NONE)
         {
             ERR("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
@@ -1182,7 +1017,7 @@ static int focus_register(void)
             {
                 if(g_session_options == 0)
                 {
-                    ret = mm_sound_set_focus_watch_callback_for_session(getpid(), FOCUS_FOR_BOTH, focus_watch_cb, (void*)user_data, &g_focus_watch_id);
+                    ret = mm_sound_set_focus_watch_callback_for_session(getpid(), FOCUS_FOR_BOTH, focus_watch_cb, NULL, &g_focus_watch_id);
                     TRACE(" mm_sound_set_focus_watch_callback_for_session ret value is %x \n", ret);
                     if(ret!= MM_ERROR_NONE)
                     {
@@ -1200,7 +1035,7 @@ static int focus_register(void)
                         return -1;
                     }
                     /* register sound focus callback */
-                    ret = mm_sound_register_focus_for_session(g_focus_handle_id, getpid(), "media", focus_cb, (void*)user_data);
+                    ret = mm_sound_register_focus_for_session(g_focus_handle_id, getpid(), "media", focus_cb, NULL);
                     if(ret != MM_ERROR_NONE)
                     {
                         ERR("mm_sound_register_focus is failed\n");
@@ -1231,6 +1066,7 @@ static int focus_register(void)
 static void focus_unregister(void)
 {
     int ret = MM_ERROR_NONE;
+    g_acquired_focus_type = FOCUS_NONE;
     if(g_focus_handle_id > 0)
     {
         ret = mm_sound_unregister_focus(g_focus_handle_id);
@@ -1307,7 +1143,11 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
         if(ret)
         {
             ERR("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
+            focus_unregister();
+            pa_threaded_mainloop_unlock(self->loop);
+            return ALC_FALSE;
         }
+        g_acquired_focus_type = FOCUS_FOR_BOTH;
     }
 #endif
     TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
index 0dcdd53..631b45b 100644 (file)
@@ -23,6 +23,7 @@ extern "C" {
 
 #ifdef __TIZEN__
 #include <sound_manager.h>
+#include <sound_manager_internal.h>
 #endif
 
 /** Deprecated macro. */
index c6cdb28..afc9a0b 100644 (file)
@@ -1,6 +1,6 @@
 Name:           openal-soft
 Version:        1.17.2
-Release:        4
+Release:        6
 License:        LGPL-2.0+
 Summary:        A cross-platform 3D audio API
 URL:            http://connect.creativelabs.com/openal/