Release version 0.10.17
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_util.c
index 7527691..c8abf6b 100644 (file)
@@ -146,37 +146,6 @@ static int __gdbus_method_call_sync(const char* bus_name, const char* object, co
 }
 
 
-static int __storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
-{
-       char **root_directory = (char **)user_data;
-
-       if (root_directory == NULL) {
-               _mmcam_dbg_warn("user data is NULL");
-               return FALSE;
-       }
-
-       _mmcam_dbg_log("storage id %d, type %d, state %d, path %s",
-                      storage_id, type, state, path ? path : "NULL");
-
-       if (type == STORAGE_TYPE_INTERNAL && path) {
-               if (*root_directory) {
-                       free(*root_directory);
-                       *root_directory = NULL;
-               }
-
-               *root_directory = strdup(path);
-               if (*root_directory) {
-                       _mmcam_dbg_log("get root directory %s", *root_directory);
-                       return FALSE;
-               } else {
-                       _mmcam_dbg_warn("strdup %s failed");
-               }
-       }
-
-       return TRUE;
-}
-
-
 gint32 _mmcamcorder_double_to_fix(gdouble d_number)
 {
        return (gint32) (d_number * 65536.0);
@@ -638,37 +607,33 @@ int _mmcamcorder_get_freespace(const gchar *path, const gchar *root_directory, g
        int ret = 0;
        struct statvfs vfs;
 
-       /*
-       * TEMPORARILY disabled (The internal / external storage distinguisher codes)
-       * : Since the camera / recorder module is working through the Muse Daemon Process,
-       *   There is an user's root path issue by the different process from the client's.
-       */
-#if 0
-       int is_internal = 0;
+       int is_internal = TRUE;
        struct stat stat_path;
        struct stat stat_root;
 
-       if (path == NULL || root_directory == NULL || free_space == NULL) {
-               _mmcam_dbg_err("invalid parameter %p, %p, %p", path, root_directory, free_space);
+       if (path == NULL || free_space == NULL) {
+               _mmcam_dbg_err("invalid parameter %p, %p", path, free_space);
                return -1;
        }
 
-       if (stat(path, &stat_path) != 0) {
-               *free_space = 0;
-               _mmcam_dbg_err("failed to stat for [%s][errno %d]", path, errno);
-               return -1;
-       }
+       if (root_directory && strlen(root_directory) > 0) {
+               if (stat(path, &stat_path) != 0) {
+                       *free_space = 0;
+                       _mmcam_dbg_err("failed to stat for [%s][errno %d]", path, errno);
+                       return -1;
+               }
 
-       if (stat(root_directory, &stat_root) != 0) {
-               *free_space = 0;
-               _mmcam_dbg_err("failed to stat for [%s][errno %d]", path, errno);
-               return -1;
-       }
+               if (stat(root_directory, &stat_root) != 0) {
+                       *free_space = 0;
+                       _mmcam_dbg_err("failed to stat for [%s][errno %d]", root_directory, errno);
+                       return -1;
+               }
 
-       if (stat_path.st_dev == stat_root.st_dev) {
-               is_internal = TRUE;
+               if (stat_path.st_dev != stat_root.st_dev) {
+                       is_internal = FALSE;
+               }
        } else {
-               is_internal = FALSE;
+               _mmcam_dbg_warn("root_directory is NULL, assume that it's internal storage.");
        }
 
        if (is_internal) {
@@ -676,9 +641,6 @@ int _mmcamcorder_get_freespace(const gchar *path, const gchar *root_directory, g
        } else {
                ret = storage_get_external_memory_size(&vfs);
        }
-#else
-       ret = storage_get_internal_memory_size(&vfs);
-#endif
 
        if (ret < 0) {
                *free_space = 0;
@@ -1025,6 +987,7 @@ void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_
 }
 
 
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
 gboolean _mmcamcorder_msg_callback(void *data)
 {
        _MMCamcorderMsgItem *item = (_MMCamcorderMsgItem*)data;
@@ -1098,12 +1061,15 @@ MSG_CALLBACK_DONE:
        /* For not being called again */
        return FALSE;
 }
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
 
 gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data)
 {
        mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
        _MMCamcorderMsgItem *item = NULL;
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
        mmf_return_val_if_fail(data, FALSE);
@@ -1137,6 +1103,7 @@ gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat
                        break;
        }
 
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
        item = g_malloc(sizeof(_MMCamcorderMsgItem));
        if (item) {
                memcpy(item, data, sizeof(_MMCamcorderMsgItem));
@@ -1145,7 +1112,7 @@ gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat
 
                _MMCAMCORDER_LOCK(handle);
                hcamcorder->msg_data = g_list_append(hcamcorder->msg_data, item);
-//             _mmcam_dbg_log("item[%p]", item);
+               /*_mmcam_dbg_log("item[%p]", item);*/
 
                /* Use DEFAULT priority */
                g_idle_add_full(G_PRIORITY_DEFAULT, _mmcamcorder_msg_callback, item, NULL);
@@ -1154,6 +1121,43 @@ gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat
        } else {
                _mmcam_dbg_err("item[id:0x%x] malloc failed : %d", data->id, sizeof(_MMCamcorderMsgItem));
        }
+#else /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
+       _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(hcamcorder);
+
+       if (hcamcorder->msg_cb) {
+               hcamcorder->msg_cb(data->id, (MMMessageParamType*)(&(data->param)), hcamcorder->msg_cb_param);
+       } else {
+               _mmcam_dbg_log("message callback is NULL. message id %d", data->id);
+       }
+
+       _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
+
+       /* release allocated memory */
+       if (data->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
+               MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)data->param.data;
+               if (cam_fd_info) {
+                       SAFE_FREE(cam_fd_info->face_info);
+                       free(cam_fd_info);
+                       cam_fd_info = NULL;
+
+                       data->param.data = NULL;
+                       data->param.size = 0;
+               }
+       } else if (data->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED ||
+                  data->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
+               MMCamRecordingReport *report = (MMCamRecordingReport *)data->param.data;
+               if (report) {
+                       if (report->recording_filename) {
+                               free(report->recording_filename);
+                               report->recording_filename = NULL;
+                       }
+                       free(report);
+                       report = NULL;
+
+                       data->param.data = NULL;
+               }
+       }
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
        return TRUE;
 }
@@ -1162,18 +1166,21 @@ gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat
 void _mmcamcorder_remove_message_all(MMHandleType handle)
 {
        mmf_camcorder_t* hcamcorder = MMF_CAMCORDER(handle);
-       _MMCamcorderMsgItem *item = NULL;
        gboolean ret = TRUE;
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
+       _MMCamcorderMsgItem *item = NULL;
        GList *list = NULL;
        struct timespec timeout;
        struct timeval tv;
        struct timeval tv_to_add;
        struct timeval tv_result;
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
        mmf_return_if_fail(hcamcorder);
 
        _MMCAMCORDER_LOCK(handle);
 
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
        if (!hcamcorder->msg_data) {
                _mmcam_dbg_log("No message data is remained.");
        } else {
@@ -1257,6 +1264,7 @@ void _mmcamcorder_remove_message_all(MMHandleType handle)
                g_list_free(hcamcorder->msg_data);
                hcamcorder->msg_data = NULL;
        }
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
        /* remove idle function for playing capture sound */
        do {
@@ -2157,23 +2165,3 @@ static gboolean _mmcamcorder_convert_NV12_to_I420(unsigned char *src, guint widt
 
        return TRUE;
 }
-
-
-int _mmcamcorder_get_root_directory(char **root_directory)
-{
-       int ret = STORAGE_ERROR_NONE;
-
-       if (root_directory == NULL) {
-               _mmcam_dbg_warn("user data is NULL");
-               return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
-       }
-
-       ret = storage_foreach_device_supported((storage_device_supported_cb)__storage_device_supported_cb, root_directory);
-       if (ret != STORAGE_ERROR_NONE) {
-               _mmcam_dbg_err("storage_foreach_device_supported failed 0x%x", ret);
-               return MM_ERROR_CAMCORDER_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-