From 22bc5490df0173d1b31a531d9e7c9ea87764a8e7 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 5 Aug 2022 20:01:52 +0900 Subject: [PATCH] Unmap buffer after use - 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 --- packaging/libmm-camcorder.spec | 2 +- src/mm_camcorder_gstcommon.c | 44 ++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/packaging/libmm-camcorder.spec b/packaging/libmm-camcorder.spec index 0736d53..19aaafb 100755 --- a/packaging/libmm-camcorder.spec +++ b/packaging/libmm-camcorder.spec @@ -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 diff --git a/src/mm_camcorder_gstcommon.c b/src/mm_camcorder_gstcommon.c index 9a639a0..44e7a84 100644 --- a/src/mm_camcorder_gstcommon.c +++ b/src/mm_camcorder_gstcommon.c @@ -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]); -- 2.34.1