return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
}
+ hcamcorder->error_code = MM_ERROR_NONE;
+
/* copy var_args to keep original var_args */
va_copy(var_args_copy, var_args);
}
if (ret == MM_ERROR_NONE) {
- hcamcorder->error_code = MM_ERROR_NONE;
/* In 64bit environment, unexpected result is returned if var_args is used again. */
ret = mm_attrs_set_valist(attrs, &tmp_err_attr_name, attribute_name, var_args_copy);
}
bool _mmcamcorder_commit_camera_format(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
{
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+ int ret = MM_ERROR_NONE;
int current_state = MM_CAMCORDER_STATE_NONE;
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
mmf_return_val_if_fail(hcamcorder && value, FALSE);
return FALSE;
}
+ if (hcamcorder->is_configured && hcamcorder->mmcam_capability) {
+ ret = _mmcamcorder_capability_update_capability_format(handle, value->value.i_val);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update capability format failed[0x%x]", ret);
+ return FALSE;
+ }
+
+ ret = _mmcamcorder_capability_update_preview_resolution_list(handle);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update resolution list failed[0x%x]", ret);
+ return FALSE;
+ }
+ }
+
+ MMCAM_LOG_INFO("done");
+
return TRUE;
}
MMCAM_LOG_INFO("FPS(%d)", value->value.i_val);
+ if (hcamcorder->on_preview_resolution_update) {
+ MMCAM_LOG_INFO("no need to check FPS list");
+ return TRUE;
+ }
+
ret = mm_camcorder_get_attributes(handle, NULL,
MMCAM_CAMERA_WIDTH, &resolution_width,
MMCAM_CAMERA_HEIGHT, &resolution_height,
bool _mmcamcorder_commit_camera_height(MMHandleType handle, int attr_idx, const MMAttrsValue *value)
{
- int ret = 0;
+ bool ret = false;
+ int mm_ret = MM_ERROR_NONE;
int current_state = MM_CAMCORDER_STATE_NONE;
+ int width = 0;
+ int height = 0;
+ int preview_format = MM_PIXEL_FORMAT_NV12;
+ int codec_type = MM_IMAGE_CODEC_JPEG;
MMHandleType attr = 0;
mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
_MMCamcorderSubContext *sc = NULL;
- mmf_return_val_if_fail(hcamcorder && value, FALSE);
+ mmf_return_val_if_fail(hcamcorder && value, false);
sc = MMF_CAMCORDER_SUBCONTEXT(handle);
if (!sc)
- return TRUE;
+ return true;
attr = MMF_CAMCORDER_ATTRS(hcamcorder);
- mmf_return_val_if_fail(attr, FALSE);
+ mmf_return_val_if_fail(attr, false);
MMCAM_LOG_INFO("Height(%d)", value->value.i_val);
current_state = _mmcamcorder_get_state(handle);
if (current_state > MM_CAMCORDER_STATE_PREPARE) {
MMCAM_LOG_INFO("Resolution can't be changed.(state=%d)", current_state);
hcamcorder->error_code = MM_ERROR_CAMCORDER_INVALID_STATE;
- return FALSE;
- } else {
- int width = 0;
- int height = value->value.i_val;
- int preview_format = MM_PIXEL_FORMAT_NV12;
- int codec_type = MM_IMAGE_CODEC_JPEG;
- int video_stabilization = 0;
-
- mm_camcorder_get_attributes(handle, NULL,
- MMCAM_CAMERA_WIDTH, &width,
- MMCAM_CAMERA_FORMAT, &preview_format,
- MMCAM_IMAGE_ENCODER, &codec_type,
- MMCAM_CAMERA_VIDEO_STABILIZATION, &video_stabilization,
- NULL);
+ return false;
+ }
- sc->info_video->preview_width = width;
- sc->info_video->preview_height = height;
+ height = value->value.i_val;
- if (current_state == MM_CAMCORDER_STATE_PREPARE) {
- if (hcamcorder->resolution_changed == FALSE) {
- MMCAM_LOG_INFO("no need to restart preview");
- return TRUE;
- }
+ mm_ret = mm_camcorder_get_attributes(handle, NULL,
+ MMCAM_CAMERA_WIDTH, &width,
+ MMCAM_CAMERA_FORMAT, &preview_format,
+ MMCAM_IMAGE_ENCODER, &codec_type,
+ NULL);
+ if (mm_ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("attributes get failed[0x%x]", ret);
+ return false;
+ }
- hcamcorder->resolution_changed = FALSE;
+ sc->info_video->preview_width = width;
+ sc->info_video->preview_height = height;
- if (g_mutex_trylock(&hcamcorder->restart_preview_lock)) {
- MMCAM_LOG_INFO("restart preview");
+ /* 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;
+ }
- MMCAM_LOG_INFO("set empty buffers");
+ hcamcorder->on_preview_resolution_update = TRUE;
+ mm_ret = _mmcamcorder_capability_update_preview_fps(hcamcorder);
+ hcamcorder->on_preview_resolution_update = FALSE;
- 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);
+ if (mm_ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update resolution list failed[0x%x]", mm_ret);
+ return false;
+ }
+ }
- if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format))
- _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY);
+ if (current_state != MM_CAMCORDER_STATE_PREPARE) {
+ sc->info_image->preview_format = preview_format;
+ sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codec_type, hcamcorder->use_zero_copy_format);
+ return _mmcamcorder_set_camera_resolution(handle, width, height);
+ }
- /* check decoder recreation */
- if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) {
- MMCAM_LOG_ERROR("_mmcamcorder_recreate_decoder_for_encoded_preview failed");
- g_mutex_unlock(&hcamcorder->restart_preview_lock);
- return FALSE;
- }
+ if (hcamcorder->resolution_changed == FALSE) {
+ MMCAM_LOG_INFO("no need to restart preview");
+ return true;
+ }
- /* get preview format */
- sc->info_image->preview_format = preview_format;
- sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codec_type, hcamcorder->use_zero_copy_format);
+ hcamcorder->resolution_changed = FALSE;
- ret = _mmcamcorder_set_camera_resolution(handle, width, height);
+ if (!g_mutex_trylock(&hcamcorder->restart_preview_lock)) {
+ MMCAM_LOG_ERROR("currently locked for preview restart");
+ return false;
+ }
- 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);
+ MMCAM_LOG_INFO("restart preview");
- if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format))
- _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING);
+ 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);
- /* unlock */
- g_mutex_unlock(&hcamcorder->restart_preview_lock);
- } else {
- MMCAM_LOG_ERROR("currently locked for preview restart");
- return FALSE;
- }
- } else {
- /* get preview format */
- sc->info_image->preview_format = preview_format;
- sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codec_type, hcamcorder->use_zero_copy_format);
- ret = _mmcamcorder_set_camera_resolution(handle, width, height);
- }
+ if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format))
+ _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY);
- return ret;
+ if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) {
+ MMCAM_LOG_ERROR("_mmcamcorder_recreate_decoder_for_encoded_preview failed");
+ g_mutex_unlock(&hcamcorder->restart_preview_lock);
+ return false;
}
+
+ sc->info_image->preview_format = preview_format;
+ sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codec_type, hcamcorder->use_zero_copy_format);
+
+ ret = _mmcamcorder_set_camera_resolution(handle, width, height);
+
+ 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);
+
+ if (!_mmcamcorder_is_encoded_preview_pixel_format(preview_format))
+ _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING);
+
+ g_mutex_unlock(&hcamcorder->restart_preview_lock);
+
+ return ret;
}
}
}
- return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
+ return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
}
if (!strcmp(check_pair_name[i][0], MMCAM_CAMERA_WIDTH)) {
--- /dev/null
+/*
+ * libmm-camcorder
+ *
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jeongmo Yang <jm80.yang@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/*=======================================================================================
+| INCLUDE FILES |
+=======================================================================================*/
+#include "mm_camcorder_internal.h"
+
+/*---------------------------------------------------------------------------------------
+| GLOBAL VARIABLE DEFINITIONS |
+---------------------------------------------------------------------------------------*/
+#define CAPABILITY_INDEX_INVALID -1
+#define CONFIGURE_FPS_ARRAY_NAME_MAX 8
+
+static const char *g_format_string_table[MM_PIXEL_FORMAT_NUM] = {
+ [MM_PIXEL_FORMAT_NV12] = "NV12",
+ [MM_PIXEL_FORMAT_NV21] = "NV21",
+ [MM_PIXEL_FORMAT_I420] = "I420",
+ [MM_PIXEL_FORMAT_YV12] = "YV12",
+ [MM_PIXEL_FORMAT_YUYV] = "YUYV",
+ [MM_PIXEL_FORMAT_UYVY] = "UYVY",
+ [MM_PIXEL_FORMAT_ENCODED] = "JPEG",
+ [MM_PIXEL_FORMAT_ENCODED_H264] = "H264",
+ [MM_PIXEL_FORMAT_ENCODED_MJPEG] = "MJPEG",
+ [MM_PIXEL_FORMAT_ENCODED_VP8] = "VP8",
+ [MM_PIXEL_FORMAT_ENCODED_VP9] = "VP9",
+ [MM_PIXEL_FORMAT_INVZ] = "INVZ"
+};
+
+static const MMPixelFormatType g_format_convert_table[CAMERA_PIXEL_FORMAT_MAX] = {
+ [CAMERA_PIXEL_FORMAT_NV12] = MM_PIXEL_FORMAT_NV12,
+ [CAMERA_PIXEL_FORMAT_NV21] = MM_PIXEL_FORMAT_NV21,
+ [CAMERA_PIXEL_FORMAT_I420] = MM_PIXEL_FORMAT_I420,
+ [CAMERA_PIXEL_FORMAT_YV12] = MM_PIXEL_FORMAT_YV12,
+ [CAMERA_PIXEL_FORMAT_YUYV] = MM_PIXEL_FORMAT_YUYV,
+ [CAMERA_PIXEL_FORMAT_UYVY] = MM_PIXEL_FORMAT_UYVY,
+ [CAMERA_PIXEL_FORMAT_JPEG] = MM_PIXEL_FORMAT_ENCODED,
+ [CAMERA_PIXEL_FORMAT_H264] = MM_PIXEL_FORMAT_ENCODED_H264,
+ [CAMERA_PIXEL_FORMAT_MJPEG] = MM_PIXEL_FORMAT_ENCODED_MJPEG,
+ [CAMERA_PIXEL_FORMAT_VP8] = MM_PIXEL_FORMAT_ENCODED_VP8,
+ [CAMERA_PIXEL_FORMAT_VP9] = MM_PIXEL_FORMAT_ENCODED_VP9,
+ [CAMERA_PIXEL_FORMAT_DEPTH] = MM_PIXEL_FORMAT_INVZ
+};
+
+
+static int __mmcamcorder_capability_update_attribute_int_array(MMHandleType attrs,
+ const char *attribute_name, int *new_list, int new_size,
+ int new_default, gboolean update_default)
+{
+ int ret = MM_ERROR_NONE;
+ int attribute_index = 0;
+
+ mmf_return_val_if_fail(attrs, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+ mmf_return_val_if_fail(attribute_name, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+ mmf_return_val_if_fail(new_list, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ ret = mm_attrs_get_index(attrs, attribute_name, &attribute_index);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("[%s] get index failed[0x%x]", attribute_name, ret);
+ return ret;
+ }
+
+ MMCAM_LOG_WARNING("[%s], size[%d], default[%d], update default[%d]",
+ attribute_name, new_size, new_default, update_default);
+
+ ret = mm_attrs_set_valid_array(attrs, attribute_index,
+ new_list, new_size, new_default);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("[%s] set new list failed[0x%x]", attribute_name, ret);
+ return ret;
+ }
+
+ if (!update_default)
+ return MM_ERROR_NONE;
+
+ MMCAM_LOG_WARNING("[%s] update new default[%d]", attribute_name, new_default);
+
+ ret = mm_attrs_set_int(attrs, attribute_index, new_default);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("[%s] set new default[%d] failed[0x%x]",
+ attribute_name, new_default, ret);
+ return ret;
+ }
+
+ ret = mm_attrs_commit(attrs, attribute_index);
+
+ MMCAM_LOG_WARNING("done[0x%x]", ret);
+
+ return ret;
+}
+
+
+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);
+
+ if (device_index >= mmcam_capability->list.device_count) {
+ MMCAM_LOG_ERROR("invalid device index[%d] vs device count[%d]",
+ device_index, mmcam_capability->list.device_count);
+ return NULL;
+ }
+
+ if (!mmcam_capability->list.capability[device_index]) {
+ MMCAM_LOG_ERROR("NULL capability for device index[%d]", device_index);
+ return NULL;
+ }
+
+ mmcam_capability->current_capability = mmcam_capability->list.capability[device_index];
+
+ MMCAM_LOG_INFO("device[%d] capability[%p]", device_index, mmcam_capability->current_capability);
+
+ return mmcam_capability->current_capability;
+}
+
+
+static void __mmcamcorder_capability_dump(mmcam_device_capability_s *mmcam_capability)
+{
+ int device_index = 0;
+ int format_index = 0;
+ int resolution_index = 0;
+ int fps_index = 0;
+ camera_device_capability_s *_capability = NULL;
+ camera_device_capability_format_s *_format = NULL;
+ camera_device_capability_resolution_s *_resolution = NULL;
+
+ mmf_return_if_fail(mmcam_capability);
+
+ for (device_index = 0 ; device_index < mmcam_capability->list.device_count ; device_index++) {
+ _capability = mmcam_capability->list.capability[device_index];
+ if (!_capability) {
+ MMCAM_LOG_WARNING("NULL capability[i:%d]", device_index);
+ continue;
+ }
+
+ MMCAM_LOG_DEBUG("device[%02d] format count[%d]", device_index, _capability->format_count);
+
+ for (format_index = 0 ; format_index < _capability->format_count ; format_index++) {
+ _format = _capability->format[format_index];
+ if (!_format) {
+ MMCAM_LOG_WARNING(" NULL format[i:%d]", format_index);
+ continue;
+ }
+
+ MMCAM_LOG_DEBUG(" format[%02d] %d, resolution count[%d]", format_index,
+ _format->pixel_format, _format->resolution_count);
+
+ for (resolution_index = 0 ; resolution_index < _format->resolution_count ; resolution_index++) {
+ _resolution = _format->resolution[resolution_index];
+ if (!_resolution) {
+ MMCAM_LOG_WARNING(" NULL resolution[i:%d]", resolution_index);
+ continue;
+ }
+
+ MMCAM_LOG_DEBUG(" resolution[%02d] %04d x %04d, fps count[%d]", resolution_index,
+ _resolution->width, _resolution->height, _resolution->fps_list.count);
+
+ for (fps_index = 0 ; fps_index < _resolution->fps_list.count ; fps_index++) {
+ MMCAM_LOG_DEBUG(" fps[%02d] %d", fps_index,
+ _resolution->fps_list.fps[fps_index]);
+ }
+ }
+ }
+ }
+}
+
+
+int _mmcamcorder_capability_init(MMHandleType handle)
+{
+ int ret = CAMERA_ERROR_NONE;
+ g_autofree mmcam_device_capability_s *new_mmcam_capability = NULL;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+ new_mmcam_capability = g_new0(mmcam_device_capability_s, 1);
+
+ ret = hal_camera_init(NULL, &new_mmcam_capability->hal_handle);
+ if (ret != CAMERA_ERROR_NONE) {
+ MMCAM_LOG_WARNING("hal_camera_init failed[0x%x]", ret);
+ return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+ }
+
+ ret = hal_camera_get_device_capability_list(new_mmcam_capability->hal_handle, &new_mmcam_capability->list);
+ if (ret != CAMERA_ERROR_NONE) {
+ MMCAM_LOG_WARNING("failed to get capability from camera HAL");
+
+ if (hal_camera_deinit(new_mmcam_capability->hal_handle) != CAMERA_ERROR_NONE)
+ MMCAM_LOG_WARNING("failed to deinit HAL handle");
+
+ return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+ }
+
+ __mmcamcorder_capability_dump(new_mmcam_capability);
+
+ hcamcorder->mmcam_capability = g_steal_pointer(&new_mmcam_capability);
+
+ return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_capability_deinit(MMHandleType handle)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ 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_NONE);
+
+ ret = hal_camera_deinit(hcamcorder->mmcam_capability->hal_handle);
+ if (ret != CAMERA_ERROR_NONE)
+ MMCAM_LOG_WARNING("failed to deinit HAL handle[0x%x]", ret);
+
+ MMCAM_LOG_INFO("handle[%p], capability[%p]", hcamcorder, hcamcorder->mmcam_capability);
+
+ g_free(hcamcorder->mmcam_capability);
+ hcamcorder->mmcam_capability = NULL;
+
+ return MM_ERROR_NONE;
+}
+
+
+int _mmcamcorder_capability_update_capability_format(MMHandleType handle, MMPixelFormatType mm_format)
+{
+ int index = 0;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+ camera_device_capability_s *_capability = NULL;
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+ mmf_return_val_if_fail(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+
+ _capability = hcamcorder->mmcam_capability->current_capability;
+
+ mmf_return_val_if_fail(_capability, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+ MMCAM_LOG_INFO("update capability format for [%s]", g_format_string_table[mm_format]);
+
+ for (index = 0 ; index < _capability->format_count ; index++) {
+ camera_device_capability_format_s *_format = _capability->format[index];
+
+ if (!_format)
+ continue;
+
+ if (mm_format == g_format_convert_table[_format->pixel_format]) {
+ hcamcorder->mmcam_capability->current_format = _format;
+
+ MMCAM_LOG_INFO("found capability format[%p] for [%s]",
+ _format, g_format_string_table[mm_format]);
+
+ return MM_ERROR_NONE;
+ }
+ }
+
+ MMCAM_LOG_ERROR("capability format not found for [%s]", g_format_string_table[mm_format]);
+
+ return MM_ERROR_CAMCORDER_INTERNAL;
+}
+
+
+int _mmcamcorder_capability_update_capability_resolution(MMHandleType handle, int width, int height)
+{
+ int index = 0;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+ camera_device_capability_format_s *_format = NULL;
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+ mmf_return_val_if_fail(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+
+ _format = hcamcorder->mmcam_capability->current_format;
+
+ mmf_return_val_if_fail(_format, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+ for (index = 0 ; index < _format->resolution_count ; index++) {
+ camera_device_capability_resolution_s *_resolution = _format->resolution[index];
+
+ if (!_resolution)
+ continue;
+
+ if (_resolution->width == width && _resolution->height == height) {
+ hcamcorder->mmcam_capability->current_resolution = _resolution;
+
+ MMCAM_LOG_INFO("found capability resolution[%p] for [%d x %d]",
+ _resolution, width, height);
+
+ return MM_ERROR_NONE;
+ }
+ }
+
+ MMCAM_LOG_ERROR("capability resolution not found for [%d x %d]", width, height);
+
+ return MM_ERROR_CAMCORDER_INTERNAL;
+}
+
+
+int _mmcamcorder_capability_update_preview_format_list(MMHandleType handle)
+{
+ int ret = MM_ERROR_NONE;
+ int format_index = 0;
+ int format_count = 0;
+ int format_list[MM_PIXEL_FORMAT_NUM] = {0, };
+ gboolean is_current_supported = FALSE;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+ MMPixelFormatType default_mm_format = MM_PIXEL_FORMAT_INVALID;
+ MMPixelFormatType current_mm_format = MM_PIXEL_FORMAT_INVALID;
+
+ camera_device_capability_s *_capability = NULL;
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+ _capability = __mmcamcorder_capability_get_capability(hcamcorder->mmcam_capability, hcamcorder->device_type);
+
+ mmf_return_val_if_fail(_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+
+ MMCAM_LOG_INFO("device[%d], capability format count[%d]",
+ hcamcorder->device_type, _capability->format_count);
+
+ ret = mm_camcorder_get_attributes(handle, NULL,
+ MMCAM_CAMERA_FORMAT, ¤t_mm_format,
+ NULL);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("get current format failed[0x%x]", ret);
+ return ret;
+ }
+
+ format_index = format_count = 0;
+ for ( ; format_index < _capability->format_count ; format_index++) {
+ MMPixelFormatType converted_mm_format = MM_PIXEL_FORMAT_INVALID;
+ camera_device_capability_format_s *_format = _capability->format[format_index];
+
+ if (!_format)
+ continue;
+
+ /* get converted MM format list */
+ converted_mm_format = g_format_convert_table[_format->pixel_format];
+
+ MMCAM_LOG_INFO("MM format list [i:%2d] [%s]",
+ format_count, g_format_string_table[converted_mm_format]);
+
+ format_list[format_count] = converted_mm_format;
+ format_count++;
+
+ /* check whether current format is supported or not */
+ if (!is_current_supported && converted_mm_format == current_mm_format) {
+ is_current_supported = TRUE;
+
+ MMCAM_LOG_INFO("current format [%s] is supported",
+ g_format_string_table[converted_mm_format]);
+ }
+
+ /* get default MM format */
+ if (_capability->default_format_index == format_index) {
+ default_mm_format = converted_mm_format;
+
+ MMCAM_LOG_INFO("default format [%s] from capability",
+ g_format_string_table[converted_mm_format]);
+ }
+ }
+
+ if (!is_current_supported && default_mm_format == MM_PIXEL_FORMAT_INVALID) {
+ MMCAM_LOG_ERROR("update format failed [count:%d, default index:%d]",
+ _capability->format_count, _capability->default_format_index);
+ return MM_ERROR_CAMCORDER_INTERNAL;
+ }
+
+ MMCAM_LOG_INFO("new MM format count[%d]", format_count);
+
+ ret = __mmcamcorder_capability_update_attribute_int_array(MMF_CAMCORDER_ATTRS(hcamcorder),
+ MMCAM_CAMERA_FORMAT, format_list, format_count,
+ default_mm_format, !is_current_supported);
+ if (ret != MM_ERROR_NONE)
+ return ret;
+
+ ret = _mmcamcorder_capability_update_capability_format(handle,
+ is_current_supported ? current_mm_format : default_mm_format);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update capability format failed[0x%x]", ret);
+ return ret;
+ }
+
+ MMCAM_LOG_INFO("done");
+
+ return _mmcamcorder_capability_update_preview_resolution_list(handle);
+}
+
+
+int _mmcamcorder_capability_update_preview_resolution_list(MMHandleType handle)
+{
+ int ret = MM_ERROR_NONE;
+ int resolution_index = 0;
+ int update_index = CAPABILITY_INDEX_INVALID;
+ int default_index = CAPABILITY_INDEX_INVALID;
+ int width_list[RESOLUTION_COUNT_MAX] = {0, };
+ int height_list[RESOLUTION_COUNT_MAX] = {0, };
+ int current_width = 0;
+ int current_height = 0;
+ int default_width = 0;
+ int default_height = 0;
+ gboolean is_current_supported = FALSE;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+ camera_device_capability_format_s *_format = NULL;
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+ mmf_return_val_if_fail(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+
+ _format = hcamcorder->mmcam_capability->current_format;
+
+ mmf_return_val_if_fail(_format, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ ret = mm_camcorder_get_attributes(handle, NULL,
+ MMCAM_CAMERA_WIDTH, ¤t_width,
+ MMCAM_CAMERA_HEIGHT, ¤t_height,
+ NULL);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("get resolution failed[0x%x]", ret);
+ return ret;
+ }
+
+ default_index = _format->default_resolution_index;
+
+ for (resolution_index = 0 ; resolution_index < _format->resolution_count ; resolution_index++) {
+ width_list[resolution_index] = _format->resolution[resolution_index]->width;
+ height_list[resolution_index] = _format->resolution[resolution_index]->height;
+
+ MMCAM_LOG_INFO("resolution [i:%02d] [%d x %d]",
+ resolution_index, width_list[resolution_index], height_list[resolution_index]);
+
+ if (!is_current_supported &&
+ current_width == width_list[resolution_index] &&
+ current_height == height_list[resolution_index]) {
+ is_current_supported = TRUE;
+ update_index = resolution_index;
+
+ MMCAM_LOG_INFO("current resolution[%d x %d] is supported [i:%d]",
+ current_width, current_height, resolution_index);
+ }
+ }
+
+ if (update_index == CAPABILITY_INDEX_INVALID) {
+ update_index = default_index;
+ MMCAM_LOG_WARNING("use default index[%d]", update_index);
+ }
+
+ default_width = _format->resolution[default_index]->width;
+ default_height = _format->resolution[default_index]->height;
+
+ MMCAM_LOG_INFO("new resolution count[%d], update[%d x %d, supported:%d], default[%d x %d]",
+ _format->resolution_count,
+ current_width, current_height, is_current_supported,
+ default_width, default_height);
+
+ ret = __mmcamcorder_capability_update_attribute_int_array(MMF_CAMCORDER_ATTRS(hcamcorder),
+ MMCAM_CAMERA_WIDTH, width_list, _format->resolution_count,
+ default_width, !is_current_supported);
+
+ ret |= __mmcamcorder_capability_update_attribute_int_array(MMF_CAMCORDER_ATTRS(hcamcorder),
+ MMCAM_CAMERA_HEIGHT, height_list, _format->resolution_count,
+ default_height, !is_current_supported);
+
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update attribute for preview resolution failed[0x%x]", ret);
+ return ret;
+ }
+
+ ret = _mmcamcorder_capability_update_capability_resolution(handle,
+ is_current_supported ? current_width : default_width,
+ is_current_supported ? current_height : default_height);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("update capability resolution failed[0x%x]", ret);
+ return ret;
+ }
+
+ MMCAM_LOG_INFO("done");
+
+ return _mmcamcorder_capability_update_preview_fps(handle);
+}
+
+
+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;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+ camera_device_capability_resolution_s *_resolution = NULL;
+
+ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+ mmf_return_val_if_fail(hcamcorder->mmcam_capability, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
+
+ _resolution = hcamcorder->mmcam_capability->current_resolution;
+
+ mmf_return_val_if_fail(_resolution, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ ret = mm_camcorder_get_attributes(handle, NULL,
+ MMCAM_CAMERA_FPS, &fps,
+ NULL);
+ if (ret != MM_ERROR_NONE) {
+ MMCAM_LOG_ERROR("get current preview fps failed[0x%x]", ret);
+ return ret;
+ }
+
+ fps_list = &_resolution->fps_list;
+
+ for (fps_index = 0 ; fps_index < fps_list->count ; fps_index++) {
+ if (fps == fps_list->fps[fps_index]) {
+ MMCAM_LOG_INFO("current fps[%d] is supported", fps);
+ return MM_ERROR_NONE;
+ }
+ }
+
+ 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("done [0x%x]", ret);
+
+ return ret;
+}
+
+
+int _mmcamcorder_capability_get_preview_fps_list_by_resolution(MMHandleType handle,
+ int width, int height, int **fps_list, int *count, int *default_fps)
+{
+ int i = 0;
+
+ camera_device_capability_format_s *_format = NULL;
+ camera_device_capability_resolution_s *_resolution = NULL;
+
+ 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(fps_list && count && default_fps, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+ _format = hcamcorder->mmcam_capability->current_format;
+ mmf_return_val_if_fail(_format, MM_ERROR_CAMCORDER_INTERNAL);
+
+ for (i = 0 ; i < _format->resolution_count ; i++) {
+ _resolution = _format->resolution[i];
+ if (!_resolution) {
+ MMCAM_LOG_WARNING("NULL capability resolution[%d]", i);
+ continue;
+ }
+
+ if (width == _resolution->width && height == _resolution->height) {
+ *fps_list = _resolution->fps_list.fps;
+ *count = _resolution->fps_list.count;
+ *default_fps = _resolution->fps_list.fps[_resolution->default_fps_index];
+
+ MMCAM_LOG_INFO("matched resolution[%dx%d] -> fps count[%d],default[%d]",
+ width, height, *count, *default_fps);
+
+ return MM_ERROR_NONE;
+ }
+ }
+
+ MMCAM_LOG_ERROR("should not be reached here for [%dx%d]", width, height);
+
+ return MM_ERROR_CAMCORDER_INTERNAL;
+}