Support raw image capture with encodebin
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_stillshot.c
index 414e6af..7fece95 100644 (file)
@@ -26,7 +26,6 @@
 #include <sys/time.h>
 #include <sys/times.h>
 #include <gst/video/cameracontrol.h>
-#include <mm_sound.h>
 #include "mm_camcorder_internal.h"
 #include "mm_camcorder_stillshot.h"
 #include "mm_camcorder_exifinfo.h"
@@ -265,7 +264,7 @@ void _mmcamcorder_destroy_video_capture_pipeline(MMHandleType handle)
                /* set sink element pointer to attribute */
                mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
                attr_item = &attrs->items[attr_index];
-               mmf_attribute_set_data(attr_item, (void *)sink_element, sizeof(sink_element));
+               mmf_attribute_set_data(attr_item, (void *)sink_element, sizeof(*sink_element));
                mmf_attribute_commit(attr_item);
 
                /* remove notify callback */
@@ -385,7 +384,7 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle)
                info->next_shot_time = 0;
                info->multi_shot_stop = FALSE;
 
-               /* sound init to pause other session */
+               /* sound init */
                _mmcamcorder_sound_init(handle);
        }
 
@@ -530,6 +529,9 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle)
 
                        info->resolution_change = TRUE;
 
+                       /* set frame stability count for capture */
+                       _mmcamcorder_video_frame_stabilize(handle, _MMCamcorder_CMD_CAPTURE);
+
                        /* make pipeline state as PLAYING */
                        ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING);
                        if (ret != MM_ERROR_NONE) {
@@ -652,8 +654,6 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle)
        info->multi_shot_stop = TRUE;
        info->capturing = FALSE;
 
-       _mmcamcorder_vframe_stablize(handle);
-
        current_state = _mmcamcorder_get_state(handle);
        _mmcam_dbg_log("current state [%d]", current_state);
 
@@ -783,6 +783,9 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle)
                                        goto cmd_error;
                                }
 
+                               /* set frame stability count for preview */
+                               _mmcamcorder_video_frame_stabilize(handle, _MMCamcorder_CMD_PREVIEW_START);
+
                                ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING);
                                if (ret != MM_ERROR_NONE)
                                        goto cmd_error;
@@ -801,6 +804,9 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle)
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE);
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE);
 
+               /* set frame stability count for preview */
+               _mmcamcorder_video_frame_stabilize(handle, _MMCamcorder_CMD_PREVIEW_START);
+
                traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:START:SET_PLAYING_TO_PIPELINE");
 
                ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING);
@@ -1202,7 +1208,9 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sampl
 
        /* check capture state */
        if (info->type == _MMCamcorder_MULTI_SHOT && info->capture_send_count > 0)
-               mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL, "capture-break-cont-shot", &stop_cont_shot, NULL);
+               mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
+                       MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, &stop_cont_shot,
+                       NULL);
 
        if (!info->capturing || stop_cont_shot) {
                _mmcam_dbg_warn("stop command[%d] or not capturing state[%d]. skip this...", stop_cont_shot, info->capturing);
@@ -1395,9 +1403,9 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sampl
 
                /* encode thumbnail */
                if (encode_src.data) {
+                       size_t thumb_length = 0;
                        unsigned int thumb_width = 0;
                        unsigned int thumb_height = 0;
-                       unsigned int thumb_length = 0;
                        unsigned char *thumb_raw_data = NULL;
 
                        /* encode image */
@@ -1497,6 +1505,11 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sampl
                _mmcam_dbg_log("Done Internal Encode - data %p, length %d", dest.data, dest.length);
        }
 
+       if (pixtype_main < MM_PIXEL_FORMAT_ENCODED) {
+               _mmcam_dbg_log("raw capture, skip EXIF related functions");
+               goto _CAPTURE_CB_EXIF_DONE;
+       }
+
        /* create EXIF info */
        if (!provide_exif) {    /* make new exif */
                ret = mm_exif_create_exif_info(&(hcamcorder->exif_info));
@@ -1552,32 +1565,32 @@ static void __mmcamcorder_image_capture_cb(GstElement *element, GstSample *sampl
        mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL, MMCAM_TAG_ENABLE, &tag_enable, NULL);
 
        /* Set extra data for JPEG if tag enabled and doesn't provide EXIF */
-       if (dest.format == MM_PIXEL_FORMAT_ENCODED) {
-               if (tag_enable) {
-                       mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
-                               MMCAM_IMAGE_ENCODER, &codectype,
-                               NULL);
-                       _mmcam_dbg_log("codectype %d", codectype);
+       if (tag_enable) {
+               mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
+                       MMCAM_IMAGE_ENCODER, &codectype,
+                       NULL);
+               _mmcam_dbg_log("codectype %d", codectype);
 
-                       switch (codectype) {
-                       case MM_IMAGE_CODEC_JPEG:
-                       case MM_IMAGE_CODEC_SRW:
-                       case MM_IMAGE_CODEC_JPEG_SRW:
-                               ret = __mmcamcorder_set_jpeg_data((MMHandleType)hcamcorder, &dest, &thumb, provide_exif);
-                               if (ret != MM_ERROR_NONE) {
-                                       _mmcam_dbg_err("Error on setting extra data to jpeg");
-                                       MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, ret);
-                                       goto error;
-                               }
-                               break;
-                       default:
-                               _mmcam_dbg_err("The codectype is not supported. (%d)", codectype);
-                               MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, MM_ERROR_CAMCORDER_INTERNAL);
+               switch (codectype) {
+               case MM_IMAGE_CODEC_JPEG:
+               case MM_IMAGE_CODEC_SRW:
+               case MM_IMAGE_CODEC_JPEG_SRW:
+                       ret = __mmcamcorder_set_jpeg_data((MMHandleType)hcamcorder, &dest, &thumb, provide_exif);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("Error on setting extra data to jpeg");
+                               MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, ret);
                                goto error;
                        }
+                       break;
+               default:
+                       _mmcam_dbg_err("The codectype is not supported. (%d)", codectype);
+                       MMCAM_SEND_MESSAGE(hcamcorder, MM_MESSAGE_CAMCORDER_ERROR, MM_ERROR_CAMCORDER_INTERNAL);
+                       goto error;
                }
        }
 
+_CAPTURE_CB_EXIF_DONE:
+
        /* Handle Capture Callback */
        _MMCAMCORDER_LOCK_VCAPTURE_CALLBACK(hcamcorder);
 
@@ -1769,8 +1782,7 @@ static ExifData *__mmcamcorder_update_exif_make(MMHandleType handle, ExifData *e
                if (ret != MM_ERROR_NONE)
                        EXIF_SET_ERR(ret, EXIF_TAG_MAKE);
        } else {
-               ret = MM_ERROR_CAMCORDER_LOW_MEMORY;
-               EXIF_SET_ERR(ret, EXIF_TAG_MAKE);
+               _mmcam_dbg_err("strdup failed [%s]", MM_MAKER_NAME);
        }
 
 exit: