Fix Svace issue
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index b473eb7..b9f0f7e 100644 (file)
@@ -155,17 +155,12 @@ static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_t
        new_handle->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
 
        if (device_type != MM_VIDEO_DEVICE_NONE) {
-               new_handle->gdbus_info_sound.mm_handle = new_handle;
-               g_mutex_init(&new_handle->gdbus_info_sound.sync_mutex);
-               g_cond_init(&new_handle->gdbus_info_sound.sync_cond);
-
-               new_handle->gdbus_info_solo_sound.mm_handle = new_handle;
-               g_mutex_init(&new_handle->gdbus_info_solo_sound.sync_mutex);
-               g_cond_init(&new_handle->gdbus_info_solo_sound.sync_cond);
+               new_handle->gdbus_info_sound = _mmcamcorder_gdbus_info_new();
+               new_handle->gdbus_info_solo_sound = _mmcamcorder_gdbus_info_new();
        }
 
        /* create task thread */
-       new_handle->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
+       new_handle->task_thread = g_thread_try_new("mmcam:util_task",
                (GThreadFunc)_mmcamcorder_util_task_thread_func, (gpointer)new_handle, NULL);
        if (new_handle->task_thread == NULL) {
                MMCAM_LOG_ERROR("_mmcamcorder_create::failed to create task thread");
@@ -264,10 +259,8 @@ static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder)
        g_mutex_clear(&hcamcorder->restart_preview_lock);
 
        if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
-               g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
-               g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
+               _mmcamcorder_gdbus_info_check_free(hcamcorder->gdbus_info_sound);
+               _mmcamcorder_gdbus_info_check_free(hcamcorder->gdbus_info_solo_sound);
        }
 
        g_mutex_clear(&hcamcorder->task_thread_lock);
@@ -328,6 +321,8 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
        int play_capture_sound = TRUE;
        int camera_default_flip = MM_FLIP_NONE;
        int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
+       int wb_temp_step = 1;
+       int gain_step = 1;
        char *err_attr_name = NULL;
        char conf_file_name[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
        const char *platform_privilege_camera = NULL;
@@ -445,16 +440,34 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                "SupportZSL",
                &hcamcorder->support_zsl_capture);
 
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
+               CONFIGURE_CATEGORY_CTRL_EFFECT,
+               "WhiteBalanceTemperatureStep",
+               &wb_temp_step);
+
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
+               CONFIGURE_CATEGORY_CTRL_PHOTOGRAPH,
+               "GainStep",
+               &gain_step);
+
        MMCAM_LOG_INFO("Recommend format[capture:%d, recording:%d]", rcmd_fmt_capture, rcmd_fmt_recording);
        MMCAM_LOG_INFO("Recommend display rotation[%d]", rcmd_dpy_rotation);
        MMCAM_LOG_INFO("Camera facing direction[%d]", camera_facing_direction);
        MMCAM_LOG_INFO("Brightness step denominator[%d]", hcamcorder->brightness_step_denominator);
        MMCAM_LOG_INFO("Support ZSL capture[%d]", hcamcorder->support_zsl_capture);
+       MMCAM_LOG_INFO("Step: wb_temp[%d], gain[%d]", wb_temp_step, gain_step);
 
-       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
-               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
-               "UseZeroCopyFormat",
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
+               CONFIGURE_CATEGORY_CTRL_CAMERA,
+               "AltUseZeroCopyFormat",
                &hcamcorder->use_zero_copy_format);
+       if (hcamcorder->use_zero_copy_format == -1) {
+               MMCAM_LOG_WARNING("AltUseZeroCopyFormat is not set, so use \"UseZeroCopyFormat\".");
+               _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+                       CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+                       "UseZeroCopyFormat",
+                       &hcamcorder->use_zero_copy_format);
+       }
 
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
@@ -559,6 +572,8 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
                        platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
                MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
+               MMCAM_FILTER_WB_TEMPERATURE_STEP, wb_temp_step,
+               MMCAM_CAMERA_GAIN_STEP, gain_step,
                NULL);
        if (ret != MM_ERROR_NONE) {
                MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
@@ -618,11 +633,11 @@ static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
                &device_count);
 
        _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
-               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
+               hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
                NULL, &videosrc_name);
 
        _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
-               CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, "AudiosrcElement",
+               hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, "AudiosrcElement",
                NULL, &audiosrc_name);
 
        MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
@@ -1410,23 +1425,6 @@ int _mmcamcorder_stop(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
 
-       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
-               /* unsubscribe remained unsubscribed signal */
-               g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
-               if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
-                       MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
-                       g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_sound.subscribe_id);
-               }
-               g_mutex_unlock(&hcamcorder->gdbus_info_sound.sync_mutex);
-
-               g_mutex_lock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-               if (hcamcorder->gdbus_info_solo_sound.subscribe_id > 0) {
-                       MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_solo_sound.subscribe_id);
-                       g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
-               }
-               g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-       }
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -2283,14 +2281,27 @@ int _mmcamcorder_stop_focusing(MMHandleType handle)
        }
 }
 
-int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
+int _mmcamcorder_get_exposure(MMHandleType handle, int *exposure)
 {
+       int ret = MM_ERROR_NONE;
+       int state = MM_CAMCORDER_STATE_NONE;
        GstCameraControl *control = NULL;
        _MMCamcorderSubContext *sc = NULL;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-       mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       mmf_return_val_if_fail(exposure, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       state = _mmcamcorder_get_state(handle);
+       if (state < MM_CAMCORDER_STATE_READY) {
+               ret = mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_CAMERA_EXPOSURE_VALUE, exposure,
+                       NULL);
+
+               MMCAM_LOG_INFO("exposure[%d] from attribute[ret:0x%x]", *exposure, ret);
+
+               return ret;
+       }
 
        sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
@@ -2306,17 +2317,16 @@ int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
                return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
        }
 
-       if (!gst_camera_control_get_focus_level(control, level)) {
-               MMCAM_LOG_ERROR("get focus level failed");
-               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       if (!gst_camera_control_get_exposure(control, GST_CAMERA_CONTROL_EXPOSURE_VALUE, exposure, NULL)) {
+               MMCAM_LOG_ERROR("get exposure failed");
+               return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
-       MMCAM_LOG_INFO("focus level[%d]", *level);
+       MMCAM_LOG_INFO("exposure[%d] from device", *exposure);
 
        return MM_ERROR_NONE;
 }
 
-
 /*-----------------------------------------------
 |        CAMCORDER INTERNAL LOCAL              |
 -----------------------------------------------*/
@@ -2595,6 +2605,8 @@ int _mmcamcorder_set_functions(MMHandleType handle, int type)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
        /*MMCAM_LOG_INFO("");*/
 
        switch (type) {