[libmm-camcorder] g_free and g_printf function fixes
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_attribute.c
index bfd00ae..409aba4 100644 (file)
@@ -38,6 +38,8 @@
 -----------------------------------------------------------------------*/
 #define MMCAMCORDER_DEFAULT_CAMERA_WIDTH        640
 #define MMCAMCORDER_DEFAULT_CAMERA_HEIGHT       480
+#define MMCAMCORDER_DEFAULT_ENCODED_PREVIEW_BITRATE (1024*1024*10)
+#define MMCAMCORDER_DEFAULT_ENCODED_PREVIEW_GOP_INTERVAL 1000
 
 /*---------------------------------------------------------------------------------------
 |    GLOBAL VARIABLE DEFINITIONS for internal                                          |
@@ -388,7 +390,7 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        {(void*)1},
                        MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
                        {.double_min = 0.0},
-                       {.double_max = _MMCAMCORDER_MAX_INT},
+                       {.double_max = _MMCAMCORDER_MAX_DOUBLE},
                        _mmcamcorder_commit_camera_recording_motion_rate,
                },
                {
@@ -696,7 +698,7 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        "display-surface",
                        MMF_VALUE_TYPE_INT,
                        MM_ATTRS_FLAG_RW,
-                       {(void*)MM_DISPLAY_SURFACE_X},
+                       {(void*)MM_DISPLAY_SURFACE_OVERLAY},
                        MM_ATTRS_VALID_TYPE_INT_ARRAY,
                        {0},
                        {0},
@@ -1412,6 +1414,28 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        NULL,
                },
                {
+                       MM_CAM_ENCODED_PREVIEW_BITRATE,
+                       "encoded-preview-bitrate",
+                       MMF_VALUE_TYPE_INT,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)MMCAMCORDER_DEFAULT_ENCODED_PREVIEW_BITRATE},
+                       MM_ATTRS_VALID_TYPE_INT_RANGE,
+                       {.int_min = 0},
+                       {.int_max = _MMCAMCORDER_MAX_INT},
+                       _mmcamcorder_commit_encoded_preview_bitrate,
+               },
+               {
+                       MM_CAM_ENCODED_PREVIEW_GOP_INTERVAL,
+                       "encoded-preview-gop-interval",
+                       MMF_VALUE_TYPE_INT,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)MMCAMCORDER_DEFAULT_ENCODED_PREVIEW_GOP_INTERVAL},
+                       MM_ATTRS_VALID_TYPE_INT_RANGE,
+                       {.int_min = 0},
+                       {.int_max = _MMCAMCORDER_MAX_INT},
+                       _mmcamcorder_commit_encoded_preview_gop_interval,
+               },
+               {
                        MM_CAM_RECORDER_TAG_ENABLE,
                        "recorder-tag-enable",
                        MMF_VALUE_TYPE_INT,
@@ -1423,8 +1447,8 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        NULL,
                },
                {
-                       MM_CAM_DISPLAY_SHM_SOCKET_PATH,
-                       "display-shm-socket-path",
+                       MM_CAM_DISPLAY_SOCKET_PATH,
+                       "display-socket-path",
                        MMF_VALUE_TYPE_STRING,
                        MM_ATTRS_FLAG_RW,
                        {(void*)NULL},
@@ -1443,6 +1467,18 @@ _mmcamcorder_alloc_attribute( MMHandleType handle, MMCamPreset *info )
                        {.int_min = 0},
                        {.int_max = _MMCAMCORDER_MAX_INT},
                        _mmcamcorder_commit_pid_for_sound_focus,
+               },
+               //120
+               {
+                       MM_CAM_ROOT_DIRECTORY,
+                       "root-directory",
+                       MMF_VALUE_TYPE_STRING,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)NULL},
+                       MM_ATTRS_VALID_TYPE_NONE,
+                       {0},
+                       {0},
+                       NULL,
                }
        };
 
@@ -2101,7 +2137,7 @@ bool _mmcamcorder_commit_camera_width(MMHandleType handle, int attr_idx, const m
 
                                hcamcorder->resolution_changed = FALSE;
 
-                               if (!pthread_mutex_trylock(&(hcamcorder->restart_preview_lock))) {
+                               if (g_mutex_trylock(&hcamcorder->restart_preview_lock)) {
                                        _mmcam_dbg_log("restart preview");
 
                                        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE);
@@ -2120,7 +2156,7 @@ bool _mmcamcorder_commit_camera_width(MMHandleType handle, int attr_idx, const m
                                        _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING);
 
                                        /* unlock */
-                                       pthread_mutex_unlock(&(hcamcorder->restart_preview_lock));
+                                       g_mutex_unlock(&hcamcorder->restart_preview_lock);
                                } else {
                                        _mmcam_dbg_err("currently locked for preview restart");
                                        return FALSE;
@@ -2189,7 +2225,7 @@ bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const
 
                        hcamcorder->resolution_changed = FALSE;
 
-                       if (!pthread_mutex_trylock(&(hcamcorder->restart_preview_lock))) {
+                       if (g_mutex_trylock(&hcamcorder->restart_preview_lock)) {
                                _mmcam_dbg_log("restart preview");
 
                                _mmcam_dbg_log("set empty buffers");
@@ -2211,7 +2247,7 @@ bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const
                                _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING);
 
                                /* unlock */
-                               pthread_mutex_unlock(&(hcamcorder->restart_preview_lock));
+                               g_mutex_unlock(&hcamcorder->restart_preview_lock);
                        } else {
                                _mmcam_dbg_err("currently locked for preview restart");
                                return FALSE;
@@ -2919,11 +2955,8 @@ bool _mmcamcorder_commit_target_filename(MMHandleType handle, int attr_idx, cons
        }
 
        if (sc->info_video) {
-               if (sc->info_video->filename) {
-                       free(sc->info_video->filename);
-                       sc->info_video->filename = NULL;
-               }
-               sc->info_video->filename = strdup(filename);
+               SAFE_G_FREE(sc->info_video->filename);
+               sc->info_video->filename = g_strdup(filename);
                if (sc->info_video->filename == NULL) {
                        _mmcam_dbg_err("failed to strdup filename [%s]", filename);
                        return FALSE;
@@ -3326,7 +3359,7 @@ bool _mmcamcorder_commit_display_rotation(MMHandleType handle, int attr_idx, con
                return TRUE;
        }
 
-       return _mmcamcorder_set_display_rotation(handle, value->value.i_val);
+       return _mmcamcorder_set_display_rotation(handle, value->value.i_val, _MMCAMCORDER_VIDEOSINK_SINK);
 }
 
 
@@ -3351,7 +3384,7 @@ bool _mmcamcorder_commit_display_flip(MMHandleType handle, int attr_idx, const m
                return TRUE;
        }
 
-       return _mmcamcorder_set_display_flip(handle, value->value.i_val);
+       return _mmcamcorder_set_display_flip(handle, value->value.i_val, _MMCAMCORDER_VIDEOSINK_SINK);
 }
 
 
@@ -3658,7 +3691,6 @@ bool _mmcamcorder_commit_strobe (MMHandleType handle, int attr_idx, const mmf_va
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        int strobe_type, mslVal, newVal, cur_value;
        int current_state = MM_CAMCORDER_STATE_NONE;
-       int set_flash_state = -1;
 
        if (hcamcorder == NULL) {
                _mmcam_dbg_err("NULL handle");
@@ -3678,7 +3710,7 @@ bool _mmcamcorder_commit_strobe (MMHandleType handle, int attr_idx, const mmf_va
                int flash_brightness = 0;
 
                /* get current flash brightness */
-               if (_mmcamcorder_get_device_flash_brightness(&flash_brightness) != MM_ERROR_NONE) {
+               if (_mmcamcorder_get_device_flash_brightness(hcamcorder->gdbus_conn, &flash_brightness) != MM_ERROR_NONE) {
                        _mmcam_dbg_err("_mmcamcorder_get_device_flash_brightness failed");
                        hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
                        return FALSE;
@@ -3693,14 +3725,7 @@ bool _mmcamcorder_commit_strobe (MMHandleType handle, int attr_idx, const mmf_va
                        _mmcam_dbg_err("other module already turned on flash. avoid to set flash mode here.");
                        return FALSE;
                } else {
-                       /* flash is OFF state, this case will set flash state key */
-                       if (mslVal == MM_CAMCORDER_STROBE_MODE_OFF) {
-                               set_flash_state = VCONFKEY_CAMERA_FLASH_STATE_OFF;
-                       } else {
-                               set_flash_state = VCONFKEY_CAMERA_FLASH_STATE_ON;
-                       }
-
-                       _mmcam_dbg_log("keep going, and will set flash state key %d", set_flash_state);
+                       _mmcam_dbg_log("keep going");
                }
        }
 
@@ -3708,13 +3733,6 @@ bool _mmcamcorder_commit_strobe (MMHandleType handle, int attr_idx, const mmf_va
        current_state = _mmcamcorder_get_state(handle);
        if (current_state < MM_CAMCORDER_STATE_READY) {
                _mmcam_dbg_log("It doesn't need to change dynamically.(state=%d)", current_state);
-
-               if (set_flash_state != -1) {
-                       _mmcam_dbg_log("set VCONFKEY_CAMERA_FLASH_STATE : %d", set_flash_state);
-                       vconf_set_int(VCONFKEY_CAMERA_FLASH_STATE, set_flash_state);
-                       vconf_set_int(VCONFKEY_CAMERA_PID, (int)getpid());
-               }
-
                return TRUE;
        } else if (current_state == MM_CAMCORDER_STATE_CAPTURING) {
                _mmcam_dbg_warn("invalid state[capturing]");
@@ -3776,12 +3794,6 @@ bool _mmcamcorder_commit_strobe (MMHandleType handle, int attr_idx, const mmf_va
                }
        }
 
-       if (bret == TRUE && set_flash_state != -1) {
-               _mmcam_dbg_log("set VCONFKEY_CAMERA_FLASH_STATE : %d", set_flash_state);
-               vconf_set_int(VCONFKEY_CAMERA_FLASH_STATE, set_flash_state);
-               vconf_set_int(VCONFKEY_CAMERA_PID, (int)getpid());
-       }
-
        return bret;
 }
 
@@ -3978,11 +3990,69 @@ bool _mmcamcorder_commit_detect(MMHandleType handle, int attr_idx, const mmf_val
 }
 
 
+bool _mmcamcorder_commit_encoded_preview_bitrate(MMHandleType handle, int attr_idx, const mmf_value_t *value)
+{
+       int current_state = MM_CAMCORDER_STATE_NONE;
+       int preview_format = MM_PIXEL_FORMAT_NV12;
+
+       if ((void *)handle == NULL) {
+               _mmcam_dbg_warn("handle is NULL");
+               return FALSE;
+       }
+
+       _mmcam_dbg_log("Commit : encoded preview bitrate - %d", value->value.i_val);
+
+       /* check preview format */
+       mm_camcorder_get_attributes(handle, NULL, MMCAM_CAMERA_FORMAT, &preview_format, NULL);
+       if (preview_format != MM_PIXEL_FORMAT_ENCODED_H264) {
+               _mmcam_dbg_err("current preview format[%d] is not encoded format", preview_format);
+               return FALSE;
+       }
+
+       /* check state */
+       current_state = _mmcamcorder_get_state(handle);
+       if (current_state < MM_CAMCORDER_STATE_READY) {
+               _mmcam_dbg_log("will be applied when preview starts");
+               return TRUE;
+       }
+
+       return _mmcamcorder_set_encoded_preview_bitrate(handle, value->value.i_val);
+}
+
+
+bool _mmcamcorder_commit_encoded_preview_gop_interval(MMHandleType handle, int attr_idx, const mmf_value_t *value)
+{
+       int current_state = MM_CAMCORDER_STATE_NONE;
+       int preview_format = MM_PIXEL_FORMAT_NV12;
+
+       if ((void *)handle == NULL) {
+               _mmcam_dbg_warn("handle is NULL");
+               return FALSE;
+       }
+
+       _mmcam_dbg_log("Commit : encoded preview I-frame interval - %d", value->value.i_val);
+
+       /* check preview format */
+       mm_camcorder_get_attributes(handle, NULL, MMCAM_CAMERA_FORMAT, &preview_format, NULL);
+       if (preview_format != MM_PIXEL_FORMAT_ENCODED_H264) {
+               _mmcam_dbg_err("current preview format[%d] is not encoded format", preview_format);
+               return FALSE;
+       }
+
+       /* check state */
+       current_state = _mmcamcorder_get_state(handle);
+       if (current_state < MM_CAMCORDER_STATE_READY) {
+               _mmcam_dbg_log("will be applied when preview starts");
+               return TRUE;
+       }
+
+       return _mmcamcorder_set_encoded_preview_gop_interval(handle, value->value.i_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 new_pid = 0;
        int current_state = MM_CAMCORDER_STATE_NONE;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -3998,37 +4068,25 @@ bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx,
                return FALSE;
        }
 
-       pid_new = value->value.i_val;
+       new_pid = 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);
+       _mmcam_dbg_log("Commit : pid %d, current sound_focus_register %d, sound_focus_id %d",
+                      new_pid, hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
 
        /* 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);
-                       }
+       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("no need to unregister sound focus");
+                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done", hcamcorder->sound_focus_id);
                }
-       }
-
-       /* 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;
+               _mmcam_dbg_log("no need to unregister sound focus");
        }
 
+       /* register sound focus */
        if (hcamcorder->sound_focus_register) {
+               hcamcorder->sound_focus_id = 0;
                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;
@@ -4036,7 +4094,7 @@ bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx,
                }
 
                if (MM_ERROR_NONE != mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
-                                                                        pid_new,
+                                                                        new_pid,
                                                                         "media",
                                                                         _mmcamcorder_sound_focus_cb,
                                                                         hcamcorder)) {