[Release version 0.10.47] Fix bug for DPM usage - could not check microphone policy
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_platform.c
index 5c5df8c..5817538 100644 (file)
@@ -35,7 +35,6 @@
 /*---------------------------------------------------------------------------
 |    LOCAL VARIABLE DEFINITIONS for internal                                                           |
 ---------------------------------------------------------------------------*/
-#define        MM_CAMCORDER_ATTR_NONE  -1
 
 
 // Rule 1. 1:1 match except NONE.
@@ -221,6 +220,18 @@ _MMCamcorderEnumConvert _mmcamcorder_enum_conv_detect_mode =
  * For detail information, refer below documents.
  *
  */
+static _MMCamcorderInfoConverting      g_audio_info[] = {
+       {
+               CONFIGURE_TYPE_MAIN,
+               CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
+               MM_CAM_AUDIO_DEVICE,
+               MM_CAMCORDER_ATTR_NONE,
+               "AudioDevice",
+               MM_CAMCONVERT_TYPE_INT_ARRAY,
+               NULL,
+       }
+};
+
 static _MMCamcorderInfoConverting      g_display_info[] = {
        {
                CONFIGURE_TYPE_MAIN,
@@ -282,23 +293,59 @@ static _MMCamcorderInfoConverting g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
        {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_CAMERA,
-               MM_CAM_CAMERA_FPS,
+               MM_CAM_CAMERA_FORMAT,
                MM_CAMCORDER_ATTR_NONE,
-               "FPS",
+               "PictureFormat",
                MM_CAMCONVERT_TYPE_INT_ARRAY,
                NULL,
        },
-       { /* 5 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_CAMERA,
-               MM_CAM_CAMERA_FORMAT,
+               MM_CAM_CAMERA_PAN_MECHA,
                MM_CAMCORDER_ATTR_NONE,
-               "PictureFormat",
-               MM_CAMCONVERT_TYPE_INT_ARRAY,
+               "PanMecha",
+               MM_CAMCONVERT_TYPE_INT_RANGE,
+               NULL,
+       },
+       {
+               CONFIGURE_TYPE_CTRL,
+               CONFIGURE_CATEGORY_CTRL_CAMERA,
+               MM_CAM_CAMERA_PAN_ELEC,
+               MM_CAMCORDER_ATTR_NONE,
+               "PanElec",
+               MM_CAMCONVERT_TYPE_INT_RANGE,
+               NULL,
+       },
+       {
+               CONFIGURE_TYPE_CTRL,
+               CONFIGURE_CATEGORY_CTRL_CAMERA,
+               MM_CAM_CAMERA_TILT_MECHA,
+               MM_CAMCORDER_ATTR_NONE,
+               "TiltMecha",
+               MM_CAMCONVERT_TYPE_INT_RANGE,
                NULL,
        },
        {
                CONFIGURE_TYPE_CTRL,
+               CONFIGURE_CATEGORY_CTRL_CAMERA,
+               MM_CAM_CAMERA_TILT_ELEC,
+               MM_CAMCORDER_ATTR_NONE,
+               "TiltElec",
+               MM_CAMCONVERT_TYPE_INT_RANGE,
+               NULL,
+       },
+       {
+               CONFIGURE_TYPE_CTRL,
+               CONFIGURE_CATEGORY_CTRL_CAMERA,
+               MM_CAM_CAMERA_PTZ_TYPE,
+               MM_CAMCORDER_ATTR_NONE,
+               "PtzType",
+               MM_CAMCONVERT_TYPE_INT_ARRAY,
+               NULL,
+       },
+       {/* 10 */
+               CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_STROBE,
                MM_CAM_STROBE_CONTROL,
                MM_CAMCORDER_ATTR_NONE,
@@ -333,7 +380,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_RANGE,
                NULL,
        },
-       { /* 10 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_EFFECT,
                MM_CAM_FILTER_CONTRAST,
@@ -378,7 +425,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_ARRAY,
                &_mmcamcorder_enum_conv_whitebalance,
        },
-       { /* 15 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_EFFECT,
                MM_CAM_FILTER_COLOR_TONE,
@@ -387,7 +434,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_ARRAY,
                &_mmcamcorder_enum_conv_colortone,
        },
-       {
+       {/* 20 */
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_EFFECT,
                MM_CAM_CAMERA_WDR,
@@ -423,7 +470,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_RANGE,
                NULL,
        },
-       { /* 20 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_PHOTOGRAPH,
                MM_CAM_CAMERA_OPTICAL_ZOOM,
@@ -477,7 +524,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_ARRAY,
                NULL,
        },
-       {
+       {/* 30 */
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_PHOTOGRAPH,
                MM_CAM_CAMERA_SHUTTER_SPEED,
@@ -513,7 +560,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_ARRAY,
                &_mmcamcorder_enum_conv_ahs,
        },
-       { /* 30 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_CAPTURE,
                MM_CAM_CAPTURE_FORMAT,
@@ -567,7 +614,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_RANGE,
                NULL,
        },
-       {
+       {/* 40 */
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_DETECT,
                MM_CAM_DETECT_FOCUS_SELECT,
@@ -603,7 +650,7 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
                MM_CAMCONVERT_TYPE_INT_PAIR_ARRAY,
                NULL,
        },
-       { /* 40 */
+       {
                CONFIGURE_TYPE_CTRL,
                CONFIGURE_CATEGORY_CTRL_PHOTOGRAPH,
                MM_CAM_CAMERA_VIDEO_STABILIZATION,
@@ -627,7 +674,6 @@ static _MMCamcorderInfoConverting   g_caminfo_convert[CAMINFO_CONVERT_NUM] = {
 |    LOCAL FUNCTION PROTOTYPES:                                                                                                |
 ---------------------------------------------------------------------------*/
 /* STATIC INTERNAL FUNCTION */
-static int  __mmcamcorder_set_info_to_attr( MMHandleType handle, _MMCamcorderInfoConverting *info, int table_size );
 static int  __mmcamcorder_get_valid_array(int * original_array, int original_count, int ** valid_array, int * valid_default );
 
 /*===========================================================================================
@@ -689,6 +735,71 @@ int _mmcamcorder_convert_msl_to_sensor(MMHandleType handle, int attr_idx, int ms
        return mslval;
 }
 
+int _mmcamcorder_get_fps_array_by_resolution(MMHandleType handle, int width, int height,  MMCamAttrsInfo* fps_info)
+{
+       MMCamAttrsInfo *infoW = NULL;
+       MMCamAttrsInfo *infoH = NULL;
+       int i = 0;
+       char nameFps[10] = {0,};
+       bool valid_check = false;
+
+       type_int_array *fps_array;
+
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       //_mmcam_dbg_log("prev resolution w:%d, h:%d", width, height);
+
+       infoW = (MMCamAttrsInfo*)calloc(1, sizeof(MMCamAttrsInfo));
+       if (infoW == NULL) {
+               _mmcam_dbg_err("failed to alloc infoW");
+               return MM_ERROR_CAMCORDER_LOW_MEMORY;
+       }
+
+       infoH = (MMCamAttrsInfo*)calloc(1, sizeof(MMCamAttrsInfo));
+       if (infoH == NULL) {
+               _mmcam_dbg_err("failed to alloc infoH");
+
+               free(infoW);
+               infoW = NULL;
+
+               return MM_ERROR_CAMCORDER_LOW_MEMORY;
+       }
+
+       mm_camcorder_get_attribute_info(handle, MMCAM_CAMERA_WIDTH, infoW);
+       mm_camcorder_get_attribute_info(handle, MMCAM_CAMERA_HEIGHT, infoH);
+
+       for(i=0; i < infoW->int_array.count; i++) {
+               //_mmcam_dbg_log("width :%d, height : %d\n", infoW->int_array.array[i], infoH->int_array.array[i]);
+               if(infoW->int_array.array[i] == width && infoH->int_array.array[i] == height) {
+                       valid_check = true;
+                       snprintf(nameFps, 10, "FPS%d", i);
+                       _mmcam_dbg_log("nameFps : %s!!!", nameFps);
+                       break;
+               }
+       }
+
+       free(infoW);
+       infoW = NULL;
+       free(infoH);
+       infoH = NULL;
+
+       if(!valid_check) {
+               _mmcam_dbg_err("FAILED : Can't find the valid resolution from attribute.");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       if (!_mmcamcorder_conf_get_value_int_array(hcamcorder->conf_ctrl, CONFIGURE_CATEGORY_CTRL_CAMERA, nameFps, &fps_array)) {
+               _mmcam_dbg_err("FAILED : Can't find the valid FPS array.");
+               return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
+       }
+
+       fps_info->int_array.count = fps_array->count;
+       fps_info->int_array.array = fps_array->value;
+       fps_info->int_array.def = fps_array->default_value;
+
+       return MM_ERROR_NONE;
+}
+
 //convert sensor value to MSL value
 int _mmcamcorder_convert_sensor_to_msl(MMHandleType handle, int attr_idx, int sensval)
 {
@@ -755,19 +866,24 @@ __mmcamcorder_get_valid_array(int * original_array, int original_count, int ** v
        if (valid_count > 0) {
                *valid_array = (int*)malloc(sizeof(int) * valid_count);
 
-               valid_count = 0;
-               for (i = 0; i < original_count; i++) {
-                       if (original_array[i] != _MMCAMCORDER_SENSOR_ENUM_NONE) {
-                               (*valid_array)[valid_count++] = i;
-                               //_mmcam_dbg_log( "valid_array[%d] = %d", valid_count-1, (*valid_array)[valid_count-1] );
-
-                               if (original_array[i] == *valid_default &&
-                                   new_default == _MMCAMCORDER_SENSOR_ENUM_NONE) {
-                                       new_default = i;
-                                       //_mmcam_dbg_log( "converted MSL default[%d]", new_default );
+               if (*valid_array) {
+                       valid_count = 0;
+                       for (i = 0; i < original_count; i++) {
+                               if (original_array[i] != _MMCAMCORDER_SENSOR_ENUM_NONE) {
+                                       (*valid_array)[valid_count++] = i;
+                                       /*_mmcam_dbg_log( "valid_array[%d] = %d", valid_count-1, (*valid_array)[valid_count-1] );*/
+
+                                       if (original_array[i] == *valid_default &&
+                                           new_default == _MMCAMCORDER_SENSOR_ENUM_NONE) {
+                                               new_default = i;
+                                               /*_mmcam_dbg_log( "converted MSL default[%d]", new_default );*/
+                                       }
                                }
                        }
                }
+               else {
+                       valid_count = 0;
+               }
        }
 
        if (new_default != _MMCAMCORDER_SENSOR_ENUM_NONE) {
@@ -778,7 +894,7 @@ __mmcamcorder_get_valid_array(int * original_array, int original_count, int ** v
 }
 
 
-int _mmcamcorder_init_attr_from_configure(MMHandleType handle)
+int _mmcamcorder_init_attr_from_configure(MMHandleType handle, MMCamConvertingCategory category)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderInfoConverting *info = NULL;
@@ -788,30 +904,48 @@ int _mmcamcorder_init_attr_from_configure(MMHandleType handle)
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("");
+       _mmcam_dbg_log("category : %d", category);
 
-       /* Initialize attribute related to camera control */
-       info = hcamcorder->caminfo_convert;
-       table_size = sizeof(g_caminfo_convert) / sizeof(_MMCamcorderInfoConverting);
-       ret = __mmcamcorder_set_info_to_attr( handle, info, table_size );
-       if( ret != MM_ERROR_NONE )
-       {
-               _mmcam_dbg_err( "ret : %x", ret );
-               return ret;
+       if (category & MM_CAMCONVERT_CATEGORY_CAMERA) {
+               /* Initialize attribute related to camera control */
+               info = hcamcorder->caminfo_convert;
+               table_size = sizeof(g_caminfo_convert) / sizeof(_MMCamcorderInfoConverting);
+               ret = __mmcamcorder_set_info_to_attr(handle, info, table_size);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("camera info set error : 0x%x", ret);
+                       return ret;
+               }
        }
 
-       /* Initialize attribute related to display */
-       info = g_display_info;
-       table_size = sizeof(g_display_info) / sizeof(_MMCamcorderInfoConverting);
-       ret = __mmcamcorder_set_info_to_attr( handle, info, table_size );
+       if (category & MM_CAMCONVERT_CATEGORY_DISPLAY) {
+               /* Initialize attribute related to display */
+               info = g_display_info;
+               table_size = sizeof(g_display_info) / sizeof(_MMCamcorderInfoConverting);
+               ret = __mmcamcorder_set_info_to_attr(handle, info, table_size);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("display info set error : 0x%x", ret);
+                       return ret;
+               }
+       }
 
-       _mmcam_dbg_log( "result: %x", ret );
+       if (category & MM_CAMCONVERT_CATEGORY_AUDIO) {
+               /* Initialize attribute related to audio */
+               info = g_audio_info;
+               table_size = sizeof(g_audio_info) / sizeof(_MMCamcorderInfoConverting);
+               ret = __mmcamcorder_set_info_to_attr(handle, info, table_size);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("audio info set error : 0x%x", ret);
+                       return ret;
+               }
+       }
+
+       _mmcam_dbg_log("done");
 
        return ret;
 }
 
-static int
-__mmcamcorder_set_info_to_attr( MMHandleType handle, _MMCamcorderInfoConverting *info, int table_size )
+
+int __mmcamcorder_set_info_to_attr(MMHandleType handle, _MMCamcorderInfoConverting *info, int table_size)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        MMHandleType     attrs      = 0;
@@ -833,7 +967,7 @@ __mmcamcorder_set_info_to_attr( MMHandleType handle, _MMCamcorderInfoConverting
                                info[i].type,
                                info[i].category,
                                info[i].attr_idx,
-                               info[i].attr_idx_sub,
+                               info[i].attr_idx_pair,
                                info[i].keyword,
                                info[i].conv_type );
                */
@@ -901,9 +1035,9 @@ __mmcamcorder_set_info_to_attr( MMHandleType handle, _MMCamcorderInfoConverting
                                                /* "mmf_attrs_set_valid_type" initializes spec value in attribute, so allocated memory could be missed */
                                                //mmf_attrs_set_valid_type(attrs, info[i].attr_idx, MM_ATTRS_VALID_TYPE_INT_ARRAY);
                                                mmf_attrs_set_valid_array(attrs, info[i].attr_idx, iarray, iarray_size, idefault);
-                                       }
 
-                                       ret = mm_attrs_set_int(MMF_CAMCORDER_ATTRS(hcamcorder), info[i].attr_idx, idefault);
+                                               ret = mm_attrs_set_int(MMF_CAMCORDER_ATTRS(hcamcorder), info[i].attr_idx, idefault);
+                                       }
                                }
 
                                if (iarray && iarray != tarray->value )