From dc6b729fca334c6a263aa4496f90e2f740c02285 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 15 Sep 2021 14:12:17 +0900 Subject: [PATCH] Add new functions for extra preview GOP interval [Version] 0.10.246 [Issue Type] New feature Change-Id: I6e9520a0e84b31272adf5eb1e5e891302e1b1b84 Signed-off-by: Jeongmo Yang --- packaging/libmm-camcorder.spec | 2 +- src/include/mm_camcorder.h | 2 + src/include/mm_camcorder_internal.h | 5 +- src/include/mm_camcorder_stillshot.h | 2 + src/mm_camcorder.c | 10 +++ src/mm_camcorder_stillshot.c | 125 ++++++++++++++++++++++----- 6 files changed, 124 insertions(+), 22 deletions(-) diff --git a/packaging/libmm-camcorder.spec b/packaging/libmm-camcorder.spec index dc8a088..87c0f61 100755 --- a/packaging/libmm-camcorder.spec +++ b/packaging/libmm-camcorder.spec @@ -1,6 +1,6 @@ Name: libmm-camcorder Summary: Camera and recorder library -Version: 0.10.245 +Version: 0.10.246 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/include/mm_camcorder.h b/src/include/mm_camcorder.h index 2ac283a..c6b915b 100644 --- a/src/include/mm_camcorder.h +++ b/src/include/mm_camcorder.h @@ -3460,6 +3460,8 @@ int mm_camcorder_set_extra_preview_stream_format(MMHandleType camcorder, int str int mm_camcorder_get_extra_preview_stream_format(MMHandleType camcorder, int stream_id, int *pixel_format, int *width, int *height, int *fps); int mm_camcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int bitrate); int mm_camcorder_get_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int *bitrate); +int mm_camcorder_set_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int interval); +int mm_camcorder_get_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int *interval); /** @} diff --git a/src/include/mm_camcorder_internal.h b/src/include/mm_camcorder_internal.h index 2430057..9fc3273 100644 --- a/src/include/mm_camcorder_internal.h +++ b/src/include/mm_camcorder_internal.h @@ -684,7 +684,10 @@ typedef struct { int height; int fps; int bitrate; - gboolean need_to_set; + int gop_interval; + gboolean need_to_set_format; + gboolean need_to_set_bitrate; + gboolean need_to_set_gop_interval; } _MMCamcorderExtraPreviewStreamFormat; /** diff --git a/src/include/mm_camcorder_stillshot.h b/src/include/mm_camcorder_stillshot.h index 121a890..107cc6d 100644 --- a/src/include/mm_camcorder_stillshot.h +++ b/src/include/mm_camcorder_stillshot.h @@ -149,6 +149,8 @@ int _mmcamcorder_set_extra_preview_stream_format(MMHandleType camcorder, int str int _mmcamcorder_get_extra_preview_stream_format(MMHandleType camcorder, int stream_id, int *pixel_format, int *width, int *height, int *fps); int _mmcamcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int bitrate); int _mmcamcorder_get_extra_preview_bitrate(MMHandleType camcorder, int stream_id, int *bitrate); +int _mmcamcorder_set_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int interval); +int _mmcamcorder_get_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int *interval); #ifdef __cplusplus } diff --git a/src/mm_camcorder.c b/src/mm_camcorder.c index 4e903ee..9c2b190 100644 --- a/src/mm_camcorder.c +++ b/src/mm_camcorder.c @@ -501,3 +501,13 @@ int mm_camcorder_get_extra_preview_bitrate(MMHandleType camcorder, int stream_id { return _mmcamcorder_get_extra_preview_bitrate(camcorder, stream_id, bitrate); } + +int mm_camcorder_set_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int interval) +{ + return _mmcamcorder_set_extra_preview_gop_interval(camcorder, stream_id, interval); +} + +int mm_camcorder_get_extra_preview_gop_interval(MMHandleType camcorder, int stream_id, int *interval) +{ + return _mmcamcorder_get_extra_preview_gop_interval(camcorder, stream_id, interval); +} diff --git a/src/mm_camcorder_stillshot.c b/src/mm_camcorder_stillshot.c index 8d01346..340a6d7 100644 --- a/src/mm_camcorder_stillshot.c +++ b/src/mm_camcorder_stillshot.c @@ -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; @@ -854,13 +866,11 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle) 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); - } + 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_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); @@ -2972,7 +2982,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 +3055,7 @@ int _mmcamcorder_set_extra_preview_bitrate(MMHandleType camcorder, int stream_id mm_camcorder_get_state(camcorder, ¤t_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 +3068,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 +3108,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, ¤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; } -- 2.34.1