-int _mmcamcorder_create_command_loop(MMHandleType handle)
-{
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
- _MMCamcorderCommand *cmd;
-
- mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-
- _mmcam_dbg_log("");
-
- cmd = (_MMCamcorderCommand *)&(hcamcorder->cmd);
- cmd->cmd_queue = g_queue_new();
- mmf_return_val_if_fail(cmd->cmd_queue, MM_ERROR_CAMCORDER_INVALID_CONDITION);
-
- sem_init(&cmd->sema, 0, 0);
-
- if (pthread_create(&cmd->pCommandThread, NULL, _mmcamcorder_command_loop_thread, hcamcorder)) {
- perror("Make Command Thread Fail");
- return MM_ERROR_COMMON_UNKNOWN;
- }
-
- return MM_ERROR_NONE;
-}
-
-
-int _mmcamcorder_destroy_command_loop(MMHandleType handle)
-{
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
- _MMCamcorderCommand *cmd;
-
- mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
- _mmcam_dbg_log("");
-
- cmd = (_MMCamcorderCommand *)&(hcamcorder->cmd);
- mmf_return_val_if_fail(cmd->cmd_queue, MM_ERROR_CAMCORDER_INVALID_CONDITION);
-
- _mmcamcorder_append_simple_command(handle, _MMCAMCORDER_CMD_QUIT);
-
- sem_post(&cmd->sema); /* why is this needed? */
-
- _mmcam_dbg_log("wait for pthread join");
-
- pthread_join(cmd->pCommandThread, NULL);
-
- _mmcam_dbg_log("pthread join!!");
-
- sem_destroy(&cmd->sema);
-
- while (!g_queue_is_empty(cmd->cmd_queue)) {
- __MMCamcorderCmdInfo *info = NULL;
- info = g_queue_pop_head(cmd->cmd_queue);
- _mmcamcorder_delete_command_info(info);
- }
- g_queue_free(cmd->cmd_queue);
-
- _mmcam_dbg_log("Command loop clear.");
-
- return MM_ERROR_NONE;
-}
-
-
-int _mmcamcorder_append_command(MMHandleType handle, __MMCamcorderCmdInfo *info)
-{
- int value = 0;
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
- _MMCamcorderCommand *cmd;
-
- mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-
- _mmcam_dbg_log("");
-
- cmd = (_MMCamcorderCommand *)&(hcamcorder->cmd);
- mmf_return_val_if_fail(cmd->cmd_queue, MM_ERROR_CAMCORDER_INVALID_CONDITION);
-
- g_queue_push_tail (cmd->cmd_queue, (gpointer)info);
-
- sem_getvalue(&cmd->sema, &value);
-
- if (value == 0) {
- sem_post(&cmd->sema);
- } else {
- /* Don't need to post. */
- }
-
- return MM_ERROR_NONE;
-}
-
-
-int _mmcamcorder_append_simple_command(MMHandleType handle, _MMCamcorderCommandType type)
-{
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
- __MMCamcorderCmdInfo *info = NULL;
-
- mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-
- _mmcam_dbg_log("Command Type=%d", type);
-
- info = (__MMCamcorderCmdInfo*)malloc(sizeof(__MMCamcorderCmdInfo));
-
- info->handle = handle;
- info->type = type;
-
- _mmcamcorder_append_command(handle, info);
-
- return MM_ERROR_NONE;
-}
-
-
-void *_mmcamcorder_command_loop_thread(void *arg)
-{
- gboolean bExit_loop = FALSE;
- mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(arg);
- _MMCamcorderCommand *cmd = NULL;
- __MMCamcorderCmdInfo *cmdinfo = NULL;
-
- mmf_return_val_if_fail(hcamcorder, NULL);
-
- cmd = (_MMCamcorderCommand *)&(hcamcorder->cmd);
- mmf_return_val_if_fail(cmd->cmd_queue, NULL);
-
- _mmcam_dbg_log("");
-
- while (!bExit_loop) {
- sem_wait(&cmd->sema);
-
- /* send command */
- while (!g_queue_is_empty (cmd->cmd_queue)) {
- int bRet = MM_ERROR_NONE;
-
- cmdinfo = g_queue_pop_head(cmd->cmd_queue);
- if (cmdinfo->handle == (MMHandleType)NULL) {
- _mmcam_dbg_log("Handle in cmdinfo is Null.");
- bRet = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
- } else {
- switch (cmdinfo->type) {
- case _MMCAMCORDER_CMD_CREATE:
- case _MMCAMCORDER_CMD_DESTROY:
- case _MMCAMCORDER_CMD_CAPTURESTART:
- case _MMCAMCORDER_CMD_CAPTURESTOP:
- case _MMCAMCORDER_CMD_RECORD:
- case _MMCAMCORDER_CMD_PAUSE:
- case _MMCAMCORDER_CMD_COMMIT:
- __ta__("_mmcamcorder_commit",
- bRet = _mmcamcorder_commit(cmdinfo->handle);
- );
- break;
- case _MMCAMCORDER_CMD_CANCEL:
- //Not used yet.
- break;
- case _MMCAMCORDER_CMD_REALIZE:
- __ta__("_mmcamcorder_realize",
- bRet = _mmcamcorder_realize(cmdinfo->handle);
- );
- break;
- case _MMCAMCORDER_CMD_UNREALIZE:
- __ta__("_mmcamcorder_unrealize",
- bRet = _mmcamcorder_unrealize(cmdinfo->handle);
- );
- break;
- case _MMCAMCORDER_CMD_START:
- __ta__("_mmcamcorder_start",
- bRet = _mmcamcorder_start(cmdinfo->handle);
- );
- break;
- case _MMCAMCORDER_CMD_STOP:
- __ta__("_mmcamcorder_stop",
- bRet = _mmcamcorder_stop(cmdinfo->handle);
- );
- break;
- case _MMCAMCORDER_CMD_QUIT:
- _mmcam_dbg_log("Exit command loop!!");
- bExit_loop = TRUE;
- break;
- default:
- _mmcam_dbg_log("Wrong command type!!!");
- break;
- }
- }
-
- if (bRet != MM_ERROR_NONE) {
- _mmcam_dbg_log("Error on command process!(%x)", bRet);
- /* Do something? */
- }
-
- _mmcamcorder_delete_command_info(cmdinfo);
-
- if (bExit_loop) {
- break;
- }
- usleep(1);
- }
- }
-
- return NULL;
-}
-