Release version 0.10.15
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index eaf78d2..37e41c9 100644 (file)
@@ -39,6 +39,9 @@
 #include <asm/types.h>
 
 #include <system_info.h>
+#include <mm_session.h>
+#include <mm_session_private.h>
+
 
 /*---------------------------------------------------------------------------------------
 |    GLOBAL VARIABLE DEFINITIONS for internal                                          |
@@ -55,9 +58,9 @@ struct sigaction mm_camcorder_sys_old_action;
 ---------------------------------------------------------------------------------------*/
 #define __MMCAMCORDER_CMD_ITERATE_MAX           3
 #define __MMCAMCORDER_SET_GST_STATE_TIMEOUT     3
+#define __MMCAMCORDER_FORCE_STOP_TRY_COUNT      30
+#define __MMCAMCORDER_FORCE_STOP_WAIT_TIME      100000  /* us */
 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT        3
-#define __MMCAMCORDER_PATH_CAMERA_RESOURCE      "/usr/share/sounds/mm-camcorder/camera_resource"
-#define __MMCAMCORDER_PATH_RECORDER_RESOURCE    "/usr/share/sounds/mm-camcorder/recorder_resource"
 
 
 /*---------------------------------------------------------------------------------------
@@ -74,7 +77,6 @@ static gint     __mmcamcorder_gst_handle_core_error(MMHandleType handle, int cod
 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);
 
-
 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
@@ -197,7 +199,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        int camera_device_count = MM_VIDEO_DEVICE_NUM;
        int camera_default_flip = MM_FLIP_NONE;
        int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
-       int resource_fd = -1;
        char *err_attr_name = NULL;
        const char *ConfCtrlFile = NULL;
        mmf_camcorder_t *hcamcorder = NULL;
@@ -219,6 +220,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        hcamcorder->sub_context = NULL;
        hcamcorder->target_state = MM_CAMCORDER_STATE_NULL;
        hcamcorder->capture_in_recording = FALSE;
+       hcamcorder->session_type = MM_SESSION_TYPE_MEDIA;
 
        pthread_mutex_init(&((hcamcorder->mtsafe).lock), NULL);
        pthread_cond_init(&((hcamcorder->mtsafe).cond), NULL);
@@ -248,12 +250,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        /* create task thread */
        pthread_create(&(hcamcorder->task_thread), NULL, _mmcamcorder_util_task_thread_func, (void *)hcamcorder);
 
-       /* get root directory */
-       ret = _mmcamcorder_get_root_directory(&hcamcorder->root_directory);
-       if (ret != MM_ERROR_NONE) {
-               goto _ERR_DEFAULT_VALUE_INIT;
-       }
-
        if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
            info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
                _mmcam_dbg_err("_mmcamcorder_create::video device type is out of range.");
@@ -265,24 +261,31 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        hcamcorder->device_type = info->videodev_type;
        _mmcam_dbg_warn("Device Type : %d", hcamcorder->device_type);
 
-       if (hcamcorder->device_type == MM_VIDEO_DEVICE_NONE) {
-               resource_fd = open(__MMCAMCORDER_PATH_RECORDER_RESOURCE, O_RDONLY);
-       } else {
-               resource_fd = open(__MMCAMCORDER_PATH_CAMERA_RESOURCE, O_RDONLY);
-       }
+       if (MM_ERROR_NONE == _mm_session_util_read_information(-1, &hcamcorder->session_type, &hcamcorder->session_flags)) {
+               _mmcam_dbg_log("use sound focus function.");
+               hcamcorder->sound_focus_register = TRUE;
 
-       if (resource_fd < 0) {
-               _mmcam_dbg_log("open error %s : cur %d",strerror(errno),errno);
-               if(errno == EPERM || errno == EACCES) {
-                       ret = MM_ERROR_COMMON_INVALID_PERMISSION;
-               } else {
-                       ret = MM_ERROR_CAMCORDER_INTERNAL;
+               if (MM_ERROR_NONE != mm_sound_focus_get_id(&hcamcorder->sound_focus_id)) {
+                       _mmcam_dbg_err("mm_sound_focus_get_uniq failed");
+                       ret = MM_ERROR_POLICY_BLOCKED;
+                       goto _ERR_DEFAULT_VALUE_INIT;
                }
-               goto _ERR_DEFAULT_VALUE_INIT;
+
+               if (MM_ERROR_NONE != mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
+                                                                        getpid(),
+                                                                        "media",
+                                                                        _mmcamcorder_sound_focus_cb,
+                                                                        hcamcorder)) {
+                       _mmcam_dbg_err("mm_sound_register_focus failed");
+                       ret = MM_ERROR_POLICY_BLOCKED;
+                       goto _ERR_DEFAULT_VALUE_INIT;
+               }
+
+               _mmcam_dbg_log("mm_sound_register_focus done - id %d, session type %d, flags 0x%x",
+                              hcamcorder->sound_focus_id, hcamcorder->session_type, hcamcorder->session_flags);
        } else {
-               close(resource_fd);
-               resource_fd = -1;
-               _mmcam_dbg_warn("permission check done");
+               _mmcam_dbg_log("_mm_session_util_read_information failed. skip sound focus function.");
+               hcamcorder->sound_focus_register = FALSE;
        }
 
        /* Get Camera Configure information from Camcorder INI file */
@@ -292,7 +295,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                _mmcam_dbg_err( "Failed to get configure(main) info." );
 
                ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
-               goto _ERR_AFTER_ASM_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        hcamcorder->attributes = _mmcamcorder_alloc_attribute((MMHandleType)hcamcorder, info);
@@ -300,7 +303,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                _mmcam_dbg_err("_mmcamcorder_create::alloc attribute error.");
 
                ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-               goto _ERR_AFTER_ASM_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
@@ -329,7 +332,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                        default:
                                _mmcam_dbg_err( "Not supported camera type." );
                                ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        _mmcam_dbg_log("videodev_type : [%d], ConfCtrlPath : [%s]", info->videodev_type, ConfCtrlFile);
@@ -342,21 +345,21 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                        if (!(hcamcorder->conf_ctrl)) {
                                _mmcam_dbg_err( "Failed to get configure(control) info." );
                                ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_warn("converting table initialize error!!");
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, info->videodev_type);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_warn("converting table initialize error!!");
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        /* Get device info, recommend preview fmt and display rotation from INI */
@@ -455,7 +458,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                free(err_attr_name);
                                err_attr_name = NULL;
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        /* Get default value of brightness */
@@ -467,7 +470,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                free(err_attr_name);
                                err_attr_name = NULL;
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_AFTER_ASM_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
                        _mmcam_dbg_log("Default brightness : %d", hcamcorder->brightness_default);
                } else {
@@ -487,14 +490,14 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                        free(err_attr_name);
                        err_attr_name = NULL;
                        ret = MM_ERROR_CAMCORDER_INTERNAL;
-                       goto _ERR_AFTER_ASM_REGISTER;
+                       goto _ERR_DEFAULT_VALUE_INIT;
                }
 
                ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, info->videodev_type);
                if (ret != MM_ERROR_NONE) {
                        _mmcam_dbg_warn("init attribute from configure error : 0x%x", ret);
                        ret = MM_ERROR_CAMCORDER_INTERNAL;
-                       goto _ERR_AFTER_ASM_REGISTER;
+                       goto _ERR_DEFAULT_VALUE_INIT;
                }
        }
 
@@ -502,7 +505,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        if (!ret) {
                _mmcam_dbg_err( "Failed to initialize gstreamer!!" );
                ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
-               goto _ERR_AFTER_ASM_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        /* Make some attributes as read-only type */
@@ -563,9 +566,25 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 
        return MM_ERROR_NONE;
 
-_ERR_AFTER_ASM_REGISTER:
-
 _ERR_DEFAULT_VALUE_INIT:
+       /* unregister sound focus */
+       if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
+               if (MM_ERROR_NONE != mm_sound_unregister_focus(hcamcorder->sound_focus_id)) {
+                       _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed", hcamcorder->sound_focus_id);
+               } else {
+                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done", hcamcorder->sound_focus_id);
+               }
+       } else {
+               _mmcam_dbg_warn("no need to unregister sound focus[%d, id %d]",
+                              hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
+       }
+
+       /* Remove attributes */
+       if (hcamcorder->attributes) {
+               _mmcamcorder_dealloc_attribute((MMHandleType)hcamcorder, hcamcorder->attributes);
+               hcamcorder->attributes = 0;
+       }
+
        /* Release lock, cond */
        pthread_mutex_destroy(&((hcamcorder->mtsafe).lock));
        pthread_cond_destroy(&((hcamcorder->mtsafe).cond));
@@ -614,11 +633,6 @@ _ERR_DEFAULT_VALUE_INIT:
        pthread_mutex_destroy(&(hcamcorder->task_thread_lock));
        pthread_cond_destroy(&(hcamcorder->task_thread_cond));
 
-       if (hcamcorder->root_directory) {
-               free(hcamcorder->root_directory);
-               hcamcorder->root_directory = NULL;
-       }
-
        /* Release handle */
        memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
        free(hcamcorder);
@@ -749,6 +763,20 @@ int _mmcamcorder_destroy(MMHandleType handle)
        /* Remove messages which are not called yet */
        _mmcamcorder_remove_message_all(handle);
 
+       /* unregister sound focus */
+       if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
+               if (mm_sound_unregister_focus(hcamcorder->sound_focus_id) != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed",
+                                      hcamcorder->sound_focus_id);
+               } else {
+                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done",
+                                      hcamcorder->sound_focus_id);
+               }
+       } else {
+               _mmcam_dbg_log("no need to unregister sound focus.[%d, id %d]",
+                              hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
+       }
+
        /* release model_name */
        if (hcamcorder->model_name) {
                free(hcamcorder->model_name);
@@ -787,12 +815,6 @@ int _mmcamcorder_destroy(MMHandleType handle)
        pthread_mutex_destroy(&(hcamcorder->task_thread_lock));
        pthread_cond_destroy(&(hcamcorder->task_thread_cond));
 
-       /* Release internal root directory string */
-       if (hcamcorder->root_directory) {
-               free(hcamcorder->root_directory);
-               hcamcorder->root_directory = NULL;
-       }
-
        /* Release handle */
        memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
        free(hcamcorder);
@@ -816,13 +838,17 @@ _ERR_CAMCORDER_CMD_PRECON:
 int _mmcamcorder_realize(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
+       int ret_sound = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
        int state_FROM = MM_CAMCORDER_STATE_NULL;
        int state_TO = MM_CAMCORDER_STATE_READY;
        int display_surface_type = MM_DISPLAY_SURFACE_X;
+       int pid_for_sound_focus = 0;
        double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
        char *videosink_element_type = NULL;
        const char *videosink_name = NULL;
+       char *socket_path = NULL;
+       int socket_path_len;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -857,6 +883,7 @@ int _mmcamcorder_realize(MMHandleType handle)
        mm_camcorder_get_attributes(handle, NULL,
                                    MMCAM_DISPLAY_SURFACE, &display_surface_type,
                                    MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
+                                   MMCAM_DISPLAY_SHM_SOCKET_PATH, &socket_path, &socket_path_len,
                                    NULL);
 
        /* set camera/recorder state to vconf key */
@@ -891,6 +918,63 @@ int _mmcamcorder_realize(MMHandleType handle)
                               vconf_recorder_state, VCONFKEY_RECORDER_STATE_CREATED);
        }
 
+       /* 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);
+               }
+
+               /* acquire sound focus or set sound focus watch callback */
+               hcamcorder->acquired_focus = 0;
+               hcamcorder->sound_focus_watch_id = 0;
+
+               /* check session flags */
+               if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
+                       /* acquire sound focus */
+                       _mmcam_dbg_log("PAUSE_OTHERS - acquire sound focus");
+
+                       ret_sound = mm_sound_acquire_focus(0, FOCUS_FOR_BOTH, NULL);
+                       if (ret_sound != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("mm_sound_acquire_focus failed [0x%x]", ret_sound);
+
+                               /* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
+                               ret = MM_ERROR_POLICY_BLOCKED;
+                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+                       }
+
+                       hcamcorder->acquired_focus = FOCUS_FOR_BOTH;
+               } else if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
+                       /* do nothing */
+                       _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
+               } else {
+                       /* set sound focus watch callback */
+                       _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,
+                                                                                 FOCUS_FOR_BOTH,
+                                                                                 (mm_sound_focus_changed_watch_cb)_mmcamcorder_sound_focus_watch_cb,
+                                                                                 hcamcorder,
+                                                                                 &hcamcorder->sound_focus_watch_id);
+                       if (ret_sound != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("mm_sound_set_focus_watch_callback failed [0x%x]", ret_sound);
+
+                               /* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
+                               ret = MM_ERROR_POLICY_BLOCKED;
+                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+                       }
+
+                       _mmcam_dbg_log("sound focus watch cb id %d", hcamcorder->sound_focus_watch_id);
+               }
+       } else {
+               _mmcam_dbg_log("no need to register sound focus");
+       }
+
+
        /* alloc sub context */
        hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
        if(!hcamcorder->sub_context) {
@@ -936,6 +1020,11 @@ int _mmcamcorder_realize(MMHandleType handle)
                break;
        }
 
+       if (socket_path == NULL) {
+               _mmcam_dbg_warn("Socket Path is not properly set, -> to NullSink.");
+               videosink_element_type = strdup("VideosinkElementNull");
+       }
+
        /* check string of videosink element */
        if (videosink_element_type) {
                _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
@@ -1024,6 +1113,28 @@ _ERR_CAMCORDER_CMD:
 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
+       if (hcamcorder->sound_focus_register) {
+               if (hcamcorder->sound_focus_watch_id > 0) {
+                       if (mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id) != MM_ERROR_NONE) {
+                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] failed",
+                                               hcamcorder->sound_focus_watch_id);
+                       } else {
+                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] done",
+                                               hcamcorder->sound_focus_watch_id);
+                       }
+               }
+
+               if (hcamcorder->acquired_focus > 0) {
+                               if (mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL) != MM_ERROR_NONE) {
+                                       _mmcam_dbg_err("mm_sound_release_focus[focus %d] failed",
+                                                      hcamcorder->acquired_focus);
+                               } else {
+                                       _mmcam_dbg_err("mm_sound_release_focus[focus %d] done",
+                                                      hcamcorder->acquired_focus);
+                               }
+               }
+       }
+
 _ERR_CAMCORDER_CMD_PRECON:
        _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)",
                       hcamcorder->type, state, ret);
@@ -1074,6 +1185,44 @@ int _mmcamcorder_unrealize(MMHandleType handle)
        /* Deinitialize main context member */
        hcamcorder->command = NULL;
 
+       _mmcam_dbg_log("focus register %d, session flag 0x%x, state_change_by_system %d",
+                      hcamcorder->sound_focus_register, hcamcorder->session_flags, hcamcorder->state_change_by_system);
+
+       /* release sound focus or unset sound focus watch callback */
+       if (hcamcorder->sound_focus_register) {
+               int ret_sound = MM_ERROR_NONE;
+
+               _mmcam_dbg_log("state_change_by_system %d, session flag 0x%x, acquired_focus %d, sound_focus_id %d, sound_focus_watch_id %d",
+                              hcamcorder->state_change_by_system, hcamcorder->session_flags, hcamcorder->acquired_focus,
+                              hcamcorder->sound_focus_id, hcamcorder->sound_focus_watch_id);
+
+               if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM &&
+                   hcamcorder->sound_focus_watch_id > 0) {
+                       ret_sound = mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+                       if (ret_sound != MM_ERROR_NONE) {
+                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback failed [0x%x]",
+                                               ret_sound);
+                       } else {
+                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback done");
+                       }
+               } else {
+                       _mmcam_dbg_warn("no need to unset watch callback.[state_change_by_system %d, sound_focus_watch_id %d]",
+                                       hcamcorder->state_change_by_system, hcamcorder->sound_focus_watch_id);
+               }
+
+               if (hcamcorder->acquired_focus > 0) {
+                       ret_sound = mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL);
+                       if (ret_sound != MM_ERROR_NONE) {
+                               _mmcam_dbg_warn("mm_sound_release_focus failed [0x%x]",
+                                               ret_sound);
+                       } else {
+                               _mmcam_dbg_log("mm_sound_release_focus done");
+                       }
+               } else {
+                       _mmcam_dbg_warn("no need to release focus - current acquired focus %d",
+                                       hcamcorder->acquired_focus);
+               }
+       }
 
        /* set camera state to vconf key */
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
@@ -2936,6 +3085,125 @@ GstBusSyncReply _mmcamcorder_audio_pipeline_bus_sync_callback(GstBus *bus, GstMe
 }
 
 
+void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
+                                 mm_sound_focus_state_e focus_state, const char *reason_for_change,
+                                 const char *additional_info, void *user_data)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
+       int current_state = MM_CAMCORDER_STATE_NONE;
+
+       mmf_return_if_fail((MMHandleType)hcamcorder);
+
+       current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
+       if (current_state <= MM_CAMCORDER_STATE_NONE ||
+           current_state >= MM_CAMCORDER_STATE_NUM) {
+               _mmcam_dbg_err("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
+               return;
+       }
+
+       /* set value to inform a status is changed by asm */
+       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_ASM;
+
+       _mmcam_dbg_log("sound focus callback : focus state %d, reason %s",
+                      focus_state, reason_for_change ? reason_for_change : "N/A");
+
+       if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
+               _mmcam_dbg_warn("session flag is UNINTERRUPTIBLE. do nothing.");
+               return;
+       }
+
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+
+       if (focus_state == FOCUS_IS_RELEASED) {
+               hcamcorder->acquired_focus &= ~focus_type;
+
+               _mmcam_dbg_log("FOCUS is released [type %d, remained focus %d] : Stop pipeline[state:%d]",
+                              focus_type, hcamcorder->acquired_focus, current_state);
+
+               __mmcamcorder_force_stop(hcamcorder);
+
+               _mmcam_dbg_log("Finish opeartion. Pipeline is released");
+       } else if (focus_state == FOCUS_IS_ACQUIRED) {
+               _MMCamcorderMsgItem msg;
+
+               hcamcorder->acquired_focus |= focus_type;
+
+               _mmcam_dbg_log("FOCUS is acquired [type %d, new focus %d]",
+                              focus_type, hcamcorder->acquired_focus);
+
+               msg.id = MM_MESSAGE_READY_TO_RESUME;
+               _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
+
+               _mmcam_dbg_log("Finish opeartion");
+       } else {
+               _mmcam_dbg_log("unknown focus state %d", focus_state);
+       }
+
+       /* restore value */
+       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
+
+       _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+       return;
+}
+
+
+void _mmcamcorder_sound_focus_watch_cb(mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
+                                       const char *reason_for_change, const char *additional_info, void *user_data)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
+       int current_state = MM_CAMCORDER_STATE_NONE;
+
+       mmf_return_if_fail((MMHandleType)hcamcorder);
+
+       current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
+       if (current_state <= MM_CAMCORDER_STATE_NONE ||
+           current_state >= MM_CAMCORDER_STATE_NUM) {
+               _mmcam_dbg_err("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
+               return;
+       }
+
+       /* set value to inform a status is changed by asm */
+       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_ASM;
+
+       _mmcam_dbg_log("sound focus watch callback : focus state %d, reason %s",
+                      focus_state, reason_for_change ? reason_for_change : "N/A");
+
+       if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
+               _mmcam_dbg_warn("session flag is UNINTERRUPTIBLE. do nothing.");
+               return;
+       }
+
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+
+       if (focus_state == FOCUS_IS_RELEASED) {
+               _MMCamcorderMsgItem msg;
+
+               _mmcam_dbg_log("other process's FOCUS is acquired");
+
+               msg.id = MM_MESSAGE_READY_TO_RESUME;
+               _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
+
+               _mmcam_dbg_log("Finish opeartion");
+       } else if (focus_state == FOCUS_IS_ACQUIRED) {
+               _mmcam_dbg_log("other process's FOCUS is released : Stop pipeline[state:%d]", current_state);
+
+               __mmcamcorder_force_stop(hcamcorder);
+
+               _mmcam_dbg_log("Finish opeartion. Pipeline is released");
+       } else {
+               _mmcam_dbg_log("unknown focus state %d", focus_state);
+       }
+
+       /* restore value */
+       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
+
+       _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+       return;
+}
+
+
 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
 {
        int ret = MM_ERROR_NONE;
@@ -3219,6 +3487,112 @@ void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
 }
 
 
+void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
+{
+       int i = 0;
+       int loop = 0;
+       int itr_cnt = 0;
+       int result = MM_ERROR_NONE;
+       int cmd_try_count = 0;
+       int current_state = MM_CAMCORDER_STATE_NONE;
+
+       mmf_return_if_fail(hcamcorder);
+
+       /* check command running */
+       do {
+               if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
+                       if (cmd_try_count++ < __MMCAMCORDER_FORCE_STOP_TRY_COUNT) {
+                               _mmcam_dbg_warn("Another command is running. try again after %d ms", __MMCAMCORDER_FORCE_STOP_WAIT_TIME/1000);
+                               usleep(__MMCAMCORDER_FORCE_STOP_WAIT_TIME);
+                       } else {
+                               _mmcam_dbg_err("wait timeout");
+                               break;
+                       }
+               } else {
+                       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+                       break;
+               }
+       } while (TRUE);
+
+       current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
+
+       _mmcam_dbg_warn("Force STOP MMFW Camcorder");
+
+       for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
+               itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
+               switch (current_state) {
+               case MM_CAMCORDER_STATE_CAPTURING:
+               {
+                       _MMCamcorderSubContext *sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
+                       _MMCamcorderImageInfo *info = NULL;
+
+                       mmf_return_if_fail(sc);
+                       mmf_return_if_fail((info = sc->info_image));
+
+                       _mmcam_dbg_warn("Stop capturing.");
+
+                       /* if caturing isn't finished, waiting for 2 sec to finish real capture operation. check 'info->capturing'. */
+                       mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
+                                                   MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, TRUE,
+                                                   NULL);
+
+                       for (i = 0; i < 20 && info->capturing; i++) {
+                               usleep(100000);
+                       }
+
+                       if (i == 20) {
+                               _mmcam_dbg_err("Timeout. Can't check stop capturing.");
+                       }
+
+                       while ((itr_cnt--) && ((result = _mmcamcorder_capture_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
+                                       _mmcam_dbg_warn("Can't stop capturing.(%x)", result);
+                       }
+
+                       break;
+               }
+               case MM_CAMCORDER_STATE_RECORDING:
+               case MM_CAMCORDER_STATE_PAUSED:
+               {
+                       _mmcam_dbg_warn("Stop recording.");
+
+                       while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
+                               _mmcam_dbg_warn("Can't commit.(%x)", result);
+                       }
+                       break;
+               }
+               case MM_CAMCORDER_STATE_PREPARE:
+               {
+                       _mmcam_dbg_warn("Stop preview.");
+
+                       while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
+                               _mmcam_dbg_warn("Can't stop preview.(%x)", result);
+                       }
+                       break;
+               }
+               case MM_CAMCORDER_STATE_READY:
+               {
+                       _mmcam_dbg_warn("unrealize");
+
+                       if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE) {
+                               _mmcam_dbg_warn("Can't unrealize.(%x)", result);
+                       }
+                       break;
+               }
+               case MM_CAMCORDER_STATE_NULL:
+               default:
+                       _mmcam_dbg_warn("Already stopped.");
+                       break;
+               }
+
+               current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
+       }
+
+       _mmcam_dbg_warn( "Done." );
+
+       return;
+}
+
+
 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -3576,3 +3950,31 @@ static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMe
 
        return MM_ERROR_NONE;
 }
+
+int _mmcamcorder_get_video_caps(MMHandleType handle, char **caps)
+{
+       GstPad *pad = NULL;
+       GstCaps *sink_caps = NULL;
+       _MMCamcorderSubContext *sc = NULL;
+
+       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
+       _mmcam_dbg_warn("Entered ");
+       pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "sink");
+       if(!pad) {
+               _mmcam_dbg_err("static pad is NULL");
+               return MM_ERROR_CAMCORDER_INVALID_STATE;
+       }
+
+       sink_caps = gst_pad_get_current_caps(pad);
+       gst_object_unref( pad );
+       if(!sink_caps) {
+               _mmcam_dbg_err("fail to get caps");
+               return MM_ERROR_CAMCORDER_INVALID_STATE;
+       }
+
+       *caps = gst_caps_to_string(sink_caps);
+       _mmcam_dbg_err("video caps : %s", *caps);
+       gst_caps_unref(sink_caps);
+
+       return MM_ERROR_NONE;
+}
\ No newline at end of file