We use GST functions to create a screenshot from the buffer that we use as a reference for a feature on our app. We find that the code works fine the majority of the time, but will crash the program on this code lines:
gst_buffer_unmap(buf, &map_info);
and
gst_buffer_map(buf, &map_info, GST_MAP_READ)
Essentially what the full code is trying tto accomplish is:
- GstSample Retrieval: It retrieves the last sample from a sink element in the GStreamer pipeline. This is done using
g_object_get()
function. - Extracting Information from the Sample: The function then retrieves information about the sample such as its capabilities (width, height, format) and the buffer containing the image data.
- Mapping Buffer and Validating Data: It maps the buffer to a
GstMapInfo
structure, which provides information about the mapped memory, including the pointer to the data. It checks if the mapping was successful and if the data pointer is valid. - Creating an OpenCV Mat: Using the information retrieved (width, height, data pointer), it creates an OpenCV Mat object to store the image data. The image data is then copied into this Mat.
- Color Conversion: It converts the color format of the captured frame from RGB to BGR. This is likely done because OpenCV typically uses BGR color format.
- Cleanup and Return: It releases mapped buffer and returns
true
if the process is successful, otherwisefalse
.
What could be causing these random crashes, and is there a way to do the same thing we are trying to accomplish with a different function?