Replace gst_structure_get_int() by gst_structure_get()
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_stillshot.c
index 8d01346..b2ac5c2 100644 (file)
@@ -188,17 +188,29 @@ int _mmcamcorder_initialize_extra_preview_stream(MMHandleType handle)
        for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_NUM ; i++) {
                e_fmt = &hcamcorder->extra_preview_format[i];
 
-               if (!e_fmt->need_to_set)
-                       continue;
+               if (e_fmt->need_to_set_format) {
+                       if (!gst_camera_control_set_extra_preview_stream_format(control,
+                               i, _mmcamcorder_get_pixel_format2(e_fmt->pixel_format),
+                               e_fmt->width, e_fmt->height, e_fmt->fps))
+                               MMCAM_LOG_WARNING("set format[%d,%dx%d,%d] failed for stream[%d]",
+                                       e_fmt->pixel_format, e_fmt->width, e_fmt->height, e_fmt->fps, i);
 
-               if (!gst_camera_control_set_extra_preview_stream_format(control,
-                       i, _mmcamcorder_get_pixel_format2(e_fmt->pixel_format),
-                       e_fmt->width, e_fmt->height, e_fmt->fps))
-                       MMCAM_LOG_WARNING("set format[%d,%dx%d,%d] failed for stream[%d]",
-                               e_fmt->pixel_format, e_fmt->width, e_fmt->height, e_fmt->fps, i);
+                       e_fmt->need_to_set_format = FALSE;
+               }
+
+               if (e_fmt->need_to_set_bitrate) {
+                       if (!gst_camera_control_set_extra_preview_bitrate(control, i, e_fmt->bitrate))
+                               MMCAM_LOG_WARNING("set bitrate[%d] failed for stream[%d]", e_fmt->bitrate, i);
+
+                       e_fmt->need_to_set_bitrate = FALSE;
+               }
 
-               if (!gst_camera_control_set_extra_preview_bitrate(control, i, e_fmt->bitrate))
-                       MMCAM_LOG_WARNING("set bitrate[%d] failed for stream[%d]", e_fmt->bitrate, i);
+               if (e_fmt->need_to_set_gop_interval) {
+                       if (!gst_camera_control_set_extra_preview_gop_interval(control, i, e_fmt->gop_interval))
+                               MMCAM_LOG_WARNING("set GOP interval[%d] failed for stream[%d]", e_fmt->gop_interval, i);
+
+                       e_fmt->need_to_set_gop_interval = FALSE;
+               }
        }
 
        return MM_ERROR_NONE;
@@ -848,19 +860,13 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle)
                        _mmcamcorder_sound_finalize(handle);
        } else {
                if (_mmcamcorder_is_encoded_preview_pixel_format(info->preview_format)) {
-                       ret = mm_camcorder_get_attributes(handle, NULL,
+                       mm_camcorder_get_attributes(handle, NULL,
                                MMCAM_ENCODED_PREVIEW_BITRATE, &bitrate,
+                               MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
                                NULL);
-                       if (ret == MM_ERROR_NONE)
-                               _mmcamcorder_set_encoded_preview_bitrate(handle, bitrate);
 
-                       if (info->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                               ret = mm_camcorder_get_attributes(handle, NULL,
-                                       MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
-                                       NULL);
-                               if (ret == MM_ERROR_NONE)
-                                       _mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval);
-                       }
+                       _mmcamcorder_set_encoded_preview_bitrate(handle, bitrate);
+                       _mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval);
                }
 
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE);
@@ -1145,8 +1151,10 @@ void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataType *capt
        gst_buffer_map(gst_sample_get_buffer(sample), &mapinfo, GST_MAP_READ);
        capture_data->data = mapinfo.data;
        capture_data->format = pixtype;
-       gst_structure_get_int(structure, "width", &capture_data->width);
-       gst_structure_get_int(structure, "height", &capture_data->height);
+       gst_structure_get(structure,
+               "width", G_TYPE_INT, &capture_data->width,
+               "height", G_TYPE_INT, &capture_data->height,
+               NULL);
        capture_data->length = mapinfo.size;
        gst_buffer_unmap(gst_sample_get_buffer(sample), &mapinfo);
 
@@ -2972,7 +2980,7 @@ int _mmcamcorder_set_extra_preview_stream_format(MMHandleType camcorder, int str
                }
        } else {
                MMCAM_LOG_INFO("It will be set when start preview");
-               hcamcorder->extra_preview_format[stream_id].need_to_set = TRUE;
+               hcamcorder->extra_preview_format[stream_id].need_to_set_format = TRUE;
        }
 
        hcamcorder->extra_preview_format[stream_id].pixel_format = pixel_format;
@@ -3045,7 +3053,7 @@ int _mmcamcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id
 
        mm_camcorder_get_state(camcorder, &current_state);
 
-       MMCAM_LOG_INFO("state[%d] stream_id[%d], bitrate[%d]", current_state, stream_id, bitrate);
+       MMCAM_LOG_INFO("state[%d] stream[%d], bitrate[%d]", current_state, stream_id, bitrate);
 
        if (current_state >= MM_CAMCORDER_STATE_READY) {
                sc = MMF_CAMCORDER_SUBCONTEXT(camcorder);
@@ -3058,7 +3066,7 @@ int _mmcamcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id
                }
        } else {
                MMCAM_LOG_INFO("It will be set when start preview");
-               hcamcorder->extra_preview_format[stream_id].need_to_set = TRUE;
+               hcamcorder->extra_preview_format[stream_id].need_to_set_bitrate = TRUE;
        }
 
        hcamcorder->extra_preview_format[stream_id].bitrate = bitrate;
@@ -3098,7 +3106,82 @@ int _mmcamcorder_get_extra_preview_bitrate(MMHandleType camcorder, int stream_id
                *bitrate = hcamcorder->extra_preview_format[stream_id].bitrate;
        }
 
-       MMCAM_LOG_INFO("get bitrate[%d] for stream[%d][state:%d]", *bitrate, stream_id, current_state);
+       MMCAM_LOG_INFO("get bitrate[%d] for stream[%d][state:%d]",
+               *bitrate, stream_id, current_state);
+
+       return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_set_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int interval)
+{
+       mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *)camcorder;
+       MMCamcorderStateType current_state = MM_CAMCORDER_STATE_NONE;
+       GstCameraControl *control = NULL;
+       _MMCamcorderSubContext *sc = NULL;
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       mmf_return_val_if_fail(hcamcorder->support_extra_preview, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+       mmf_return_val_if_fail(stream_id >= 0 && stream_id < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_NUM,
+               MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       mm_camcorder_get_state(camcorder, &current_state);
+
+       MMCAM_LOG_INFO("state[%d] stream[%d], interval[%d]", current_state, stream_id, interval);
+
+       if (current_state >= MM_CAMCORDER_STATE_READY) {
+               sc = MMF_CAMCORDER_SUBCONTEXT(camcorder);
+               mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+               control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+               if (!gst_camera_control_set_extra_preview_gop_interval(control, stream_id, interval)) {
+                       MMCAM_LOG_ERROR("set GOP interval[%d] for stream[%d] failed", interval, stream_id);
+                       return MM_ERROR_CAMCORDER_INTERNAL;
+               }
+       } else {
+               MMCAM_LOG_INFO("It will be set when start preview");
+               hcamcorder->extra_preview_format[stream_id].need_to_set_gop_interval = TRUE;
+       }
+
+       hcamcorder->extra_preview_format[stream_id].gop_interval = interval;
+
+       return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_get_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int *interval)
+{
+       int _interval = 0;
+       GstCameraControl *control = NULL;
+       mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *)camcorder;
+       MMCamcorderStateType current_state = MM_CAMCORDER_STATE_NONE;
+       _MMCamcorderSubContext *sc = NULL;
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       mmf_return_val_if_fail(hcamcorder->support_extra_preview, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+       mmf_return_val_if_fail(stream_id >= 0 && stream_id < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_NUM,
+               MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+       mmf_return_val_if_fail(interval, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       mm_camcorder_get_state(camcorder, &current_state);
+
+       if (current_state >= MM_CAMCORDER_STATE_READY) {
+               sc = MMF_CAMCORDER_SUBCONTEXT(camcorder);
+               mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+               control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+               if (!gst_camera_control_get_extra_preview_gop_interval(control, stream_id, &_interval)) {
+                       MMCAM_LOG_ERROR("get GOP interval for stream[%d] failed", stream_id);
+                       return MM_ERROR_CAMCORDER_INTERNAL;
+               }
+
+               *interval = _interval;
+       } else {
+               *interval = hcamcorder->extra_preview_format[stream_id].gop_interval;
+       }
+
+       MMCAM_LOG_INFO("get GOP interval[%d] for stream[%d][state:%d]",
+               *interval, stream_id, current_state);
 
        return MM_ERROR_NONE;
 }