[Release version 0.10.37] Return NOT_SUPPORTED error when configure file is not existed
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 990f8d4..deaa15f 100644 (file)
@@ -261,12 +261,9 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        }
 
        /* Get Camera Configure information from Camcorder INI file */
-       _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
-
-       if (!(hcamcorder->conf_main)) {
-               _mmcam_dbg_err( "Failed to get configure(main) info." );
-
-               ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
+       ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
+       if (ret != MM_ERROR_NONE) {
+               _mmcam_dbg_err("Failed to get configure(main) info.");
                goto _ERR_DEFAULT_VALUE_INIT;
        }
 
@@ -309,17 +306,15 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 
                        _mmcam_dbg_log("videodev_type : [%d], ConfCtrlPath : [%s]", info->videodev_type, ConfCtrlFile);
 
-                       _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_CTRL, ConfCtrlFile, &hcamcorder->conf_ctrl);
+                       ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_CTRL, ConfCtrlFile, &hcamcorder->conf_ctrl);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("Failed to get configure(control) info.");
+                               goto _ERR_DEFAULT_VALUE_INIT;
+                       }
 /*
                        _mmcamcorder_conf_print_info(&hcamcorder->conf_main);
                        _mmcamcorder_conf_print_info(&hcamcorder->conf_ctrl);
 */
-                       if (!(hcamcorder->conf_ctrl)) {
-                               _mmcam_dbg_err( "Failed to get configure(control) info." );
-                               ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
-                               goto _ERR_DEFAULT_VALUE_INIT;
-                       }
-
                        ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_warn("converting table initialize error!!");
@@ -327,7 +322,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                goto _ERR_DEFAULT_VALUE_INIT;
                        }
 
-                       ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_CAMERA|MM_CAMCONVERT_CATEGORY_DISPLAY);
+                       ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_ALL);
                        if (ret != MM_ERROR_NONE) {
                                _mmcam_dbg_warn("converting table initialize error!!");
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
@@ -427,8 +422,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                        if (err_attr_name) {
                                _mmcam_dbg_err("Set %s FAILED.", err_attr_name);
-                               free(err_attr_name);
-                               err_attr_name = NULL;
+                               SAFE_FREE(err_attr_name);
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
                                goto _ERR_DEFAULT_VALUE_INIT;
                        }
@@ -439,8 +433,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                        if (err_attr_name) {
                                _mmcam_dbg_err("Get brightness FAILED.");
-                               free(err_attr_name);
-                               err_attr_name = NULL;
+                               SAFE_FREE(err_attr_name);
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
                                goto _ERR_DEFAULT_VALUE_INIT;
                        }
@@ -459,8 +452,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                if (err_attr_name) {
                        _mmcam_dbg_err("Set %s FAILED.", err_attr_name);
-                       free(err_attr_name);
-                       err_attr_name = NULL;
+                       SAFE_FREE(err_attr_name);
                        ret = MM_ERROR_CAMCORDER_INTERNAL;
                        goto _ERR_DEFAULT_VALUE_INIT;
                }
@@ -787,7 +779,7 @@ int _mmcamcorder_realize(MMHandleType handle)
        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 display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
        int pid_for_sound_focus = 0;
        double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
        char *videosink_element_type = NULL;
@@ -826,10 +818,9 @@ int _mmcamcorder_realize(MMHandleType handle)
        _mmcam_dbg_log("Profile mode [%d]", hcamcorder->type);
 
        mm_camcorder_get_attributes(handle, NULL,
-                                   MMCAM_DISPLAY_SURFACE, &display_surface_type,
-                                   MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
-                                   MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
-                                   NULL);
+               MMCAM_DISPLAY_SURFACE, &display_surface_type,
+               MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
+               NULL);
 
        /* sound focus */
        if (hcamcorder->sound_focus_register) {
@@ -915,30 +906,32 @@ int _mmcamcorder_realize(MMHandleType handle)
                _mmcam_dbg_warn("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
        }
 
-       if (socket_path == NULL) {
-               _mmcam_dbg_warn("Socket Path is not properly set, -> to NullSink.");
+       switch (display_surface_type) {
+       case MM_DISPLAY_SURFACE_OVERLAY:
+               videosink_element_type = strdup("VideosinkElementOverlay");
+               break;
+       case MM_DISPLAY_SURFACE_EVAS:
+               videosink_element_type = strdup("VideosinkElementEvas");
+               break;
+       case MM_DISPLAY_SURFACE_GL:
+               videosink_element_type = strdup("VideosinkElementGL");
+               break;
+       case MM_DISPLAY_SURFACE_NULL:
                videosink_element_type = strdup("VideosinkElementNull");
-       } else {
-               switch (display_surface_type) {
-               case MM_DISPLAY_SURFACE_X:
-                       videosink_element_type = strdup("VideosinkElementX");
-                       break;
-               case MM_DISPLAY_SURFACE_EVAS:
-                       videosink_element_type = strdup("VideosinkElementEvas");
-                       break;
-               case MM_DISPLAY_SURFACE_GL:
-                       videosink_element_type = strdup("VideosinkElementGL");
-                       break;
-               case MM_DISPLAY_SURFACE_NULL:
+               break;
+       case MM_DISPLAY_SURFACE_REMOTE:
+               mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
+                       NULL);
+               if (socket_path == NULL) {
+                       _mmcam_dbg_warn("REMOTE surface, but socket path is NULL -> to NullSink");
                        videosink_element_type = strdup("VideosinkElementNull");
-                       break;
-               case MM_DISPLAY_SURFACE_REMOTE:
+               } else
                        videosink_element_type = strdup("VideosinkElementRemote");
-                       break;
-               default:
-                       videosink_element_type = strdup("VideosinkElementX");
-                       break;
-               }
+               break;
+       default:
+               videosink_element_type = strdup("VideosinkElementOverlay");
+               break;
        }
 
        /* check string of videosink element */
@@ -986,7 +979,7 @@ int _mmcamcorder_realize(MMHandleType handle)
                mm_camcorder_get_attributes(handle, NULL,
                                             MMCAM_DISPLAY_SURFACE, &display_surface_type,
                                             NULL);
-               if(display_surface_type == MM_DISPLAY_SURFACE_X) {
+               if(display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
                        if((_mmcamcorder_resource_manager_prepare(&hcamcorder->resource_manager, RESOURCE_TYPE_VIDEO_OVERLAY))) {
                                _mmcam_dbg_err("could not prepare for video overlay resource");
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
@@ -1924,6 +1917,7 @@ int _mmcamcorder_init_focusing(MMHandleType handle)
        control = GST_CAMERA_CONTROL (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
        if (control == NULL) {
                _mmcam_dbg_err("cast CAMERA_CONTROL failed");
+               _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
@@ -2371,31 +2365,28 @@ _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
        /* alloc info for each mode */
        switch (type) {
        case MM_CAMCORDER_MODE_AUDIO:
-               sc->info_audio = malloc( sizeof(_MMCamcorderAudioInfo));
+               sc->info_audio = g_malloc0( sizeof(_MMCamcorderAudioInfo));
                if(!sc->info_audio) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_audio, 0x00, sizeof(_MMCamcorderAudioInfo));
                break;
        case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
        default:
-               sc->info_image = malloc( sizeof(_MMCamcorderImageInfo));
+               sc->info_image = g_malloc0( sizeof(_MMCamcorderImageInfo));
                if(!sc->info_image) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_image, 0x00, sizeof(_MMCamcorderImageInfo));
 
                /* init sound status */
                sc->info_image->sound_status = _SOUND_STATUS_INIT;
 
-               sc->info_video = malloc( sizeof(_MMCamcorderVideoInfo));
+               sc->info_video = g_malloc0( sizeof(_MMCamcorderVideoInfo));
                if(!sc->info_video) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_video, 0x00, sizeof(_MMCamcorderVideoInfo));
                g_mutex_init(&sc->info_video->size_check_lock);
                break;
        }
@@ -2433,19 +2424,12 @@ _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
 
 ALLOC_SUBCONTEXT_FAILED:
        if (sc) {
-               if (sc->info_audio) {
-                       free(sc->info_audio);
-                       sc->info_audio = NULL;
-               }
-               if (sc->info_image) {
-                       free(sc->info_image);
-                       sc->info_image = NULL;
-               }
+               SAFE_G_FREE(sc->info_audio);
+               SAFE_G_FREE(sc->info_image);
                if (sc->info_video) {
                        g_mutex_clear(&sc->info_video->size_check_lock);
-                       free(sc->info_video);
-                       sc->info_video = NULL;
                }
+               SAFE_G_FREE(sc->info_video);
                if (sc->element) {
                        free(sc->element);
                        sc->element = NULL;
@@ -2487,10 +2471,7 @@ void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
 
                if (sc->info_video) {
                        _mmcam_dbg_log("release info_video");
-                       if (sc->info_video->filename) {
-                               free(sc->info_video->filename);
-                               sc->info_video->filename = NULL;
-                       }
+                       SAFE_G_FREE(sc->info_video->filename);
                        g_mutex_clear(&sc->info_video->size_check_lock);
                        free(sc->info_video);
                        sc->info_video = NULL;
@@ -2498,10 +2479,7 @@ void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
 
                if (sc->info_audio) {
                        _mmcam_dbg_log("release info_audio");
-                       if (sc->info_audio->filename) {
-                               free(sc->info_audio->filename);
-                               sc->info_audio->filename = NULL;
-                       }
+                       SAFE_G_FREE(sc->info_audio->filename);
                        free(sc->info_audio);
                        sc->info_audio = NULL;
                }
@@ -2829,13 +2807,10 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                goto DROP_MESSAGE;
                        }
 
-                       cam_fd_info = (MMCamFaceDetectInfo *)malloc(sizeof(MMCamFaceDetectInfo));
+                       cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
                        if (cam_fd_info == NULL) {
                                _mmcam_dbg_warn("cam_fd_info alloc failed");
-
-                               free(fd_info);
-                               fd_info = NULL;
-
+                               SAFE_FREE(fd_info);
                                goto DROP_MESSAGE;
                        }
 
@@ -2843,7 +2818,7 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        cam_fd_info->num_of_faces = fd_info->num_of_faces;
 
                        if (cam_fd_info->num_of_faces > 0) {
-                               cam_fd_info->face_info = (MMCamFaceInfo *)malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
+                               cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
                                if (cam_fd_info->face_info) {
                                        /* set information of each face */
                                        for (i = 0 ; i < fd_info->num_of_faces ; i++) {
@@ -2867,8 +2842,7 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                        _mmcam_dbg_warn("MMCamFaceInfo alloc failed");
 
                                        /* free allocated memory that is not sent */
-                                       free(cam_fd_info);
-                                       cam_fd_info = NULL;
+                                       SAFE_G_FREE(cam_fd_info);
                                }
                        } else {
                                cam_fd_info->face_info = NULL;