• Hardware Platform: Jetson Nano
• DeepStream Version: 6.0
• JetPack Version 4.6
• Segmentation fault
**• running my code **
• jetson nano with ds 6.0
Despite
sources\apps\sample_apps\deepstream-image-meta-test
working well on my jetson nano , when I want to use my own pipeline (that was working before) I got a segmentation fault at nvds_obj_enc_process(ctx, &userData, ip_surf, obj_meta, frame_meta);
the frame saving work on jetson orin and dgpu with the same pipeline. I have no warning or no error else than segmentation fault.
here my pipeline :
/*
* Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <math.h>
#include <cuda_runtime_api.h>
#include "gstnvdsmeta.h"
#include "nvbufsurface.h"
#include "nvds_obj_encode.h"
#include "gst-nvmessage.h"
#define MAX_DISPLAY_LEN 64
#define PGIE_CLASS_ID_VEHICLE 0
#define PGIE_CLASS_ID_PERSON 2
/* The muxer output resolution must be set if the input streams will be of
* different resolution. The muxer will scale all the input frames to this
* resolution. */
#define MUXER_OUTPUT_WIDTH 1920
#define MUXER_OUTPUT_HEIGHT 1080
/* Muxer batch formation timeout, for e.g. 40 millisec. Should ideally be set
* based on the fastest source's framerate. */
#define MUXER_BATCH_TIMEOUT_USEC 40000
#define TILED_OUTPUT_WIDTH 1920
#define TILED_OUTPUT_HEIGHT 1080
/* NVIDIA Decoder source pad memory feature. This feature signifies that source
* pads having this capability will push GstBuffers containing cuda buffers. */
#define GST_CAPS_FEATURES_NVMM "memory:NVMM"
gchar pgie_classes_str[4][32] = { "Vehicle", "TwoWheeler", "Person",
"RoadSign"
};
#define FPS_PRINT_INTERVAL 300
#define save_img TRUE
#define attach_user_meta TRUE
/* pgie_src_pad_buffer_probe will extract metadata received on pgie src pad
* and update params for drawing rectangle, object information etc. We also
* iterate through the object list and encode the cropped objects as jpeg
* images and attach it as user meta to the respective objects.*/
GstPadProbeReturn pgie_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
NvDsObjEncCtxHandle ctx = (NvDsObjEncCtxHandle)user_data;
GstBuffer *buf = (GstBuffer *) info->data;
GstMapInfo inmap = GST_MAP_INFO_INIT;
if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
GST_ERROR ("input buffer mapinfo failed");
return GST_PAD_PROBE_OK;
}
NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
gst_buffer_unmap (buf, &inmap);
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
NvDsMetaList *l_frame = NULL;
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next) {
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)(l_obj->data);
if (!obj_meta)
continue;
NvDsObjEncUsrArgs userData = {0};
userData.saveImg = true;
userData.attachUsrMeta = true;
userData.scaleImg = false;
userData.quality = 85;
static int frame_count = 0;
snprintf(userData.fileNameImg, sizeof(userData.fileNameImg), "frame_%d.jpg", frame_count++);
g_print("obj_ctx_handle: %p\n", ctx);
nvds_obj_enc_process(ctx, &userData, ip_surf, obj_meta, frame_meta);
}}
nvds_obj_enc_finish (ctx);
return GST_PAD_PROBE_OK;
}
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
GMainLoop *loop = (GMainLoop *)data;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error(msg, &error, &debug);
g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
g_printerr("Debugging information: %s\n", debug ? debug : "none");
g_clear_error(&error);
g_free(debug);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc, char *argv[]) {
GMainLoop *loop = NULL;
GstElement *pipeline = NULL;
GstBus *bus = NULL;
guint bus_watch_id;
/* Initialize GStreamer */
gst_init(&argc, &argv);
loop = g_main_loop_new(NULL, FALSE);
/* Define the pipeline string */
const gchar *pipeline_desc =
"v4l2src device=\"/dev/video0\" ! "
"capsfilter caps=\"image/jpeg, width=1920, height=1080, framerate=30/1\" ! "
"jpegdec ! "
"videoconvert ! "
"nvvideoconvert ! "
"capsfilter caps=\"video/x-raw(memory:NVMM), format=RGBA, width=1920, height=1080, framerate=30/1\" ! "
"mux.sink_0 nvstreammux name=\"mux\" batch-size=1 width=1920 height=1080 batched-push-timeout=4000000 "
"live-source=1 num-surfaces-per-frame=1 sync-inputs=0 max-latency=0 ! "
"nvinfer name=\"primary-inference\" config-file-path=\"/home/vision/cfg/infer_cfg/YOLOV8S.txt\" ! "
"nvtracker tracker-width=640 tracker-height=384 gpu-id=0 "
"ll-lib-file=\"/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so\" "
"ll-config-file=\"/home/vision/cfg/infer_cfg/config_tracker_NvDCF_perf.yml\" ! "
"nvdsanalytics name=\"analytics\" config-file=\"/home/vision/cfg/infer_cfg/analytics.txt\" ! "
"nvvideoconvert ! "
"nvdsosd name=\"onscreendisplay\" ! "
"nvegltransform ! "
"nveglglessink sync=\"false\"";
/* Create the pipeline from the pipeline description */
pipeline = gst_parse_launch(pipeline_desc, NULL);
if (!pipeline) {
g_printerr("Failed to create pipeline\n");
return -1;
}
/* Start playing the pipeline */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
/* Setup bus watch for messages */
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
bus_watch_id = gst_bus_add_watch(bus, bus_call, loop);
gst_object_unref(bus);
NvDsObjEncCtxHandle ctx = nvds_obj_enc_create_context(); // Initialize this based on your context creation needs
// Set up the probe
GstElement *pgie = gst_bin_get_by_name(GST_BIN(pipeline), "primary-inference");
GstPad *pgie_src_pad = gst_element_get_static_pad(pgie, "src"); // Get the source pad of the nvinfer element
gst_pad_add_probe(pgie_src_pad, GST_PAD_PROBE_TYPE_BUFFER, pgie_src_pad_buffer_probe, ctx, NULL);
gst_object_unref(pgie_src_pad);
/* Run the main loop */
g_main_loop_run(loop);
/* Cleanup */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
g_source_remove(bus_watch_id);
g_main_loop_unref(loop);
return 0;
}
thanks for any help !