+ 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 */
+
+#ifdef _MMCAMCORDER_RM_SUPPORT
+ 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);
+
+ resource_count = 0;
+ memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
+ memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
+
+ if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+ hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+ hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER;
+
+ _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER);
+
+ resource_count++;
+ }
+
+ if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
+ hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+ hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
+
+ _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
+
+ resource_count++;
+ }
+
+ hcamcorder->request_resources.request_num = resource_count;
+
+ if (resource_count > 0) {
+ qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
+ if (qret != RM_OK || qret_avail != 1) {
+ _mmcam_dbg_log("rm query failed. retry with sub devices");
+
+ resource_count = 0;
+
+ if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+ hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB;
+ _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER_SUB);
+ resource_count++;
+ }
+
+ if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
+ hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
+ _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
+ 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 rsc - category 0x%x", RM_CATEGORY_CAMERA);
+
+ 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 */
+ }
+
+ /* create pipeline */
+ traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
+
+ ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
+
+ traceEnd(TTRACE_TAG_CAMERA);
+
+ if (ret != MM_ERROR_NONE) {
+ /* check internal error of gstreamer */
+ if (hcamcorder->error_code != MM_ERROR_NONE) {
+ ret = hcamcorder->error_code;
+ _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
+ }
+
+ /* release sub context */
+ _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
+ hcamcorder->sub_context = NULL;
+ goto _ERR_CAMCORDER_CMD;
+ }
+
+ /* set command function */
+ ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
+ if (ret != MM_ERROR_NONE) {
+ _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
+ _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
+ hcamcorder->sub_context = NULL;
+ goto _ERR_CAMCORDER_CMD;
+ }
+
+ _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
+
+ _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+
+ return MM_ERROR_NONE;
+
+_ERR_CAMCORDER_CMD:
+#ifdef _MMCAMCORDER_MURPHY_SUPPORT
+ /* release hw resources */
+ if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
+ _mmcamcorder_resource_manager_release(&hcamcorder->resource_manager);
+#endif /* _MMCAMCORDER_MURPHY_SUPPORT */
+#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_AFTER_LOCK:
+ _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+
+ if (hcamcorder->sound_focus_watch_id > 0) {
+ mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+ _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+ hcamcorder->sound_focus_watch_id = 0;
+ }
+
+ if (hcamcorder->acquired_focus > 0) {
+ mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, "mm-camcorder release focus");
+ _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
+ hcamcorder->acquired_focus = 0;
+ }
+
+_ERR_CAMCORDER_CMD_PRECON:
+ _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
+
+ return ret;
+}
+
+
+int _mmcamcorder_unrealize(MMHandleType handle)
+{
+ int ret = MM_ERROR_NONE;
+ int state = MM_CAMCORDER_STATE_NONE;
+
+ mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+ _mmcam_dbg_log("");
+
+ if (!hcamcorder) {
+ _mmcam_dbg_err("Not initialized");
+ ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
+ return ret;