#include <stdlib.h>
#include <sys/time.h>
#include <sys/times.h>
-#include <gst/video/cameracontrol.h>
#include "mm_camcorder_internal.h"
#include "mm_camcorder_stillshot.h"
#include "mm_camcorder_exifinfo.h"
}
-int _mmcamcorder_connect_extra_preview_stream(MMHandleType handle)
+int _mmcamcorder_initialize_extra_preview_stream(MMHandleType handle)
{
+ int i = 0;
mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
_MMCamcorderSubContext *sc = NULL;
+ GstCameraControl *control = NULL;
+ _MMCamcorderExtraPreviewStreamFormat *e_fmt = NULL;
mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
G_CALLBACK(__mmcamcorder_extra_preview_stream_cb),
hcamcorder);
+ control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+ if (!control) {
+ MMCAM_LOG_ERROR("no camera control");
+ return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+ }
+
+ for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_NUM ; i++) {
+ e_fmt = &hcamcorder->extra_preview_format[i];
+
+ 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);
+
+ 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 (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;
}
if (sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst) {
ret = _mmcamcorder_gst_set_state(handle, sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_NULL);
if (ret != MM_ERROR_NONE) {
- MMCAM_LOG_ERROR("Faile to change encode main pipeline state [0x%x]", ret);
+ MMCAM_LOG_ERROR("Failed to change encode main pipeline state [0x%x]", ret);
return ret;
}
_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);
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);
return;
}
+
+
+int _mmcamcorder_set_extra_preview_stream_format(MMHandleType camcorder, int stream_id, int pixel_format, int width, int height, int fps)
+{
+ 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);
+ mmf_return_val_if_fail(pixel_format > MM_PIXEL_FORMAT_INVALID && pixel_format < MM_PIXEL_FORMAT_NUM,
+ MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+ mmf_return_val_if_fail(width > 0 && height > 0 && fps >= 0, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ mm_camcorder_get_state(camcorder, ¤t_state);
+
+ MMCAM_LOG_INFO("state[%d] stream_id[%d],fmt[%d],res[%dx%d],fps[%d]",
+ current_state, stream_id, pixel_format, width, height, fps);
+
+ 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_stream_format(control,
+ stream_id, _mmcamcorder_get_camera_control_image_format(pixel_format), width, height, fps)) {
+ MMCAM_LOG_ERROR("camera control failed");
+ 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_format = TRUE;
+ }
+
+ hcamcorder->extra_preview_format[stream_id].pixel_format = pixel_format;
+ hcamcorder->extra_preview_format[stream_id].width = width;
+ hcamcorder->extra_preview_format[stream_id].height = height;
+ hcamcorder->extra_preview_format[stream_id].fps = fps;
+
+ return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_get_extra_preview_stream_format(MMHandleType camcorder, int stream_id, int *pixel_format, int *width, int *height, int *fps)
+{
+ int _width = 0;
+ int _height = 0;
+ int _fps = 0;
+ GstCameraControlImageFormat _img_fmt = GST_CAMERA_CONTROL_IMAGE_FORMAT_NV12;
+ 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(pixel_format && width && height && fps, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ mm_camcorder_get_state(camcorder, ¤t_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_stream_format(control,
+ stream_id, &_img_fmt, &_width, &_height, &_fps)) {
+ MMCAM_LOG_ERROR("extra preview stream format get failed");
+ return MM_ERROR_CAMCORDER_INTERNAL;
+ }
+
+ *pixel_format = _mmcamcorder_get_pixel_format2(_img_fmt);
+ *width = _width;
+ *height = _height;
+ *fps = _fps;
+ } else {
+ *pixel_format = hcamcorder->extra_preview_format[stream_id].pixel_format;
+ *width = hcamcorder->extra_preview_format[stream_id].width;
+ *height = hcamcorder->extra_preview_format[stream_id].height;
+ *fps = hcamcorder->extra_preview_format[stream_id].fps;
+ }
+
+ MMCAM_LOG_INFO("get result[fmt:%d(%d),res:%dx%d,fps:%d][state:%d]",
+ *pixel_format, _img_fmt, *width, *height, *fps, current_state);
+
+ return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int bitrate)
+{
+ 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);
+ mmf_return_val_if_fail(bitrate > 0, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ mm_camcorder_get_state(camcorder, ¤t_state);
+
+ 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);
+ 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_bitrate(control, stream_id, bitrate)) {
+ MMCAM_LOG_ERROR("set bitrate[%d] for stream[%d] failed", bitrate, 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_bitrate = TRUE;
+ }
+
+ hcamcorder->extra_preview_format[stream_id].bitrate = bitrate;
+
+ return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_get_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int *bitrate)
+{
+ int _bitrate = 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(bitrate, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ mm_camcorder_get_state(camcorder, ¤t_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_bitrate(control, stream_id, &_bitrate)) {
+ MMCAM_LOG_ERROR("get bitrate for stream[%d] failed", stream_id);
+ return MM_ERROR_CAMCORDER_INTERNAL;
+ }
+
+ *bitrate = _bitrate;
+ } else {
+ *bitrate = hcamcorder->extra_preview_format[stream_id].bitrate;
+ }
+
+ 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, ¤t_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, ¤t_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;
+}