#include <mm_session.h>
#include <mm_session_private.h>
-#include <cynara-client.h>
/*---------------------------------------------------------------------------------------
| GLOBAL VARIABLE DEFINITIONS for internal |
#define __MMCAMCORDER_FORCE_STOP_TRY_COUNT 30
#define __MMCAMCORDER_FORCE_STOP_WAIT_TIME 100000 /* us */
#define __MMCAMCORDER_SOUND_WAIT_TIMEOUT 3
-#define __MMCAMCORDER_PATH_CAMERA_RESOURCE "/usr/share/sounds/mm-camcorder/camera_resource"
-#define __MMCAMCORDER_PATH_RECORDER_RESOURCE "/usr/share/sounds/mm-camcorder/recorder_resource"
/*---------------------------------------------------------------------------------------
int camera_device_count = MM_VIDEO_DEVICE_NUM;
int camera_default_flip = MM_FLIP_NONE;
int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
-#if 0
- int resource_fd = -1;
-#endif
char *err_attr_name = NULL;
const char *ConfCtrlFile = NULL;
mmf_camcorder_t *hcamcorder = NULL;
/* create task thread */
pthread_create(&(hcamcorder->task_thread), NULL, _mmcamcorder_util_task_thread_func, (void *)hcamcorder);
- /* get root directory */
- ret = _mmcamcorder_get_root_directory(&hcamcorder->root_directory);
- if (ret != MM_ERROR_NONE) {
- goto _ERR_DEFAULT_VALUE_INIT;
- }
-
if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
_mmcam_dbg_err("_mmcamcorder_create::video device type is out of range.");
/* set device type */
hcamcorder->device_type = info->videodev_type;
_mmcam_dbg_warn("Device Type : %d", hcamcorder->device_type);
-#if 0
- if (hcamcorder->device_type == MM_VIDEO_DEVICE_NONE) {
- resource_fd = open(__MMCAMCORDER_PATH_RECORDER_RESOURCE, O_RDONLY);
- } else {
- resource_fd = open(__MMCAMCORDER_PATH_CAMERA_RESOURCE, O_RDONLY);
- }
- if (resource_fd < 0) {
- _mmcam_dbg_log("open error %s : cur %d",strerror(errno),errno);
- if(errno == EPERM || errno == EACCES) {
- ret = MM_ERROR_COMMON_INVALID_PERMISSION;
- } else {
- ret = MM_ERROR_CAMCORDER_INTERNAL;
- }
- goto _ERR_DEFAULT_VALUE_INIT;
- } else {
- close(resource_fd);
- resource_fd = -1;
- _mmcam_dbg_warn("permission check done");
- }
-#else
- {
- FILE *fp = NULL;;
- int length_read = 0;
- int priv_check = FALSE;
- uid_t my_uid = 0;
- char *client_session = "";
- char *smack_string = NULL;
- char uid_string[50];
- size_t buffer_length = 0;
- cynara *p_cynara = NULL;
-
- if (cynara_initialize(&p_cynara, NULL) != CYNARA_API_SUCCESS) {
- ret = MM_ERROR_CAMCORDER_INTERNAL;
- goto _ERR_DEFAULT_VALUE_INIT;
- }
+ if (MM_ERROR_NONE == _mm_session_util_read_information(-1, &hcamcorder->session_type, &hcamcorder->session_flags)) {
+ _mmcam_dbg_log("use sound focus function.");
+ hcamcorder->sound_focus_register = TRUE;
- fp = fopen("/proc/self/attr/current", "r");
- if (fp == NULL) {
- ret = MM_ERROR_CAMCORDER_INTERNAL;
+ if (MM_ERROR_NONE != mm_sound_focus_get_id(&hcamcorder->sound_focus_id)) {
+ _mmcam_dbg_err("mm_sound_focus_get_uniq failed");
+ ret = MM_ERROR_POLICY_BLOCKED;
goto _ERR_DEFAULT_VALUE_INIT;
}
- length_read = getline(&smack_string, &buffer_length, fp);
- if (length_read > 0) {
- int cynara_ret = 0;
-
- my_uid = getuid();
- snprintf(uid_string, 50, "%d", my_uid);
- _mmcam_dbg_log("label %s, uid %u, %s", smack_string, my_uid, uid_string);
-
- if (hcamcorder->device_type == MM_VIDEO_DEVICE_NONE) {
- cynara_ret = cynara_check(p_cynara, smack_string, client_session, uid_string,
- "http://tizen.org/privilege/recorder");
- } else {
- cynara_ret = cynara_check(p_cynara, smack_string, client_session, uid_string,
- "http://tizen.org/privilege/camera");
- }
- if (cynara_ret == CYNARA_API_ACCESS_ALLOWED) {
- priv_check = TRUE;
- _mmcam_dbg_err("privilege check done");
- } else {
- ret = MM_ERROR_COMMON_INVALID_PERMISSION;
- _mmcam_dbg_err("permission denied");
- }
- } else {
- ret = MM_ERROR_CAMCORDER_INTERNAL;
- _mmcam_dbg_err("getline failed");
- }
-
- if (smack_string) {
- free(smack_string);
- smack_string = NULL;
- }
-
- fclose(fp);
- fp = NULL;
-
- cynara_finish(p_cynara);
- p_cynara = NULL;
-
- if (priv_check == FALSE) {
+ if (MM_ERROR_NONE != mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
+ getpid(),
+ "media",
+ _mmcamcorder_sound_focus_cb,
+ hcamcorder)) {
+ _mmcam_dbg_err("mm_sound_register_focus failed");
+ ret = MM_ERROR_POLICY_BLOCKED;
goto _ERR_DEFAULT_VALUE_INIT;
}
+
+ _mmcam_dbg_log("mm_sound_register_focus done - id %d, session type %d, flags 0x%x",
+ hcamcorder->sound_focus_id, hcamcorder->session_type, hcamcorder->session_flags);
+ } else {
+ _mmcam_dbg_log("_mm_session_util_read_information failed. skip sound focus function.");
+ hcamcorder->sound_focus_register = FALSE;
}
-#endif
/* Get Camera Configure information from Camcorder INI file */
_mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
goto _ERR_DEFAULT_VALUE_INIT;
}
- ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, info->videodev_type);
+ ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_CAMERA|MM_CAMCONVERT_CATEGORY_DISPLAY);
if (ret != MM_ERROR_NONE) {
_mmcam_dbg_warn("converting table initialize error!!");
ret = MM_ERROR_CAMCORDER_INTERNAL;
goto _ERR_DEFAULT_VALUE_INIT;
}
- ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, info->videodev_type);
+ ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
if (ret != MM_ERROR_NONE) {
_mmcam_dbg_warn("init attribute from configure error : 0x%x", ret);
ret = MM_ERROR_CAMCORDER_INTERNAL;
return MM_ERROR_NONE;
_ERR_DEFAULT_VALUE_INIT:
+ /* unregister sound focus */
+ if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
+ if (MM_ERROR_NONE != mm_sound_unregister_focus(hcamcorder->sound_focus_id)) {
+ _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed", hcamcorder->sound_focus_id);
+ } else {
+ _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done", hcamcorder->sound_focus_id);
+ }
+ } else {
+ _mmcam_dbg_warn("no need to unregister sound focus[%d, id %d]",
+ hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
+ }
+
/* Remove attributes */
if (hcamcorder->attributes) {
_mmcamcorder_dealloc_attribute((MMHandleType)hcamcorder, hcamcorder->attributes);
pthread_mutex_destroy(&(hcamcorder->task_thread_lock));
pthread_cond_destroy(&(hcamcorder->task_thread_cond));
- if (hcamcorder->root_directory) {
- free(hcamcorder->root_directory);
- hcamcorder->root_directory = NULL;
- }
-
/* Release handle */
memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
free(hcamcorder);
_mmcamcorder_remove_message_all(handle);
/* unregister sound focus */
- if(hcamcorder->sound_focus_register) {
- if (MM_ERROR_NONE != mm_sound_unregister_focus(hcamcorder->sound_focus_id)) {
- _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed", hcamcorder->sound_focus_id);
+ if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
+ if (mm_sound_unregister_focus(hcamcorder->sound_focus_id) != MM_ERROR_NONE) {
+ _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed",
+ hcamcorder->sound_focus_id);
+ } else {
+ _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done",
+ hcamcorder->sound_focus_id);
}
+ } else {
+ _mmcam_dbg_log("no need to unregister sound focus.[%d, id %d]",
+ hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
}
/* release model_name */
pthread_mutex_destroy(&(hcamcorder->task_thread_lock));
pthread_cond_destroy(&(hcamcorder->task_thread_cond));
- /* Release internal root directory string */
- if (hcamcorder->root_directory) {
- free(hcamcorder->root_directory);
- hcamcorder->root_directory = NULL;
- }
-
/* Release handle */
memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
free(hcamcorder);
mm_camcorder_get_attributes(handle, NULL,
MMCAM_DISPLAY_SURFACE, &display_surface_type,
MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
- MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
MMCAM_DISPLAY_SHM_SOCKET_PATH, &socket_path, &socket_path_len,
NULL);
vconf_recorder_state, VCONFKEY_RECORDER_STATE_CREATED);
}
- /* acquire sound focus or set sound focus watch callback */
- if(hcamcorder->sound_focus_register) {
+ /* sound focus */
+ if (hcamcorder->sound_focus_register) {
+ mm_camcorder_get_attributes(handle, NULL,
+ MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
+ NULL);
+
+ if (pid_for_sound_focus == 0) {
+ pid_for_sound_focus = getpid();
+ _mmcam_dbg_warn("pid for sound focus is not set, use my pid %d", pid_for_sound_focus);
+ }
+
+ /* acquire sound focus or set sound focus watch callback */
+ hcamcorder->acquired_focus = 0;
+ hcamcorder->sound_focus_watch_id = 0;
+
/* check session flags */
if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
/* acquire sound focus */
/* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
ret = MM_ERROR_POLICY_BLOCKED;
-
goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
}
+
+ hcamcorder->acquired_focus = FOCUS_FOR_BOTH;
} else if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
/* do nothing */
_mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
} else {
/* set sound focus watch callback */
- if (pid_for_sound_focus == 0) {
- _mmcam_dbg_warn("pid for sound focus is not set, so call getpid");
- pid_for_sound_focus = getpid();
- }
-
_mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
ret_sound = mm_sound_set_focus_watch_callback_for_session(pid_for_sound_focus,
- FOCUS_FOR_BOTH,
- (mm_sound_focus_changed_watch_cb)_mmcamcorder_sound_focus_watch_cb,
- hcamcorder,
- &hcamcorder->sound_focus_watch_id);
+ FOCUS_FOR_BOTH,
+ (mm_sound_focus_changed_watch_cb)_mmcamcorder_sound_focus_watch_cb,
+ hcamcorder,
+ &hcamcorder->sound_focus_watch_id);
if (ret_sound != MM_ERROR_NONE) {
_mmcam_dbg_err("mm_sound_set_focus_watch_callback failed [0x%x]", ret_sound);
/* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
ret = MM_ERROR_POLICY_BLOCKED;
-
goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
}
_mmcam_dbg_log("sound focus watch cb id %d", hcamcorder->sound_focus_watch_id);
}
+ } else {
+ _mmcam_dbg_log("no need to register sound focus");
}
+
/* alloc sub context */
hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
if(!hcamcorder->sub_context) {
case MM_DISPLAY_SURFACE_NULL:
videosink_element_type = strdup("VideosinkElementNull");
break;
+ case MM_DISPLAY_SURFACE_REMOTE:
+ videosink_element_type = strdup("VideosinkElementRemote");
+ break;
default:
videosink_element_type = strdup("VideosinkElementX");
break;
_ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
_MMCAMCORDER_UNLOCK_CMD(hcamcorder);
- if (hcamcorder->sound_focus_watch_id > 0) {
- ret_sound = mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
- if (ret_sound != MM_ERROR_NONE) {
- _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback failed [0x%x]", ret_sound);
+ if (hcamcorder->sound_focus_register) {
+ if (hcamcorder->sound_focus_watch_id > 0) {
+ if (mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id) != MM_ERROR_NONE) {
+ _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] failed",
+ hcamcorder->sound_focus_watch_id);
+ } else {
+ _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] done",
+ hcamcorder->sound_focus_watch_id);
+ }
}
- hcamcorder->sound_focus_watch_id = 0;
+ if (hcamcorder->acquired_focus > 0) {
+ if (mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL) != MM_ERROR_NONE) {
+ _mmcam_dbg_err("mm_sound_release_focus[focus %d] failed",
+ hcamcorder->acquired_focus);
+ } else {
+ _mmcam_dbg_err("mm_sound_release_focus[focus %d] done",
+ hcamcorder->acquired_focus);
+ }
+ }
}
_ERR_CAMCORDER_CMD_PRECON:
/* Deinitialize main context member */
hcamcorder->command = NULL;
- /* check who calls unrealize. it's no need to do nothing if caller is sound focus callback */
- if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM) {
- /* release sound focus or unset sound focus watch callback */
- if(hcamcorder->sound_focus_register) {
- int ret_sound = MM_ERROR_NONE;
+ _mmcam_dbg_log("focus register %d, session flag 0x%x, state_change_by_system %d",
+ hcamcorder->sound_focus_register, hcamcorder->session_flags, hcamcorder->state_change_by_system);
- /* check session flags */
- if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
- /* release sound focus */
- _mmcam_dbg_log("PAUSE_OTHERS - release sound focus");
+ /* release sound focus or unset sound focus watch callback */
+ if (hcamcorder->sound_focus_register) {
+ int ret_sound = MM_ERROR_NONE;
- ret_sound = mm_sound_release_focus(0, FOCUS_FOR_BOTH, NULL);
- if (ret_sound != MM_ERROR_NONE) {
- _mmcam_dbg_warn("mm_sound_release_focus failed [0x%x]", ret_sound);
- }
- } else if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
- /* do nothing */
- _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
- } else {
- /* unset sound focus watch callback */
- _mmcam_dbg_log("ETC - unset sound focus watch callback - id %d", hcamcorder->sound_focus_watch_id);
+ _mmcam_dbg_log("state_change_by_system %d, session flag 0x%x, acquired_focus %d, sound_focus_id %d, sound_focus_watch_id %d",
+ hcamcorder->state_change_by_system, hcamcorder->session_flags, hcamcorder->acquired_focus,
+ hcamcorder->sound_focus_id, hcamcorder->sound_focus_watch_id);
- if (hcamcorder->sound_focus_watch_id > 0) {
- ret_sound = mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
- if (ret_sound != MM_ERROR_NONE) {
- _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback failed [0x%x]", ret_sound);
- }
- } else {
- _mmcam_dbg_warn("invalid sound focus id %d", hcamcorder->sound_focus_watch_id);
- }
+ if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM &&
+ hcamcorder->sound_focus_watch_id > 0) {
+ ret_sound = mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+ if (ret_sound != MM_ERROR_NONE) {
+ _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback failed [0x%x]",
+ ret_sound);
+ } else {
+ _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback done");
+ }
+ } else {
+ _mmcam_dbg_warn("no need to unset watch callback.[state_change_by_system %d, sound_focus_watch_id %d]",
+ hcamcorder->state_change_by_system, hcamcorder->sound_focus_watch_id);
+ }
- hcamcorder->sound_focus_watch_id = 0;
+ if (hcamcorder->acquired_focus > 0) {
+ ret_sound = mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL);
+ if (ret_sound != MM_ERROR_NONE) {
+ _mmcam_dbg_warn("mm_sound_release_focus failed [0x%x]",
+ ret_sound);
+ } else {
+ _mmcam_dbg_log("mm_sound_release_focus done");
}
+ } else {
+ _mmcam_dbg_warn("no need to release focus - current acquired focus %d",
+ hcamcorder->acquired_focus);
}
}
_MMCAMCORDER_LOCK_ASM(hcamcorder);
if (focus_state == FOCUS_IS_RELEASED) {
- _mmcam_dbg_log("FOCUS is released : Stop pipeline[state:%d]", current_state);
+ hcamcorder->acquired_focus &= ~focus_type;
+
+ _mmcam_dbg_log("FOCUS is released [type %d, remained focus %d] : Stop pipeline[state:%d]",
+ focus_type, hcamcorder->acquired_focus, current_state);
__mmcamcorder_force_stop(hcamcorder);
} else if (focus_state == FOCUS_IS_ACQUIRED) {
_MMCamcorderMsgItem msg;
- _mmcam_dbg_log("FOCUS is acquired");
+ hcamcorder->acquired_focus |= focus_type;
+
+ _mmcam_dbg_log("FOCUS is acquired [type %d, new focus %d]",
+ focus_type, hcamcorder->acquired_focus);
msg.id = MM_MESSAGE_READY_TO_RESUME;
_mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);