From fed7ec717ccbc554ac5c5dc4eacaf813cf1ec463 Mon Sep 17 00:00:00 2001 From: Hyuntae Kim Date: Mon, 13 Jul 2020 09:36:35 +0900 Subject: [PATCH] Resolution changes for encoded frame without pipeline pause, resume Change-Id: Ib3e644d5e7012dd7d4e6fd83e142ee7438f63817 --- packaging/libmm-camcorder.spec | 4 ++-- src/include/mm_camcorder_util.h | 4 ++++ src/mm_camcorder_attribute.c | 12 +++++++---- src/mm_camcorder_gstcommon.c | 36 +++++++++++++++++---------------- src/mm_camcorder_util.c | 6 ++++++ 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/packaging/libmm-camcorder.spec b/packaging/libmm-camcorder.spec index 4d7f0c4..3fd96f7 100644 --- a/packaging/libmm-camcorder.spec +++ b/packaging/libmm-camcorder.spec @@ -1,7 +1,7 @@ Name: libmm-camcorder Summary: Camera and recorder library -Version: 0.10.205 -Release: 1 +Version: 0.10.206 +Release: 0 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/include/mm_camcorder_util.h b/src/include/mm_camcorder_util.h index 786c575..409215e 100644 --- a/src/include/mm_camcorder_util.h +++ b/src/include/mm_camcorder_util.h @@ -322,6 +322,10 @@ void _mmcamcorder_emit_dbus_signal(GDBusConnection *conn, const char *object_nam /* audio buffer */ int _mmcamcorder_get_audiosrc_blocksize(int samplerate, int format, int channel, int interval, int *blocksize); +/* check encoded pixel format */ +gboolean _mmcamcorder_is_encoded_preview_pixel_format(int pixel_format); + + #ifdef __cplusplus } #endif diff --git a/src/mm_camcorder_attribute.c b/src/mm_camcorder_attribute.c index fbbb11a..192d3ea 100644 --- a/src/mm_camcorder_attribute.c +++ b/src/mm_camcorder_attribute.c @@ -2371,7 +2371,8 @@ bool _mmcamcorder_commit_camera_width(MMHandleType handle, int attr_idx, const M MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); - _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY); + if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format)) + _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY); /* check decoder recreation */ if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) { @@ -2388,7 +2389,8 @@ bool _mmcamcorder_commit_camera_width(MMHandleType handle, int attr_idx, const M 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); - _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); + if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format)) + _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); /* unlock */ g_mutex_unlock(&hcamcorder->restart_preview_lock); @@ -2468,7 +2470,8 @@ bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); - _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY); + if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format)) + _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY); /* check decoder recreation */ if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) { @@ -2486,7 +2489,8 @@ bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const 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); - _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); + if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format)) + _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); /* unlock */ g_mutex_unlock(&hcamcorder->restart_preview_lock); diff --git a/src/mm_camcorder_gstcommon.c b/src/mm_camcorder_gstcommon.c index fb01c73..19dbcc8 100644 --- a/src/mm_camcorder_gstcommon.c +++ b/src/mm_camcorder_gstcommon.c @@ -154,7 +154,6 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate); static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name); -static inline bool __mmcamcorder_is_encoded_preview_pixel_format(int pixel_format); #ifdef _MMCAMCORDER_PRODUCT_TV static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height); #endif /* _MMCAMCORDER_PRODUCT_TV */ @@ -329,7 +328,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) } } - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { /* get recreate_decoder flag */ _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT, @@ -892,7 +891,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin /* set capsfilter */ if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) { - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { _mmcam_dbg_log("get pad from videosrc_filter"); pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src"); } else { @@ -1027,7 +1026,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin goto pipeline_creation_error; } - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { /* set dummy element */ gst_element_venc_name = "identity"; } else { @@ -1349,7 +1348,7 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle) } /* set dataprobe for video recording */ - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src"); else srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src"); @@ -1761,7 +1760,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP GstMemory *memory = NULL; GstMapInfo mapinfo; - if (!__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + if (!_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { state = _mmcamcorder_get_state((MMHandleType)hcamcorder); if (state < MM_CAMCORDER_STATE_PREPARE) { _mmcam_dbg_warn("Not ready for stream callback"); @@ -1814,7 +1813,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP } /* set size and timestamp */ - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) memory = gst_buffer_get_all_memory(buffer); else memory = gst_buffer_peek_memory(buffer, 0); @@ -2017,7 +2016,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP /* unmap memory */ if (mapinfo.data) gst_memory_unmap(memory, &mapinfo); - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) gst_memory_unref(memory); } @@ -2716,7 +2715,7 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in gst_structure_get_int(structure, "rotate", &caps_rotate); #ifdef _MMCAMCORDER_PRODUCT_TV - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { if (set_width == caps_width && set_height == caps_height && set_rotate == caps_rotate && fps == caps_fps) { _mmcam_dbg_log("No need to replace caps."); @@ -3108,6 +3107,7 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle) _MMCamcorderSubContext *sc = NULL; mmf_camcorder_t *hcamcorder = NULL; const char *videodecoder_name = NULL; + int display_surface_type = MM_DISPLAY_SURFACE_NULL; #ifdef _MMCAMCORDER_RM_SUPPORT char decoder_name[20] = {'\0',}; int decoder_index = 0; @@ -3126,13 +3126,22 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle) return FALSE; } - if (__mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false || + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false || hcamcorder->recreate_decoder == FALSE) { _mmcam_dbg_log("skip this fuction - format %d, recreate decoder %d", sc->info_image->preview_format, hcamcorder->recreate_decoder); return TRUE; } + mm_camcorder_get_attributes(handle, NULL, + MMCAM_DISPLAY_SURFACE, &display_surface_type, + NULL); + + if (display_surface_type == MM_DISPLAY_SURFACE_NULL) { + _mmcam_dbg_log("no need to control decoder element"); + return TRUE; + } + if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL || sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) { _mmcam_dbg_warn("main pipeline or decoder plugin is NULL"); @@ -3241,13 +3250,6 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle) return TRUE; } -static inline bool __mmcamcorder_is_encoded_preview_pixel_format(int pixel_format) { - if (pixel_format == MM_PIXEL_FORMAT_ENCODED_H264 || pixel_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) - return true; - - return false; -} - #ifdef _MMCAMCORDER_PRODUCT_TV static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height) { diff --git a/src/mm_camcorder_util.c b/src/mm_camcorder_util.c index ec1cf78..290dce3 100644 --- a/src/mm_camcorder_util.c +++ b/src/mm_camcorder_util.c @@ -2389,3 +2389,9 @@ int _mmcamcorder_get_audiosrc_blocksize(int samplerate, int format, int channel, return TRUE; } + +gboolean _mmcamcorder_is_encoded_preview_pixel_format(int pixel_format) +{ + return (pixel_format == MM_PIXEL_FORMAT_ENCODED_H264 || + pixel_format == MM_PIXEL_FORMAT_ENCODED_MJPEG); +} -- 2.34.1