Add sub functions for recording 89/215789/4
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 16 Oct 2019 01:59:21 +0000 (10:59 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 16 Oct 2019 06:57:09 +0000 (15:57 +0900)
- _mmcamcorder_get_storage_validity()
- _mmcamcorder_adjust_recording_max_size()

[Version] 0.10.187
[Profile] Common
[Issue Type] Update

Change-Id: I525510ddc5fed1e6ef561c6ae47dc606ee60ff65
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/libmm-camcorder.spec
src/include/mm_camcorder_util.h
src/mm_camcorder_audiorec.c
src/mm_camcorder_internal.c
src/mm_camcorder_util.c
src/mm_camcorder_videorec.c

index 4eb9e7d..5750ff3 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.186
+Version:    0.10.187
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index db349e3..786c575 100644 (file)
@@ -293,8 +293,10 @@ gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationIn
 guint64 _mmcamcorder_get_container_size(const guchar *size);
 guint64 _mmcamcorder_get_container_size64(const guchar *size);
 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
+void _mmcamcorder_adjust_recording_max_size(const char *filename, guint64 *max_size);
 
 /* File system */
+int _mmcamcorder_get_storage_validity(MMHandleType handle, const char *filename, guint64 min_space, gboolean *storage_validity);
 int _mmcamcorder_get_storage_info(const gchar *path, const gchar *root_directory, _MMCamcorderStorageInfo *storage_info);
 int _mmcamcorder_get_freespace(storage_type_e type, guint64 *free_space);
 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
index f8dd8d4..213410f 100644 (file)
@@ -324,8 +324,6 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
 {
        int cmd = command;
        int ret = MM_ERROR_NONE;
-       int err = 0;
-       guint64 free_space = 0;
        char *err_attr_name = NULL;
 
        GstElement *pipeline = NULL;
@@ -352,11 +350,10 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
        case _MMCamcorder_CMD_RECORD:
                /* check status for resume case */
                if (_mmcamcorder_get_state((MMHandleType)hcamcorder) != MM_CAMCORDER_STATE_PAUSED) {
+                       gboolean storage_validity = FALSE;
                        guint imax_size = 0;
                        guint imax_time = 0;
-                       char *temp_filename = NULL;
-                       char *dir_name = NULL;
-                       int file_system_type = 0;
+                       char *target_filename = NULL;
                        int filename_length = 0;
                        int root_directory_length = 0;
 
@@ -369,7 +366,7 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
                                MMCAM_TARGET_MAX_SIZE, &imax_size,
                                MMCAM_TARGET_TIME_LIMIT, &imax_time,
                                MMCAM_FILE_FORMAT, &(info->fileformat),
-                               MMCAM_TARGET_FILENAME, &temp_filename, &filename_length,
+                               MMCAM_TARGET_FILENAME, &target_filename, &filename_length,
                                MMCAM_ROOT_DIRECTORY, &hcamcorder->root_directory, &root_directory_length,
                                NULL);
                        if (ret != MM_ERROR_NONE) {
@@ -378,7 +375,7 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
                                goto _ERR_CAMCORDER_AUDIO_COMMAND;
                        }
 
-                       if (!temp_filename && !hcamcorder->mstream_cb) {
+                       if (!target_filename && !hcamcorder->mstream_cb) {
                                _mmcam_dbg_err("filename is not set and muxed stream cb is NULL");
                                ret = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
                                goto _ERR_CAMCORDER_AUDIO_COMMAND;
@@ -386,10 +383,10 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
 
                        SAFE_G_FREE(info->filename);
 
-                       if (temp_filename) {
-                               info->filename = g_strdup(temp_filename);
+                       if (target_filename) {
+                               info->filename = g_strdup(target_filename);
                                if (!info->filename) {
-                                       _mmcam_dbg_err("STRDUP was failed for [%s]", temp_filename);
+                                       _mmcam_dbg_err("STRDUP was failed for [%s]", target_filename);
                                        goto _ERR_CAMCORDER_AUDIO_COMMAND;
                                }
 
@@ -419,49 +416,14 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
                        else
                                info->max_time = ((guint64)imax_time) * 1000; /* to millisecond */
 
-                       /* TODO : check free space before recording start */
-                       dir_name = g_path_get_dirname(info->filename);
-                       if (dir_name) {
-                               err = _mmcamcorder_get_storage_info(dir_name, hcamcorder->root_directory, &hcamcorder->storage_info);
-                               if (err != 0) {
-                                       _mmcam_dbg_err("get storage info failed");
-                                       g_free(dir_name);
-                                       dir_name = NULL;
-                                       return MM_ERROR_OUT_OF_STORAGE;
-                               }
-
-                               err = _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space);
-
-                               _mmcam_dbg_warn("current space - %s [%" G_GUINT64_FORMAT "]", dir_name, free_space);
-
-                               if (_mmcamcorder_get_file_system_type(dir_name, &file_system_type) == 0) {
-                                       /* MSDOS_SUPER_MAGIC : 0x4d44 */
-                                       if (file_system_type == MSDOS_SUPER_MAGIC &&
-                                           (info->max_size == 0 || info->max_size > FAT32_FILE_SYSTEM_MAX_SIZE)) {
-                                               _mmcam_dbg_warn("FAT32 and too large max[%"G_GUINT64_FORMAT"], set max as %lu",
-                                                       info->max_size, FAT32_FILE_SYSTEM_MAX_SIZE);
-                                               info->max_size = FAT32_FILE_SYSTEM_MAX_SIZE;
-                                       } else {
-                                               _mmcam_dbg_warn("file system 0x%x, max size %"G_GUINT64_FORMAT,
-                                                                               file_system_type, info->max_size);
-                                       }
-                               } else {
-                                       _mmcam_dbg_warn("_mmcamcorder_get_file_system_type failed");
-                               }
-
-                               g_free(dir_name);
-                               dir_name = NULL;
-                       } else {
-                               _mmcam_dbg_err("failed to get directory name");
-                               err = -1;
+                       ret = _mmcamcorder_get_storage_validity(handle, info->filename,
+                               _MMCAMCORDER_AUDIO_MINIMUM_SPACE, &storage_validity);
+                       if (ret != MM_ERROR_NONE || !storage_validity) {
+                               _mmcam_dbg_err("storage validation failed[0x%x]:%d", ret, storage_validity);
+                               return ret;
                        }
 
-                       if (temp_filename &&
-                               (err == -1 || free_space <= _MMCAMCORDER_AUDIO_MINIMUM_SPACE)) {
-                               _mmcam_dbg_err("OUT of STORAGE [err:%d or free space [%" G_GUINT64_FORMAT "] is smaller than [%d]",
-                                       err, free_space, _MMCAMCORDER_AUDIO_MINIMUM_SPACE);
-                               return MM_ERROR_OUT_OF_STORAGE;
-                       }
+                       _mmcamcorder_adjust_recording_max_size(info->filename, &info->max_size);
                }
 
                ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING);
index cb9a8f7..a48529f 100644 (file)
@@ -3144,7 +3144,6 @@ static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcam
 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
 {
        GstBusSyncReply ret = GST_BUS_PASS;
-       GstElement *element = NULL;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
        _MMCamcorderSubContext *sc = NULL;
index 1053e4c..bdcef72 100644 (file)
@@ -704,6 +704,86 @@ static int __mmcamcorder_storage_supported_cb(int storage_id, storage_type_e typ
 }
 
 
+int _mmcamcorder_get_storage_validity(MMHandleType handle, const char *filename, guint64 min_space, gboolean *storage_validity)
+{
+       int ret = MM_ERROR_NONE;
+       int err = 0;
+       char *dir_name = NULL;
+       guint64 free_space = 0;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+       mmf_return_val_if_fail(storage_validity, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       if (!filename) {
+               _mmcam_dbg_warn("NULL filename, but keep going...");
+               *storage_validity = TRUE;
+               return MM_ERROR_NONE;
+       }
+
+       dir_name = g_path_get_dirname(filename);
+       mmf_return_val_if_fail(dir_name, MM_ERROR_OUT_OF_STORAGE);
+
+       err = _mmcamcorder_get_storage_info(dir_name, hcamcorder->root_directory, &hcamcorder->storage_info);
+       if (err != 0) {
+               _mmcam_dbg_err("get storage info failed");
+               ret = MM_ERROR_CAMCORDER_INTERNAL;
+               goto _CHECK_DONE;
+       }
+
+       err = _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space);
+       if (err != 0) {
+               _mmcam_dbg_err("get free space failed");
+               ret = MM_ERROR_CAMCORDER_INTERNAL;
+               goto _CHECK_DONE;
+       }
+
+       _mmcam_dbg_warn("current free space - %s [%" G_GUINT64_FORMAT "]", dir_name, free_space);
+
+_CHECK_DONE:
+       g_free(dir_name);
+
+       if (ret == MM_ERROR_NONE && free_space > min_space) {
+               *storage_validity = TRUE;
+               _mmcam_dbg_log("validity and free space of storage : OK");
+       } else {
+               *storage_validity = FALSE;
+               _mmcam_dbg_err("OUT of STORAGE [err:%d or free space [%"G_GUINT64_FORMAT"] is smaller than [%"G_GUINT64_FORMAT"]",
+                       err, free_space, min_space);
+       }
+
+       return ret;
+}
+
+
+void _mmcamcorder_adjust_recording_max_size(const char *filename, guint64 *max_size)
+{
+       int file_system_type = 0;
+       char *dir_name = NULL;
+
+       mmf_return_if_fail(max_size);
+       mmf_return_if_fail(filename);
+
+       dir_name = g_path_get_dirname(filename);
+       mmf_return_if_fail(dir_name);
+
+       if (_mmcamcorder_get_file_system_type(dir_name, &file_system_type) == 0) {
+               /* MSDOS_SUPER_MAGIC : 0x4d44 */
+               if (file_system_type == MSDOS_SUPER_MAGIC &&
+                       (*max_size == 0 || *max_size > FAT32_FILE_SYSTEM_MAX_SIZE)) {
+                       _mmcam_dbg_warn("FAT32 and too large max[%"G_GUINT64_FORMAT"], set max as %lu",
+                               *max_size, FAT32_FILE_SYSTEM_MAX_SIZE);
+                       *max_size = FAT32_FILE_SYSTEM_MAX_SIZE;
+               } else {
+                       _mmcam_dbg_warn("file system 0x%x, max size %"G_GUINT64_FORMAT,
+                               file_system_type, *max_size);
+               }
+       }
+
+       g_free(dir_name);
+}
+
+
 int _mmcamcorder_get_storage_info(const gchar *path, const gchar *root_directory, _MMCamcorderStorageInfo *info)
 {
        int ret = 0;
index 1acd72f..7eac0b9 100644 (file)
@@ -504,7 +504,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
        int ret = MM_ERROR_NONE;
        double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
        char *err_name = NULL;
-       char *temp_filename = NULL;
+       char *target_filename = NULL;
        GstCameraControl *CameraControl = NULL;
        GstCameraControlChannel *CameraControlChannel = NULL;
        const GList *controls = NULL;
@@ -537,12 +537,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
                        /**
                         * start recording
                         */
+                       gboolean storage_validity = FALSE;
                        guint imax_size = 0;
                        guint imax_time = 0;
-                       int ret_free_space = 0;
-                       char *dir_name = NULL;
-                       guint64 free_space = 0;
-                       int file_system_type = 0;
                        int root_directory_length = 0;
 
                        /* Recording */
@@ -589,7 +586,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
                                MMCAM_VIDEO_WIDTH, &(info->video_width),
                                MMCAM_VIDEO_HEIGHT, &(info->video_height),
                                MMCAM_FILE_FORMAT, &fileformat,
-                               MMCAM_TARGET_FILENAME, &temp_filename, &size,
+                               MMCAM_TARGET_FILENAME, &target_filename, &size,
                                MMCAM_TARGET_MAX_SIZE, &imax_size,
                                MMCAM_TARGET_TIME_LIMIT, &imax_time,
                                MMCAM_FILE_FORMAT, &(info->fileformat),
@@ -602,7 +599,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
                                goto _ERR_CAMCORDER_VIDEO_COMMAND;
                        }
 
-                       if (!temp_filename && !hcamcorder->mstream_cb) {
+                       if (!target_filename && !hcamcorder->mstream_cb) {
                                _mmcam_dbg_err("filename is not set and muxed stream cb is NULL");
                                ret = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
                                goto _ERR_CAMCORDER_VIDEO_COMMAND;
@@ -620,48 +617,14 @@ int _mmcamcorder_video_command(MMHandleType handle, int command)
                        else
                                info->max_time = (guint64)((double)imax_time * (double)1000 * motion_rate); /* to millisecond */
 
-                       dir_name = g_path_get_dirname(temp_filename);
-                       if (dir_name) {
-                               ret = _mmcamcorder_get_storage_info(dir_name, hcamcorder->root_directory, &hcamcorder->storage_info);
-                               if (ret != 0) {
-                                       _mmcam_dbg_err("get storage info failed");
-                                       g_free(dir_name);
-                                       dir_name = NULL;
-                                       return MM_ERROR_OUT_OF_STORAGE;
-                               }
-
-                               ret_free_space = _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space);
-
-                               _mmcam_dbg_warn("current space - %s [%" G_GUINT64_FORMAT "]", dir_name, free_space);
-
-                               if (_mmcamcorder_get_file_system_type(dir_name, &file_system_type) == 0) {
-                                       /* MSDOS_SUPER_MAGIC : 0x4d44 */
-                                       if (file_system_type == MSDOS_SUPER_MAGIC &&
-                                           (info->max_size == 0 || info->max_size > FAT32_FILE_SYSTEM_MAX_SIZE)) {
-                                               _mmcam_dbg_warn("FAT32 and too large max[%"G_GUINT64_FORMAT"], set max as %lu",
-                                                       info->max_size, FAT32_FILE_SYSTEM_MAX_SIZE);
-                                               info->max_size = FAT32_FILE_SYSTEM_MAX_SIZE;
-                                       } else {
-                                               _mmcam_dbg_warn("file system 0x%x, max size %"G_GUINT64_FORMAT,
-                                                       file_system_type, info->max_size);
-                                       }
-                               } else {
-                                       _mmcam_dbg_warn("_mmcamcorder_get_file_system_type failed");
-                               }
-
-                               g_free(dir_name);
-                               dir_name = NULL;
-                       } else {
-                               _mmcam_dbg_err("failed to get directory name");
-                               ret_free_space = -1;
+                       ret = _mmcamcorder_get_storage_validity(hcamcorder, target_filename,
+                               _MMCAMCORDER_VIDEO_MINIMUM_SPACE, &storage_validity);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("storage validation failed[0x%x]:%d", ret, storage_validity);
+                               return ret;
                        }
 
-                       if (temp_filename &&
-                               (ret_free_space == -1 || free_space <= _MMCAMCORDER_VIDEO_MINIMUM_SPACE)) {
-                               _mmcam_dbg_err("OUT of STORAGE [ret_free_space:%d or free space [%" G_GUINT64_FORMAT "] is smaller than [%d]",
-                                       ret_free_space, free_space, _MMCAMCORDER_VIDEO_MINIMUM_SPACE);
-                               return MM_ERROR_OUT_OF_STORAGE;
-                       }
+                       _mmcamcorder_adjust_recording_max_size(target_filename, &info->max_size);
 
                        g_mutex_lock(&hcamcorder->task_thread_lock);
                        if (sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst == NULL &&