From c5c7baebae64a49f39813925fa8254af43755d21 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 7 Nov 2024 14:14:43 +0900 Subject: [PATCH] Update supported FPS when resolution is changed - Previously, unsupported FPS could be used after resolution is changed. - The FPS list can be different by resolution, then it should be checked and updated if needed. [Version] 1.3.2 [Issue Type] Improvement Change-Id: I5774006e5e24810976261f58e4562497cdd19eca Signed-off-by: Jeongmo Yang --- packaging/libmm-camcorder.spec | 2 +- src/include/mm_camcorder_configure.h | 1 + src/include/mm_camcorder_internal.h | 6 ++++ src/include/mm_camcorder_util.h | 3 ++ src/mm_camcorder_attribute.c | 44 ++++++++++++++++------------ src/mm_camcorder_capability.c | 23 +++++---------- src/mm_camcorder_configure.c | 37 +++++++++++++++++++++++ src/mm_camcorder_platform.c | 8 ++--- src/mm_camcorder_util.c | 27 +++++++++++++++++ 9 files changed, 111 insertions(+), 40 deletions(-) diff --git a/packaging/libmm-camcorder.spec b/packaging/libmm-camcorder.spec index bd8aada..590112c 100755 --- a/packaging/libmm-camcorder.spec +++ b/packaging/libmm-camcorder.spec @@ -1,6 +1,6 @@ Name: libmm-camcorder Summary: Camera and recorder library -Version: 1.3.1 +Version: 1.3.2 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/include/mm_camcorder_configure.h b/src/include/mm_camcorder_configure.h index 278b2bf..f9619a4 100644 --- a/src/include/mm_camcorder_configure.h +++ b/src/include/mm_camcorder_configure.h @@ -400,6 +400,7 @@ int _mmcamcorder_conf_get_default_element(MMHandleType handle, int type, int cat int _mmcamcorder_conf_get_category_size(MMHandleType handle, int type, int category, int *size); void _mmcamcorder_conf_get_element_and_name(MMHandleType handle, camera_conf *configure_info, int category, const char *name, type_element **element, const char **element_name); +int _mmcamcorder_conf_update_preview_fps(MMHandleType handle, int width, int height); #ifdef __cplusplus } diff --git a/src/include/mm_camcorder_internal.h b/src/include/mm_camcorder_internal.h index b2ce52c..c3c130a 100644 --- a/src/include/mm_camcorder_internal.h +++ b/src/include/mm_camcorder_internal.h @@ -94,6 +94,12 @@ extern "C" { return (val); \ } +#define mmf_return_val_if_fail_warning(expr, val) \ + if (!(expr)) { \ + MMCAM_LOG_WARNING("failed [%s]", #expr); \ + return (val); \ + } + #ifndef ARRAY_SIZE /** diff --git a/src/include/mm_camcorder_util.h b/src/include/mm_camcorder_util.h index 7e7eb49..bc4e6de 100644 --- a/src/include/mm_camcorder_util.h +++ b/src/include/mm_camcorder_util.h @@ -319,6 +319,9 @@ gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_wid gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height, unsigned char **dst, unsigned int dst_width, unsigned int dst_height); +/* Camera preview */ +int _mmcamcorder_set_fps_on_preview_resolution_update(MMHandleType handle, int new_fps); + /* Recording */ /* find top level tag only, do not use this function for finding sub level tags. tag_fourcc is Four-character-code (FOURCC) */ diff --git a/src/mm_camcorder_attribute.c b/src/mm_camcorder_attribute.c index 6a346f7..49866cb 100644 --- a/src/mm_camcorder_attribute.c +++ b/src/mm_camcorder_attribute.c @@ -2392,8 +2392,8 @@ bool _mmcamcorder_commit_camera_fps(MMHandleType handle, int attr_idx, const MMA { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); MMCamAttrsInfo fps_info; - int resolution_width = 0; - int resolution_height = 0; + int width = 0; + int height = 0; int i = 0; int ret = 0; int current_state = MM_CAMCORDER_STATE_NONE; @@ -2418,8 +2418,8 @@ bool _mmcamcorder_commit_camera_fps(MMHandleType handle, int attr_idx, const MMA } ret = mm_camcorder_get_attributes(handle, NULL, - MMCAM_CAMERA_WIDTH, &resolution_width, - MMCAM_CAMERA_HEIGHT, &resolution_height, + MMCAM_CAMERA_WIDTH, &width, + MMCAM_CAMERA_HEIGHT, &height, NULL); if (ret != MM_ERROR_NONE) { @@ -2427,9 +2427,9 @@ bool _mmcamcorder_commit_camera_fps(MMHandleType handle, int attr_idx, const MMA return FALSE; } - ret = mm_camcorder_get_fps_list_by_resolution(handle, resolution_width, resolution_height, &fps_info); + ret = mm_camcorder_get_fps_list_by_resolution(handle, width, height, &fps_info); if (ret != MM_ERROR_NONE) { - MMCAM_LOG_ERROR("FAILED : coult not get FPS values by resolution."); + MMCAM_LOG_ERROR("FAILED : FPS list by resolution[%dx%d]", width, height); return FALSE; } @@ -2624,22 +2624,28 @@ bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const sc->info_video->preview_width = width; sc->info_video->preview_height = height; - /* update FPS from capability */ - if (hcamcorder->is_configured && hcamcorder->mmcam_capability) { - mm_ret = _mmcamcorder_capability_update_capability_resolution(handle, width, height); - if (mm_ret != MM_ERROR_NONE) { - MMCAM_LOG_ERROR("update capability resolution failed[0x%x]", mm_ret); - return false; - } + /* update FPS */ + do { + if (!hcamcorder->is_configured) + break; - hcamcorder->on_preview_resolution_update = TRUE; - mm_ret = _mmcamcorder_capability_update_preview_fps(hcamcorder); - hcamcorder->on_preview_resolution_update = FALSE; + if (hcamcorder->mmcam_capability) { + /* from capability */ + mm_ret = _mmcamcorder_capability_update_capability_resolution(handle, width, height); + if (mm_ret != MM_ERROR_NONE) + break; - if (mm_ret != MM_ERROR_NONE) { - MMCAM_LOG_ERROR("update resolution list failed[0x%x]", mm_ret); - return false; + mm_ret = _mmcamcorder_capability_update_preview_fps(hcamcorder); + } else { + /* from ini */ + mm_ret = _mmcamcorder_conf_update_preview_fps(handle, width, height); } + } while (0); + + if (mm_ret != MM_ERROR_NONE) { + MMCAM_LOG_ERROR("[configured:%d,capability:%p] update resolution/FPS failed[0x%x]", + hcamcorder->is_configured, hcamcorder->mmcam_capability, mm_ret); + return false; } if (current_state != MM_CAMCORDER_STATE_PREPARE) { diff --git a/src/mm_camcorder_capability.c b/src/mm_camcorder_capability.c index cb1cfb4..265999c 100644 --- a/src/mm_camcorder_capability.c +++ b/src/mm_camcorder_capability.c @@ -110,7 +110,7 @@ static int __mmcamcorder_capability_update_attribute_int_array(MMHandleType attr static camera_device_capability_s *__mmcamcorder_capability_get_capability(mmcam_device_capability_s *mmcam_capability, int device_index) { - mmf_return_val_if_fail(mmcam_capability, NULL); + mmf_return_val_if_fail_warning(mmcam_capability, NULL); if (device_index >= mmcam_capability->list.device_count) { MMCAM_LOG_ERROR("invalid device index[%d] vs device count[%d]", @@ -375,7 +375,7 @@ int _mmcamcorder_capability_update_preview_format_list(MMHandleType handle) _capability = __mmcamcorder_capability_get_capability(hcamcorder->mmcam_capability, hcamcorder->device_type); - mmf_return_val_if_fail(_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED); + mmf_return_val_if_fail_warning(_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED); MMCAM_LOG_INFO("device[%d], capability format count[%d]", hcamcorder->device_type, _capability->format_count); @@ -562,8 +562,6 @@ int _mmcamcorder_capability_update_preview_fps(MMHandleType handle) int ret = MM_ERROR_NONE; int fps_index = 0; int fps = 0; - int new_fps = 0; - int attribute_index = 0; camera_fps_list_s *fps_list = NULL; @@ -594,17 +592,12 @@ int _mmcamcorder_capability_update_preview_fps(MMHandleType handle) } } - new_fps = fps_list->fps[_resolution->default_fps_index]; - - MMCAM_LOG_INFO("set new default fps[%d], old fps[%d)", new_fps, fps); - - ret = mm_attrs_get_index(MMF_CAMCORDER_ATTRS(handle), MMCAM_CAMERA_FPS, &attribute_index); - ret |= mm_attrs_set_int(MMF_CAMCORDER_ATTRS(handle), attribute_index, new_fps); - ret |= mm_attrs_commit(MMF_CAMCORDER_ATTRS(handle), attribute_index); + MMCAM_LOG_INFO("update fps [%d] -> [%d] for resolution[%ux%u]", + fps, fps_list->fps[_resolution->default_fps_index], + _resolution->width, _resolution->height); - MMCAM_LOG_INFO("done [0x%x]", ret); - - return ret; + return _mmcamcorder_set_fps_on_preview_resolution_update(handle, + fps_list->fps[_resolution->default_fps_index]); } @@ -619,7 +612,7 @@ int _mmcamcorder_capability_get_preview_fps_list_by_resolution(MMHandleType hand mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED); - mmf_return_val_if_fail(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED); + mmf_return_val_if_fail_warning(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED); mmf_return_val_if_fail(fps_list && count && default_fps, MM_ERROR_CAMCORDER_INVALID_ARGUMENT); _format = hcamcorder->mmcam_capability->current_format; diff --git a/src/mm_camcorder_configure.c b/src/mm_camcorder_configure.c index b946112..82a11b2 100644 --- a/src/mm_camcorder_configure.c +++ b/src/mm_camcorder_configure.c @@ -2730,3 +2730,40 @@ int _mmcamcorder_get_available_format(MMHandleType handle, int conf_category, in return total_count; } + +int _mmcamcorder_conf_update_preview_fps(MMHandleType handle, int width, int height) +{ + int i = 0; + int fps = 0; + int ret = MM_ERROR_NONE; + MMCamAttrsInfo info; + + ret = mm_camcorder_get_attributes(handle, NULL, + MMCAM_CAMERA_FPS, &fps, + NULL); + if (ret != MM_ERROR_NONE) { + MMCAM_LOG_ERROR("get fps failed[0x%x]", ret); + return MM_ERROR_CAMCORDER_INTERNAL; + } + + ret = mm_camcorder_get_fps_list_by_resolution(handle, width, height, &info); + if (ret != MM_ERROR_NONE) { + MMCAM_LOG_ERROR("get fps list for [%dx%d] failed[0x%x]", width, height, ret); + return MM_ERROR_CAMCORDER_INTERNAL; + } + + for (i = 0 ; i < info.int_array.count ; i++) { + if (info.int_array.array[i] != fps) + continue; + + MMCAM_LOG_INFO("new resolution[%dx%d] supports current fps[%d]", + width, height, fps); + + return MM_ERROR_NONE; + } + + MMCAM_LOG_INFO("update fps [%d] -> [%d] for resolution[%dx%d]", + fps, info.int_array.def, width, height); + + return _mmcamcorder_set_fps_on_preview_resolution_update(handle, info.int_array.def); +} diff --git a/src/mm_camcorder_platform.c b/src/mm_camcorder_platform.c index c4d5058..97541c0 100644 --- a/src/mm_camcorder_platform.c +++ b/src/mm_camcorder_platform.c @@ -757,7 +757,6 @@ int _mmcamcorder_get_fps_array_by_resolution(MMHandleType handle, int width, int { int i = 0; char nameFps[16] = {0, }; - bool valid_check = false; MMCamAttrsInfo infoW; MMCamAttrsInfo infoH; @@ -773,15 +772,14 @@ int _mmcamcorder_get_fps_array_by_resolution(MMHandleType handle, int width, int for (i = 0; i < infoW.int_array.count; i++) { MMCAM_LOG_VERBOSE("check resolution %dx%d", infoW.int_array.array[i], infoH.int_array.array[i]); if (infoW.int_array.array[i] == width && infoH.int_array.array[i] == height) { - valid_check = true; snprintf(nameFps, sizeof(nameFps), "FPS%d", i); MMCAM_LOG_INFO("nameFps[%s]", nameFps); break; } } - if (!valid_check) { - MMCAM_LOG_ERROR("FAILED : Can't find the valid resolution from attribute."); + if (i >= infoW.int_array.count) { + MMCAM_LOG_ERROR("FAILED : resolution[%dx%d] from attribute.", width, height); return MM_ERROR_CAMCORDER_NOT_SUPPORTED; } @@ -792,7 +790,7 @@ int _mmcamcorder_get_fps_array_by_resolution(MMHandleType handle, int width, int /* get fps list from ini if it's failed from capability. */ if (!_mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl, CONFIGURE_CATEGORY_CTRL_CAMERA, nameFps, &fps_array)) { - MMCAM_LOG_ERROR("FAILED : Can't find the valid FPS array."); + MMCAM_LOG_ERROR("FAILED : [%s] array.", nameFps); return MM_ERROR_CAMCORDER_CREATE_CONFIGURE; } diff --git a/src/mm_camcorder_util.c b/src/mm_camcorder_util.c index 788bf0f..4c94acc 100644 --- a/src/mm_camcorder_util.c +++ b/src/mm_camcorder_util.c @@ -2740,3 +2740,30 @@ void _mmcamcorder_set_property_array_int(GstElement *element, const char *proper g_value_unset(&tmp); g_value_unset(&value); } + +int _mmcamcorder_set_fps_on_preview_resolution_update(MMHandleType handle, int new_fps) +{ + int ret = MM_ERROR_NONE; + int attribute_index = 0; + + mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); + + mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED); + + MMCAM_LOG_INFO("set new fps[%d]", new_fps); + + hcamcorder->on_preview_resolution_update = TRUE; + + ret = mm_attrs_get_index(MMF_CAMCORDER_ATTRS(handle), MMCAM_CAMERA_FPS, &attribute_index); + ret |= mm_attrs_set_int(MMF_CAMCORDER_ATTRS(handle), attribute_index, new_fps); + ret |= mm_attrs_commit(MMF_CAMCORDER_ATTRS(handle), attribute_index); + + hcamcorder->on_preview_resolution_update = FALSE; + + if (ret != MM_ERROR_NONE) { + MMCAM_LOG_ERROR("set new fps[%d] failed[0x%x]", new_fps, ret); + return MM_ERROR_CAMCORDER_INTERNAL; + } + + return MM_ERROR_NONE; +} -- 2.34.1