Add protection code for focus-callback creation 45/110645/3 accepted/tizen/3.0/common/20170124.081313 accepted/tizen/3.0/ivi/20170124.042417 accepted/tizen/3.0/mobile/20170124.042250 accepted/tizen/3.0/tv/20170124.042320 accepted/tizen/3.0/wearable/20170124.042349 submit/tizen_3.0/20170123.123302
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 17 Jan 2017 09:06:35 +0000 (18:06 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 23 Jan 2017 07:30:58 +0000 (16:30 +0900)
[Version] 0.10.84
[Profile] Common
[Issue Type] Debug

Change-Id: Ib91e9fca348bae24b6bd446236d91eef25c96506

mm_sound_client.c
mm_sound_keysound.c
packaging/libmm-sound.spec

index ee666d1..87a6bf8 100644 (file)
@@ -1043,9 +1043,12 @@ int mm_sound_client_unset_session_interrupt_callback(void)
 
 static gpointer _focus_thread_func(gpointer data)
 {
-       debug_log(">>> thread func..ID of this thread(%u)\n", (unsigned int)pthread_self());
-       g_main_loop_run(g_focus_loop);
-       debug_log("<<< quit thread func..\n");
+       unsigned int thread_id = (unsigned int)pthread_self();
+       debug_warning(">>> thread func..ID of this thread(%u), mainloop(%p)", thread_id, g_focus_loop);
+       if (g_focus_loop)
+               g_main_loop_run(g_focus_loop);
+
+       debug_warning("<<< quit thread func..(%u), mainloop(%p)", thread_id, g_focus_loop);
        return NULL;
 }
 
@@ -1603,24 +1606,36 @@ int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_
                        GMainContext* focus_context = g_main_context_new ();
                        g_focus_loop = g_main_loop_new (focus_context, FALSE);
                        g_main_context_unref(focus_context);
-                       g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
+                       if (g_focus_loop == NULL) {
+                               debug_error("could not create mainloop..");
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+
+                       g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
                        if (g_focus_thread == NULL) {
-                               debug_error ("could not create thread..");
+                               debug_error("could not create thread..");
                                g_main_loop_unref(g_focus_loop);
-                               g_focus_sound_handle[index].is_used = false;
                                ret = MM_ERROR_SOUND_INTERNAL;
                                goto cleanup;
                        }
+               } else {
+                       debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
+                                               g_focus_thread, g_focus_loop);
                }
        } else {
                debug_error("[Client] Error occurred : 0x%x \n",ret);
-               g_focus_sound_handle[index].is_used = false;
                goto cleanup;
        }
 
        _focus_init_callback(index, false);
 
 cleanup:
+
+       if (ret) {
+               g_focus_sound_handle[index].is_used = false;
+       }
+
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
 
@@ -1864,13 +1879,22 @@ int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focu
                        GMainContext* focus_context = g_main_context_new ();
                        g_focus_loop = g_main_loop_new (focus_context, FALSE);
                        g_main_context_unref(focus_context);
-                       g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
+                       if (g_focus_loop == NULL) {
+                               debug_error("could not create mainloop..");
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+
+                       g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
                        if (g_focus_thread == NULL) {
                                debug_error ("could not create thread..");
                                g_main_loop_unref(g_focus_loop);
                                ret = MM_ERROR_SOUND_INTERNAL;
                                goto cleanup;
                        }
+               } else {
+                       debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
+                                               g_focus_thread, g_focus_loop);
                }
        } else {
                debug_error("[Client] Error occurred : 0x%x",ret);
index 9794d56..2daa6e9 100644 (file)
@@ -61,7 +61,7 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_
 
 static const char* convert_volume_type_to_role(int volume_type)
 {
-       debug_warning ("volume_type(%d)", volume_type);
+       debug_log("volume_type(%d)", volume_type);
        switch(volume_type) {
        case VOLUME_TYPE_MEDIA:
                return "media";
@@ -83,7 +83,7 @@ static const char* convert_volume_type_to_role(int volume_type)
 
 static const char* convert_volume_gain_type_to_string(int volume_gain_type)
 {
-       debug_warning ("volume_gain_type(0x%x)", volume_gain_type);
+       debug_log("volume_gain_type(0x%x)", volume_gain_type);
        switch(volume_gain_type) {
        case VOLUME_GAIN_DEFAULT:
                return "";
index 2907593..01c84e1 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.10.83
+Version:    0.10.84
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0