X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmm_camcorder_internal.c;h=870347a7b96c06555f33c0c3e3353d2cc54ff4d9;hb=bbd2630cc204b326c20418cebaa9032b5b204658;hp=6403c29d95eb3d67aa829bb701f4488d0659fdc7;hpb=3d5e8a1e5d430bb13fdaa98d845580ce40793350;p=platform%2Fcore%2Fmultimedia%2Flibmm-camcorder.git diff --git a/src/mm_camcorder_internal.c b/src/mm_camcorder_internal.c index 6403c29..870347a 100644 --- a/src/mm_camcorder_internal.c +++ b/src/mm_camcorder_internal.c @@ -46,6 +46,9 @@ #include #endif /* _MMCAMCORDER_MURPHY_SUPPORT */ +#ifdef _MMCAMCORDER_RM_SUPPORT +#include +#endif /* _MMCAMCORDER_RM_SUPPORT */ /*--------------------------------------------------------------------------------------- | LOCAL VARIABLE DEFINITIONS for internal | @@ -60,6 +63,10 @@ #define DPM_ALLOWED 1 #define DPM_DISALLOWED 0 +#ifdef _MMCAMCORDER_MURPHY_SUPPORT +#define __MMCAMCORDER_RESOURCE_WAIT_TIME 5 +#endif /* _MMCAMCORDER_MURPHY_SUPPORT */ + /*--------------------------------------------------------------------------------------- | LOCAL FUNCTION PROTOTYPES: | @@ -75,6 +82,10 @@ static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int cod static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error); static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error); +#ifdef _MMCAMCORDER_RM_SUPPORT +rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src, + rm_device_request_s *info, void *cb_data); +#endif /* _MMCAMCORDER_RM_SUPPORT */ #ifdef _MMCAMCORDER_USE_SET_ATTR_CB static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data); #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */ @@ -134,6 +145,10 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info) g_mutex_init(&(hcamcorder->mtsafe).vcapture_cb_lock); g_mutex_init(&(hcamcorder->mtsafe).vstream_cb_lock); g_mutex_init(&(hcamcorder->mtsafe).astream_cb_lock); +#ifdef _MMCAMCORDER_MURPHY_SUPPORT + g_cond_init(&(hcamcorder->mtsafe).resource_cond); + g_mutex_init(&(hcamcorder->mtsafe).resource_lock); +#endif /* _MMCAMCORDER_MURPHY_SUPPORT */ g_mutex_init(&hcamcorder->restart_preview_lock); @@ -568,6 +583,10 @@ _ERR_DEFAULT_VALUE_INIT: g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock); g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock); g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock); +#ifdef _MMCAMCORDER_MURPHY_SUPPORT + g_cond_clear(&(hcamcorder->mtsafe).resource_cond); + g_mutex_clear(&(hcamcorder->mtsafe).resource_lock); +#endif /* _MMCAMCORDER_MURPHY_SUPPORT */ g_mutex_clear(&hcamcorder->snd_info.open_mutex); g_cond_clear(&hcamcorder->snd_info.open_cond); @@ -616,6 +635,9 @@ int _mmcamcorder_destroy(MMHandleType handle) int ret = MM_ERROR_NONE; int state = MM_CAMCORDER_STATE_NONE; int state_FROM = MM_CAMCORDER_STATE_NULL; +#ifdef _MMCAMCORDER_RM_SUPPORT + int iret = RM_OK; +#endif /* _MMCAMCORDER_RM_SUPPORT */ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); @@ -712,6 +734,14 @@ int _mmcamcorder_destroy(MMHandleType handle) _mmcam_dbg_log("no need to unregister sound focus.[%d, id %d]", hcamcorder->sound_focus_register, hcamcorder->sound_focus_id); } +#ifdef _MMCAMCORDER_RM_SUPPORT + if (hcamcorder->rm_handle != 0) { + iret = rm_unregister(hcamcorder->rm_handle); + if (iret != RM_OK) + _mmcam_dbg_err("rm_unregister() failed"); + hcamcorder->rm_handle = 0; + } +#endif /* _MMCAMCORDER_RM_SUPPORT */ /* release model_name */ if (hcamcorder->model_name) { @@ -766,6 +796,10 @@ int _mmcamcorder_destroy(MMHandleType handle) g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock); g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock); g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock); +#ifdef _MMCAMCORDER_MURPHY_SUPPORT + g_cond_clear(&(hcamcorder->mtsafe).resource_cond); + g_mutex_clear(&(hcamcorder->mtsafe).resource_lock); +#endif /* _MMCAMCORDER_MURPHY_SUPPORT */ g_mutex_clear(&hcamcorder->snd_info.open_mutex); g_cond_clear(&hcamcorder->snd_info.open_cond); @@ -807,6 +841,9 @@ int _mmcamcorder_realize(MMHandleType handle) const char *videosink_name = NULL; char *socket_path = NULL; int socket_path_len; +#ifdef _MMCAMCORDER_RM_SUPPORT + int iret = RM_OK; +#endif /* _MMCAMCORDER_RM_SUPPORT */ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); @@ -899,6 +936,79 @@ int _mmcamcorder_realize(MMHandleType handle) _mmcam_dbg_log("no need to register sound focus"); } +#ifdef _MMCAMCORDER_RM_SUPPORT + int preview_format = MM_PIXEL_FORMAT_NV12; + int qret = RM_OK; + int qret_avail = RM_OK; + rm_consumer_info rci; + int app_pid = 0; + int resource_count = 0; + + mm_camcorder_get_attributes(handle, NULL, + MMCAM_PID_FOR_SOUND_FOCUS, &app_pid, + NULL); + rci.app_pid = app_pid; + aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id)); + + /* RM register */ + if (hcamcorder->rm_handle == 0) { + iret = rm_register((rm_resource_cb)_mmcamcorder_rm_callback, (void*)hcamcorder, + &(hcamcorder->rm_handle), &rci); + if (iret != RM_OK) { + _mmcam_dbg_err("rm_register fail"); + ret = MM_ERROR_POLICY_BLOCKED; + goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK; + } + } + + mm_camcorder_get_attributes(handle, NULL, + MMCAM_CAMERA_FORMAT, &preview_format, + NULL); + + if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO && preview_format == MM_PIXEL_FORMAT_ENCODED_H264) { + + resource_count = 0; + memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s)); + memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s)); + hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE; + hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER; + _mmcam_dbg_log("request video decoder resource - device category 0x%x",hcamcorder->request_resources.category_id[resource_count]); + + resource_count++; + hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE; + hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER; + hcamcorder->request_resources.request_num = resource_count + 1; + _mmcam_dbg_log("request scaler resource - device category 0x%x",hcamcorder->request_resources.category_id[resource_count]); + + + qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail); + + if (qret != RM_OK || qret_avail != RM_OK) { + _mmcam_dbg_log("Resource manager main device request fail"); + + resource_count = 0; + hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB; + _mmcam_dbg_log("request video decoder resource - device category 0x%x",hcamcorder->request_resources.category_id[resource_count]); + + resource_count++; + hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB; + _mmcam_dbg_log("request scaler resource - device category 0x%x",hcamcorder->request_resources.category_id[resource_count]); + } + + resource_count++; + hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE; + hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA; + hcamcorder->request_resources.request_num = resource_count + 1; + _mmcam_dbg_log("request camera resource - device category 0x%x",hcamcorder->request_resources.category_id[resource_count]); + + iret = rm_allocate_resources(hcamcorder->rm_handle, &(hcamcorder->request_resources), &hcamcorder->returned_devices); + if (iret != RM_OK) { + _mmcam_dbg_err("Resource allocation request failed"); + ret = MM_ERROR_POLICY_BLOCKED; + goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK; + } + } +#endif /* _MMCAMCORDER_RM_SUPPORT */ /* alloc sub context */ hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type); @@ -990,6 +1100,9 @@ int _mmcamcorder_realize(MMHandleType handle) if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) { int dpm_camera_state = DPM_ALLOWED; +#ifdef _MMCAMCORDER_MURPHY_SUPPORT + gint64 end_time = 0; +#endif /* _MMCAMCORDER_MURPHY_SUPPORT */ /* check camera policy from DPM */ if (hcamcorder->dpm_policy) { @@ -997,7 +1110,7 @@ int _mmcamcorder_realize(MMHandleType handle) _mmcam_dbg_log("DPM camera state %d", dpm_camera_state); if (dpm_camera_state == DPM_DISALLOWED) { _mmcam_dbg_err("CAMERA DISALLOWED by DPM"); - ret = MM_ERROR_COMMON_INVALID_PERMISSION; + ret = MM_ERROR_POLICY_RESTRICTED; goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK; } } else { @@ -1007,6 +1120,8 @@ int _mmcamcorder_realize(MMHandleType handle) _mmcam_dbg_warn("NULL dpm_policy"); } #ifdef _MMCAMCORDER_MURPHY_SUPPORT + hcamcorder->resource_manager.acquire_count = 0; + /* prepare resource manager for camera */ ret = _mmcamcorder_resource_manager_prepare(&hcamcorder->resource_manager, MM_CAMCORDER_RESOURCE_TYPE_CAMERA); if (ret != MM_ERROR_NONE) { @@ -1030,11 +1145,36 @@ int _mmcamcorder_realize(MMHandleType handle) } /* acquire resources */ + _MMCAMCORDER_LOCK_RESOURCE(hcamcorder); + if (hcamcorder->resource_manager.rset && _mmcamcorder_resource_manager_acquire(&hcamcorder->resource_manager)) { + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); + _mmcam_dbg_err("could not acquire resources"); + _mmcamcorder_resource_manager_unprepare(&hcamcorder->resource_manager); goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK; } + + if (hcamcorder->resource_manager.acquire_count > 0) { + _mmcam_dbg_warn("wait for resource state change"); + + /* wait for resource state change */ + end_time = g_get_monotonic_time() + (__MMCAMCORDER_RESOURCE_WAIT_TIME * G_TIME_SPAN_SECOND); + + if (_MMCAMCORDER_RESOURCE_WAIT_UNTIL(hcamcorder, end_time)) { + _mmcam_dbg_warn("signal received"); + } else { + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); + _mmcam_dbg_err("timeout"); + ret = MM_ERROR_RESOURCE_INTERNAL; + goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK; + } + } else { + _mmcam_dbg_log("already all acquired"); + } + + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); #endif /* _MMCAMCORDER_MURPHY_SUPPORT */ } @@ -1115,6 +1255,27 @@ _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK: } } } +#ifdef _MMCAMCORDER_RM_SUPPORT + if (hcamcorder->rm_handle) { + if (hcamcorder->returned_devices.allocated_num > 0) { + int idx = 0; + rm_device_request_s requested; + memset(&requested, 0x0, sizeof(rm_device_request_s)); + requested.request_num = hcamcorder->returned_devices.allocated_num; + for (idx = 0; idx < requested.request_num; idx++) { + requested.device_id[idx] = hcamcorder->returned_devices.device_id[idx]; + } + iret = rm_deallocate_resources(hcamcorder->rm_handle, &requested); + if (iret != RM_OK) + _mmcam_dbg_err("Resource deallocation request failed "); + } + /* unregister RM */ + int ires = rm_unregister(hcamcorder->rm_handle); + if (ires != RM_OK) + _mmcam_dbg_err("rm_unregister() failed"); + hcamcorder->rm_handle = 0; + } +#endif /* _MMCAMCORDER_RM_SUPPORT*/ _ERR_CAMCORDER_CMD_PRECON: _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)", @@ -1182,6 +1343,22 @@ int _mmcamcorder_unrealize(MMHandleType handle) } #endif /* _MMCAMCORDER_MURPHY_SUPPORT */ +#ifdef _MMCAMCORDER_RM_SUPPORT + if (hcamcorder->rm_handle && (hcamcorder->returned_devices.allocated_num > 0)) { + int iret = RM_OK; + int idx = 0; + rm_device_request_s requested; + memset(&requested, 0x0, sizeof(rm_device_request_s)); + requested.request_num = hcamcorder->returned_devices.allocated_num; + for (idx = 0; idx < requested.request_num; idx++) { + requested.device_id[idx] = hcamcorder->returned_devices.device_id[idx]; + } + iret = rm_deallocate_resources(hcamcorder->rm_handle, &requested); + if (iret != RM_OK) + _mmcam_dbg_err("Resource deallocation request failed "); + } +#endif /* _MMCAMCORDER_RM_SUPPORT*/ + /* Deinitialize main context member */ hcamcorder->command = NULL; @@ -4030,3 +4207,45 @@ int _mmcamcorder_get_video_caps(MMHandleType handle, char **caps) return MM_ERROR_NONE; } +#ifdef _MMCAMCORDER_RM_SUPPORT +rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src, + rm_device_request_s *info, void* cb_data) +{ + mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(cb_data); + int current_state = MM_CAMCORDER_STATE_NONE; + rm_cb_result cb_res = RM_CB_RESULT_OK; + + mmf_return_val_if_fail((MMHandleType)hcamcorder, RM_CB_RESULT_OK); + + current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder); + if (current_state <= MM_CAMCORDER_STATE_NONE || + current_state >= MM_CAMCORDER_STATE_NUM) { + _mmcam_dbg_err("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state); + } + + _MMCAMCORDER_LOCK_ASM(hcamcorder); + + /* set value to inform a status is changed by RM */ + hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_RM; + + /* set RM event code for sending it to application */ + hcamcorder->interrupt_code = event_src; + + _mmcam_dbg_log("RM conflict callback : event code 0x%x", event_src); + switch (event_src) { + case RM_CALLBACK_TYPE_RESOURCE_CONFLICT: + case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD: + __mmcamcorder_force_stop(hcamcorder); + break; + default: + break; + } + + /* restore value */ + hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL; + + _MMCAMCORDER_UNLOCK_ASM(hcamcorder); + + return cb_res; +} +#endif /* _MMCAMCORDER_RM_SUPPORT */ \ No newline at end of file