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
29 #include <ri-module-api.h>
30 #include "mm_camcorder_rm.h"
31 #include "mm_camcorder_internal.h"
33 static rm_cb_result __mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
34 rm_device_request_s *info, void* cb_data)
36 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(cb_data);
37 int current_state = MM_CAMCORDER_STATE_NONE;
38 rm_cb_result cb_res = RM_CB_RESULT_OK;
40 mmf_return_val_if_fail((MMHandleType)hcamcorder, RM_CB_RESULT_OK);
42 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
44 _mmcam_dbg_warn("current state %d (handle %p)", current_state, hcamcorder);
46 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
48 /* set RM event code for sending it to application */
49 hcamcorder->interrupt_code = event_src;
51 _mmcam_dbg_log("RM conflict callback : event code 0x%x", event_src);
53 case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
54 case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
55 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
61 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
68 int _mmcamcorder_rm_create(MMHandleType handle)
74 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
76 _mmcam_dbg_err("Not initialized");
77 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
80 memset(&rci, 0x00, sizeof(rm_consumer_info));
82 mm_camcorder_get_attributes(handle, NULL,
83 MMCAM_CLIENT_PID, &app_pid,
85 rci.app_pid = app_pid;
86 aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id));
89 if (hcamcorder->rm_handle == 0) {
90 ret = rm_register((rm_resource_cb)__mmcamcorder_rm_callback,
92 &(hcamcorder->rm_handle),
93 (rci.app_id[0] != '\0') ? &rci : NULL);
95 _mmcam_dbg_err("rm_register fail ret = %d",ret);
96 return MM_ERROR_RESOURCE_INTERNAL;
102 int _mmcamcorder_rm_allocate(MMHandleType handle)
105 int preview_format = MM_PIXEL_FORMAT_NV12;
107 int qret_avail = 0; /* 0: not available, 1: available */
108 int resource_count = 0;
109 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
110 int camera_width = 0;
112 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
114 _mmcam_dbg_err("Not initialized");
115 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
118 mm_camcorder_get_attributes(handle, NULL,
119 MMCAM_DISPLAY_SURFACE, &display_surface_type,
122 if (display_surface_type != MM_DISPLAY_SURFACE_NULL) {
123 mm_camcorder_get_attributes(handle, NULL,
124 MMCAM_CAMERA_FORMAT, &preview_format,
128 memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
129 memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
131 if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
132 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
133 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER;
135 _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER);
138 } else if (preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
139 mm_camcorder_get_attributes(handle, NULL,
140 MMCAM_CAMERA_WIDTH, &camera_width,
143 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
144 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_MJPEG_DECODER;
145 hcamcorder->request_resources.category_option[resource_count] = ri_get_jpeg_category_id("MJPEG", camera_width);
146 _mmcam_dbg_log("request dec rsc - category 0x%x, option width [%d]", RM_CATEGORY_MJPEG_DECODER, camera_width);
149 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
150 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
151 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
152 _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
156 hcamcorder->request_resources.request_num = resource_count;
158 if (resource_count > 0) {
159 qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
160 if (qret != RM_OK || qret_avail != 1) {
161 _mmcam_dbg_log("rm query failed. retry with sub devices");
164 memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
165 memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
167 if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
168 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
169 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB;
170 _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER_SUB);
172 } else if (preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
173 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
174 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_MJPEG_DECODER;
175 hcamcorder->request_resources.category_option[resource_count] = ri_get_jpeg_category_id("MJPEG", camera_width);
176 _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_MJPEG_DECODER);
179 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
180 if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
181 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
182 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
183 _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
185 } else if (preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
186 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
187 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
188 _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
196 hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
197 hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA;
199 hcamcorder->request_resources.request_num = resource_count + 1;
200 _mmcam_dbg_log("request camera rsc - category 0x%x", RM_CATEGORY_CAMERA);
202 iret = rm_allocate_resources(hcamcorder->rm_handle, &(hcamcorder->request_resources), &hcamcorder->returned_devices);
204 _mmcam_dbg_err("Resource allocation request failed ret = %d",iret);
205 return MM_ERROR_RESOURCE_INTERNAL;
208 return MM_ERROR_NONE;
212 int _mmcamcorder_rm_deallocate(MMHandleType handle)
216 rm_device_request_s requested;
218 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
220 if (!hcamcorder->rm_handle) {
221 _mmcam_dbg_err("Resource is not initialized ");
222 return MM_ERROR_RESOURCE_NOT_INITIALIZED;
225 if (hcamcorder->returned_devices.allocated_num > 0) {
226 memset(&requested, 0x0, sizeof(rm_device_request_s));
227 requested.request_num = hcamcorder->returned_devices.allocated_num;
228 for (idx = 0; idx < requested.request_num; idx++)
229 requested.device_id[idx] = hcamcorder->returned_devices.device_id[idx];
231 rm_ret = rm_deallocate_resources(hcamcorder->rm_handle, &requested);
233 _mmcam_dbg_err("Resource deallocation request failed ");
236 return MM_ERROR_NONE;
239 int _mmcamcorder_rm_release(MMHandleType handle)
243 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
245 if (!hcamcorder->rm_handle) {
246 _mmcam_dbg_err("Resource is not initialized ");
247 return MM_ERROR_RESOURCE_NOT_INITIALIZED;
251 rm_ret = rm_unregister(hcamcorder->rm_handle);
253 _mmcam_dbg_err("rm_unregister() failed");
254 hcamcorder->rm_handle = 0;
256 return MM_ERROR_NONE;
259 #endif /* _MMCAMCORDER_RM_SUPPORT*/