Add defensive code for resource release conflict 70/117170/1
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 2 Mar 2017 11:42:54 +0000 (20:42 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 3 Mar 2017 05:54:27 +0000 (14:54 +0900)
Because of some reason, stopping preview can take much time.(some camera buffer is not returned.)
In that case, mm_camcorder_unrealize has timeout for resource release if resource release callback is come while stopping preview.
This patch prevent the situation and avoid the timeout.

[Version] 0.10.108
[Profile] Common
[Issue Type] Bug fix
[Dependency module] N/A
[Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=]

Change-Id: I09443314107e6da9dda061300e2ad03343d2e9a6
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/libmm-camcorder.spec
src/include/mm_camcorder_internal.h
src/mm_camcorder_internal.c
src/mm_camcorder_resource.c

index 670ca64..b9fb802 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.109
+Version:    0.10.110
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 3b0b83c..88c17dc 100644 (file)
@@ -778,6 +778,7 @@ typedef struct mmf_camcorder {
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        /* resource manager for H/W resources */
        MMCamcorderResourceManager resource_manager;
+       gboolean resource_release_cb_calling;
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
        /* gdbus */
index 61e71a6..97c1632 100644 (file)
@@ -1350,13 +1350,15 @@ int _mmcamcorder_unrealize(MMHandleType handle)
        }
 
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
+       _mmcam_dbg_warn("lock resource - cb calling %d", hcamcorder->resource_release_cb_calling);
+
+       _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
+
        if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
-               hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM) {
+               hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
+               hcamcorder->resource_release_cb_calling == FALSE) {
                gint64 end_time = 0;
 
-               _mmcam_dbg_log("lock resource");
-               _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
-
                /* release resource */
                ret = _mmcamcorder_resource_manager_release(&hcamcorder->resource_manager);
                if (ret == MM_ERROR_RESOURCE_INVALID_STATE) {
@@ -1380,10 +1382,11 @@ int _mmcamcorder_unrealize(MMHandleType handle)
 
                        _MMCAMCORDER_RESOURCE_WAIT_UNTIL(hcamcorder, end_time);
                }
-
-               _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
-               _mmcam_dbg_log("unlock resource");
        }
+
+       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
+
+       _mmcam_dbg_warn("unlock resource");
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
index 1b76787..cb4fd49 100644 (file)
@@ -231,17 +231,19 @@ static void __mmcamcorder_resource_release_cb(mrp_res_context_t *cx, const mrp_r
                return;
        }
 
-       _MMCAMCORDER_LOCK_ASM(camcorder);
+       _mmcam_dbg_warn("enter");
 
-       /* set value to inform a status is changed by resource manaer */
-       camcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_RM;
+       _MMCAMCORDER_LOCK_RESOURCE(camcorder);
 
        if (!mrp_res_equal_resource_set(rs, camcorder->resource_manager.rset)) {
-               _MMCAMCORDER_UNLOCK_ASM(camcorder);
+               _MMCAMCORDER_UNLOCK_RESOURCE(camcorder);
                _mmcam_dbg_warn("- resource set(%p) is not same as this camcorder handle's(%p)", rs, camcorder->resource_manager.rset);
                return;
        }
 
+       /* set flag for resource release callback */
+       camcorder->resource_release_cb_calling = TRUE;
+
        _mmcam_dbg_log(" - resource set state of camcorder(%p) is changed to [%s]",
                camcorder, __mmcamcorder_resource_state_to_str(rs->state));
 
@@ -254,6 +256,13 @@ static void __mmcamcorder_resource_release_cb(mrp_res_context_t *cx, const mrp_r
                }
        }
 
+       _MMCAMCORDER_UNLOCK_RESOURCE(camcorder);
+
+       _MMCAMCORDER_LOCK_ASM(camcorder);
+
+       /* set value to inform a status is changed by resource manager */
+       camcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_RM;
+
        /* Stop the camera */
        __mmcamcorder_force_stop(camcorder);
 
@@ -262,6 +271,15 @@ static void __mmcamcorder_resource_release_cb(mrp_res_context_t *cx, const mrp_r
 
        _MMCAMCORDER_UNLOCK_ASM(camcorder);
 
+       _MMCAMCORDER_LOCK_RESOURCE(camcorder);
+
+       /* restore flag for resource release callback */
+       camcorder->resource_release_cb_calling = FALSE;
+
+       _MMCAMCORDER_UNLOCK_RESOURCE(camcorder);
+
+       _mmcam_dbg_warn("leave");
+
        return;
 }