Add new APIs for camera settings
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_rm.c
index 024baaf..b3e1d12 100644 (file)
@@ -27,6 +27,7 @@
 #include <rm_api.h>
 #include <ri-api.h>
 #include <ri-module-api.h>
+#include <resource_center.h>
 #include "mm_camcorder_rm.h"
 #include "mm_camcorder_internal.h"
 
@@ -63,34 +64,28 @@ static rm_cb_result __mmcamcorder_rm_callback(int handle, rm_callback_type event
        return cb_res;
 }
 
-
-
 int _mmcamcorder_rm_create(MMHandleType handle)
 {
        int ret = RM_OK;
-       rm_consumer_info rci;
-       int app_pid = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        if (!hcamcorder) {
                MMCAM_LOG_ERROR("Not initialized");
                return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
-
-       memset(&rci, 0x00, sizeof(rm_consumer_info));
-
+       memset(&hcamcorder->rci, 0x00, sizeof(rm_consumer_info));
        mm_camcorder_get_attributes(handle, NULL,
-               MMCAM_CLIENT_PID, &app_pid,
+               MMCAM_CLIENT_PID, &hcamcorder->rci.app_pid,
                NULL);
-       rci.app_pid = app_pid;
-       aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id));
+       aul_app_get_appid_bypid(hcamcorder->rci.app_pid, hcamcorder->rci.app_id, sizeof(hcamcorder->rci.app_id));
 
        /* RM register */
+       /* NULL should be passed for the rci parameter if the application does not have "visibility" */
        if (hcamcorder->rm_handle == 0) {
                ret = rm_register((rm_resource_cb)__mmcamcorder_rm_callback,
                        (void*)hcamcorder,
                        &(hcamcorder->rm_handle),
-                       (rci.app_id[0] != '\0') ? &rci : NULL);
+                       (hcamcorder->rci.app_id[0] != '\0') ? &hcamcorder->rci : NULL);
                if (ret != RM_OK) {
                        MMCAM_LOG_ERROR("rm_register fail ret = %d",ret);
                        return MM_ERROR_RESOURCE_INTERNAL;
@@ -115,6 +110,11 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
                return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
 
+       MMCAM_LOG_INFO("app id : %s", hcamcorder->rci.app_id);
+       /* if the app_id is null,
+          In the multiview mode, the rc_get_capable_category_id returns the error(RI_CATEGORY_NOT_PERMITTED).
+          In the normal mode, it returns the category itself which is passed in the parameter. */
+
        mm_camcorder_get_attributes(handle, NULL,
                MMCAM_DISPLAY_SURFACE, &display_surface_type,
                NULL);
@@ -131,7 +131,7 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
                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;
-
+                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, RM_CATEGORY_VIDEO_DECODER);
                        MMCAM_LOG_INFO("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER);
 
                        resource_count++;
@@ -139,16 +139,16 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
                        mm_camcorder_get_attributes(handle, NULL,
                                MMCAM_CAMERA_WIDTH, &camera_width,
                                NULL);
-
                        hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
                        hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_MJPEG_DECODER;
-                       hcamcorder->request_resources.category_option[resource_count] = ri_get_jpeg_category_id("MJPEG", camera_width);
+                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, ri_get_jpeg_category_id("MJPEG", camera_width));
                        MMCAM_LOG_INFO("request dec rsc - category 0x%x, option width [%d]", RM_CATEGORY_MJPEG_DECODER, camera_width);
                        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;
+                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, RM_CATEGORY_SCALER);
                        MMCAM_LOG_INFO("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
                        resource_count++;
                }
@@ -159,7 +159,6 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
                        qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
                        if (qret != RM_OK || qret_avail != 1) {
                                MMCAM_LOG_INFO("rm query failed. retry with sub devices");
-
                                resource_count = 0;
                                memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
                                memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
@@ -167,27 +166,23 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
                                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_SUB;
+                                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, RM_DEVICE_OPT_SUB);
                                        MMCAM_LOG_INFO("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER_SUB);
                                        resource_count++;
                                } else if (preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
                                        hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
                                        hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_MJPEG_DECODER;
-                                       hcamcorder->request_resources.category_option[resource_count] = ri_get_jpeg_category_id("MJPEG", camera_width);
+                                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, ri_get_jpeg_category_id("MJPEG", camera_width));
                                        MMCAM_LOG_INFO("request dec rsc - category 0x%x", RM_CATEGORY_MJPEG_DECODER);
                                        resource_count++;
                                }
-                               if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
-                                       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_SCALER_SUB;
-                                               MMCAM_LOG_INFO("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
-                                               resource_count++;
-                                       } else if (preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
-                                               hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
-                                               hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
-                                               MMCAM_LOG_INFO("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
-                                               resource_count++;
-                                       }
+                               if ((display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) &&
+                                       (preview_format == MM_PIXEL_FORMAT_ENCODED_H264 || preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG)) {
+                                       hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+                                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
+                                       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, RM_DEVICE_OPT_SUB);
+                                       MMCAM_LOG_INFO("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
+                                       resource_count++;
                                }
                        }
                }
@@ -195,6 +190,7 @@ int _mmcamcorder_rm_allocate(MMHandleType handle)
 
        hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
        hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA;
+       hcamcorder->request_resources.category_option[resource_count] = rc_get_capable_category_id(hcamcorder->rm_handle, hcamcorder->rci.app_id, RM_CATEGORY_CAMERA);
 
        hcamcorder->request_resources.request_num = resource_count + 1;
        MMCAM_LOG_INFO("request camera rsc - category 0x%x", RM_CATEGORY_CAMERA);