Unmap buffer after use 23/279323/3 accepted/tizen/unified/20220819.122516 submit/tizen/20220817.064510
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 5 Aug 2022 11:01:52 +0000 (20:01 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 11 Aug 2022 01:32:50 +0000 (10:32 +0900)
- The crash is occurred when access mapped data pointer after unmap buffer.
  So, change the timing to unmap buffer.

[Version] 0.10.266
[Issue Type] Bug fix

Change-Id: I0f40014992065e4593dd32aa4038d398806f0503
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/libmm-camcorder.spec
src/mm_camcorder_gstcommon.c

index 0736d53..19aaafb 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.265
+Version:    0.10.266
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 9a639a0..44e7a84 100644 (file)
@@ -156,34 +156,27 @@ static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_n
 static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height);
 #endif /* _MMCAMCORDER_PRODUCT_TV */
 
-static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
+static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
 static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
 
 /*=======================================================================================
 |  FUNCTION DEFINITIONS                                                                 |
 =======================================================================================*/
-static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
+static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
 {
        gboolean ret = TRUE;
-       GstMapInfo map_info;
 
        mmf_return_val_if_fail(buffer, FALSE);
        mmf_return_val_if_fail(stream, FALSE);
+       mmf_return_val_if_fail(map_info, FALSE);
 
-       memset(&map_info, 0x0, sizeof(GstMapInfo));
-
-       if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
-               MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
-               return FALSE;
-       }
-
-       stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
+       stream->length_total = map_info->size;
 
        switch (stream->format) {
        case MM_PIXEL_FORMAT_NV12: /* fall through */
        case MM_PIXEL_FORMAT_NV21:
                stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
-               stream->data.yuv420sp.y = map_info.data;
+               stream->data.yuv420sp.y = map_info->data;
                stream->data.yuv420sp.length_y = stream->width * stream->height;
                stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
                stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
@@ -196,7 +189,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
 
        case MM_PIXEL_FORMAT_I420:
                stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
-               stream->data.yuv420p.y = map_info.data;
+               stream->data.yuv420p.y = map_info->data;
                stream->data.yuv420p.length_y = stream->width * stream->height;
                stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
                stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
@@ -211,7 +204,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
 
        case MM_PIXEL_FORMAT_422P:
                stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
-               stream->data.yuv422p.y = map_info.data;
+               stream->data.yuv422p.y = map_info->data;
                stream->data.yuv422p.length_y = stream->width * stream->height;
                stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
                stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
@@ -228,7 +221,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
        case MM_PIXEL_FORMAT_UYVY: /* fall through */
        case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
                stream->data_type = MM_CAM_STREAM_DATA_YUV422;
-               stream->data.yuv422.yuv = map_info.data;
+               stream->data.yuv422.yuv = map_info->data;
                stream->data.yuv422.length_yuv = stream->length_total;
                stream->stride[0] = stream->width << 1;
                stream->elevation[0] = stream->height;
@@ -240,7 +233,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
        case MM_PIXEL_FORMAT_ENCODED_VP8:   /* fall through */
        case MM_PIXEL_FORMAT_ENCODED_VP9:   /* fall through */
                stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
-               stream->data.encoded.data = map_info.data;
+               stream->data.encoded.data = map_info->data;
                stream->data.encoded.length_data = stream->length_total;
                stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
                stream->num_planes = 1;
@@ -248,7 +241,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
 
        case MM_PIXEL_FORMAT_INVZ:
                stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
-               stream->data.depth.data = map_info.data;
+               stream->data.depth.data = map_info->data;
                stream->data.depth.length_data = stream->length_total;
                stream->stride[0] = stream->width << 1;
                stream->elevation[0] = stream->height;
@@ -258,7 +251,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
        case MM_PIXEL_FORMAT_RGBA: /* fall through */
        case MM_PIXEL_FORMAT_ARGB:
                stream->data_type = MM_CAM_STREAM_DATA_RGB;
-               stream->data.rgb.data = map_info.data;
+               stream->data.rgb.data = map_info->data;
                stream->data.rgb.length_data = stream->length_total;
                stream->stride[0] = stream->width << 2;
                stream->elevation[0] = stream->height;
@@ -271,8 +264,6 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
                break;
        }
 
-       gst_memory_unmap(memory, &map_info);
-
        return ret;
 }
 
@@ -393,6 +384,7 @@ gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sam
 
        GstBuffer *buffer = NULL;
        GstMemory *memory = NULL;
+       GstMapInfo map_info;
        GstCaps *caps = NULL;
        GstStructure *structure = NULL;
 
@@ -442,7 +434,14 @@ gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sam
                if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
                        goto _INVOKE_VIDEO_STREAM_CB_DONE;
        } else {
-               if (!__mmcamcorder_set_stream_data(&stream, buffer, memory))
+               memset(&map_info, 0x0, sizeof(GstMapInfo));
+
+               if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
+                       MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
+                       return FALSE;
+               }
+
+               if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
                        goto _INVOKE_VIDEO_STREAM_CB_DONE;
        }
 
@@ -467,6 +466,9 @@ gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sam
        }
 
 _INVOKE_VIDEO_STREAM_CB_DONE:
+       if (!gst_is_tizen_memory(memory))
+               gst_memory_unmap(memory, &map_info);
+
        for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
                tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
                tbm_bo_unmap(stream.bo[i]);