4 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 /*=======================================================================================
24 ========================================================================================*/
25 #ifdef _MMCAMCORDER_RM_SUPPORT
28 #include "mm_camcorder_rm.h"
29 #include "mm_camcorder_internal.h"
31 static rm_cb_result __mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
32 rm_device_request_s *info, void* cb_data)
34 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(cb_data);
35 int current_state = MM_CAMCORDER_STATE_NONE;
36 rm_cb_result cb_res = RM_CB_RESULT_OK;
38 mmf_return_val_if_fail((MMHandleType)hcamcorder, RM_CB_RESULT_OK);
40 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
42 _mmcam_dbg_warn("current state %d (handle %p)", current_state, hcamcorder);
44 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
46 /* set RM event code for sending it to application */
47 hcamcorder->interrupt_code = event_src;
49 _mmcam_dbg_log("RM conflict callback : event code 0x%x", event_src);
51 case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
52 case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
53 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
59 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
66 int _mmcamcorder_rm_create(MMHandleType handle)
72 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
74 _mmcam_dbg_err("Not initialized");
75 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
78 mm_camcorder_get_attributes(handle, NULL,
79 MMCAM_CLIENT_PID, &app_pid,
81 rci.app_pid = app_pid;
82 aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id));
85 if (hcamcorder->rm_handle == 0) {
86 ret = rm_register((rm_resource_cb)__mmcamcorder_rm_callback, (void*)hcamcorder, &(hcamcorder->rm_handle), &rci);
88 _mmcam_dbg_err("rm_register fail ret = %d",ret);
89 return MM_ERROR_RESOURCE_INTERNAL;
95 int _mmcamcorder_rm_allocate(MMHandleType handle)
98 int preview_format = MM_PIXEL_FORMAT_NV12;
100 int qret_avail = 0; /* 0: not available, 1: available */
101 int resource_count = 0;
102 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
104 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
106 _mmcam_dbg_err("Not initialized");
107 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
110 mm_camcorder_get_attributes(handle, NULL,
111 MMCAM_DISPLAY_SURFACE, &display_surface_type,
114 if (display_surface_type != MM_DISPLAY_SURFACE_NULL) {
115 mm_camcorder_get_attributes(handle, NULL,
116 MMCAM_CAMERA_FORMAT, &preview_format,
120 memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
121 memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
123 if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
124 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
125 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER;
127 _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER);
132 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
133 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
134 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
136 _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
141 hcamcorder->request_resources.request_num = resource_count;
143 if (resource_count > 0) {
144 qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
145 if (qret != RM_OK || qret_avail != 1) {
146 _mmcam_dbg_log("rm query failed. retry with sub devices");
149 memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
150 memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
152 if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
153 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
154 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB;
155 _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER_SUB);
159 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
160 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
161 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
162 _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
169 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
170 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA;
172 hcamcorder->request_resources.request_num = resource_count + 1;
173 _mmcam_dbg_log("request camera rsc - category 0x%x", RM_CATEGORY_CAMERA);
175 iret = rm_allocate_resources(hcamcorder->rm_handle, &(hcamcorder->request_resources), &hcamcorder->returned_devices);
177 _mmcam_dbg_err("Resource allocation request failed ret = %d",iret);
178 return MM_ERROR_RESOURCE_INTERNAL;
181 return MM_ERROR_NONE;
185 int _mmcamcorder_rm_deallocate(MMHandleType handle)
189 rm_device_request_s requested;
191 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
193 if (!hcamcorder->rm_handle) {
194 _mmcam_dbg_err("Resource is not initialized ");
195 return MM_ERROR_RESOURCE_NOT_INITIALIZED;
198 if (hcamcorder->returned_devices.allocated_num > 0) {
199 memset(&requested, 0x0, sizeof(rm_device_request_s));
200 requested.request_num = hcamcorder->returned_devices.allocated_num;
201 for (idx = 0; idx < requested.request_num; idx++)
202 requested.device_id[idx] = hcamcorder->returned_devices.device_id[idx];
204 rm_ret = rm_deallocate_resources(hcamcorder->rm_handle, &requested);
206 _mmcam_dbg_err("Resource deallocation request failed ");
209 return MM_ERROR_NONE;
212 int _mmcamcorder_rm_release(MMHandleType handle)
216 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
218 if (!hcamcorder->rm_handle) {
219 _mmcam_dbg_err("Resource is not initialized ");
220 return MM_ERROR_RESOURCE_NOT_INITIALIZED;
224 rm_ret = rm_unregister(hcamcorder->rm_handle);
226 _mmcam_dbg_err("rm_unregister() failed");
227 hcamcorder->rm_handle = 0;
229 return MM_ERROR_NONE;
232 #endif /* _MMCAMCORDER_RM_SUPPORT*/