Update code for sound focus APIs 71/47971/2 accepted/tizen/common/20160108.084016 accepted/tizen/mobile/20150918.024636 accepted/tizen/tv/20150918.024653 accepted/tizen/wearable/20150918.024707 submit/tizen/20150917.021316 submit/tizen/20150917.064134 submit/tizen_common/20160104.190333
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 10 Sep 2015 10:59:36 +0000 (19:59 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 16 Sep 2015 02:41:05 +0000 (11:41 +0900)
Change-Id: I42e19987c055e3700aed88b583e7922cee6fa4d4
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/libmm-camcorder.spec
src/include/mm_camcorder.h
src/include/mm_camcorder_attribute.h
src/include/mm_camcorder_internal.h
src/mm_camcorder_attribute.c
src/mm_camcorder_internal.c

index 36c160043bdf9e2440209ff535ad59125592b6e7..b36bdd7a9cec537b16062b20fcd9f586df33a2af 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.8
+Version:    0.10.9
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 788ab3ccafd40ae0ba721a101e47d0db29b13dfa..d1e188a3676c590284d7322edf9ae32d823a9f16 100644 (file)
@@ -1232,6 +1232,11 @@ extern "C" {
  */
 #define MMCAM_DISPLAY_SHM_SOCKET_PATH          "display-shm-socket-path"
 
+/**
+ * PID for sound focus
+ */
+#define MMCAM_PID_FOR_SOUND_FOCUS               "pid-for-sound-focus"
+
 
 /*=======================================================================================
 | ENUM DEFINITIONS                                                                     |
index 231f73cdcc9b50602a6769fb4d7336830ff954a8..b25db493f14db72d7ed5bf7481e995da430e75c2 100644 (file)
@@ -173,6 +173,7 @@ typedef enum
        MM_CAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB,
        MM_CAM_RECORDER_TAG_ENABLE,
        MM_CAM_DISPLAY_SHM_SOCKET_PATH,
+       MM_CAM_PID_FOR_SOUND_FOCUS,
        MM_CAM_ATTRIBUTE_NUM
 }MMCamcorderAttrsID;
 
@@ -364,6 +365,7 @@ bool _mmcamcorder_commit_strobe(MMHandleType handle, int attr_idx, const mmf_val
 bool _mmcamcorder_commit_detect(MMHandleType handle, int attr_idx, const mmf_value_t *value);
 bool _mmcamcorder_commit_camera_flip(MMHandleType handle, int attr_idx, const mmf_value_t *value);
 bool _mmcamcorder_commit_camera_hdr_capture(MMHandleType handle, int attr_idx, const mmf_value_t *value);
+bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx, const mmf_value_t *value);
 
 /**
  * This function initialize effect setting.
index 7a22041d0c7c3d9dc8716e25b1ae2efcca3a9507..58f06774ebc43820855face7b4772f689286c325 100644 (file)
@@ -35,6 +35,7 @@
 #include <mm_attrs.h>
 #include <mm_attrs_private.h>
 #include <mm_message.h>
+#include <mm_sound_focus.h>
 #include <sndfile.h>
 #include <vconf.h>
 #include <gst/video/video-format.h>
@@ -1160,6 +1161,14 @@ void _mmcamcorder_video_current_framerate_init(MMHandleType handle);
 int _mmcamcorder_video_current_framerate(MMHandleType handle);
 int _mmcamcorder_video_average_framerate(MMHandleType handle);
 
+/* sound focus related function */
+void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder);
+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);
+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);
+
 #ifdef __cplusplus
 }
 #endif
index e9014f854392de2da05d29723b0c9bcf52abe703..bfd00ae1c859a264ca58c6e057be304ff79cbe12 100644 (file)
@@ -1432,6 +1432,17 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        {0},
                        {0},
                        NULL,
+               },
+               {
+                       MM_CAM_PID_FOR_SOUND_FOCUS,
+                       "pid-for-sound-focus",
+                       MMF_VALUE_TYPE_INT,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)0},
+                       MM_ATTRS_VALID_TYPE_INT_RANGE,
+                       {.int_min = 0},
+                       {.int_max = _MMCAMCORDER_MAX_INT},
+                       _mmcamcorder_commit_pid_for_sound_focus,
                }
        };
 
@@ -3967,6 +3978,83 @@ bool _mmcamcorder_commit_detect(MMHandleType handle, int attr_idx, const mmf_val
 }
 
 
+bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx, const mmf_value_t *value)
+{
+       bool bret = FALSE;
+       int pid_current = 0;
+       int pid_new = 0;
+       int current_state = MM_CAMCORDER_STATE_NONE;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       if (hcamcorder == NULL) {
+               _mmcam_dbg_warn("handle is NULL");
+               return FALSE;
+       }
+
+       /* state check */
+       current_state = _mmcamcorder_get_state( handle);
+       if (current_state > MM_CAMCORDER_STATE_NULL) {
+               _mmcam_dbg_log("invalid state %d", current_state);
+               return FALSE;
+       }
+
+       pid_new = value->value.i_val;
+
+       mm_camcorder_get_attributes(handle, NULL,
+                                   MMCAM_PID_FOR_SOUND_FOCUS, &pid_current,
+                                   NULL);
+
+       _mmcam_dbg_log("Commit : pid_for_sound_focus - pid new %dm current %d", pid_new, pid_current);
+
+       /* unregister sound focus before set new one */
+       if (pid_current > 0) {
+               if (hcamcorder->sound_focus_register) {
+                       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_log("no need to unregister sound focus");
+               }
+       }
+
+       /* register sound focus */
+       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;
+       } else {
+               _mmcam_dbg_log("_mm_session_util_read_information failed. skip sound focus function.");
+               hcamcorder->sound_focus_register = FALSE;
+       }
+
+       if (hcamcorder->sound_focus_register) {
+               if (MM_ERROR_NONE != mm_sound_focus_get_id(&hcamcorder->sound_focus_id)) {
+                       _mmcam_dbg_err("mm_sound_focus_get_uniq failed");
+                       hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                       return FALSE;
+               }
+
+               if (MM_ERROR_NONE != mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
+                                                                        pid_new,
+                                                                        "media",
+                                                                        _mmcamcorder_sound_focus_cb,
+                                                                        hcamcorder)) {
+                       _mmcam_dbg_err("mm_sound_register_focus failed");
+                       hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                       return FALSE;
+               }
+
+               _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 {
+               _mmcam_dbg_log("no need to register sound focus");
+       }
+
+       return TRUE;
+}
+
+
 static bool
 __mmcamcorder_attrs_is_supported(MMHandleType handle, int idx)
 {
index 0a3b103ddc821d05b24acde2cebbe5999fce8f04..2ea5b752770d496b180786dee09926a6188dba24 100644 (file)
@@ -41,7 +41,6 @@
 #include <system_info.h>
 #include <mm_session.h>
 #include <mm_session_private.h>
-#include <mm_sound_focus.h>
 
 #include <cynara-client.h>
 
@@ -81,15 +80,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);
 
-/* sound focus related function */
-static void     __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder);
-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);
-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);
-
-
 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
@@ -212,7 +202,9 @@ 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;
+#if 0
        int resource_fd = -1;
+#endif
        char *err_attr_name = NULL;
        const char *ConfCtrlFile = NULL;
        mmf_camcorder_t *hcamcorder = NULL;
@@ -367,33 +359,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        }
 #endif
 
-       /* Check session */
-       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;
-       } else {
-               _mmcam_dbg_log("_mm_session_util_read_information failed. skip sound focus function.");
-               hcamcorder->sound_focus_register = FALSE;
-       }
-
-       /* register sound focus */
-       if (hcamcorder->sound_focus_register) {
-               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;
-               }
-
-               if (MM_ERROR_NONE != mm_sound_register_focus_for_session(hcamcorder->sound_focus_id, "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);
-       }
-
        /* Get Camera Configure information from Camcorder INI file */
        _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
 
@@ -401,7 +366,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_SOUND_FOCUS_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        hcamcorder->attributes = _mmcamcorder_alloc_attribute((MMHandleType)hcamcorder, info);
@@ -409,7 +374,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                _mmcam_dbg_err("_mmcamcorder_create::alloc attribute error.");
 
                ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-               goto _ERR_SOUND_FOCUS_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
@@ -438,7 +403,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                        default:
                                _mmcam_dbg_err( "Not supported camera type." );
                                ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
-                               goto _ERR_SOUND_FOCUS_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        _mmcam_dbg_log("videodev_type : [%d], ConfCtrlPath : [%s]", info->videodev_type, ConfCtrlFile);
@@ -451,21 +416,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_SOUND_FOCUS_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_SOUND_FOCUS_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_SOUND_FOCUS_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        /* Get device info, recommend preview fmt and display rotation from INI */
@@ -564,7 +529,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                free(err_attr_name);
                                err_attr_name = NULL;
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_SOUND_FOCUS_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
                        /* Get default value of brightness */
@@ -576,7 +541,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                free(err_attr_name);
                                err_attr_name = NULL;
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
-                               goto _ERR_SOUND_FOCUS_REGISTER;
+                               goto _ERR_DEFAULT_VALUE_INIT;
                        }
                        _mmcam_dbg_log("Default brightness : %d", hcamcorder->brightness_default);
                } else {
@@ -596,14 +561,14 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                        free(err_attr_name);
                        err_attr_name = NULL;
                        ret = MM_ERROR_CAMCORDER_INTERNAL;
-                       goto _ERR_SOUND_FOCUS_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_SOUND_FOCUS_REGISTER;
+                       goto _ERR_DEFAULT_VALUE_INIT;
                }
        }
 
@@ -611,7 +576,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_SOUND_FOCUS_REGISTER;
+               goto _ERR_DEFAULT_VALUE_INIT;
        }
 
        /* Make some attributes as read-only type */
@@ -672,14 +637,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 
        return MM_ERROR_NONE;
 
-_ERR_SOUND_FOCUS_REGISTER:
-       /* unregister sound focus */
-       if(hcamcorder->sound_focus_register) {
-               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);
-               }
-       }
-
 _ERR_DEFAULT_VALUE_INIT:
        /* Remove attributes */
        if (hcamcorder->attributes) {
@@ -949,6 +906,7 @@ int _mmcamcorder_realize(MMHandleType handle)
        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;
@@ -986,6 +944,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_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
                                    NULL);
 
        /* set camera/recorder state to vconf key */
@@ -1041,12 +1000,18 @@ int _mmcamcorder_realize(MMHandleType handle)
                        _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");
+                       if (pid_for_sound_focus == 0) {
+                               _mmcam_dbg_warn("pid for sound focus is not set, so call getpid");
+                               pid_for_sound_focus = getpid();
+                       }
+
+                       _mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
 
-                       ret_sound = mm_sound_set_focus_watch_callback(FOCUS_FOR_BOTH,
-                                                                     (mm_sound_focus_changed_watch_cb)_mmcamcorder_sound_focus_watch_cb,
-                                                                     hcamcorder,
-                                                                     &hcamcorder->sound_focus_watch_id);
+                       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);
 
@@ -3545,7 +3510,7 @@ void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
 }
 
 
-static void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
+void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
 {
        int i = 0;
        int loop = 0;