Enhance session backward compatibility 26/158426/2
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 1 Nov 2017 02:06:19 +0000 (11:06 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 1 Nov 2017 04:35:57 +0000 (13:35 +0900)
 - Check my session type when setting client pid via attribute.
 - Simulate ASM conflict table of Tizen 2.4

[Version] 0.10.140
[Profile] Common
[Issue Type] Enhancement
[Dependency module] N/A

Change-Id: I9bac3a63bcc4360855f6444e6d3cf43c6c2ec638
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/libmm-camcorder.spec
src/mm_camcorder_attribute.c
src/mm_camcorder_internal.c

index b247996..fd300a2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.139
+Version:    0.10.140
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index c61cff0..c92fcc8 100644 (file)
@@ -4546,6 +4546,17 @@ bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx,
                        hcamcorder->sound_focus_register = FALSE;
                        _mmcam_dbg_warn("no need to use sound focus internally");
                } else {
                        hcamcorder->sound_focus_register = FALSE;
                        _mmcam_dbg_warn("no need to use sound focus internally");
                } else {
+                       /* check my session type : allow only media & call series here */
+                       if ((hcamcorder->session_type != MM_SESSION_TYPE_MEDIA) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_MEDIA_RECORD) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_CALL) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_VIDEOCALL) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_VOIP)) {
+                               _mmcam_dbg_err("Blocked by session policy, my session_type[%s]", hcamcorder->session_type);
+                               hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                               return FALSE;
+                       }
+
                        ret = mm_sound_focus_get_id(&hcamcorder->sound_focus_id);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_err("mm_sound_focus_get_id failed");
                        ret = mm_sound_focus_get_id(&hcamcorder->sound_focus_id);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_err("mm_sound_focus_get_id failed");
index d9daaaa..bb043d6 100644 (file)
@@ -74,6 +74,7 @@ static gint     __mmcamcorder_gst_handle_library_error(MMHandleType handle, int
 static gint     __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
 static gint     __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
 static gint     __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
 static gint     __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
+static int      __mmcamcorder_simulate_asm_conflict_table(int session_type, int pid);
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
 rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
 rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
@@ -865,9 +866,6 @@ int _mmcamcorder_realize(MMHandleType handle)
        int app_pid = 0;
        int resource_count = 0;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
        int app_pid = 0;
        int resource_count = 0;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
-       char *stream_type = NULL;
-       char *ext_info = NULL;
-       int option = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -914,6 +912,19 @@ int _mmcamcorder_realize(MMHandleType handle)
 
        /* sound focus */
        if (hcamcorder->sound_focus_register) {
 
        /* sound focus */
        if (hcamcorder->sound_focus_register) {
+               mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
+                       NULL);
+
+               if (pid_for_sound_focus == 0) {
+                       pid_for_sound_focus = getpid();
+                       _mmcam_dbg_warn("pid for sound focus is not set, use my pid %d", pid_for_sound_focus);
+               }
+
+               ret = __mmcamcorder_simulate_asm_conflict_table(hcamcorder->session_type, pid_for_sound_focus);
+               if (ret != MM_ERROR_NONE)
+                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+
                /* acquire sound focus or set sound focus watch callback */
                if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
                        /* acquire sound focus */
                /* acquire sound focus or set sound focus watch callback */
                if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
                        /* acquire sound focus */
@@ -932,37 +943,6 @@ int _mmcamcorder_realize(MMHandleType handle)
                        /* do nothing */
                        _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
                } else {
                        /* do nothing */
                        _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
                } else {
-                       /* check previous acquired focus */
-                       ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info);
-                       if (ret == MM_ERROR_NONE && stream_type) {
-                               if (!strcmp(stream_type, "alarm") ||
-                                       !strcmp(stream_type, "ringtone-voip") ||
-                                       !strcmp(stream_type, "ringtone-call") ||
-                                       !strcmp(stream_type, "voip") ||
-                                       !strcmp(stream_type, "call-voice") ||
-                                       !strcmp(stream_type, "call-video")) {
-                                       _mmcam_dbg_err("Blocked by session policy, stream_type [%s]", stream_type);
-                                       ret = MM_ERROR_POLICY_BLOCKED;
-                               }
-                       } else {
-                               _mmcam_dbg_warn("get stream type failed 0x%x, stream type %s, but ignore it",
-                                       ret, stream_type ? stream_type : "NULL");
-                               ret = MM_ERROR_NONE;
-                       }
-
-                       if (stream_type) {
-                               free(stream_type);
-                               stream_type = NULL;
-                       }
-
-                       if (ext_info) {
-                               free(ext_info);
-                               ext_info = NULL;
-                       }
-
-                       if (ret != MM_ERROR_NONE)
-                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
-
                        /* unset remained watch cb */
                        if (hcamcorder->sound_focus_watch_id > 0) {
                                mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
                        /* unset remained watch cb */
                        if (hcamcorder->sound_focus_watch_id > 0) {
                                mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
@@ -971,15 +951,6 @@ int _mmcamcorder_realize(MMHandleType handle)
                        }
 
                        /* set sound focus watch callback */
                        }
 
                        /* set sound focus watch callback */
-                       mm_camcorder_get_attributes(handle, NULL,
-                               MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
-                               NULL);
-
-                       if (pid_for_sound_focus == 0) {
-                               pid_for_sound_focus = getpid();
-                               _mmcam_dbg_warn("pid for sound focus is not set, use my pid %d", pid_for_sound_focus);
-                       }
-
                        _mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
 
                        ret_sound = mm_sound_set_focus_watch_callback_for_session(pid_for_sound_focus,
                        _mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
 
                        ret_sound = mm_sound_set_focus_watch_callback_for_session(pid_for_sound_focus,
@@ -4326,6 +4297,64 @@ static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMe
        return MM_ERROR_NONE;
 }
 
        return MM_ERROR_NONE;
 }
 
+/* Conditions below are from ASM conflict table of Tizen 2.4 */
+static int __mmcamcorder_simulate_asm_conflict_table(int session_type, int pid)
+{
+       int ret = MM_ERROR_NONE;
+       char *stream_type = NULL;
+       char *ext_info = NULL;
+       int option = 0;
+
+       /* check previous acquired focus of other PID */
+       ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info);
+       if (ret == MM_ERROR_NONE && stream_type) {
+               if (ext_info && (pid != atoi(ext_info))) { /* 'ext_info' should contain pid */
+                       if ((session_type == MM_SESSION_TYPE_CALL) ||
+                               (session_type == MM_SESSION_TYPE_VIDEOCALL) ||
+                               (session_type == MM_SESSION_TYPE_VOIP)) {
+                               /* case 1. if my session type is call/videocall/voip */
+                               if (!strcmp(stream_type, "call-voice") ||
+                                       !strcmp(stream_type, "call-video") ||
+                                       !strcmp(stream_type, "ringtone-call")) {
+                                       _mmcam_dbg_err("Blocked by session policy, stream_type[%s] of acquired focus", stream_type);
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                               }
+                       } else if ((session_type == MM_SESSION_TYPE_MEDIA) ||
+                               (session_type == MM_SESSION_TYPE_MEDIA_RECORD)) {
+                               /* case 2. if my session type is media */
+                               if (!strcmp(stream_type, "alarm") ||
+                                       !strcmp(stream_type, "ringtone-voip") ||
+                                       !strcmp(stream_type, "ringtone-call") ||
+                                       !strcmp(stream_type, "voip") ||
+                                       !strcmp(stream_type, "call-voice") ||
+                                       !strcmp(stream_type, "call-video")) {
+                                       _mmcam_dbg_err("Blocked by session policy, stream_type[%s] of acquired focus", stream_type);
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                               }
+                       }
+               } else {
+                       _mmcam_dbg_log("acquired focus is same process with it, skip it");
+               }
+       } else {
+               /* No data case */
+               _mmcam_dbg_warn("get stream type failed 0x%x, stream type %s, but ignore it",
+                       ret, stream_type ? stream_type : "NULL");
+               ret = MM_ERROR_NONE;
+       }
+
+       if (stream_type) {
+               free(stream_type);
+               stream_type = NULL;
+       }
+
+       if (ext_info) {
+               free(ext_info);
+               ext_info = NULL;
+       }
+
+       return ret;
+}
+
 
 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
        const char *interface_name, const char *signal_name, int value)
 
 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
        const char *interface_name, const char *signal_name, int value)