#undef LOG_TAG
#endif
#define LOG_TAG "MUSED_CAMERA"
-#define KEY_NUM 9527
+#define KEY_LENGTH 24
#define CAMERA_PRIVILEGE_NAME "http://tizen.org/privilege/camera"
void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
{
muse_module_h module = (muse_module_h)user_data;
+ muse_camera_handle_s *muse_camera = NULL;
+ camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
+ char value_key[KEY_LENGTH] = {'\0',};
+ int ret = CAMERA_ERROR_NONE;
+ int set_value = -1;
LOGD("Enter - previous %d, current %d, by_policy %d",
previous, current, by_policy);
INT, current,
INT, by_policy);
+ muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
+ if (muse_camera) {
+ ret = legacy_camera_get_device_type(muse_camera->camera_handle, &device_type);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("get device type failed 0x%x", ret);
+ return;
+ }
+
+ snprintf(value_key, KEY_LENGTH, "device_state_camera%d", device_type);
+ if (previous == CAMERA_STATE_CREATED && current == CAMERA_STATE_PREVIEW)
+ set_value = CAMERA_DEVICE_STATE_WORKING;
+ else if (previous == CAMERA_STATE_PREVIEW && current == CAMERA_STATE_CREATED)
+ set_value = CAMERA_DEVICE_STATE_NULL;
+
+ if (set_value != -1) {
+ LOGD("device state set : %d", set_value);
+ muse_core_client_set_value(module, value_key, set_value);
+ }
+ } else {
+ LOGW("NULL muse camera handle");
+ }
+
return;
}
return MUSE_CAMERA_ERROR_NONE;
}
+ ret = legacy_camera_set_state_changed_cb(muse_camera->camera_handle,
+ (camera_state_changed_cb)_camera_dispatcher_state_changed_cb,
+ (void *)module);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("legacy_camera_set_state_changed_cb failed : 0x%x", ret);
+ goto _CREATE_ERROR;
+ }
+
ret = legacy_camera_set_client_pid(muse_camera->camera_handle, pid);
if (ret != CAMERA_ERROR_NONE) {
LOGE("legacy_camera_set_client_pid failed : 0x%x", ret);
-
- legacy_camera_destroy(muse_camera->camera_handle);
- muse_camera->camera_handle = NULL;
-
- free(muse_camera);
- muse_camera = NULL;
- muse_camera_msg_return(api, class, ret, module);
-
- return MUSE_CAMERA_ERROR_NONE;
+ goto _CREATE_ERROR;
}
g_mutex_init(&muse_camera->list_lock);
muse_camera_msg_return1(api, class, ret, module, POINTER, handle);
return MUSE_CAMERA_ERROR_NONE;
+
+_CREATE_ERROR:
+ legacy_camera_destroy(muse_camera->camera_handle);
+ muse_camera->camera_handle = NULL;
+
+ free(muse_camera);
+ muse_camera = NULL;
+ muse_camera_msg_return(api, class, ret, module);
+
+ return MUSE_CAMERA_ERROR_NONE;
}
muse_camera_handle_s *muse_camera = NULL;
muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
- char *caps = NULL;
- camera_state_e prev_state = CAMERA_STATE_NONE;
muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
LOGD("handle : %p", muse_camera);
- legacy_camera_get_state(muse_camera->camera_handle, &prev_state);
-
ret = legacy_camera_start_preview(muse_camera->camera_handle);
- if (ret != CAMERA_ERROR_NONE) {
- LOGD("start preview failed 0x%x", ret);
- muse_camera_msg_return(api, class, ret, module);
- return MUSE_CAMERA_ERROR_NONE;
- }
- if (prev_state == CAMERA_STATE_CREATED) {
- ret = legacy_camera_get_video_caps(muse_camera->camera_handle, &caps);
- if (ret == CAMERA_ERROR_NONE && caps) {
- LOGD("caps : %s", caps);
- muse_camera_msg_return2(api, class, ret, module, STRING, caps, INT, prev_state);
- g_free(caps);
- } else {
- LOGD("Failed to get server's video caps. ret 0x%x, caps %p", ret, caps);
- muse_camera_msg_return(api, class, ret, module);
- if (legacy_camera_stop_preview(muse_camera->camera_handle) != CAMERA_ERROR_NONE) {
- LOGW("failed to stop preview");
- }
- }
- } else {
- LOGD("preview started after capture");
- muse_camera_msg_return1(api, class, ret, module, INT, prev_state);
- }
+ muse_camera_msg_return(api, class, ret, module);
return MUSE_CAMERA_ERROR_NONE;
}
{
int ret = CAMERA_ERROR_NONE;
int count = 0;
+ char value_key[KEY_LENGTH] = {'\0',};
camera_h camera = NULL;
camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
camera_flash_state_e get_flash_state = CAMERA_FLASH_STATE_NOT_USED;
muse_camera_msg_get(device_type, muse_core_client_get_msg(module));
if (device_type < CAMERA_DEVICE_CAMERA0 || device_type > CAMERA_DEVICE_CAMERA1) {
- LOGE("invalid device type %d", device_type);
+ LOGE("invalid device %d", device_type);
ret = CAMERA_ERROR_INVALID_PARAMETER;
muse_camera_msg_return(api, class, ret, module);
return MUSE_CAMERA_ERROR_NONE;
}
- if (device_type == CAMERA_DEVICE_CAMERA0)
- muse_core_client_get_value(module, "flash_state_camera0", (int *)&get_flash_state);
- else
- muse_core_client_get_value(module, "flash_state_camera1", (int *)&get_flash_state);
+ snprintf(value_key, KEY_LENGTH, "flash_state_camera%d", device_type);
+ muse_core_client_get_value(module, value_key, (int *)&get_flash_state);
- LOGD("fash state : %d", get_flash_state);
+ LOGD("[%d] flash state : %d", device_type, get_flash_state);
muse_camera_msg_return1(api, class, ret, module, INT, get_flash_state);
int camera_dispatcher_set_state_changed_cb(muse_module_h module)
{
int ret = CAMERA_ERROR_NONE;
- muse_camera_handle_s *muse_camera = NULL;
muse_camera_api_e api = MUSE_CAMERA_API_SET_STATE_CHANGED_CB;
muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
- muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
-
- LOGD("handle : %p", muse_camera);
-
- ret = legacy_camera_set_state_changed_cb(muse_camera->camera_handle,
- (camera_state_changed_cb)_camera_dispatcher_state_changed_cb,
- (void *)module);
-
- LOGD("ret : 0x%x", ret);
+ LOGD("Enter");
muse_camera_msg_return(api, class, ret, module);
int camera_dispatcher_unset_state_changed_cb(muse_module_h module)
{
int ret = CAMERA_ERROR_NONE;
- muse_camera_handle_s *muse_camera = NULL;
muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
- muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
-
- LOGD("handle : %p", muse_camera);
-
- ret = legacy_camera_unset_state_changed_cb(muse_camera->camera_handle);
-
- LOGD("ret : 0x%x", ret);
+ LOGD("Enter");
muse_camera_msg_return(api, class, ret, module);
int camera_dispatcher_attr_set_flash_mode(muse_module_h module)
{
int ret = CAMERA_ERROR_NONE;
- muse_camera_handle_s *muse_camera = NULL;
int set_mode = 0;;
+ char value_key[KEY_LENGTH] = {'\0',};
+ muse_camera_handle_s *muse_camera = NULL;
camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
if (ret == CAMERA_ERROR_NONE) {
ret = legacy_camera_get_device_type(muse_camera->camera_handle, &device_type);
if (ret == CAMERA_ERROR_NONE) {
- if (device_type == CAMERA_DEVICE_CAMERA0)
- muse_core_client_set_value(module, "flash_state_camera0", set_mode > 0 ? 1 : 0);
- else
- muse_core_client_set_value(module, "flash_state_camera1", set_mode > 0 ? 1 : 0);
+ snprintf(value_key, KEY_LENGTH, "flash_state_camera%d", device_type);
+ muse_core_client_set_value(module, value_key, set_mode > 0 ? 1 : 0);
}
}
return MUSE_CAMERA_ERROR_NONE;
}
+int camera_dispatcher_get_device_state(muse_module_h module)
+{
+ int ret = CAMERA_ERROR_NONE;
+ char value_key[KEY_LENGTH] = {'\0',};
+ camera_h camera = NULL;
+ camera_device_e device_type = CAMERA_DEVICE_CAMERA0;
+ camera_device_state_e get_device_state = CAMERA_DEVICE_STATE_NULL;
+ muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_STATE;
+ muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE;
+
+ muse_camera_msg_get(device_type, muse_core_client_get_msg(module));
+
+ if (device_type < CAMERA_DEVICE_CAMERA0 || device_type > CAMERA_DEVICE_CAMERA1) {
+ LOGE("invalid device %d", device_type);
+
+ ret = CAMERA_ERROR_INVALID_PARAMETER;
+ muse_camera_msg_return(api, class, ret, module);
+
+ return MUSE_CAMERA_ERROR_NONE;
+ }
+
+ ret = legacy_camera_create(device_type, &camera);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("failed to create camera handle 0x%x", ret);
+
+ muse_camera_msg_return(api, class, ret, module);
+
+ return MUSE_CAMERA_ERROR_NONE;
+ }
+
+ legacy_camera_destroy(camera);
+ camera = NULL;
+
+ snprintf(value_key, KEY_LENGTH, "device_state_camera%d", device_type);
+ muse_core_client_get_value(module, value_key, (int *)&get_device_state);
+
+ LOGD("device[%d] state : %d", device_type, get_device_state);
+
+ muse_camera_msg_return1(api, class, ret, module, INT, get_device_state);
+
+ return MUSE_CAMERA_ERROR_NONE;
+}
+
int (*dispatcher[MUSE_CAMERA_API_MAX]) (muse_module_h module) = {
camera_dispatcher_create, /* MUSE_CAMERA_API_CREATE */
camera_dispatcher_destroy, /* MUSE_CAMERA_API_DESTROY */
camera_dispatcher_preview_cb_return, /* MUSE_CAMERA_API_PREVIEW_CB_RETURN */
camera_dispatcher_set_display_reuse_hint, /* MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT */
camera_dispatcher_get_display_reuse_hint, /* MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT */
- camera_dispatcher_change_device /* MUSE_CAMERA_API_CHANGE_DEVICE */
+ camera_dispatcher_change_device, /* MUSE_CAMERA_API_CHANGE_DEVICE */
+ camera_dispatcher_get_device_state /* MUSE_CAMERA_API_GET_DEVICE_STATE */
};