Add focus auto reacquirement option setting api 24/51224/11 accepted/tizen/mobile/20151124.234153 accepted/tizen/tv/20151124.234204 accepted/tizen/wearable/20151124.234218 submit/tizen/20151124.091803 submit/tizen/20151124.092122
authorinhyeok <i_bc.kim@samsung.com>
Thu, 5 Nov 2015 11:11:46 +0000 (20:11 +0900)
committerinhyeok <i_bc.kim@samsung.com>
Tue, 24 Nov 2015 08:46:10 +0000 (17:46 +0900)
[Version] Release 0.2.273
[Profile] Common
[Issue Type] Add feature

Change-Id: I13d411f9f54ae1cc407290ddc392a0ce0b7d3d81
Signed-off-by: inhyeok <i_bc.kim@samsung.com>
focus_server/mm_sound_mgr_focus.c
include/mm_sound_client.h
include/mm_sound_focus.h
mm_sound_client.c
mm_sound_focus.c
packaging/libmm-sound.spec
testsuite/mm_sound_testsuite_simple.c

index 6db01f3..553fea7 100644 (file)
@@ -384,7 +384,7 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
        int endtime = 0;
        int fd_FOCUS_R = -1;
        int fd_FOCUS = -1;
-       int ret = -1;
+       unsigned int ret;
        struct pollfd pfd;
        int pret = 0;
        int pollingTimeout = 2500; /* NOTE : This is temporary code, because of Deadlock issues. If you fix that issue, remove this comment */
@@ -394,6 +394,8 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
        int flag_for_taken_index = 0;
        int taken_pid = 0;
        int taken_hid = 0;
+       int ret_handle = -1;
+       bool auto_reacquire = true;
        bool taken_by_session = false;
 
        focus_cb_data cb_data;
@@ -489,6 +491,8 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
                        debug_error("read error\n");
                        goto fail;
                }
+               ret_handle = (int)(ret & 0x0000ffff);
+               auto_reacquire = (bool)((ret >> 16) & 0xf);
        }
        g_free(filename2);
        filename2 = NULL;
@@ -509,23 +513,33 @@ int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victi
        }
        //debug_log("[RETCB] Return value 0x%x\n", buf);
 
-       /* update victim node */
-       taken_pid = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->pid : 0;
-       taken_hid = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->handle_id : 0;
-       taken_by_session = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->is_for_session : false;
-       flag_for_taken_index = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->request_type & victim_node->status : assaulter_param->request_type;
-       for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
-               if (flag_for_taken_index & (i+1)) {
-                       if (command == FOCUS_COMMAND_ACQUIRE && (victim_node->taken_by_id[i].pid != assaulter_param->pid || (victim_node->taken_by_id[i].handle_id != assaulter_param->handle_id && !(victim_node->taken_by_id[i].by_session & assaulter_param->is_for_session)))) {
-                               /* skip */
-                               debug_error("skip updating victim node");
-                               continue;
+       if (auto_reacquire) {
+               /* update victim node */
+               if (command == FOCUS_COMMAND_RELEASE) {
+                       taken_pid = assaulter_param->pid;
+                       taken_hid = assaulter_param->handle_id;
+                       taken_by_session = assaulter_param->is_for_session;
+                       flag_for_taken_index = assaulter_param->request_type & victim_node->status;
+               } else {
+                       taken_pid = 0;
+                       taken_hid = 0;
+                       taken_by_session = false;
+                       flag_for_taken_index = assaulter_param->request_type;
+               }
+
+               for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                       if (flag_for_taken_index & (i+1)) {
+                               if (command == FOCUS_COMMAND_ACQUIRE && (victim_node->taken_by_id[i].pid != assaulter_param->pid || (victim_node->taken_by_id[i].handle_id != assaulter_param->handle_id && !(victim_node->taken_by_id[i].by_session & assaulter_param->is_for_session)))) {
+                                       /* skip */
+                                       debug_error("skip updating victim node");
+                                       continue;
+                               }
+                               UPDATE_FOCUS_TAKEN_INFO(victim_node, taken_pid, taken_hid, taken_by_session);
                        }
-                       UPDATE_FOCUS_TAKEN_INFO(victim_node, taken_pid, taken_hid, taken_by_session);
                }
        }
-       if(ret == victim_node->handle_id) {
-               /* return from client is success, ret will be its handle_id */
+       if (ret_handle == victim_node->handle_id) {
+               /* return from client is success, ret_handle will be its handle_id */
                victim_node->status = (command == FOCUS_COMMAND_RELEASE) ? (victim_node->status & ~(cb_data.type)) : (victim_node->status | cb_data.type);
        } else {
                victim_node->status = FOCUS_STATUS_DEACTIVATED;
index 35ddb81..4a31114 100644 (file)
@@ -61,6 +61,8 @@ int mm_sound_client_get_uniq_id(int *id);
 int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result);
 int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* user_data);
 int mm_sound_client_unregister_focus(int id);
+int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition);
+int mm_sound_client_get_focus_reacquisition(int id, bool *reacquisition);
 int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option);
 int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, const char *option);
 int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* user_data, int *id);
index 7f8e31c..8fe26b8 100644 (file)
@@ -53,6 +53,8 @@ typedef void (*mm_sound_focus_changed_cb) (int id, mm_sound_focus_type_e focus_t
 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data);
 int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data);
 int mm_sound_unregister_focus(int id);
+int mm_sound_set_focus_reacquisition(int id, bool reacquisition);
+int mm_sound_get_focus_reacquisition(int id, bool *reacquisition);
 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info);
 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info);
 
index cc6d6ac..6a8734e 100644 (file)
@@ -91,6 +91,7 @@ typedef struct {
        GPollFD* g_poll_fd;
        GSource* focus_src;
        bool is_used;
+       bool auto_reacquire;
        GMutex focus_lock;
        mm_sound_focus_changed_cb focus_callback;
        mm_sound_focus_changed_watch_cb watch_callback;
@@ -1138,7 +1139,7 @@ static gboolean _focus_callback_handler(gpointer d)
 
                                int rett = 0;
                                int tmpfd = -1;
-                               int buf = 0;
+                               unsigned int buf = 0;
                                char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
                                tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
                                if (tmpfd < 0) {
@@ -1149,7 +1150,7 @@ static gboolean _focus_callback_handler(gpointer d)
                                        g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
                                        return FALSE;
                                }
-                               buf = cb_data.handle;
+                               buf = (unsigned int)((0x0000ffff & cb_data.handle) |(g_focus_sound_handle[focus_index].auto_reacquire << 16));
                                rett = write(tmpfd, &buf, sizeof(buf));
                                close(tmpfd);
                                g_free(filename2);
@@ -1563,6 +1564,7 @@ int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_
        g_focus_sound_handle[index].focus_callback = callback;
        g_focus_sound_handle[index].user_data = user_data;
        g_focus_sound_handle[index].is_for_session = is_for_session;
+       g_focus_sound_handle[index].auto_reacquire = true;
 
        ret = mm_sound_client_dbus_register_focus(id, pid, stream_type, callback, is_for_session, user_data);
 
@@ -1636,6 +1638,51 @@ int mm_sound_client_unregister_focus(int id)
        return ret;
 }
 
+int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
+
+       debug_fenter();
+
+       index = _focus_find_index_by_handle(id);
+       if (index == -1) {
+               debug_error("Could not find index");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       g_focus_sound_handle[index].auto_reacquire = reacquisition;
+
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_get_focus_reacquisition(int id, bool *reacquisition)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
+
+       debug_fenter();
+
+       if (!reacquisition) {
+               debug_error("Invalid parameter");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       index = _focus_find_index_by_handle(id);
+       if (index == -1) {
+               debug_error("Could not find index");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       *reacquisition = g_focus_sound_handle[index].auto_reacquire;
+
+       debug_fleave();
+
+       return ret;
+}
+
 int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
 {
        int ret = MM_ERROR_NONE;
index d24bff3..f990a8c 100644 (file)
@@ -190,6 +190,52 @@ int mm_sound_unregister_focus(int id)
 }
 
 EXPORT_API
+int mm_sound_set_focus_reacquisition(int id, bool reacquisition)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_set_focus_reacquisition(id, reacquisition);
+
+       if (ret) {
+               debug_error("Could not set focus reacquisition, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_get_focus_reacquisition(int id, bool *reacquisition)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0 || !reacquisition) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_get_focus_reacquisition(id, reacquisition);
+
+       if (ret) {
+               debug_error("Could not get focus reacquisition, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
 {
        int ret = MM_ERROR_NONE;
index 82817de..9fbe3b0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.9.272
+Version:    0.9.273
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 1df0f5e..d2698df 100755 (executable)
@@ -284,6 +284,7 @@ static void displaymenu()
                g_print("SF : Set Focus Callback\t");
                g_print("FFS : Set Focus Callback for session\t");
                g_print("UF : Unset Focus Callback\n");
+               g_print("DF : Disable Auto Focus Reacquirement\t");
                g_print("AF : Acquire Focus\t");
                g_print("RF : Release Focus\n");
                g_print("WS : Set Focus Watch Callback\t");
@@ -448,7 +449,7 @@ static void interpret (char *cmd)
        {
                case CURRENT_STATUS_MAINMENU:
 #ifdef USE_FOCUS
-                       if(strncmp(cmd, "DS", 2) ==0) {
+                       if(strncmp(cmd, "DS", 2) == 0) {
                                ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_subscribe_id1, __mm_sound_signal_cb1, NULL);
                                if(ret < 0)
                                        debug_log("mm_sound_subscribe_signal() failed with 0x%x\n", ret);
@@ -461,14 +462,14 @@ static void interpret (char *cmd)
                                        debug_log("id: %u, callback:%p\n", g_subscribe_id2, __mm_sound_signal_cb2);
                        }
 
-                       else if(strncmp(cmd, "DU", 2) ==0) {
+                       else if(strncmp(cmd, "DU", 2) == 0) {
                                mm_sound_unsubscribe_signal(g_subscribe_id1);
                                debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id1);
                                mm_sound_unsubscribe_signal(g_subscribe_id2);
                                debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id2);
                        }
 
-                       else if(strncmp(cmd, "SS", 2) ==0) {
+                       else if(strncmp(cmd, "SS", 2) == 0) {
                                ret = mm_sound_send_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1);
                                if(ret < 0)
                                        debug_log("mm_sound_send_signal() failed with 0x%x\n", ret);
@@ -485,7 +486,7 @@ static void interpret (char *cmd)
                                g_print (" -- get value of RELEASE_INTERNAL_FOCUS : %d\n", value);
                        }
 
-                       else if(strncmp(cmd, "GU", 2) ==0) {
+                       else if(strncmp(cmd, "GU", 2) == 0) {
                                int id = 0;
                                ret = mm_sound_focus_get_id(&id);
                                if(ret < 0)
@@ -494,7 +495,7 @@ static void interpret (char *cmd)
                                        debug_log("id : %d\n", id);
                        }
 
-                       else if(strncmp(cmd, "SF", 2) ==0) {
+                       else if(strncmp(cmd, "SF", 2) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1, flag_2;
@@ -543,7 +544,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "FFS", 3) ==0) {
+                       else if(strncmp(cmd, "FFS", 3) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1, flag_2;
@@ -592,7 +593,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "UF", 2) ==0) {
+                       else if(strncmp(cmd, "UF", 2) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1;
@@ -613,7 +614,37 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "AF", 2) ==0) {
+                       else if(strncmp(cmd, "DF", 2) == 0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1, flag_2;
+                               int id = 0;
+                               bool reacquisition = true;
+                               fflush(stdin);
+                               g_print ("1. enable auto reacquirement\n");
+                               g_print ("2. disable auto reacquirement\n");
+                               g_print("> select id and option: (eg. 0 1)");
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+                               flag_2 = input_string[2];
+
+                               if(flag_1 == '0') { id = 0; }
+                               else if(flag_1 == '1') { id = 1; }
+                               else if(flag_1 == '2') { id = 2; }
+                               else { id = 2; }
+
+                               if(flag_2 == '1') { reacquisition = true; }
+                               else if(flag_2 == '2') { reacquisition = false; }
+                               else { reacquisition = true; }
+                               ret = mm_sound_set_focus_reacquisition(id, reacquisition);
+                               if (ret) {
+                                       g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "AF", 2) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1, flag_2;
@@ -644,7 +675,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "RF", 2) ==0) {
+                       else if(strncmp(cmd, "RF", 2) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1, flag_2;
@@ -675,7 +706,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "WFS", 3) ==0) {
+                       else if(strncmp(cmd, "WFS", 3) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1;
@@ -705,7 +736,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "WS", 2) ==0) {
+                       else if(strncmp(cmd, "WS", 2) == 0) {
                                int ret = 0;
                                char input_string[128];
                                char flag_1;
@@ -735,7 +766,7 @@ static void interpret (char *cmd)
                                }
                        }
 
-                       else if(strncmp(cmd, "WU", 2) ==0) {
+                       else if(strncmp(cmd, "WU", 2) == 0) {
                                int ret = 0;
                                ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
                                if (ret) {
@@ -1515,38 +1546,38 @@ static void interpret (char *cmd)
                        }
        }
 
-               else if(strncmp(cmd, "z", 1) ==0) {
+               else if(strncmp(cmd, "z", 1) == 0) {
                        if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_CALL))
                        {
                                g_print("Call session init failed\n");
                        }
                }
-               else if(strncmp(cmd, "Z", 1) ==0) {
+               else if(strncmp(cmd, "Z", 1) == 0) {
                        if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VIDEOCALL))
                        {
                                g_print("VideoCall session init failed\n");
                        }
                }
-               else if(strncmp(cmd, "N", 1) ==0) {
+               else if(strncmp(cmd, "N", 1) == 0) {
                        if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_NOTIFY))
                        {
                                g_print("Notify session init failed\n");
                        }
                }
-               else if(strncmp(cmd, "n", 1) ==0) {
+               else if(strncmp(cmd, "n", 1) == 0) {
                        if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VOIP))
                        {
                                g_print("VOIP session init failed\n");
                        }
                }
-               else if(strncmp(cmd, "v", 1) ==0) {
+               else if(strncmp(cmd, "v", 1) == 0) {
                        if(MM_ERROR_NONE != mm_session_finish())
                        {
                                g_print("Call session finish failed\n");
                        }
                }
 
-               else if(strncmp(cmd, "V", 1) ==0) {
+               else if(strncmp(cmd, "V", 1) == 0) {
                        int value;
                        if(vconf_get_int(SOUND_STATUS_KEY, &value)) {
                                g_print("Can not get %s\n", SOUND_STATUS_KEY);
@@ -1584,7 +1615,7 @@ static void interpret (char *cmd)
                        }
                }
 
-               else if(strncmp(cmd, "L", 1) ==0) {
+               else if(strncmp(cmd, "L", 1) == 0) {
                        int ret = 0;
                        mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
                        MMSoundDeviceList_t device_list;
@@ -1661,7 +1692,7 @@ static void interpret (char *cmd)
                        }
                }
 
-               else if(strncmp(cmd, "C", 1) ==0) {
+               else if(strncmp(cmd, "C", 1) == 0) {
                        int ret = 0;
                        char input_string[128];
                        mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
@@ -1721,14 +1752,14 @@ static void interpret (char *cmd)
                        }
                }
 
-               else if(strncmp(cmd, "D", 1) ==0) {
+               else if(strncmp(cmd, "D", 1) == 0) {
                        int ret = 0;
                        ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
                        if (ret) {
                                g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
                        }
                }
-               else if(strncmp(cmd, "Q", 1) ==0) {
+               else if(strncmp(cmd, "Q", 1) == 0) {
                        int ret = 0;
                        char input_string[128];
                        mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
@@ -1788,7 +1819,7 @@ static void interpret (char *cmd)
                        }
                }
 
-               else if(strncmp(cmd, "W", 1) ==0) {
+               else if(strncmp(cmd, "W", 1) == 0) {
                        int ret = 0;
                        ret = mm_sound_remove_device_information_changed_callback(g_subs_id_device_info);
                        if (ret) {