Support zero-copy with encoded format
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 3920cbc..27a683d 100644 (file)
@@ -36,7 +36,6 @@
 #include <mm_types.h>
 
 #include <gst/video/colorbalance.h>
-#include <gst/video/cameracontrol.h>
 #include <asm/types.h>
 
 #include <system_info.h>
@@ -49,7 +48,7 @@
 |    LOCAL VARIABLE DEFINITIONS for internal                                           |
 ---------------------------------------------------------------------------------------*/
 #define __MMCAMCORDER_CMD_ITERATE_MAX           3
-#define __MMCAMCORDER_SET_GST_STATE_TIMEOUT     5
+#define __MMCAMCORDER_SET_GST_STATE_TIMEOUT     10
 #define __MMCAMCORDER_FORCE_STOP_TRY_COUNT      30
 #define __MMCAMCORDER_FORCE_STOP_WAIT_TIME      100000  /* us */
 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT        3
@@ -343,27 +342,34 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
 
+       if (hcamcorder->is_network) {
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s_network.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX);
+       } else {
 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
-       snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
-       memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
-       ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
-               &hcamcorder->conf_device_info);
-       if (ret_conf !=  CAMERA_CONF_MGR_ERROR_NONE) {
-               MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
-               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
-       }
+               snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
+               memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
+               ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
+                       &hcamcorder->conf_device_info);
+               if (ret_conf !=  CAMERA_CONF_MGR_ERROR_NONE) {
+                       MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
+                       return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+               }
 
-       snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
-               CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
-               hcamcorder->conf_device_info.product_id);
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
+                       hcamcorder->conf_device_info.product_id);
 
-       MMCAM_LOG_INFO("Load control configure file [%d][%s][%s]", hcamcorder->device_type,
-               conf_file_name, hcamcorder->conf_device_info.node);
+               MMCAM_LOG_INFO("device info : node[%s]",
+                       hcamcorder->conf_device_info.node);
 #else
-       snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
-               CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
-       MMCAM_LOG_INFO("Load control configure file [%d][%s]", hcamcorder->device_type, conf_file_name);
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
 #endif
+       }
+
+       MMCAM_LOG_INFO("Load control configure file [%d][%s]",
+               hcamcorder->device_type, conf_file_name);
 
        ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
                CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
@@ -469,6 +475,11 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                "MeasurePreviewFPS",
                &hcamcorder->measure_preview_fps);
 
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "DefaultEncodedPreviewBitrate",
+               &hcamcorder->default_encoded_preview_bitrate);
+
        ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
                MMCAM_CAMERA_WIDTH, &resolution_width,
                MMCAM_CAMERA_HEIGHT, &resolution_height,
@@ -484,10 +495,11 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
-       MMCAM_LOG_INFO("ZC %d, UB %d, VC %d, MPPC %d, EP %d, MPFPS %d",
+       MMCAM_LOG_INFO("ZC %d, UB %d, VC %d, MPPC %d, EP %d, MPFPS %d, DEPB %d",
                hcamcorder->use_zero_copy_format, hcamcorder->support_user_buffer,
                hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb,
-               hcamcorder->support_extra_preview, hcamcorder->measure_preview_fps);
+               hcamcorder->support_extra_preview, hcamcorder->measure_preview_fps,
+               hcamcorder->default_encoded_preview_bitrate);
 
        MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
                resolution_width, resolution_height, fps_info.int_array.def);
@@ -524,11 +536,13 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
                MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
                MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
+               MMCAM_SUPPORT_EXTRA_PREVIEW, hcamcorder->support_extra_preview,
                MMCAM_CAMERA_FPS, fps_info.int_array.def,
                MMCAM_DISPLAY_FLIP, camera_default_flip,
                MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
                MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
                        platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
+               MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
                NULL);
        if (ret != MM_ERROR_NONE) {
                MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
@@ -2283,6 +2297,39 @@ int _mmcamcorder_stop_focusing(MMHandleType handle)
        }
 }
 
+int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
+{
+       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);
+
+       sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
+       mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+       if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
+               MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+       if (!control) {
+               MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
+               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;
+       }
+
+       MMCAM_LOG_INFO("focus level[%d]", *level);
+
+       return MM_ERROR_NONE;
+}
+
 
 /*-----------------------------------------------
 |        CAMCORDER INTERNAL LOCAL              |
@@ -3095,7 +3142,7 @@ int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
                }
 
                if (hcamcorder->support_extra_preview &&
-                       _mmcamcorder_connect_extra_preview_stream(handle) != MM_ERROR_NONE)
+                       _mmcamcorder_initialize_extra_preview_stream(handle) != MM_ERROR_NONE)
                        MMCAM_LOG_WARNING("connect extra preview stream signal failed");
                break;
        }