Change event class from THREAD_MAIN to THREAD_SUB for capture callback 04/91804/1 accepted/tizen/common/20161012.154128 accepted/tizen/ivi/20161012.065352 accepted/tizen/mobile/20161012.065232 accepted/tizen/tv/20161012.065303 accepted/tizen/wearable/20161012.065325 submit/tizen/20161012.010406
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 11 Oct 2016 11:19:19 +0000 (20:19 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Tue, 11 Oct 2016 11:19:19 +0000 (20:19 +0900)
THREAD_MAIN event class is workaround code for TBT test.
It's rollbacked because this commit will make capture callback as syncronously,
then TBT capture issue could not be occurred.
(capture completed callback can be called although capture callback is not returned.)

[Version] 0.2.52
[Profile] Common
[Issue Type] Update
[Dependency module] N/A
[Dependency commit] N/A
[Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-mobile_20161007.1]

Change-Id: I6430ccca7c8acf7a2f9b7333f9dc440a8de844ea
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
muse/include/muse_camera.h
muse/include/muse_camera_internal.h
muse/src/muse_camera_dispatcher.c
packaging/mmsvc-camera.spec

index 909bf11..c420d31 100644 (file)
@@ -248,6 +248,7 @@ typedef struct {
        int key;
        void *internal_buffer;
        tbm_bo data_bo;
+       bool is_capture;
 } muse_camera_export_data;
 
 
index 1637990..6c92e98 100644 (file)
@@ -41,6 +41,7 @@ typedef struct {
        tbm_bufmgr bufmgr;
        GList *data_list;
        GMutex list_lock;
+       GCond list_cond;
        GMutex preview_cb_lock;
        GCond preview_cb_cond;
        guint preview_cb_flag;
index 546c8f0..f490120 100644 (file)
@@ -305,6 +305,11 @@ static int _camera_remove_export_data(muse_module_h module, int key, int remove_
                        if (export_data->key == key || remove_all) {
                                /*LOGD("key %d matched, remove it (remove_all %d)", key, remove_all);*/
 
+                               if (export_data->is_capture) {
+                                       LOGD("capture callback is done");
+                                       g_cond_signal(&muse_camera->list_cond);
+                               }
+
                                if (export_data->bo) {
                                        tbm_bo_unref(export_data->bo);
                                        export_data->bo = NULL;
@@ -373,158 +378,168 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da
        int tbm_key_thumb = 0;
        muse_module_h module = (muse_module_h)user_data;
        unsigned char *buf_pos = NULL;
+       gint64 end_time = 0;
 
        LOGD("Enter!!");
 
        muse_camera = (muse_camera_handle_s *)muse_core_ipc_get_handle(module);
-       if (muse_camera == NULL) {
-               LOGE("NULL handle");
+       if (!muse_camera || !image || image->size <= 0) {
+               LOGE("invalid ptr %p %p or size %d", muse_camera, image, image->size);
                return;
        }
 
+       /* main image */
        export_data_main = g_new0(muse_camera_export_data, 1);
        if (export_data_main == NULL) {
                LOGE("alloc export_data failed");
                return;
        }
 
-       if (image != NULL) {
-               if (image->size > 0) {
-                       data_size_main = sizeof(camera_image_data_s) + image->size;
+       data_size_main = sizeof(camera_image_data_s) + image->size;
 
-                       /* alloc bo */
-                       bo_main = tbm_bo_alloc(muse_camera->bufmgr, data_size_main, TBM_BO_DEFAULT);
-                       if (bo_main == NULL) {
-                               LOGE("bo alloc failed");
-                               goto main_image_error;
-                       }
-
-                       bo_main_handle = tbm_bo_map(bo_main, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
-                       if (bo_main_handle.ptr == NULL) {
-                               LOGE("bo map Error!");
-                               goto main_image_error;
-                       }
+       /* alloc bo */
+       bo_main = tbm_bo_alloc(muse_camera->bufmgr, data_size_main, TBM_BO_DEFAULT);
+       if (bo_main == NULL) {
+               LOGE("bo alloc failed");
+               goto main_image_error;
+       }
 
-                       buf_pos = (unsigned char *)bo_main_handle.ptr;
-                       memcpy(buf_pos, image, sizeof(camera_image_data_s));
-                       buf_pos += sizeof(camera_image_data_s);
-                       memcpy(buf_pos, image->data, image->size);
-                       tbm_bo_unmap(bo_main);
+       bo_main_handle = tbm_bo_map(bo_main, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
+       if (bo_main_handle.ptr == NULL) {
+               LOGE("bo map Error!");
+               goto main_image_error;
+       }
 
-                       tbm_key_main = tbm_bo_export(bo_main);
-                       if (tbm_key_main == 0) {
-                               LOGE("Create key_info ERROR!!");
-                               goto main_image_error;
-                       }
-                       LOGD("bo %p, vaddr %p, size %d, key %d",
-                               bo_main, bo_main_handle.ptr, data_size_main, tbm_key_main);
+       buf_pos = (unsigned char *)bo_main_handle.ptr;
+       memcpy(buf_pos, image, sizeof(camera_image_data_s));
+       buf_pos += sizeof(camera_image_data_s);
+       memcpy(buf_pos, image->data, image->size);
+       tbm_bo_unmap(bo_main);
 
-                       /* set bo info */
-                       export_data_main->key = tbm_key_main;
-                       export_data_main->bo = bo_main;
-               }
+       tbm_key_main = tbm_bo_export(bo_main);
+       if (tbm_key_main == 0) {
+               LOGE("Create key_info ERROR!!");
+               goto main_image_error;
        }
 
-       if (postview != NULL) {
-               if (postview->size > 0) {
-                       data_size_post = sizeof(camera_image_data_s) + postview->size;
+       LOGD("bo %p, vaddr %p, size %d, key %d",
+               bo_main, bo_main_handle.ptr, data_size_main, tbm_key_main);
 
-                       export_data_post = g_new0(muse_camera_export_data, 1);
-                       if (export_data_post == NULL) {
-                               LOGE("alloc export_data failed");
-                               goto postview_image_error;
-                       }
+       /* set bo info */
+       export_data_main->key = tbm_key_main;
+       export_data_main->bo = bo_main;
+       export_data_main->is_capture = true;
 
-                       /* alloc bo */
-                       bo_post = tbm_bo_alloc(muse_camera->bufmgr, data_size_post, TBM_BO_DEFAULT);
-                       if (bo_post == NULL) {
-                               LOGE("bo alloc failed");
-                               goto postview_image_error;
-                       }
+       /* postview image */
+       if (postview && postview->size > 0) {
+               data_size_post = sizeof(camera_image_data_s) + postview->size;
 
-                       bo_post_handle = tbm_bo_map(bo_post, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
-                       if (bo_post_handle.ptr == NULL) {
-                               LOGE("bo map Error!");
-                               goto postview_image_error;
-                       }
+               export_data_post = g_new0(muse_camera_export_data, 1);
+               if (export_data_post == NULL) {
+                       LOGE("alloc export_data failed");
+                       goto postview_image_error;
+               }
 
-                       buf_pos = (unsigned char *)bo_post_handle.ptr;
-                       memcpy(buf_pos, postview, sizeof(camera_image_data_s));
-                       buf_pos += sizeof(camera_image_data_s);
-                       memcpy(buf_pos, postview->data, postview->size);
-                       tbm_bo_unmap(bo_post);
+               /* alloc bo */
+               bo_post = tbm_bo_alloc(muse_camera->bufmgr, data_size_post, TBM_BO_DEFAULT);
+               if (bo_post == NULL) {
+                       LOGE("bo alloc failed");
+                       goto postview_image_error;
+               }
 
-                       tbm_key_post = tbm_bo_export(bo_post);
-                       if (tbm_key_post == 0) {
-                               LOGE("Create key_info ERROR!!");
-                               goto postview_image_error;
-                       }
+               bo_post_handle = tbm_bo_map(bo_post, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
+               if (bo_post_handle.ptr == NULL) {
+                       LOGE("bo map Error!");
+                       goto postview_image_error;
+               }
 
-                       /* set bo info */
-                       export_data_post->key = tbm_key_post;
-                       export_data_post->bo = bo_post;
+               buf_pos = (unsigned char *)bo_post_handle.ptr;
+               memcpy(buf_pos, postview, sizeof(camera_image_data_s));
+               buf_pos += sizeof(camera_image_data_s);
+               memcpy(buf_pos, postview->data, postview->size);
+               tbm_bo_unmap(bo_post);
+
+               tbm_key_post = tbm_bo_export(bo_post);
+               if (tbm_key_post == 0) {
+                       LOGE("Create key_info ERROR!!");
+                       goto postview_image_error;
                }
-       }
 
-       if (thumbnail != NULL) {
-               if (thumbnail->size > 0) {
-                       data_size_thumb = sizeof(camera_image_data_s) + thumbnail->size;
+               /* set bo info */
+               export_data_post->key = tbm_key_post;
+               export_data_post->bo = bo_post;
+       }
 
-                       export_data_thumb = g_new0(muse_camera_export_data, 1);
-                       if (export_data_thumb == NULL) {
-                               LOGE("alloc export_data failed");
-                               goto thumbnail_image_error;
-                       }
+       /* thumbnail image */
+       if (thumbnail && thumbnail->size > 0) {
+               data_size_thumb = sizeof(camera_image_data_s) + thumbnail->size;
 
-                       /* alloc bo */
-                       bo_thumb = tbm_bo_alloc(muse_camera->bufmgr, data_size_thumb, TBM_BO_DEFAULT);
-                       if (bo_thumb == NULL) {
-                               LOGE("bo alloc failed");
-                               goto thumbnail_image_error;
-                       }
+               export_data_thumb = g_new0(muse_camera_export_data, 1);
+               if (export_data_thumb == NULL) {
+                       LOGE("alloc export_data failed");
+                       goto thumbnail_image_error;
+               }
 
-                       bo_thumb_handle = tbm_bo_map(bo_thumb, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
-                       if (bo_thumb_handle.ptr == NULL) {
-                               LOGE("bo map Error!");
-                               goto thumbnail_image_error;
-                       }
+               /* alloc bo */
+               bo_thumb = tbm_bo_alloc(muse_camera->bufmgr, data_size_thumb, TBM_BO_DEFAULT);
+               if (bo_thumb == NULL) {
+                       LOGE("bo alloc failed");
+                       goto thumbnail_image_error;
+               }
 
-                       buf_pos = (unsigned char *)bo_thumb_handle.ptr;
-                       memcpy(buf_pos, thumbnail, sizeof(camera_image_data_s));
-                       buf_pos += sizeof(camera_image_data_s);
-                       memcpy(buf_pos, thumbnail->data, thumbnail->size);
-                       tbm_bo_unmap(bo_thumb);
+               bo_thumb_handle = tbm_bo_map(bo_thumb, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
+               if (bo_thumb_handle.ptr == NULL) {
+                       LOGE("bo map Error!");
+                       goto thumbnail_image_error;
+               }
 
-                       tbm_key_thumb = tbm_bo_export(bo_thumb);
-                       if (tbm_key_thumb == 0) {
-                               LOGE("Create key_info ERROR!!");
-                               goto thumbnail_image_error;
-                       }
+               buf_pos = (unsigned char *)bo_thumb_handle.ptr;
+               memcpy(buf_pos, thumbnail, sizeof(camera_image_data_s));
+               buf_pos += sizeof(camera_image_data_s);
+               memcpy(buf_pos, thumbnail->data, thumbnail->size);
+               tbm_bo_unmap(bo_thumb);
 
-                       /* set bo info */
-                       export_data_thumb->key = tbm_key_thumb;
-                       export_data_thumb->bo = bo_thumb;
+               tbm_key_thumb = tbm_bo_export(bo_thumb);
+               if (tbm_key_thumb == 0) {
+                       LOGE("Create key_info ERROR!!");
+                       goto thumbnail_image_error;
                }
+
+               /* set bo info */
+               export_data_thumb->key = tbm_key_thumb;
+               export_data_thumb->bo = bo_thumb;
        }
 
        /* add bo info to list */
        g_mutex_lock(&muse_camera->list_lock);
+
        muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_main);
-       if (export_data_post != NULL)
+
+       if (export_data_post)
                muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_post);
-       if (export_data_thumb != NULL)
+
+       if (export_data_thumb)
                muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_thumb);
-       g_mutex_unlock(&muse_camera->list_lock);
 
        /* send message */
        muse_camera_msg_event3(MUSE_CAMERA_CB_EVENT,
                MUSE_CAMERA_EVENT_TYPE_CAPTURE,
-               MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
+               MUSE_CAMERA_EVENT_CLASS_THREAD_SUB,
                module,
                INT, tbm_key_main,
                INT, tbm_key_post,
                INT, tbm_key_thumb);
 
+       /* wait for capture callback return */
+       end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND * 3;
+       if (!g_cond_wait_until(&muse_camera->list_cond, &muse_camera->list_lock, end_time)) {
+               LOGW("capture callback return timeout");
+       } else {
+               LOGD("capture callback return");
+       }
+
+       g_mutex_unlock(&muse_camera->list_lock);
+
        return;
 
 thumbnail_image_error:
@@ -1080,6 +1095,7 @@ int camera_dispatcher_create(muse_module_h module)
        }
 
        g_mutex_init(&muse_camera->list_lock);
+       g_cond_init(&muse_camera->list_cond);
        g_mutex_init(&muse_camera->preview_cb_lock);
        g_cond_init(&muse_camera->preview_cb_cond);
        muse_camera->preview_cb_flag = 0;
@@ -1141,6 +1157,7 @@ int camera_dispatcher_destroy(muse_module_h module)
                _camera_remove_export_data(module, 0, TRUE);
 
                g_mutex_clear(&muse_camera->list_lock);
+               g_cond_clear(&muse_camera->list_cond);
                g_mutex_clear(&muse_camera->preview_cb_lock);
                g_cond_clear(&muse_camera->preview_cb_cond);
 
index fc96504..462891d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mmsvc-camera
 Summary:    A Camera module for muse server
-Version:    0.2.51
+Version:    0.2.52
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0